Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

AttributeError: module object has no attribute

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


mnikhil at gmail

May 20, 2008, 10:30 AM

Post #1 of 6 (69 views)
Permalink
AttributeError: module object has no attribute

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?


Thanks in advance.

Nikhil
--
http://mail.python.org/mailman/listinfo/python-list


__peter__ at web

May 20, 2008, 10:49 AM

Post #2 of 6 (69 views)
Permalink
Re: AttributeError: module object has no attribute [In reply to]

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'

Peter
--
http://mail.python.org/mailman/listinfo/python-list


afilash+python at gmail

May 20, 2008, 10:52 AM

Post #3 of 6 (70 views)
Permalink
Re: AttributeError: module object has no attribute [In reply to]

hai nikhil,
please check your __init__ file if you had any

cheers,
abhilash

On Tue, May 20, 2008 at 11:00 PM, Nikhil <mnikhil[at]gmail.com> 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?
>
>
> Thanks in advance.
>
> Nikhil
> --
> http://mail.python.org/mailman/listinfo/python-list
>


mnikhil at gmail

May 20, 2008, 11:01 AM

Post #4 of 6 (70 views)
Permalink
Re: AttributeError: module object has no attribute [In reply to]

Peter Otten wrote:
> 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'
>
> 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
--
http://mail.python.org/mailman/listinfo/python-list


bj_666 at gmx

May 20, 2008, 11:13 AM

Post #5 of 6 (70 views)
Permalink
Re: AttributeError: module object has no attribute [In reply to]

On Tue, 20 May 2008 23:31:15 +0530, Nikhil wrote:

> Peter Otten wrote:
>> 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.
--
http://mail.python.org/mailman/listinfo/python-list


mnikhil at gmail

May 20, 2008, 11:21 AM

Post #6 of 6 (70 views)
Permalink
Re: AttributeError: module object has no attribute [In reply to]

Marc 'BlackJack' Rintsch wrote:
> On Tue, 20 May 2008 23:31:15 +0530, Nikhil wrote:
>
>> Peter Otten wrote:
>>> 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 :-)

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.