国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

香港云服务器
服務器之家 - 腳本之家 - Python - Python文件及目錄操作實例詳解

Python文件及目錄操作實例詳解

2020-07-12 11:33raygtr Python

這篇文章主要介紹了Python文件及目錄操作的方法,實例分析了Python中os模塊的使用技巧,需要的朋友可以參考下

本文實例講述了Python文件目錄操作的方法。分享給大家供大家參考。具體分析如下:

在python中對文件及目錄的操作一般涉及多os模塊,os.path模塊。具體函數以及使用方法在程序中說明。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#-*- coding=UTF8 -*-
import os
import os.path as op
def change_dir():
  '''
 該函數顯示及改變前目錄
 using chdir() to change current dir
    getcwd() can show the current working directory
  '''
  directory="/tmp"
  #使用getcwd()返回當前目錄
  print os.getcwd()
  #chdir改變當前目錄為:directory目錄
  os.chdir(directory)
  print os.getcwd()
def show_filesOfdir(whichDir):
  '''
 此函數只顯示目錄下的所有文件
 using listdir() to shows all of the file execpt directory
   join() function catenate 'whichDir' with listdir() returns values
   isfile() check that file is a regular file
   '''
   #listdir() 函數顯示前目錄的內容
  for file in os.listdir(whichDir):
 #利用join()把whichDir目錄及listdir() 返回值連接起來組成合法路徑
    file_name = op.join(whichDir,file)
 #isfile()函數可以判斷該路徑上的文件是否為一個普通文件
    if op.isfile(file_name):
      print file_name
def printaccess(path):
  '''
 顯示文件的最后訪問時間,修改時間
 shows 'path' the last access time
      getatime() return the time of last access of path
   stat() return information of a file,use its st_atime return the time of last access
   ctime() return a string of local time
  '''
  import time
  #利用ctime()函數返回最后訪問時間
  #getatime()函數返回最后訪問時間,不過是以秒為單位(從新紀元起計算)
  print time.ctime(op.getatime(path))
  #stat()函數返回一個對象包含文件的信息
  stat = os.stat(path)
  #st_atime 最后一次訪問的時間
  print time.ctime(stat.st_atime)
  print the modify time
  print "modify time is:",
  print time.ctime(op.getctime(path))
  print "modify time is:",
  #st_ctime 最后一次修改的時間
  print time.ctime(stat.st_ctime)
def isDIR(path):
  '''
 一個os.path.isdir()函數的實現
 Implement isdir() function by myself
  '''
  import stat
  MODE = os.stat(path).st_mode
  #返回真假值
  return stat.S_ISDIR(MODE)
if __name__== "__main__":
  change_dir()
  show_filesOfdir('''/root''')
  printaccess('/etc/passwd')
  print isDIR('/etc')

希望本文所述對大家的Python程序設計有所幫助。

延伸 · 閱讀

精彩推薦
372
主站蜘蛛池模板: 中日韩黄色大片 | 日韩久久综合 | 中文久久久久 | 国产精品无码久久久久 | 国产区第一页 | 日韩激情一区二区 | 欧美福利在线 | 久久成人精品视频 | 亚洲一区二区三区在线免费观看 | 久久久亚洲国产美女国产盗摄 | 激情综合五月天 | 中文在线观看视频 | 久草视频在线播放 | 一级黄色片欧美 | 日韩第一视频 | 在线中文一区 | 久久久婷婷一区二区三区不卡 | 可以免费看黄色的网站 | 国产在线不卡一区 | 欧美资源在线 | 国产黄色一级片视频 | 亚洲成人中文字幕 | 欧美日韩精品一区二区三区 | 国产第一亚洲 | 午夜视频在线播放 | 亚洲精品久久久久中文字幕欢迎你 | www.日韩系列 | 精品国产一二三区 | 综合自拍| 久久久久亚洲精品 | 久久久无码精品亚洲日韩按摩 | 欧美电影在线观看 | 成人区精品一区二区婷婷 | 中文字幕人成乱码在线观看 | 亚洲一区二区三区在线免费观看 | 国产成人一区 | 欧美国产91 | 久久aⅴ乱码一区二区三区 一区二区精品视频 | 欧美一级片在线 | 精品国产乱码久久久久久牛牛 | 亚洲男人网 |