Re: [Tutor] Do I have to initialize TKInter before I can use it?

2005-11-14 Thread Alex Hunsley
Nathan Pinno wrote:

> Hey all,
>  
> Do I have to initialize TKInter before I can use it, and if so, how 
> would I go about doing that?
>  
> Thanks,
> Nathan Pinno


Btw, your question would be a little more user-friendly if you don't 
post HTML, and don't post embedded images as well! (Not everyone has an 
email reader that renders HTML and graphics. And for those people, your 
email looks like a dogs dinner!)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] triangulation

2005-11-10 Thread Alex Hunsley
Alan Gauld wrote:

>>As in Pythagoras?
>>
>>
>
>  
>
>>Or as in triangulation on a 2D surface, navigation etc.?
>>
>>
>
>  
>
>>Or, do you mean radio triangulation by directional signal propagation
>>
>>
>
>  
>
>>Or, do you mean drawing a triangle in Tkinter?
>>
>>
>
>Or even triangulation of currency from EU currency to EU currency 
>via the euro?
>
>See:
>http://www.sysmod.com/eurofaq.htm#Triangulation
>
>Alan G.
>  
>
This Shi Mu character is a little frustrating. They won't even respond 
to peoples polite responses for clarification
Hit'n'run help requests.


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


Re: [Tutor] python watchfolder as daemon

2005-11-10 Thread Alex Hunsley
Frank Hoffsümmer wrote:

>Hello all,
>I found this gem of a python recipe that allows me to monitor a hierarchy of
>folders on my filesystem for additions / changes / removals of files: 
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/215418
>
>I would like to monitor a folder hierarchy using this script but now I
>wonder what would be the best way to have this watchfolder script running at
>all times in the background?
>
>nohup python watchfolder.py myfolder &
>
>? would that be suitable?? or is there a way to launch a process like that
>from python that detaches itself from the shell?
>  
>
Using nohup should certainly work fine.
Make sure you understand what happens to any standard (etc.) output  
from your script when you use it with nohup - i.e. read the nohup man page!
alex



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


Re: [Tutor] image

2005-11-09 Thread Alex Hunsley
Shi Mu wrote:

>any python module to calculate sin, cos, arctan?
>  
>
STFW. Have you heard of this site called "Google"?

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


Re: [Tutor] draw lines

2005-11-09 Thread Alex Hunsley
Danny Yoo wrote:

>On Sun, 6 Nov 2005, Shi Mu wrote:
>
>  
>
>>I have a list of random points: [[x0,y0],[x1,y1],...,[xn,yn]] how can I
>>use Tkinter to draw lines to connect them one by one based on the order
>>in the list?
>>
>>
>
>Do you know how to draw a single line in Tkinter?  Have you looked at the
>Canvas widget documentation?
>
>http://www.pythonware.com/library/tkinter/introduction/canvas.htm
>
>Next time, you may want to show us what you've done to try to solve the
>problem you have.
>
>For the past few questions, I have not been able to get an intuitive sense
>of why you're having trouble figuring out things from documentation.  All
>I see right now is that you have some new requirement, and then you ask
>the Tutor list for help.  It's the step in-between that is a mystery to
>me.
>  
>
I get the impression the OP isn't even trying to look anything up. They 
just seem to be firing random requirements at the tutor mailing list. 
(And calling them 'requirements' is being charitable.. :)



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


Re: [Tutor] triangulation

2005-11-09 Thread Alex Hunsley
Shi Mu wrote:

>is there any sample code of triangulation? many thanks!
>  
>
Yes, probably.


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


Re: [Tutor] testing: doctest and unittest

2005-11-08 Thread Alex Hunsley
Colin J. Williams wrote:

