[Tutor] serial connection was: adding a listbox

alan.gauld@bt.com alan.gauld@bt.com
Mon Feb 24 12:10:03 2003


> however) For some reason, it only works with "import
> Serial" and "Serial.Serial(0, timeout=1)". For whatever
> reason, when I execute the serial part of the code by
> calling the callback, I get this: 
> 
> module has no attribute Serial
> ...
> So what exactly is an attribute? Isn't it a function
> within that module?

Nope, it's a name. The name could be a function or a piece of data. 
Attributes can exist within a module or a class.

I'm not quite clear whats happening but I think you arte saying that:

serial.Serial(...)
serial.serial(...) and
Serial.serial(....)

all give errors and

Serial.Serial(...)

works OK?

That would suggest you should use Serial.Serial(...)   :-)

Python is case sensitive so only the right capitalisation will work.
When in doubt use the dir() function to find out what names(attributes) 
exist within a module:

>>> import Serial
>>> print dir(Serial)
....names galore here.....

Once you find the nam4e you can find how to use it by examining the doc
string:

print Serial.Serial.__doc__

Or using the inbuilt help() function.

Python is very friendly to code exploration...

Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/