您的位置:首页 > 编程语言 > Python开发

python遇到的问题

2015-11-28 14:42 561 查看
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()

这样调用也是正确的。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python