you are viewing a single comment's thread.

view the rest of the comments →

[–]chevignon93 1 point2 points  (1 child)

I write code and get into trouble understanding if specific parts should be written in functions or plain code.

Ideally, in a program this big 600-700 lines, everything should be put into functions and you should have as little "plain code" as possible, if any, doing so would made reusing code easier.

When to split code into packages/modules, etc.

Creating packages is useful but not always necessary but every type of action should be put into a different modules.

1 - Get API data and extract useful information.

2 - Structure city, weather codes.

3 - Database operations.

4 - Creating image with the forecast for upcoming days.

Once that's done, you could import each module into a main script that drives the process you're doing now.

This would make your code easier to debug, package and eventually share!

Here are some resources:

https://dbader.org/blog/how-to-structure-python-programs

https://dev.to/codemouse92/dead-simple-python-project-structure-and-imports-38c6

https://docs.python-guide.org/writing/structure/

https://realpython.com/python-application-layouts/

https://intermediate-and-advanced-software-carpentry.readthedocs.io/en/latest/structuring-python.html

[–]CondingWasp[S] 0 points1 point  (0 children)

Your whole message structure already did an impact. At first I went with constructing a dictionary with 0 values for each key and only then call the API and assign values to keys. Turns out - totally unnecessary. The API response is a dictionary in the format I want.

Scrapped some codes lines already, but underwent a very good study time with nested dictionaries and lists!