python下, 我已经在文件中写了一段代码,文件名叫x.py,如何在shell中打开这个文件?用import还是什么?
1个回答
展开全部
~$ cat x.py
#!/usr/bin/python
# encoding: utf-8
def main():
print("Hello Pythoner.")
if __name__=='__main__':
main()
:~$ x.py
x.py: command not found
~$ python x.py
Hello Pythoner.
~$ python
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import x
>>> x.main()
Hello Pythoner.
>>>
#!/usr/bin/python
# encoding: utf-8
def main():
print("Hello Pythoner.")
if __name__=='__main__':
main()
:~$ x.py
x.py: command not found
~$ python x.py
Hello Pythoner.
~$ python
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import x
>>> x.main()
Hello Pythoner.
>>>
更多追问追答
追问
$ python x.py
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'x.py': [Errno 2] No such file or directory
这是意味着我的保存目录有问题吗?
追答
en
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询