Re: New Python 3.0 string formatting - really necessary?

2008-12-31 Thread r
You know, it is so much easier to find my posts now that someone has
been thoughtful enough to mark them for me. Thank you kind chaps, i
shall leave a shiny new nickel for you, just send me your name,
address, and phone numbers. I'll get them in the mail right away.
--
http://mail.python.org/mailman/listinfo/python-list


Re: string in files

2008-12-31 Thread Glauco

Steven D'Aprano ha scritto:

On Tue, 30 Dec 2008 11:53:17 +0100, Glauco wrote:



thanks brother
i mean how do i particularly assign (u = this)
(y = is)
in the strings up there. i have been able to split strings with any
character sign.



If i'm not wrong this is simple with RE:


If that's your idea of "simple", I'd hate to see what you consider 
complicated!


*Simple* is just using the split method.

a, b, c, d, e, f = 'this is a python coding group'.split()



I've done a lot of file import procedure and IMHO this solution help you 
 in all situation. You can validate line before import, you can do a 
specific RE for check a more detailed line and so on, it's more powerful.


For simple i mean simple programming code.


Glauco
--
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError when list append... plz help

2008-12-31 Thread Francesco Bochicchio

[BON] ha scritto:

==
s=[]
for i in range(11000-1): 
for j in range(i+1, 11000): 

s.append(((i,j),sim)) 
==

above sim is floating type.
s.append is totally coducted 60,494,500 times.
but this code raise MemoryError.

My computer has 4G RAM.
i think it's enough. but it doesn't...

So, i've tested below code.
==
a=[] 
i=0 
while i<60494500 : 
a.append(i) 
i+=1

==
but this code raise also MemoryError.

How can i resolve this problem?
please, help...

Regards,



If you _really_ have to store so many numbers in memory (hint: if you 
are processing them sequentially, you don't need to store all them - use

generators instead) then you may have better luck using mmap module to
create a huge file-memory object, that you can access both as a file and 
as a list, and put numbers in it after packing/unpacking with struct.

Something like this (only marginally tested ):

>>> memory = mmap.mmap(-1, 60494500*4)
>>> def memory_put(offset, f):
... memory[offset*4:(offset+1)*4] = struct.pack( "%f", f )
 >>> def memory_get(offset):
... return struct.unpack( "f", memory[offset*4:(offset+1)*4] )[0]
>>> memory_put(12, 3.14 )
>>> memory_get(12)
3.141049041748

Ciao
--
FB

--
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError when list append... plz help

2008-12-31 Thread Steven D'Aprano
On Tue, 30 Dec 2008 22:02:49 -0800, [BON] wrote:

> ==
> s=[]
> for i in range(11000-1):
> for j in range(i+1, 11000):
> 
> s.append(((i,j),sim))
> ==
> above sim is floating type.
> s.append is totally coducted 60,494,500 times. but this code raise
> MemoryError.
> 
> My computer has 4G RAM.
> i think it's enough. but it doesn't...

Your computer might have 4GB, but how much memory can Python allocate? 
What operating system are you using?

Each time you are appending to the list, you append a tuple:

((i, j), sim)

where sim is a float and i and j are ints. How much memory does each of 
those take?

>>> sys.getsizeof( ((0, 1), 1.1) )
32


So each entry requires 32 bytes. 60 million times 32 bytes = almost 2GB 
alone. Plus the list itself will require (approximately) between 230MB 
and 460MB just for the pointers.

What are you expecting to do with this enormous list, and why do you need 
it all at once?



-- 
Steven
--
http://mail.python.org/mailman/listinfo/python-list


Re: Memory leak problem (while using tkinter)

2008-12-31 Thread Marc 'BlackJack' Rintsch
On Tue, 30 Dec 2008 20:21:06 -0800, André wrote:

> I have written a small program (my first Tkinter-based app) to play
> around the idea mentioned on
> http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-
lisa/
> and, in doing so, have encountered a memory leak problem.   I have seen
> mentions on the web of using the delete() method of canvas to prevent
> such problems - which I have tried to do with limited success.  Below is
> the code I wrote; to run it, you will need a small image file
> (I used the one found on http://alteredqualia.com/visualization/evolve/)
> that is saved under "mona_lisa.png".
> 
> Any help would be greatly appreciated.

I don't see anything obvious but that the program is too long and uses 
too much components to be sure that `Tkinter` is the culprit.  Try too 
trim it down to the smallest possible program that still has the problem.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError when list append... plz help

2008-12-31 Thread bearophileHUGS
[BON]:
> above sim is floating type.
> s.append is totally coducted 60,494,500 times.
> but this code raise MemoryError.
>
> My computer has 4G RAM.
> i think it's enough. but it doesn't...

Try creating it in a more clean way, here an array of doubles:

>>> from array import array
>>> a = array("d", [0.0]) * 60494500

This requires about 477 MB to me.
Note that I have not used "append" that slows down code a lot and
wastes memory, that's what I mean with "clean".
If you really need the (i,j) part too (and you may not need it), then
you can create two more "parallel arrays". Also a numpy array may be
better for such large amount of data.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio

Grant Edwards ha scritto:

On 2008-12-30, Francesco Bochicchio  wrote:

3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in 
select between blocking and non-blocking mode. The difference is in the
recv (again, assuming that you use TCP as protocol, that is AF_INET, 
SOCK_STREAM), which in the blocking case would wait to receive all the 
bytes that you requested,


No, in blocking mode it will wait to receive _some_ data (1 or
more bytes).  The "requested" amount is strictly an upper
limit: recv won't return more than the requested number of
bytes, but it might return less.



Uhm. In my experience, with TCP protocol recv only returned less than 
the required bytes if the remote end disconnects. I always check the
returned value of recv and signal an error if the read bytes are less 
than the expected ones, but this error is never occurred (and its about 
20 years that I use sockets in various languages and various flavor of 
unix and occasionally on windows. Maybe  have always been lucky ? :-)


And, on some unices  system call recv also returns when a signal 
interrupts the syscall, but I half-remember reading that python recv in

such a case repeat the system call by itself ... although this might be
only my desire ...


In non-blocking mode, it will always return immediately, either
with some data, no data (other end closed), or an EAGAIN or
EWOULDBLOCK error (I forget which).


[...] I myself tend to avoid using non-blocking sockets, since
blocking sockets are much easier to handle...


That depends on whether you can tolerate blocking or not.  In
an event-loop, blocking is generally not allowed.


What I usually do, when I cannot block is:

- use socket in blocking mode
- do a select with a very small timeout and do a recv only if the select 
returns with input events
- (with TCP) do a recv for the exact amount of bytes that I expect ( 
this mean having a user protocol that carries the message size in the 
header, but this is usually the case ).


This usually worked for me.

If my process (or thread) has only to deal with socket I/O, I make a 
blocking select, and then make an 'exact' recv on whichever socket the 
select signals.


Ciao

FB
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio

Jean-Paul Calderone ha scritto:
On Tue, 30 Dec 2008 19:19:08 +0100, Francesco Bochicchio 
 wrote:

[snip]

If you are interested in socket errors, you should
also fill the third 'fd-set' in the select call, and after select 
returns check that fd is not in it anymore:


ready = select.select( [fd],[], [fd] )
if fd in ready[2]:
   # raise your error here


The third argument to select() isn't for monitoring sockets for errors.  
Its

behavior is also rather platform sensitive.  In general, you don't need it
at all on POSIX, but on Windows you should pass the same list for it as you
pass for the write-set, merge the results, and treat them all as writeable.

Or use a higher-level library that deals with all the asinine details for
you. ;)

Jean-Paul


Yes, now that you mention it I remember having to do something like that 
on a socket library I wrote on windows ... IIRC, the send could not 
complete and then signal the readyness of the socket through

the third argument of the select ...

My experience is mostly on unices, and I usually don't use  the third 
argument (and not often the second)  but I remember having read on 
select manual page that it was  for errors. Now both python manuals

than select manual page say it is for 'exceptional conditions', without
going into details ...

Tx for the clarification, anyway ...

Ciao

FB
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio

Francesco Bochicchio ha scritto:


No, in blocking mode it will wait to receive _some_ data (1 or
more bytes).  The "requested" amount is strictly an upper
limit: recv won't return more than the requested number of
bytes, but it might return less.



Uhm. In my experience, with TCP protocol recv only returned less than 
the required bytes if the remote end disconnects. I always check the
returned value of recv and signal an error if the read bytes are less 
than the expected ones, but this error is never occurred (and its about 
20 years that I use sockets in various languages and various flavor of 
unix and occasionally on windows. Maybe  have always been lucky ? :-)




BTW, this is not a rethorical or ironic question... my applications 
mostly run on LANs or dedicated WANs so maybe they never experienced the
kind of network congestion that could cause recv to return less than the 
expected amount of bytes ...


but then, IIRC TCP guarantees that the packet is fully received by 
hand-shaking at transport level between sender and receiver. Ad once the 
packet is fully in the receiver buffer, why should recv choose to give

back to the application only a piece of it?

Ciao
-
FB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-31 Thread Dotan Cohen
I have been following this thread with interest. Is there a way to
build Qt apps with relative easy? I use KDE and would prefer the Qt
toolkit for my GUI apps. Thanks.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Saju Pillai
On Dec 31, 2:01 pm, Francesco Bochicchio  wrote:
> Grant Edwards ha scritto:
>
> > On 2008-12-30, Francesco Bochicchio  wrote:
>
> >> 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in
> >> select between blocking and non-blocking mode. The difference is in the
> >> recv (again, assuming that you use TCP as protocol, that is AF_INET,
> >> SOCK_STREAM), which in the blocking case would wait to receive all the
> >> bytes that you requested,
>
> > No, in blocking mode it will wait to receive _some_ data (1 or
> > more bytes).  The "requested" amount is strictly an upper
> > limit: recv won't return more than the requested number of
> > bytes, but it might return less.
>
> Uhm. In my experience, with TCP protocol recv only returned less than
> the required bytes if the remote end disconnects. I always check the

What if the sending end actually sent less than you asked for ?

-srp

> returned value of recv and signal an error if the read bytes are less
> than the expected ones, but this error is never occurred (and its about
> 20 years that I use sockets in various languages and various flavor of
> unix and occasionally on windows. Maybe  have always been lucky ? :-)
>
> And, on some unices  system call recv also returns when a signal
> interrupts the syscall, but I half-remember reading that python recv in
> such a case repeat the system call by itself ... although this might be
> only my desire ...
>
> > In non-blocking mode, it will always return immediately, either
> > with some data, no data (other end closed), or an EAGAIN or
> > EWOULDBLOCK error (I forget which).
>
> >> [...] I myself tend to avoid using non-blocking sockets, since
> >> blocking sockets are much easier to handle...
>
> > That depends on whether you can tolerate blocking or not.  In
> > an event-loop, blocking is generally not allowed.
>
> What I usually do, when I cannot block is:
>
> - use socket in blocking mode
> - do a select with a very small timeout and do a recv only if the select
> returns with input events
> - (with TCP) do a recv for the exact amount of bytes that I expect (
> this mean having a user protocol that carries the message size in the
> header, but this is usually the case ).
>
> This usually worked for me.
>
> If my process (or thread) has only to deal with socket I/O, I make a
> blocking select, and then make an 'exact' recv on whichever socket the
> select signals.
>
> Ciao
> 
> FB

--
http://mail.python.org/mailman/listinfo/python-list


Pass by reference

2008-12-31 Thread iu2
Hi,

Is it possible somehow to change a varible by passing it to a
function?

I tried this:

def change_var(dict0, varname, val):
  dict0[varname] = val


def test():
  a = 100
  change_var(locals(), 'a', 3)
  print a


But test() didn't work, the value a remains 100.

I have several variables initialized to None.
I need to convert each one of them an object only if it is None.
something like:

if not var1: var1 = MyObject()

I want this to be a function, that is:

def create_obj(var):
  if not var: var = MyObj()
  # set properties of var

Now, I know I can achieve this by functional programming,

def create_obj(var):
  if not var:
x = MyObj()
# set properties of x
return x
  return var

and then

var = creaet_obj(var)

Is there another way?

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference

2008-12-31 Thread Chris Rebert
On Wed, Dec 31, 2008 at 3:30 AM, iu2  wrote:
> Hi,
>
> Is it possible somehow to change a varible by passing it to a
> function?
>
> I tried this:
>
> def change_var(dict0, varname, val):
>  dict0[varname] = val
>
>
> def test():
>  a = 100
>  change_var(locals(), 'a', 3)
>  print a
>
>
> But test() didn't work, the value a remains 100.

Yes, that's clearly stated in the documentation for locals(); from
http://docs.python.org/library/functions.html#locals :

"Warning: The contents of this dictionary should not be modified;
changes may not affect the values of local variables used by the
interpreter."

>
> I have several variables initialized to None.
> I need to convert each one of them an object only if it is None.
> something like:
>
> if not var1: var1 = MyObject()

That should be:

if var1 is None: var1 = MyObject()

