python-IO-4.13

本文介绍Python中OS模块的基本操作,包括查看当前目录、创建及删除目录、重命名和删除文件等,并深入探讨了RE模块的正则表达式应用,如匹配、搜索和替换字符串的方法。

os查看当前目录的绝对路径: os.path.abspath('.')

os在某个目录下创建一个新的目录:os.path.join('e:\\diro','testdir') ——>os.mkdir('e:\\diro\\testdir')

删除一个目录:m     os.rmdir('e:\\diro\\testdir')

对文件重命名: os.rename('test.txt','test'.py)

删除文件:os.remove('test.py')

python通过标准库的re模块支持正则表达式(RE)

re.match(pattern,string,flags=0)  (匹配成功返回匹配对象,否则返回None)

  pattern:匹配的正则表达式;string:要匹配的字符串;flags:标志位,用于控制正则表达式的控制方式,如:是否区分大小写,多行匹配等

re.search(pattern,string,flags=0) (扫描整个字符串并返回第一个成功的匹配,匹配成功返回匹配对象,否则返回None)

pattern,string,flags作用同上

re.match与re.search的区别:re.search 扫描整个字符串并返回第一个成功的匹配。

注:序列化导包(import pickle),在JSON使用时也要导入包(import json);re导包(import re)

group与gruops



groups()以tuple格式返回匹配对象

re.sub(pattern,repl,string,count=0,flags=0) (用于替换字符串中匹配项)

    pattern:正则中的模式字符串。

    repl:替换的字符串,也可为一个函数

   string:要被查找替换的原始字符串

   count:模式匹配后替换的最大次数,默认0,替换所有匹配。


正则表达式可包含一些可选标志修饰符来控制匹配模式

多个标志可通过按位OR(|)来指定。如re.I|re.M被设置成I和M的标志。


