Python 基础教程中的问题及解决方案(1)

1、 在ubuntu中,调用终端时如:

     f = open('/home/theone/test_input.txt', 'r') 中的txt格式文本不能加后缀

    正确的应为:  f = open('/home/theone/test_input', 'r') 

    同样的,生成html时:$ python simple_markup.py < test_input.txt > test_output.html

    也应为:$ python simple_markup.py < test_input > test_output.html

2、若忘记保存的.py文件应放在何处时

    在IDLE中输入 

    >>>import sys

    >>>sys.path

    就得到了保存的可直接运行的目录

ps:

if判断条件还可以简写,比如写:

    if x:    

        print 'True'

只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False

原文地址:https://www.cnblogs.com/Mellcap/p/4436998.html