> Alex Hunsley wrote:
>
>> Regards testing, I've been playing with both the unittest 
>> (http://pyunit.sourceforge.net/pyunit.html) and doctest 
>> (http://docs.python.org/lib/module-doctest.html). I was wondering 
>> what peoples thoughts were on the effectiveness and convenience of 
>> one versus the other. It seems to me that doctest is good for quicky 
>> and straightforwards input/output tests for small units, whereas 
>> unittest would be good for dynamic or complicated testing.
>>
>> Where do you seasoned pythonites see unittest and doctest in relation 
>> to each other? Do you only use one or the other?
>>
>> ta,
>> alex
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>  
>>
> I looked at doctest and feel that it clutters the module text and so 
> would prefer unittest but I haven't yet got to formalizing my tests in 
> that way.
>
> See some of the numarray source as an example of clutter.  Some argue 
> that having the examples in the source is beneficial.  I agree but 
> feel that the clutter outweighs the benefit.

I also feel that the clutter aspect of doctest can be a little bit of a 
put off. I like the idea of the having the target code nicely seperate 
from the tests, and really thorough doctests could swamp the target code 
a little too much!
Plus, of course, if you write unittests, there are more options 
apparently available,  like using the graphical test runner, etc. 
doctest is simpler (not always necessarily a bad thing).

ta
alex


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


Re: [Tutor] overloading binary operator for mixed types: a no-no?

2005-11-08 Thread Alex Hunsley
[EMAIL PROTECTED] wrote:

>Alex,
>
>I assume you've looked at NumPy?
>  
>
Yup, I'm aware of it and it would do the job just fine (and faster too, 
probably). However, I'm happy writing my own code (+tests) for the 
moment - I'm getting more experience of writing stuff in Python. I may 
switch to NumPy or similar later!
thanks
alex

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


Re: [Tutor] Raw image display in a GUI window

2005-11-08 Thread Alex Hunsley
Alex Hunsley wrote:

> Marcin Komorowski wrote:
>
>> Hello,
>>
>> I want to use Python to do some experimentation with graphic 
>> processing/manipulation, and I am looking for a way to be able to 
>> manipulate individual pixels of the image, as well as display it in a 
>> GUI.  Ideal image representation would be something of the form of a 
>> two-dimensional array of tuples, each tuple containing the Red, Green 
>> and Blue components.
>>
>> I have looked at Tk and Tkinter, and there is a PhotoImage class that 
>> can define an image which can than be displayed in a Canvas widget, 
>> but the PhotoImage class seams to be doing a lot of extra work on the 
>> image, including gamma correction, etc.  I am interested in being 
>> able to display exactly the pixel values I set.
>>
>> Thank You all in advance,
>> Marcin  
>>
> How about PyUI?
> http://pyui.sourceforge.net/
> It may do what you're looking for...
> alex

To add to my previous comment have a look at PyGame too:
http://www.pygame.org/news.html

It's designed for games programming, and makes it a snap to load and 
display an image in a window! (and lots of other things, e.g. sprites 
and animation)

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


Re: [Tutor] Raw image display in a GUI window

2005-11-08 Thread Alex Hunsley
Kent Johnson wrote:

>Marcin Komorowski wrote:
>  
>
>>Thanks Kent, this looks promising.
>>Are you very familiar with the Python Imaging Library?  
>>
>>
>
>No, I have just used it for a few small things. I know it mostly by reputation.
>
>  
>
>>Can I pick your 
>>brains if I have questions?
>>
>>
>
>Best to ask questions to the list, I will answer the ones I can.
>
>Fredrik Lundh is the author of PIL, he answers questions on comp.lang.python, 
>so if you can't get the help you need here then try there.
>  
>
I've used PIL a little before and found it to be very useful! Make 
loading, saving and manipulating images programatticaly quite easy.

>Kent
>
>___
>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] Raw image display in a GUI window

2005-11-08 Thread Alex Hunsley
Marcin Komorowski wrote:

>Hello,
>
>I want to use Python to do some experimentation with graphic 
>processing/manipulation, and I am looking for a way to be able to manipulate 
>individual pixels of the image, as well as display it in a GUI.  Ideal image 
>representation would be something of the form of a two-dimensional array of 
>tuples, each tuple containing the Red, Green and Blue components.
>
>I have looked at Tk and Tkinter, and there is a PhotoImage class that can 
>define an image which can than be displayed in a Canvas widget, but the 
>PhotoImage class seams to be doing a lot of extra work on the image, 
>including gamma correction, etc.  I am interested in being able to display 
>exactly the pixel values I set.
>
>Thank You all in advance,
>Marcin 
>  
>
How about PyUI?
http://pyui.sourceforge.net/
It may do what you're looking for...
alex

>
>___
>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] interfaces and abstract classes in python

2005-11-08 Thread Alex Hunsley
Kent Johnson wrote:

