Sunday, 9 November 2025

7 Python Automation Scripts That Make Life Easier


1. Rename multiple files

 import os

files=["photo1.png","photo2.png","photo3.png"]
for i ,f in enumerate(files,start=1):
    new_name=f"image_{i}.png"
    print(f"Renamed{f} {new_name}")

Output:

Renamedphoto1.png image_1.png
Renamedphoto2.png image_2.png
Renamedphoto3.png image_3.png


2. Auto Summarize a CSV File


import pandas as pd
data=pd.DataFrame({
    'Name':['Alice','Bob','Charlie'],
    'Score':[90,85,95],
    'Age':[23,25,22]
})
display(data.describe())

Output:


ScoreAge
count3.03.000000
mean90.023.333333
std5.01.527525
min85.022.000000
25%87.522.500000
50%90.023.000000
75%92.524.000000
max95.025.000000

3. Remove duplicate Entries


import pandas as pd
df=pd.DataFrame({
    'Name':['Alice','Bob','Alice','David'],
    'Score':[90,85,90,88]
})
df_clean=df.drop_duplicates()
display(df_clean)

Output:


NameScore
0Alice90
1Bob85
3David88

4. Display Current time and date automatically


from datetime import datetime
now=datetime.now()
print("Current Date & Time:" , now.strftime("%Y-%m-%d %H:%M:%S"))

Output:

Current Date & Time: 2025-11-04 22:25:22

5. Convert text to pdf


from fpdf import FPDF

pdf=FPDF()
pdf.add_page()
pdf.set_font("Arial",size=12)
pdf.cell(200,10,txt="hello from python",ln=True,align='C')
pdf.output("note.pdf")
print("Pdf saved as note.pdf")

Output:

Pdf saved as note.pdf


6. Search for a word in multiple text files


import glob
keyword="Python"
for file in glob.glob("*.txt"):
    with open(file) as f:
        if keyword in f.read():
           print(f"'{keyword}' found in {file}")
    

Output:

'Python' found in daily_log.txt
'Python' found in destination_file.txt


7. Generate a random password


import string,random
chars=string.ascii_letters+string.digits+string.punctuation
password=''.join(random.sample(chars,10))
print("Generated password:",password)

Output:

Generated password: U:{t*k,JzK

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (152) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (251) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (298) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (217) Data Strucures (13) Deep Learning (68) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (47) Git (6) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (186) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (11) PHP (20) Projects (32) Python (1218) Python Coding Challenge (884) Python Quiz (343) Python Tips (5) Questions (2) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (7) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)