AttributeError: module object has no attribute

Discussion in 'Python' started by Nikhil, May 20, 2008.

  1. Nikhil

    Nikhil Guest

    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
     
    Nikhil, May 20, 2008
    #1
    1. Advertisements

  2. Nikhil

    Peter Otten Guest

    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
     
    Peter Otten, May 20, 2008
    #2
    1. Advertisements

  3. Nikhil

    Nikhil Guest

    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
     
    Nikhil, May 20, 2008
    #3
  4. 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.
     
    Marc 'BlackJack' Rintsch, May 20, 2008
    #4
  5. Nikhil

    Nikhil Guest

    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 :)
     
    Nikhil, May 20, 2008
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dont bother
    Replies:
    3
    Views:
    5,413
    scriber
    Mar 31, 2009
  2. adrian
    Replies:
    4
    Views:
    1,013
    John J. Lee
    Apr 1, 2005
  3. rsd
    Replies:
    2
    Views:
    701
  4. kepioo
    Replies:
    0
    Views:
    622
    kepioo
    Sep 19, 2006
  5. Replies:
    0
    Views:
    614
  6. Matt McCredie
    Replies:
    0
    Views:
    479
    Matt McCredie
    Aug 10, 2007
  7. Matt McCredie
    Replies:
    0
    Views:
    459
    Matt McCredie
    Aug 14, 2007
  8. black_13
    Replies:
    4
    Views:
    688
    black_13
    Feb 12, 2008
Loading...