Trapped
Trapped

Reputation: 32

Importing a package with a keyword in path

I'm trying to import a package in which one of the namespaces is the keyword 'import'. How is it best to do this? Would the folder need to be renamed?

Example:

import protobuf.import.import_enum_pb2 as importEnum

This gives an invalid syntax error.

I have started to look at using __ import __ function instead-but wondered if there is a better workaround I haven't found a quotation or escaping method that works.

Upvotes: -1

Views: 438

Answers (2)

Trapped
Trapped

Reputation: 32

Have found this can be done using importlib

Example:

errorseverity = importlib.import_module(' protobuf.import.import_enum_pb2')

importlib see documentation: https://docs.python.org/3/library/importlib.html#importlib.import_module

Upvotes: 0

Related Questions