0

I was wondering if you knew how to run a python file to only display the file description. For example I have these lines on the top of my python program.

"""
===================================================
    test.py
    sphchow

    Description
====================================================
"""

I want to be able to run it so it displays this. But also have the ability to run the program normally. I tried searching around and could only find information like __docstring__ I think I'm not using the right key words?

1
  • __docstring__ is the name of the lines at the top of the program. Commented Dec 3, 2015 at 20:28

1 Answer 1

1

Say your module is foo.py then you can do:

import foo
print(foo.__doc__)

This will print the docstring for the module.

Or from the command line:

python -c "import foo; print(foo.__doc__)"

As mentioned in the comments, this information is also displayed when you use the help command:

help(foo)
Sign up to request clarification or add additional context in comments.

2 Comments

You can also access it through import foo; help(foo), which will give you other information as well.
Thanks guys, this was exactly what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.