[Tutor] Python persistent webserver?

2005-11-08 Thread Howard Kao
Hi all,

I know the subject is confusing but I don't know how to describe what
I would like to ask concisely.

Basically I would like to have a program (or server or whatever) take
an HTTP POST method (which contains some information, maybe even an
XML file) from a client, process these XML/information, and then
generate an XML to send back to the client.

Currently the environment it has to be done under is Apache on Linux. 
I am thinking that it may have to be a persistent running program... 
However it seems a daunting task for a Python noob like me.

Preferably it doesn't need threading and need not to be sophiscated at
all, as long as it can take the request, process info and send stuff
back to a client.

I have no idea how to do this at all and couldn't find much
information.  The Base, Simple, CGI HTTPServer modules all seem a
little lacking , but that's probably due to my lack of py-fu to start
with...   Any suggestions would be appreciated.  Many thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TKinter Question

2005-11-08 Thread Michael Lange
On Tue, 08 Nov 2005 00:10:16 -0600
Rob Dowell <[EMAIL PROTECTED]> wrote:

> Just a quick TKinter question. Is it possible to have custom 
> frames/widgets? In other words can I customize the way that the GUI 
> looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I 
> was just wondering if it was possible and if it is possible then where I 
> might get some information on how to do it. Thank you very much, Rob.
> 

Hi Rob,

I'm not sure what you mean with "beveled/raised edges" , maybe setting the 
widget's
relief to GROOVE or RIDGE does what you want?
Rounded corners are much more complicated; you will probably need the shape 
extension for Tk
which adds non-rectangular window support to Tk.
A version of shape that works with unix systems is included in the tkdnd drag 
and drop extension
(http://sourceforge.net/projects/tkdnd); I wrote a Tkinter wrapper for tkdnd 
(http://www.8ung.at/klappnase/TkinterDnD/TkinterDnD.html)
that makes it possible to use tkdnd from python. If you need windows support, 
you can try
a newer version of shape (http://www.cs.man.ac.uk/~fellowsd/tcl/shapeidx.html) 
that seems to support
windows platforms, too.

Regards

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


Re: [Tutor] image

2005-11-08 Thread Shi Mu
any python module to calculate sin, cos, arctan?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python persistent webserver?

2005-11-08 Thread Kent Johnson
Howard Kao wrote:
> Basically I would like to have a program (or server or whatever) take
> an HTTP POST method (which contains some information, maybe even an
> XML file) from a client, process these XML/information, and then
> generate an XML to send back to the client.
> 
> Currently the environment it has to be done under is Apache on Linux. 
> I am thinking that it may have to be a persistent running program... 
> However it seems a daunting task for a Python noob like me.

You can do this with a Python CGI program that runs behind Apache. Apachee will 
be the 'persistent running program'. Your CGI will be invoked with each POST 
request. Look at the CGI module docs and google for 'python cgi' for more 
information.

> 
> Preferably it doesn't need threading and need not to be sophiscated at
> all, as long as it can take the request, process info and send stuff
> back to a client.

With a CGI all the sophisticated stuff is handled by Apache.

Kent

-- 
http://www.kentsjohnson.com

___
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


Re: [Tutor] Percentage

2005-11-08 Thread Johan Geldenhuys




Now that I have the answer (16.801), How do I round it of
to 16.80 ? I only need it to be to the closest 1/100.

TIA

Jorge Godoy wrote:

  Frank Moore <[EMAIL PROTECTED]> writes:

  
  
Johan,

You could try:

percentage = (42 * 250)/100

This gives the answer 105.

  
  
And that sounds weird, doesn't it?  42 is smaller than 250, so I'd expect it
to be less than 100% of the value...  In fact, it is 

  
  

  
42.0/250

  

  
  0.16801
  
  

  
(42.0/250)*100

  

  
  16.801
  
  
I suspect the problem is due to the fact that Python does integer division by
default: 

  
  

  
42/250

  

  
  0
  
  
So, how to make it generic?

  
  

  
a = 42
b = 250
a / b

  

  
  0
  
  

  
float(a)/b

  

  
  0.16801
  
  
One of the members has to be a floating point so that floating point division
is performed instead of integer division.


Be seeing you,
  



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


[Tutor] any code to draw parabola or curve?

2005-11-08 Thread Shi Mu
any code to draw parabola or curve?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] image

2005-11-08 Thread Kent Johnson
Shi Mu wrote:
> any python module to calculate sin, cos, arctan?

The index to the Library Reference has the answer to this question...

Kent

-- 
http://www.kentsjohnson.com

___
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


[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] 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


Re: [Tutor] Percentage

2005-11-08 Thread Jorge Godoy
Johan Geldenhuys <[EMAIL PROTECTED]> writes:

> Now that I have the answer (16.801), How do I round it of to 16.80
>  ? I only need it to be to the closest 1/100.

>>> print "%.2f" % 16.801
16.80
>>> a = 16.80001
>>> b = "%.2f" % a
>>> b
'16.80'
>>> float(b)
16.801
>>> str(float(b))
'16.8'
>>> 

(The reason for the '0001' is because of the numeric base used to
represent data -- binary -- and the numeric base I'm requesting the answer to
be in -- decimal.)


Be seeing you,
-- 
Jorge Godoy  <[EMAIL PROTECTED]>

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


Re: [Tutor] Percentage

2005-11-08 Thread Johan Geldenhuys




Thanks, that helps.


Jorge Godoy wrote:

  Johan Geldenhuys <[EMAIL PROTECTED]> writes:

  
  
Now that I have the answer (16.801), How do I round it of to 16.80
 ? I only need it to be to the closest 1/100.

  
  
  
  

  
print "%.2f" % 16.801

  

  
  16.80
  
  

  
a = 16.80001
b = "%.2f" % a
b

  

  
  '16.80'
  
  

  
float(b)

  

  
  16.801
  
  

  
str(float(b))

  

  
  '16.8'
  
  
(The reason for the '0001' is because of the numeric base used to
represent data -- binary -- and the numeric base I'm requesting the answer to
be in -- decimal.)


Be seeing you,
  



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


Re: [Tutor] interfaces and abstract classes in python

2005-11-08 Thread Kent Johnson
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.
 
> 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.

Kent

-- 
http://www.kentsjohnson.com

___
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


[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 Kent Johnson
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

-- 
http://www.kentsjohnson.com

___
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 Kent Johnson
Alex Hunsley wrote:
> 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)

Don't you want this to return a new Vector, rather than a list? So for example 
you can add three vectors a + b + c?

Instead of defining your own function, you can use operator.add(). So I would 
write this as
  return Vector(map(operator.add, self.elems, other.elems))

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

This could be map(lambda x: x * other, self.elems) or [ x * other for x in 
self.elems ]

> 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!

No, actually it is because you have misspelled __mul__!

You might also want to implement __rmul__() so you can write 2 * a. See this 
page for a list of all special methods for numeric types:
http://docs.python.org/ref/numeric-types.html

Do you know about Numeric and numpy? They are high-performance implementations 
of arrays that support operations like these. You should probably look into 
them.

Kent

-- 
http://www.kentsjohnson.com

___
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


Re: [Tutor] Python persistent webserver?

2005-11-08 Thread Frank Bloeink
Hi,

maybe you can have a look at twisted http://twistedmatrix.com , which is
an "event-driven network framework". I think you could easily build your
own server to handle your requests, you don't even need an apache
webserver for that.
Just have a look, there's some documentation/tutorials out there and
there's even a book on the framework called "Twisted Network Programming
Essentials" which I'm working through atm.

On Tue, 2005-11-08 at 17:32 +0800, Howard Kao wrote:
> Hi all,
> 
> I know the subject is confusing but I don't know how to describe what
> I would like to ask concisely.
> 
> Basically I would like to have a program (or server or whatever) take
> an HTTP POST method (which contains some information, maybe even an
> XML file) from a client, process these XML/information, and then
> generate an XML to send back to the client.
> 
> Currently the environment it has to be done under is Apache on Linux. 
> I am thinking that it may have to be a persistent running program... 
> However it seems a daunting task for a Python noob like me.
> 
> Preferably it doesn't need threading and need not to be sophiscated at
> all, as long as it can take the request, process info and send stuff
> back to a client.
> 
> I have no idea how to do this at all and couldn't find much
> information.  The Base, Simple, CGI HTTPServer modules all seem a
> little lacking , but that's probably due to my lack of py-fu to start
> with...   Any suggestions would be appreciated.  Many thanks!
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


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


[Tutor] Raw image display in a GUI window

2005-11-08 Thread Marcin Komorowski
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 


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


Re: [Tutor] testing: doctest and unittest

2005-11-08 Thread Colin J. Williams
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.

Colin W.

Colin W.
___
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


[Tutor] Python and Semantic Web

2005-11-08 Thread Matt Williams
Dear List,

Does anyone know of any python semweb tools? I'm especially interested
in tools to build and handle ontologies. I've come across CWM (built by
Tim BL) but not that much else. I'd be really interested in anything
that can interface with a DIG reasoner.

Really, I'm looking for a pythonic version of something like Protege or
SWOOP

Thanks,
Matt
-- 
Dr. M. Williams MRCP(UK)
Clinical Research Fellow
Cancer Research UK
+44 (0)207 269 2953
+44 (0)7834 899570
http://acl.icnet.uk/~mw
http://adhominem.blogspot.com

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


Re: [Tutor] Python and Semantic Web

2005-11-08 Thread bob
At 08:19 AM 11/8/2005, Matt Williams wrote:
>Dear List,
>
>Does anyone know of any python semweb tools? I'm especially interested
>in tools to build and handle ontologies. I've come across CWM (built by
>Tim BL) but not that much else. I'd be really interested in anything
>that can interface with a DIG reasoner.
>
>Really, I'm looking for a pythonic version of something like Protege or
>SWOOP

