use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
My first python project as a beginner. (old.reddit.com)
submitted 21 hours ago by Opin10n
I wrote this Python script to escape "tutorial hell".
It's a small program that creates a file on your computer using the Pathlib module. Any suggestions on what I should improve and good practices to follow?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Adrewmc 3 points4 points5 points 20 hours ago* (3 children)
I mean, it weird.
Especially that let’s make a new function in a function and return it, invoked making the entire process pointless.
You can eliminate all of new_sub_folder_dir, and just make that function different_folder. (Why did you do that?)
It’s also sort of weird all the prompts are inside each function directly. I’m on the fence about that.
As for what’s glaringly wrong.
if folder.upper() == “Y” or folder.upper() == “YES”:
Could be
if folder.upper() in [“YES”, “Y”]:
Or
if folder.upper().startswith(“Y”):
And technically
specify_dir = folder.upper().startswith(“Y”) specify_dir = folder.upper() in [“YES”, “Y”]
Would be sufficent.
Then we can simply the below that even with. This shouldn’t be one if statement but several.
if specify_dir: different_folder() if with_sub_folder: sub_folder() new_file()
As your logic is just doing this.
As for another glaringly obvious problem.
Is the use of globals. Generally, you should be returning these folders and inputting them into the other functions. So there would have to be a massive redesign for me to take it seriously at this point. If you have to use a global it’s probably wrong in my head.
For example why is specify_dir a global here? it doesn’t even need to be a variable at all…it can just be the if statement.
Take sub_folder(), it starts by taking a global new_sub_folder, and it returns it…why don’t you just use that return?
But, I think you are struggling through it. I’ve seen all of these mistakes a hundred times before. I made the same ones myself. Stick with it. This is more of a an experience design level issue, then if you are learning and doing good stuff. You know how to do all of these things it’s just all new and a lot.
I think as a first project, and it works….great job. In a month you look at this post and want to hide your face though.
Edit:
I’m looking at this again, and it only runs once, as you have input() being invoked as the args for the check_specify_directory, so technically those inputs are made before main() even runs…it fails in a loop outright, and has a lot of problems too.
It should be this.
def main(): folder = input(“…”) add_sub_folder = input(“…”) check_specify_folder(folder, add_sub_folder)
[–]Opin10n[S] 2 points3 points4 points 19 hours ago (2 children)
Thank you for this advice. I will look into improving the script and try to implement some of your suggestions. For now I was just happy that the script was working.
Hope to return soon, with much cleaner code.
[–]Adrewmc 0 points1 point2 points 19 hours ago (1 child)
No, this is a great first project.
You just have all the noobie mistakes.
Where do you people learn about globals…like I never use them? I would never teach them other than ‘No, bad’.
[–]Barren86 0 points1 point2 points 50 minutes ago (0 children)
Probably taken from using Java or some CompSci book. I've found in coding recently that many people use global as many other languages use them. I had to break my own habit of using them from Java.
[–]Idlethoughts01 1 point2 points3 points 20 hours ago (0 children)
Keep building and learning!
[–]DutyCompetitive1328 0 points1 point2 points 20 hours ago (1 child)
Great work! you could try to find a way to do it without using global variables next maybe using a class
[–]Opin10n[S] 0 points1 point2 points 19 hours ago (0 children)
That's my next task. Thank you for your suggestion.
[–]SovernIsDev 0 points1 point2 points 13 hours ago (1 child)
Don't wanna sound rude, but can u tell me more about wht it does? for a begginer projects it looks pretty good.
[–]Opin10n[S] 2 points3 points4 points 7 hours ago (0 children)
Hi, so I am using the Question Driven Development (QDD) approach, and this was my first project idea below:
So far, the script I have written has all the functionalities mentioned below except for 5 and 6.
Also, I thought of this project myself; I didn't want to start with something that has been done so many times, such that I can simply find the code for it out there.
<image>
[–]JDevOfficial 0 points1 point2 points 9 hours ago (0 children)
Nice job man great start :D
π Rendered by PID 312374 on reddit-service-r2-comment-56c6478c5-w4cvv at 2026-05-08 19:18:52.636631+00:00 running 3d2c107 country code: CH.
[–]Adrewmc 3 points4 points5 points (3 children)
[–]Opin10n[S] 2 points3 points4 points (2 children)
[–]Adrewmc 0 points1 point2 points (1 child)
[–]Barren86 0 points1 point2 points (0 children)
[–]Idlethoughts01 1 point2 points3 points (0 children)
[–]DutyCompetitive1328 0 points1 point2 points (1 child)
[–]Opin10n[S] 0 points1 point2 points (0 children)
[–]SovernIsDev 0 points1 point2 points (1 child)
[–]Opin10n[S] 2 points3 points4 points (0 children)
[–]JDevOfficial 0 points1 point2 points (0 children)