Re: [Tutor] OOP fundamentals

2005-09-20 Thread Ed Hotchkiss
I like that, I'm all over it like white on rice! Thanks.
 
On 9/20/05, János Juhász <[EMAIL PROTECTED]> wrote:
Hi Ed,last month I have found this beautifull sample about threads and sockets: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114642It helped me to a lot to understand how these can be used together on anOOP way.It helped me much better, than any hypothetical OOP samples about cars and
wheels, those really usefull just for programming teachers who never madeany real programm, but has to tell something about why OOP is good tolearn.It was so nice to read and understand a so clean code.
Probably it can help your understanding eighter.The other place where I feel OOP very natural is using wxPython.There is another recipe about portscanning with OOP and threading: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286240Yours sincerely,__János Juhász> Message: 5> Date: Mon, 19 Sep 2005 17:01:30 -0400
> From: Ed Hotchkiss <[EMAIL PROTECTED]>> Subject: Re: [Tutor] OOP fundamentals> To: Danny Yoo <[EMAIL PROTECTED]
>> Cc: Tutor > Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"> Thanks Danny! Tommorrow I am off to get "Programming for Python, 2nd> edition" and learn everything - all of it, before I even bother with
> Sockets. Afterall, I want python for EVERYTHING not just sockets and inet> based scripts/applications.> I realized that I need to take a step back, make port scanner a classthat> does nothing but really help me learn classes, then insert threading,
then> once that works, insert the actual sockets into their respective classdef> etc ... Thanks again ...> Next time I post, I'll have something either more abstract/theoryquestion,> or something that isn't quite so simple!
> Thanks again everyone thats been helping me out especially danny!> -edward> -- next part --> An HTML attachment was scrubbed...> URL: 
http://mail.python.> org/pipermail/tutor/attachments/20050919/41d24153/attachment.html___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor-- edward hotchkiss 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDEs

2005-09-20 Thread Cedric BRINER
what about eric3 ?
http://www.die-offenbachs.de/detlev/eric3.html

Ced.

-- 

Cedric BRINER
Geneva - Switzerland
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi,

I'd like to form a list of class instances. The following does not work 
(TextfieldLong, Textarea, TextfieldShort etc being class names):

fields = [
TextfieldLong(name='title', label='Seitentitel', value=''),
Textarea(name='content', label='Inhalt', value=''),
ShortField(name='mother_id', label='MotherID', value=1)
]

Is there a way to create such a list?

Thanks in advance,

Jan
-- 
Any sufficiently advanced technology is indistinguishable from a Perl script. - 
Programming Perl
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi,

Jan Eden wrote on 20.09.2005:

>Hi,
>
>I'd like to form a list of class instances. The following does not work 
>(TextfieldLong, Textarea, TextfieldShort etc being class names):
>
>fields = [
>TextfieldLong(name='title', label='Seitentitel', value=''),
>Textarea(name='content', label='Inhalt', value=''),
>ShortField(name='mother_id', label='MotherID', value=1)
>]
>

Just found that it *does* work, but that I have to define the classes above the 
list assignment. Why is that? Why would Python not find the classes within the 
same file?

TIA,

Jan
-- 
Life's unfair - but root password helps!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of class instances

2005-09-20 Thread Kent Johnson
Jan Eden wrote:
>>I'd like to form a list of class instances. The following does not work 
>>(TextfieldLong, Textarea, TextfieldShort etc being class names):
>>
>>   fields = [
>>   TextfieldLong(name='title', label='Seitentitel', value=''),
>>   Textarea(name='content', label='Inhalt', value=''),
>>   ShortField(name='mother_id', label='MotherID', value=1)
>>   ]
>>   
> 
> 
> Just found that it *does* work, but that I have to define the classes above 
> the list assignment. Why is that? Why would Python not find the classes 
> within the same file?

Class definitions are executable statements that bind the name of the class to 
a class object. Before the definition is executed the class is undefined, like 
any other assignment. For example you wouldn't expect this to work:

