Discuss / Python / 导入模块应该放在哪个文件夹

导入模块应该放在哪个文件夹

Topic source

问题如图,我正在百度。。。

自己写的代码在下面: 'a test module'

__author__ = 'Zhangliangcheng'

import sys

def f(): args = sys.argv if (len(args) == 1): print ('Hello World!') elif (len(args) == 2): print ('Hello %s' % args[1]) else: print ('Too many arguments')

if name == 'main': f()

用命令行执行的时候没有什么问题。直接打印。但是在python界面调用f()的时候就显示: module 'test' has no attribute 'f'

Mr_RightMen

#3 Created at ... [Delete] [Delete and Lock User]

朋友,你在console上调用的时候,首先得import你的module啊,然后才能调用哦.


  • 1

Reply