• Python模块


    using_sys.py

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

    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)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream."
    
  • 相关阅读:
    Leetcode 515. Find Largest Value in Each Tree Row
    Paypal2017实习生-软件开发-B卷
    Codeblocks 遇到的问题 Cannot open output file, permission denied
    itoa()函数和atoi()函数详解
    Windows下如何更新 CodeBlocks 中的 MinGW 使其支持新版本 C++
    Leetcode 179. Largest Number
    合并两个有序数组到其中一个数组中
    腾讯2017实习生招聘软件开发编程题
    [LeetCode] 56
    360笔试
  • 原文地址:https://www.cnblogs.com/oskb/p/5069841.html
Copyright © 2020-2023  润新知