>Alex Hunsley wrote:
>  
>
>>Oh yes, I'd always reply to the list in the very least; I was really 
>>just wondering what the etiquette was concerning emails also going back 
>>to the person you're reply to directly (as well as to the list). I ask 
>>because the list is set up so that it appears replies are also meant to 
>>go to the person you're replying to. It would seem to be more sensible 
>>if the emails sent out to the list had the 'from:' being the list 
>>address, rather than the actual sender; then hitting plain old reply 
>>would work (currently I have to hit 'reply all', otherwise it just 
>>emails the person I'm replying to).
>>
>>
>
>This is a frequent request, the reason is here:
>http://www.unicom.com/pw/reply-to-harmful.html
>  
>
thanks for that.
alex



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


[Tutor] testing: doctest and unittest

2005-11-08 Thread Alex Hunsley
Regards testing, I've been playing with both the unittest 
(http://pyunit.sourceforge.net/pyunit.html) and doctest 
(http://docs.python.org/lib/module-doctest.html). I was wondering what 
peoples thoughts were on the effectiveness and convenience of one versus 
the other. It seems to me that doctest is good for quicky and 
straightforwards input/output tests for small units, whereas unittest 
would be good for dynamic or complicated testing.

Where do you seasoned pythonites see unittest and doctest in relation to 
each other? Do you only use one or the other?

ta,
alex


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


Re: [Tutor] interfaces and abstract classes in python

2005-11-08 Thread Alex Hunsley
Kent Johnson wrote:

>Alex Hunsley wrote:
>  
>
>>Alan Gauld wrote:
>>
>>
>>
>>
>>>>Interfaces and abstract classes - I know they don't exist per se in 
>>>>Python. 
>>>>
>>>>
>>>First you need to define what you mean by the terms.
>>>Every class has an interface - it is the set of messages to which it 
>>>responds.
>>>  
>>>
>>Yup, I was thinking more in terms of the Java idea, whereby an interface 
>>is declared specifically and then a class claiming to implement it 
>>causes compilation problems if it doesn't properly implement it.
>>
>>
>
>No, there is nothing like this in Python. This is a form of static type 
>checking which is not part of Python. In general type errors are detected at 
>runtime in Python.
>  
>
Yes, I've come to realise this isn't the python way. Just getting my 
head around pythonland.

> 
>  
>
>>Btw, I notice this email list sends the emails with the originator as 
>>the sender, and CC'd to the tutor@python.org address. Is it standard 
>>here to reply to the email address of the sender of the message you're 
>>replying to, as well as the list itself, or should I be trimming out the 
>>sender email and just replying to the list only?
>>
>>
>
>I don't know if it's standard, but I reply just to the list. I see this list 
>as a kind of commons that benefits many, and I want all interactions to be on 
>list. I see my replies as a contribution to the list as much as to the 
>original questioner.
>  
>
Oh yes, I'd always reply to the list in the very least; I was really 
just wondering what the etiquette was concerning emails also going back 
to the person you're reply to directly (as well as to the list). I ask 
because the list is set up so that it appears replies are also meant to 
go to the person you're replying to. It would seem to be more sensible 
if the emails sent out to the list had the 'from:' being the list 
address, rather than the actual sender; then hitting plain old reply 
would work (currently I have to hit 'reply all', otherwise it just 
emails the person I'm replying to).

cheers
alex


>Kent
>
>  
>


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


Re: [Tutor] any code to draw parabola or curve?

2005-11-08 Thread Alex Hunsley
Shi Mu wrote:

>any code to draw parabola or curve?
>  
>
That question is so general and vague it's either unanswerable, or very 
easy to answer.
I'll try the 'very easy' answer: yes, there is probably code somewhere 
to draw a parabola or curve. Have you tried making a start on this 
yourself? Did you run into a problem?
Or perhaps: did you try googling for 'draw parabola' or 'parabola equation'?

If you've not made a start on attempting this problem, and need help, 
try breaking down your help request into sub-requests. Like, you might 
be wondering what the algorithm or maths is for drawing a 
parabola/curve. Or you might be wondering about how to display a curve 
on screen. (Ascii output? Generating an image file like a gif? Output to 
a window using a GUI toolkit like wxPython?) Or are you just expecting 
someone to post fully functional code from a vague request?

The following is highly recommended reading. It's called "How to ask 
questions the smart way":
http://www.catb.org/~esr/faqs/smart-questions.html

best of luck!
alex


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


[Tutor] overloading binary operator for mixed types: a no-no?

2005-11-08 Thread Alex Hunsley
I'm writing a Vector class (think Vector as in the mathematical vector)...
A critical snippet is as follows:

class Vector(lister.Lister):
def __init__(self, *elems):
# ensure that we create a list, not a tuple
self.elems = list(elems)

def __add__(self, other):
return map(lambda x,y: x + y , self.elems, other.elems)

def __mult__(self, other):
return map(lambda x,y: x * y , self.elems, [other])


The overloading of + (add) works fine:

  >>> a=Vector(1,2,3)
  >>> a+a
  [2, 4, 6]

But of course, I have problems with mult. When using vectors, it would 
seem to make sense to overload the * (multiply) operator to mean 
multiply a vector by a scalar as this would be the common usage in 
maths/physics. (I've made a seperate method call dotProduct for dot 
products for sake of clarity.)

Anyway, my multiply doesn't work of course:

  >>> a=Vector(1,2,3)
  >>> a * 2
  Traceback (most recent call last):
File "", line 1, in ?
  TypeError: unsupported operand type(s) for *: 'instance' and 'int'

... presumably because overloading binary operators like * requires that 
both operands be instances of the class in question!
My question is: is there any way to overload * for my Vector class so 
that notation like (a * 2) would work, and call __mult__ or similar? Or 
should I just bite the bullet and write a normal method called 
'multiply'? ('scale' would be better actually.)

thanks
alex




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


Re: [Tutor] interfaces and abstract classes in python

2005-11-08 Thread Alex Hunsley
Kent Johnson wrote:

>Alex Hunsley wrote:
>  
>
>>Interfaces and abstract classes - I know they don't exist per se in 
>>Python. But what are the closest analogues? I've found a few examples, 
>>e.g. for an abstract class the following page has a fairly common 
>>suggestion:
>>
>>http://www.norvig.com/python-iaq.html
>>
>>
>
>Interfaces are generally implicit in Python. For example the docs will 
>sometimes talk about 'file-like objects' which are just objects that implement 
>the same interface as a file object. 'iterable', 'iterator', 'sequence' and 
>'mapping' are similarly defined by convention or by explicit documentation but 
>not in the language itself. For example the 'iterator protocol' is defined 
>here:
>http://docs.python.org/lib/typeiter.html
>  
>
Yup, I've run into the __getitem__ etc. methods that you can overload 
which is pretty handy stuff.

>To define an abstract method I just raise NotImplementedError in the body of 
>the method.
>  
>
Ah, ok. This appears to be the pythonic way.

>There are a couple of more formalized ways to add support for explicit type 
>requirments to the language. This is a little different from what you asked - 
>these projects allow a client of an object to specify an interface (or 
>protocol) that must be supported by the object.
>PyProtocols http://peak.telecommunity.com/PyProtocols.html
>Zope Interfaces http://www.zope.org/Wikis/Interfaces/FrontPage
>  
>
I've had a look at these before and although they look relevant, I'm 
more interested in the core python language at the moment, and what that 
can do itself.

>PEP 246 formalizes this notion. It seems to be slated for inclusion in Python 
>2.5.
>http://www.python.org/peps/pep-0246.html
>  
>
This PEP looks like a good idea!
thanks
alex

>Kent
>
>  
>


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


Re: [Tutor] interfaces and abstract classes in python

2005-11-08 Thread Alex Hunsley
Alan Gauld wrote:

>> Interfaces and abstract classes - I know they don't exist per se in 
>> Python. 
>
>
> First you need to define what you mean by the terms.
> Every class has an interface - it is the set of messages to which it 
> responds.

Yup, I was thinking more in terms of the Java idea, whereby an interface 
is declared specifically and then a class claiming to implement it 
causes compilation problems if it doesn't properly implement it.

>
> An Abstract class is one which is not intended to be instantiated.
>
> class AbstractClassError(Exception): pass
>
> class Abstract:
>def __init__(self): raise AbstractClassError

Yes, this and the code below with it are very similar to the common 
idiom for abstract classes (in Python) that I see quite often.

>
>> But what are the closest analogues? I've found a few examples, 
>
>
> Assuming you mean Interface in the Microsoft/Java specific sense of 
> the term rather than the simple OOP sense, then an Interface class is 
> simply an abstract  class with empty methods.
>
> class InterfaceError(Exception): pass
>
> class Interface(Abstract):
>def myMethod(self): pass
>def myOther(self): raise InterfaceErrror
>
> Does that do what you want?

I presume the "def myMethod(self): pass" is just for an 'optional' part 
of the interface?

The above code does serve the purpose of making an interface more 
explicit, which is helpful. I have seen this use before and  I was just 
wondering if there was any other common ways to make interfaces more 
explicit. Thanks!

Btw, I notice this email list sends the emails with the originator as 
the sender, and CC'd to the tutor@python.org address. Is it standard 
here to reply to the email address of the sender of the message you're 
replying to, as well as the list itself, or should I be trimming out the 
sender email and just replying to the list only?
thanks,
alex





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


[Tutor] interfaces and abstract classes in python

2005-11-06 Thread Alex Hunsley
Interfaces and abstract classes - I know they don't exist per se in 
Python. But what are the closest analogues? I've found a few examples, 
e.g. for an abstract class the following page has a fairly common 
suggestion:

http://www.norvig.com/python-iaq.html

thanks!
alex

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