在Python Console中执行,会报错,错误提示与代码匹配不上 。例如:
runfile('D:/project/python/example/pythonExample/LanguageExample/ObjectOrient/biz_handle.py', wdir='D:/project/python/example/pythonExample/LanguageExample/ObjectOrient')gen_report:Script 李涛Sname=Script,name=firstTraceback (most recent call last):File "D:ProgramDataAnaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 3325, in run_codeexec(code_obj, self.user_global_ns, self.user_ns)File "<ipython-input-49-9b4d67365a2c>", line 1, in <module>runfile('D:/project/python/example/pythonExample/LanguageExample/ObjectOrient/biz_handle.py', wdir='D:/project/python/example/pythonExample/LanguageExample/ObjectOrient')File "C:Program FilesJetBrainsPyCharm 2019.2helperspydev_pydev_bundlepydev_umd.py", line 197, in runfilepydev_imports.execfile(filename, global_vars, local_vars)# execute the scriptFile "C:Program FilesJetBrainsPyCharm 2019.2helperspydev_pydev_imps_pydev_execfile.py", line 18, in execfileexec(compile(contents+"n", file, 'exec'), glob, loc)File "D:/project/python/example/pythonExample/LanguageExample/ObjectOrient/biz_handle.py", line 23, in <module>ss = Special("Special")TypeError: Special() takes no arguments
在Terminal执行,就正常运行:
(venv) D:projectpythonexamplepythonExampleLanguageExampleObjectOrient>python biz_handle.pygen_report:Script 李涛Sname=Script,name=firstgen_report:韩梅梅Sname=Special,name=Special(venv) D:projectpythonexamplepythonExampleLanguageExampleObjectOrient>
在网上查了一下,Python Console是Python的交互式界面,Terminal是命令行模式 。但并没有找到资料解释他们之间的详细差别,或许大家都认为他们的效果是一样的,也没有人遇到过我这种情况 。
相关源码如下:
创建Python文件 biz_handle.py
# encoding:utf-8from general_logic import GeneralLogicclass Script(GeneralLogic):def __init__(self, name):self.Sname = self.__class__.__name__self.name = namedef gen_report(log):print("gen_report:{}".format(log))class Special(GeneralLogic):passif __name__ == "__main__":so = Script("first")so.check_run(gen_report,"Script 李涛")ss = Special("Special")ss.check_run(gen_report,"韩梅梅")
创建Python文件 general_logic.py
# encoding:utf-8class GeneralLogic(object):def __init__(self, name):self.Sname = self.__class__.__name__self.name = namedef check_run(self,gen_report,log):gen_report(log)print("Sname={},name={}".format(self.Sname,self.name))
谁知道该如何排查他们之间的差别?
版本信息:
(venv) D:projectpythonexamplepythonExampleLanguageExampleObjectOrient>python -VPython 3.7.3
print(sys.version)3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
【Pycharm中Python Console与Terminal的区别】
推荐阅读
- 再见HTML ! 用纯Python就能写一个漂亮的网页
- 最受欢迎 12 个 Python 开源框架,你用过哪些?
- 第六十一章、C程序中怎么调用Linux中的shell命令
- 大红袍――茶中状元,状元茶润肺
- 如何启用Windows 10 Version 2004中的硬件加速GPU调度?
- 禅茶中的端茶送客,叫做端茶送客
- Python基础到高级,完整全套视频分享解析,学编程方法很重要
- 百度竞价“基木鱼”中如何查看落地页数据
- 计算机端口详解
- 招聘|中国烟草再发招聘信息,年薪可达22万以上,面试通过就可上岗