Python_ Object-oriented _os system command module

Source: Internet
Author: User
Tags posix

#--os modules that operate on the operating system
System () Executes the systems command in Python
Stat () Get file information
Listdir () Gets a list of the names of all the contents in the specified folder
GETCWD () Gets the path where the current file is located
ChDir () Modify the path of the current file work
Getenv () Gets the current PATH environment variable information
Putenv () temporarily Add environment variable

#--os.environ OS Environment module
os.environ[' PATH '] writes environment variables into the system

#--os Module Properties
Name get system ID linux,mac->posix windows->nt
Sep get path split symbol Linux,mac/window-> \
Linesep get system line break symbol Linux, \ n window->\r\n or \ n

=======================================================================================

#--os modules that operate on the operating system

Import OS
# systems () Execute system commands in Python
Os.system (' mkdir lianxi001 ')
Os.system (' Rm-rf lianxi001 ')

# stat () Get file information
res = Os.stat ("1.py")
Print (RES)

# Listdir () Gets a list of the names of all the contents in the specified folder
res = Os.listdir ('. ')
Print (RES) # Returns a table of contents

# GETCWD () Gets the path where the current file is located
res = OS.GETCWD ()
Print (res) #/mnt/hgfs/vm_gongxiang/day15

# chdir () modify the path of the current file work
Os.chdir ('/home/wangwen/ceshi0801 ')
Os.system ("mkdir cesih002")

# getenv () Gets the current PATH environment variable information
res = os.getenv ("PATH")
Os.system ("Wangwen")
Print (RES)

# putenv () temporarily Add environment variable
res = os.putenv ("PATH", "/home/wangwen/ceshi0801/")
Os.system ("Wangwen")

#--os.environ OS Environment module

# os.environ[' PATH ' #把环境变量写进系统中
# Print (Os.environ)
os.environ[' PATH '] + = ":/home/wangwen/ceshi0801/"
Os.system ("star")
Print (os.environ[' PATH ')

# name gets the system ID linux,mac->posix windows->nt
Print (Os.name)

# Sep Get path split symbol Linux,mac/window-> \
Print (OS.SEP)

# Linesep Gets the line break symbol for the system Linux, \ n window->\r\n or \ n
Print (Repr (OS.LINESEP))

Python_ Object-oriented _os system command module

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.