Acronym Limit Error! That takes the record for Unknown Acronym/Term 
Density. So I can't be of any help. I hope there are some on this list who 
recognize and can help.

Otherwise please expand some of the concepts for the rest of us.


>Thanks,
>Matt
>--
>Dr. M. Williams MRCP(UK)
>Clinical Research Fellow
>Cancer Research UK
>+44 (0)207 269 2953
>+44 (0)7834 899570
>http://acl.icnet.uk/~mw
>http://adhominem.blogspot.com
>
>___
>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 Kent Johnson
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.

Take a look at Python Imaging Library http://www.pythonware.com/products/pil/
It has functions for manipulating images and it interfaces to Tkinter.

Kent

-- 
http://www.kentsjohnson.com

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


[Tutor] [OTAnn] Feedback

2005-11-08 Thread shenanigans
I was interested in getting feedback from current mail group users.We have mirrored your mail list in a new application that provides a more aggregated and safe environment which utilizes the power of broadband.Roomity.com v 1.5 is a web 2.01 community webapp. Our newest version adds broadcast video and social networking such as favorite authors and an html editor.It?s free to join and any feedback would be appreciated.S.--Broadband interface (RIA) + mail box saftey = Python_Tutor_List.roomity.com*Your* clubs, no sign up to read, ad supported; try broadband internet. ~~1131468997277~~--___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Who called me?

2005-11-08 Thread Bill Campbell
Is there a way in python for a method to determine its parent?

In particular, I'm working with SimpleXMLRPCServer, and would
like to be able to find the client_address in the routine that
has been dispatched.  I know that client_address is an attribute
of the handler class instance, but don't know how to get to that.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
UUCP:   camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

