Python OS module introduction, pythonos Module
OS. getcwd () obtains the current working directory, that is, the directory path of the current python script.
OS. chdir ("dirname") changes the current script working directory, which is equivalent to
(1) OS. The GETWD function prototype is func GETWD () (PWD string, err Error) that returns the string of the path and a ERR message, why do you want to open this first? Because when I look at the OS package, the first one is Chkdir this package, but
Os. Rename () The prototype of this function is Func Rename (oldname, newname string) error, the input is the old filename, the new file name, and then returns an error in fact the function of the real implementation of the Syscall. Rename () and
Python OS module and Pythonos ModulePython OS Module 1. OS. getcwd ()
Obtain the current working directory.
ImportOS
Print (OS. getcwd () # I: \ Python ProgramIi. OS. chdir ('path ')
Change the working directory of the current script. It is
This is a creation in
Article, where the information may have evolved or changed.
Package Mainimport ("FMT" "Io/ioutil" "OS" "Reflect" "Time"Func Main () {dir, _:=OS. GETWD () fmt. Println ("Dir:", dir) Err:= OS. Chdir ("D:/project/test2") dir, _=OS.
Summary of OS Operating Files and file path instances in python,
This article describes the operating file and file path methods in python. Share it with you for your reference. The specific analysis is as follows:
Python obtains the upper-level
This is a creation in
Article, where the information may have evolved or changed.
Golang Standard Library
Today we are analyzing the Golang OS package, why not analyze the IO package today and analyze the OS package? Check the
The OS module in the python standard library contains common operating system functions. This module is especially important if you want your program to be unrelated to the platform. That is, it allows a program to run in Linux and Windows without
Obtain the current working directory, that is, the directory path of the current Python script: OS. getcwd () returns all files and directory names in the specified directory: OS. the listdir () function is used to delete a file: OS. remove ()
Python module OS, pythonos
The OS module allows you to create, delete, and view file attributes for directories or files, as well as perform path operations on files and directories. For example: absolute path, parent directory ......
OS. sep can
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.