Python: main

Breaking down the Python from

It’s installed with:


Files are packaged using a file. E.g.


Here’s a sample script (/usr/local/bin/awslogs – source code:



Path to Python. No idea why there’s an @.

Side note: you should use a shebang like:

#!/usr/bin/env python3



# -*- coding: utf-8 -*-

Specifies the encoding.


Imported as used later on. E.g. sys.argv[0]


from awslogs.bin import main

means: from the package awslogs.bin import the module main.

How does Python find these packages?

They’re in it’s path. E.g.


What is this dist-info directory?

It’s created by Wheel – one of Python’s packaging formats. See:


the mainfunction is from awslogs/ here:


More on sys.path:


if __name__ == '__main__':

If run from the command line (e.g. python ) then __name__ will == '__main__'. Otherwise, if it’s been run as a module then __name__ will be the name of the module.


sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])




Leave a Reply

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