日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python中的loop啥意思_python怎么进行loop

發(fā)布時(shí)間:2024/9/18 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中的loop啥意思_python怎么进行loop 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

匿名用戶

1級(jí)

2018-09-07 回答

#!\urs\bin\env?python

#encoding:utf-8???????#設(shè)置編碼方式

import?os

import?re

class?loop_file:

def?__init__(self,?root_dir,?short_exclude=[],?long_exclude=[],?file_extend=[]):

self.root_dir?=?root_dir

self.short_exclude?=?short_exclude

self.long_exclude?=?long_exclude

self.file_extend?=?file_extend

def?__del__(self):

pass

def?start(self,?func):

self.func?=?func

return?self.loop_file(self.root_dir)

def?loop_file(self,?root_dir):

t_sum?=?[]

sub_gen?=?os.listdir(root_dir)

for?sub?in?sub_gen:

is_exclude?=?False

for?extends?in?self.short_exclude:??##在不檢查文件、目錄范圍中

if?extends?in?sub:??????????????##包含特定內(nèi)容

is_exclude?=?True

break

if?re.search(extends,?sub):?????##匹配指定正則

is_exclude?=?True

break

if?is_exclude:

continue

abs_path?=?os.path.join(root_dir,?sub)

is_exclude?=?False

for?exclude?in?self.long_exclude:

if?exclude?==?abs_path[-len(exclude):]:

is_exclude?=?True

break

if?is_exclude:

continue

if?os.path.isdir(abs_path):

t_sum.extend(self.loop_file(abs_path))

elif?os.path.isfile(abs_path):

if?not?"."?+?abs_path.rsplit(".",?1)[1]?in?self.file_extend:??##不在后綴名?檢查范圍中

continue

t_sum.append(self.func(abs_path))

return?t_sum

if?'__main__'==__name__:

root_dir?=?r'D:\harness\newshoppingcart\testcase\promo\single_promo'

short_exclude?=?['.svn',?'.*_new.rb']?????###不包含檢查的短目錄、文件

long_exclude?=?[]?????????????????????????###不包含檢查的長目錄、文件

file_extend?=?['.rb']?????????????????????###包含檢查的文件類型

lf?=?loop_file(root_dir,?short_exclude,?long_exclude,?file_extend)

for?f?in?lf.start(lambda?f:?f):

print?f

總結(jié)

以上是生活随笔為你收集整理的python中的loop啥意思_python怎么进行loop的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。