ikkhksvu 发表于 2024-8-17 23:35:52

做后端,php后端强,还是python后端强


    <h1 style="color: black; text-align: left; margin-bottom: 10px;">是php后端强?还是python后端强?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">是php后端强?还是python后端强?<span style="color: black;">做为</span>初学者的话若是要学习后端<span style="color: black;">研发</span>和运维,二选一的话,应该<span style="color: black;">选取</span>哪个方向?请说明你的理由?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">还是Python更强<span style="color: black;">有些</span>,从这些年两种语言的发展以及火热程度上<span style="color: black;">亦</span>能看出来,Python<span style="color: black;">已然</span>全面碾压php了,虽然可能会有<span style="color: black;">非常多</span>人跳出<span style="color: black;">来讲</span>php是最好的语言,<span style="color: black;">然则</span><span style="color: black;">非常多</span>时候,承认<span style="color: black;">亦</span>是一种进步!</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">为何</span>要学习Python?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在学习Python之前,你不要担心自己没<span style="color: black;">基本</span>或“脑子笨”,我始终认为,只要你想学并为之<span style="color: black;">奋斗</span>,就能学好,就能用Python去做<span style="color: black;">非常多</span>事情。在这个喧嚣的时代,<span style="color: black;">非常多</span>技术或概念会<span style="color: black;">持续</span>兴起,我<span style="color: black;">期盼</span>你能沉下心来去学习,不要急于求成,一步一个脚印。当你把某个技术学好、学精后,还是能做<span style="color: black;">有些</span>事情的,<span style="color: black;">乃至</span>能找到<span style="color: black;">爱好</span>的工作或完成实践项目。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">程序语言<span style="color: black;">无</span>最好,<span style="color: black;">仅有</span>最适合。<span style="color: black;">做为</span>一名初学者,我非常<span style="color: black;">举荐</span>你学习Python,为啥?一方面是<span style="color: black;">由于</span>它<span style="color: black;">拥有</span>语法清晰、代码友好、易读性高的特点,<span style="color: black;">同期</span>Python<span style="color: black;">持有</span>强大的第三方库函数,<span style="color: black;">包含</span>网络爬取、数据分析、可视化、人工智能等;另一方面Python既是一门解释性编程语言,又是面向对象的语言,其操作性和可移植性高,被广泛应用于数据挖掘、信息采集、人工智能、网络安全、自动化测试等<span style="color: black;">行业</span>。<span style="color: black;">乃至</span>,<span style="color: black;">非常多</span>小学生、高中课程和计算机二级<span style="color: black;">亦</span>都<span style="color: black;">持续</span><span style="color: black;">增多</span>了Python。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/1992520f93b14d3c9568e31de73d7de6~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=LjDvpJOE6eOUyCGHdWSOU8uk%2Br0%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Python<span style="color: black;">优良</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Python最大的<span style="color: black;">优良</span>在于效率。有时候程序员或科研工作者的效率比<span style="color: black;">设备</span>的效率更重要,<span style="color: black;">针对</span><span style="color: black;">非常多</span><span style="color: black;">繁杂</span>性的功能,<span style="color: black;">运用</span>更加清晰的语言能给程序减少<span style="color: black;">更加多</span>的<span style="color: black;">包袱</span>,从而大大<span style="color: black;">加强</span>程序的质量,其易学性和扩展性<span style="color: black;">亦</span>能让新手<span style="color: black;">火速</span>上手。虽然Python底层运行速度要比C语言慢,但Python清晰的结构能解放程序员的时间,<span style="color: black;">同期</span>很方便的和其他编程语言代码(如C语言)融合在<span style="color: black;">一块</span>。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">所以,从来<span style="color: black;">无</span>一种编程语言<span style="color: black;">能够</span>像Python<span style="color: black;">这般</span><span style="color: black;">同期</span>扎根在这么多<span style="color: black;">行业</span>,并且Python支持跨平台操作,<span style="color: black;">亦</span>支持开源,<span style="color: black;">持有</span>强大的第三方库。尤其随着人工智能的<span style="color: black;">连续</span>火热,Python在IEEE近几年发布的最热门语言中多次排名<span style="color: black;">第1</span>,越来越多的程序<span style="color: black;">兴趣</span>者、科技关注者<span style="color: black;">亦</span>都<span style="color: black;">起始</span>学习Python。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/a75c6d2b3d774eb781ff320cdbefb0b5~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=y6AQUud2T2aSHVyRtdL5P5dEuWg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">编程环境配置</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Python是一种解释性语言,它<span style="color: black;">运用</span>解释器来解释和执行代码,这对用户<span style="color: black;">来讲</span>省去了C或C++之类语言的编译<span style="color: black;">过程</span>,直接从源代码<span style="color: black;">就可</span>运行,<span style="color: black;">因此呢</span><span style="color: black;">更易</span>编写和调试。工欲善其事,必先利其器。在学习Python编程之前,先让<span style="color: black;">咱们</span>安装好相应的工具并对编程环境进行设置。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>进入Python官方下载频道</p>https://www.python.org/downloads,点击“Download Python 3.11.2”按钮进入下载页面(此数字会随着版本的升级而改变)。找到适合自己系统的下载链接,<span style="color: black;">例如</span>笔者为Windows的64位系统,<span style="color: black;">因此</span><span style="color: black;">选取</span>下载了“Windows installer (64-bit)”。双击下载所得的EXE可执行文件<span style="color: black;">起步</span>Python安装向导。
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/c8e0f50a18f7444ab3f59a6a6acab62c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=mWlRhgxSyGc%2BtPH%2B0X0WfYF3TpM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">勾选“Add python.exe to PATH”项,<span style="color: black;">这般</span>就<span style="color: black;">不消</span>后期手动将Python程序添加到系统路径中了。点击“Install Now”<span style="color: black;">就可</span>自动安装。<span style="color: black;">倘若</span>不<span style="color: black;">期盼</span>安装到默认的C盘,<span style="color: black;">能够</span>点击“Customize installation”自定义安装项,<span style="color: black;">按照</span>向导提示一步步安装。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/d2ad6e0c278a4ddda1deadbed17aa6d0~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=OUD60x4MFjk8d%2BC5beZXSf%2BbQjA%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">做为</span>初学者<span style="color: black;">选取</span>默认安装选项<span style="color: black;">就可</span>。安装成功后,<span style="color: black;">针对</span>Windows系统将会有一个“Disable path length limit(禁用路径长度限制)”的提示,这是<span style="color: black;">由于</span>Windows系统能够处理的文件路径长度有<span style="color: black;">必定</span>的限制。点击禁用这一限制<span style="color: black;">能够</span>避免处理长文件路径时<span style="color: black;">显现</span>的调试问题,<span style="color: black;">不外</span>这<span style="color: black;">亦</span>可能<span style="color: black;">引起</span>与旧版本Windows 10的兼容性问题。<span style="color: black;">针对</span><span style="color: black;">咱们</span>初学者<span style="color: black;">来讲</span><span style="color: black;">能够</span>暂时跳过此选项,<span style="color: black;">由于</span>以后有<span style="color: black;">必须</span>时还<span style="color: black;">能够</span>修改注册表来<span style="color: black;">处理</span>。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/caef6049f9304d34990b3d0c2cd3dcad~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=yE3wMPT5Ju0Y3ZvssmuzfQiSsrg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">点击“Close”按钮关闭安装向导。<span style="color: black;">此刻</span><span style="color: black;">咱们</span>测试Python<span style="color: black;">是不是</span>安装成功。按Win+R键调出运行对话框,输入“cmd”后按回车键打开命令提示符窗口,<span style="color: black;">而后</span>输入“python”并按回车,<span style="color: black;">倘若</span>能够<span style="color: black;">表示</span>出Python版本等信息内容,并且提示符变<span style="color: black;">成为了</span>“&gt;&gt;&gt;”,则<span style="color: black;">暗示</span>安装成功了。此时可输入一行测试代码:</span></p><span style="color: black;">print</span>(<span style="color: black;">"嗨,欢迎来到Python世界!"</span>)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">按回车键执行,<span style="color: black;">就可</span>得到“嗨,欢迎来到Python世界!”的<span style="color: black;">表示</span>信息。几乎每种编程语言教程中都会展示一下“hello, world!”程序,虽然很俗套,但不得不说Python的实现是如此的简单。紧接着执行代码“exit()”退出Python环境,完成此一<span style="color: black;">周期</span>的测试。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/e99dcdf1d8bf42e59d6cfe93aca6fa01~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=JBHaM4FtISckFwypsK4npRHWwzI%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">命令提示符的界面过于简陋,<span style="color: black;">咱们</span><span style="color: black;">能够</span>试试Python自带的IDLE交互式<span style="color: black;">研发</span>环境。点击系统“<span style="color: black;">起始</span>”按钮,在<span style="color: black;">起始</span>菜单顶部的<span style="color: black;">近期</span>添加中就<span style="color: black;">能够</span>看到“IDLE(Pyton 3.11 64-bit)”程序了,点击<span style="color: black;">就可</span>打开。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">IDLE<span style="color: black;">经过</span><span style="color: black;">区别</span>的颜色区分代码及执行结果,清晰明了。尤其方便的是,当<span style="color: black;">咱们</span>输入某个函数时,它会智能<span style="color: black;">表示</span>参数提示,辅助<span style="color: black;">咱们</span>输入代码,非常方便。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7b2e856163724b27997c2e455231fb76~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=b6kq%2FhqvgCT%2BTAizSFMcDjm0xKw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">PyCharm <span style="color: black;">运用</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">IDE是Integrated Development Environment的缩写,意为集成<span style="color: black;">研发</span>环境,<span style="color: black;">重点</span>用来辅助程序<span style="color: black;">研发</span>。Python并不<span style="color: black;">必定</span><span style="color: black;">必须</span>IDE,<span style="color: black;">由于</span>它<span style="color: black;">能够</span>在任何文本编辑器中编写并从命令行运行。<span style="color: black;">然则</span>IDE<span style="color: black;">能够</span><span style="color: black;">供给</span>许多辅助功能,例如代码调试、智能完成和语法高亮<span style="color: black;">表示</span>等。<span style="color: black;">另一</span>,IDE还<span style="color: black;">能够</span><span style="color: black;">供给</span>重构、代码导航和项目管理等工具,这些工具<span style="color: black;">能够</span><span style="color: black;">帮忙</span><span style="color: black;">咱们</span>更快、更<span style="color: black;">容易</span>地编写Python代码,并且<span style="color: black;">能够</span>更<span style="color: black;">容易</span>地调试和<span style="color: black;">守护</span>代码。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Python<span style="color: black;">研发</span>人员有多种IDE可用,相对<span style="color: black;">来讲</span>PyCharm是个非常不错的<span style="color: black;">选取</span>,它<span style="color: black;">能够</span>让Python<span style="color: black;">研发</span>过程变得更加<span style="color: black;">容易</span>和<span style="color: black;">有效</span>。值得<span style="color: black;">叫作</span>道的是,PyCharm<span style="color: black;">供给</span>一个强大的社区版本,可<span style="color: black;">以避免</span>费<span style="color: black;">运用</span>,并且<span style="color: black;">能够</span>在网上<span style="color: black;">得到</span>免费支持。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>进入PyCharm主页</p>https://www.jetbrains.com/pycharm,点击“DOWNLOAD”按钮进入下载频道,在“Windows”选项卡下<span style="color: black;">能够</span>看到“Professional(专业版)”和“Community(社区版)”两种版本,其中社区版是免费的,点击其下的“Download”按钮下载<span style="color: black;">就可</span>。比较而言,社区版缺少对科学工具、网站<span style="color: black;">研发</span>、Web框架、远程<span style="color: black;">研发</span>、数据库等的支持,<span style="color: black;">不外</span><span style="color: black;">针对</span>一个初学者<span style="color: black;">来讲</span>,这些影响不大。
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/967af00c985d4a01a6c530960d87e5ab~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=8XwRNvtzFgD7sLOSat2H46r8kz8%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">学习大纲</h1>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/19be4fea590e4847b12634593b887b3b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=t6jEeUuqdZjM2rk9aEc13dq3A6A%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">基本语法</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">针对</span>底层<span style="color: black;">基本</span>,肯定是<span style="color: black;">把握</span>得越多、越<span style="color: black;">牢靠</span>越好~</span></p><span style="color: black;">环境搭建</span><span style="color: black;">Python安装</span><span style="color: black;"><span style="color: black;">研发</span>工具 - PyCharm,VS Code,Jupyter Notebook</span><span style="color: black;">变量</span><span style="color: black;">定义变量</span><span style="color: black;">命名规则</span><span style="color: black;">基本数据类型</span><span style="color: black;">类型转换</span><span style="color: black;">运算符和表达式</span><span style="color: black;">基本数据结构</span><span style="color: black;">字符串</span><span style="color: black;">列表</span><span style="color: black;">字典</span><span style="color: black;">集合</span><span style="color: black;">元组</span><span style="color: black;">流程<span style="color: black;">掌控</span></span><span style="color: black;"><span style="color: black;">要求</span></span><span style="color: black;">循环</span><span style="color: black;">函数</span><span style="color: black;">调用函数</span><span style="color: black;">定义函数</span><span style="color: black;">函数参数</span><span style="color: black;">lambda 函数</span><span style="color: black;"><span style="color: black;">功效</span>域</span><span style="color: black;">重要内置函数</span><span style="color: black;">函数式编程</span><span style="color: black;">面向对象编程</span><span style="color: black;">类和对象</span><span style="color: black;"><span style="color: black;">拜访</span>限制</span><span style="color: black;">装饰器</span><span style="color: black;">封装</span><span style="color: black;">继承</span><span style="color: black;">多态</span><span style="color: black;">类<span style="color: black;">办法</span></span><span style="color: black;">实例<span style="color: black;">办法</span></span><span style="color: black;">静态<span style="color: black;">办法</span></span><span style="color: black;">反射</span><span style="color: black;">模块</span><span style="color: black;"><span style="color: black;">运用</span>模块</span><span style="color: black;">安装模块</span><span style="color: black;">常用模块</span><span style="color: black;"><span style="color: black;">反常</span>调试测试</span><span style="color: black;"><span style="color: black;">反常</span><span style="color: black;">捕捉</span></span><span style="color: black;">try...else...finally 结构</span><span style="color: black;">自定义<span style="color: black;">反常</span></span><span style="color: black;">调试</span><span style="color: black;">单元测试</span><span style="color: black;">文档测试</span><span style="color: black;">进阶知识</span><span style="color: black;">正则表达式</span><span style="color: black;">数据库编程知识</span><span style="color: black;">并发编程</span><span style="color: black;">网络编程</span><span style="color: black;">IO 编程</span><span style="color: black;">图形界面</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Web <span style="color: black;">研发</span></h1><span style="color: black;">Web <span style="color: black;">基本</span></span><span style="color: black;">HTTP <span style="color: black;">基本</span></span><span style="color: black;">HTML <span style="color: black;">基本</span></span><span style="color: black;">CSS <span style="color: black;">基本</span></span><span style="color: black;">JavaScript <span style="color: black;">基本</span></span><span style="color: black;">WSGI</span><span style="color: black;">Restful API</span><span style="color: black;">Flask</span><span style="color: black;">脚手架</span><span style="color: black;">蓝图</span><span style="color: black;">Django</span><span style="color: black;">MVT 模式</span><span style="color: black;">模板</span><span style="color: black;">模型</span><span style="color: black;">视图</span><span style="color: black;">路由</span><span style="color: black;">中间件</span><span style="color: black;">FastAPI</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">爬虫</h1><span style="color: black;"><span style="color: black;">基本</span>知识</span><span style="color: black;">爬虫概念</span><span style="color: black;">合法性</span><span style="color: black;"><span style="color: black;">重视</span>点</span><span style="color: black;">数据采集与解析</span><span style="color: black;">HTTP <span style="color: black;">基本</span>知识</span><span style="color: black;">Web <span style="color: black;">基本</span>知识</span><span style="color: black;">Socket 知识</span><span style="color: black;">Requets 库</span><span style="color: black;">正则表达式</span><span style="color: black;">Xpath</span><span style="color: black;">多种采集方式</span><span style="color: black;">同步采集</span><span style="color: black;">异步采集</span><span style="color: black;">Selenium</span><span style="color: black;">AJAX</span><span style="color: black;">Pyppeteer</span><span style="color: black;">中间人代理</span><span style="color: black;">Charles</span><span style="color: black;">Mitmproxy</span><span style="color: black;">HttpCanary</span><span style="color: black;">爬虫框架</span><span style="color: black;">Scrapy</span><span style="color: black;">Crawley</span><span style="color: black;">Selenium</span><span style="color: black;">PySpider</span><span style="color: black;">反爬虫</span><span style="color: black;">信息校验型</span><span style="color: black;">动态渲染型</span><span style="color: black;">文本混淆型</span><span style="color: black;">特征识别型</span><span style="color: black;">验证码</span><span style="color: black;">JS 混淆</span><span style="color: black;">多终端爬虫</span><span style="color: black;">Web 采集</span><span style="color: black;">APP 采集</span><span style="color: black;">小程序采集</span><span style="color: black;">数据去重</span><span style="color: black;">断点采集</span><span style="color: black;">增量采集</span><span style="color: black;">存储知识</span><span style="color: black;">本地文件</span><span style="color: black;">MySQL</span><span style="color: black;">Redis</span><span style="color: black;">MongoDB</span><span style="color: black;">Pandas</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">自动化运维</h1><span style="color: black;">Linux 知识</span><span style="color: black;">shell 知识</span><span style="color: black;">运维<span style="color: black;">关联</span>库</span><span style="color: black;">ansible</span><span style="color: black;">Paramiko</span><span style="color: black;">psutil</span><span style="color: black;">dnspython</span><span style="color: black;">IPy</span><span style="color: black;">常用运维工具</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">自动化测试</h1><span style="color: black;">测试<span style="color: black;">基本</span></span><span style="color: black;">接口测试</span><span style="color: black;">Web 页面测试</span><span style="color: black;">App 测试</span><span style="color: black;">Selenium</span><span style="color: black;">Pytest</span><span style="color: black;">UnitTest</span><span style="color: black;">Robot Framework</span><span style="color: black;">Behave</span><span style="color: black;">Locust</span><span style="color: black;">Lettuce</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">数据分析</h1><span style="color: black;">常用工具</span><span style="color: black;">Jupyter Notebook</span><span style="color: black;">Conda</span><span style="color: black;">常用类库</span><span style="color: black;">Numpy</span><span style="color: black;">Pandas</span><span style="color: black;">Matplotlib</span><span style="color: black;">数据处理</span><span style="color: black;">数据获取</span><span style="color: black;">数据清洗</span><span style="color: black;">数据合并/连接/聚合</span><span style="color: black;">数据可视化</span><span style="color: black;">Seaborn</span><span style="color: black;">Plotly</span><span style="color: black;">Pyecharts</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">人工智能</h1><span style="color: black;">数学知识</span><span style="color: black;">高等数学</span><span style="color: black;">线性代数</span><span style="color: black;">矩阵理论</span><span style="color: black;">概率论</span><span style="color: black;">统计学</span><span style="color: black;"><span style="color: black;">设备</span>学习</span><span style="color: black;"><span style="color: black;">设备</span>学习流程</span><span style="color: black;">特征工工程</span><span style="color: black;">模型</span><span style="color: black;">常用算法</span><span style="color: black;">常用库</span><span style="color: black;">深度学习</span><span style="color: black;">算法</span><span style="color: black;">重点技术分支</span><span style="color: black;">计算机视觉</span><span style="color: black;">自然语言处理</span><span style="color: black;">自动驾驶</span><span style="color: black;">群体智能</span><span style="color: black;">智能芯片</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">常用类库</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Python 的各种第三方类库是非常丰富的,这<span style="color: black;">亦</span>是 Python 能够如此流行的一大<span style="color: black;">原由</span>,基本<span style="color: black;">咱们</span>要做什么东西都能找到对应的类库,直接看文档用就行了,大大<span style="color: black;">加强</span><span style="color: black;">研发</span>效率!</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">类库太多了,直接看<span style="color: black;">照片</span>吧</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/6e2a3dea88014048b9636d8a831fa360~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723896848&amp;x-signature=0LCIBZLboV%2Bal%2BtsksgT17AEO2w%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">高级脚本</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">每日</span><span style="color: black;">咱们</span>都会面临许多<span style="color: black;">必须</span>高级编码的编程挑战。你<span style="color: black;">不可</span>用简单的 Python 基本语法来<span style="color: black;">处理</span>这些问题。下面分享 13 个高级 Python 脚本,它们<span style="color: black;">能够</span><span style="color: black;">作为</span>你项目中的<span style="color: black;">方便</span>工具。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1.<span style="color: black;">运用</span> Python 进行速度测试</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个高级脚本<span style="color: black;">帮忙</span>你<span style="color: black;">运用</span> Python 测试你的 Internet 速度。只需安装速度测试模块并运行以下代码。</span></p><span style="color: black;"># pip install pyspeedtest</span>
    <span style="color: black;"># pip install speedtest</span>
    <span style="color: black;"># pip install speedtest-cli</span>
    <span style="color: black;">#method 1</span>
    <span style="color: black;">import</span> speedtest
    speedTest = speedtest.Speedtest()
    <span style="color: black;">print</span>(speedTest.get_best_server())
    <span style="color: black;">#Check download speed</span>
    <span style="color: black;">print</span>(speedTest.download())<span style="color: black;">#Check upload speed</span>
    <span style="color: black;">print</span>(speedTest.upload())
    <span style="color: black;"># Method 2</span>
    <span style="color: black;">import</span>pyspeedtest
    st = pyspeedtest.SpeedTest()
    st.ping()
    st.download()
    st.upload()<h1 style="color: black; text-align: left; margin-bottom: 10px;">2.在谷歌上搜索</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">你<span style="color: black;">能够</span>从 Google 搜索引擎中提取重定向 URL,安装以下提及模块并遵循代码。</span></p><span style="color: black;"># pip install google</span>
    <span style="color: black;">from</span> googlesearch <span style="color: black;">import</span> search
    query = <span style="color: black;">"Medium.com"</span>

    <span style="color: black;">for</span> url <span style="color: black;">in</span> search(query):
    <span style="color: black;">print</span>(url)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3.制作网络<span style="color: black;">设备</span>人</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">该脚本将<span style="color: black;">帮忙</span>你<span style="color: black;">运用</span> Python 自动化网站。你<span style="color: black;">能够</span>构建一个可<span style="color: black;">掌控</span>任何网站的网络<span style="color: black;">设备</span>人。查看下面的代码,这个脚本在网络抓取和网络自动化中很方便。</span></p><span style="color: black;"># pip install selenium</span>
    <span style="color: black;">import</span> time
    <span style="color: black;">from</span> selenium <span style="color: black;">import</span> webdriver
    <span style="color: black;">from</span> selenium.webdriver.common.keys
    <span style="color: black;">import</span> Keysbot = webdriver.Chrome(<span style="color: black;">"chromedriver.exe"</span>)
    bot.get(<span style="color: black;">http://www.google.com</span>)
    search = bot.find_element_by_name(<span style="color: black;">q</span>)
    search.send_keys(<span style="color: black;">"@codedev101"</span>)
    search.send_keys(Keys.RETURN)
    time.sleep(<span style="color: black;">5</span>)
    bot.quit()
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">4.获取歌曲歌词</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个高级脚本将向你展示<span style="color: black;">怎样</span>从任何歌曲中获取歌词。<span style="color: black;">首要</span>,你<span style="color: black;">必要</span>从 Lyricsgenius 网站<span style="color: black;">得到</span>免费的 API 密钥,<span style="color: black;">而后</span>,你<span style="color: black;">必要</span>遵循以下代码。</span></p><span style="color: black;"># pip install lyricsgenius</span>
    import lyricsgenius
    api_key = <span style="color: black;">"xxxxxxxxxxxxxxxxxxxxx"</span>genius = lyricsgenius.Genius(api_key)
    artist = genius.search_artist(<span style="color: black;">"Pop Smoke"</span>,
    max_songs=5,sort=<span style="color: black;">"title"</span>)
    song = artist.song(<span style="color: black;">"100k On a Coupe"</span>)
    print(song.lyrics)<h1 style="color: black; text-align: left; margin-bottom: 10px;">5.获取照片的Exif数据</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span> Python Pillow 模块获取任何照片的 Exif 数据。查看下面<span style="color: black;">说到</span>的代码。我<span style="color: black;">供给</span>了两种<span style="color: black;">办法</span>来提取照片的 Exif 数据。</span></p><span style="color: black;"># Get Exif of Photo</span>
    <span style="color: black;"># Method 1</span>
    <span style="color: black;"># pip install pillow</span>
    <span style="color: black;">import</span> <span style="color: black;">PIL.Image</span>
    <span style="color: black;">import</span> <span style="color: black;">PIL.ExifTags</span>
    <span style="color: black;">img</span> = <span style="color: black;">PIL.Image.open("Img.jpg")</span>
    <span style="color: black;">exif_data</span> =
    <span style="color: black;">{</span>
    <span style="color: black;">PIL.ExifTags.TAGS</span>: <span style="color: black;">j</span>
    <span style="color: black;">for</span> <span style="color: black;">i, j in img._getexif().items()</span>
    <span style="color: black;">if</span> <span style="color: black;">i in PIL.ExifTags.TAGS</span>
    <span style="color: black;">}</span>
    <span style="color: black;">print(exif_data)</span>
    <span style="color: black;"># Method 2</span>
    <span style="color: black;"># pip install ExifRead</span>
    <span style="color: black;">import</span> <span style="color: black;">exifread</span>
    <span style="color: black;">filename</span> = <span style="color: black;">open(path_name, rb)</span>
    <span style="color: black;">tags</span> = <span style="color: black;">exifread.process_file(filename)</span>
    <span style="color: black;">print(tags)</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">6.提取图像中的 OCR 文本</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">OCR 是一种从数字和扫描文档中识别文本的<span style="color: black;">办法</span>。许多<span style="color: black;">研发</span>人员<span style="color: black;">运用</span>它来读取手写数据,下面的 Python 代码<span style="color: black;">能够</span>将扫描的图像转换为 OCR 文本格式。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">重视</span>:你<span style="color: black;">必要</span>从 Github 下载 tesseract.exe</span></p><span style="color: black;"># pip install pytesseract</span>
    <span style="color: black;">import</span>pytesseract<span style="color: black;">from</span> PIL <span style="color: black;">import</span> Image

    pytesseract.pytesseract.tesseract_cmd = <span style="color: black;">rC:\Program Files\Tesseract-OCR\tesseract.exe</span>

    t=Image.open(<span style="color: black;">"img.png"</span>)
    text = pytesseract.image_to_string(t, config=)
    print(text)<h1 style="color: black; text-align: left; margin-bottom: 10px;">7.将照片转换为Cartonize</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个简单的高级脚本会将你的照片转换为 Cartonize 格式。查看下面的示例代码并尝试一下。</span></p><span style="color: black;"># pip install opencv-python</span>import cv2

    img = cv2.imread(img.jpg)
    grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    grayimg = cv2.medianBlur(grayimg, 5)

    edges = cv2.Laplacian(grayimg , cv2.CV_8U, ksize=5)
    r,mask =cv2.threshold(edges,100,255,cv2.THRESH_BINARY_INV)
    img2 = cv2.bitwise_and(img, img, mask=mask)
    img2 = cv2.medianBlur(img2, 5)

    cv2.imwrite(<span style="color: black;">"cartooned.jpg"</span>, mask)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">8.清空回收站</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个简单的脚本<span style="color: black;">能够</span>让你用 Python 清空你的回收站,查看下面的代码以<span style="color: black;">认识</span><span style="color: black;">怎样</span>操作。</span></p><span style="color: black;"># pip install winshell</span>
    <span style="color: black;">import</span>winshell<span style="color: black;">try</span>:
    winshell.recycle_bin().empty(confirm=<span style="color: black;">False</span>, /show_progress=<span style="color: black;">False</span>, sound=<span style="color: black;">True</span>)
    print(<span style="color: black;">"Recycle bin is emptied Now"</span>)
    <span style="color: black;">except</span>:
    print(<span style="color: black;">"Recycle bin already empty"</span>)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">9.Python 图像<span style="color: black;">加强</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span> Python Pillow 库<span style="color: black;">加强</span>你的照片以使其看起来更好。在下面的代码中,我实现了四种<span style="color: black;">办法</span>来<span style="color: black;">加强</span>任何照片。</span></p><span style="color: black;"># pip install pillow</span>
    <span style="color: black;">from</span> PIL <span style="color: black;">import</span> Image,ImageFilter
    <span style="color: black;">from</span> PIL <span style="color: black;">import</span> ImageEnhance

    im = Image.open(<span style="color: black;">img.jpg</span>)

    <span style="color: black;"># Choose your filter</span>
    <span style="color: black;"># add Hastag at start if you dont want to any filter below</span>en = ImageEnhance.Color(im)
    en = ImageEnhance.Contrast(im)
    en = ImageEnhance.Brightness(im)
    en = ImageEnhance.Sharpness(im)<span style="color: black;"># result</span>
    en.enhance(<span style="color: black;">1.5</span>).show(<span style="color: black;">"enhanced"</span>)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">10.获取 Window 版本</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个简单的脚本将<span style="color: black;">帮忙</span>你<span style="color: black;">得到</span>当前<span style="color: black;">运用</span>的完整窗口版本。</span></p><span style="color: black;"># Window Versionimport wmi</span>
    <span style="color: black;">data</span> = <span style="color: black;">wmi.WMI()</span>
    <span style="color: black;">for</span> <span style="color: black;">os_name in data.Win32_OperatingSystem():</span>
    <span style="color: black;">print(os_name.Caption)</span>
    <span style="color: black;"># Microsoft Windows 11 Home</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">11.将 PDF 转换为图像</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>以下代码将所有 Pdf 页转换为图像。</span></p><span style="color: black;"># PDF to Images</span>
    <span style="color: black;">import</span> <span style="color: black;">fitz</span>
    <span style="color: black;">pdf</span> = <span style="color: black;">sample_pdf.pdf</span>
    <span style="color: black;">doc</span> = <span style="color: black;">fitz.open(pdf)</span>

    <span style="color: black;">for</span> <span style="color: black;">page in doc:</span>
    <span style="color: black;">pix</span> = <span style="color: black;">page.getPixmap(alpha=False)</span>
    <span style="color: black;">pix.writePNG(page-%i.png</span> <span style="color: black;">% page.number)</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">12.转换:十六进制到 RGB</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">该脚本将简单地将 Hex 转换为 RGB。查看下面的示例代码。</span></p><span style="color: black;"># Conversion: Hex to RGB</span>
    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">Hex_to_Rgb</span><span style="color: black;">(hex)</span>:</span>h = hex.lstrip(<span style="color: black;">#</span>)
    <span style="color: black;">return</span> tuple(int(h, <span style="color: black;">16</span>) <span style="color: black;">for</span> i <span style="color: black;">in</span> (<span style="color: black;">0</span>, <span style="color: black;">2</span>, <span style="color: black;">4</span>))
    print(Hex_to_Rgb(<span style="color: black;">#c96d9d</span>)) <span style="color: black;"># (201, 109, 157)</span>
    print(Hex_to_Rgb(<span style="color: black;">#fa0515</span>)) <span style="color: black;"># (250, 5, 21)</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">13.网站状态</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">你<span style="color: black;">能够</span><span style="color: black;">运用</span> Python <span style="color: black;">检测</span>网站<span style="color: black;">是不是</span>正常运行。<span style="color: black;">检测</span>以下代码,<span style="color: black;">表示</span>200 ,<span style="color: black;">暗示</span>网站已<span style="color: black;">起步</span>,<span style="color: black;">倘若</span><span style="color: black;">表示</span>为 404 ,则<span style="color: black;">暗示</span>网站已关闭。</span></p><span style="color: black;"># pip install requests</span>
    <span style="color: black;">#method 1</span>
    <span style="color: black;">import</span> urllib.request
    <span style="color: black;">from</span> urllib.request <span style="color: black;">import</span>Request, urlopenreq = Request(<span style="color: black;">https://medium.com/@pythonians</span>, headers={<span style="color: black;">User-Agent</span>: <span style="color: black;">Mozilla/5.0</span>})
    webpage = urlopen(req).getcode()
    <span style="color: black;">print</span>(webpage) <span style="color: black;"># 200</span>
    <span style="color: black;"># method 2</span>
    <span style="color: black;">import</span> requests
    r = requests.get(<span style="color: black;">"https://medium.com/@pythonians"</span>)
    <span style="color: black;">print</span>(r.status_code) <span style="color: black;"># 200</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">祖传代码</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这儿</span>再分享几段工作生活中常用的代码,都是最为<span style="color: black;">基本</span>的功能和操作,<span style="color: black;">况且</span>大多还都是<span style="color: black;">显现</span>频率比较高的,<span style="color: black;">非常多</span>都是<span style="color: black;">能够</span>拿来直接<span style="color: black;">运用</span><span style="color: black;">或</span>简单修改就<span style="color: black;">能够</span>放到自己的项目<span style="color: black;">其中</span></span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">日期生成</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">非常多</span>时候<span style="color: black;">咱们</span><span style="color: black;">必须</span>批量生成日期,<span style="color: black;">办法</span>有<span style="color: black;">非常多</span>,<span style="color: black;">这儿</span>分享两段代码</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">获取过去 N 天的日期</span></p><span style="color: black;">import</span> <span style="color: black;">datetime</span>

    <span style="color: black;">def</span> <span style="color: black;">get_nday_list(n):</span>
    <span style="color: black;">before_n_days</span> = <span style="color: black;">[]</span>
    <span style="color: black;">for</span> <span style="color: black;">i in range(1, n + 1)[::-1]:</span>
    <span style="color: black;">before_n_days.append(str(datetime.date.today()</span> <span style="color: black;">- datetime.timedelta(days=i)))</span>
    <span style="color: black;">return</span> <span style="color: black;">before_n_days</span>

    <span style="color: black;">a</span> = <span style="color: black;">get_nday_list(30)</span>
    <span style="color: black;">print(a)</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Output:</span></p><span style="color: black;">[<span style="color: black;">2021-12-23</span>, <span style="color: black;">2021-12-24</span>, <span style="color: black;">2021-12-25</span>, <span style="color: black;">2021-12-26</span>, <span style="color: black;">2021-12-27</span>, <span style="color: black;">2021-12-28</span>, <span style="color: black;">2021-12-29</span>, <span style="color: black;">2021-12-30</span>, <span style="color: black;">2021-12-31</span>, <span style="color: black;">2022-01-01</span>, <span style="color: black;">2022-01-02</span>, <span style="color: black;">2022-01-03</span>, <span style="color: black;">2022-01-04</span>, <span style="color: black;">2022-01-05</span>, <span style="color: black;">2022-01-06</span>, <span style="color: black;">2022-01-07</span>, <span style="color: black;">2022-01-08</span>, <span style="color: black;">2022-01-09</span>, <span style="color: black;">2022-01-10</span>, <span style="color: black;">2022-01-11</span>, <span style="color: black;">2022-01-12</span>, <span style="color: black;">2022-01-13</span>, <span style="color: black;">2022-01-14</span>, <span style="color: black;">2022-01-15</span>, <span style="color: black;">2022-01-16</span>, <span style="color: black;">2022-01-17</span>, <span style="color: black;">2022-01-18</span>, <span style="color: black;">2022-01-19</span>, <span style="color: black;">2022-01-20</span>, <span style="color: black;">2022-01-21</span>]</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">生成一段时间区间内的日期</span></p><span style="color: black;">import</span> datetime

    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">create_assist_date</span><span style="color: black;">(datestart = None,dateend = None)</span>:</span>
    <span style="color: black;"># 创建日期辅助表</span>

    <span style="color: black;">if</span> datestart <span style="color: black;">is</span> <span style="color: black;">None</span>:
    datestart = <span style="color: black;">2016-01-01</span>
    <span style="color: black;">if</span>dateend<span style="color: black;">is</span> <span style="color: black;">None</span>:
    dateend = datetime.datetime.now().strftime(<span style="color: black;">%Y-%m-%d</span>)

    <span style="color: black;"># 转为日期格式</span>
    datestart=datetime.datetime.strptime(datestart,<span style="color: black;">%Y-%m-%d</span>)
    dateend=datetime.datetime.strptime(dateend,<span style="color: black;">%Y-%m-%d</span>)
    date_list = []
    date_list.append(datestart.strftime(<span style="color: black;">%Y-%m-%d</span>))
    <span style="color: black;">while</span> datestart&lt;dateend:
    <span style="color: black;"># 日期叠加一天</span>datestart+=datetime.timedelta(days=+<span style="color: black;">1</span>)
    <span style="color: black;"># 日期转字符串存入列表</span>
    date_list.append(datestart.strftime(<span style="color: black;">%Y-%m-%d</span>))
    <span style="color: black;">return</span> date_list

    d_list = create_assist_date(datestart=<span style="color: black;">2021-12-27</span>, dateend=<span style="color: black;">2021-12-30</span>)
    d_list
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Output:</span></p><span style="color: black;">[<span style="color: black;">2021-12-27</span>, <span style="color: black;">2021-12-28</span>, <span style="color: black;">2021-12-29</span>, <span style="color: black;">2021-12-30</span>]</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">保留</span>数据到CSV</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">保留</span>数据到 CSV 是太<span style="color: black;">平常</span>的操作了,分享一段我个人比较<span style="color: black;">爱好</span>的写法</span></p>def save_data(data, date):
    if not os.path.exists(r2021_data_%s.csv % date):<span style="color: black;">with</span> <span style="color: black;">open</span>(<span style="color: black;">"2021_data_%s.csv"</span> % <span style="color: black;">date</span>, <span style="color: black;">"a+"</span>, <span style="color: black;">encoding</span>=<span style="color: black;">utf-8</span>) <span style="color: black;">as</span> f:
    f.write(<span style="color: black;">"标题,热度,时间,url\n"</span>)
    <span style="color: black;">for</span> i <span style="color: black;">in</span> <span style="color: black;">data</span>:
    title = i[<span style="color: black;">"title"</span>]
    extra = i[<span style="color: black;">"extra"</span>]
    <span style="color: black;">time</span> = i[<span style="color: black;">time</span>]
    <span style="color: black;">url</span> = i[<span style="color: black;">"url"</span>]
    <span style="color: black;">row</span> = <span style="color: black;">{},{},{},{}</span>.format(title,extra,<span style="color: black;">time</span>,<span style="color: black;">url</span>)
    f.write(<span style="color: black;">row</span>)
    f.write(<span style="color: black;">\n</span>)
    <span style="color: black;">else</span>:
    <span style="color: black;">with</span> <span style="color: black;">open</span>(<span style="color: black;">"2021_data_%s.csv"</span> % <span style="color: black;">date</span>, <span style="color: black;">"a+"</span>, <span style="color: black;">encoding</span>=<span style="color: black;">utf-8</span>) <span style="color: black;">as</span> f:
    <span style="color: black;">for</span> i <span style="color: black;">in</span> <span style="color: black;">data</span>:
    title = i[<span style="color: black;">"title"</span>]
    extra = i[<span style="color: black;">"extra"</span>]
    <span style="color: black;">time</span> = i[<span style="color: black;">time</span>]
    <span style="color: black;">url</span> = i[<span style="color: black;">"url"</span>]
    <span style="color: black;">row</span> = <span style="color: black;">{},{},{},{}</span>.format(title,extra,<span style="color: black;">time</span>,<span style="color: black;">url</span>)
    f.write(<span style="color: black;">row</span>)
    f.write(<span style="color: black;">\n</span>)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">带背景颜色的 Pyecharts</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Pyecharts <span style="color: black;">做为</span> Echarts 的优秀 Python 实现,受到众多<span style="color: black;">研发</span>者的<span style="color: black;">喜爱</span>,用 Pyecharts 作图时,<span style="color: black;">运用</span>一个舒服的背景<span style="color: black;">亦</span>会给<span style="color: black;">咱们</span>的图表增色不少</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">以饼图为例,<span style="color: black;">经过</span>添加 JavaScript 代码来改变背景颜色</span></p><span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">pie_rosetype</span><span style="color: black;">(data)</span> -&gt; Pie:</span>
    bac<span style="color: black;">公斤</span>round_color_js = (
    <span style="color: black;">"new echarts.graphic.LinearGradient(0, 0, 0, 1, "</span>
    <span style="color: black;">"[{offset: 0, color: #c86589}, {offset: 1, color: #06a7ff}], false)"</span>)
    c = (
    Pie(init_opts=opts.InitOpts(bg_color=JsCode(bac<span style="color: black;">公斤</span>round_color_js)))
    .add(<span style="color: black;">""</span>,
    data,
    radius=[<span style="color: black;">"30%"</span>, <span style="color: black;">"75%"</span>],
    center=[<span style="color: black;">"45%"</span>, <span style="color: black;">"50%"</span>],
    rosetype=<span style="color: black;">"radius"</span>,
    label_opts=opts.LabelOpts(formatter=<span style="color: black;">"{b}: {c}"</span>),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title=<span style="color: black;">""</span>),
    )
    )
    <span style="color: black;">return</span> c
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">requests 库调用</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">据统计,requests 库是 Python 家族里被引用的最多的第三方库,足见其江湖地位之<span style="color: black;">高挑</span>!</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">发送 GET 请求</span></p><span style="color: black;">import</span> requests


    headers = {
    <span style="color: black;">user-agent</span>: <span style="color: black;">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36</span>,
    <span style="color: black;">cookie</span>: <span style="color: black;">some_cookie</span>
    }
    response = requests.request(<span style="color: black;">"GET"</span>, url, headers=headers)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">发送 POST 请求</span></p><span style="color: black;">import</span>requests


    payload={}
    files=[]
    headers = {<span style="color: black;">user-agent</span>: <span style="color: black;">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36</span>,
    <span style="color: black;">cookie</span>: <span style="color: black;">some_cookie</span>
    }
    response = requests.request(<span style="color: black;">"POST"</span>, url, headers=headers, <span style="color: black;">data</span>=payload, files=files)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">按照</span>某些<span style="color: black;">要求</span>循环请求,<span style="color: black;">例如</span><span style="color: black;">按照</span>生成的日期</span></p><span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">get_data</span><span style="color: black;">(mydate)</span>:</span>date_list = create_assist_date(mydate)
    url =<span style="color: black;">"https://test.test"</span>
    files=[]
    headers = {
    <span style="color: black;">user-agent</span>: <span style="color: black;">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36</span>,
    <span style="color: black;">cookie</span>:
    }
    <span style="color: black;">for</span> d <span style="color: black;">in</span> date_list:
    payload={<span style="color: black;">p</span>: <span style="color: black;">10</span>,
    <span style="color: black;">day</span>: d,
    <span style="color: black;">nodeid</span>: <span style="color: black;">1</span>,
    <span style="color: black;">t</span>: <span style="color: black;">itemsbydate</span>,
    <span style="color: black;">c</span>: <span style="color: black;">node</span>}
    <span style="color: black;">for</span> i <span style="color: black;">in</span> range(<span style="color: black;">1</span>, <span style="color: black;">100</span>):
    payload[<span style="color: black;">p</span>] = str(i)
    print(<span style="color: black;">"get data of %s in page %s"</span> % (d, str(i)))
    response = requests.request(<span style="color: black;">"POST"</span>, url, headers=headers, data=payload, files=files)
    items = response.json()[<span style="color: black;">data</span>][<span style="color: black;">items</span>]
    <span style="color: black;">if</span> items:
    save_data(items, d)
    <span style="color: black;">else</span>:
    <span style="color: black;">break</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">Python 操作<span style="color: black;">各样</span>数据库</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">操作 Redis</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">连接 Redis</span></p><span style="color: black;">import</span> redis


    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">redis_conn_pool</span><span style="color: black;">()</span>:</span>
    pool = redis.ConnectionPool(host=<span style="color: black;">localhost</span>, port=<span style="color: black;">6379</span>, decode_responses=<span style="color: black;">True</span>)
    rd = redis.Redis(connection_pool=pool)
    <span style="color: black;">return</span> rd
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">写入 Redis</span></p><span style="color: black;">from</span> redis_conn <span style="color: black;">import</span> redis_conn_pool


    rd = redis_conn_pool()
    rd.set(<span style="color: black;">test_data</span>, <span style="color: black;">mytest</span>)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">操作 MongoDB</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">连接 MongoDB</span></p>from pymongo import MongoClient


    conn = MongoClient(<span style="color: black;">"mongodb://%s:%s@ipaddress:49974/mydb"</span> % (<span style="color: black;">username</span>, <span style="color: black;">password</span>))
    db = conn.mydb
    mongo_collection = db.mydata

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">批量<span style="color: black;">插进</span>数据</span></p>res = requests.get(url, params=query).json()
    commentList = res[<span style="color: black;">data</span>][<span style="color: black;">commentList</span>]
    mongo<span style="color: black;">_collection.insert_</span>many(commentList)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">操作 MySQL</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">连接 MySQL</span></p><span style="color: black;">import</span> MySQLdb

    <span style="color: black;"># 打开数据库连接</span>
    db = MySQLdb.connect(<span style="color: black;">"localhost"</span>, <span style="color: black;">"testuser"</span>, <span style="color: black;">"test123"</span>, <span style="color: black;">"TESTDB"</span>, charset=<span style="color: black;">utf8</span> )

    <span style="color: black;"># <span style="color: black;">运用</span>cursor()<span style="color: black;">办法</span>获取操作游标 </span>
    cursor = db.cursor()
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">执行 SQL 语句</span></p><span style="color: black;"># 使用 execute <span style="color: black;">办法</span>执行 SQL 语句</span>
    cursor.execute(<span style="color: black;">"SELECT VERSION()"</span>)

    <span style="color: black;"># <span style="color: black;">运用</span> fetchone() <span style="color: black;">办法</span>获取一条数据</span>
    data = cursor.fetchone()

    <span style="color: black;">print</span> <span style="color: black;">"Database version : %s "</span> % data

    <span style="color: black;"># 关闭数据库连接</span>db.close()<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Output:</span></p><span style="color: black;">Database version :</span> <span style="color: black;">5.0</span><span style="color: black;">.45</span>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">本地文件整理</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">整理文件<span style="color: black;">触及</span>需求的比较多,<span style="color: black;">这儿</span>分享的是将本地多个 CSV 文件整合成一个文件</span></p><span style="color: black;">import</span> pandas <span style="color: black;">as</span> pd
    <span style="color: black;">import</span> os


    df_list = []
    <span style="color: black;">for</span> i <span style="color: black;">in</span> os.listdir():
    <span style="color: black;">if</span> <span style="color: black;">"csv"</span> <span style="color: black;">in</span> i:
    day = i.split(<span style="color: black;">.</span>)[<span style="color: black;">0</span>].split(<span style="color: black;">_</span>)[<span style="color: black;">-1</span>]
    df = pd.read_csv(i)
    df[<span style="color: black;">day</span>] = day
    df_list.append(df)
    df = pd.concat(df_list, axis=<span style="color: black;">0</span>)
    df.to_csv(<span style="color: black;">"total.txt"</span>, index=<span style="color: black;">0</span>)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">多线程代码</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">多线程<span style="color: black;">亦</span>有<span style="color: black;">非常多</span>实现方式,<span style="color: black;">咱们</span><span style="color: black;">选取</span>自己最为<span style="color: black;">熟练</span>顺手的方式<span style="color: black;">就可</span></span></p>import threading
    import time

    exitFlag = <span style="color: black;">0</span>

    <span style="color: black;"><span style="color: black;">class</span> <span style="color: black;">myThread</span> (<span style="color: black;">threading</span>.<span style="color: black;">Thread</span>):</span>
    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">__init__</span><span style="color: black;">(<span style="color: black;">self</span>, threadID, name, delay)</span></span>:
    threading.Thread.__init_<span style="color: black;">_</span>(<span style="color: black;">self</span>)
    <span style="color: black;">self</span>.threadID = threadID
    <span style="color: black;">self</span>.name = name
    <span style="color: black;">self</span>.delay = delay
    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">run</span><span style="color: black;">(<span style="color: black;">self</span>)</span></span>:
    print (<span style="color: black;">"<span style="color: black;">起始</span>线程:"</span> + <span style="color: black;">self</span>.name)
    print_time(<span style="color: black;">self</span>.name, <span style="color: black;">self</span>.delay, <span style="color: black;">5</span>)
    print (<span style="color: black;">"退出线程:"</span> + <span style="color: black;">self</span>.name)

    <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">print_time</span><span style="color: black;">(threadName, delay, counter)</span></span>:
    <span style="color: black;">while</span> <span style="color: black;">counter:</span>
    <span style="color: black;">if</span> <span style="color: black;">exitFlag:</span>
    threadName.exit()
    time.sleep(delay)
    print (<span style="color: black;">"%s: %s"</span> % (threadName, time.ctime(time.time())))
    counter -= <span style="color: black;">1</span>

    <span style="color: black;"># 创建新线程</span>
    thread1 = myThread(<span style="color: black;">1</span>,<span style="color: black;">"Thread-1"</span>, <span style="color: black;">1</span>)
    thread2 = myThread(<span style="color: black;">2</span>, <span style="color: black;">"Thread-2"</span>, <span style="color: black;">2</span>)

    <span style="color: black;"># 开启新线程</span>
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()
    print (<span style="color: black;">"退出主线程"</span>)
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">异步编程代码</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">异步爬取网站</span></p><span style="color: black;">import</span> asyncio
    <span style="color: black;">import</span> aiohttp
    <span style="color: black;">import</span> aiofiles

    <span style="color: black;">async</span> <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">get_html</span><span style="color: black;">(session, url)</span>:</span>
    <span style="color: black;">try</span>:
    <span style="color: black;">async</span> <span style="color: black;">with</span> session.get(url=url, timeout=<span style="color: black;">8</span>) <span style="color: black;">as</span> resp:
    <span style="color: black;">if</span> <span style="color: black;">not</span>resp.status //<span style="color: black;">100</span> == <span style="color: black;">2</span>:
    print(resp.status)
    print(<span style="color: black;">"爬取"</span>, url, <span style="color: black;">"<span style="color: black;">显现</span>错误"</span>)
    <span style="color: black;">else</span>:
    resp.encoding = <span style="color: black;">utf-8</span>
    text = <span style="color: black;">await</span> resp.text()
    <span style="color: black;">return</span> text
    <span style="color: black;">except</span> Exception <span style="color: black;">as</span>e:
    print(<span style="color: black;">"<span style="color: black;">显现</span>错误"</span>, e)
    <span style="color: black;">await</span> get_html(session, url)
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>异步请求之后,对应的文件<span style="color: black;">保留</span><span style="color: black;">亦</span><span style="color: black;">必须</span><span style="color: black;">运用</span>异步,即是一处异步,处处异步</span></p><span style="color: black;">async</span> <span style="color: black;"><span style="color: black;">def</span> <span style="color: black;">download</span><span style="color: black;">(title_list, content_list)</span>:</span>
    <span style="color: black;">async</span> <span style="color: black;">with</span> aiofiles.open(<span style="color: black;">{}.txt</span>.format(title_list[<span style="color: black;">0</span>]), <span style="color: black;">a</span>,
    encoding=<span style="color: black;">utf-8</span>) <span style="color: black;">as</span> f:
    <span style="color: black;">await</span> f.write(<span style="color: black;">{}</span>.format(str(content_list)))




cvh132 发表于 2024-9-8 02:27:26

你的留言真是温暖如春,让我感受到了无尽的支持与鼓励。

星☆雨 发表于 2024-9-9 15:29:01

论坛的成果是显著的,但我们不能因为成绩而沾沾自喜。

j8typz 发表于 2024-9-26 05:38:21

“沙发”(SF,第一个回帖的人)‌

nqkk58 发表于 2024-10-26 23:41:37

你的话深深触动了我,仿佛说出了我心里的声音。

qzmjef 发表于 2024-10-31 10:40:26

你的见解真是独到,让我受益匪浅。
页: [1]
查看完整版本: 做后端,php后端强,还是python后端强