我对 python 和 Pycharm 都很陌生。因此,请毫不犹豫地指出我哪里做错了以及如何解决问题。
问题是IPython无法像往常一样导入我想要执行的函数。
即使 python 文件运行后,我也无法在 IPython 控制台中导入该文件中的函数。此外,IPython 控制台中没有代码完成功能。
例如我写了一个python文件,名为student.py
,其中我定义了一个名为student
。然后我运行这个文件。但是当我输入时,IPython 控制台说类“student”未定义student('Jack', 28)
在控制台中。
class student(object):
def _init_(self, name, age):
self.name=name
self.age=age
让我困惑的是我可以运行该文件。但是当我打字时student('Jack', 28)
在控制台中,IPython 控制台显示
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/IPython/core/interactiveshell.py", line 3032, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-483e7a488507>", line 1, in <module>
student('Jack',28)
NameError: name 'student' is not defined
更重要的是,IPython Magic Function
在 IPython 控制台中也不起作用。
In[3]: %run student.py
ERROR: File `u'student.py'` not found.
抱歉,由于声誉不够,没有图片让情况更清楚。