Import OS; --Python comes with
Print (OS.GETCWD ())--Get the current working directory
Os.chdir ('/users/longlong/documents ')--Convert to/users/longlong/documents directory
Os.path.join (Parm1, Parm2,...)-Constructs a path name from one or more path fragments.
Os.path.expanduser ()--used to extend the path containing the ~ symbol to the full path
Copy the Code code as follows:
>>> pathname = '/users/pilgrim/diveintopython3/examples/humansize.py '
>>> os.path.split (Pathname)-('/users/pilgrim/diveintopython3/examples ', ' humansize.py ') List directory content construct absolute path
Copy the Code code as follows:
>>> Import OS
>>> print (OS.GETCWD ())
/users/longlong/documents
>>> Os.chdir ("./python/")
>>> OS.GETCWD ()
'/users/longlong/documents/python '
>>> Print (Os.path.realpath (' whileloop.py ')
)
/users/longlong/documents/python/whileloop.py
>>> Print (Os.path.realpath ("whileloop.py"))
/users/longlong/documents/python/whileloop.py
>>>
List parsing
Copy the Code code as follows:
>>> [Os.path.realpath (f) for F in Glob.glob ("*.py")]
['/users/longlong/documents/python/indices_over_two_objects.py ', '/users/longlong/documents/python/loops_over_ indices.py ', '/users/longlong/documents/python/while_loops.py ']
>>> [F for F in Glob.glob ("*.py") if Os.stat (f). st_size > 700]
[' indices_over_two_objects.py ', ' while_loops.py ']
1
Dictionary parsing
>>> metadat_dict = {F:os.stat (f) for F in Glob.glob (' *.py ')} >>> type (metadat_dict)
> >> list (Metadat_dict.keys ()) [' indices_over_two_objects.py ', ' while_loops.py ', ' loops_over_indices.py '] > >> metadat_dict[' indices_over_two_objects.py '].st_size871
Set resolution
>>> A_set = set (range) >>> a_set{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} >>> {x**2 for x in A_set}{0, 1, 4, 0, 9, +, G, BA, +-} >>> {x for x in A_set if x%2 = = 2**x,}{0, 8, 2, 4, 6} >>> {for x in R Ange (10)}{32, 1, 2, 64, 4, 128, 256, 512, 8, 16}
The above mentioned is the whole content of this article, I hope you can like.