|  | 
|  | 
| back to board | Common Boardpython and reading from files I am learning  python.When i see  the example of problem 1000 and 1001, python reads  from stdin.
 How can i read from input.txt without changing my program every  time i send  it  in.
 
 e.g. pascal  uses #ifdef online_judge to read from files
Re: python and reading from files Posted by ilalex  13 Apr 2013 23:06In linux I prefer to use this command:
 xclip -out | python problem.py
 
 It takes input from clipboard and send it to script.
Re: python and reading from files I use Windows on my computer.
 When i define a function like
 
 def invoer(place):
 if place=='file':
 f = open('input.txt', 'r')
 regel=f.readline()
 print(sum(int(x) for x in regel.split(' ')))
 f.close()
 else:
 print(sum(int(x) for x in input().split(' ')))
 
 invoer('console')
 
 I can use a file.
 Is there a smarter way?
 | 
 | 
|