0

This is a question about Python program packaging and distribution. I installed SomeProgram from the Internet that requires Python. It works exactly like it's supposed to. There is only one single file that I can find associated with it located in \usr\bin\ It does not have a ".py" file extension, but I can open in it Python's IDLE text editor. There are just a few lines and less than 100-bytes long.

Also, it runs within BASH and accepts arguments and lots of options including some like -h for help or --verbose for alternate output. I wouldn't know it's a python program except that my understanding is that it's written in python.

I'm understanding that the code here is instructing it to import itself. The file is the SAME NAME [wrong see update] as the file it's asking to import, and there is no .py extension for the actual filename. Here is the code, [I've swapped out the name with SomeProgram because its a commercial enterprise name I don't want to print online]:

#!/usr/bin/python

import SomeProgram

if __name__ == '__main__':
    SomeProgram.main()

I want to understand where the main() source code is and learn from it. The program is fairly complex but I can't find it.

UPDATE: Problem solved. While finding the source code using the posted help below, I discovered that the file-name and and imported package-name are actually different. There is a hyphen within the python filename in my /usr/bin/ location, while the import-name has an underscore. It turns out that the source code is here: /usr/lib/python2.7/dist-packages/SomeProgram

1
  • 1
    Just print SomeProgram.__file__...... Commented Mar 26, 2017 at 19:00

1 Answer 1

1

The program loads its own module which is probably installed in Python's site-packages directory.

Open an Python interactive Python session and use these commands to find out where that is:

import site
site.getsitepackages()

Example:

> python 
Python 2.7.13 (default, Dec 28 2016, 20:51:25) 
[GCC 4.2.1 Compatible FreeBSD Clang 3.8.0 (tags/RELEASE_380/final 262564)] on freebsd11
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>> site.getsitepackages()
['/usr/local/lib/python2.7/site-packages', '/usr/local/lib/site-python']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.