python--Common Modules

Source: Internet
Author: User

Import OS


Print (OS.GETCWD ()) # Fetch the current working directory, absolute Path

Os.chdir ("..") # Change the current directory
Print (Os.curdir)  # current directory, relative path

Print (Os.pardir) # Parent directory, relative path
Os.mkdir ("Test1")  # Create a folder or write an absolute path, default to the current directory

Os.rmdir ("Test1") # Delete the specified folder, only the empty folder
Os.remove ("Test")  # Delete file, cannot delete folder
Print (Os.listdir ('. '))  # list all files in one directory
Print (Os.listdir (R ' d:\\ '))
Os.rename ("Test", "Test1")  # renamed, followed by new name
Print (Os.stat ("F1"))  # get file information

Print (__file__) # is the absolute path to this file, the delimiter is incorrect under windows
Print (Os.path.abspath (__file__)) # get absolute path
Print (Os.path.split ("/usr/hehe/hehe.txt"))  # split path and file name
Print (Os.path.dirname ("/usr/local"))  # Get Parent Directory
Print (Os.path.basename ("/usr/local"))  # Gets the last level, if the file display filename, if the directory is displayed directory name
Print (Os.path.exists ("/usr/local"))  # Directory/file exists

Print (Os.path.isfile ("F1")) # To determine if it is a file
Print (Os.path.isdir ("/usr/local"))  # is a folder
Print (Os.path.join ("root", ' hehe ', ' a.sql '))  # stitching into a path

# print (OS.SEP)  # Path delimiter for the current operating system
#
# print (OS.LINESEP) # line break for the current operating system
#
# print (OS.PATHSEP) # The delimiter for each path in the environment variables of the current system, Linux is:, Windows is;
#
# print (Os.environ) # Environment variables for the current system
#
# print (os.name) # current system name

Os.system (' calc ')  # used to execute operating system commands, can only execute, get no results

res = Os.popen (' ipconfig ')  # used to execute operating system commands, and get to return results
Print (Res.read ())

# import Sys

# print (Sys.path) # Environment variables
# print (sys.platform) # See what the current operating system is
# print (sys.version) # See Python version
# print (SYS.ARGV) # Gets the parameters passed in when the Python file is run

# quit () # Quit Program
# Print (Sys.exit (' Exit Program ')) # Exit program, Exit normally (0)

python--Common Modules

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.