python系列print报错问题


问题一:

#!D:\mysoft\mypython\python
#coding=utf-8
print '你好,美丽中国!'

报错

:::::::::::::::::::::

  File "test1.py", line 3
    print '你好,美丽中国!'
                   ^
SyntaxError: Missing parentheses in call to 'print'

::::::::::::::::::::::

print要加()括号,因为print是函数了。

::::

PS注意:在python3系列以上,raw_input()不能用了,改为input()用法了!

::::

问题二:

#!D:\mysoft\mypython\python
#coding=utf-8
import time
import sys
colours = ["1","2","3","4","5","6","7","8","9","10","100"]
for i in range(len(colours)):
 time.sleep( .5 )
 sys.stdout.write("which colour do you like?:[% %s]colour complete!\r" %colours[i])
 sys.stdout.flush()
报错

:::::::::::::::::::::

Traceback (most recent call last):
  File "test2017.py", line 8, in <module>
    sys.stdout.write("which colour do you like?:[% %s]colour complete!\r" %colou
rs[i])
TypeError: not all arguments converted during string formatting

:::::::::::::::::::::

% %s 多写了,后面的%colour不够用了!

然后,完美的进度条可以了~

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM