Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

Python Training Course IX

System
System

 Files
 Directories
 Programs and Processes
 Calendars and Clocks

2
Files

3
Check Existence with exists(); Check Type with isfile()

絕對目錄

( . ) is current directory
( .. ) stands is parent directory

4
Copy with copy()

shutil.move() function copies a file and then removes the original

Change Name with rename()

5
Link with link() or symlink()

hard link

soft link also


called symbolic link

6
Change Permissions with chmod()

7
Change Ownership with chown()

8
Get a Pathname with abspath()

Get a symlink Pathname with realpath()


jeepers.txt is a symbolic link of oops.txt

Delete a File with remove()

9
Directories

10
Create with mkdir()

Delete with rmdir()

11
List Contents with listdir()

12
Change Current Directory with chdir()

13
List Matching Files with glob()

14
練習題

 Book P.259
 Things to Do 10.1~10.5

15
Programs and Processes

16
getpid(), getcwd(), getuid(), getgid()

get the process ID

get current working directory

get my user ID

get my group ID

17
Create a Process with subprocess
僅在 shell 另執行程式,並取得輸

( 標準輸出或錯誤輸出 )

也可以加入引數

也可以加入
pipe 導到另一
支程式
takes a list of the command and arguments
By default it only returns standard output
as type bytes rather than a string and does
not use the shell

18
Create a Process with subprocess

to show the exit status


of the other program

don’t want to capture the


output but might want to
In Unix-like systems, 0 is know its exit status
usually the exit status
for success.
to run programs with
arguments is to specify
them in a single string

a list of the arguments

19
Calendars and Clocks

20
calendar.isleap()

是否為閏年

21
date and timedelta of datetime module

timedelta 用來運算日
期時間

The iso refers to ISO 8601, an


international standard for
representing dates and
times. 22
datetime of datetime module

23
combine() of datetime module

combine 後的 datetime
object
一樣可以再利用 date(), time()

24
time module

epoch: the number of seconds


since midnight on January 1,
1970.
January 1, 1970 據說是 Unix 誕生之

mktime():converts a struct_time
object to epoch seconds
25
strftime()
strftime() converts a struct_time object to a string
and uses format strings to specify the output

數字左邊補 26
strptime()
strptime() converts a string to a struct_time object
and uses the same format string

數字左邊補 27
locale
locale—internationalization settings for your operating system

28
練習題

 Book P.259
 Things to Do 10.7~10.9

29

You might also like