'as' keyword - when/how to use it

D

Dummey

I am having the hardest time trying to find documentation on proper
use of the 'as' keyword (aside from . I initially thought that I would
be allowed to do something such as:

import shared.util as util

The as statement seems to be causing a lot of ''module' object has no
attribute'. Is it safe to assume that this is not the way to use it?
 
T

Terry Reedy

I am having the hardest time trying to find documentation on proper
use of the 'as' keyword (aside from . I initially thought that I would
be allowed to do something such as:

import shared.util as util

The as statement seems to be causing a lot of ''module' object has no
attribute'. Is it safe to assume that this is not the way to use it?

Give an example of real code raising an exception when importing from
the stdlib and the corresponding error traceback in its entirety.
 
S

Steven D'Aprano

I am having the hardest time trying to find documentation on proper use
of the 'as' keyword (aside from . I initially thought that I would be
allowed to do something such as:

import shared.util as util

The as statement seems to be causing a lot of ''module' object has no
attribute'. Is it safe to assume that this is not the way to use it?

It works for me.
<module 'email.mime.text' from '/usr/lib/python2.5/email/mime/text.pyc'>


My guess is that you are trying to import individual objects from a
module using the package dot notation:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sin
 
D

Dummey

It works for me.


<module 'email.mime.text' from '/usr/lib/python2.5/email/mime/text.pyc'>

My guess is that you are trying to import individual objects from a
module using the package dot notation:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sin

I was being an idiot and doing a circular import. I erroneously
thought it was the "as" part of the statement. For some reason,
removing the "as" part of the statement remove/delayed the error from
popping up which made me thought it was the culprit. Thanks for the
help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,475
Latest member
NovellaSce

Latest Threads

Top