Skip to main content

Timeline for answer to What is __init__.py for? by caritos

Current License: CC BY-SA 4.0

Post Revisions

14 events
when toggle format what by license comment
Nov 26, 2024 at 15:40 comment added NotoriousPyro IMHO: caveit... sometimes I've seen using __init__ to import and then export as __all__ to me is a code smell. Because if you choose this design, no longer can you use __init__ for any common functionality between all of the files in that directory because they will not be able to reference the import since it will be circular (e.g. foo/my_module/my_file.py imports from foo.my_module and foo/my_module/__init__.py imports from foo.my_module.my_file to export it). Thus __init__.py becomes nothing more than a file exporting other things... a smelly situation.
Nov 12, 2023 at 10:18 comment added robertspierre @alper if you declare a variable a inside inside spam's __init__py, you can access it with import spam and then spam.a.
Nov 12, 2023 at 10:18 history edited robertspierre CC BY-SA 4.0
Make clear what "based on" means
Apr 26, 2022 at 14:20 comment added Diego Cuadros @alper he doesn't have import spam inside __init__.py, he has it inside main.py or whatever file needs to import the contents of spam. You can treat spam as an object you import and use functions defined within spam/__init__.py
Oct 17, 2021 at 11:47 comment added alper Why do you have import spam inside` init.py`, what's its help
S Jul 12, 2021 at 9:38 history edited Shaido CC BY-SA 4.0
added 43 characters in body
Jul 12, 2021 at 8:31 review Suggested edits
S Jul 12, 2021 at 9:38
S Mar 28, 2017 at 16:01 history suggested Jordi Vicens CC BY-SA 3.0
inserting links in the correct way
Mar 28, 2017 at 11:40 review Suggested edits
S Mar 28, 2017 at 16:01
Oct 30, 2016 at 14:49 comment added Rob_before_edits Update: The file __init__.py was required under Python 2.X and is still required under Python 2.7.12 (I tested it) but it is no longer required from (allegedly) Python 3.3 onwards, and is not required under Python 3.4.3 (I tested it). See stackoverflow.com/questions/37139786 for more details.
Jun 5, 2014 at 9:36 history edited Smi CC BY-SA 3.0
added 5 characters in body
Nov 6, 2013 at 13:56 history edited Sarfaraz Nawaz CC BY-SA 3.0
I think it should vbe `mydir`, not `midir`
May 15, 2011 at 21:40 history edited Jeff Atwood CC BY-SA 3.0
added 63 characters in body
Nov 7, 2010 at 3:31 history answered caritos CC BY-SA 2.5