My brother sent me a postcard the other day with this big satellite photo
of the entire earth on it. On the back it said: ``Wish you were here''.
-- Steven Wright
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] lists and strings

2005-11-08 Thread Mike Haft
Hello,
 I've been working on a problem and have now sorted most of it (thanks
to some help from the list).

All the ways of writing data to a file I know keep telling me that lists
can't be written to the file. I'm trying to convert data from one set of
files into files of a different format. But the easiest way to get the
data from the first set of files is in a list(s).

So, is there any way to convert lists to strings? Or a way to write lists
to a file?

Thanks

Mike

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


Re: [Tutor] Python and Semantic Web

2005-11-08 Thread Matt Williams
Mea Culpa, Mea Culpa, Mea Maxima Culpa (or, MCMCMMC to repeat my sin of
poly-acronymony.

Semantic Web - (loosely) the idea of incorporating semantic information
in the WWW, so it becomes machine understandable (rather than just
parsable).

CWM is Tim Berners-Lee's (and others) tool to handle ontologies. I think
it has some rules in-built, but for reasons of efficiency, most ontology
tools communicte with external Description Logic Reasoners via the DIG
(Desc. Logic Implementation Group) interface, which is http/XML based.

Much of the semweb stuff is OWL (Web Ontology Language - need to be a
Winnie The Pooh fan to get the acronym) based. OWL is a layer that lies
on top of RDF (which in turn, lies on top of XML). In general, yu build
an ontology in OWL, and then interface with a reasoner to infer more
info. about the model.

The two big ontology building tools are Protege (with the Protege OWL
plugin) and SWOOP, but both are Java based.

HTH.
Matt


-- 
Dr. M. Williams MRCP(UK)
Clinical Research Fellow
Cancer Research UK
+44 (0)207 269 2953
+44 (0)7834 899570
http://acl.icnet.uk/~mw
http://adhominem.blogspot.com

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


Re: [Tutor] lists and strings

2005-11-08 Thread Hugo González Monteverde
Hi Mike,

Converting an (almost)arbitrary object into a string is what the Pickle 
module does. CPickle is faster. Take a look into into it in the docs.

Here's an example:

 >>> import cPickle
 >>> lala = [1, 2, 3, 'four', 'V']
 >>> lala
[1, 2, 3, 'four', 'V']


 >>> fileo = open('lala.pkl', 'w')
 >>> cPickle.dump(lala, fileo)
 >>> fileo.close()


 >>> fileo = open('lala.pkl', 'r')
 >>> serialized_data = fileo.read()
 >>> serialized_data
"(lp1\nI1\naI2\naI3\naS'four'\np2\naS'V'\na."

 >>> fileo.seek(0)
 >>> recovered = cPickle.load(fileo)
 >>> recovered
[1, 2, 3, 'four', 'V']
 >>>

See the docs and feel free to ask if there is some part oyu do not 
understand.

Hope it helps!

Hugo

Mike Haft wrote:
> Hello,
>  I've been working on a problem and have now sorted most of it (thanks
> to some help from the list).
> 
> All the ways of writing data to a file I know keep telling me that lists
> can't be written to the file. I'm trying to convert data from one set of
> files into files of a different format. But the easiest way to get the
> data from the first set of files is in a list(s).
> 
> So, is there any way to convert lists to strings? Or a way to write lists
> to a file?
> 
> Thanks
> 
> Mike
> 
> ___
> 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] lists and strings

2005-11-08 Thread Pujo Aji
yes it is...
 
convert list to string:
    L = [1,2,3]    L = [str(x) for x in L]    s = string.join(L,' ')    print len(s) 
convert list to a file
    myF = open(namaFile,"w")    for s in myList[:-1]:    myF.write(str(s)+"\n")    myF.write(str(myList[len(myList)-1]))    myF.close() 
 
Cheers,
pujo 
On 11/8/05, Mike Haft <[EMAIL PROTECTED]> wrote:
 
Hello,I've been working on a problem and have now sorted most of it (thanksto some help from the list). 
All the ways of writing data to a file I know keep telling me that listscan't be written to the file. I'm trying to convert data from one set offiles into files of a different format. But the easiest way to get the 
data from the first set of files is in a list(s).So, is there any way to convert lists to strings? Or a way to write liststo a file?ThanksMike___ 
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 Marcin Komorowski
Thanks Alex,

Do you know if I can find somewhere sample code that would, lets say, create 
a 100x100 image and display it?

Thanks,
Marcin
- Original Message - 
From: "Alex Hunsley" <[EMAIL PROTECTED]>
To: "Marcin Komorowski" <[EMAIL PROTECTED]>
Cc: "python-tutor" 
Sent: Tuesday, November 08, 2005 10:32 AM
Subject: Re: [Tutor] Raw image display in a GUI window


> 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 alan . gauld
>>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.

I guessed as much but that is an idea dreamt up by 
Microsoft for COM and picked up by Java to compensate 
for its lack of multiple inheritance. Since Python 
supports MI interfaces are neither useful nor 
desirable IMHO! Howeber they are being introduced 
in a future version I believe, mainly to appease 
the legions of Java programmers who think they 
are using OOP...

>>> 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?

Its an optional way of doing interfaces. If you 
take the ObjectiveC or lisp approach defining 
a null method is a valid implementation, the 
second case shows what to do if you want a 
failure for unimplemented methods. 

The 'pass' approach is most akin to mixin style 
programming used in Lisp to implement interfaces 
(as originally defined in the Flavors dialect 
of Lisp) and used in most Multiple Inheriting 
languages(including C++) where as the exception 
style is typically used in statically typed 
single inheritance languages.

