美文网首页
Python 引用其他.py文件

Python 引用其他.py文件

作者: DiligentLeo | 来源:发表于2018-03-14 14:28 被阅读84次

Python 引用其他.py文件中的类和类的方法

HelloWorld是文件名称,Hello是类

from HelloWorld import Hello

调用,Hello类的方法:

h = Hello()
h.hello()
Hello, world #输出结果
附:HelloWorld.py文件内容

#  
class Hello(object):  
    def hello(self,name= 'world'):  
        print('Hello, %s' %name)

引入其他文件夹中的普通.py文件

from app.util import conf #此时将加载配置

conf.init()
print(conf.get_mysql_host())

引入同级文件夹的文件

from . import myglobal #引入本地文件

def get_mysql_host():
return (myglobal.getEnvironmentProperty('mysql.host','fkkk'))

相关文章

网友评论

      本文标题:Python 引用其他.py文件

      本文链接:https://www.haomeiwen.com/subject/sljfqftx.html