Explore your training options in 10 minutes

X

Back

Global navigation

What is __init__.py? : A guide

Comments (2)
  1. Geert Vancompernolle says:

    Hi,

    Just read your article about __init__.py since it’s not clear to me what the purpose is of that “mysterious” file.

    I have the following python project tree (not all given, but it makes the idea clear):

    main.py
    canbus/canbus.py
    canparser/canparser.py
    heartbeat/hearbeat.py
    .
    .
    .

    As you can see, not one of them currently has the __init__.py.

    According to your article, it should NOT be possible to do an “from canbus import canbus” without the file __init__.py being part of the canbus directory, in main.py.

    Well, it looks like I am able to do that. Whether I put a __init__.py file or not in the directory canbus, it works equally fine.

    I can also write “from canbus.canbus import CANbus” in main.py (which is a class within canbus.py) without having the __init__.py present.

    So, I’m even more confused then before about the purpose of this __init__.py file.

    Hope you can explain why I can do this all without having not a single __init__.py in my project…

  2. Geert Vancompernolle says:

    OK… I just now saw that with Python3 there’s no need anymore for __init__.py files. That explains why it’s working for me, since I’m using Python3…

Leave a Reply

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

Ad
At Career Karma, our mission is to empower users to make confident decisions by providing a trustworthy and free directory of bootcamps and career resources. We believe in transparency and want to ensure that our users are aware of how we generate revenue to support our platform.

Career Karma recieves compensation from our bootcamp partners who are thoroughly vetted before being featured on our website. This commission is reinvested into growing the community to provide coaching at zero cost to their members.

It is important to note that our partnership agreements have no influence on our reviews, recommendations, or the rankings of the programs and services we feature. We remain committed to delivering objective and unbiased information to our users.

In our bootcamp directory, reviews are purely user-generated, based on the experiences and feedback shared by individuals who have attended the bootcamps. We believe that user-generated reviews offer valuable insights and diverse perspectives, helping our users make informed decisions about their educational and career journeys.
Find the right bootcamp for you
X
GET MATCHED
By completing and submitting this form, you agree that Career Karma, LLC may deliver or cause to be delivered information, advertisements, and telemarketing messages regarding their services by email, call, text, recording, and message using a telephone system, dialer, automated technology or system, artificial or prerecorded voice or message device to your email and/or telephone number(s) (and not any other person’s email or telephone number) that you entered. Consent is not a condition of receiving information, receiving Career Karma services, or using the website, and you may obtain information by emailing info@careerkarma.com. Message & Data rates may apply. Message frequency may vary. Text STOP to unsubscribe. Terms of Service and Privacy Policy govern the processing and handling of your data.
X
By completing and submitting this form, you agree that Career Karma, LLC may deliver or cause to be delivered information, advertisements, and telemarketing messages regarding their services by email, call, text, recording, and message using a telephone system, dialer, automated technology or system, artificial or prerecorded voice or message device to your email and/or telephone number(s) (and not any other person’s email or telephone number) that you entered. Consent is not a condition of receiving information, receiving Career Karma services, or using the website, and you may obtain information by emailing info@careerkarma.com. Message & Data rates may apply. Message frequency may vary. Text STOP to unsubscribe. Terms of Service and Privacy Policy govern the processing and handling of your data.