How to run a Python package with one command line

by Han Van Pham   Last Updated July 12, 2019 05:26 AM

I'm a newbie in Python. And I don't know how to run a python package with only one command line. I have been searched it on GG but I have no key-word. There is my folder:

├── config.json
└── my_source
    ├──__init__.py
    ├──filter.py
    └──get_new_users.py

And config.json contains 3 parameters and able change by the user. So, I want to run this my_source package with one command line like this:

my_source -c config.json

Could I able to run my code in this way? If it's possible. Could anyone give me a key-word or a way to do it? If you need more info, please leave a comment. Thank you.



Answers 2


It's not clear what you mean "run a folder". Rather you can import the folder as a module, in other code, say app.py

├── config.json
├── app.py
└── my_source
    ├──__init__.py
    ├──filter.py
    └──get_new_users.py

And do from my_source import * within app.py to use the function/variables defined there

Then, run python app.py, and pass config.json somehow depending on the internals of that code

cricket_007
cricket_007
November 23, 2018 08:16 AM

To run a python module/package specify the -m flag.

For example in your situation it will be something like:

python -m my_course.filter

See this SO question for more info.

Kunal Mukherjee
Kunal Mukherjee
November 23, 2018 10:44 AM

Related Questions


Updated February 24, 2018 05:26 AM

Updated June 20, 2017 14:26 PM

Updated December 17, 2018 14:26 PM

Updated July 28, 2017 22:26 PM

Updated May 07, 2017 08:26 AM