values = [x, y, z]
x=1
y=2
z=3

Your code suffers from the same problem. When you say
class foo:
  pass

this means, roughly,
foo = (the result of executing the class body)
and the name 'foo' is not defined until this executes.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of class instances

2005-09-20 Thread Orri Ganel
As a side-note, unless you're okay with only being able to access those 
instance variables through the fields list (ie fields[0], fields[1], 
fields[2]), you may want to actually name them first.

Jan Eden wrote:

>Hi,
>
>Jan Eden wrote on 20.09.2005:
>
>  
>
>>Hi,
>>
>>I'd like to form a list of class instances. The following does not work 
>>(TextfieldLong, Textarea, TextfieldShort etc being class names):
>>
>>   fields = [
>>   TextfieldLong(name='title', label='Seitentitel', value=''),
>>   Textarea(name='content', label='Inhalt', value=''),
>>   ShortField(name='mother_id', label='MotherID', value=1)
>>   ]
>>   
>>
>>
>
>Just found that it *does* work, but that I have to define the classes above 
>the list assignment. Why is that? Why would Python not find the classes within 
>the same file?
>
>TIA,
>
>Jan
>  
>


-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List of class instances

2005-09-20 Thread Jan Eden
Hi,

Orri Ganel wrote on 20.09.2005:

>As a side-note, unless you're okay with only being able to access
>those instance variables through the fields list (ie fields[0],
>fields[1], fields[2]), you may want to actually name them first.

Yes, I am fine with that - I actually prefer to have a sorted list instead of a 
dictionary. I'll always access them like

for field in fields:
...

Thanks,

Jan
-- 
I'd never join any club that would have the likes of me as a member. - Groucho 
Marx
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with matplot

2005-09-20 Thread nephish
hey there,
anyone have any luck getting up and running with matplot-lib on debian?
from the website, i followed the instructions to get it with apt. but 
something is messed up in the dependencies.

i get this
import pylab

Traceback (most recent call last):
  File "", line 1, in -toplevel-
import pylab
  File "/usr/lib/python2.3/site-packages/pylab.py", line 1, in -toplevel-
from matplotlib.pylab import *
  File "/usr/lib/python2.3/site-packages/matplotlib/pylab.py", line 198, 
in -toplevel-
from axes import Axes, PolarAxes
  File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 13, 
in -toplevel-
from artist import Artist, setp
  File "/usr/lib/python2.3/site-packages/matplotlib/artist.py", line 4, 
in -toplevel-
from transforms import identity_transform
  File "/usr/lib/python2.3/site-packages/matplotlib/transforms.py", line 
189, in -toplevel-
from _transforms import Value, Point, Interval, Bbox, Affine
  File "/usr/lib/python2.3/site-packages/matplotlib/_transforms.py", 
line 11, in -toplevel-
from matplotlib._nc_transforms import *
ImportError: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.4' not found 
(required by /usr/lib/python2.3/site-packages/matplotlib/_nc_transforms.so)

i have already installed libstdc++6, and i dont really know what version 
GLIBCXX_3.4.4 means.

anyone have an idea?

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread Danny Yoo


> anyone have any luck getting up and running with matplot-lib on debian?
> from the website, i followed the instructions to get it with apt. but
> something is messed up in the dependencies.

Check with the Debian folks about this one; the problem you're running
into looks really specific to the way Debian has packaged libstdc++6.
This topic isn't really one that folks on Tutor will necessarily have
competence in.  Instead, try the debian-python mailing list:

http://lists.debian.org/debian-python/

I did try to Google what was going on, and there's a thread in:

http://lists.badopi.org/pipermail/comandob/Week-of-Mon-20050801/011594.html

Unfortunately, I'm not quite sure what they're saying, given that it's not
English.  *grin* But I suspect that someone intimate with the Debian
packaging system would know what was going on here.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread nephish
Danny Yoo wrote:

