Python comes with a large library - beginner to learn how to

Python comes with a large library - called standard library - which covers everything from Internet access to text processing.
A frequently asked question is that you should first learn what the library; as a beginner - in the face of more than 100 entries in the list, from where you started. Before you start - do not panic: you are unlikely to need to know the details of each library; you will learn more about some of you will know more Overview; and it is essential that if you need them, you will know how can I find more information about other people.
Where to start:
Almost all programs need to be in some way to interact with the operating system - Details of files and directories either find, or find data about processes and applications. A good starting point is the os [1] module; for example:

import OS
print('User name : ' ,OS 。getlogin ())
print('Running in directory:' ,OS 。GETCWD ())
print('Current process:' ,OS 。GETPID ())

Obtainable by a large number of details of the os module.
The module has a very useful os submodule [2], which is a set of useful functions for operating a file path: os.path

import OS
import os.path
root = os 。getcwd ()
print('Parent directory ', os.path.dirname(root))
print('Executing file ', os.path.basename(__file__))

There is also a modern alternative, [3]. The difference is that for the os.path, the file path as a string, where the object based. The above code is used as follows: os.pathpathlibpathlibpathlib

import os
import pathlib
root = pathlib.Path(os.getcwd())
print('Parent directory ', root.parent)
print('Executing file ', pathlib.Path(__file__).name)

I encourage you to explore and play os, and - the habit of using them, and what they offer. os.pathpathlib

Guess you like

Origin blog.csdn.net/gzyiCG/article/details/92573340