r/learnpython • u/Final-Cartoonist-423 • 3d ago
Asking your ratings for my first ever python project!
Hello, everyone!
I'm learning Python through the CS50 course. In the meantime, I built a simple weather app using the concepts I've learned so far.
I'd really appreciate it if you could take a look at my work and point out any weaknesses in my program. I'd also love to hear your suggestions for future improvements.
Thank you! 🤗
GitHub: https://github.com/bihandumethum096-droid/Weather-App
3
u/jpgoldberg
3d ago
•
That is very impressive for a first project.
One thing is that imports should be at the top of the file and not within functions. I see why you imported pyfiglet where you did, but this is better solved by breaking the code up into modules (separate Python files.)
Put the functions that involve fetching the data in a separate file while leaving main and all of the user interface. You will need to learn how to import your own module to do so. But it looks like you are ready to work on that.
Also there is an incantation for calling main() in a script. You don’t need to understand why it is preferred to what you did or how all the pieces fit together just yet. So just consider it an incantation that is good to get into the habit of using. I can’t format this properly in the Reddit app I am using. So imagine a line break and indentation after the colon. (Also the underscores might not render properly.)
if __name__ == '__main__': main()
2
2
u/Kevdog824_
3d ago
•
One suggestion is to organize your project so it’s easy for other to clone and use. This could be using uv and pyproject.toml for building and running. It could also be a pyproject.toml/requirements.txt + Makefile or something similar. There’s quite a few options but the idea would be that it would be as easy as running one or two commands to build your project (download dependencies, etc.) and run it. At the very least your README would describe the specific commands I need to run (e.g. pip install requests)
2
u/PureWasian
3d ago
edited 3d ago
•
good overall, so I'll nitpick on minor things, which are largely just Python code convention things to be aware of when you start collaborating with others:
Move the import in Line 3 (L3): from pyfiglet import Figlet to the top of your file. It's convention to have all includes/imports at the top. Have a space between function args after the comma (L8: latitude, longitude). Similar for tuples, such as in L40. Have spaces between variable, assignment, and expression (such as L65: location = take_user_input()). Also, usually in Python it's uncommon to put parentheses around return values like how you did for your functions.
in search_location(), I'd add something to guard against no results returned by API so you don't have issue with [0] being IndexError if content['results'] is empty or key does not exist, even if the GET request is supposedly successful
if not results or len(results) == 0:
# do whatever err handling, example:
return None1
u/atrocia6
3d ago
•
A few more minor suggestions:
Consider using the common
if __name__ == "__main__"Python idiom - you can occasionally run into odd problems if you don't.
1
u/GrowlingOcelot_4516
2d ago
•
You don't have many dependencies yet, but consider using an environment manager moving forward. It will ensure users have the python version and dependencies required to run your code.
I personally use UV that is faster than poetry.
1
11
u/1One2Twenty2Two 3d ago •
The best thing you could do for yourself and for people who will read your code is to have linting and typing enforced.
Add mypy and ruff to your project and you will get a huge increase in quality + it will help develop your coding skills.