Python can use the somple method of throwing an 
exception when a method is not found - this 
allows partial implementation of interfaces as 
is commonly found with "file-like2 interfaces 
where only open() and read() are actually 
coded not the whole gamut of file object methods.
This is a much more powerful mechanism since it 
reduces the code to be produced while still 
ensuring errors are thrown when actually necessary.

>>wondering if there was any other common ways 
>> to make interfaces more

Not that I know of, after all one of the strengths 
of Python (and other dynamic OOPLs) is that they 
on rely on static checking of types. 

>>here to reply to the email address of the sender of the message

In general yes, use Reply-All. It seems to prevent problems.

Alan G.


___
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 alan . gauld
Alex,

I assume you've looked at NumPy?

It has a bunch of math stuff written as a Python module in C.
So its fast and proven correct. (Lawrence Livermore Labs 
wrote it I believe)

It should do all the heavy lifting you need, 
and might even provide a full solution.

Just a thought,

Alan G.



___
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 Kent Johnson
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.

Kent

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


Re: [Tutor] Who called me?

2005-11-08 Thread Liam Clarke-Hutchinson
I believe only by explicitly passing a reference to the parent?

Liam Clarke-Hutchinson

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Bill Campbell
Sent: Wednesday, 9 November 2005 7:00 a.m.
To: Tutor
Subject: [Tutor] Who called me?


Is there a way in python for a method to determine its parent?

In particular, I'm working with SimpleXMLRPCServer, and would like to be
able to find the client_address in the routine that has been dispatched.  I
know that client_address is an attribute of the handler class instance, but
don't know how to get to that.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
UUCP:   camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

My brother sent me a postcard the other day with this big satellite photo of
the entire earth on it. On the back it said: ``Wish you were here''.
-- Steven Wright
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
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 alan . gauld
>
>>>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. 

Sounds like a job for the Python Image Library - PIL.

Alan G



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


Re: [Tutor] Who called me?

2005-11-08 Thread Kent Johnson
Bill Campbell wrote:
> Is there a way in python for a method to determine its parent?
> 
> In particular, I'm working with SimpleXMLRPCServer, and would
> like to be able to find the client_address in the routine that
> has been dispatched.  I know that client_address is an attribute
> of the handler class instance, but don't know how to get to that.

You can inspect the stack frame to find this out. Search the online cookbook 
for _getframe - I don't see one recipe that does exactly what you want but the 
pieces are there.
http://aspn.activestate.com/ASPN/Cookbook/Python

Kent

-- 
http://www.kentsjohnson.com

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


Re: [Tutor] [OTAnn] Feedback

2005-11-08 Thread Liam Clarke-Hutchinson
Oh dear. 

Is Web 2.01 like that whole Web 2 I've heard so much about, but better? Is
it the semantic web, but not so pedantic?



Liam Clarke-Hutchinson  

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of shenanigans
Sent: Wednesday, 9 November 2005 5:57 a.m.
To: tutor@python.org
Subject: [Tutor] [OTAnn] Feedback


I was interested in getting feedback from current mail group users.

We have mirrored your mail list in a new application that provides a more
aggregated and safe environment which utilizes the power of broadband.

Roomity.com v 1.5 is a web 2.01 community webapp. Our newest version adds
broadcast video and social networking such as favorite authors and an html
editor.

It?s free to join and any feedback would be appreciated.

S.




--
Broadband interface (RIA) + mail box saftey = Python_Tutor_List.roomity.com
*Your* clubs, no sign up to read, ad supported; try broadband internet.
~~1131468997277~~

--

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Who called me?

2005-11-08 Thread Andrei
Bill Campbell wrote:
> Is there a way in python for a method to determine its parent?
 > In particular, I'm working with SimpleXMLRPCServer, and would
 > like to be able to find the client_address in the routine that
 > has been dispatched.  I know that client_address is an attribute
 > of the handler class instance, but don't know how to get to that.

I'm not sure what you mean by its parent (also never worked with 
SimpleXMLRPCServer). Something like this?

 >>> class A(object):
... pass
 >>> class B(object):
... pass
 >>> def func(self):
... print self.__class__
 >>> A.f = func
 >>> B.f = func
 >>> a, b = A(), B()
 >>> a.f(), b.f()



-- 
Yours,

Andrei

=
Mail address in header catches spam. Real contact info:
''.join([''.join(s) for s in zip(
"[EMAIL PROTECTED] pmfe!Pes ontuei ulcpss  edtels,s hr' one oC.",
"rjc5wndon.Sa-re laed o s npbi ot.Ira h it oteesn edt C")])

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


Re: [Tutor] Who called me?

2005-11-08 Thread Colin J. Williams
Liam Clarke-Hutchinson wrote:

>I believe only by explicitly passing a reference to the parent?
>
>Liam Clarke-Hutchinson
>
>-Original Message-
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
>Of Bill Campbell
>Sent: Wednesday, 9 November 2005 7:00 a.m.
>To: Tutor
>Subject: [Tutor] Who called me?
>
>
>Is there a way in python for a method to determine its parent?
>
>In particular, I'm working with SimpleXMLRPCServer, and would like to be
>able to find the client_address in the routine that has been dispatched.  I
>know that client_address is an attribute of the handler class instance, but
>don't know how to get to that.
>
>Bill
>--
>INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
>UUCP:   camco!bill  PO Box 820; 6641 E. Mercer Way
>FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
>URL: http://www.celestial.com/
>
>My brother sent me a postcard the other day with this big satellite photo of
>the entire earth on it. On the back it said: ``Wish you were here''.
>   -- Steven Wright
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>A new monthly electronic newsletter covering all aspects of MED's work is now 
>available.  Subscribers can choose to receive news from any or all of seven 
>categories, free of charge: Growth and Innovation, Strategic Directions, 
>Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
>http://news.business.govt.nz for more details.
>
>
>
>
>http://www.govt.nz - connecting you to New Zealand central & local government 
>services
>
>Any opinions expressed in this message are not necessarily those of the 
>Ministry of Economic Development. This message and any files transmitted with 
>it are confidential and solely for the use of the intended recipient. If you 
>are not the intended recipient or the person responsible for delivery to the 
>intended recipient, be advised that you have received this message in error 
>and that any use is strictly prohibited. Please contact the sender and delete 
>the message and any attachment from your computer.
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
You might consider the inspect module.  See 3.11.4 in the Library 
Reference.  I think that the interpreter stack contains this information 
but have not used te module myself.

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


