noob import question

Brian Blazer brian at brianandkate.com
Fri May 19 09:44:00 EDT 2006


Thank you for your responses.  I had a feeling is had something to do  
with a namespace issue but I wasn't sure.

You are right, I do come from a Java background.  If it is poor form  
to name your class file the same as your class, can I ask what the  
standard is?

Thanks again,
Brian

On May 19, 2006, at 8:33 AM, Diez B. Roggisch wrote:

>> I have tried to look up what is going on, but I have not found
>> anything.  Would it be possible for someone to take a minute and give
>> an explanation?
>
> The
>
> from <module> import <*|nameslist>
>
> syntax imports some or all names found in <module> into the current  
> modules
> namespace. Thus you can access your class.
>
> But if you do
>
> import <module>
>
> you only get <module> in your current namespace. So you need to access
> anything inside <module> by prefixing the expression. In your case,  
> it is
>
> Student.Student
>
> If you only write Student, that in fact is the MODULE Student, which
> explains the error message.
>
> Now while this sounds as if the from <module> import * syntax is  
> the way to
> go, you should refrain from that until you really know what you are  
> doing
> (and you currently _don't_ know), as this can introduce subtle and
> difficult to debug bugs. If you don't want to write long module- 
> names, you
> can alias them:
>
> import <moduel-with-long-name> as <shortname>
>
>
> And it seems as if you have some JAVA-background, putting one class  
> in one
> file called the same as the class. Don't do that, it's a stupid  
> restriction
> in JAVA and should be avoided in PYTHON.
>
> Diez
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list