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 () delete multiple directories: OS. removedirs (r "c: \ python") checks whether the given
How to add the path "permanent" to sys. path?
Sys. path is the path set of the python search module and is a list
Copy codeThe Code is as follows:['', 'C: \ WINDOWS \ system32 \ python26.zip ', 'c: \ Python26 \ DLLs', 'c: \ Python26 \ lib ', 'C: \ Python26 \ lib \ plat-win',
This article mainly introduces the operating system in Python. path usage. the instance analyzes the OS. the various common methods of path have some reference value. if you need them, you can refer to the examples in this article to analyze the OS in Python. path usage. Sha
There are two types of paths: relative path and absolute path. For a Unix-like system, the absolute path is the path starting. A relative path is a path that does not start with a slash.
In fact, there is only one
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
How to view the path of a Python search package:
The path to the Python search package is stored under Sys.path
View Method:
Import Sys
Sys.path
How to temporarily add a Python search package path:
Method 1: (enter
First, the Python environment to buildWindows environment1.: https://www.python.org/downloads/2. python2.7 is installed by default under C:\python2.73. Configure Environment variablesIf you install both 2.0 and 3.0 different versions of the Python compiler, the win system defaults to looking for the first python in the path
This method solves the portability of Python code, does not need to configure the Python environment on the new machine, and embeds Python code in Java Engineering only by installing Jython1. How Jython Installs: Jython_installer-2.5.0.jar. Need to download points, if no points, you can contact the landlord.The next way to install a fool, the
This article mainly introduces the Python standard library OS. path package and glob package usage examples. This article provides the code directly. the code contains detailed comments. For more information, see
OS. path package
The OS. path package is mainly used to process string paths, such as '/home/zikong/doc/fi
This article describes how to install python from the source code in Linux to any path (non-site-packages, if you are interested, refer to centos7 as an example:
Install python in the source code. install some devel packages first:
Yum-y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
Then download the source code
Decom
Below for you to share a Python get program to execute file path (recommended), with a good reference value, I hope to help you. Come and see it together.
1. Get the current execution main script method: Sys.argv[0] And _ file _
(1) SYS.ARGV
A list of instruction parameters to be passed to the Python script. Sys.argv[0] is the name of the script. Generally get a
1. Get the current execution main script method: Sys.argv[0] and _ file _(1) SYS.ARGVA list of instruction parameters to be passed to the Python script. Sys.argv[0] is the name of the script. Generally get a relative path, with Os.path.abspath (Sys.argv[0]) to get the absolute path of the execution file:?
12
dirname, filename = os.path.split(
Python file directory operations
Always can't remember the API. Last night, when I wrote this, I didn't remember, so just sort it out:files, folders in Python (file manipulation function) operation requires an OS module and a shutil module. Get the current working directory, that is, the directory path of the current
the configuration by specifying the configuration path for the startup parameter. Of course, conf.py You can change a similar name here, for example settings.py . Or you can use other formats to write configuration files, such as settings.yaml . -------------------------atm.py-------------------------------Print (__file__) #返回当前程序的相对路径import Osimport Sysprint (Os.path.abspath (__file__)) #返回绝对路径print (Os.path.dirname (Os.path.abspath (__file__))) #返回
,k) + dis (k,j) Algorithm features
Using the idea of dynamic programming
You can calculate an image without a direction or a graph
Short core code (five elements)
Can calculate the distance between any two points at once
Algorithm complexity O (n^3), is a good algorithm
A key issueWhen judging the equation for dis (i,k) + dis (k,j) The answer is yes, you can use the mathematical inductive method to prove that reference to this blogExample figure g for diameter to be
python get file Top level directory: Retrieve the directory of the file directory
Os.path.abspath (Os.path.join (os.path.dirname (' settings.py '), Os.path.pardir)
Os.path.pardir is the parent directory, Os.path.abspath is the absolute path
For example, look at the output:
Print Os.path.dirname (Os.path.abspath ("__file__"))Print Os.path.pardirPrint Os.path.join (Os.path.dirname ("__file__"), Os.path.pardir
__init__.py module under this package when importing the module under a package, for example, we specify the contents of the __init__.py module as follows:Print ("This is __init__ module")Then re-import the package in interactive mode, the effect is as follows:>>> import Pkg.module_3this is __init__ Modulehello world>>>It can be seen that PVM first loads the __init__.py module and then the other modules in the directory are found and loaded.Second, the module search
) Base.metadata.create_all (engine) #创建所有表结构if __name__ = = ' __main__ ': sessioncls = Sessionmaker (bind=engine) #创建与数据库的会话session class, notice that this returns toThe session is a class, not an instance session = Sessioncls () g3 = Session.query (Group). Filter (group.name== ' G3 '). First () #查到一个已经存在的组 h = session.query (Host). Filter (host.hostname== ' localhost '). Update ({' group_id ': g3.id}) #查到一个主机的信息并更新其group_ ID is the ID of the group that was found in the previous step, which comp
2nd. How Python Runs the program1. What is a Python interpreterThe Python interpreter is the program that runs the Python program.2, what is the source code?The source code is the statement written for the program: it contains text files (with a. py suffix)3. What is a byte code?Bytecode is the underlying form that
os.path.getsize (path) # query File size os.path.getatime (path) # query file Last read time os.path.getmtime (path) # query file Last modified time os.path.isfile (path) # does the path point to regular file os.path.isdir (pa
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.