Importing from within package

Chris Angelico rosuav at gmail.com
Tue Sep 22 20:31:16 EDT 2020


On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer
> <arj.python at gmail.com> declaimed the following:
>
> >I have this main script:
> >https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py
> >
>
>         Well, that file name scares me...
>
>         __main__ is the name Python uses internally for the, well, main program
> (whatever the real file name is), and becomes part of the convention
>
> if __name__ == "__main__":
>         #running as stand-alone program
>         #do stuff
>
> where imported files will appear with the name by which they were imported.
>

In a package, __main__.py does that same job.

ChrisA


More information about the Python-list mailing list