Ask Your Question

why does "import filename" give a SYNTAX error

asked 2022-07-21 10:26:34 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have a file in the project directory and another file in the same directory. In B I have the statement "import A" in the first line. I get the following error message:

Syntax Error: invalid syntax:

The same thing happens with : import, import '', etc. The error is not that the file is missing or that the file has errors, but rather the import statement is syntactically incorrect.

What to do???

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-07-22 08:21:50 -0500

For the record, this was resolved by email. The problem was that the imported filename was not but rather a name that contained dashes like The syntax error was due to 'import A-1' not being valid Python. Python files can be named using dashes in the name but then can only be run directly and not imported. Using underscores as in solves the problem since 'import A_1' is valid syntax.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2022-07-21 10:26:34 -0500

Seen: 2,064 times

Last updated: Jul 22 '22