[Tutor] How to launch executable from a Python script??

2005-11-08 Thread Chris Irish
Hello all :)
I made a GUI app with pyGTK that I want to be able to launch a game I've 
downloaded from the pygame website when a button is clicked.  I was able 
to do this on a linux box since the file was a .py file, but I'm not 
sure how to do it on a windows box since the file is an executeable.  On 
linux I did this:

import os
olddir = os.getcwd()   #to keep a reference to the old 
directory to switch games later
os.chdir('spacinVaders-0.1')   #switch to the game's directory
os.spawnlp(os.P_NOWAIT, 'pythonw', 'pythonw', 'play.py')

and it would launch fine can someone help me with this??

Thanks in advance. Chris :P
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OTAnn] Feedback

2005-11-08 Thread Danny Yoo


On Wed, 9 Nov 2005, Liam Clarke-Hutchinson wrote:

> Is Web 2.01 like that whole Web 2 I've heard so much about, but better? Is
> it the semantic web, but not so pedantic?

That was bad, and the first spam I've seen on the list in a while.  I'm
blocking this joker off the mailing list now.

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


Re: [Tutor] Who called me?

2005-11-08 Thread Kent Johnson
Kent Johnson wrote:
> Bill Campbell wrote:
> 
>>Is there a way in python for a method to determine its parent?
>>
>>In particular, I'm working with SimpleXMLRPCServer, and would
>>like to be able to find the client_address in the routine that
>>has been dispatched.  I know that client_address is an attribute
>>of the handler class instance, but don't know how to get to that.
> 
> 
> You can inspect the stack frame to find this out. Search the online cookbook 
> for _getframe - I don't see one recipe that does exactly what you want but 
> the pieces are there.
> http://aspn.activestate.com/ASPN/Cookbook/Python

OK here is a simple module that shows callers on the stack. 

import sys

def showFrame(f):
print 'Name =', f.f_code.co_name
for k, v in f.f_locals.iteritems():
print '   ', k, '=', v
print

def whereAmI():
i=1
while True:
try:
f = sys._getframe(i)
showFrame(f)
i += 1
except ValueError:
break

if __name__ == '__main__':
def foo(a):
bar = 'baz'
zap = 3
whereAmI()

def bar():
foo(3)

bar()

When I run this it prints 

Name = foo
a = 3
bar = baz
zap = 3

Name = bar

Name = ?
bar = 
showFrame = 
__builtins__ = 
__file__ = F:\Tutor\ShowStack.py
sys = 
whereAmI = 
__name__ = __main__
foo = 
__doc__ =  Show stuff from the stack frame 


HOWEVER, I don't think this is a good solution to your problem - it's quite a 
fragile hack. Better would be to find a way to pass the information you need to 
your function. For example, from a quick look at the code for 
SimpleXMLRPCServer, it looks like you could subclass SimpleXMLRPCServer and 
make your own _dispatch() method that adds client_address to the parameter 
list, then all your functions would be passed the client_address. Or even 
specialize it so that just one special function gets this treatment.

Kent

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


Re: [Tutor] lists and strings

2005-11-08 Thread Shantanoo Mahajan
+++ Hugo Gonz?lez Monteverde [08-11-05 13:13 -0600]:
| Hi Mike,
| 
| Converting an (almost)arbitrary object into a string is what the Pickle 
module does. CPickle is faster. Take 
| a look into into it in the docs.
| 

Is there a way to dump the varialble in XML format and retrive it?

e.g.
a="this is string"
b=1234567890
c={}
c['a'] = a
c['b'] = b

and then dump c.

Regards,
Shantanoo


pgp5hG8KxTdBW.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lists and strings

2005-11-08 Thread Christopher Arndt
Shantanoo Mahajan schrieb:
> +++ Hugo Gonz?lez Monteverde [08-11-05 13:13 -0600]:
> | Hi Mike,
> | 
> | Converting an (almost)arbitrary object into a string is what the Pickle 
> module does. CPickle is faster. Take 
> | a look into into it in the docs.
> | 
> 
> Is there a way to dump the varialble in XML format and retrive it?

Look for xml_pickle.py in http://gnosis.cx/download/Gnosis_Utils-current.tar.gz

and see the article on it here:
http://gnosis.cx/publish/programming/xml_matters_1.txt

Also, xmlrpclib.py from the Standard library contains functions to serialize
basic Python data types to XML according to the XML-RPC specification.

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


Re: [Tutor] lists and strings

2005-11-08 Thread Kent Johnson
Mike Haft wrote:
> All the ways of writing data to a file I know keep telling me that lists
> can't be written to the file. I'm trying to convert data from one set of
> files into files of a different format. But the easiest way to get the
> data from the first set of files is in a list(s).
> 
> So, is there any way to convert lists to strings? Or a way to write lists
> to a file?

What do you want the data to look like in the file? You can create a string 
from your list and write the string to the file. For example if the list 
contains strings and you just want to separate the values with spaces use 
join():

 >>> data = ['22.5', '0.3', '11.9']
 >>> ' '.join(data)
'22.5 0.3 11.9'

