ok so im mainly a frontend/fullstack guy i do React TypeScript Node all that stuff but i never really touched Python. i thought it was just for data science nerds or people who build AI stuff and i didn't think i needed it
then one day i had to automate something boring basically looping through a bunch of files and renaming them based on some logic and i was like ok let me just google it real quick
bro. Python had that done in like 10 lines
no imports no npm install 47 packages no webpack config just... python script.py and it worked. i kinda felt dumb for ignoring it this long
the syntax is also clean in a way thats different from JS. like in JS im always fighting semicolons and arrow functions and figuring out if something is undefined or null or just broken. Python just reads like english almost you write what you mean and it does what you said
one thing that tripped me up though is the indentation thing coming from JS where you use curly braces Python uses whitespace to define blocks and at first i kept messing it up. not gonna lie i had bugs that took me 20 minutes to find and it was just a wrong indent lol
but once you get past that its actually pretty fun to write
the file rename thing that started it all
here's basically what i wrote nothing crazy but it got the job done
pythonimport os
folder = "./my_files"
for filename in os.listdir(folder):
if filename.endswith(".txt"):
old = os.path.join(folder, filename)
new = os.path.join(folder, "done_" + filename)
os.rename(old, new)
print(f"renamed: {filename} -> done_{filename}")
thats it thats the whole script. try doing this in JS without feeling like you're overengineering something
and just to show how clean the syntax is
pythonnames = ["ali", "sara", "john", "mike"]
result = [name.upper() for name in names if len(name) > 3]
print(result) # ['SARA', 'JOHN', 'MIKE']
in JS id write a .filter() then a .map() chained together. python does it in one line and it reads almost like a sentence took me a minute to get used to it but now i think its clean
quick fetch from an api
pythonimport requests
res = requests.get("https://jsonplaceholder.typicode.com/posts/1")
data = res.json()
print(data["title"])
no async await no .then().catch() no try catch wrapping everything. just call it and get the data
im not switching from TS or anything i still think TypeScript is goated for big projects. but Python is now my go-to whenever i need to write a quick script or automate something its like the duct tape of programming languages in a good way
if youre a JS dev who never touched Python try it for one small project just one you might be surprised
Top comments (0)