Is being an HSP a crime?

No matter how old you’re or what time your age has passed, the fact is that you can’t satisfy yourself being an HSP. HSP stands for Highly Sensitive Person. A person who overthinks about each little…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to import a module in python without using the import keyword

Python has a reasonably straightforward way to work with custom modules by using the builtin statement. However there is a caveat when the module shares the name with a python keyword.

o for example if the file you would import is name “lambda.py”. You would try to import with the following

This would throw an syntax error as the interpreter tries to evaluate the import statement followed by the lambda keyword.

There a few ways around this as one can either renamed the file (personally I prefer this). You could also use the importlib to the import which is what will be demonstrated on here.

The importlib allows you to import a file using a string representing the file or module.

The importlib also allows you to reload a module by using the reload function.

In conclusion, in most situations you should be able to use the import directly, the importlib can be used under really specific circumstances.

Add a comment

Related posts:

The Making of a Sunflower

An ekphrastic sonnet by Carolyn Hastings for Déjà Vu at Paper Poetry, describing how her grandson, Wesley, learned to draw a sunflower.

2nd Democratic Debate Chosen

Tonight the Clinton News Network chose the slots that the people will be Debating for the second time. It was done better than the first one. I missed how they did it, but they will replay it, but it…

Synthetic Intelligence

Androids have a bad reputation in science fiction. But in science fact, robot-human hybrids can be preferable to both the former and the latter. The trick is balancing the flexibility, intuition, and…