Jiminion Jiminion - 1 year ago 95
Python Question

Using from in Python (directory name begins with a number, invalid identifier)

I am just trying to import from different directories.
This works:

if (ssize == 32):
from Python_32bit import mycoolmodule
from Python_64bit import mycoolmodule

But this does not:

if (ssize == 32):
from 32bit_Python import mycoolmodule
from 64bit_Python import mycoolmodule

Answer Source

Valid module name have to be correct identifier.

Identifiers follow lexical notation defined as:

identifier ::=  (letter|"_") (letter | digit | "_")*
letter     ::=  lowercase | uppercase
lowercase  ::=  "a"..."z"
uppercase  ::=  "A"..."Z"
digit      ::=  "0"..."9"
  • Python_32bit is a valid identifier.
  • 32bit_Python is not (it starts with a number, while identifiers have to start with (letter|"_")).
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download