【Python有坑系列】报错NameError: name 'execfile' is not defined

想用execfile顺序执行脚本文件,但是报错:

NameError: name 'execfile' is not defined

execfile在python3中已被废除,代替函数: 

exec(open(filename).read())

 

使用替代函数,输入文件名后,依然报错:

UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 2508: illegal multibyte sequence

改为:

exec(open("binEA_q1.py", encoding = 'utf-8').read())

exec(open("binEA_q2.py", encoding = 'utf-8').read())

顺利读取!

 

你可能感兴趣的:(Python编程手册,专栏:Python有坑系列)