Fundamentals 10 min read

10 Must‑Try Python Scripts to Supercharge Your Daily Tasks

This guide presents ten practical Python scripts—from batch file renaming and web‑image downloading to email automation, password generation, Excel processing, image compression, weather lookup, PDF merging, text‑to‑speech, and a simple Snake game—each explained with clear scenarios, code examples, results, and handy tips for both beginners and seasoned developers.

Code Mala Tang
Code Mala Tang
Code Mala Tang
10 Must‑Try Python Scripts to Supercharge Your Daily Tasks

Ever felt stuck not knowing where to start with Python, or ended up rewriting code that already exists online? This article compiles ten practical Python scripts covering office automation, data processing, and fun tools, suitable for beginners and seasoned developers alike.

1. Batch rename files (Office tool)

Scenario: Need to rename dozens of files in a folder manually? Python can do it in three lines.

<code>import os
path = "D:\\Files"  # replace with your folder path
for i, filename in enumerate(os.listdir(path)):
    os.rename(f"{path}/{filename}", f"{path}/file_{i+1}.txt")
</code>

Effect: Automatically renames all files to "file_1.txt", "file_2.txt", …

Tips: Use double backslashes (\\) for Windows paths and single slashes (/) for macOS/Linux.

2. One‑click download webpage images (Crawling intro)

Scenario: Want to bulk‑save images from a website?

<code>import requests
from bs4 import BeautifulSoup
url = "https://example.com"  # replace with target page
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
for img in soup.find_all("img"):
    img_url = img.get("src")
    if img_url.startswith("http"):
        with open(img_url.split("/")[-1], "wb") as f:
            f.write(requests.get(img_url).content)
</code>

Effect: Automatically downloads all images on the page to the local directory.

Tips: Install dependencies with pip install requests beautifulsoup4 ; complex sites may need code adjustments.

3. Auto‑send email (Boost workplace efficiency)

Scenario: Sending daily reports manually is tedious.

<code>import smtplib
from email.mime.text import MIMEText
msg = MIMEText("This is the email body", "plain", "utf-8")
msg["Subject"] = "Automated Email Title"
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
with smtplib.SMTP_SSL("smtp.qq.com", 465) as server:
    server.login("[email protected]", "email_authorization_code")
    server.send_message(msg)
</code>

Effect: Sends the email with a single command, saving time.

Tips: QQ mail authorization code is generated in Settings → Account, not the login password.

4. Random password generator (Secure and fun)

Scenario: Can't think of a strong password for a new account?

<code>import random
import string
length = 12
chars = string.ascii_letters + string.digits + string.punctuation
password = "".join(random.choice(chars) for _ in range(length))
print(f"Your new password: {password}")
</code>

Effect: Generates a 12‑character password containing letters, numbers, and symbols.

Tips: Adjust the length to increase security.

5. Excel automation (Data enthusiast's favorite)

Scenario: Hundreds of rows in Excel are tiring to process manually.

<code>import pandas as pd
df = pd.read_excel("your_file.xlsx")
df["NewColumn"] = df["OldColumn"] * 2  # example: double a column
df.to_excel("new_file.xlsx", index=False)
</code>

Effect: Reads the Excel file, processes data, and saves a new file.

Tips: Install dependencies with pip install pandas openpyxl ; adjust column names as needed.

6. Batch compress images (Save space)

Scenario: Too many photos taking up storage? Compress them in bulk.

<code>from PIL import Image
import os
path = "D:\\Pictures"  # image folder path
for filename in os.listdir(path):
    if filename.endswith(".jpg"):
        img = Image.open(f"{path}/{filename}")
        img.resize((800, 600)).save(f"{path}/compressed_{filename}", quality=85)
</code>

Effect: Resizes images to 800×600 pixels with 85% quality.

Tips: Install Pillow with pip install Pillow ; customize dimensions and quality as desired.

7. Weather query script (Life assistant)

Scenario: Want to know tomorrow's weather automatically?

<code>import requests
city = "Beijing"  # replace with city name in English
url = f"http://wttr.in/{city}?format=%C+%t"
response = requests.get(url)
print(f"{city} weather: {response.text}")
</code>

Effect: Prints something like "Beijing weather: Sunny +15°C".

Tips: Uses a free API, no registration required.

8. PDF merge tool (Document organization)

Scenario: Need to combine multiple PDFs into one?

<code>from PyPDF2 import PdfMerger
merger = PdfMerger()
for pdf in ["file1.pdf", "file2.pdf"]:  # replace with actual filenames
    merger.append(pdf)
merger.write("merged_file.pdf")
merger.close()
</code>

Effect: Merges the listed PDFs into a new file.

Tips: Install PyPDF2 with pip install PyPDF2 ; ensure filenames are correct.

9. Text‑to‑speech (Creative use)

Scenario: Convert text to audio for sharing with friends.

<code>from gtts import gTTS
text = "你好,我是Python小助手"
tts = gTTS(text=text, lang="zh-CN")
tts.save("output.mp3")
</code>

Effect: Generates a Chinese MP3 file named "output.mp3".

Tips: Install gTTS with pip install gtts ; supports multiple languages.

10. Simple Snake game (Relax)

Scenario: Need a quick break from work? Play a tiny Python game.

<code>import pygame
pygame.init()
screen = pygame.display.set_mode((600, 400))
snake = [(200, 200)]
direction = (20, 0)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
    snake.append((snake[-1][0] + direction[0], snake[-1][1] + direction[1]))
    snake.pop(0)
    screen.fill((0, 0, 0))
    for pos in snake:
        pygame.draw.rect(screen, (0, 255, 0), (*pos, 20, 20))
    pygame.display.flip()
    pygame.time.delay(100)
</code>

Effect: Shows a simple green snake moving on a black background.

Tips: Install pygame with pip install pygame ; the full version can add food and keyboard controls.

How about these ten Python scripts? From office efficiency to entertainment, there’s surely one that can help you. Try them out, leave comments if you have questions, and share the post if you find it useful!

PythonAutomationproductivityTutorialScripts
Code Mala Tang
Written by

Code Mala Tang

Read source code together, write articles together, and enjoy spicy hot pot together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.