Or you could separate the values with comma and space:
 >>> ', '.join(data)
'22.5, 0.3, 11.9'

I think from your previous post that your actual data is a list of lists, so 
you have to iterate the outside list, formatting each line and writing it to 
the file, something like this (borrowing from your previous unanswered post):

out_file = open("test.txt","w")
data = readSOMNETM(filename)
for line in data:
  line = ' '.join(line)
  out_file.write(line)
  out_file.write('\n')  # need a newline after each line
out_file.close()

Kent



-- 
http://www.kentsjohnson.com

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


[Tutor] TKinter Question

2005-11-08 Thread John Fouhy
On 08/11/05, Rob Dowell <[EMAIL PROTECTED]> wrote:
> Just a quick TKinter question. Is it possible to have custom
> frames/widgets? In other words can I customize the way that the GUI
> looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I
> was just wondering if it was possible and if it is possible then where I
> might get some information on how to do it. Thank you very much, Rob.

Have you looked at the options for the frame class? Eg, Frame(parent,
borderwidth=2, relief=RIDGE)

If you want more, you could build custom widgets using a Canvas.

Finally, you could try the Widget Construction Kit:
http://effbot.org/zone/wck.htm This is quite new, however, so you
might not get any help here (unless there's some WCK experts hiding
here somewhere :-) ).

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


Re: [Tutor] TKinter Question

2005-11-08 Thread Danny Yoo


> On 08/11/05, Rob Dowell <[EMAIL PROTECTED]> wrote:
> > Just a quick TKinter question. Is it possible to have custom
> > frames/widgets? In other words can I customize the way that the GUI
> > looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I
> > was just wondering if it was possible and if it is possible then where I
> > might get some information on how to do it. Thank you very much, Rob.
>
> Have you looked at the options for the frame class? Eg, Frame(parent,
> borderwidth=2, relief=RIDGE)


Hi Rob,

Also, some people have written some custom widget classes as part of the
Python Megawidgets project:

http://pmw.sourceforge.net/

But it sounds more like you might be interested in things like skinning;
unfortunately, I don't know too much about that.

Best of wishes to you!

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


Re: [Tutor] How to launch executable from a Python script??

2005-11-08 Thread Pujo Aji
Try to add .py in PATHEXT environment windows XP
After that, you can call your python program just like you call exe file.
 
Hope this help.
pujo  
On 11/8/05, Chris Irish <[EMAIL PROTECTED]> wrote:
Hello all :)I made a GUI app with pyGTK that I want to be able to launch a game I'vedownloaded from the pygame website when a button is clicked.  I was able
to do this on a linux box since the file was a .py file, but I'm notsure how to do it on a windows box since the file is an executeable.  Onlinux I did this:import osolddir = os.getcwd()   #to keep a reference to the old
directory to switch games lateros.chdir('spacinVaders-0.1')   #switch to the game's directoryos.spawnlp(os.P_NOWAIT, 'pythonw', 'pythonw', 'play.py')and it would launch fine can someone help me with this??
Thanks in advance. Chris :P___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
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
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] 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] 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


[Tutor] Video

2005-11-08 Thread Eric Walker
I would like to do some testing of video streams from say a vcr tape. Possibly 
using the PVR type capture card. Maybe modules to control it.. or some info 
on how I can control it through C/C++ and link those functions into python.  
Are there any python user groups or modules that could help me in this 
regard?

Thanks

Eric ...

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


[Tutor] Testing for gui

2005-11-08 Thread Ken Stevens

How does one test for a running gui in python?

Thanks, Ken


-- 
A journey of a thousand miles starts under one's feet.
-- Lao Tsu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Testing for gui

2005-11-08 Thread Liam Clarke-Hutchinson

Hi Ken, 

How do you mean? I assume you're referring to a non-Windows environment? In
Linux, I'd imagine that using os.popen("ps") would do it.

Cheers, 

Liam 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Ken Stevens
Sent: Wednesday, 9 November 2005 1:12 p.m.
To: tutor@python.org
Subject: [Tutor] Testing for gui



How does one test for a running gui in python?

Thanks, Ken


-- 
A journey of a thousand miles starts under one's feet.
-- Lao Tsu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Testing for gui

2005-11-08 Thread Liam Clarke-Hutchinson

Hmm, no x-server. If you're looking to detect running Python GUI packages,
you could check the namespaces for 'em, but beyond that, I'm stumped.


