Danny Yoo | 1 Jul 2004 01:04
Picon

Re: testing new style class properties using pyUnit ?


On Wed, 30 Jun 2004, Duncan Gibson wrote:

> I had a class which used get and set methods to access a class variable.
> I set up some unit tests using pyUnit. After some fiddling about, I
> managed to get it all working.
>
> I've just upgraded the source to use the new style classes with
> properties instead of explicit get and set methods. However, so far I've
> been unable to convert the unit tests. I note the error message, but I
> don't understand why.

[some code cut]

Hi Duncan,

Ok,, what you're running into is actually not so much related properties
feature, but actually of the naming-mangling that Python does on any
property with leading double underscores.

In the 'A_new' class, you have the following methods:

> class A_New(object):
>     __slots__ = ('__x',)
>     def __init__(self, x=0):
>         self.x = x
>     def __get_x(self):
>         return self.__x
>     def __set_x(self, x):
>         assert isinstance(x, int)
(Continue reading)

Danny Yoo | 1 Jul 2004 01:21
Picon

Re: strange listed nest behaviour


On Wed, 30 Jun 2004, Dave S wrote:

> I have a problem with lists,
>
> As an example the following makes sense to me and works as I would
> expect ...
>
>  >>> b=[[0,0,0,0],[0,0,0,0]]
>  >>> b
> [[0, 0, 0, 0], [0, 0, 0, 0]]
>  >>> b[1][1]=5
>  >>> b
> [[0, 0, 0, 0], [0, 5, 0, 0]]
>  >>>
>
> However I have to set up a large data list, so I have used
> "self.startslot=[[float(0)]*110]*36" inside a class.

Hi Dave,

Today seems like a FAQ-referral day for me.  *grin*


Here you go:

http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list

Hope this helps!

(Continue reading)

Alan Gauld | 1 Jul 2004 01:37
Picon
Favicon

Re: New Python user on board

> I currently work in Marseille, France, as a rendering technical
director (we
> are doing a full 3D animation feature film called "Magic
Roundabout").

Excellent, I heard that they were doing a film version. The Magic
Roundabout
was one of my favourite puppet shows when I was a kid :-)

> At this point I'm very new to Python but I have read the tutorial in
the
> documentation, it seems very promising. At this moment I'm mainly
looking
> into Python to in hopes to develop a rendering management software.
>
> I apoligize in advance for the tons of newbie questions that will
follow,
> and thank you in advance for your time.

Thats OK, its what the list is for. If you read the official tutorial
you might be a wee bit more adbvanced a newbie than many of our
readers,
but you are welcome nonetheless.

Also if you know VBScript/JScript you might find my new online tutor
useful
since it teaches basic Python but using VBscript and JScript as
comparison
languages...

(Continue reading)

Mike | 1 Jul 2004 05:07

subclass / superclass methods

Greetings,
I'm trying to find out why the below does not work as I'm expecting. I'm
sure there is a good answer, just I'm too green to understand why. Any
help would be appreciated. My expected results are for it to say 'Hello
other OnTick'

Thanks,
Mike

class object:

    def __init__(self):
        print 'Hello object __init__'

    def EventTick(self):
        print 'Hello object EventTick'
        self.OnTick()

    def OnTick(self):
        print 'Hello object OnTick'

class other(object):

    def __init__(self):
        print 'Hello other __init__'

    def OnEvent(self):
        print 'Hello other OnTick'

if __name__ == '__main__':
(Continue reading)

Dragonfirebane | 1 Jul 2004 05:55
Picon
Favicon

Re: subclass / superclass methods

I, too, am farily new at Python, but it occurs to me that perhaps you meant to have
 
class object:
    def __init__(self):
        print 'Hello object __init__'
    def EventTick(self):
        print 'Hello object EventTick'
        self.OnTick()
    def OnTick(self):
        print 'Hello object OnTick'
class other(object):
    def __init__(self):
        print 'Hello other __init__'
    def OnEvent(self):
        print 'Hello other OnTick'
if __name__ == '__main__':
    my = other()
    my.EventTick()
 
be
 
class object:
    def __init__(self):
        print 'Hello object __init__'
    def EventTick(self):
        print 'Hello object EventTick'
        self.OnTick()
    def OnTick(self):
        print 'Hello object OnTick'
class other(object):
    def __init__(self):
        print 'Hello other __init__'
    def OnTick(self):
        print 'Hello other OnTick'
if __name__ == '__main__':
    my = other()
    my.EventTick()
 
