相关文章推荐
豪气的鸡蛋面  ·  java代码转javascript ...·  1 年前    · 
谦和的火龙果  ·  APScheduler中两种调度器的区别及使 ...·  1 年前    · 
刚分手的跑步机  ·  SpringBootAdmin设置邮件通知_ ...·  1 年前    · 
小眼睛的仙人球  ·  linux进程间通信--socket套接字( ...·  1 年前    · 
听话的伤痕  ·  bcprov-jdk15-1.46.jar ...·  2 年前    · 
Code  ›  Github | 推荐一个Python脚本集合项目开发者社区
python python算法 directory python写文件
https://cloud.tencent.com/developer/article/1761519
愉快的双杠
2 年前
作者头像
bugsuse
0 篇文章

Github | 推荐一个Python脚本集合项目

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 气象杂货铺 > Github | 推荐一个Python脚本集合项目

Github | 推荐一个Python脚本集合项目

作者头像
bugsuse
发布 于 2020-12-16 11:47:03
1.4K 0
发布 于 2020-12-16 11:47:03
举报


Python 大数据 分析

记录 分享 成长

用python写小脚本是一件好玩的事情,因为不是个大活儿,而且能解决眼边前十分繁琐的事情,这种轻松且便宜的代码颇受人民群众的欢迎~有点生活小妙招的意味

大家较为熟知的脚本是用python来做爬虫、抢票、签到、自动回复机器人、批量处理文件等,这些比较常规,还有些较复杂的,比如做物品识别、语义分析、图像处理等,只要你有需求场景,总会想到办法写个脚本去处理它。

github上有个python项目,里面提供了几百个(可能上千)小脚本,涉及到算法、文件、文本、图像、视频、音乐、爬虫、邮件、可视化、系统、下载等各种常用场景的处理脚本。

项目地址:https://github.com/geekcomputers/Python

这个项目不是什么牛逼的大程序,而是作者在日常工作和python学习过程中积累的脚本,一个脚本解决一个问题。获得1万9的赞,说明颇有群众基础。

作者在介绍中所说,他并非专业程序员,而是为了解决问题、提高效率写了这些代码。我也是鼓励初学者可以先按照这种模式来学习编程,从解决问题的角度来写代码,把python当作一把锤子,不断找钉子。

分享其中几个脚本:

1、检查主目录中是否存在某文件夹,若不存在则创建文件

# Description   : Checks to see if a directory exists in the users home directory, if not then create it
import os  # Import the OS module
MESSAGE = 'The directory already exists.'
TESTDIR = 'testdir'
    home = os.path.expanduser("~")  # Set the variable home by expanding the user's set home directory
    print(home)  # Print the location
    if not os.path.exists(os.path.join(home, TESTDIR)):  # os.path.join() for making a full path safely
        os.makedirs(os.path.join(home, TESTDIR))  # If not create the directory, inside their home directory
    else:
        print(MESSAGE)
except Exception as e:
    print(e)

2、打印图片分辨率

def jpeg_res(filename):
   """"This function prints the resolution of the jpeg image file passed into it"""
   # open image for reading in binary mode
   with open(filename,'rb') as img_file:
       # height of image (in 2 bytes) is at 164th position
       img_file.seek(163)
       # read the 2 bytes
       a = img_file.read(2)
       # calculate height
       height = (a[0] << 8) + a[1]
       # next 2 bytes is width
       a = img_file.read(2)
       # calculate width
       width = (a[0] << 8) + a[1]
   print("The resolution of the image is",width,"x",height)
jpeg_res("img1.jpg")

3、连接 MySQL 数据库

import mysql.connector
# MySQl databses details
mydb = mysql.connector.connect(
    host="0.0.0.0",
    user="root",
    passwd="",
    database="db_name"
mycursor = mydb.cursor()
# Execute SQL Query =>>>> mycursor.execute("SQL Query")
mycursor.execute("SELECT column FROM table")
myresult = mycursor.fetchall()
for x in myresult:
    print(x)

4、PDF转音频

import pyttsx3
import pyPDF2
book = open('book.pdf','rb')
pdfreader = pyPDF2.PdfFileReader(book)
pages = pdfreader.numPages
print(pages)
 
推荐文章
豪气的鸡蛋面  ·  java代码转javascript java代码转php代码_mob6454cc6acccd的技术博客_51CTO博客
1 年前
谦和的火龙果  ·  APScheduler中两种调度器的区别及使用过程中要注意的问题 - Littlefish- - 博客园
1 年前
刚分手的跑步机  ·  SpringBootAdmin设置邮件通知_springboot admin 邮件通知-CSDN博客
1 年前
小眼睛的仙人球  ·  linux进程间通信--socket套接字(三)--多线程实现一个server对应多个client - 知乎
1 年前
听话的伤痕  ·  bcprov-jdk15-1.46.jar 与bcprov-ext-jdk15o?400报错-问答-阿里云开发者社区-阿里云
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号