ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

python and reading from files
Posted by TinyJanssen 13 Apr 2013 18:56
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:06
In 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
Posted by TinyJanssen 20 Apr 2013 00:22
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?