How to get the same result as python -m requests.certs inside a python script?

This might be a dumb question -

in the command line, python -m requests.cert gives result:
/etc/pki/tls/certs/ca-bundle.crt

What is the right way to get the result inside python script?

#!/usr/bin/env python
import requets

result=requests.cert
print(result)

The script above returns result:
<module ‘requests.certs’ from ‘/usr/lib/python2.7/dist-packages/requests/certs.pyc’>

not sure why it is like this. I would like to get /etc/pki/tls/certs/ca-bundle.crt

When you run at command-line

python -m foo.bar

I treat it the same as:

  • If bar is a module (ie file “bar.py”)
    from foo import bar
    
  • If bar is a package (ie directory “bar/” with an “__init__.py”)
    from foo.bar import __main__
    

However, technically the module code is loaded and passed to an exec call

This means that “bar.py” / "__main__.py " need to exist, and will be executed like a script. A common idiom is to have in this file:

def main():
    # parse command-line arguments
    # then run application

if __name__ == "__main__":
    main()

Further reading:

1 Like

Thanks. That explains it.