-1

While working with python, I come across some one liner commands like below

python -m http.server  # to create http server
python -m idlelib.idle # to open idle in virtual environment

So what does -m stands for in those one liner commands, and is there any other commands like these ?

Vikramd
  • 204
  • 1
  • 4
  • You can also type `python -h` at the command line to see a list of the arguments – pault Aug 17 '18 at 13:40
  • @pault, I think my question is different. From answer above I got it -m stands for module. But not getting what are other modules available in python. – Vikramd Aug 17 '18 at 13:47
  • You can run any module using the `-m` option. Another helpful post: [Execution of Python code with -m option or not](https://stackoverflow.com/questions/22241420/execution-of-python-code-with-m-option-or-not) - or check out [this blog post](http://pythonwise.blogspot.com/2015/01/python-m.html). – pault Aug 17 '18 at 13:56
  • 1
    To get list of available modules, run help() in python prompt and after that run modules command. It will give you list of all modules available in python. Also you can get topics also with command topics. –  Aug 22 '18 at 06:54

1 Answers1

0

If you run the -m flag python imports the module and than runs it as a script. Without the -m flag it is just run as a script (See the documentation)

If you want to run a one liner you should probably use following command:

python -c "print('Hello World')"

For multiple lines you can just add a semicolon:

python -c "print('Hello');print('World')"

I hope this helped you out.

ldh03
  • 1