Python 3 m flag


I am a new to Python and I have a question regarding the m flag in Python.

While python -m pydoc sys will give an explanation on what the sys module does in windows powershell but if i were to change the statement to python pydoc sys (without the -m), i will get the "can’t open file ‘pydoc’: [Errno 2] No such file or directory error.

I appreciate if anyone of you could maybe help me on this.

Thanks alot!

The -m flag just says “load this module and try to run it like a script”. The pydoc module in Python knows how to be run as a script, so that’s why it works. Lots of python modules can do that. I use this though because a lot of times the pydoc command isn’t installed for people, but the pydoc module is.

1 Like