>  
>
>>anyone have any luck getting up and running with matplot-lib on debian?
>>from the website, i followed the instructions to get it with apt. but
>>something is messed up in the dependencies.
>>
>>
>
>Check with the Debian folks about this one; the problem you're running
>into looks really specific to the way Debian has packaged libstdc++6.
>This topic isn't really one that folks on Tutor will necessarily have
>competence in.  Instead, try the debian-python mailing list:
>
>http://lists.debian.org/debian-python/
>
>I did try to Google what was going on, and there's a thread in:
>
>http://lists.badopi.org/pipermail/comandob/Week-of-Mon-20050801/011594.html
>
>Unfortunately, I'm not quite sure what they're saying, given that it's not
>English.  *grin* But I suspect that someone intimate with the Debian
>packaging system would know what was going on here.
>
>
>  
>
thanks for the links, i will dig some more, i know this isnt really a 
python issue, but i thought that since debian is popular, matplot is 
most peoples recommendation for graphing, and it is for python...
figgured i may not be the only one to run into this brick wall.
anyway, thanks for your time, maybe an upgrade to 'testing' will help 
for this package.
ok, thanks much.
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread Danny Yoo
> >Check with the Debian folks about this one; the problem you're running
> >into looks really specific to the way Debian has packaged libstdc++6.
> >This topic isn't really one that folks on Tutor will necessarily have
> >competence in.  Instead, try the debian-python mailing list:
> >
> >http://lists.debian.org/debian-python/
> >
> thanks for the links, i will dig some more, i know this isnt really a
> python issue, but i thought that since debian is popular, matplot is
> most peoples recommendation for graphing, and it is for python...


True, but let's try to maintain the topical "Learn to program"  nature of
the mailing list.  I really want to try to avoid turning Tutor into the
"Help with installing package X on system Y" mailing list.  We'll try to
help out as best we can on such questions, of course, but this is probably
not the best place to ask this.

I guess I'm really trying to say: let's try to keep Tutor from turning
into comp.lang.python.  *grin*

>From the Google searches I've done so far, this problem really doesn't
look specific to Python, but basically to anything that links up with the
libstdc++ library on both Debian and Red Hat systems.  It's not exclusive
to Python, and since it's so far reaching, I have to assume that it's the
particular Linux distribution's faul... er, responsibility.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread nephish
Danny Yoo wrote:

>>>Check with the Debian folks about this one; the problem you're running
>>>into looks really specific to the way Debian has packaged libstdc++6.
>>>This topic isn't really one that folks on Tutor will necessarily have
>>>competence in.  Instead, try the debian-python mailing list:
>>>
>>>   http://lists.debian.org/debian-python/
>>>
>>>  
>>>
>>thanks for the links, i will dig some more, i know this isnt really a
>>python issue, but i thought that since debian is popular, matplot is
>>most peoples recommendation for graphing, and it is for python...
>>
>>
>
>
>True, but let's try to maintain the topical "Learn to program"  nature of
>the mailing list.  I really want to try to avoid turning Tutor into the
>"Help with installing package X on system Y" mailing list.  We'll try to
>help out as best we can on such questions, of course, but this is probably
>not the best place to ask this.
>
>I guess I'm really trying to say: let's try to keep Tutor from turning
>into comp.lang.python.  *grin*
>
>>From the Google searches I've done so far, this problem really doesn't
>look specific to Python, but basically to anything that links up with the
>libstdc++ library on both Debian and Red Hat systems.  It's not exclusive
>to Python, and since it's so far reaching, I have to assume that it's the
>particular Linux distribution's faul... er, responsibility.
>
>
>  
>
he he he. yeah, i admit, i have been breezing over distrowatch.
sorry about the clutter. wont happen again. i don't know where i would
be without this list.
cheers,
sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do you organize code snippets?

