cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

In Python, how does the "as" clause influence "import"?

sachinbhatt
8-Gravel

In Python, how does the "as" clause influence "import"?

I assumed that the "as" phrase just created an alias for an imported module. However, in the following code, "import" fails with the "as" phrase.

 

 

import tensorflow.python.eager as eager

 

 

The following error occurs as a result of this statement.

 

 

Traceback (most recent call last):
  File "/home/snippet/prof/importer.py", line 2, in <module>
    import tensorflow.python.eager as eager
AttributeError: module 'tensorflow' has no attribute 'python'

 

 

When I delete the "as" clause, the "import" function works well. What effect does the "as" clause have on the success or failure of "import"?

This article suggests not using ".eager" when importing "eager" as anything and suggests the following:

 

 

from tensorflow.python import eager as eager

 

 

This works great, however, I'm not sure why my example is incorrect. could someone please explain

 

2 REPLIES 2
slangley
23-Emerald II
(To:sachinbhatt)

Hi @sachinbhatt.

 

This post doesn't appear to be ThingWorx related.   Can you confirm?

 

Regards.

 

--Sharon

You can ask about it here: https://python-forum.io/ 

Announcements


Top Tags