ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Общий форум

python and reading from files
Послано TinyJanssen 13 апр 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
Послано ilalex 13 апр 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
Послано TinyJanssen 20 апр 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?