码迷,mamicode.com
首页 > 编程语言 > 详细

Python模块导入和常用内置方法

时间:2016-12-04 06:54:10      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:添加   name   变量   python   pytho   ...   str   sys   os.path   

模块导入和常见内置方法
__file__: os.path.dirname(__file__)和os.path.join(dirname, filename),通过sys.path.append()可以把模块添加到Python的环境变量目录中
__name__: 直接执行py文件时__name__返回"__main__", 通过import调用时__name__返回的是(包名.模块名)
__doc__: 返回.py文件中"""xxx"""注释部分
class.__dict_: 返回一个类里面有哪些方法和字段_
__repr__: 返回实例对象
>>> class D(object):
... def __str__(self):
... return "a __str__"
... def __repr__(self):
... return "a __repr__"
...
>>> dr = D()
>>> print dr
a __str__
>>> dr
a __repr__
>>> "%s" % dr
‘a __str__‘
>>> "%r" % dr
‘a __repr__‘

Python模块导入和常用内置方法

标签:添加   name   变量   python   pytho   ...   str   sys   os.path   

原文地址:http://www.cnblogs.com/raykuan/p/6130039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!