AttributeError: module object has no attribute

N

Nikhil

I have recently written a small module. When I import the module, I
always get the error


only when I do

--
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'
---


but when I do the below, I do not get any error.

----

Any ideas on what could be wrong?


Thanks in advance.

Nikhil
 
P

Peter Otten

Nikhil said:
I have recently written a small module. When I import the module, I
always get the error


only when I do


--
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'
---


but when I do the below, I do not get any error.

--

Are you abusing the __all__ attribute?

$ cat tmp.py
__all__ = ['/xyz/py/file']

$ python -c "from tmp import *"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'

Peter
 
N

Nikhil

Peter said:
Nikhil said:
I have recently written a small module. When I import the module, I
always get the error


only when I do


--
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'
---


but when I do the below, I do not get any error.

--

Are you abusing the __all__ attribute?

$ cat tmp.py
__all__ = ['/xyz/py/file']

$ python -c "from tmp import *"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'

Peter

Hi Peter,

Yes, I am. Is there any reason not to?

basically, since this is implemented in the module, I have to export it
since the caller to the function in the module is responsible for
ensuring he has enough proper permissions to read the file.

Thanks,
Nikhil
 
M

Marc 'BlackJack' Rintsch

Peter said:
Nikhil said:
I have recently written a small module. When I import the module, I
always get the error


only when I do

from local.my.module import *

Are you abusing the __all__ attribute?

$ cat tmp.py
__all__ = ['/xyz/py/file']

$ python -c "from tmp import *"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'

Yes, I am. Is there any reason not to?

That your module raises the `AttributeError` and is broke is not reason
enough!? :)
basically, since this is implemented in the module, I have to export it
since the caller to the function in the module is responsible for
ensuring he has enough proper permissions to read the file.

What do you mean by "implemented in the module"? `__all__` is for names
that live in the module's namespace -- '/xyz/py/file' isn't even a legal
identifier name in Python!

Ciao,
Marc 'BlackJack' Rintsch.
 
N

Nikhil

Marc said:
Peter said:
Nikhil wrote:

I have recently written a small module. When I import the module, I
always get the error


only when I do

from local.my.module import *

--
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'
---


but when I do the below, I do not get any error.

--
import local.my.module

--

Any ideas on what could be wrong?
Are you abusing the __all__ attribute?

$ cat tmp.py
__all__ = ['/xyz/py/file']

$ python -c "from tmp import *"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '/xyz/py/file'
Yes, I am. Is there any reason not to?

That your module raises the `AttributeError` and is broke is not reason
enough!? :)
basically, since this is implemented in the module, I have to export it
since the caller to the function in the module is responsible for
ensuring he has enough proper permissions to read the file.

What do you mean by "implemented in the module"? `__all__` is for names
that live in the module's namespace -- '/xyz/py/file' isn't even a legal
identifier name in Python!

Ciao,
Marc 'BlackJack' Rintsch.
Okay.. thanks :)

I removed the entry from __all__, and I earlier assumed the module to
break, but it did not. Thanks again :)
 

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
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top