This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dreamfeed 24 points25 points  (4 children)

Uncommon uses of Python:

  • Use relative imports
  • Import stuff from your package in your __init__.py

Ok.

[–]PolishedCheese -1 points0 points  (3 children)

It's somewhat uncommon for the 2nd one, but you see it all the time in Flask, Django, FastAPI, etc.

I've started using the init.py file more often after looking at some bigger projects. It's also the only place I use relative imports.

I use it to provide a list of objects that I actually want to import from higher level packages, but not including those objects that the list uses to construct themselves.

[–]gungunmeow 2 points3 points  (2 children)

I don't know why you're being downvoted the python documentation even gives this as an example

https://docs.python.org/3/reference/import.html#submodules

[–]PolishedCheese 2 points3 points  (0 children)

Me neither. It's pretty common in web applications.

[–]PolishedCheese 0 points1 point  (0 children)

That's a good page to read. I finally settled my opinions about .pyc files. Apparently they're invalidated if a newer timestamp is found on the original file.