Skip to content
Fix Code Error

What is __init__.py for?

March 13, 2021 by Code Error
Posted By: Mat

What is __init__.py for in a Python source directory?

Solution

It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”).

Here’s the documentation.

Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an __init__.py file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace. The __init__.py file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported.

But just click the link, it contains an example, more information, and an explanation of namespace packages, the kind of packages without __init__.py.

Answered By: Loki

Related Articles

  • Plugin…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Can't install via pip because of egg_info error
  • How to set HTML5 required attribute in Javascript?
  • How to generate JAXB classes from XSD?
  • Error 'Map', but got one of type 'Null' flutter web…
  • What does "Fatal error: Unexpectedly found nil while…
  • Ubuntu apt-get unable to fetch packages
  • npm install error in vue
  • What are the undocumented features and limitations…
  • Playing HTML5 video on fullscreen in android webview
  • What's the difference between eval, exec, and compile?
  • Relative imports for the billionth time
  • Where and why do I have to put the "template" and…
  • How to update Python?
  • How to change the color of vaadin-select-text-field…
  • For-each over an array in JavaScript
  • What is your most productive shortcut with Vim?
  • Difference between DTO, VO, POJO, JavaBeans?
  • What is The Rule of Three?
  • How can I view the source code for a function?
  • coercing to Unicode: need string or buffer, NoneType…
  • Ukkonen's suffix tree algorithm in plain English
  • Specifying java version in maven - differences…
  • Error using core-scaffold from polymer JS in the…
  • What is an optional value in Swift?
  • Improve INSERT-per-second performance of SQLite
  • What are type hints in Python 3.5?
  • Usage of __slots__?
  • How does PHP 'foreach' actually work?
  • Smart way to truncate long strings
  • What does a "Cannot find symbol" or "Cannot resolve…
  • SQL query return data from multiple tables
  • Why do we use __init__ in Python classes?
  • Why call git branch --unset-upstream to fixup?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Jetty: HTTP ERROR: 503/ Service Unavailable
  • How to prevent scrolling the whole page?
  • What is an application binary interface (ABI)?
  • How do I use namespaces with TypeScript external modules?
  • What are the rules about using an underscore in a…
  • Adding asterisk to required fields in Bootstrap 3
  • The null object does not have a method []=
  • How do I test to see if a line of a .txt exists or…
  • How should I deal with "package '✘✘✘' is not…
  • JavaScript hashmap equivalent
  • Why do git fetch origin and git fetch : behave differently?
  • Importing a GitHub project into Eclipse
  • How can I pass a wct test while rearranging children…
  • Python Variable Declaration
  • What does an exclamation mark mean in the Swift language?
  • Reference - What does this regex mean?
  • How to filter a RecyclerView with a SearchView
  • Backbone.js - Should nested Views maintain…
  • The definitive guide to form-based website authentication
  • How to resolve "Could not find schema information…
  • What is the scope of variables in JavaScript?
  • What is a NullReferenceException, and how do I fix it?
  • What is Ember RunLoop and how does it work?
  • How do I merge two dictionaries in a single…
  • Vue&TypeScript: how to avoid error TS2345 when…
  • How to solve Internal Server Error in Next.Js?
  • Difference between variable declaration syntaxes in…
  • Why does C++ code for testing the Collatz conjecture…
  • How can I find the product GUID of an installed MSI setup?
  • How to handle Vue 2 memory usage for large data (~50…
  • Apache server keeps crashing, "caught SIGTERM,…
  • How to make a SIMPLE C++ Makefile
  • Copy a file in a sane, safe and efficient way
  • How can I access and process nested objects, arrays or JSON?
  • Syntax error: right syntax to use near ' ' when…
  • How to use Vuex types constants with module namespace?
  • Getting the closest string match
  • Why does writeObject throw…
  • Callback functions in C++
  • How should a model be structured in MVC?
  • Launching Spring application Address already in use
  • Using a bitmask in C#
  • ExpressJS How to structure an application?
  • Git Using Remote Branch
  • load and execute order of scripts
  • Vuetify v-tabs v-tab-item overflows window width
  • correct way to use super (argument passing)
  • For Loop on Lua
  • How can I parse a CSV string with JavaScript, which…
  • Python: importing a sub‑package or sub‑module
  • What is an IndexOutOfRangeException /…
  • What is the copy-and-swap idiom?
  • What are the new features in C++17?
  • Vuejs build checkbox dynamically from array
  • Creating a singleton in Python
  • Good way of getting the user's location in Android
  • Webpack build error
  • Making macOS Installer Packages which are Developer ID ready
  • data.table vs dplyr: can one do something well the…
  • Error message "Forbidden You don't have permission…
  • What is Common Gateway Interface (CGI)?
  • Updating products with fetch and input value fields
  • What's the difference between Instant and LocalDateTime?
  • How can I get the source directory of a Bash script…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to print a number with commas as thousands separators in JavaScript

Next Post:

Git push requires username and password

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error