2005-09-20 Thread Mike Hansen
> 
> 
> Subject:
> Re: [Tutor] How do you organize code snippets?
> From:
> Poor Yorick <[EMAIL PROTECTED]>
> Date:
> Sun, 18 Sep 2005 13:28:10 -0400
> 
> CC:
> tutor@python.org
> 
> 
> List wrote:
> 
>> Is there a way of naming or organizing snippets that might help? (For 
>> example, file i/o snippets, text processing snippets, etc.)
>>
> 
> If you really want to have fun, you can use LEO, 
> http://webpages.charter.net/edreamleo/front.html to store your code 
> snippets and generate files from them.  The fun part is that you can 
> clone each node which may contain some code and move the clone to a 
> different point in the hierarchy.  When you change your code in any of 
> the clones, it gets changed in all of the clones.  At the most basic 
> level, you can use LEO as on outliner, like Treepad.  If you decide to 
> get more complicated, you can use LEO as a templating tool to generate 
> your resulting .py files from your snippets.
> 
> -- 
> Poor Yorick

I'm facing a similar problem. I was hoping to find some sort of snippets 
plug-in 
for VIM, but haven't come across anything. I found a couple of open source 
snippet database programs for Windows. One kept crashing on my machine and the 
other was kind of klunky. LEO looks promising. I'm reading through the tutorial 
now.

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do you organize code snippets?

2005-09-20 Thread DogWalker
"Mike Hansen" <[EMAIL PROTECTED]> said:

[...]

http://freshmeat.net/projects/pysnippet/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Threading in a for loop

2005-09-20 Thread Bill Burns
I've got a few questions regarding Threading. I've never used threads
before and I want to make sure I'm doing it correctly ;-)

I have a GUI app and it processes Tiff files to PDF (or PostScript). The
GUI has a ListBox which the user populates with files to convert. You
click on a Button and the file conversion starts. When all the files
have been converted, the ListBox items (the files) are cleared.

Initially, you had no way of knowing what was going on until all the
files where cleared from the ListBox.

So I thought of creating threads in the 'for loop' and displaying the
name of each file in the statusBar of the GUI (as they are being
processed).

Here's my method which takes the files in the ListBox and sends them off
to my Convert() class (self.convert = Convert()).

def convertTiff2PDF(self):
 from time import time
 #Let's see how long this takes... I saw Kent do this on the
 #Python Tutor list before :-)
 start = time()
 #Grab a tuple which contains width & length
 sizes = self.getPaperSize()
 width = sizes[0]
 length = sizes[1]
 #Count the number of files in the ListBox
 fileCount = self.fileListBox.count()
 for index in range(fileCount):
 #Get each filename
 filenames = str(self.fileListBox.text(index))
 #Setup the worker thread and send the filenames in
 worker = WorkerThread(self, filenames)
 #Start threading
 worker.start()
 #Send each file to be converted
 self.convert.tiff2pdf(width, length, filenames)
 #We're done, so clear the ListBox
 self.fileListBox.clear()
 #Check the time again
 end = time()
 msg = '%s Files Processed in %0.3f Seconds.' % (fileCount,
(end-start))
 #Grab the statusBar and insert the message
 statusBar = self.statusBar()
 statusBar.message(msg, 0)


And here's what I'm doing in my Thread class:

class WorkerThread(Thread):
 """Thread class."""
 def __init__(self, parent, files):
 Thread.__init__(self)
 self.parent = parent
 self.files = files

 def run(self):
 statusBar = self.parent.statusBar()
 msg = 'Processing: %s, please wait.' % (self.files)
 statusBar.message(msg, 100)
 time.sleep(1)


Am I doing this threading properly? Is it 'OK' to start multiple threads
like this (in the for loop)? It's possible that a user could put 'many'
files into the ListBox, by 'many' I mean 100-200 files.

Thanks for your help.

Bill


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread Bernard Lebel
Hello,

I have this little math problem. I have this formula from wich I get a
dot product between two vectors.

cos(ß) = A.B / |A|.|B| = -0.0634
So this would give me radians, right?

Then if I use

math.degrees( -0.0634 )

This gives me a value of -3.6325524211294193.

However I have a book in front of me who says I should get a value of
93.635 degrees. m

