[Python] What are the requirements for naming Python modules?

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I've been going through Learn Python The Hard Way. Instead of naming each example ex#.py (where # is the number of the exercise), however, I've just been calling them #.py. This worked fine until I got to Exercise 25, which requires you to import a module you just created through the interpreter. When I try this the following happens:

    >>> import 25
    File "<stdin>", line 1
    import 25
    ^

    SyntaxError: invalid syntax


    I tried renaming the file to ex25.py and it then worked as expected (>>> import ex25). What are the naming requirements for Python modules? I had a look at the official documentation here but didn't see it mention any restrictions.

    Continue reading...

Compartilhe esta Página