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

Python模块

时间:2015-12-23 16:00:24      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

using_sys.py

import sys
print (‘the command line argument are:‘)
for i in sys.argv:
    print (i)
print (‘\n\n the python path is‘, sys.path, ‘\n‘)

using_name.py

if __name__ ==‘__main__‘:
    print (‘this program is being run by itself‘)
else:
    print (‘i am being imported from another module‘)

mymodule.py

def sayhi():
    print (‘Hi, this is my module speaking.‘)
version=‘0.1‘
sayhi()

mymodule_demo.py

import mymodule
mymodule.sayhi()
print (‘Version‘, mymodule.version)

mymodule_demo2.py

from mymodule import sayhi,version
sayhi()
print (‘version‘, version)

dir()函数

>>> import sys
>>> dir (sys)
[‘__displayhook__‘, ‘__doc__‘, ‘__excepthook__‘, ‘__interactivehook__‘, ‘__loader__‘, ‘__name__‘, ‘__package__‘, ‘__spec__‘, ‘__stderr__‘, ‘__stdin__‘, ‘__stdout__‘, ‘_clear_type_cache‘, ‘_current_frames‘, ‘_debugmallocstats‘, ‘_getframe‘, ‘_home‘, ‘_mercurial‘, ‘_xoptions‘, ‘api_version‘, ‘argv‘, ‘base_exec_prefix‘, ‘base_prefix‘, ‘builtin_module_names‘, ‘byteorder‘, ‘call_tracing‘, ‘callstats‘, ‘copyright‘, ‘displayhook‘, ‘dllhandle‘, ‘dont_write_bytecode‘, ‘exc_info‘, ‘excepthook‘, ‘exec_prefix‘, ‘executable‘, ‘exit‘, ‘flags‘, ‘float_info‘, ‘float_repr_style‘, ‘get_coroutine_wrapper‘, ‘getallocatedblocks‘, ‘getcheckinterval‘, ‘getdefaultencoding‘, ‘getfilesystemencoding‘, ‘getprofile‘, ‘getrecursionlimit‘, ‘getrefcount‘, ‘getsizeof‘, ‘getswitchinterval‘, ‘gettrace‘, ‘getwindowsversion‘, ‘hash_info‘, ‘hexversion‘, ‘implementation‘, ‘int_info‘, ‘intern‘, ‘is_finalizing‘, ‘maxsize‘, ‘maxunicode‘, ‘meta_path‘, ‘modules‘, ‘path‘, ‘path_hooks‘, ‘path_importer_cache‘, ‘platform‘, ‘prefix‘, ‘set_coroutine_wrapper‘, ‘setcheckinterval‘, ‘setprofile‘, ‘setrecursionlimit‘, ‘setswitchinterval‘, ‘settrace‘, ‘stderr‘, ‘stdin‘, ‘stdout‘, ‘thread_info‘, ‘version‘, ‘version_info‘, ‘warnoptions‘, ‘winver‘]
>>> sys.__name__
‘sys‘
>>> sys.version
‘3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)]‘
>>> dir(print)
[‘__call__‘, ‘__class__‘, ‘__delattr__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__le__‘, ‘__lt__‘, ‘__module__‘, ‘__name__‘, ‘__ne__‘, ‘__new__‘, ‘__qualname__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__self__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘__text_signature__‘]
>>> print.__doc__
"print(value, ..., sep=‘ ‘, end=‘\\n‘, file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile:  a file-like object (stream); defaults to the current sys.stdout.\nsep:   string inserted between values, default a space.\nend:   string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream."

 

Python模块

标签:

原文地址:http://www.cnblogs.com/oskb/p/5069841.html

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