(change OnEvent(self) in Class other to OnTick(self) so that when my.EventTick() is run, it goes to Class other's OnTick rather than Class object since Class other's OnTick wouldn't exist)
 
the proposed change produces the following in IDLE:
 
Hello other __init__
Hello object EventTick
Hello other OnTick
 
I don't know if that's what you wanted, but it has "Hello other OnTick" in it.
 
Email: dragonfirebane <at> aol.com
AIM: singingxduck
Programming Python for the fun of it.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
janos.juhasz | 1 Jul 2004 07:59
Favicon

Re: help with regular expressions


Hi Jeff,

>At 10:29 PM 6/29/2004, Jeff Peery wrote:
>>hello I am having trouble with using the re module. I have a statement:
>>
>>line = FileHandle.readline(-1)
>>test = findall('\d', line)
>>
>>where "line" is a line of text from a file I would like to read and
>>extract numbers from. the line is simply three numbers, example
>>3.444456    4   84.3546354.  I want to put these number in "test" but the
>>findall expression seems to only take whole numbers, so for example test
>>would be for the above numbers [3, 4, 4, 4, 4, 5, 6, 4, 8, ....].  How is
>>this done so that test = [3.444456    4   84.3546354]?
>
>
>>>> re.findall(r'\d+.?\d*', '3.444456    4   84.3546354')
>['3.444456', '4 ', '84.3546354']


I fell that, you are looking for this:

>>> re.findall('\S+', '3.444456    4   84.3546354')
['3.444456', '4', '84.3546354']


Yours sincerely,
János Juhász
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Andrei | 1 Jul 2004 08:55

Re: IDLE question

Dick Moores <rdm <at> rcblue.com> writes:

> >If you want a >>> prompt with the color coding and other bells of IDLE
> >try the pyShell that comes with wxPython. It is now my preferred
> >Python interactive prompt...
> 
> To use the pyShell that comes with wxPython, I'd have to download and 
> install and use all of wxPython, I suppose. I just read about wxPython on 

PyCrust is a really nice Python shell - my favorite in fact - worth downloading
wxPython IMO.

> it's website, and I'm interested in what is said there about having the 
> best GUI toolkit. 

Everyone claims their product is better than the competition :). (I happen to
agree on wxPython, but it's very much a matter of taste.)

> But if I switch to wxPython, except for not using 
> tkinter, will I be able to rely on the Python documentation, tutorials 
> and books for learning Python? I'm guessing I can, but can you confirm this?

Yes. wxPython is just a set of libraries and tools like all the other libraries
and tools you get with Python. You use whatever you need and ignore the rest.

> Also, on the wxPython main page it says, "Welcome to the home of 
> wxPython, a blending of the wxWidgets C++ class library with the Python 
> programming language." Does this mean I'd have to know C++ to use the 
> wxWidgets? Or is it the case that I would no more need to know C++ for 
> wxPython than I need to know C to use Python.

Nope. I don't know C(++), and I can use it just fine. The docs are C++ oriented
(with some Python annotations here and there), but although that's not an ideal
situation, they're quite easy to follow after the inital shock :) - plus that it
comes with a great demo with a lot of educational value. But anyway, you don't
need to read the docs in order to use PyCrust/PyShell.

Yours,

Andrei

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Dave S | 1 Jul 2004 09:04

Re: strange listed nest behaviour

Danny Yoo wrote:

>On Wed, 30 Jun 2004, Dave S wrote:
>
>  
>
>>I have a problem with lists,
>>
>>As an example the following makes sense to me and works as I would
>>expect ...
>>
>> >>> b=[[0,0,0,0],[0,0,0,0]]
>> >>> b
>>[[0, 0, 0, 0], [0, 0, 0, 0]]
>> >>> b[1][1]=5
>> >>> b
>>[[0, 0, 0, 0], [0, 5, 0, 0]]
>> >>>
>>
>>However I have to set up a large data list, so I have used
>>"self.startslot=[[float(0)]*110]*36" inside a class.
>>    
>>
>
>Hi Dave,
>
>Today seems like a FAQ-referral day for me.  *grin*
>
>
>Here you go:
>
>http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list
>
>
>Hope this helps!
>  
>
Its perfect :-) ... I will read the FAQ. I have been learning my Python 
from o'reilly and did not realise there was a FAQ on line - thats great 
cheers

Dave

PS thanks for your patience with us newbes !

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 1 Jul 2004 09:45
Picon
Favicon

Re: subclass / superclass methods

> I'm trying to find out why the below does not work as I'm expecting.
I'm
> sure there is a good answer, just I'm too green to understand why.
Any
> help would be appreciated. My expected results are for it to say
'Hello
> other OnTick'

First, its a bad oidea to create a class called object, since that
will hide the builtin class called object which could produce
weird results!

> class object:
>     def __init__(self):
>     def EventTick(self):
>         print 'Hello object EventTick'
>         self.OnTick()
>     def OnTick(self):
>
> class other(object):
>     def __init__(self):
>     def OnEvent(self):

You have an OnTick() in object but an OnEvent() in other.
I suspect you meant to have an OnTick() in both?

Alan G.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Duncan Gibson | 1 Jul 2004 10:40

Re: testing new style class properties using pyUnit ?


dyoo .at. hkn . eecs . berkeley . edu said:
> Something strikes me weird though: if you're testing the set/get stuff,
> why not modify your test to:
>
>      def testSet(self):
>          a = A_New()
>          self.assertEqual(0, a.x)
>          a.x = 1
>          self.assertEqual(1, a.x)

Yes, you are quite right: keep it simple, stupid!

In the actual original code I had the more contorted
           self.assertEqual(None, a.set_x(1))
because I wanted to do as much as possible within the pyUnit context
and also because the original setter did a bit more behind the scenes
than is obvious from this simplified example.

Cheers
Duncan

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane