1

以下を実行してから、対話型コマンドを実行しようとすると失敗します...

c:\> python -u -i test.py | tee output.txt
... test.py output ...   

  File "<stdin>", line 1

    ^
SyntaxError: invalid syntax
>>> print "Hi"
  File "<stdin>", line 1
   print "Hi"
              ^

SyntaxError: invalid syntax

より単純なテストも失敗します。

c:\> python -u 
>>> print "Hi"
  File "<stdin>", line 1
   print "Hi"
              ^

SyntaxError: invalid syntax

Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32Windows 7で 使用しています。

4

2 に答える 2

0

この問題の回避策は次のとおりです。

c:\> python -u 
>>> print "Hi" # This comment prevents the bug
Hi

残念ながら、これは複数行のステートメントについて私が思いつくことができる最高のものです:

c:\> python -u 
>>> exec ''' # Comments still needed inside string
... for i in range(4): # 
...     print i #
... ''' # comment on the end of line
0
1
2
3
于 2015-10-02T15:10:47.967 に答える