Btw, in the book, the equation is written

ß = cos-1(-0.0634) = 93.635, where -1 is actually an exponent. Maybe
I'm just interpreting this wrong?



Thanks
Bernard
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread Kent Johnson
Bernard Lebel wrote:
> Hello,
> 
> I have this little math problem. I have this formula from wich I get a
> dot product between two vectors.
> 
> cos(ß) = A.B / |A|.|B| = -0.0634
> So this would give me radians, right?

No, it's the cosine of ß, which has no units (a cosine is a ratio of two 
lengths)

> 
> Then if I use
> 
> math.degrees( -0.0634 )
> 
> This gives me a value of -3.6325524211294193.
> 
> However I have a book in front of me who says I should get a value of
> 93.635 degrees. m
> 
> Btw, in the book, the equation is written
> 
> ß = cos-1(-0.0634) = 93.635, where -1 is actually an exponent. Maybe
> I'm just interpreting this wrong?

The -1 means inverse. You have cos(ß) = -0.0634 - you want to find the angle 
whose cosine is -0.0634, i.e. (inverse cosine)(-0.0634). Another name for cos-1 
is arccosine. In Python it is math.acos():
 >>> import math
 >>> math.acos(-0.0634)
1.6342388771557625
 >>> math.degrees(_)
93.634990377223801

Kent
> 
> 
> 
> Thanks
> Bernard
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread R. Alan Monroe
> Bernard Lebel wrote:

>  >>> import math
>  >>> math.acos(-0.0634)
> 1.6342388771557625
>  >>> math.degrees(_)  <--- in all my time on tutor
 I have never noticed
 this underscore trick
 before
> 93.634990377223801

That's quite handy.

Alan

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread John Fouhy
On 21/09/05, R. Alan Monroe <[EMAIL PROTECTED]> wrote:
> >  >>> math.degrees(_)  <--- in all my time on tutor
>  I have never noticed
>  this underscore trick
>  before

I'm not a big fan of it, actually.  It smells of Perl and those opaque
one-liners that make use of implicit functions implicitely setting
implicit variables...

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread Nathan Coulter
John Fouhy wrote:
> On 21/09/05, R. Alan Monroe <[EMAIL PROTECTED]> wrote:
> 
>>> >>> math.degrees(_)  <--- in all my time on tutor
>>
>> I have never noticed
>> this underscore trick
>> before
> 
> 
> I'm not a big fan of it, actually.  It smells of Perl and those opaque
> one-liners that make use of implicit functions implicitely setting
> implicit variables...
> 

It also only works in *interactive* interpreters. -- Poor Yorick
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread Kent Johnson
John Fouhy wrote:
> On 21/09/05, R. Alan Monroe <[EMAIL PROTECTED]> wrote:
> 
>>> >>> math.degrees(_)  <--- in all my time on tutor
>>
>> I have never noticed
>> this underscore trick
>> before
> 
> 
> I'm not a big fan of it, actually.  It smells of Perl and those opaque
> one-liners that make use of implicit functions implicitely setting
> implicit variables...

I'm actually not much of a fan either - it's too easy to lose what I wanted by 
doing another step, then it's too late. And I usually don't use it on tutor 
because I think it is a bit obscure. This time I wondered if anyone would 
notice :-)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Maths: getting degrees from radians (or am I wrong?)

2005-09-20 Thread Terry Carroll
On Tue, 20 Sep 2005, R. Alan Monroe wrote:

> >  >>> math.degrees(_)  <--- in all my time on tutor
>  I have never noticed
>  this underscore trick
>  before


That *is* cool.

I've usually done something like:

 >>> a+ 3*b +(5*ht/9) * 32
 9936254.2

Then use the up-arrow key to get

 >>> a+ 3*b +(5*ht/9) * 32

and edit it toL

 >>> x = a+ 3*b +(5*ht/9) * 32
 >>> foo(x)

The underscore's a nice stepsaver.  And limiting it to the interpreter 
avoids perlish abuse.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor