In Python, how does the "as" clause influence "import"?
Jan 18, 2023
02:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jan 18, 2023
02:13 AM
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
Labels:
- Labels:
-
Coding
2 REPLIES 2
Jan 24, 2023
11:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jan 24, 2023
11:25 AM
Hi @sachinbhatt.
This post doesn't appear to be ThingWorx related. Can you confirm?
Regards.
--Sharon
Jan 25, 2023
01:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
