本文整理汇总了Python中mod_unicode.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_files
def get_files(path=getcwd()):
"""path=getcwd() ---> generateur(path) ---> files in path"""
if path == "" : path = getcwd()
path = decode(path).replace("\\","/")
if path[-1] != "/" : path += "/"
files = listdir(path)
for i in files:
i = decode(i)
if is_file(path + i): yield i
示例2: get_dirs
def get_dirs(path=getcwd()):
"""path=getcwd() ---> generateur(dirs)"""
if path == "" : path = getcwd()
path = decode(path).replace("\\","/")
if path[-1] != "/" : path += "/"
dirs = listdir(path)
path_start = getcwd()
for i in dirs:
i = decode(i)
if is_dir(path + i): yield i + "/"
示例3: get_paths2
def get_paths2(path=getcwd()):
"""generateur renvoyant toutes les urls filles du dossier parent"""
if path == "" : path = getcwd()
path = decode(path).replace("\\","/")
if path[-1] != "/" : path += "/"
yield path
for i in get_dirs(path):
try :
i = decode(i)
for p in get_paths2(path+i) : yield p
except :
yield "erreur"
示例4: get_allpaths
def get_allpaths(path=getcwd()):
"""retourne toutes les urls du dossier parent (les urls peuvent etre en plusieurs exemplaires)"""
if path == "" : path = getcwd()
path = decode(path).replace("\\","/")
if path[-1] != "/" : path += "/"
list_path = []
list_dossiers = [path]
for i in get_dirs(path):
i = path + decode(i)
list_dossiers.append(i)
recup=get_allpaths(i)
if recup != []:
for x in recup: list_dossiers.append(decode(x))
return list_dossiers
示例5: get_paths
def get_paths(path=getcwd()):
"""version ameliore de "get_allpaths(), les urls ne sont qu'en un seul exemplaire"""
if path == "" : path = getcwd()
path = decode(path)
p = get_allpaths(path)
paths = []
for i in p :
if i not in paths : paths.append(i)
return paths
示例6: get_name
def get_name(name, with_ext=True):
name = decode(name).replace("\\","/")
if name:
if name[-1] == "/": name = name[ : -1]
name = name.split("/")[-1]
if with_ext: return name
else:
name = name.split('.')
if not name[0]: return '.'.join(name)
else: return name[0]
示例7: get_path
def get_path(name):
if name:
if name != "/":
name = decode(name)
name = name.replace("\\","/")
if name[-1] == "/": name = name[:-1]
path = "/".join(name.split("/")[:-1])
if name[0] == "/" and not path: return "/"
return path+"/"*bool(path)
else: return "/"
else: return ""
示例8: supprdir
def supprdir(dossier):
"""supprime un dossier, tous ses sous-dossiers et tous les fichiers contenus"""
dossier = decode(dossier)
if dossier[-1] != "/" : dossier += "/"
try:
dirfile = get_dirfile(dossier)
for f in dirfile[1]: remove(dossier+f)
for d in dirfile[0]: supprdir(dossier+d)
rmdir(dossier)
return ""
except Exception, err: return err[-1]
示例9: copydir
def copydir(dossier_original,dossier_copy):
"""copie un dossier, tous ses sous-dossiers et tous les fichiers contenus"""
dossier_original = decode(dossier_original)
dossier_copy = decode(dossier_copy)
if dossier_original[-1] != "/": dossier_original += "/"
if dossier_copy[-1] != "/": dossier_copy += "/"
try:
dossier_copy = name_exists(dossier_copy+get_name(dossier_original[:-1]))
try: mkdir(dossier_copy)
except Exception, err: print err
dirfile = get_dirfile(dossier_original)
for d in dirfile[0]:
copydir(dossier_original+d,dossier_copy)
for f in dirfile[1]:
file(dossier_original+f).copy(dossier_copy+f, true)
return ""
except Exception, err: return err[-1]
示例10: get_allfiles2
def get_allfiles2(path=getcwd()):
"""generateur renvoyant toutes les paths filles du dossier parent"""
if path == "" : path = getcwd()
path = decode(path).replace("\\","/")
if path[-1] != "/" : path += "/"
dirfile = get_dirfile(path)
yield (path,dirfile[1])
for i in dirfile[0]:
try:
for d,f in get_allfiles2(path+i):yield (d,f)
except:
yield ("erreur",[])
示例11: get_dirfile
def get_dirfile(path=getcwd()):
"""path=getcwd() ---> tuple(dirs,files)"""
if path == "" : path = getcwd()
path = decode(path)
if path[-1] != "/" : path += "/"
dos = listdir(path)
fichier = []
dossier = []
for i in dos :
if is_file(path + i): fichier.append(i)
elif is_dir(path + i): dossier.append(i)
return [dossier,fichier]
示例12: try_name
def try_name(name):
name = decode(name)
path = get_path(name)
ext = "."+get_ext(name)
if ext == ".": ext = ""
name = get_name(name)
if ext: name = name[:-len(ext)]
if path: liste = listdir(path)
else: liste = listdir(getcwd())
erreur = 0
temp = name[:]+ext
while temp in liste:
erreur += 1
temp = name + " ("+str(erreur)+")"+ext
return path+temp
示例13: try_file
def try_file(name):
name = decode(name)
path = get_path(name)
name = get_name(name)
ext = "." + get_ext(name)
if ext != ".": name = name[:-len(ext)]
else: ext = ""
erreur = 0
temp_name = name + ext
while file_exists(path + temp_name):
erreur += 1
temp_name = name+(" ("+str(erreur)+")")+ext
return path+temp_name
示例14: get_ext
def get_ext(name):
name = get_name(decode(name))
temp = name.split(".")[-1]
if temp != name: return temp
else: return ""
示例15: get_name
def get_name(name):
name = decode(name).replace("\\","/")
if name:
if name[-1] == "/": name = name[ : -1]
return name.split("/")[-1]