我是python和Pycharm的新手.因此,请不要犹豫,指出我做错了什么以及如何解决问题.
问题是IPython无法像往常一样导入我想要执行的函数.即使在运行python文件之后,我也无法在IPython控制台中从该文件导入函数.此外,在IPython控制台中没有代码完成.
例如,我编写了一个名为python的文件student.py,其中我定义了一个名为的类student.然后我运行这个文件.但是当我输入student('Jack', 28)控制台时,IPython控制台说没有定义类'student' .
class student(object):
def _init_(self, name, age):
self.name=name
self.age=age
Run Code Online (Sandbox Code Playgroud)
令我困惑的是我可以运行该文件.但是当我输入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
Run Code Online (Sandbox Code Playgroud)
更重要的是,IPython Magic Function在IPython控制台中也不起作用.
In[3]: %run student.py
ERROR: File `u'student.py'` not found.
Run Code Online (Sandbox Code Playgroud)
很抱歉没有图片,因为没有足够的声誉,使情况更加清晰.