作者Xphenomenon (啦 )
看板Python
标题[问题] 关於使用者输入资料
时间Mon Jun 30 18:23:13 2008
在 c 里面可以这样写
test.c
#define
int main(void) {
int num;
while(scanf("%d", &num) == 1) {
printf("%d\n", num);
}
return 0;
}
num.txt 内容:
3
3
5
6
7
8
gcc -o test test.c
./test < num.txt
请问如果在 Python 里面我要怎麽写才能达到如 C 的要求呢?
我试过如:
test.py
while True:
a = raw_input()
if(len(a)
print a
python test.py < num.txt
但会有以下错误:
Traceback (most recent call last):
File "test.py", line 2, in <module>
a = raw_input()
EOFError: EOF when reading a line
麻烦大大解答一下,感谢 :>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.66.37.44
1F:→ lion0208:第3行..... if len(a): 07/07 14:21