I_Love_Div_4's blog

By I_Love_Div_4, history, 11 days ago, In English
        #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt" , "w" , stdout);
	#endif

Is there anything in python like this. If python has something of this type can you guide me how to use it?

 
 
 
 
  • Vote: I like it
  • -7
  • Vote: I do not like it

»
11 days ago, # |
Rev. 2   Vote: I like it -17 Vote: I do not like it

.

»
11 days ago, # |
  Vote: I like it +8 Vote: I do not like it

check this blog

»
11 days ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

in python we don't have these lines its present only in Cpp see this link

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

import sys

sys.stdin = open('input.txt', 'r')

sys.stdout = open('output.txt', 'w')

this works for me

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think this is the intended way to do it in Python. Using this you can just use print() and input() as normal.

    Btw, if you want to go back to using stdin/stdout again, you can just do

    sys.stdin = sys.__stdin__
    sys.stdout = sys.__stdout__