Classes are the basic python object,
They have methods which act on instances of the class. the self variable
is the reference to the specific instance.
class AnObject(object):
def method(self):
print 'I'm doing something to myself %s' % self
You make instances of them:-
ao = AnObject()
They have both parameters
ao.comment = ' A bit of text'
ad you can run methods on them:
ao.method()
It can do set up type things by declaring a method called __init__ ( __,
double underscore methods do some predeclared stuff )
Another handy one is __unicode__, which allows you to specify how the
object will respond to anything that interprets the object as a string
class AnObject(object):
def __init__(self):
print ' Do setuppy type stuff'
self.method()
self.name = 'An instance of AnObject
def __unicode__(self):
return self.name
def method(self):
print 'I'm doing something to myself %s' % self
ao = AnObject()
class AnObject(object):
def __init__(self):
print ' Do setuppy type stuff'
self.method()
self.name = 'An instance of AnObject
def __unicode(self):
return self.name
def method(self):
print 'I'm doing something to myself %s' % self
ao = AnObject()
ao.method()
Dive into python seems to be well regarded as a python tutorial.
Chris
Mick Sulley wrote:
> Pascal, Marcus,
>
> Yes it works now, it was a typo. I now need to read up on Python to
> find out how to use classes.
>
> Thanks to you both for your help.
>
> Mick
>
> On Wed, 2010-04-07 at 20:46 +0200, Pascal Baerten wrote:
>> Mick,
>>
>> If your previous mail was a copy-paste from your console, it's
>> effectively a wrong id:
>> you put the letter 'O' instead of zero '0' on first position of your
>> id...
>>
>> Pascal
>>
>> 2010/4/7 Marcus Priesch <[email protected]>
>> Hi mick,
>>
>> i just tried 2.7p34 and it works again with pyowfs ... thanks
>> paul !!!
>>
>> i also tried searching the bus for a sensor specified by
>> id ... the
>> correct syntax is:
>>
>> c.find (id="7F9221000000")
>>
>> without the familiy code - so your try should have worked ...
>> maybe you
>> had wrong id ?!?!
>>
>> you can try this all without writing a python script directly
>> in the
>> python interpreter - this way you can play around
>> interactively with all
>> that fun :)
>>
>> (owfs_test)p...@pr-laptop:~/work/tmp$ python
>> Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
>> [GCC 4.4.1] on linux2
>> Type "help", "copyright", "credits" or "license" for more
>> information.
>> >>> import pyowfs
>> >>> c = pyowfs.Connection ("127.0.0.1:4711")
>> >>> c.find ()
>> DEFAULT: ow_reconnect.c:TestConnection(58) tcp bus master
>> reconnected
>> [<Sensor /81.7F9221000000/ - DS1420>]
>> >>> s=c.find ()[0]
>> >>> for i in s.iter_entries() : print i
>> ... <- just hit enter here ...
>> address
>> alias
>> crc8
>> family
>> id
>> locator
>> present
>> r_address
>> r_id
>> r_locator
>> type
>> >>> s.get ("id")
>> '7F9221000000'
>> >>> c.find (id="7F9221000000")
>> [<Sensor /81.7F9221000000/ - DS1420>]
>>
>> have fun,
>> marcus.
>>
>> btw: for learning python the python tutorial at python.org is
>> a good
>> starting point ... also diveintopython.org is a good try ...
>>
>>
>
>
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Owfs-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers