Python Common Module 3 (OS and SYS modules)

Source: Internet
Author: User

Import OS
Import Sys

# Print (OS.GETCWD ()) #取当前工作目录
# Os.chmod ("/usr/local", 7) #给文件/directory plus permissions
# Print (Os.chdir (r "E:\byz_code\day2")) #更改当前目录
# print (Os.curdir) #当前目录
# print (Os.pardir) #父目录
# Print (Os.mkdir (r "test1)) #创建文件夹
# Print (Os.makedirs (r "Test1\test2")) #递归创建文件夹, parent directory does not exist when parent directory is created
# Print (Os.removedirs (r "Test1\test2")) #递归删除空目录
# Print (Os.rmdir ("Test1")) #删除指定的文件夹, only empty folders can be deleted
# Print (Os.remove (r "E:\byz_code\day4\a.txt")) #删除文件
# Print (Os.listdir ('. ')) #列出一个目录下的所有文件
# os.rename ("Test", "Test1") #重命名
# print (OS.SEP) #当前操作系统的路径分隔符
# print (R '%s '%os.linesep) #当前操作系统的换行符
# print (OS.PATHSEP) #当前系统的环境变量中每个路径的分隔符, Linux is:, Windows is;
# print (Os.environ) #当前操作系统的环境变量
# print (__file__) #代表当前文件
# Print (Os.path.abspath (' bb.py ')) #获取绝对路径
# Print (os.path.dirname)
# Print (Os.path.dirname (Os.path.dirname (__file__))) #获取父目录
# Print (os.path.exists ("hhaaa")) #目录/file is present
# Print (Os.path.isfile ("bb.py")) #判断是否是一个文件
# Print (Os.path.isdir ("/usr/local")) #是否是一个路径
# Print (Os.path.join ("root", ' hehe ', ' haha ', ' a.log ')) #拼接成一个路径
# os.path.join ("root", ' hehe ', ' haha ', ' a.log ')




# Print (Os.path.split ("/usr/hehe/hehe.txt")) #分割路径和文件名
# Print (Os.path.dirname ("/usr/local")) #获取父目录
# Print (Os.path.basename ("/usr/local")) #获取最后一级, if it is file display file name, if it is directory display directory name
# Print (os.path.exists ("/usr/local")) #目录/file is present
# Print (Os.path.isabs (".")) #判断是否是绝对路径
# Print (Os.path.isfile ("/usr/local")) #判断是否是一个文件
# Print (Os.path.isdir ("/usr/local")) #是否是一个路径
# Print (Os.path.join ("/root", ' hehe ', ' a.sql ')) #拼接成一个路径
# Print (Os.path.getatime ("len_os.py")) #输出最近访问时间
# Print (Os.path.getmtime ("len_os.py")) #输出最近访问时间


Import Sys
#sys. argv command line argument list, the first element is the path of the program itself
# sys.exit (' xxxxx ')
#退出程序, Exit normally (0)
# print (sys.version) #获取Python解释程序的版本信息
#sys. Path #返回模块的搜索路径, using the value of the PYTHONPATH environment variable when initializing
# print (sys.platform) #返回操作系统平台名称
def sayhi (name):
Print (' hi~%s '%name)

If __name__== ' __main__ ': #只有在运行自己这个python文件的时候
#才会执行下面的代码, it will not be executed when importing in another module.
Print (' This is the time in your own file: ', __name__)
Sayhi (' WMH ') # I'm calling when I'm self-rated

Python Common Module 3 (OS and SYS 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.