Syntax error when importing a file which starts with a number

Miles semanticist at
Mon Mar 23 19:16:24 CET 2009

On Mon, Mar 23, 2009 at 1:56 PM,  <simon.woolf at> wrote:
> Hello, all.
> I don't suppose anyone has any idea why it seems to be impossible to
> import any file which starts with a number?  You get a syntax error,
> whether the file exists or not.

Identifiers can't start with a number.

> It's a bit annoying, as I have an enforced naming scheme.  Any way
> round it?

You could import it like so:

some_valid_identifer = __import__('1foo', globals(), locals())

But a far better solution is to fix your naming scheme—it's completely
illogical to have a Python module naming scheme where the names aren't
valid identifiers.


More information about the Python-list mailing list