First time here? Check out the FAQ!

why does "import filename" give a SYNTAX error

  • retag add tags

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???

asked 2022-07-21 10:26:34 -0500
This post is a wiki. Anyone with karma >75 is welcome to improve it.
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

1 Answer


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.

Wingware Support's avatar
Wingware Support
answered 2022-07-22 08:21:50 -0500
edit flag offensive 0 remove flag delete link


add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer