-2

I shall inform you that this is my first question on stack overflow, so if I did any mistakes then tell me. I am a 15 year old teenager learning Python. Now coming to the point. I have named all my files as #1 detail_detail, #2 detail_detail.

Now my instructor has introduced me to modules but when I import my files it comes as a comment.

from #33 modules_part_2 import *

Plz help me.

Kraay89
  • 919
  • 1
  • 7
  • 19
Shlok
  • 11
  • 5
    # is a python keyword and you can't use it in your module names. Simply rename your files and then import them – Davide Anghileri Dec 24 '20 at 12:26
  • 1
    I don't think that is a valid module name. Not sure about module names, but python variables can only start with a letter, and apart from letters, can only contain underscores (`_`) and spaces. – Kraay89 Dec 24 '20 at 12:26
  • There is a workaround described [here](https://stackoverflow.com/questions/9090079/in-python-how-to-import-filename-starts-with-a-number) that would work in this situation. However, I'd **strongly advise against this**. The best actionable advice would be to **rename your files to something more appropriate**. – costaparas Dec 24 '20 at 12:27
  • Read the doc: https://www.python.org/dev/peps/pep-0008/#:~:text=Modules%20should%20have%20short%2C%20all,use%20of%20underscores%20is%20discouraged. – Danny Varod Dec 24 '20 at 12:30
  • I’m voting to close this question because no effort from OP. – Danny Varod Dec 24 '20 at 12:31
  • Also, he introduced you to modules before he teached you to use comments? Pretty sure you understand what's wrong as soon as you read this tid-bit about [Inline Comments](https://www.python.org/dev/peps/pep-0008/#inline-comments) – Kraay89 Dec 24 '20 at 12:33

1 Answers1

2

Use importlib:

import importlib
your_module = importlib.import_module("#1 detail_detail")

It's still not advised to have this kind of naming convention for your modules in Python.

Jarvis
  • 8,494
  • 3
  • 27
  • 58