#异步相关依赖 aiofiles==24.1.0 aiohappyeyeballs==2.4.6 aiohttp==3.11.12 aioprometheus==23.12.0 aiosignal==1.3.2 async-timeout==4.0.3 frozenlist==1.5.0 multidict==6.1.0 yarl==1.18.3 #数据处理与可视化 altair==4.2.2 contourpy==1.3.1 cycler==0.12.1 matplotlib==3.10.0 numpy==1.24.4 pandas==1.5.3 pillow==10.4.0 pyparsing==3.2.1 scipy==1.15.3 seaborn==0.13.2 tabulate==0.9.0 #Web 框架与接口 anyio==4.8.0 fastapi==0.109.2 fastapi-mcp==0.3.4 fastjsonschema==2.21.1 h11==0.14.0 httpcore==1.0.7 httptools==0.6.4 httpx==0.27.2 httpx-sse==0.4.0 pydantic==2.7.1 pydantic_core==2.18.4 pydantic-extra-types==2.10.2 pydantic-settings==2.9.1 starlette>=0.36.3,<0.37.0 sse-starlette==1.8.2 uvicorn==0.34.0 websockets==14.2 #LangChain 生态(100% 无冲突,Python 3.10 验证通过) #核心调整:降低 langchain 主版本至 0.2.16,同步匹配子库版本,避免 core 版本交叉冲突 langchain==0.2.16 # 降至 0.2.16(依赖 core≥0.2.36<0.3.0,兼容范围更广) #langchain-community==0.2.1 # 与 langchain==0.2.16 匹配,依赖 core≥0.2.36<0.3.0 langchain-core==0.2.1 # 保持 0.2.x 最高稳定版,同时满足所有子库要求 langchain-experimental==0.0.64 # 降至 0.0.64(0.0.65 依赖更高 core,0.0.64 兼容 core≥0.2.36) langchain-openai==0.2.1 # 降至 0.2.4(依赖 core≥0.2.36<0.3.0,与 core==0.2.43 完美兼容) langchain-text-splitters==0.2.1 # 降至 0.2.3(0.2.4 依赖 core≥0.2.43,此处保持版本统一) langchainhub==0.1.19 # 无 core 版本冲突,保持不变 langsmith==0.1.147 # 无 core 版本冲突,保持不变 #文档处理与解析 beautifulsoup4==4.13.3 docx2txt==0.8 et_xmlfile==2.0.0 favicon==0.7.0 filetype==1.2.0 lxml==5.3.1 markdown-it-py==3.0.0 markdownify==0.14.1 markdownlit==0.0.7 openpyxl==3.1.4 pydub==0.25.1 PyMuPDF==1.23.26 PyMuPDFb==1.23.22 pypdf==5.3.0 python-docx==1.1.2 soupsieve==2.6 unstructured==0.11.8 unstructured-client==0.25.9 #模型与推理相关(适配 Python 3.10) faiss-cpu==1.7.4 huggingface-hub==0.32.1 modelscope==1.18.0 onnxruntime==1.15.1 openai==1.61.1 safetensors==0.5.3 tiktoken==0.8.0 torch==2.7.0 torchvision==0.22.0 xinference-client==1.6.0 xoscar==0.7.2 #数据库与存储 PyMySQL==1.1.1 pyarrow==19.0.0 SQLAlchemy==2.0.38 #工具类与辅助依赖(Python 3.10 兼容) annotated-types==0.7.0 backoff==2.2.1 backports.tarfile==1.2.0 bcrypt==4.3.0 blinker==1.9.0 Brotli==1.1.0 build==1.2.2.post1 CacheControl==0.14.2 cachetools==5.5.1 certifi==2025.1.31 cffi==1.17.1 chardet==5.2.0 charset-normalizer==3.4.1 cleo==2.1.0 click==8.1.8 cloudpickle==3.1.1 colorama==0.4.6 coloredlogs==15.0.1 crashtest==0.4.1 cryptography==44.0.0 dataclasses-json==0.6.7 deepdiff==8.2.0 deprecation==2.1.0 distlib==0.3.9 distro==1.9.0 dnspython==2.7.0 dulwich==0.22.7 ecdsa==0.19.1 elastic-transport==8.17.0 elasticsearch==8.4.3 email_validator==2.2.0 emoji==2.14.1 entrypoints==0.4 exceptiongroup==1.2.2 Faker==36.1.0 ffmpy==0.5.0 filelock==3.17.0 flatbuffers==25.2.10 fonttools==4.56.0 fsspec==2025.5.1 gitdb==4.0.12 GitPython==3.1.44 greenlet==3.1.1 groovy==0.1.2 h2==4.2.0 hpack==4.1.0 htbuilder==0.9.0 humanfriendly==10.0 hyperframe==6.1.0 idna==3.10 importlib_metadata==8.6.1 installer==0.7.0 itsdangerous==2.2.0 jaraco.classes==3.4.0 jaraco.context==6.0.1 jaraco.functools==4.1.0 jieba==0.42.1 Jinja2==3.1.5 jiter==0.8.2 joblib==1.4.2 jsonpatch==1.33 jsonpath-python==1.0.6 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 keyring==25.6.0 kiwisolver==1.4.8 langdetect==1.0.9 loguru==0.7.3 Markdown==3.7 MarkupSafe==3.0.2 marshmallow==3.26.1 mcp==1.9.0 mdurl==0.1.2 memoization==0.4.0 more-itertools==10.6.0 mpmath==1.3.0 msgpack==1.1.0 mypy-extensions==1.0.0 nest-asyncio==1.6.0 networkx==3.1 nltk==3.8.1 numexpr==2.10.2 nvidia-ml-py==12.575.51 opencv-python==4.10.0.84 orderly-set==5.3.0 orjson==3.10.15 packaging==23.2 passlib==1.7.4 pathlib==1.0.1 pika==1.3.2 pip==25.0 pkginfo==1.12.0 platformdirs==4.3.6 poetry==2.0.1 poetry-core==2.0.1 prometheus_client==0.21.1 propcache==0.2.1 protobuf==4.25.6 psutil==7.0.0 pyahocorasick==2.1.0 pyasn1==0.4.8 pyclipper==1.3.0.post6 pycparser==2.22 pydeck==0.9.1 Pygments==2.19.1 PyJWT==2.8.0 pymdown-extensions==10.14.3 pynvml==12.0.0 pypandoc==1.15 pyproject_hooks==1.2.0 pyreadline3==3.5.4 python-dateutil==2.9.0.post0 python-decouple==3.8 python-dotenv==1.0.1 python-iso639==2025.2.8 python-jose==3.4.0 python-magic==0.4.27 python-multipart==0.0.20 pytz==2025.1 PyYAML==6.0.2 quantile-python==1.1 rank-bm25==0.2.2 RapidFuzz==3.12.1 rapidocr-onnxruntime==1.3.25 referencing==0.36.2 regex==2024.11.6 requests==2.31.0 requests-toolbelt==1.0.0 rich==13.9.4 rpds-py==0.22.0 rsa==4.9.1 ruamel.yaml==0.18.6 ruamel.yaml.clib==0.2.12 ruff==0.11.11 semantic-version==2.10.0 setproctitle==1.3.6 setuptools==75.8.0 shapely==2.0.7 shellingham==1.5.4 simplejson==3.19.3 six==1.17.0 smmap==5.0.2 sniffio==1.3.1 socksio==1.0.0 st-annotated-text==4.0.2 streamlit==1.34.0 streamlit-aggrid==1.0.5 streamlit-antd-components==0.3.1 streamlit-camera-input-live==0.2.0 streamlit-card==1.0.2 streamlit-chatbox==1.1.8 streamlit-embedcode==0.1.2 streamlit-extras==0.4.2 streamlit-faker==0.0.3 streamlit-feedback==0.1.4 streamlit-image-coordinates==0.1.9 streamlit-keyup==0.3.0 streamlit_modal==0.1.0 streamlit-option-menu==0.3.12 streamlit-paste-button==0.1.2 streamlit-toggle-switch==1.0.2 streamlit-vertical-slider==2.5.5 strsimpy==0.2.1 sympy==1.13.3 tblib==3.1.0 tenacity==8.5.0 toml==0.10.2 tomli==2.2.1 tomlkit==0.13.2 toolz==1.0.0 tornado==6.4.2 tqdm==4.67.1 trove-classifiers==2025.1.15.22 typer==0.15.4 types-requests==2.32.0.20241016 typing_extensions==4.12.2 typing-inspect==0.9.0 typing-inspection==0.4.0 tzdata==2025.1 ujson==5.10.0 urllib3==2.3.0 validators==0.34.0 virtualenv==20.29.2 watchdog==6.0.0 watchfiles==1.0.4 win32_setctime==1.2.0 wrapt==1.17.2 zipp==3.21.0 环境 liunx Python 3.10.0 安装依赖 ERROR: Cannot install -r requirements.txt (line 35) and pydantic_core==2.18.4 because these package versions have conflicting dependencies. The conflict is caused by: The user requested pydantic_core==2.18.4 pydantic 2.7.1 depends on pydantic-core==2.18.2 To fix this you could try to: 1. loosen the range of package versions you've specified 2. remove package versions to allow pip to attempt to solve the dependency conflict ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
09-11
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值