Otherwise, the "conversion" will also happen if var1 happens to be a
false but non-None object, e.g. {}, [], 0, etc
Also, it's just the idiomatic way of writing tests against None in Python.

>
> I want this to be a function, that is:
>
> def create_obj(var):
>  if not var: var = MyObj()
>  # set properties of var
>
> Now, I know I can achieve this by functional programming,
>
> def create_obj(var):
>  if not var:
>x = MyObj()
># set properties of x
>return x
>  return var
>
> and then
>
> var = creaet_obj(var)
>
> Is there another way?

Not really, or at the very least it'll be kludgey. Python uses
call-by-object (http://effbot.org/zone/call-by-object.htm), not
call-by-value or call-by-reference.

Could you explain why you have to set so many variables to the same
value (if they're None)? It's a bit strange and could be a sign that
there's a better way to structure your program (e.g. use a
dictionary). We might be able to offer more helpful suggestions if you
explain.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference

2008-12-31 Thread Bruno Desthuilliers

iu2 a écrit :

Hi,

Is it possible somehow to change a varible by passing it to a
function?


For which definition of "change a variable" ?


I tried this:

def change_var(dict0, varname, val):
  dict0[varname] = val


Ok, this is mutating dict0, so it works.



def test():
  a = 100
  change_var(locals(), 'a', 3)


Please (re)read the doc for locals():
http://www.python.org/doc/2.6/library/functions.html#locals

See the big warning ?


  print a





But test() didn't work,


It did. The problem is elsewhere.


the value a remains 100.

I have several variables initialized to None.


Where ?


I need to convert each one of them an object only if it is None.
something like:

if not var1: var1 = MyObject()


Warning : some objects can eval to false in a boolean context without 
being None. Better to explicitely test identity here:


if var1 is None:
var1 = Something()



I want this to be a function, that is:

def create_obj(var):
  if not var: var = MyObj()


This is a rebinding, not a mutation. Here, 'var' is a local *name*, so 
rebinding it will only affect the local namespace.



  # set properties of var


Why don't you use the initializer of MyObj here ?

class MyObj(object):
def __init__(self, prop1, propx):
# set properties of self
self.prop1 = prop1
self.propx = propx


Then just call:

var = MyObj(somevalue, someothervalue)


Now, I know I can achieve this by functional programming,


???


def create_obj(var):
  if not var:
x = MyObj()
# set properties of x
return x
  return var


This is just a plain function. You may want to re-read the definition of 
"functional programming" !-)



and then

var = creaet_obj(var)

Is there another way?


What's wrong with this one ?

--
http://mail.python.org/mailman/listinfo/python-list


Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Benjamin Blundell
Hi all. I've had a look around the forums and the we and im looking
for a library (or a set of libraries) for dealing with Visualisation
and Interaction in Python. At the moment i've been using Flash with
the Five3D library to do most of the work. Sadly this isnt an option
anymore but it is a good example. Pretty,anti-aliased 2D and 3D
graphics, simple interaction and no need to rewrite the wheel.

Im a fan of OpenGL and PyOpenGL is fairly cool but I really dont want
to have to write yet another camera, another way of dealing with
Vectors, texture organiser, picking, etc etc. Is there a library or
set of libraries that people are aware of that might do this? I
remember a few in C++ and C but it'd be nicer to stick to working with
Python

Cheers
Ben
--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Python


On 31 dec 2008, at 13:37, Benjamin Blundell wrote:


Hi all. I've had a look around the forums and the we and im looking
for a library (or a set of libraries) for dealing with Visualisation
and Interaction in Python. At the moment i've been using Flash with
the Five3D library to do most of the work. Sadly this isnt an option
anymore but it is a good example. Pretty,anti-aliased 2D and 3D
graphics, simple interaction and no need to rewrite the wheel.

Im a fan of OpenGL and PyOpenGL is fairly cool but I really dont want
to have to write yet another camera, another way of dealing with
Vectors, texture organiser, picking, etc etc. Is there a library or
set of libraries that people are aware of that might do this? I
remember a few in C++ and C but it'd be nicer to stick to working with
Python

Cheers
Ben


Hey Ben,

dunno if this is exactly what you;re looking for,
yet you could have a look at Blender
http://blender.org/
http://wiki.blender.org/index.php/Scripts

it's an open source 3D application and has a python
scripting engine... (just like maya from Autodesk)

gr
Arno
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference

2008-12-31 Thread iu2
On Dec 31, 1:48 pm, "Chris Rebert"  wrote:
...
>
> Not really, or at the very least it'll be kludgey. Python uses
> call-by-object (http://effbot.org/zone/call-by-object.htm), not
> call-by-value or call-by-reference.
>
> Could you explain why you have to set so many variables to the same
> value (if they're None)? It's a bit strange and could be a sign that
> there's a better way to structure your program (e.g. use a
> dictionary). We might be able to offer more helpful suggestions if you
> explain.
>
> Cheers,
> Chris
>
> --

Hi, thanks for your reply.

Well, I wrote an application that talks via UDP to several targets
(embedded). Currently there are only two of them connected to my PC,
but there could be more. Let's call them target 1 and target 2.

Now, each target has its own IP address, and is connected straight to
my PC, no DHCP or common bus or whatsover
The GUI of my application enables the user to enter the IP for each
target.
The user can disconnect one target, and then connect a different one
with a different IP.
Let's say he replaces target 2 with a different one. Then he must tell
the python app that target 2 now has a different IP. He does that by
entering a different IP for target 2 in the GUI.

When the app sends data to a target, it must know whether to create a
new socket or use the previous one for that target. It deduces this by
observing a change in the IP address in the GUI for that target.

For the 2 targets I have the variables comm1 and comm2. They are of
some class I wrote, representing many properties of the communication,
including the IP address.
There is one function that sends data, and it receives a commX var
(comm1 or comm2) as the means for sending the data.
Before sending the data the function needs to initilze commX (if it is
still None), or creating it a new, if it sees that the IP for that
target has changed.

Something like this:

def send_data(comm, data, current_ip_from_gui):
  if comm is None:
# I want to assign comm a new MyComm
  elif comm.ip != current_ip_from_gui:
# I want to re-assign a new MyComm that uses the new IP
  comm.socket.SendTo(comm.addr, data)  # eventually send the data

I could re-design it to have send_data be a method of MyComm. But I
don't think I should, beacuse I planned MyComm to have only
properties. I'd like functions to receive it and manipulate it. MyComm
could also be a mere string just as well...
Since I can apply this idiom in C (pointer), Lisp (macro),  tcl
(upvar) and C# (ref) I wondered what the python way was.

But I guess I can achieve this using a class holding my vars, maybe
like this:

class CommVars:
  comm1 = None
  comm2 = None

myvars = CommVars()

and then change a value like this:

def set_var(dict0, varname, val):
  dict0[varname] = val

set_var(myvars.__dict__, 'comm1', MyComm(...))






--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Benjamin Blundell
On Dec 31, 12:55 pm, Python  wrote:
> On 31 dec 2008, at 13:37, Benjamin Blundell wrote:
>
>
>
> > Hi all. I've had a look around the forums and the we and im looking
> > for a library (or a set of libraries) for dealing with Visualisation
> > and Interaction in Python. At the moment i've been using Flash with
> > the Five3D library to do most of the work. Sadly this isnt an option
> > anymore but it is a good example. Pretty,anti-aliased 2D and 3D
> > graphics, simple interaction and no need to rewrite the wheel.
>
> > Im a fan of OpenGL and PyOpenGL is fairly cool but I really dont want
> > to have to write yet another camera, another way of dealing with
> > Vectors, texture organiser, picking, etc etc. Is there a library or
> > set of libraries that people are aware of that might do this? I
> > remember a few in C++ and C but it'd be nicer to stick to working with
> > Python
>
> > Cheers
> > Ben
>
> Hey Ben,
>
> dunno if this is exactly what you;re looking for,
> yet you could have a look at 
> Blenderhttp://blender.org/http://wiki.blender.org/index.php/Scripts
>
> it's an open source 3D application and has a python
> scripting engine... (just like maya from Autodesk)
>
> gr
> Arno

Sorry, I should have explained a little more. I've used Blender quite
a bit and its an ace program.

But what im after is a set of tools for creating a visualisation
program. A while ago, we used QT with the OpenGL plugins and this
library:

http://www.libqglviewer.com/

Essentially, you mashed these 3 together and you got a proper OpenGL
window with basic mouse looks, picks and all the rest of the
'standard' stuff you cant be arsed coding for the 15th time or so ;)
Model loading is also supported from a small array of formats.

im not uber keen that it has to be opengl but im sure there must be a
similar set of python libs out there. PyGame isnt a bad one at all but
its graphic manipulation routines can be a pain (rotations) and its 2D
only but its certainly along the right lines.

Cheers
Ben
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference

2008-12-31 Thread Chris Rebert
On Wed, Dec 31, 2008 at 5:04 AM, iu2  wrote:

> For the 2 targets I have the variables comm1 and comm2. They are of
> some class I wrote, representing many properties of the communication,
> including the IP address.
> There is one function that sends data, and it receives a commX var
> (comm1 or comm2) as the means for sending the data.
> Before sending the data the function needs to initilze commX (if it is
> still None), or creating it a new, if it sees that the IP for that
> target has changed.

Based on the naming alone (though further corroborated by your
details), I can recommend that you use a dictionary instead of
variables for the commX-s.

Basically, remove the comm1, comm2, etc variables and instead do (you
might want to use a defaultdict or list rather than a plain dict):

comms = {1 : MyComm(...), 2 : None}

>
> Something like this:
>
> def send_data(comm, data, current_ip_from_gui):
>  if comm is None:
># I want to assign comm a new MyComm
>  elif comm.ip != current_ip_from_gui:
># I want to re-assign a new MyComm that uses the new IP
>  comm.socket.SendTo(comm.addr, data)  # eventually send the data

Instead that becomes:

def send_data(comms, id_num, data, current_ip_from_gui):
if comms[id_num] is None:
comms[id_num] = MyComm(...)
elif comms[id_num].ip != current_ip_from_gui:
comms[id_num] = MyComm(current_ip_from_gui, ...)
comm = comms[id_num]
comm.socket.SendTo(comm.addr, data)  # eventually send the data


> But I guess I can achieve this using a class holding my vars, maybe
> like this:

That's similar to what I'm suggesting, but mine has less indirection.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: list indices must be integers

