10

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.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Han Van Pham
  • 462
  • 1
  • 6
  • 24

2 Answers2

31

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
  • 5,775
  • 3
  • 25
  • 53
3

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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245