Simon Guo Simon Guo - 2 months ago 5x
Python Question

In python, how to import filename starts with a number

Basically there is a file called
and I want to import the file into another file (in the same folder and I cannot change the file name as the file is provided). Is there anyway to do this in Python? I tried usual way
from 8puzzle import *
, it gives me an error.

Error is:

>>> import 8puzzle
File "<input>", line 1
import 8puzzle
SyntaxError: invalid syntax


You could do

puzzle = __import__('8puzzle')

Very interesting problem. I'll remember not to name anything with a number.

If you'd like to import * -- you should check out this question and answer.