Import a file that starts with numbers in Python

Asked

Viewed 31 times

1

I have the following problem: I am trying to import a module into Python. I have the following code:

# -*- coding: utf-8 -*-

import 01_Jogo
print("----------------------------------------")
print("Bem vindo ao jogo!")
print("----------------------------------------")
print("Adivinhação (1) Forca (2)")

jogo = int(input("Qual jogo? "))

if (jogo == 1):
    print("Jogando Adivinhação")
    Jogo.jogar_advinhacao()
elif(jogo == 2):
    print("Jogando Forca")
    jogar_foca()

The problem is in the import that this not recognizing the archive that is also .py, but starting with a numbering. When rotating the code the following error is shown: Syntaxerror: invalid decimal literal. I also tried to put *import "01_Jogo" I had another error: Syntaxerror: invalid syntax. I could not find a solution for this in the documentation and nor rules that I can not import with files that start with number. Does anyone know why this error is happening and how I can fix it?

1 answer

0


Interesting problem...

You can do it like this:

jogo_01 = __import__('01_Jogo')

and I believe that this way also works:

import 01_Jogo as meu_modulo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.