首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

[d]如何在python中调用python文件

2012-10-30 
[d]怎么在python中调用python文件我说的调用不是第一个调第二个的函数,而是调文件,不是这个##############

[d]怎么在python中调用python文件
我说的调用不是第一个调第二个的函数,而是调文件,
不是这个
#######################################
#文件1内容:

#FileName: test.py
def work():
  print "Hello,world!"
文件保存为test.py
----------------------
#文件2内容:
#FileName: main.py
import test #将文件1 test.py导入进来
test.work() #调用test.py中定义的work()函数
----------------------
###############################################
而是
#############################
#文件1内容:
#FileName: test.py
print 'hello'
----------------------
#文件2内容:
#FileName: main.py
……#调用文件1----------------------
--------------------
Double行动:
原帖分数:30
帖子加分:30
 

[解决办法]

探讨

不用打开文件,直接给文件地址就行,用execfile()函数

execfile(filename[, globals[, locals]])

This function is similar to the exec statement, but parses a file instead of a string. It is different from the impor……

热点排行