玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容

Win环境下python代码执行报错NON-ASCII character问题

pythondashes = '\n' + '-' * 50 #  #破折号行
exec_dict = {

'f':"""
for %s in %s:
    print %s
""",

's':"""
%s = 0
%s = %s
while %s < len(%s):
    print %s [%s]
    %s = %s + 1
""",

'n':"""
%s = %d
while %s <%d:
    print %s
    %s = %s + %d
"""
}



def main():

    itype=raw_input('Loop type?(For/While) ')
    dtype= raw_input('Data type?(Number/seq) ')

    if dtype =='n':
        start = input('Starting value?')
        stop = input('Ending value(non-inclusive)?')
        step = input('Stepping value?')
        seq = str(range(start,stop,step))

else:
    seq = raw_input('Enter sequence: ')

    var = raw_input('Iterative variable name?')

    if Itype =='f':
        exec_str = exec_dict['f'] % (var,seq,var)

    elif Itype =='w':
        if dtype =='s':
            svar = raw_input('Enter sequence name? ')
            exec_str = exec_dict['s'] %\
    (var,svar seq,var,svar,svar,var,var,var)

        elif dtype =='n':
            exec_str = exec_dict['n'] %  \
        (var,start,var,stop,var,var,var,step)

        print dashes
        print 'Your custom-generated code:'+dashes
        print exec_str + dashes
        print 'Test execution of the code:'+dashes
        exec exec_str
        print dawshes

if_name_ == '_main_':
    main()

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/wenda/wd18510.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年06月07日 - 19时43分19秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules