Python Learning Path-module concepts, special variables in modules, OS, SYS modules

Source: Internet
Author: User

Module concept
1 #Note: The custom module name is not the same as the standard module name, and only the custom module will be imported if the same2 #single module and in the same directory:3 #directly with the import module name, called with the module name. Method Name ()4 #nested under Other folders:5 #from xxx import xxx as alias6 ImportExample7 Importlib.commons8  fromLibImportCommons as Lib_commons9  fromSrcImportCommons as Src_commons
Installing third-party modules
1. SOURCE installation: Download the required module source code, unzip, and execute the file in the setup.py (python3 setup.py install)
2. Pip:pip Install requests
Special variables in the module
1 # __name__==__main__ When executing the current file, the special variable name = = Main 2 # __file__     All comments 4# in the relative path 3# __doc__ file     where the current file is located __cached__  Cache location 5#  __package__ The current file in which package, the project does not count
Os

Provides system-level operations

Os.path.abspath (PATH)#returns the absolute path normalized by pathOs.path.split (PATH)#split path into directory and file name two tuples returnedOs.path.dirname (PATH)#returns the directory of path. is actually the first element of Os.path.split (path)Os.path.basename (PATH)#returns the last file name of path. If path ends with a/or \, then a null value is returned. The second element of Os.path.split (path)Os.path.exists (PATH)#Returns true if path exists, false if path does not existOs.path.isabs (PATH)#returns True if path is an absolute pathOs.path.isfile (PATH)#returns True if path is a file that exists. Otherwise returns falseOs.path.isdir (PATH)#returns True if path is a directory that exists. Otherwise returns falseOs.path.join (path1[, path2[, ...])#when multiple paths are combined, the parameters before the first absolute path are ignoredOs.path.getatime (PATH)#returns the last access time of the file or directory to which path is pointingOs.path.getmtime (PATH)#returns the last modified time of the file or directory to which path is pointing

More ...

Sys

Provide interpreter-related actions

SYS.ARGV           # command-line argument list, the first element is the program itself path sys.exit (n)        # exit program, Exit normally (0) Sys.version       # Gets the version information of the Python interpreter sys.maxint        # the largest int value Sys.path           # Returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing sys.platform      # returns the operating system platform name sys.stdout.write ('please:'= sys.stdin.readline () [:-1]

More ...

Python Learning Path-module concepts, special variables in modules, OS, SYS modules

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.