-Original Message-
From: Ken Stevens [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 9 November 2005 1:23 p.m.
To: Liam Clarke-Hutchinson
Subject: Re: [Tutor] Testing for gui


On Wed, Nov 09, 2005 at 01:16:03PM +1300, Liam Clarke-Hutchinson wrote:
> 
> Hi Ken,
> 
> How do you mean? I assume you're referring to a non-Windows 
> environment? In Linux, I'd imagine that using os.popen("ps") would do 
> it.
> 
> Cheers,
> 
> Liam
> 

Yes. Under Linux no x-server running? I guess it really wouldn't be
applicable under a windows enviroment, although I would like my code
to be transportable. Just under a MS windows enviroment it would
always be a "gui" environment.

Thanks, Ken

-- 
Go 'way!  You're bothering me!

A new monthly electronic newsletter covering all aspects of MED's work is now 
available.  Subscribers can choose to receive news from any or all of seven 
categories, free of charge: Growth and Innovation, Strategic Directions, Energy 
and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
http://news.business.govt.nz for more details.




http://www.govt.nz - connecting you to New Zealand central & local government 
services

Any opinions expressed in this message are not necessarily those of the 
Ministry of Economic Development. This message and any files transmitted with 
it are confidential and solely for the use of the intended recipient. If you 
are not the intended recipient or the person responsible for delivery to the 
intended recipient, be advised that you have received this message in error and 
that any use is strictly prohibited. Please contact the sender and delete the 
message and any attachment from your computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Testing for gui

2005-11-08 Thread John Fouhy
From: Ken Stevens [mailto:[EMAIL PROTECTED]
> Yes. Under Linux no x-server running? I guess it really wouldn't be
> applicable under a windows enviroment, although I would like my code
> to be transportable. Just under a MS windows enviroment it would
> always be a "gui" environment.

What happens if you try to create a GUI and X is not running? Maybe
you could just try to create a Tkinter.Tk() --- if it throws a python
exception (probably TclError), you could just catch that.

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


[Tutor] Using debuglevel with urllib2?

2005-11-08 Thread Terry Carroll

With urllib, you can set httplib.HTTPConnection.debuglevel to see the HTTP 
conversation.  But it doesn't work with urllib2.  Can someone explain how 
to use it in conjunction with urllib2?


Longer story: debuuglevel is a nice debug tool that lets you see the 
client-server HTTP conversation:

>>> import httplib
>>> httplib.HTTPConnection.debuglevel = 1
>>> import urllib
>>> testurl = "http://www.yahoo.com";
>>> f = urllib.urlopen(testurl)
connect: (www.yahoo.com, 80)
send: 'GET / HTTP/1.0\r\nHost: www.yahoo.com\r\nUser-agent: 
Python-urllib/1.16\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Wed, 09 Nov 2005 00:37:50 GMT
header: P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml";, CP="CAO DSP COR CUR 
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND 
PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
header: Cache-Control: private
header: Vary: User-Agent
header: Set-Cookie: FPB=pkvre11vo11n2h6u; expires=Thu, 01 Jun 2006 19:00:00 
GMT; path=/; domain=www.yahoo.com
header: Connection: close
header: Content-Type: text/html
>>>


Alas, it doesn't work with urllib2:

>>> import urllib2
>>> f = urllib2.urlopen(testurl)
>>>

[silence]

I need to use urllib2, because I need to include some headers, and as far 
as I can tell, urllib doesn't let you do that.

The debuglevel issue was reported as a bug, 1152723,[1] but one of the
comments is that the h.set_debuglevel(self._debuglevel) can be used to
address this, on a per-connection basis.

Leaving aside the issue of whether this actually is a bug or an 
imporvement, I don't follow the explanation.

Can someone explain to me how to set the debuglevel using urllib2?

Thanks!


[1] Link to bug report:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1152723&group_id=5470
or  http://makeashorterlink.com/?F23C2102C


___
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 R. Alan Monroe
> 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.

Somewhat related question: Why isn't PIL in the standard library?

Alan

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


Re: [Tutor] testing: doctest and unittest

2005-11-08 Thread Kent Johnson
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?

I think it is mostly personal preference. Doctest is nice where you create 
examples for others, maybe not so nice where you are creating exhaustive unit 
tests trying to exercise every corner case. unittest is perhaps easier to 
aggregate tests from multiple modules. Doctests integrate with unittest in 
Python 2.4. Personally I use unittest but I come from a Java background and 
learned TDD with JUnit which is related to unittest.

Another option is py.test which is part of the PyPy project, not part of the 
standard library. Some people think it is simpler and more Pythonic than 
unittest. This page has good articles about doctest, unittest and py.test:
http://agiletesting.blogspot.com/2005/11/articles-and-tutorials-page-updated.html

-- 
http://www.kentsjohnson.com

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


[Tutor] Spanish text in BS problem

2005-11-08 Thread Ismael Garrido
Hello

I'm using Beautiful Soup to scrape a site (that's in Spanish) I 
sometimes come across strings like:
'Ner\\xf3n como cantor'

Which gets printed:
Ner\xf3n como cantor

When they should be:
Nerón como cantor

I don't know if it is my fault (due to me misusing BS) or is it a BS 
fault. Anyway, is there a way to print the string correctly?

This is the code I'm using in BS

a = open("zona.htm")
text = a.readlines()
a.close()

BS = BeautifulSoup.BeautifulSoup(str(text))

for ed in BS('span', {'class':'ed_ant_fecha'}):
urlynombre = ed.findNextSibling().findNextSibling().findNextSibling()
nombre = urlynombre.next.next

And "nombre" is that string I mentioned.

Any help is appreciated, thanks
Ismael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using debuglevel with urllib2?

2005-11-08 Thread Kent Johnson
Terry Carroll wrote:
> With urllib, you can set httplib.HTTPConnection.debuglevel to see the HTTP 
> conversation.  But it doesn't work with urllib2.  Can someone explain how 
> to use it in conjunction with urllib2?

You have to create your own HTTPHandler, set it to debug and install it in 
urllib2. Like this:

 >>> import urllib2
 >>> h=urllib2.HTTPHandler(debuglevel=1)
 >>> opener = urllib2.build_opener(h)
 >>> urllib2.install_opener(opener)
 >>> urllib2.urlopen('http://www.google.com').read()
connect: (www.google.com, 80)
send: 'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: 
www.google.com\r\nConnection: close\r\nUser-agent: Python-urllib/2.
reply: 'HTTP/1.1 200 OK\r\n'
header: Cache-Control: private
...etc.

> Leaving aside the issue of whether this actually is a bug or an 
> imporvement, I don't follow the explanation.

It's pretty obscure. I had to poke around in the source for a while before I 
could understand it.

Kent

-- 
http://www.kentsjohnson.com

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


[Tutor] Problem appending to a list using a property within a class

2005-11-08 Thread Roy Bleasdale
I have created a List within a class. If I try and append to the list using 
the set function using the property value my variable stops being a list.

Can anyone explain why the set function called by the class property does 
not append to the list?


Here is some sample code:

class ShoppingBag:

 def __init__(self):
 self.fruit = []
 self.veg = []
 self.spam = 0
 self.beer = []

 def getspam(self):
 return self.spam

 def setspam(self,value):
 self.spam = value

 spam = property(getspam,setspam,None,None)

 def getveg(self):
 return self.veg

 def setveg(self,value):
 self.veg.append(value)

 veg = property(getveg,setveg,None,None)


 def getfruit(self):
 return self.fruit

 def setfruit(self,value):
 self.fruit.append(value)

 fruit = property(getfruit,setfruit,None,None)

 def Addfruit(self,value):
 self.fruit.append(value)

 def getbeer(self):
 return self.beer

 def setbeer(self,value):
 self.beer.append(value)

 beer = property(getbeer,setbeer,None,None)

bag = ShoppingBag()
bag.spam = 3
bag.veg = "carrots"
bag.veg = "broccoli"
bag.veg = "cauliflower"
bag.Addfruit("apple")
bag.Addfruit("banana")
bag.Addfruit("orange")
bag.setbeer ("coopers")
bag.setbeer("mountain goat")
bag.setbeer("cascade")

print "contents of bag"
print bag.spam
print bag.veg
print bag.fruit
print bag.beer

basket = ShoppingBag()
basket.setveg ( "carrots")
basket.setveg ( "broccoli")
basket.setveg ( "cauliflower")

print "contents of basket"
print basket.veg

when I run it I get:

contents of bag
3
cauliflower
['apple', 'banana', 'orange']
['coopers', 'mountain goat', 'cascade']

contents of basket
['carrots', 'broccoli', 'cauliflower']


Thanks

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


[Tutor] Find multiple lines in a file

2005-11-08 Thread Bill Burns
I have a PostScript file which contains the following lines (the numbers
are for reference only and are *not* in the file):

1 <<
2   /Policies <<
3 /PageSize 3
4   >>
5 >> setpagedevice

These lines never change and are always formatted like this (at least in
the PostScript files that I'm generating with tiff2ps).

I want to open the the file and read it, find these five lines and then
replace the lines with something different.

I understand how to open and read the file. I have no problems finding
and changing a *single* line, but I can not figure out how to find the
*multiple* lines (and put them into one variable).

Here's some code I'm using to replace just a *single* line in the
PostScript file (Note - I'm changing the BoundingBox which is in the
same file, but is *not* one of the five lines above).


import fileinput

class ChangeBBox:
 pass

 def getBBox(self, filename):
 f = open(filename, "rb")
 buffer = 1000
 tmp = f.readlines(buffer)
 f.close()
 for line in tmp:
 if line.startswith('%%BoundingBox:'):
 return line.strip()

 def modifyBBox(self, filename):
 old = self.getBBox(filename)
 new = '%%BoundingBox: 0 0 1296 1728'
 for line in fileinput.input(filename, inplace=1):
 print line.replace(old, new),


The above code uses the fileinput module which makes it really nice for
modifying a file 'inplace'. I use the code like this

c = ChangeBBox()
c.modifyBBox(somePostScriptFile.ps)

and it works great, but it's really simple because it only has to modify
*one* line.

Can anyone offer suggestions on how to find all five lines? I don't
think I'll have a problem replacing the lines, it's just getting them
all into one variable that stumping me :-)

Thanks,

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


Re: [Tutor] Problem appending to a list using a property within a class

2005-11-08 Thread John Fouhy
On 09/11/05, Roy Bleasdale <[EMAIL PROTECTED]> wrote:
> I have created a List within a class. If I try and append to the list using
> the set function using the property value my variable stops being a list.
>
> Can anyone explain why the set function called by the class property does
> not append to the list?
>
>
> Here is some sample code:
>
> class ShoppingBag:

Properties only work properly with new style classes.  You get a new
style class by inheriting from another new style class, or by
inheriting from object.

Try changing the first line to "class ShoppingBag(object):".

This is a somewhat annoying distinction that will hopefully go away in
a future version of python (when all classes become new style).

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


Re: [Tutor] Using debuglevel with urllib2?

2005-11-08 Thread Terry Carroll
On Tue, 8 Nov 2005, Kent Johnson wrote:

> You have to create your own HTTPHandler, set it to debug and install it
> in urllib2. Like this:

Thanks, Kent!

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


Re: [Tutor] Video

2005-11-08 Thread Eric Walker
no takrs on this one?


--- Eric Walker <[EMAIL PROTECTED]> wrote:

> I would like to do some testing of video streams
> from say a vcr tape. Possibly 
> using the PVR type capture card. Maybe modules to
> control it.. or some info 
> on how I can control it through C/C++ and link those
> functions into python.  
> Are there any python user groups or modules that
> could help me in this 
> regard?
> 
> Thanks
> 
> Eric ...
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


 

Pre-Paid Legal can help protect your legal rights.

Be able to say, "I'm going to talk to my lawyer about that." -- AND MEAN IT!

Phone Consultations on Unlimited Matters

Legally written Letters to show you mean Business

Contract and Document Review.
 
 
Need Webhosting?


 
 





__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Video

2005-11-08 Thread Danny Yoo


On Tue, 8 Nov 2005, Eric Walker wrote:

> I would like to do some testing of video streams from say a vcr tape.
> Possibly using the PVR type capture card. Maybe modules to control it..
> or some info on how I can control it through C/C++ and link those
> functions into python.  Are there any python user groups or modules that
> could help me in this regard?

Hi Eric,

You probably want to ask this on a newsgroup like comp.lang.python; I
don't think many of us here are familiar with PVR stuff.  There are such
systems written in Python.  For example, Freevo:

http://freevo.sourceforge.net/

but the subject is so specialized that Python-tutor probably won't be too
effective.  A larger audience like comp.lang.python might be able to give
you better guidance.


Good luck!

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