python遇到的问题

1. import 可以导入同一级目录下的py文件, 例如 test1.py和 main.py 是同一个目录下的两个文件。

#test1.py

def test():

    print "this is test"

#main.py

import test1

test1.test()     #需要在函数名前面加上文件名

这样调用是正确的。


或者这样调用

#test1.py

def test():

    print "this is test"

#main.py

from test1 import *

test()


或者

#test1.py

def test():

    print "this is test"

#main.py

import test1 as TEST

TEST.test()

这样调用也是正确的。 

猜你喜欢

转载自blog.csdn.net/sunny04/article/details/50083935
今日推荐