2008-12-31 Thread John Machin
On Dec 31 2008, 3:26 pm, dubux  wrote:
> thanks for help everyone. it turned out the function itself worked
> fine.. it was the way i was calling it that was messing everything up.
> i ended up re-doing the whole thing as follows, and it now works
> perfectly.
>
> def news(x,y):
>         news_file = '/home/scam/Desktop/www/info/news'
>         news = open(news_file, 'r')
>         news_list = news.readlines()
>         news.close()
>         if x == 'date':
>                 mylist = map(lambda i: news_list[i], filter(lambda i: i%2 == 
> 0, range
> (len(news_list
>                 date = mylist[y].replace("\n","")
>                 return '%s\n\n' % (date)
>         if x == 'news':
>                 mylist = map(lambda i: news_list[i], filter(lambda i: i%2 == 
> 1, range
> (len(news_list
>                 news = mylist[y].replace("\n","")
>                 return '%s\n\n' % (news)
>         else:
>                 return news_list
>
> news_parse, count, news_list = " ", 0, news('list','list')
> newss = map(lambda i: news_list[i], filter(lambda i: i%2 == 1, range
> (len(news_list
> while count < len(newss):
>         get_date = news('date', count)
>         get_news = news('news', count)
>         news_parse = '%s %s %s' % (news_parse, get_date, get_news)
>         count = count + 1

Unless I'm sorely mistaken, the whole of the above can be replaced by
something like (untested):

news_file = '/home/scam/Desktop/www/info/news'
news = open(news_file, 'r')
accum = []
for lineno, line in enumerate(news):
accum.append('%s\n%s\n' % (line.strip(),
('', '')[lineno % 1]))
news_parse = ' '.join(accum)
news.close()
count = (lineno + 1) // 2 # if indeed count is needed

with the virtues of brevity and speed ... if there are N (date, news)
items, your code reads the file 2*N+1 times!!!

How big is N?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Stef Mientki

Maybe VPython (Visual) or Panda fits your needs.
cheers,
Stef

--
http://mail.python.org/mailman/listinfo/python-list


change only the nth occurrence of a pattern in a string

2008-12-31 Thread TP
Hi everybody,

I would like to change only the nth occurence of a pattern in a string. The
problem with "replace" method of strings, and "re.sub" is that we can only
define the number of occurrences to change from the first one.

>>> v="coucou"
>>> v.replace("o","i",2)
'ciuciu'
>>> import re
>>> re.sub( "o", "i", v,2)
'ciuciu'
>>> re.sub( "o", "i", v,1)
'ciucou'

What is the best way to change only the nth occurence (occurrence number n)?

Why this default behavior? For the user, it would be easier to put re.sub or
replace in a loop to change the first n occurences.

Thanks

Julien
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio

< ... >


Uhm. In my experience, with TCP protocol recv only returned less than
the required bytes if the remote end disconnects. I always check the


What if the sending end actually sent less than you asked for ?

-srp



In blocking mode and with TCP protocol, the recv waits until more bytes 
are received -  mixing up the next message with the previous one and 
then loosing the 'sync' and being unable to interpretate the received 
data -  or the remote end disconnects.


Yes this is bad,  and is a good reason why socket receive should be 
handled   in non-blocking mode if you receive data from untrusted 
sources. But luckily for me, as I said in the other post, I used socket 
mostly to communicate between specific applications on a private LAN or 
WAN, so I could afford to ignore the problem.


Ciao

FB
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Saju Pillai
On Dec 31, 7:48 pm, Francesco Bochicchio  wrote:
> < ... >
>
> >> Uhm. In my experience, with TCP protocol recv only returned less than
> >> the required bytes if the remote end disconnects. I always check the
>
> > What if the sending end actually sent less than you asked for ?
>
> > -srp
>
> In blocking mode and with TCP protocol, the recv waits until more bytes
> are received -  mixing up the next message with the previous one and

Is this correct ? IIRC even in blocking mode recv() can return with
less bytes than requested, unless the MSG_WAITALL flag is supplied.
Blocking mode only guarantees that recv() will wait for a message if
none is available - but not that it *will* return the number of bytes
requested.

-srp

> then loosing the 'sync' and being unable to interpretate the received
> data -  or the remote end disconnects.
>
> Yes this is bad,  and is a good reason why socket receive should be
> handled   in non-blocking mode if you receive data from untrusted
> sources. But luckily for me, as I said in the other post, I used socket
> mostly to communicate between specific applications on a private LAN or
> WAN, so I could afford to ignore the problem.
>
> Ciao
> 
> FB

--
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing Excel spreadsheets

2008-12-31 Thread John Machin
On Dec 31 2008, 4:02 pm, brooklineTom  wrote:
> [email protected] wrote:
> > Hi,
>
> > Can anybody recommend an approach for loading and parsing Excel
> > spreadsheets in Python. Any well known/recommended libraries for this?
>
> > The only thing I found in a brief search 
> > washttp://www.lexicon.net/sjmachin/xlrd.htm,
> > but I'd rather get some more input before going with something I don't
> > know.
>
> > Thanks,
> > Andy.
>
> I save the spreadsheets (in Excel) in xml format.

Which means that you need to be on a Windows box with a licensed copy
of Excel. I presume you talking about using Excel 2003 and saving as
"XML Spreadsheet (*.xml)". Do you save the files manually, or using a
COM script? What is the largest xls file that you've saved as xml, how
big was the xml file, and how long did it take to parse the xml file?
Do you extract formatting information or just cell contents?

> I started with the
> standard xml tools (xml.dom and xml.dom.minidom). I built a
> pullparser, and then just crack them. The MS format is tedious and
> overly complex (like all MS stuff), but straightforward.

What do you think of the xml spat out by Excel 2007's (default) xlsx
format?

>  Once I've
> cracked them into their component parts (headers, rows, cells, etc),
> then I walk through them doing whatever I want.
>
> I found this material to be no worse than doing similar crud with
> xhtml. I know there are various python packages around that do it, but
> I found the learning curve of those packages to be steeper than just
> grokking the spreadsheet structure itself.

I'm curious to know which are the "various python packages" with the
so steep learning curves, and what the steep bits were.

Cheers,
John



--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Karen Tracey
On Wed, Dec 31, 2008 at 5:39 AM, Francesco Bochicchio
wrote:

> Francesco Bochicchio ha scritto:
>
>>
>>> No, in blocking mode it will wait to receive _some_ data (1 or
>>> more bytes).  The "requested" amount is strictly an upper
>>> limit: recv won't return more than the requested number of
>>> bytes, but it might return less.
>>>
>>>
>> Uhm. In my experience, with TCP protocol recv only returned less than the
>> required bytes if the remote end disconnects. I always check the
>> returned value of recv and signal an error if the read bytes are less than
>> the expected ones, but this error is never occurred (and its about 20 years
>> that I use sockets in various languages and various flavor of unix and
>> occasionally on windows. Maybe  have always been lucky ? :-)
>>
>>
> BTW, this is not a rethorical or ironic question... my applications mostly
> run on LANs or dedicated WANs so maybe they never experienced the
> kind of network congestion that could cause recv to return less than the
> expected amount of bytes ...
>
> but then, IIRC TCP guarantees that the packet is fully received by
> hand-shaking at transport level between sender and receiver. Ad once the
> packet is fully in the receiver buffer, why should recv choose to give
> back to the application only a piece of it?
>

One way to get less data than you ask for: TCP internally buffers a finite
amount of data for your connection.  If you ever ask to receive in one
recv() call more than TCP is willing to buffer for your connection, you will
get back only what TCP has buffered, not the amount you ask for, even if the
other side has sent the larger amount.  The remaining data will likely be
buffered in the TCP send buffers on the other side of the connection*.  Your
call to recv() will empty your side's receive buffers (it is likely TCP will
return all the data it has buffered in a single call, though I don't think
that is an API requirement), causing your side's TCP to send a window update
to the other side indicating it is willing to receive more data on the
connection, the data will be transfered, and a subsequent recv() call by
your application will be able to retrieve more of the data.

TCP provides a stream of bytes to its applications, not a datagram/packet
interface.  Assuming "packets" sent by one side will be received in their
entirety on a single receive call on the other side is really asking for
trouble.  TCP does not maintain any sort of packet boundaries that you seem
to think are implied by the sequence of sends issued on one side of the
connection.

Karen

*This is assuming the other side's send buffers aren't filled up by the
left-over data your TCP isn't willing to buffer.  If they are, and the
sending socket is in blocking mode, the sender will have been blocked during
the send waiting for buffer space to free up.  If the sender's socket is
non-blocking, and both the send and receive buffers fill up, then the
sending socket will start returning EWOULDBLOCK or EAGAIN (I forget which)
on calls to send data, until some buffer space is freed up by your side's
receiving some data.
--
http://mail.python.org/mailman/listinfo/python-list


Re: change only the nth occurrence of a pattern in a string

2008-12-31 Thread Roy Smith
In article <[email protected]>,
 TP  wrote:

> Hi everybody,
> 
> I would like to change only the nth occurence of a pattern in a string.

It's a little ugly, but the following looks like it works.  The gist is to 
split the string on your pattern, then re-join the pieces using the 
original delimiter everywhere except for the n'th splice.  Split() is a 
wonderful tool.  I'm a hard-core regex geek, but I find that most things I 
might have written a big hairy regex for are easier solved by doing split() 
and then attacking the pieces.

There may be some fencepost errors here.  I got the basics working, and 
left the details as an exercise for the reader :-)

This version assumes the pattern is a literal string.  If it's really a 
regex, you'll need to put the pattern in parens when you call split(); this 
will return the exact text matched each time as elements of the list.  And 
then your post-processing gets a little more complicated, but nothing 
that's too bad.

This does a couple of passes over the data, but at least all the operations 
are O(n), so the whole thing is O(n).


#!/usr/bin/python   
 

import re

v = "coucoucoucou"

pattern = "o"
n = 2
parts = re.split(pattern, v)
print parts

first = parts[:n]
last = parts[n:]
print first
print last

j1 = pattern.join(first)
j2 = pattern.join(last)
print j1
print j2
print "i".join([j1, j2])
print v
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Jean-Paul Calderone

On Wed, 31 Dec 2008 15:48:50 +0100, Francesco Bochicchio  
wrote:

< ... >

Uhm. In my experience, with TCP protocol recv only returned less than
the required bytes if the remote end disconnects. I always check the


What if the sending end actually sent less than you asked for ?

-srp


In blocking mode and with TCP protocol, the recv waits until more bytes are 
received -  mixing up the next message with the previous one and then 
loosing the 'sync' and being unable to interpretate the received data -  or 
the remote end disconnects.


Nope, this isn't how TCP works, whether your sockets are blocking or non-
blocking.  It's easy to see this:

 >>> s = socket.socket()
 >>> s.connect(('www.google.com', 80))
 >>> s.sendall('GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: 
keep-alive\r\n\r\n')
 >>> len(s.recv(1024 * 1024))
 6191
 >>> s.sendall('GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: 
keep-alive\r\n\r\n')
 >>> len(s.recv(1024 * 1024))
 6191
 >>> s.sendall('GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: 
keep-alive\r\n\r\n')
 >>> len(s.recv(1024 * 1024))
 6191
 >>> s.sendall('GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: 
keep-alive\r\n\r\n')
 >>> len(s.recv(1024 * 1024))
 6191
 >>>

Numerous blocking recv calls which returned fewer bytes than asked for
without the connection having been closed.

The only guarantee you get with a blocking socket is that the recv will
return at least one byte and at most the number of bytes you asked for
(or raise an exception instead).

On a LAN, it's likely that you'll generally get the exact number of bytes
which the sender passed to one call of send (until the sender starts to
pass really huge strings to send, then it'll get split up) just because
the network has lots of capacity compared to the traffic you're putting
on it.  However, even on a LAN it's not guaranteed, and on the internet,
it's extremely likely that this won't happen most of the time.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: change only the nth occurrence of a pattern in a string

2008-12-31 Thread Steven D'Aprano
On Wed, 31 Dec 2008 15:40:32 +0100, TP wrote:

> Hi everybody,
> 
> I would like to change only the nth occurence of a pattern in a string.
> The problem with "replace" method of strings, and "re.sub" is that we
> can only define the number of occurrences to change from the first one.
> 
 v="coucou"
 v.replace("o","i",2)
> 'ciuciu'
 import re
 re.sub( "o", "i", v,2)
> 'ciuciu'
 re.sub( "o", "i", v,1)
> 'ciucou'
> 
> What is the best way to change only the nth occurence (occurrence number
> n)?

Step 1: Find the nth occurrence.
Step 2: Change it.


def findnth(source, target, n):
num = 0
start = -1
while num < n:
start = source.find(target, start+1)
if start == -1: return -1
num += 1
return start

def replacenth(source, old, new, n):
p = findnth(source, old, n)
if n == -1: return source
return source[:p] + new + source[p+len(old):]


And in use:

>>> replacenth("abcabcabcabcabc", "abc", "WXYZ", 3)
'abcabcWXYZabcabc'


> Why this default behavior? For the user, it would be easier to put
> re.sub or replace in a loop to change the first n occurences.

Easier than just calling a function? I don't think so.

I've never needed to replace only the nth occurrence of a string, and I 
guess the Python Development team never did either. Or they thought that 
the above two functions were so trivial that anyone could write them. 



-- 
Steven
--
http://mail.python.org/mailman/listinfo/python-list


Re: change only the nth occurrence of a pattern in a string

2008-12-31 Thread Tim Chase
I would like to change only the nth occurence of a pattern in 
a string. The problem with "replace" method of strings, and

"re.sub" is that  we can only define the number of occurrences
to change from the  first one.


v="coucou"
v.replace("o","i",2)

'ciuciu'

import re
re.sub( "o", "i", v,2)

'ciuciu'

re.sub( "o", "i", v,1)

'ciucou'

What is the best way to change only the nth occurence
(occurrence number n)?


Well, there are multiple ways of doing this, including munging 
the regexp to skip over the first instances of a match. 
Something like the following untested:


  re.sub("((?:[^o]*o){2})o", r"\1i", s)

However, for a more generic solution, you could use something like

  import re
  class Nth(object):
def __init__(self, n_min, n_max, replacement):
  #assert n_min <= n_max, \
  #  "Hey, look, I don't know what I'm doing!"
  if n_max > n_min:
# don't be a dope
n_min, n_max = n_max, n_min
  self.n_min = n_min
  self.n_max = n_max
  self.replacement = replacement
  self.calls = 0
def __call__(self, matchobj):
  self.calls += 1
  if self.n_min <= self.calls <= self.n_max:
return self.replacement
  return matchobj.group(0)

  s = 'coucoucoucou'
  print "Initial:"
  print s
  print "Just positions 3-4:"
  print re.sub('o', Nth(3,4,'i'), s)
  for params in [
  (1, 1, 'i'),  # just the 1st
  (1, 2, 'i'),  # 1-2
  (2, 2, 'i'),  # just the 2nd
  (2, 3, 'i'),  # 2-3
  (2, 4, 'i'),  # 2-4
  (4, 4, 'i'),  # just the 4th
  ]:
print "Nth(%i, %i, %s)" % params
print re.sub('o', Nth(*params), s)


Why this default behavior?


Can't answer that one, but with so many easy solutions, it's not 
been a big concern of mine.


-tkc





--
http://mail.python.org/mailman/listinfo/python-list


How to initialize an array with a large number of members ?

2008-12-31 Thread David
Thanks to those who have helped a beginner in
Python. Using version 3.0

# script23
from array import array
< see failed initialization attempts  below >

tally = array('H',for i in range(75) : [0])

tally = array('H',[for i in range(75) : 0])

tally = array('H',range(75) : [0])

tally = array('H',range(75) [0])

  Above give either Syntax error or TypeError

   All examples of sequences in docs show only
   a few members being initialized. Array doc 
   says an iterator can be used, but doen't show
   how.  What would you do for a 2 dimensional 
   array ?  Incorporate c code ?
   The online docs are clearly insufficient for a
   novice.  Have ordered Summerfields new book.
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Grant Edwards
On 2008-12-31, Francesco Bochicchio  wrote:
> Grant Edwards ha scritto:
>> On 2008-12-30, Francesco Bochicchio  wrote:
>> 
>>> 3. AFAIK (sorry, I feel acronym-ly today ;), there is no difference in 
>>> select between blocking and non-blocking mode. The difference is in the
>>> recv (again, assuming that you use TCP as protocol, that is AF_INET, 
>>> SOCK_STREAM), which in the blocking case would wait to receive all the 
>>> bytes that you requested,
>> 
>> No, in blocking mode it will wait to receive _some_ data (1 or
>> more bytes).  The "requested" amount is strictly an upper
>> limit: recv won't return more than the requested number of
>> bytes, but it might return less.
>
> Uhm. In my experience, with TCP protocol recv only returned less than 
> the required bytes if the remote end disconnects.

I've no idea how you got recv() to behave that way, because
I've never seen it do that.  Take a look at the echo
client/server examples at http://docs.python.org/library/socket.html.

If recv worked the way you claimed it did, those programs
wouldn't work -- they would deadlock.  But, that example does
work.

In that example, the server program calls recv(1024), and yet
it returns 12 bytes.

The manual page for recv() specifically states that the "len"
parameter is a maximum:

   The maximum amount of data to be received at once is specified
   by bufsize. See the Unix manual page recv(2) for the meaning of
   the optional argument flags; it defaults to zero.

   Note: For best match with hardware and network realities, the value
 of bufsize should be a relatively small power of 2, for
 example, 4096.

The Linux man page for recv() also says len is the length of
the receive buffer and is an upper limit on the number of bytes
to read.

Can you post an example program that exhibits the behavior you
describe?


> [...]

> What I usually do, when I cannot block is:
>
> - use socket in blocking mode
> - do a select with a very small timeout and do a recv only if the select 
> returns with input events
> - (with TCP) do a recv for the exact amount of bytes that I expect ( 
> this mean having a user protocol that carries the message size in the 
> header, but this is usually the case ).
>
> This usually worked for me.

Yes that will usually (almost always) work.  But, IIRC, there
are theoretically situraitons where something happens after
select returns and before you call recv() that could cause
recv() to block.

-- 
Grant Edwards

--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Grant Edwards
On 2008-12-31, Benjamin Blundell  wrote:

> Hi all. I've had a look around the forums and the we and im looking
> for a library (or a set of libraries) for dealing with Visualisation
> and Interaction in Python.

Have you looked at VTK?  

http://www.vtk.org/

I've only used some of the numerical stuff (rather than the
visualization stuff).  The parts I've used have a rather
screwy, overly complex API because it's a thinly wrapped C++
library.  But, it appears to be quite powerful and well
documented.

http://cens.ioc.ee/projects/pyvtk/
http://www.imaging.robarts.ca/~dgobbi/vtk/vtkpython.html

-- 
Grant


--
http://mail.python.org/mailman/listinfo/python-list


Solved. was: Memory leak problem (while using tkinter)

2008-12-31 Thread André
On Dec 31, 12:21 am, André  wrote:
> I have written a small program (my first Tkinter-based app) to play
> around the idea mentioned on
> http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mo...
> and, in doing so, have encountered a memory leak problem.   I have
> seen mentions on the web of using the delete() method of canvas to
> prevent such problems - which I have tried to do with limited
> success.  Below is the code I wrote; to run it, you will need a small
> image file
> (I used the one found onhttp://alteredqualia.com/visualization/evolve/)
> that is saved under "mona_lisa.png".
>


It appears that the problem occurred due to creating drawing
"contexts" with aggdraw which became orphaned in some ways.  Below is
some changes that appear to solve the problem.  Perhaps this will be
useful to others at some point...

André


[SNIP]
>
> class AggDrawCanvas(Canvas):
>     def __init__(self, width, height, win):
>         Canvas.__init__(self, win)
>         self.image_id = None
>         self.win = win
>         self._width = width
>         self._height = height
>         self._size = width, height
>         self.config(width=width, height=height+20)
>         self.info = self.create_text(width/2, height+20)
>         self.pack()
>         self.dna = DNA(self._width, self._height)
>         self.mutations = 0

 self.img = None

>
>     def draw_dna(self):
>         img = Image.new("RGBA", self._size, "black")
>         self.context = aggdraw.Draw(img)

replace by:

if self.img is None:
self.img = Image.new("RGBA", self._size, "black")
self.context = aggdraw.Draw(self.img)
else:
brush = aggdraw.Brush((0, 0, 0), opacity=255)
self.context.rectangle((0, 0, self._width, self._height),
brush)




>         for gene in self.dna.dna:
>             brush = aggdraw.Brush(tuple(gene[1][0:3]), opacity=gene[1]
> [3])
>             self.context.polygon(gene[0], brush)
>         self.delete(img)
>         self.redraw()
>
[SNIP]
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to initialize an array with a large number of members ?

2008-12-31 Thread MRAB

[email protected] wrote:

Thanks to those who have helped a beginner in
Python. Using version 3.0

# script23
from array import array
< see failed initialization attempts  below >

tally = array('H',for i in range(75) : [0])

tally = array('H',[for i in range(75) : 0])

tally = array('H',range(75) : [0])

tally = array('H',range(75) [0])

  Above give either Syntax error or TypeError

   All examples of sequences in docs show only
   a few members being initialized. Array doc 
   says an iterator can be used, but doen't show
   how.  What would you do for a 2 dimensional 
   array ?  Incorporate c code ?

   The online docs are clearly insufficient for a
   novice.  Have ordered Summerfields new book.


>>> # With a list
>>> tally = array('H', [0] * 75)
>>>
>>> # With a generator
>>> tally = array('H', (0 for i in range(75)))
--
http://mail.python.org/mailman/listinfo/python-list


Desktop/File management support on MS Windows

2008-12-31 Thread [email protected]
Are there any Python libraries that can trash files (move to Trash,
not delete) or for example return a list of applications that can open
given file? I can't find anything related to this for Windows.
--
http://mail.python.org/mailman/listinfo/python-list


RE: error on windows with commands.getstatusoutput

2008-12-31 Thread Lee Harr

> Anyhow, I've replaced it with this:
> 
> 
> from subprocess import Popen, PIPE, STDOUT
> p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
> stderr=STDOUT, close_fds=True)
> output, unused = p.communicate()
> status = p.returncode
> 
> 
> Does that look more windows-friendly?


Unfortunately, no.

close_fds is also not available on windows (or at least not
when trying to capture stderr with stdout like this.)

So, now I'm going with ...

p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
  
stderr=STDOUT)


I don't really understand what close_fds does. I only put it
in because it was in the example code.

I have a report that this code works on windows,
and it is also working for me on linux.


_
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Desktop/File management support on MS Windows

2008-12-31 Thread r
On Dec 31, 11:08 am, "[email protected]" 
wrote:
> Are there any Python libraries that can trash files (move to Trash,
> not delete) or for example return a list of applications that can open
> given file? I can't find anything related to this for Windows.

try pywin32
http://python.net/crew/mhammond/win32/Downloads.html
--
http://mail.python.org/mailman/listinfo/python-list


Why not Ruby?

2008-12-31 Thread Xah Lee
Just spent 3 hours looking into Ruby today. Here's my short impression
for those interested.

* Why Not Ruby?
  http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html

plain text version follows:
--

Why Not Ruby?

Xah Lee, 2008-12-31

Spent about 3 hours looking into Ruby language today.

The articles i read in detail are:

* Wikipedia: Ruby (programming language)�J. Gives general overview.

* Brief tutorial: "Ruby in Twenty Minutes"
http://www.ruby-lang.org/en/documentation/quickstart/

* Personal blog by Stevey Yegge, published in 2004-10.
http://steve.yegge.googlepages.com/ruby-tour

The Wikipedia gives the best intro and overview in proper context. The
"Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete
intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't
teach much and rambles, but provide a little personal view. I read it
because his opinions i respect.

Q: Will you learn Ruby?

No. For practical application, the lang is some 100 times less useful
than each of Perl, Python, PHP, Javascript. For academic study,
functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far
more interesting and powerful in almost all aspects. Further, there's
also Perl6, NewLisp, Clojure, Scala... With respect to elegance or
power, these modern lang of the past 5 years matches or exceed Ruby.

Q: Do you think Ruby lang is elegant?

Yes. In my opinion, better than Perl, Python, PHP. As a high level
lang, it's far better than Java, C, C++ type of shit. However, i don't
think it is any better than emacs lisp, Scheme lisp, javascript,
Mathematica. Note that Ruby doesn't have a spec, and nor a formal
spec. Javascript has. Ruby's syntax isn't that regular, nor is it
based on a system. Mathemtica's is. Ruby's power is probably less than
Scheme, and probably same as Javascript.

I also didn't like the fact that ruby uses keyword "end" to indicate
code block much as Pascal and Visual Basic, Logo, do. I don't like
that.

Q: Won't Ruby be a interesting learning experience?

No. As far as semantics goes, Ruby is basically identical to Perl,
Python, PHP. I am a expert in Perl and PHP, and have working knowledge
of Python. I already regretted having spent significant amount of time
(roughly over a year) on Python. In retrospect, i didn't consider the
time invested in Python worthwhile. (as it turns out, i don't like
Python and Guido cult, as the lang is going the ways of OOP mumbo-
jumbo with its Python 3 "brand new" future.) There is absolutely
nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp,
Scheme lisp.

Q: Do you recommend new programers to learn Ruby then?

Not particularly. As i mentioned, if you are interested in practical
utility, there's already Perl, PHP, Python, Javascript, which are all
heavily used in the computing industry. If you are interested as a
academic exercise, there's Scheme lisp, and much of functional langs
such as OCaml, Haskell, Mathematica, which will teach you a whole lot
more about computer science, features of language semantics, etc.

Q: Do you condemn Ruby?

No. I think it's reasonably elegant, but today there are too many
languages, so Ruby don't particularly standout for me. Many of them,
are arguably quite more elegant and powerful than Ruby. See:
Proliferation of Computing Languages.

--
http://mail.python.org/mailman/listinfo/python-list


Re: SQL, lite lite lite

2008-12-31 Thread Joel Koltner
"Gerhard Häring"  wrote in message 
news:[email protected]...
> Using an ORM when you don't grasp the relational model and/or the SQL query 
> language is futile.

You'd probably be surprised just how many people there are out there using 
SQLlite (and other databases) who have no more than a 5 minute introduction to 
relational databasess.  "See, you have tables, and you can stick columns for 
various attributes, and then add records for rows, and if you make multiple 
tables you specify which attribute becomes a 'key value' to find the 
corresponding record in another.  Have fun!"

> That's probably the case for many other abstraction layers, too.

GUIs come to mind...


--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get back a list object from its string representation?

2008-12-31 Thread Gabriel Genellina
En Wed, 31 Dec 2008 04:27:01 -0200, Steven D'Aprano  
 escribió:



On Wed, 31 Dec 2008 03:08:29 -0200, Gabriel Genellina wrote:


eval is like Pandora´s box, all kind of bad things can come from it. Do
not use it with any user-supplied string. If you can restrict the values
to be just constants, there is a "safe eval" recipe in
http://code.activestate.com


The ast module in Python 2.6 includes a "literal eval" function:


ast.literal_eval("[1, 2, 3]")

[1, 2, 3]


That's a very nice addition!

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to initialize an array with a large number of members ?

2008-12-31 Thread bearophileHUGS
MRAB:
>  >>> # With a list
>  >>> tally = array('H', [0] * 75)
>  >>>
>  >>> # With a generator
>  >>> tally = array('H', (0 for i in range(75)))

Time ago we have had a long discussion about this, the right way is:

tally = array(someformat, [0]) * 75

(If you need to initialize it to something that isn't constant then
you may have to do something different).

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError when list append... plz help

2008-12-31 Thread Gabriel Genellina
En Wed, 31 Dec 2008 06:34:48 -0200, Steven D'Aprano  
 escribió:



Each time you are appending to the list, you append a tuple:

((i, j), sim)

where sim is a float and i and j are ints. How much memory does each of
those take?


sys.getsizeof( ((0, 1), 1.1) )

32


(On Windows, 32 bits, I get 36)


So each entry requires 32 bytes. 60 million times 32 bytes = almost 2GB
alone. Plus the list itself will require (approximately) between 230MB
and 460MB just for the pointers.


That was just the size of the "outer" tuple; you have to add the size of  
each element too. First one is another 2-item tuple (36 bytes too) plus  
its elements (two integers, 12 bytes each). Second element is a float and  
takes 16 bytes. Total: 112 bytes per item; the final size may be a bit  
smaller because some objects may be shared (e.g. small integers)


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Scott David Daniels

Jean-Paul Calderone wrote:

...
On a LAN, it's likely that you'll generally get the exact number of bytes
which the sender passed to one call of send (until the sender starts to
pass really huge strings to send, then it'll get split up) just because
the network has lots of capacity compared to the traffic you're putting
on it.  However, even on a LAN it's not guaranteed, and on the internet,
it's extremely likely that this won't happen most of the time.


I don't mean to rebut your point here,rather to "pile on" with a bit
more information.

One point I haven't seen mentioned in this discussion is that nodes in
the internet that carry the TCP/IP traffic are allowed to, for their own
purposes, break large packets up into several smaller packets, and
combine several smaller packets into a single larger packet.  So, no
matter how your TCP/IP packets leave your machine, there is no guarantee
they will reach the destination in the same clumps.  It is the stream,
and not the packets, that is provided by TCP/IP.

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Francesco Bochicchio

Saju Pillai ha scritto:

On Dec 31, 7:48 pm, Francesco Bochicchio  wrote:

Is this correct ? IIRC even in blocking mode recv() can return with
less bytes than requested, unless the MSG_WAITALL flag is supplied.
Blocking mode only guarantees that recv() will wait for a message if
none is available - but not that it *will* return the number of bytes
requested.

-srp



You are right ... most of my socket experience predates MSG_WAITALL, and 
I forgot that now the default behaviour is different ... oops ...


Ciao
--
FB
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread Roger
On Dec 31, 12:55 pm, Xah Lee  wrote:
> Just spent 3 hours looking into Ruby today. Here's my short impression
> for those interested.
>

Who are you?

In case no one tells you, you are a cocky, egotistical windbag with
opinions that border constructive but never gets there.  Why would
anyone care what you think?  Again, who are you?  Xah Lee?  And?  I
didn't subscribe to read reviews on Ruby.  And I'm pretty sure anyone
that bothers to subscribe to a group about programming has the
wherewithal to research a language themselves and come to their own
determiniation.

Also, this is a Python group and not Ruby.  I knew I should have
avoided this post and read the one about Nike Shoes from China.  At
least those bits of trolling spam don't try to mask themselves as
something worthwhile.
--
http://mail.python.org/mailman/listinfo/python-list


[ANN] Builds of PyWebkitGtk and Webkit-Glib-Gtk (r39359+#16401.master) for Debian i386, Debian AMD64 and Macports MacOSX 10.4

2008-12-31 Thread Luke Kenneth Casson Leighton
webkit-glib-gtk provides gobject bindings to webkit's DOM model.
pywebkitgtk provides python bindings to the gobject bindings of
webkit's DOM model.

files are available for download at:
https://sourceforge.net/project/showfiles.php?group_id=236659&package_id=290457&release_id=650548

separate pre-built .debs for AMD64 and i386 Debian are included, for
pywebkitgtk and webkit-gtk with gobject bindings to the DOM model.  if
you have seen OLPC/SUGAR's "hulahop", or if you have used Gecko / XUL
DOM bindings, or KDE's KHTMLPart DOM bindings, you will appreciate the
value of webkit-glib-gtk.  pywebkitgtk with glib/gobject bindings
basically brings pywebkitgtk on a par with hulahop.

if you find the thought of pywebkitgtk with glib bindings, and/or
hulahop to be "all too much", then do consider looking at pyjd (the
other download from the same location, above).  pyjd - aka
pyjamas-desktop - is a level "above" pywebkitgtk-glib, and is on a par
with pykde, pyqt4, pygtk2, python-wxWidgets and other desktop-based
widget sets.  (side-note: the advantage of pyjd is that if you write
an app which conforms to the pyjamas UI widget set API, you can
compile the same python app source code to javascript and run it
directly in all major web browsers: see http://pyjs.org, which is a
python-to-javascript compiler).

code-stability-wise, pywebkitgtk and webkit-glib-gtk should be
considered "experimental" (not least because this is a release from a
svn build!).  that having been said, pyjamas-desktop is declared
"production" because pywebkitgtk with DOM bindings, thanks to
webkit-glib-gtk, provides absolutely everything that pyjamas-desktop
needs (and if webkit-glib-gtk becomes a moving target, the DOM.py
abstraction layer in pyjamas-desktop will take care of it.  if it
becomes a _severe_ moving target, pyjamas-desktop will drop webkit and
provide a python-hulahop / XUL-Geck port instead.  or as well.
whatev :).

gobject-interface-wise, the webkit gobject DOM bindings that have been
added _can_ be considered to be "stable", as long as the underlying
webkit library IDL files are "stable" (additions to Console.idl were
made in the past couple of months, for example, and HTML5 is making
advances as well).  that having been said, _some_ functionality proved
intransigent during the initial main development phase of the webkit
gobject DOM bindings, such as RGBColour conversion of CSS Style
Properties, and so were *temporarily* left out.  given that
pyjamas-desktop is considered "production", that should give a pretty
clear indication of the importance of those rare bits of DOM model
bindings features that were left out.  SVG Canvas bindings, however,
have NOT been included, as that would have added a further 120
gobjects to the list.


instructions for anyone brave enough to install webkit-glib-gtk from
source, themselves, on macosx:
http://github.com/lkcl/webkit/wikis/installing-webkit-glib-on-macosx
there is an (experimental) Portfile in the macosx 10.4 glib tarball, as well.

please note that the MacOSX build is NOT a "native" webkit build: it
is a GTK / X11 build (known as a "gtk port", in webkit developer
terminology).  the reason for providing the MacOSX webkit-glib-gtk
build, along with a MacOSX port of pywebkitgtk is because the "native"
webkit build - which includes ObjectiveC bindings and thus can
automatically get python bindings - has very subtly different
functionality.  whilst the native ObjectiveC bindings are more fully
compliant with the W3C standards, providing javascript-like
functionality where absolutely necessary, the webkit-glib-gtk build's
gobject bindings are going specifically for direct correspondance with
the functionality provided by the webkit javascript bindings, falling
back to alternatives where it is absolutely not possible to achieve
that goal.

the actual differences, however, are extremely small, percentage-wise.
 out of around 300 objects, providing around 1,500 functions, and tens
of thousands of properties, there are approximately 20 functions that
are different, and only four properties that are different.

examples of the differences in the bindings APIs offered by ObjectiveC
and webkit-glib-gtk Gobject bindings include:

* the provision of the function "toString", which is known as a
javascriptism that is not in the W3C standard.  _not_ providing this
function, which is a de-facto standard, is considered to be
inconvenient, especially as both Gecko's language bindings _and_
PyKDE's PyKHTMLPart bindings provide toString() functions.  The
ObjectiveC bindings, in sticking to the W3C standard, religiously, do
not offer "toString".  the reason for including toString in the
webkit-glib-gtk bindings should be fairly obvious: it is unreasonable
to expect developers who will be used to the de-facto existence of
toString in javascript to find that it's ... disappeared for no good
reason, thus forcing them to make unnecessary coding workarounds,
duplicating the exact same functionality that *already

Re: Why not Ruby?

2008-12-31 Thread Giampaolo Rodola'
On 31 Dic, 18:55, Xah Lee  wrote:
> Just spent 3 hours looking into Ruby today. Here's my short impression
> for those interested.
>
> * Why Not Ruby?
>  http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html
>
> plain text version follows:
> --
>
> Why Not Ruby?
>
> Xah Lee, 2008-12-31
>
> Spent about 3 hours looking into Ruby language today.
>
> The articles i read in detail are:
>
> * Wikipedia: Ruby (programming language)�J. Gives general overview.
>
> * Brief tutorial: "Ruby in Twenty 
> Minutes"http://www.ruby-lang.org/en/documentation/quickstart/
>
> * Personal blog by Stevey Yegge, published in 
> 2004-10.http://steve.yegge.googlepages.com/ruby-tour
>
> The Wikipedia gives the best intro and overview in proper context. The
> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete
> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't
> teach much and rambles, but provide a little personal view. I read it
> because his opinions i respect.
>
> Q: Will you learn Ruby?
>
> No. For practical application, the lang is some 100 times less useful
> than each of Perl, Python, PHP, Javascript. For academic study,
> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far
> more interesting and powerful in almost all aspects. Further, there's
> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or
> power, these modern lang of the past 5 years matches or exceed Ruby.
>
> Q: Do you think Ruby lang is elegant?
>
> Yes. In my opinion, better than Perl, Python, PHP. As a high level
> lang, it's far better than Java, C, C++ type of shit. However, i don't
> think it is any better than emacs lisp, Scheme lisp, javascript,
> Mathematica. Note that Ruby doesn't have a spec, and nor a formal
> spec. Javascript has. Ruby's syntax isn't that regular, nor is it
> based on a system. Mathemtica's is. Ruby's power is probably less than
> Scheme, and probably same as Javascript.
>
> I also didn't like the fact that ruby uses keyword "end" to indicate
> code block much as Pascal and Visual Basic, Logo, do. I don't like
> that.
>
> Q: Won't Ruby be a interesting learning experience?
>
> No. As far as semantics goes, Ruby is basically identical to Perl,
> Python, PHP. I am a expert in Perl and PHP, and have working knowledge
> of Python. I already regretted having spent significant amount of time
> (roughly over a year) on Python. In retrospect, i didn't consider the
> time invested in Python worthwhile. (as it turns out, i don't like
> Python and Guido cult, as the lang is going the ways of OOP mumbo-
> jumbo with its Python 3 "brand new" future.) There is absolutely
> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp,
> Scheme lisp.
>
> Q: Do you recommend new programers to learn Ruby then?
>
> Not particularly. As i mentioned, if you are interested in practical
> utility, there's already Perl, PHP, Python, Javascript, which are all
> heavily used in the computing industry. If you are interested as a
> academic exercise, there's Scheme lisp, and much of functional langs
> such as OCaml, Haskell, Mathematica, which will teach you a whole lot
> more about computer science, features of language semantics, etc.
>
> Q: Do you condemn Ruby?
>
> No. I think it's reasonably elegant, but today there are too many
> languages, so Ruby don't particularly standout for me. Many of them,
> are arguably quite more elegant and powerful than Ruby. See:
> Proliferation of Computing Languages.

This is not a Ruby group.
I recommend you to go waste your time there.


--- Giampaolo
http://code.google.com/p/pyftpdlib
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-31 Thread Daniel Fetchinson
> Does anyone know if PIL will be ported to the 3.x branch?

Actually, Guilherme Polo has ported PIL 1.1.6 to python 3.0:

http://mail.python.org/pipermail/image-sig/2008-December/005338.html

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread Tim Greer
Giampaolo Rodola' wrote:

> This is not a Ruby group.
> I recommend you to go waste your time there.

That poster has a frequent habit of cross posting to multiple,
irrelevant news groups.  There's no rhyme or reason to it.  It's best
to just filter the guy's posts.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
--
http://mail.python.org/mailman/listinfo/python-list


type conversion

2008-12-31 Thread Hamish McKenzie
sometimes I want to be able to initialize an instance with a variety of 
different data types.

as an obvious example I might want to initialize a 4x4 matrix with either 16 
floats, a list/tuple or 16 floats, another matrix or a quaternion.

is there any other way to do it other than putting case statements in the 
__init__ method of the class, or having a Matrix.FromQuaternion( quat )?

thx
--
http://mail.python.org/mailman/listinfo/python-list


Creating an application for Linux

2008-12-31 Thread Mike Driscoll
Hi,

My boss wants me to port one of my applications to Ubuntu. I
successfully ported it without too many headaches but now I need a way
to distribute it to people that may or may not already have the
dependencies my application requires. I'm a newb with Linux so I'm not
even sure what they call the distribution (rpms, deb, source code).

After browsing the various "installer" docs out there, it looks like
bbfreeze or PyInstaller might work, but I couldn't find any examples.
Any advice is appreciated. Thanks!

I am using Python 2.5.2 and this is a wxPython application with
SqlAlchemy and a few other external packages.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an application for Linux

2008-12-31 Thread Benjamin Kaplan
On Wed, Dec 31, 2008 at 4:06 PM, Mike Driscoll  wrote:

> Hi,
>
> My boss wants me to port one of my applications to Ubuntu. I
> successfully ported it without too many headaches but now I need a way
> to distribute it to people that may or may not already have the
> dependencies my application requires. I'm a newb with Linux so I'm not
> even sure what they call the distribution (rpms, deb, source code).
>

Debian packages (debs) are basically a zipped directory with all of the
files, descriptions of where to put them, and a list of dependencies. You
can find more about them here.
http://www.debian.org/doc/FAQ/ch-pkg_basics.en.html


> After browsing the various "installer" docs out there, it looks like
> bbfreeze or PyInstaller might work, but I couldn't find any examples.
> Any advice is appreciated. Thanks!


When you create a debian package, you are trying to create a program for one
specific distro. Deb files are installers, closer to MSI files than EXE (I
assume you're coming from Windows). Using the deb files, you can install the
program into /usr/lib or /usr/local/lib, put the program on the system path,
and add it to the applications menu. You don't need to create a binary for
this- you can just run the python files directly. Using debian packages, you
can also add documentation and man pages. Apt will ensure that all of the
dependencies are installed before your program is. Using apt, you can also
uninstall the program easily. I haven't created any packages, so I don't
know how hard it is to generate the package.

bbfreeze and PyInstaller work differently. They create a binary executible
that the user can run. Everything the user needs (Python and all your
libraries) are put into a single file (or into an executable and a bunch of
library files). This is easier to distribute and will work on all versions
of Linux, but it won't be "installed" (to remove it, you have to manually
remove all the files). If you want to use these, you should probably look at
gui2exe (http://code.google.com/p/gui2exe/) rather than trying to figure out
the commands yourself. Andrea Gavana, the program's creator, follows the
wxPython-users list if you need help with it.


>
> I am using Python 2.5.2 and this is a wxPython application with
> SqlAlchemy and a few other external packages.
>
> Mike
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an application for Linux

2008-12-31 Thread lkcl
hiya mike: where do i know you from?  i've heard your name somewhere
and for the life of me can't remember where!  anyway... onwards.

your simplest bet is to take advantage of the .deb install system,
which, if you follow that, will allow you to pull in all of the
dependencies _without_ screwing around with the ubuntu distribution,
or requiring that you build "special" versions of the dependencies.

so - your first port of call is to locate a similar app to your own
one:

apt-cache  search wxwidgets
[rose-tinted filter on the results...]
cryptonit - A client side PKI (X.509) cryptographic tool
fontypython - A GUI tool to manage ttf fonts
jmdlx - jugglemaster deluxe using wxWidgets
wxmaxima - a wxWidgets GUI for the computer algebra system maxima
multiget - graphical download manager

then, do apt-cache show , paying particular attention to
the dependencies.  apt-cache show fontypython looks like a good
candidate.

so, do apt-get source fontypython (or other candidate)

also do apt-get build-essential dh-make dpkg-dev debutils python-dev
devscripts python-setuptools juuust for fun, but the essential ones
are probably dh-make and dpkg-dev.

then you have something to work from (an example - the source of the
deb-wrapped fontypython) and you will have most of the debian
developer utils etc. etc.

_then_ you go to e.g.  this:
http://www.pythonmark.com/python-library/debian/howto-build-a-debian-package-from-python-sources/
the preamble for which says "don't bother with that annoying ubuntu
python deb howto video, particularly on the basis that who gives a
stuff about _verbal_ instructions when you actually want stuff you can
READ!"

:)

the most important thing that _you_ need to remember is that you
_must_ identify the correct libraries (and their debian packagenames -
can't bring myself to say ubuntu packagenames) and make damn sure that
you add them into the dependencies in the debian/control file.

do _not_ be tempted to "bundle" customised versions of python-
pysqlite, python-sqlalchemy etc. etc.

testing: you should really use a debootstrap absolute "basic"
environment (set up a chroot, or a virtual KVM or other virtual PC,
qemu, whatever, or even a real machine) do NOT do a "full" install of
ubuntu, do an absolute minimalist install (netbook, businesscard,
whatever).

... and _then_ install your .deb (with dpkg -i) followed by apt-get -f
install (to pull in all of the dependencies).

then, use export DISPLAY=192.168.1.5:0.0 (adapt as necessary), run
xhost + on 192.168.1.5 (adapt as necessary), and _then_ fire up your
test app.

if you get a python library not found runtime error, you know that you
got your dependencies wrong, in the debian/control file.

if you install a "vanilla" ubuntu desktop, various other packages will
pull in the dependencies for you - and you will never find out if you
got all of the dependencies correct.

that having been said, if you don't _care_ about correctness, skip the
above six sentences :)

l.



On Dec 31, 9:06 pm, Mike Driscoll  wrote:
> Hi,
>
> My boss wants me to port one of my applications to Ubuntu. I
> successfully ported it without too many headaches but now I need a way
> to distribute it to people that may or may not already have the
> dependencies my application requires. I'm a newb with Linux so I'm not
> even sure what they call the distribution (rpms, deb, source code).
>
> After browsing the various "installer" docs out there, it looks like
> bbfreeze or PyInstaller might work, but I couldn't find any examples.
> Any advice is appreciated. Thanks!
>
> I am using Python 2.5.2 and this is a wxPython application with
> SqlAlchemy and a few other external packages.
>
> Mike

--
http://mail.python.org/mailman/listinfo/python-list


PyS60, GPS and SMS

2008-12-31 Thread makobu

# Send an SMS with your current GPS co-ordinates using a
# Nokia SmartPhone and PyS60
#
# Timothy Makobu, 01-01-2009


import positioning
import messaging
import appuifw
import sys


# Get your GPS co-ordinates #
def getCoordinates():
positioning.select_module(positioning.default_module())
positioning.set_requestors([{'type':'service',
'format':'application','data':'position'}])
try:
sys.stdout.write('Retrieving GPS co-ordinates ...\n')
data = positioning.position(course=1, satellites=1)
except:
sys.stdout.write('Could not retrieve GPS co-ordinates\n\n\n')
sys.exit(-1)
else:
sys.stdout.write('GPS co-ordinates retrieved\n')
return (data['position']['latitude'], data['position']
['longitude'])

# Send your GPS co-ordinates as an SMS #
def sendCoordinates(coords, number):
message = u'I\'m at location:\nLatitute  --> %f\nLongitute --> %f
\n' % coords
try:
sys.stdout.write('Sending SMS ...\n')
messaging.sms_send(number, message)
except:
sys.stdout.write('Could not send SMS :(\n\n\n')
sys.exit(-1)
else:
sys.stdout.write('SMS sent :)\n')


if __name__ == '__main__':
presetPhoneNumber = None # Enter phoneNumber here eg
'+25472200'
phoneNumber = presetPhoneNumber or appuifw.query(u'Enter number:
','text')
if not phoneNumber:
sys.stdout.write('No number entered; exiting ...\n\n\n')
sys.exit(-1)
sendCoordinates(getCoordinates(), phoneNumber)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an application for Linux

2008-12-31 Thread Mike Driscoll
On Dec 31, 3:36 pm, lkcl  wrote:
> hiya mike: where do i know you from?  i've heard your name somewhere
> and for the life of me can't remember where!  anyway... onwards.
>

I don't know...while your username looks vaguely familiar, I don't
think I've communicated with you recently. I spend most of my time on
the wxPython list now...


> your simplest bet is to take advantage of the .deb install system,
> which, if you follow that, will allow you to pull in all of the
> dependencies _without_ screwing around with the ubuntu distribution,
> or requiring that you build "special" versions of the dependencies.
>
> so - your first port of call is to locate a similar app to your own
> one:
>
> apt-cache  search wxwidgets
> [rose-tinted filter on the results...]
> cryptonit - A client side PKI (X.509) cryptographic tool
> fontypython - A GUI tool to manage ttf fonts
> jmdlx - jugglemaster deluxe using wxWidgets
> wxmaxima - a wxWidgets GUI for the computer algebra system maxima
> multiget - graphical download manager
>
> then, do apt-cache show , paying particular attention to
> the dependencies.  apt-cache show fontypython looks like a good
> candidate.
>
> so, do apt-get source fontypython (or other candidate)
>
> also do apt-get build-essential dh-make dpkg-dev debutils python-dev
> devscripts python-setuptools juuust for fun, but the essential ones
> are probably dh-make and dpkg-dev.
>
> then you have something to work from (an example - the source of the
> deb-wrapped fontypython) and you will have most of the debian
> developer utils etc. etc.
>
> _then_ you go to e.g.  
> this:http://www.pythonmark.com/python-library/debian/howto-build-a-debian-...
> the preamble for which says "don't bother with that annoying ubuntu
> python deb howto video, particularly on the basis that who gives a
> stuff about _verbal_ instructions when you actually want stuff you can
> READ!"
>
> :)
>
> the most important thing that _you_ need to remember is that you
> _must_ identify the correct libraries (and their debian packagenames -
> can't bring myself to say ubuntu packagenames) and make damn sure that
> you add them into the dependencies in the debian/control file.
>
> do _not_ be tempted to "bundle" customised versions of python-
> pysqlite, python-sqlalchemy etc. etc.
>
> testing: you should really use a debootstrap absolute "basic"
> environment (set up a chroot, or a virtual KVM or other virtual PC,
> qemu, whatever, or even a real machine) do NOT do a "full" install of
> ubuntu, do an absolute minimalist install (netbook, businesscard,
> whatever).


I thought the general practice was to test on the closest software/
hardware combo that your application was most likely to run on. I have
heard of doing testing on the lowest common denominator before though.
Unfortunately, I don't have time to set up a bare-bones VM since we're
closing soon, but I may give this a go on Friday and report back.

>
> ... and _then_ install your .deb (with dpkg -i) followed by apt-get -f
> install (to pull in all of the dependencies).
>
> then, use export DISPLAY=192.168.1.5:0.0 (adapt as necessary), run
> xhost + on 192.168.1.5 (adapt as necessary), and _then_ fire up your
> test app.
>
> if you get a python library not found runtime error, you know that you
> got your dependencies wrong, in the debian/control file.
>
> if you install a "vanilla" ubuntu desktop, various other packages will
> pull in the dependencies for you - and you will never find out if you
> got all of the dependencies correct.
>
> that having been said, if you don't _care_ about correctness, skip the
> above six sentences :)
>
> l.
>

Thanks for the instructions.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: type conversion

2008-12-31 Thread Steven D'Aprano
On Wed, 31 Dec 2008 12:35:20 -0800, Hamish McKenzie wrote:

> sometimes I want to be able to initialize an instance with a variety of
> different data types.

Type conversion is a bit of a misleading subject line. You're not really 
converting different types, just initialising from different types.

 
> as an obvious example I might want to initialize a 4x4 matrix with
> either 16 floats, a list/tuple or 16 floats, another matrix or a
> quaternion.
> 
> is there any other way to do it other than putting case statements in
> the __init__ method of the class, or having a Matrix.FromQuaternion(
> quat )?


You could have an external function qtom:

def qtom(quaternion):
a, b, c, d = quaternion
return Matrix([
a, 0, 0, 0,
0, b, 0, 0, 
0, 0, c, 0, 
0, 0, 0, d])


But the first two solutions seem reasonable to me, except of course 
Python doesn't have a case statement you have to use an if...elseif block.


-- 
Steven
--
http://mail.python.org/mailman/listinfo/python-list


Re: math module for Decimals

2008-12-31 Thread Steven D'Aprano
On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote:

> On Dec 28, 7:28 am, Steven D'Aprano  cybersource.com.au> wrote:
>> Ah crap, I forgot that from_float() has been left out of the decimal
>> API. That's very annoying.
> 
> Agreed.  It's maybe even annoying enough that a feature request at
> bugs.python.org might be honoured.  (Hint, hint!)


I can take a hint :)

http://bugs.python.org/issue4796#


Thank you for looking at this.


-- 
Steven
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing vs thread performance

2008-12-31 Thread Aaron Brady
On Dec 29, 9:29 am, mk  wrote:
> Christian Heimes wrote:
> > mk wrote:
> >> Am I doing smth wrong in code below? Or do I have to use
> >> multiprocessing.Pool to get any decent results?
>
> > You have missed an important point. A well designed application does
> > neither create so many threads nor processes.
>
> Except I was not developing "well designed application" but writing the
> test the goal of which was measuring the thread / process creation cost.
>
> > The creation of a thread
> > or forking of a process is an expensive operation.
>
> Sure. The point is, how expensive? While still being relatively
> expensive, it turns out that in Python creating a thread is much, much
> cheaper than creating a process via multiprocessing on Linux, while this
> seems to be not necessarily true on Mac OS X.
>
> > You should use a pool
> > of threads or processes.
>
> Probably true, except, again, that was not quite the point of this
> exercise..
>
> > The limiting factor is not the creation time but the communication and
> > synchronization overhead between multiple threads or processes.
>
> Which I am probably going to test as well.

I had an idea.  You could use 'multiprocessing' for synchronization,
and just use an mmap for the actual communication.  (I think it's a
good idea.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2008-12-31 Thread Aaron Brady
On Dec 30, 9:40 pm, "James Mills" 
wrote:
> Hey all,
>
> The "greenlet" fromhttp://codespeak.net/py/dist/greenlet.html
> is a rather interesting way of handling flow of control.
>
> I can't seem to find anything else on the subject
> except for the above link and the most recent version
> 0.2 and it's tests.
>
> What can "greenlet"'s be used for ? What use-cases
> have you guys used them for (if any) ?
>
> Can they be used in place of threads with much
> the same effect -  but more lightweight ?

I don't know Erlang, but it seems to be useful for a construction of a
unit of work that is more consistent with the underlying goal.

I had a dream for a while that in a GUI framework, every event would
spawn a unique thread.  The GUI would remain responsive even while
executing minor tasks.  Of course, shaving a second off running time
isn't exactly mission-critical to GUI users.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-31 Thread Aaron Brady
On Dec 29, 5:49 pm, "Joel Koltner" 
wrote:
> Thanks to everyone who responded; I'll be checking out the various toolkits
> people have listed!
>
> ---Joel

There is wxFormBuilder, which stores a GUI design in XML format.  It
may be lengthy, but your data reside in a data structure, and your
program resides in a program structure.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to initialize an array with a large number of members ?

2008-12-31 Thread Scott David Daniels

David Lemper wrote:

... Python. Using version 3.0
# script23
from array import array
< see failed initialization attempts  below >
tally = array('H',for i in range(75) : [0])
tally = array('H',[for i in range(75) : 0])
tally = array('H',range(75) : [0])
tally = array('H',range(75) [0])
  Above give either Syntax error or TypeError

 All examples of sequences in docs show only a few members
 being initialized. Array doc says an iterator can be used,
but doesn't show how. 

First, [1,2,3] is iterable.  You could look up iterators or
generators or list comprehension, but since it's the holidays:
import array
tally = array.array('H', (0 for i in range(75)))# a generator
tally = array.array('H', [0 for i in range(75)])# list comprehension

What would you do for a 2 dimensional array ?  

You'll have to wait for numpy for the most general 2-D,
but for list-of-array:
square = [array.array('H', (i * 100 + j for j in range(75)))
  for i in range(75)]
square[4][8]
--
http://mail.python.org/mailman/listinfo/python-list


Re: type conversion

2008-12-31 Thread Benjamin Kaplan
On Wed, Dec 31, 2008 at 5:26 PM, Steven D'Aprano <
[email protected]> wrote:

> On Wed, 31 Dec 2008 12:35:20 -0800, Hamish McKenzie wrote:
>
> > sometimes I want to be able to initialize an instance with a variety of
> > different data types.
>
> Type conversion is a bit of a misleading subject line. You're not really
> converting different types, just initialising from different types.
>
>
> > as an obvious example I might want to initialize a 4x4 matrix with
> > either 16 floats, a list/tuple or 16 floats, another matrix or a
> > quaternion.
> >
> > is there any other way to do it other than putting case statements in
> > the __init__ method of the class, or having a Matrix.FromQuaternion(
> > quat )?
>
>
> You could have an external function qtom:
>
> def qtom(quaternion):
>a, b, c, d = quaternion
>return Matrix([
>a, 0, 0, 0,
>0, b, 0, 0,
>0, 0, c, 0,
>0, 0, 0, d])
>
>
> But the first two solutions seem reasonable to me, except of course
> Python doesn't have a case statement you have to use an if...elseif block.


You could also use a dict with type:method key/value pairings. This is
closer to a switch/case than an if...elif chain is.
(untested)

def __init__(self, *args) :
inits = {list: self._init_from_list,
float: self._init_from_floats,
Matrix: self._init_from_matrix} #and so on
inits[type(args[0])](*args)




>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pass by reference

2008-12-31 Thread Aaron Brady
On Dec 31, 5:30 am, iu2  wrote:
> Hi,
>
> Is it possible somehow to change a varible by passing it to a
> function?
>
> I tried this:
>
> def change_var(dict0, varname, val):
>   dict0[varname] = val
>
> def test():
>   a = 100
>   change_var(locals(), 'a', 3)
>   print a
>
> But test() didn't work, the value a remains 100.
>
> I have several variables initialized to None.
> I need to convert each one of them an object only if it is None.
> something like:
>
> if not var1: var1 = MyObject()
>
> I want this to be a function, that is:
>
> def create_obj(var):
>   if not var: var = MyObj()
>   # set properties of var
>
> Now, I know I can achieve this by functional programming,
>
> def create_obj(var):
>   if not var:
>     x = MyObj()
>     # set properties of x
>     return x
>   return var
>
> and then
>
> var = creaet_obj(var)
>
> Is there another way?
>
> Thanks

A practical way is to use a container.  Some people use lists; I like
an object.

thingref= Ref( thing )
f( thingref )
print thingref() #or thingref.get() or w'ver.

Then 'f' can assign like this:

def f( aref ):
  # blah blah
  aref( newthing ) #or aref.set( newthing )

But the short answer is no.  A function receives the contents of a
variable, not a variable.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphics Library with Standard Interaction Features, 2D and 3D

2008-12-31 Thread Mirage
On Dec 31, 6:18 am, Stef Mientki  wrote:
> Maybe VPython (Visual) or Panda fits your needs.
> cheers,
> Stef

I second that. Panda3D is awesome in so many ways.
--
http://mail.python.org/mailman/listinfo/python-list


Re: SQL, lite lite lite

2008-12-31 Thread Aaron Brady
On Dec 30, 2:52 pm, Bruno Desthuilliers
 wrote:
> Aaron Brady a écrit :
>
> > On Dec 30, 11:16 am, [email protected] wrote:
> (snip)
> >> You really do like to reinvent the wheels do you? :-) Nothing wrong
> >> with that. Just be aware that most people that really need what you
> >> are proposing are probably already using mature feature rich libraries
> >> for that.
>
> >>http://wiki.python.org/moin/HigherLevelDatabaseProgramming
>
> > Look at these options!  Who invents the wheel?  Naturally, I've had
> > time to master every one.
>
> Oh, so that's why you propose to add yet another item to the list ?

Aha, so it is.  Your criticism might seem harsh, but it has an
advantage.  It made me get the lead out, that is, think.

Assuming I do want my Relation class to be backed by a full-fledged
database, all I would need is an adapter to a Dee or Django object.
The only restriction is, records have to be uniform types.  (In many
cases, this can be good, since relations are statically typed.)

I recognize that on average, I'm only saving a little syntax.  If I
have a Student object and I want the classes s/he is in, the SQL isn't
horrible.

SELECT objectrep FROM Classes WHERE Student IS studentA
//'IS' is not supported in SQL

It returns a list of Class instances.  The Python is better.

studentA.getClasses()

To make it fully dynamic,

studentA.get( 'Classes' ) or
studentA.get( Classes ) or
studentA.cross( Classes )

would be closer to what I have in mind.  If readers will permit a
brainstorm, maybe one of the options will spark an idea.

studentA and Classes
studentA.intersection( Classes )

However, I want a list of classes, not a list of students, so I am not
wanting a pure 'intersection' relation, that is, not a commutative
one.

Classes.get( studentA )
Classes and studentA  #breaks commutativity of 'and'
Classes.intersection( studentA )

The method will have to determine what field 'studentA' is supposed to
match.
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing vs thread performance

2008-12-31 Thread Paul Rubin
Aaron Brady  writes:
> I had an idea.  You could use 'multiprocessing' for synchronization,
> and just use an mmap for the actual communication.  (I think it's a
> good idea.)

Are you reinventing POSH?  (http://poshmodule.sourceforge.net)
--
http://mail.python.org/mailman/listinfo/python-list


Re: why cannot assign to function call

2008-12-31 Thread Aaron Brady
On Dec 31, 1:39 am, Tim Roberts  wrote:
> Aaron Brady  wrote:
>
> >I think the problem goes deeper than just English.  In any language
> >that has a plural, the propositions in question come out as, 'one
> >thing is two things' or 'two things are one thing'.  According to some
> >rules, these are ungrammatical sentences, due to plurality
> >disagreement.  Ex:
>
> >The Morning Star is ...
> >The Evening Star is ...
> >*The Morning Star and The Evening Star is...
> >*The Morning Star and The Evening Star are...
>
> >Neither of the latter two is correct.  (* marks ungrammatical.)   As
> >such, the listener isn't sure what meaning to take.
>
> This is taking a serious twist into off-topicness, but I need to dispute
> this.  I will assert that the 4th line is, in fact, grammatically correct,
> modulo the capitalization of the second "The".  The fragment is clearly of
> the form "X and Y are...", and regardless of the substitution of X and Y,
> the plurality of the subject agrees with the verb.
>
>   The Morning Star and the Evening Star are bright tonight.
>
> Ignoring the fact that we can't see both at the same time, why is the
> meaning of that unclear?

I want to get around to a clear answer to the OP's question, but I'm
frustrated by a month-long argument about it that suffered from some
serious misunderstandings of technical terms.  (Therefore, thanks for
entertaining my detour so far, as well as not jumping down my throat
yet.)  We didn't do a good job of explaining, and even disputed some
of the terms ourselves.  So, I'm trying to look for some clear,
vernacular language that won't confuse lay speakers in an explanation.

I agree that the form of the 4th fragment is 'X and Y are' in
general.  However, native speakers don't often use the form 'X and X
are'.  This is the source of my protest, because X = the Morning Star
= the Evening Star.  We don't say, 'G.H.W. Bush and the President
are...', say, at Camp David.  It is not that the meaning is unclear,
it's just that form is never used.

In fact, moreover, there is some exclusion implied.  If I said, 'I'm
going to St. Paul's and church,' my listener might think I had two
destinations, or I was being philosophical.  The conversational maxim
of quantity [1] even leads him/r to believe that I want to convey more
information that just that I'm going to church.

[1] http://en.wikipedia.org/wiki/Gricean_maxim#Maxim_of_Quantity

In other words, s/he infers that there is a reason I didn't say only,
'I'm going to St. Paul's' or 'I'm going to church', and s/he wants to
know what it is.

How all this relates to Python semantics is, if I say, 'a and b are
the same object', the listener can get confused.  I don't say, 'G.H.W.
Bush and the President are the same'; I say, 'G.H.W. Bush is the
President'.

Part of the problem is that Python divorced variables from their
contents; variables and objects are two different things.  One is a
key in a namespace lookup; the other is the value there.  I want to
conclude that, 'Therefore, there is no such thing as a reference to a
variable; only a namespace and a key'.  However, I'm not on firm
footing to explain further, due to the uncommonness of the forms of
speech I would need to use.  Maybe I could observe, 'variable
references are a peculiarity of C++, not available in every variable
model'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing vs thread performance

2008-12-31 Thread Philip Semanchuk


On Dec 31, 2008, at 7:19 PM, Paul Rubin wrote:


Aaron Brady  writes:

I had an idea.  You could use 'multiprocessing' for synchronization,
and just use an mmap for the actual communication.  (I think it's a
good idea.)


Are you reinventing POSH?  (http://poshmodule.sourceforge.net)


Or sysv_ipc? Or posix_ipc?

http://semanchuk.com/philip/sysv_ipc/
http://semanchuk.com/philip/posix_ipc/

Bug fix version of the latter coming out in a day or two...
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing vs thread performance

2008-12-31 Thread Aaron Brady
On Dec 31, 6:19 pm, Paul Rubin  wrote:
> Aaron Brady  writes:
> > I had an idea.  You could use 'multiprocessing' for synchronization,
> > and just use an mmap for the actual communication.  (I think it's a
> > good idea.)
>
> Are you reinventing POSH?  (http://poshmodule.sourceforge.net)

I thought the same thing!  Paul Boddie introduced me to POSH some
months ago.  I don't recall the implementation of synchro. objects in
POSH, but IIRC, 'multiprocessing' uses native OS handles opening in
multiple processes.  It could be that there would be substantial
overlap, or the trade-offs could be significant.  For one, the above
combination only permits strings to be shared, not objects.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread Bruno Desthuilliers

Roger a écrit :

On Dec 31, 12:55 pm, Xah Lee  wrote:

(snip)


Who are you?


His name is Xah Lee, and he's a well(hem)known troll. Just ignore him.
--
http://mail.python.org/mailman/listinfo/python-list


multiprocessing BaseManager doesn't clean up net connections?

2008-12-31 Thread Chris Brooks

Hi,

I'm trying to use remote managers in the multiprocessing module to listen
for some events synchronously while my program goes off and does other
things.  I use the .start() method which forks a new process to handle
communication.  When I catch the sigint and call sys.exit() though, the
network port is still bound even after the python interpretor finishes. 
Here is my short code and the output:

from multiprocessing.managers import BaseManager
import threading
import sys
import signal
import time

class WorkManager(BaseManager):
def __init__(self):
BaseManager.__init__(self,address=('', 51114), authkey='chris')
self.register('get_string', callable=self.getString)

def getString(self):
return "hi"

manager = WorkManager()
manager.start()

def quit( arg1, arg2 ):
sys.exit()

signal.signal(signal.SIGINT, quit)

#busy wait
while 1:
time.sleep(1)



cab...@ubuntu:~$ python2.6 server.py 
^ccab...@ubuntu:~$ python2.6 server.py 
Process WorkManager-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/multiprocessing/process.py", line 231, in
_bootstrap
self.run()
  File "/usr/local/lib/python2.6/multiprocessing/process.py", line 88, in
run
self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 517, in
_run_server
server = cls._Server(registry, address, authkey, serializer)
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 136, in
__init__
self.listener = Listener(address=address, backlog=5)
  File "/usr/local/lib/python2.6/multiprocessing/connection.py", line 97, in
__init__
self._listener = SocketListener(address, family, backlog)
  File "/usr/local/lib/python2.6/multiprocessing/connection.py", line 217,
in __init__
self._socket.bind(address)
  File "", line 1, in bind
error: [Errno 98] Address already in use
Traceback (most recent call last):
  File "server.py", line 16, in 
manager.start()
  File "/usr/local/lib/python2.6/multiprocessing/managers.py", line 499, in
start
self._address = reader.recv()
EOFError
cab...@ubuntu:~$ 


Comments?  Is this a bug, or is there a better way to clean up the manager
myself before shutting down?

Chris
-- 
View this message in context: 
http://www.nabble.com/multiprocessing-BaseManager-doesn%27t-clean-up-net-connections--tp21238615p21238615.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Easy-to-use Python GUI

2008-12-31 Thread Gerhard Häring

Dotan Cohen wrote:

I have been following this thread with interest. Is there a way to
build Qt apps with relative easy? I use KDE and would prefer the Qt
toolkit for my GUI apps. Thanks.


A few years ago, I've had bad experiences with wxPython (random things 
not actually working on Linux, only on Windows; getting segfaults when 
using not exactly the right values for API calls).


So, when I had to decide for a toolkit for a new application I'm 
developing on my job which required:


- ability to run on Windows
- ability to run on MacOS
- time to develop is short

I recommended to go with PyQt.

I remembered it was warmly recommended by Alex Martelli and others a few 
years ago.


So far, it's been nothing but joy. We bought the book "Rapid GUI 
Programming with Python and Qt" (http://www.qtrac.eu/pyqtbook.html) 
which is *really* well written. It's probably the best tech book I ever 
had. The author formerly did Qt documentation for Trolltech, so he has 
deep understanding of what he's writing about.


There may be not so many third-party add-ons for PyQt like for wxPython, 
 but in my opinion, the quality of Qt, PyQt and documentation like the 
book make up for it.


And, it's really extensive. So far I've found everything in Qt/PyQt I 
wanted/needed:


- MDI workspaces
- Dock windows
- I needed something like wxPythons wxOGL for a process modeler and 
after looking around for two days, I found out that it's already all 
there in Qt 4.4: QGraphicsScene/QGraphicsView

- etc.

-- Gerhard
--
http://mail.python.org/mailman/listinfo/python-list


Re: greenlets and how they can be used

2008-12-31 Thread James Mills
On Thu, Jan 1, 2009 at 9:24 AM, Aaron Brady  wrote:
(snip)

> I had a dream for a while that in a GUI framework, every event would
> spawn a unique thread.  The GUI would remain responsive even while
> executing minor tasks.  Of course, shaving a second off running time
> isn't exactly mission-critical to GUI users.

Do you think greenlet's (this implementation anyway)
would be useful in circuits (1) ? When you say every
even that was created would spawn a new thread
or greenlet ... Makes me wonder ... Just a thought ...
What's yours ?

cheers
James

1. http://trac.softcircuit.com.au/circuits/
--
http://mail.python.org/mailman/listinfo/python-list


Videocapture in python

2008-12-31 Thread koranthala
I face issues in videocapture in python. Cant find anyplace where we
can raise bug reports, so mentioning here. Also help required if
somebody has solved it earlier.

On using videocapture (python 2.4), I am facing the following issues
while creating a video sort of application.
-> Pull out the usb cable : Videocapture gets the data stored
initially in the buffer and returns always. The images are not updated
- but also there is no error returned.
i.e. there is no information to the viewer that it is not working
anymore. Especially because since the timestamp is updated everytime
(it is done inside videocapture.py - wherein current time is
overwritten on the received image), it gives a feeling that video is
running.

Currently I have done a workaround in that every 2 captures, i setup
the camera again - but it takes too much time. Anyone has any
suggestions on solving this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread Kenneth Tilton
Xah Lee wrote:
> Just spent 3 hours looking into Ruby today. Here's my short impression
> for those interested.
> 
> * Why Not Ruby?
>   http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html
> 
> plain text version follows:
> --
> 
> Why Not Ruby?
> 
> Xah Lee, 2008-12-31
> 
> Spent about 3 hours looking into Ruby language today.
> 
> The articles i read in detail are:
> 
> * Wikipedia: Ruby (programming language)�J. Gives general overview.
> 
> * Brief tutorial: "Ruby in Twenty Minutes"
> http://www.ruby-lang.org/en/documentation/quickstart/
> 
> * Personal blog by Stevey Yegge, published in 2004-10.
> http://steve.yegge.googlepages.com/ruby-tour
> 
> The Wikipedia gives the best intro and overview in proper context. The
> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete
> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't
> teach much and rambles, but provide a little personal view. I read it
> because his opinions i respect.
> 
> Q: Will you learn Ruby?
> 
> No. For practical application, the lang is some 100 times less useful
> than each of Perl, Python, PHP, Javascript. For academic study,
> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far
> more interesting and powerful in almost all aspects. Further, there's
> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or
> power, these modern lang of the past 5 years matches or exceed Ruby.
> 
> Q: Do you think Ruby lang is elegant?
> 
> Yes. In my opinion, better than Perl, Python, PHP. As a high level
> lang, it's far better than Java, C, C++ type of shit. However, i don't
> think it is any better than emacs lisp, Scheme lisp, javascript,
> Mathematica. Note that Ruby doesn't have a spec, and nor a formal
> spec. Javascript has. Ruby's syntax isn't that regular, nor is it
> based on a system. Mathemtica's is. Ruby's power is probably less than
> Scheme, and probably same as Javascript.
> 
> I also didn't like the fact that ruby uses keyword "end" to indicate
> code block much as Pascal and Visual Basic, Logo, do. I don't like
> that.
> 
> Q: Won't Ruby be a interesting learning experience?
> 
> No. As far as semantics goes, Ruby is basically identical to Perl,
> Python, PHP. I am a expert in Perl and PHP, and have working knowledge
> of Python. I already regretted having spent significant amount of time
> (roughly over a year) on Python. In retrospect, i didn't consider the
> time invested in Python worthwhile. (as it turns out, i don't like
> Python and Guido cult, as the lang is going the ways of OOP mumbo-
> jumbo with its Python 3 "brand new" future.) There is absolutely
> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp,
> Scheme lisp.
> 
> Q: Do you recommend new programers to learn Ruby then?
> 
> Not particularly. As i mentioned, if you are interested in practical
> utility, there's already Perl, PHP, Python, Javascript, which are all
> heavily used in the computing industry. If you are interested as a
> academic exercise, there's Scheme lisp, and much of functional langs
> such as OCaml, Haskell, Mathematica, which will teach you a whole lot
> more about computer science, features of language semantics, etc.
> 
> Q: Do you condemn Ruby?
> 
> No. I think it's reasonably elegant, but today there are too many
> languages, so Ruby don't particularly standout for me. Many of them,
> are arguably quite more elegant and powerful than Ruby. See:
> Proliferation of Computing Languages.
> 

Kenny Tilton, 2008-12-31

Q: Why not Xah's review of Ruby?

>> Spent about 3 hours looking into Ruby language today.

A. Three hours? I've had belches that lasted longer than that. Of
course, a true master can tell a lot in just a few hours of coding with
a new language...

>> The articles i read in detail are:

Q: Read?!

A: That's what he said.


hth,kzo

--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread member thudfoo
2008/12/31 Giampaolo Rodola' :
> On 31 Dic, 18:55, Xah Lee  wrote:
>> Just spent 3 hours looking into Ruby today. Here's my short impression
[...]

> --- Giampaolo
> http://code.google.com/p/pyftpdlib
>

Hey, Giampaolo:

I had gone to the trouble to filter out the posts from xah lee, but
you have quoted his entire message. If you would like to scold xah
lee, you can do so directly without reposting to this fine newsgroup.

Thank You Very Much.

> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why not Ruby?

2008-12-31 Thread sln
On Wed, 31 Dec 2008 23:16:41 -0500, Kenneth Tilton  wrote:

>Xah Lee wrote:
>> Just spent 3 hours looking into Ruby today. Here's my short impression
>> for those interested.
>> 
>> * Why Not Ruby?
>>   http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html
>> 
>> plain text version follows:
>> --
>> 
>> Why Not Ruby?
>> 
>> Xah Lee, 2008-12-31
>> 
>> Spent about 3 hours looking into Ruby language today.
>> 
>> The articles i read in detail are:
>> 
>> * Wikipedia: Ruby (programming language)¨J. Gives general overview.
>> 
>> * Brief tutorial: "Ruby in Twenty Minutes"
>> http://www.ruby-lang.org/en/documentation/quickstart/
>> 
>> * Personal blog by Stevey Yegge, published in 2004-10.
>> http://steve.yegge.googlepages.com/ruby-tour
>> 
>> The Wikipedia gives the best intro and overview in proper context. The
>> "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete
>> intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't
>> teach much and rambles, but provide a little personal view. I read it
>> because his opinions i respect.
>> 
>> Q: Will you learn Ruby?
>> 
>> No. For practical application, the lang is some 100 times less useful
>> than each of Perl, Python, PHP, Javascript. For academic study,
>> functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far
>> more interesting and powerful in almost all aspects. Further, there's
>> also Perl6, NewLisp, Clojure, Scala... With respect to elegance or
>> power, these modern lang of the past 5 years matches or exceed Ruby.
>> 
>> Q: Do you think Ruby lang is elegant?
>> 
>> Yes. In my opinion, better than Perl, Python, PHP. As a high level
>> lang, it's far better than Java, C, C++ type of shit. However, i don't
>> think it is any better than emacs lisp, Scheme lisp, javascript,
>> Mathematica. Note that Ruby doesn't have a spec, and nor a formal
>> spec. Javascript has. Ruby's syntax isn't that regular, nor is it
>> based on a system. Mathemtica's is. Ruby's power is probably less than
>> Scheme, and probably same as Javascript.
>> 
>> I also didn't like the fact that ruby uses keyword "end" to indicate
>> code block much as Pascal and Visual Basic, Logo, do. I don't like
>> that.
>> 
>> Q: Won't Ruby be a interesting learning experience?
>> 
>> No. As far as semantics goes, Ruby is basically identical to Perl,
>> Python, PHP. I am a expert in Perl and PHP, and have working knowledge
>> of Python. I already regretted having spent significant amount of time
>> (roughly over a year) on Python. In retrospect, i didn't consider the
>> time invested in Python worthwhile. (as it turns out, i don't like
>> Python and Guido cult, as the lang is going the ways of OOP mumbo-
>> jumbo with its Python 3 "brand new" future.) There is absolutely
>> nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp,
>> Scheme lisp.
>> 
>> Q: Do you recommend new programers to learn Ruby then?
>> 
>> Not particularly. As i mentioned, if you are interested in practical
>> utility, there's already Perl, PHP, Python, Javascript, which are all
>> heavily used in the computing industry. If you are interested as a
>> academic exercise, there's Scheme lisp, and much of functional langs
>> such as OCaml, Haskell, Mathematica, which will teach you a whole lot
>> more about computer science, features of language semantics, etc.
>> 
>> Q: Do you condemn Ruby?
>> 
>> No. I think it's reasonably elegant, but today there are too many
>> languages, so Ruby don't particularly standout for me. Many of them,
>> are arguably quite more elegant and powerful than Ruby. See:
>> Proliferation of Computing Languages.
>> 
>
>Kenny Tilton, 2008-12-31
>
>Q: Why not Xah's review of Ruby?
>
>>> Spent about 3 hours looking into Ruby language today.
>
>A. Three hours? I've had belches that lasted longer than that. Of
>course, a true master can tell a lot in just a few hours of coding with
>a new language...
>
>>> The articles i read in detail are:
>
>Q: Read?!
>
>A: That's what he said.
>
>
>hth,kzo

Be carefull what you say. If they pay me I would rip your and Xah's
guts out in a second.

sln

--
http://mail.python.org/mailman/listinfo/python-list


Re: select.select and socket.setblocking

2008-12-31 Thread Hendrik van Rooyen
"Francesco Bochicchio"  wrote:

> but then, IIRC TCP guarantees that the packet is fully received by 
> hand-shaking at transport level between sender and receiver. Ad once the 
> packet is fully in the receiver buffer, why should recv choose to give
> back to the application only a piece of it?

This depends a lot on the definition of "package" - 

At the TCP/IP level, the protocol is quite complex - there 
are all sorts of info flowing back and forth, telling the 
transmitter how much space the receiver has available.
So your "record" or "package" could be split up...

But it gets worse, or better, depending on your point of view:

At the ethernet level, a packet is less than 1.5k - so if your
record is longer, it can also be split up - OTOH, if it all
fits into one ethernet packet, there is every chance that
it won't be split up, unless you send a lot of them in a row,
without waiting for a response - if you are running something that
sends a small request and listens for a small answer, then you
will probably never see a record split - but if you run a kind
of sliding window protocol that streams a lot of data (even in
small packets) then sooner or later one of them will be partly
delivered...

- Hendrik


--
http://mail.python.org/mailman/listinfo/python-list