How to name a Python file

Every Python source file can essentially be considered as a module. The following rule applies to the name of a module, if it needs to be imported without problems:

(letter|"_") (letter | digit | "_")*

That is, the rule for naming a Python file is the same as naming a variable in it. First character has to be letter or underscore, followed by any number of letters, digits or underscores. No other characters, like dash, are allowed.

If the file is not named correctly, the following error or warning might be generated on importing it:

Invalid name for Python module

Tried with: Python 2.7.6 and Ubuntu 14.04


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.