Jump to content
  • Advertisement
Sign in to follow this  
iamspecial

explain

This topic is 3747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what does the following code means in python if __name__ == "__main__": print info.__doc__ where info is a name of a function

Share this post


Link to post
Share on other sites
Advertisement
There are basically two ways that a python source file an be run: it can be run as the main program or it can be imported. So if you had a python file my_module.py and used the command line "python my_module.py" it would be run as the main program. If instead, you used "import my_module" in some other module, it would be imported. Depending on if its the main program module or if it's imported, the __name__ variable for the module is set differently. When run as the main program module it is set to "__main__"; otherwise it is set to the name of the module. So checking if __name__ is equal to __main__ checks to see if the module is being executed rather than imported.

In this case, the if block is saying that if the module is being executed directly, print the doc string for the info function.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
In this case, the if block is saying that if the module is being executed directly, print the doc string for the info function.


doc strings.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!