#coding:utf-8 #批量修改文件名 import os import re import datetime re_st = r'(\d+)\+\s?\((\d+)\)' #用于匹配旧的文件名,需含分组 re_match_old_file_name = re.compile(re_st) #要修改的目录 WORKING_PATH = r'F:\Gallery' #---------------------------------------------------------------------- def rename_fomat(name): """ 文件重命名格式组织模块(一般修改这里就可以了) NOTE:返回类型必须是unicode """ if name: re_rn = re_match_old_file_name.findall(name) if re_rn and re_rn != []: re_rn = re_rn[0] num = int(re_rn) new_nm = u'NO.%04d' % ( num) return new_nm #---------------------------------------------------------------------- def logs(error): """ 错误记录 """ log = '' LOG_FILE = open(r'./log.txt', 'a') live_info =""" ========== Time : %s title : %s Path : %s ========== """ % ( datetime.datetime.now(), str(error['title']), str(error['index']), ) log += live_info errors = error['error_paths'] for item in errors: item = '%s\n' % item log += item log = log.encode('utf-8') try: LOG_FILE.write(log) except IOError: print u'写入日志失败' finally: LOG_FILE.close() #---------------------------------------------------------------------- def rename(old, new): """ 文件重命名模块 return: 0:rename success 1:the new path is exists -1:rename failed """ if not os.path.exists(new): try: os.renames(old, new) return 0 except IOError: print 'path error:', new return -1 else: return 1 #---------------------------------------------------------------------- def get_dirs(path): """ 获取目录列表 """ if os.path.exists(path): return os.listdir(path) else: return -1 #---------------------------------------------------------------------- def get_input_result(word, choice): """ 获取正确的输入结果 """ correct_result = set(choice) word = '===%s?\n[in]:' % (word) while True: in_choice = raw_input(word) if in_choice in correct_result: return in_choice #---------------------------------------------------------------------- def batch_rename(index, dirs = []): """ 批量修改文件 """ index = unicode(index) errors = [] if dirs == []: dirs = get_dirs(path = index) if dirs and dirs != []: for item in dirs: item = unicode(item) new_name = rename_fomat(item) if new_name : old_pt = u'%s\\%s'% (index, item) new_pt = u'%s\\%s'% (index, new_name) res_rn = rename(old_pt, new_pt) if res_rn != 0: errors.append(item) else: errors.append(item) if errors and errors != []: print 'Rename Failed:' logs({ 'index': index, 'title': 'Rename Failed' , 'error_paths': errors, }) for i, item in enumerate(errors): print item, '|', if i % 5 == 4: print '' print '' else: return -1 #---------------------------------------------------------------------- def batch_rename_test(index): """ 测试 返回过滤结果 """ index = unicode(index) errors = [] correct = [] dirs = get_dirs(path = index) if dirs and dirs != []: for x, item in enumerate(dirs): item = unicode(item) new_name = rename_fomat(item) if new_name : correct.append(item) old_pt = u'%s\\%s'% (index, item) new_pt = u'%s\\%s'% (index, new_name) print '[%d]O: %s' % ( x + 1, old_pt) print '[%d]N: %s' % ( x + 1, new_pt) else: errors.append(item) if errors and errors != []: print 'Not Match:' logs({ 'index': index, 'title': 'Not Match', 'error_paths': errors, }) for i, item in enumerate(errors): print item, '|', if i % 5 == 4: print '' print '' return correct #---------------------------------------------------------------------- def manage(index): """ 程序组织块 """ file_filter = batch_rename_test(index) do_choice = get_input_result( word = 'Do with this(y / n)', choice = ['y', 'n'] ) if do_choice == 'y': batch_rename(index, dirs= file_filter) print 'Finished !' if __name__ == '__main__': path = WORKING_PATH manage(index = path)

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造

数组的同质性对性能的影响是双重的:1)同质性允许编译器优化内存访问,提高性能;2)但限制了类型多样性,可能导致效率低下。总之,选择合适的数据结构至关重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,内存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver CS6
视觉化网页开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。