Re: pyWin32 attempted installation; Error message: Skipping exchdapi: No library 'Ex2KSdk'

2011-01-02 Thread Kev Dwyer
On Sat, 01 Jan 2011 20:53:47 -0800, marceepoo wrote:

> I just downloaded pyWin32 (https://sourceforge.net/projects/pywin32/)
> and started to install it.
> 
> I get these error msgs:
> 
> Skipping exchange: No library 'Ex2KSdk' Skipping exchdapi: No library
> 'Ex2KSdk' Skipping directsound: The header 'dsound.h' can not be located
> 
> Does anyone have any suggestions about how to address this?
> 
> Thanks,Marceepoo

Are you using the binary installer or building from source?

Cf 
http://stackoverflow.com/questions/4476764/pywin32-support-trouble-while-building-syntax-error

Cheers,

Kev

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


Re: How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

2011-01-02 Thread Stefan Behnel

Terry Reedy, 01.01.2011 23:47:

1. Code running in multiple versions has to be syntactically correct in
every detail all versions in order to be compiled without error. However,
version specific syntax *can* be used in modules that are conditionally
imported and therefore conditionally compiled and executed.


This is something that might also be a suitable solution for the OP's 
problem. The format strings can be by externalised into an importable 
module, which can then be duplicated to use the 'b' bytes prefix for Python 3.


The obvious drawback is that this moves the strings out of the immediate 
sight of someone reading the sources, and that it requires the two string 
modules to be kept in sync. But at least for the synchronisation, a 
simplistic conversion tool run during installation could do the trick.


Stefan

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


list 2 dict?

2011-01-02 Thread Octavian Rasnita
Hi,

If I want to create a dictionary from a list, is there a better way than the 
long line below?

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
range(len(l)) if x %2 == 1]))

print(d)

{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

Thanks.

Octavian

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


Re: CPython on the Web

2011-01-02 Thread Katie T
On Sun, Jan 2, 2011 at 7:26 AM, azakai  wrote:
> The idea is that by compiling CPython itself, all the features of the
> language are immediately present, and at the latest version, unlike
> writing a new implementation which takes time and tends to lag behind.
> As to why run it on the web, there could be various uses, for example
> it could allow a simple learning environment for Python, which since
> it's on the web can be entered immediately without any download (and
> would run even in places where Python normally can't, like say an
> iPad).

It looks pretty neat ! - most solutions I've seen involve running
Python in a sandbox environment on the server as opposed to on the
client desktop.

Katie
-- 
CoderStack
http://www.coderstack.co.uk/perl-jobs
The Software Developer Job Board
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-02 Thread Ian Kelly

On 1/2/2011 6:18 AM, Octavian Rasnita wrote:

Hi,

If I want to create a dictionary from a list, is there a better way than the 
long line below?

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
range(len(l)) if x %2 == 1]))


d = dict(zip(l[0::2], l[1::2]))

Or, using the "grouper" function recipe from the itertools documentation:

d = dict(grouper(2, l))

Cheers,
Ian

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


Re: list 2 dict?

2011-01-02 Thread Stefan Sonnenberg-Carstens

Am 02.01.2011 14:18, schrieb Octavian Rasnita:

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
dict(zip(l[0::2],l[1::2]))
{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}
--
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-02 Thread python
Azakai,

WOW! That's incredible!! Thank you for sharing your work with the
community.

1. Are there plans to support IE 7 or 8?

2. I'm not sure what you mean by non-static modules? Can we use modules
such as json, pickle/cPickle, StringIO/cStringIO?

3. Is there a virtual file system we can take advantage of so calls to
open() would work?

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


Re: CPython on the Web

2011-01-02 Thread Octavian Rasnita
From: "Katie T" 
Subject: Re: CPython on the Web


> On Sun, Jan 2, 2011 at 7:26 AM, azakai  wrote:
>> The idea is that by compiling CPython itself, all the features of the
>> language are immediately present, and at the latest version, unlike
>> writing a new implementation which takes time and tends to lag behind.
>> As to why run it on the web, there could be various uses, for example
>> it could allow a simple learning environment for Python, which since
>> it's on the web can be entered immediately without any download (and
>> would run even in places where Python normally can't, like say an
>> iPad).
> 
> It looks pretty neat ! - most solutions I've seen involve running
> Python in a sandbox environment on the server as opposed to on the
> client desktop.
> 
> Katie
> -- 


I don't understand what can be this program used for. Can anyone explain please?

Ok, I understand that it can be used for learning, which is pretty useless 
because I doubt that a Python newbie will start using Python and learning 
Python that way.

Then, how can the Python programs run on the "desktop"?
I suspect that the Python code is somehow translated to Javascript in order to 
run on the browser. Am I right?

If yes, then how can run a Python code that access a database or one that 
create a web server, or a WxPython GUI run?

If it can run just simple things that prints things in the browser, then why 
not writing that code directly in JS?


As you can see, there are many things I don't understand. :-)

Thank you.

BTW. I have tried that page, and it appeared a JS error window telling that the 
JS scripts run too slow and it asked me if I want to continue.
I have executed the default Python script, but nothing happend. Nothing was 
printed. I use Internet Explorer.

Octavian


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


Re: list 2 dict?

2011-01-02 Thread Rob Williscroft
Octavian Rasnita wrote in news:0db6c288b2274dbba5463e7771349...@teddy in
gmane.comp.python.general: 

> Hi,
> 
> If I want to create a dictionary from a list, is there a better way
> than the long line below? 
> 
> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
> 
> d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x
> in range(len(l)) if x %2 == 1])) 
> 
> print(d)
> 
> {8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

>>> dict( zip( l[ :: 2 ], l[ 1 :: 2 ] ) )
{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

If you don't know about slice notation, the synatax I'm using above is:

list[ start : stop : step ]

where I have ommited the "stop" item, which defaults to the length of the
list.



That will make 3 lists before it makes the dict thought, so if the
list is large:

>>> dict( ( l[ i ], l[ i + 1 ] ) for i in xrange( 0, len( l ), 2 ) )

may be better.

Rob.

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


Re: list 2 dict?

2011-01-02 Thread Hrvoje Niksic
"Octavian Rasnita"  writes:

> If I want to create a dictionary from a list, is there a better way than the 
> long line below?
>
> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>
> d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
> range(len(l)) if x %2 == 1]))
>
> print(d)
>
> {8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

it = iter(l)
d = dict(izip(it, it))

izip is the iterator equivalent of zip, import it from itertools.  (Or, if
your list is short, just use zip instead.)

It can be written in a single short line, at the cost of additional
obfuscation:

d = dict(izip(*[iter(l)]*2))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-02 Thread Stefan Sonnenberg-Carstens

Am 02.01.2011 14:18, schrieb Octavian Rasnita:

Hi,

If I want to create a dictionary from a list, is there a better way than the 
long line below?

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
range(len(l)) if x %2 == 1]))

print(d)

{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

Thanks.

Octavian


Or so:

dict(zip((y for x,y in enumerate(l) if x%2==0),(y for x,y in 
enumerate(l) if not x%2==0)))

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


Re: list 2 dict?

2011-01-02 Thread Octavian Rasnita
From: "Ian Kelly" 


> On 1/2/2011 6:18 AM, Octavian Rasnita wrote:
>> Hi,
>>
>> If I want to create a dictionary from a list, is there a better way than the 
>> long line below?
>>
>> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>>
>> d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
>> range(len(l)) if x %2 == 1]))
> 
> d = dict(zip(l[0::2], l[1::2]))
> 
> Or, using the "grouper" function recipe from the itertools documentation:
> 
> d = dict(grouper(2, l))
> 
> Cheers,
> Ian


The grouper-way looks nice, but I tried it and it didn't work:

from itertools import *
...
d = dict(grouper(2, l))

NameError: name 'grouper' is not defined

I use Python 2.7. Should it work with this version?
Octavian

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


Re: list 2 dict?

2011-01-02 Thread Octavian Rasnita
From: "Rob Williscroft" 

> Octavian Rasnita wrote in news:0db6c288b2274dbba5463e7771349...@teddy in
> gmane.comp.python.general: 
> 
>> Hi,
>> 
>> If I want to create a dictionary from a list, is there a better way
>> than the long line below? 
>> 
>> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>> 
>> d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x
>> in range(len(l)) if x %2 == 1])) 
>> 
>> print(d)
>> 
>> {8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}
> 
 dict( zip( l[ :: 2 ], l[ 1 :: 2 ] ) )
> {8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}
> 
> If you don't know about slice notation, the synatax I'm using above is:
> 
>list[ start : stop : step ]
> 
> where I have ommited the "stop" item, which defaults to the length of the
> list.
> 
> 
>  list-tuple-bytearray-buffer-xrange>
> 
> That will make 3 lists before it makes the dict thought, so if the
> list is large:
> 
> >>> dict( ( l[ i ], l[ i + 1 ] ) for i in xrange( 0, len( l ), 2 ) )
> 
> may be better.


Thank you all.

I have also discovered that I can zip 2 lists made with range(0, len(l), 2) and 
range(1, len(l), 2) but I remembered about that the slice notation accepts that 
third argument and as Stefan suggested, looks to be a shorter way.

I have first thought to the solution you suggested, but I have forgotten to 
create a tuple from the pair of elements so it didn't work.
I wasn't thinking to performance, but yes, it may be important for large lists.

It seems that in some cases there are more ways to do it in Python than in 
Perl. :-)

Octavian

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


Re: list 2 dict?

2011-01-02 Thread Stefan Sonnenberg-Carstens

Am 02.01.2011 16:36, schrieb Octavian Rasnita:

From: "Ian Kelly"



On 1/2/2011 6:18 AM, Octavian Rasnita wrote:

Hi,

If I want to create a dictionary from a list, is there a better way than the 
long line below?

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
range(len(l)) if x %2 == 1]))

d = dict(zip(l[0::2], l[1::2]))

Or, using the "grouper" function recipe from the itertools documentation:

d = dict(grouper(2, l))

Cheers,
Ian


The grouper-way looks nice, but I tried it and it didn't work:

from itertools import *
...
d = dict(grouper(2, l))

NameError: name 'grouper' is not defined

I use Python 2.7. Should it work with this version?
Octavian


A last one:

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
dict((x[1],x[0]) for x in ((l.pop(),l.pop()) for x in xrange(len(l)/2)))
--
http://mail.python.org/mailman/listinfo/python-list


Python programming

2011-01-02 Thread Maurice Shih
Dear python-list@python.org,
I am making a program of the quadratic sieve on python 2.5.2. I am also 
using sympy to find linear dependencies in mod 2. For example matrix A is :
10110
01101
00011
1
And using sympy I can type in a command to solve ax=0, which is:
1=0
01002=0
0010-1=0
00011=0
To find the values of vector x is easy by hand if you assign one value as 1, 
but I was wondering if I could turn the numbers into letters ( variables) so I 
could run the solve command in sympy. Thank you for listening to by question 
and I hope that you can help me. Thank you again.


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


Re: String building using join

2011-01-02 Thread gervaz
On 31 Dic 2010, 16:43, Emile van Sebille  wrote:
> On 12/31/2010 7:22 AM gervaz said...
>
>
>
>
>
> > Hi all, I would like to ask you how I can use the more efficient join
> > operation in a code like this:
>
>  class Test:
> > ...     def __init__(self, v1, v2):
> > ...         self.v1 = v1
> > ...         self.v2 = v2
> > ...
>  def prg(l):
> > ...     txt = ""
> > ...     for x in l:
> > ...         if x.v1 is not None:
> > ...             txt += x.v1 + "\n"
> > ...         if x.v2 is not None:
> > ...             txt += x.v2 + "\n"
> > ...     return txt
> > ...
>  t1 = Test("hello", None)
>  t2 = Test(None, "ciao")
>  t3 = Test("salut", "hallo")
>  t = [t1, t2, t3]
>
>  prg(t)
> > 'hello\nciao\nsalut\nhallo\n'
>
> > The idea would be create a new list with the values not None and then
> > use the join function... but I don't know if it is really worth it.
> > Any hint?
>
>  def prg2(l):
>
>              return "\n".join([x for x in l if x])
>
> Emile
>
>
>
> > ...     e = []
> > ...     for x in l:
> > ...         if x.v1 is not None:
> > ...             e.append(x.v1)
> > ...         if x.v2 is not None:
> > ...             e.append(x.v2)
> > ...     return "\n".join(e)
> > ...
>  prg2(t)
> > 'hello\nciao\nsalut\nhallo'
>
> > Thanks, Mattia- Nascondi testo citato
>
> - Mostra testo citato -- Nascondi testo citato
>
> - Mostra testo citato -

Sorry, but it does not work

>>> def prg3(l):
... return "\n".join([x for x in l if x])
...
>>> prg3(t)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in prg3
TypeError: sequence item 0: expected str instance, Test found
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-02 Thread gervaz
On 31 Dic 2010, 23:25, Alice Bevan–McGregor 
wrote:
> On 2010-12-31 10:28:26 -0800, John Nagle said:
>
> > Even worse, sending control-C to a multi-thread program
> > is unreliable in CPython.  See "http://blip.tv/file/2232410";
> > for why.  It's painful.
>
> AFIK, that has been resolved in Python 3.2 with the introduction of an
> intelligent thread scheduler as part of the GIL release/acquire process.
>
>         - Alice.

Ok, but then suppose I have multiple long running threads that I want
to delete/suspend because they are tooking too much time, which
solution do you propose?

Thanks,

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


Re: list 2 dict?

2011-01-02 Thread Alex Willmer
On Sunday, January 2, 2011 3:36:35 PM UTC, T wrote:
> The grouper-way looks nice, but I tried it and it didn't work:
> 
> from itertools import *
> ...
> d = dict(grouper(2, l))
> 
> NameError: name 'grouper' is not defined
> 
> I use Python 2.7. Should it work with this version?

No. As Ian said grouper() is a receipe in the itertools documentation. 

http://docs.python.org/library/itertools.html#recipes

The module doesn't provide it directly
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String building using join

2011-01-02 Thread Emile van Sebille

On 1/2/2011 9:43 AM gervaz said...

On 31 Dic 2010, 16:43, Emile van Sebille  wrote:

On 12/31/2010 7:22 AM gervaz said...






Hi all, I would like to ask you how I can use the more efficient join
operation in a code like this:



class Test:

... def __init__(self, v1, v2):
... self.v1 = v1
... self.v2 = v2
...

def prg(l):

... txt = ""
... for x in l:
... if x.v1 is not None:
... txt += x.v1 + "\n"
... if x.v2 is not None:
... txt += x.v2 + "\n"
... return txt
...

t1 = Test("hello", None)
t2 = Test(None, "ciao")
t3 = Test("salut", "hallo")
t = [t1, t2, t3]



prg(t)

'hello\nciao\nsalut\nhallo\n'



The idea would be create a new list with the values not None and then
use the join function... but I don't know if it is really worth it.
Any hint?



def prg2(l):


  return "\n".join([x for x in l if x])

Emile




... e = []
... for x in l:
... if x.v1 is not None:
... e.append(x.v1)
... if x.v2 is not None:
... e.append(x.v2)
... return "\n".join(e)
...

prg2(t)

'hello\nciao\nsalut\nhallo'



Thanks, Mattia- Nascondi testo citato


- Mostra testo citato -- Nascondi testo citato

- Mostra testo citato -


Sorry, but it does not work


Oh -- you want a working solution, not a hint?  OK.

class Test:
 def __init__(self, v1, v2):
 self.v1 = v1
 self.v2 = v2


t1 = Test("hello", None)
t2 = Test(None, "ciao")
t3 = Test("salut", "hallo")
t = [t1, t2, t3]


"\n".join([y for x in t for y in [x.v1,x.v2] if y])

Emile




def prg3(l):

... return "\n".join([x for x in l if x])
...

prg3(t)

Traceback (most recent call last):
   File "", line 1, in
   File "", line 2, in prg3
TypeError: sequence item 0: expected str instance, Test found



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


Re: String building using join

2011-01-02 Thread Alex Willmer
On Sunday, January 2, 2011 5:43:38 PM UTC, gervaz wrote:
> Sorry, but it does not work
> 
> >>> def prg3(l):
> ... return "\n".join([x for x in l if x])
> ...
> >>> prg3(t)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in prg3
> TypeError: sequence item 0: expected str instance, Test found

def prg3(l):
return '\n'.join([str(x) for x in l if x])

That should do it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-02 Thread Emile van Sebille

On 1/2/2011 8:31 AM Stefan Sonnenberg-Carstens said...


A last one:

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
dict((x[1],x[0]) for x in ((l.pop(),l.pop()) for x in xrange(len(l)/2)))


This also works:


l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

pop=l.pop

dict([(pop(),pop()) for i in l])

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


Re: list 2 dict?

2011-01-02 Thread Emile van Sebille

On 1/2/2011 8:31 AM Stefan Sonnenberg-Carstens said...

Nevermind -- my bad.

Emile


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


Re: list 2 dict?

2011-01-02 Thread Stefan Sonnenberg-Carstens

Am 02.01.2011 19:19, schrieb Emile van Sebille:

On 1/2/2011 8:31 AM Stefan Sonnenberg-Carstens said...


A last one:

l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
dict((x[1],x[0]) for x in ((l.pop(),l.pop()) for x in xrange(len(l)/2)))


This also works:


l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

pop=l.pop

dict([(pop(),pop()) for i in l])


No, it does not:

>>> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>>>
>>> pop=l.pop
>>>
>>> dict([(pop(),pop()) for i in l])
{'a': 7, 'b': 8, 4: 3, 6: 5}
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Where is win32service

2011-01-02 Thread catalinf...@gmail.com
I install Python 2.7 on Windows XP.
I try use :

import win32service
import win32serviceutil

But I got that error :

ImportError: No module named win32service
Where is this module ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where is win32service

2011-01-02 Thread Alex Willmer
On Sunday, January 2, 2011 6:40:45 PM UTC, catalinf...@gmail.com wrote:
> I install Python 2.7 on Windows XP.
> I try use :
> 
> import win32service
> import win32serviceutil
> 
> But I got that error :
> 
> ImportError: No module named win32service
> Where is this module ?

It's part of the pywin32 (aka win32all) package

http://sourceforge.net/projects/pywin32/

The latest download for your Python version is

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.7.exe/download

Regards, Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-02 Thread azakai
On Jan 2, 5:42 am, pyt...@bdurham.com wrote:
>
> 1. Are there plans to support IE 7 or 8?

I think it might run slowly there, but otherwise sure, it should run -
the code is intended to be valid JavaScript (if it isn't, that's a
bug). Currently though a minor issue prevents it from running on IE, I
have been told (I don't have a Windows machine to test on myself),
http://code.google.com/p/emscripten/issues/detail?id=22

>
> 2. I'm not sure what you mean by non-static modules? Can we use modules
> such as json, pickle/cPickle, StringIO/cStringIO?
>

Sorry, I should have been more clear. There isn't support for
dlopen(), which opens dynamically linked libraries. That means that
you can import libraries like sys, which are already linked into
python. But loading a module that exists as a separate file won't work
yet (but hopefully soon).

> 3. Is there a virtual file system we can take advantage of so calls to
> open() would work?
>

No, not yet, the libc implementation used just has stubs for input/
output stuff so far. Work in progress ;)

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


Re: CPython on the Web

2011-01-02 Thread azakai
On Jan 2, 5:52 am, "Octavian Rasnita"  wrote:
>
> Then, how can the Python programs run on the "desktop"?
> I suspect that the Python code is somehow translated to Javascript in order 
> to run on the browser. Am I right?

To clarify, in this demo, CPython itself - the C implementation of
Python - was translated from C to JavaScript (or more specifically, C
to LLVM, and LLVM to JavaScript). So your web browser is running the
same CPython that you would run on your computer normally.

That CPython executes Python by compiling it into bytecode, etc., and
that is exactly the same with CPython normally and CPython on the web
in this demo. So actual Python code is not translated into JavaScript
(which is the approach pyjamas takes), instead the entire interpreter
is.

>
> If yes, then how can run a Python code that access a database or one that 
> create a web server, or a WxPython GUI run?

By implementing whatever library functions and system calls CPython
needs, in the browser. For example, if the CPython code calls printf()
to print stuff, then we need to implement printf() in JavaScript, and
so forth.

Obviously there are limitations of the JS environment, so not
everything can be done.

>
> BTW. I have tried that page, and it appeared a JS error window telling that 
> the JS scripts run too slow and it asked me if I want to continue.
> I have executed the default Python script, but nothing happend. Nothing was 
> printed. I use Internet Explorer.
>

I've been told it doesn't run properly on IE, we have a bug open on
that, sorry. It will work on Firefox, Chrome and Safari right now.

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


Re: Tkinter: The good, the bad, and the ugly!

2011-01-02 Thread CM
On Jan 1, 7:39 pm, rantingrick  wrote:
> On Jan 1, 5:39 pm, CM  wrote:
>
> > And I don't see this as a problem anyway.  I wanted to do GUI
> > programming in Python, so I read a bit, chose wxPython, downloaded it,
> > and started learning it.  Done.
>
> I, I, I...Me,Me,Me.
>
> Seems you are only concerned about yourself CM. However this a
> community discussion. You must put your wants and needs in the
> backseat before you can see what is best for the Python community as a
> whole.

Must have been too many holiday baked goods that made me even try...





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


Re: list 2 dict?

2011-01-02 Thread Octavian Rasnita

Octavian

- Original Message - 
From: "Alex Willmer" 
Newsgroups: comp.lang.python
To: 
Cc: 
Sent: Sunday, January 02, 2011 8:07 PM
Subject: Re: list 2 dict?


> On Sunday, January 2, 2011 3:36:35 PM UTC, T wrote:
>> The grouper-way looks nice, but I tried it and it didn't work:
>> 
>> from itertools import *
>> ...
>> d = dict(grouper(2, l))
>> 
>> NameError: name 'grouper' is not defined
>> 
>> I use Python 2.7. Should it work with this version?
> 
> No. As Ian said grouper() is a receipe in the itertools documentation. 
> 
> http://docs.python.org/library/itertools.html#recipes

I know that, that is why I used:

from itertools import *


Isn't enough?

Octavian

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


Re: list 2 dict?

2011-01-02 Thread Simon Brunning
On 2 January 2011 21:04, Octavian Rasnita  wrote:
>> No. As Ian said grouper() is a receipe in the itertools documentation.
>>
>> http://docs.python.org/library/itertools.html#recipes
>
> I know that, that is why I used:
>
> from itertools import *
>
> Isn't enough?

Did you follow the link? grouper() is a recipe, not part of the
itertools module.

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 19:14, Emile van Sebille  wrote:
> On 1/2/2011 9:43 AM gervaz said...
>
>
>
>
>
> > On 31 Dic 2010, 16:43, Emile van Sebille  wrote:
> >> On 12/31/2010 7:22 AM gervaz said...
>
> >>> Hi all, I would like to ask you how I can use the more efficient join
> >>> operation in a code like this:
>
> >> class Test:
> >>> ...     def __init__(self, v1, v2):
> >>> ...         self.v1 = v1
> >>> ...         self.v2 = v2
> >>> ...
> >> def prg(l):
> >>> ...     txt = ""
> >>> ...     for x in l:
> >>> ...         if x.v1 is not None:
> >>> ...             txt += x.v1 + "\n"
> >>> ...         if x.v2 is not None:
> >>> ...             txt += x.v2 + "\n"
> >>> ...     return txt
> >>> ...
> >> t1 = Test("hello", None)
> >> t2 = Test(None, "ciao")
> >> t3 = Test("salut", "hallo")
> >> t = [t1, t2, t3]
>
> >> prg(t)
> >>> 'hello\nciao\nsalut\nhallo\n'
>
> >>> The idea would be create a new list with the values not None and then
> >>> use the join function... but I don't know if it is really worth it.
> >>> Any hint?
>
> >> def prg2(l):
>
> >>               return "\n".join([x for x in l if x])
>
> >> Emile
>
> >>> ...     e = []
> >>> ...     for x in l:
> >>> ...         if x.v1 is not None:
> >>> ...             e.append(x.v1)
> >>> ...         if x.v2 is not None:
> >>> ...             e.append(x.v2)
> >>> ...     return "\n".join(e)
> >>> ...
> >> prg2(t)
> >>> 'hello\nciao\nsalut\nhallo'
>
> >>> Thanks, Mattia- Nascondi testo citato
>
> >> - Mostra testo citato -- Nascondi testo citato
>
> >> - Mostra testo citato -
>
> > Sorry, but it does not work
>
> Oh -- you want a working solution, not a hint?  OK.
>
> class Test:
>       def __init__(self, v1, v2):
>           self.v1 = v1
>           self.v2 = v2
>
> t1 = Test("hello", None)
> t2 = Test(None, "ciao")
> t3 = Test("salut", "hallo")
> t = [t1, t2, t3]
>
> "\n".join([y for x in t for y in [x.v1,x.v2] if y])
>
> Emile
>
>
>
>
>
>  def prg3(l):
> > ...     return "\n".join([x for x in l if x])
> > ...
>  prg3(t)
> > Traceback (most recent call last):
> >    File "", line 1, in
> >    File "", line 2, in prg3
> > TypeError: sequence item 0: expected str instance, Test found- Nascondi 
> > testo citato
>
> - Mostra testo citato -- Nascondi testo citato
>
> - Mostra testo citato -

Thanks Emile, despite that now the solution runs in quadratic time I
guess. I could also provide a __str__(self) representation, but in my
real code I don't have access to the class. Also using str() on an
empty object (i.e. None), the representation is 'None'.

Ciao,

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


Re: Multiple instances and wrong parental links

2011-01-02 Thread Josh English
Chas,

Thanks. The "self" in the setattr statement works sometimes, but what I'm 
adding most of the time is a property, and if I don't use the class when 
setting a property, nothing works. The property is returned instead of the 
value of the function the property returns. (yeah, it's complicated).

This is the same project I asked about at 
https://groups.google.com/d/topic/comp.lang.python/K9PinAbuCJk/discussion.

That's why this simple sample looks so incredibly complicated. I'm coding on 
the far edge of my learning curve.

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


Re: Multiple instances and wrong parental links

2011-01-02 Thread Josh English
Steven, 

This was simplified. The complete story is, well, tedious:

I have created a set of XML Validation and Normalization classes. With them I 
can define my data structures and make sure my data is good. These 
complications have come in wanting to take this tool and create a GUI (in 
wxPython) around these objects. Okay, really these complication come from me 
generalizing the problem, probably one step too far. I want a tool to take my 
structural definition and create the GUI. To use some of the "easy" tools like 
Validators that transfer data to the GUI and back, I need an interface.

I tried creating validators that went straight to the element, but that got 
complicated. 

Then I created a map from a dictionary to an element (as defined by the XML 
validation tool) and back again. This also bogged down and fixing one problem 
undid all the other progress I had made.

So this is my third attempt: create a Python object around the XML definition.

I've looked at pyxb. It doesn't make any sense to me. I looked at pysxer, that 
made even less sense. Hence, I try it on my own.

The Element List isn't a list, it has the same interface as a list, but always 
goes back to the original XML element (an elementree.Element object in this 
case.) 

Insanely complicated and just beyond my comprehension, I fear. I haven't found 
an easier way to wrap an object around these XML validators of mine.

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


Re: list 2 dict?

2011-01-02 Thread Benjamin Kaplan
On Jan 2, 2011 4:15 PM, "Octavian Rasnita"  wrote:
>
>
> Octavian
>
> - Original Message -
> From: "Alex Willmer" 
> Newsgroups: comp.lang.python
> To: 
> Cc: 
> Sent: Sunday, January 02, 2011 8:07 PM
> Subject: Re: list 2 dict?
>
>
> > On Sunday, January 2, 2011 3:36:35 PM UTC, T wrote:
> >> The grouper-way looks nice, but I tried it and it didn't work:
> >>
> >> from itertools import *
> >> ...
> >> d = dict(grouper(2, l))
> >>
> >> NameError: name 'grouper' is not defined
> >>
> >> I use Python 2.7. Should it work with this version?
> >
> > No. As Ian said grouper() is a receipe in the itertools documentation.
> >
> > http://docs.python.org/library/itertools.html#recipes
>
> I know that, that is why I used:
>
> from itertools import *
>
>
> Isn't enough?
>
> Octavian
>

It would be, if, the function was actually a part of the itertools module.
It isn't. It's just a code example used in the documentation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-02 Thread Gerry Reno
On 01/02/2011 02:26 AM, azakai wrote:
> Hello, I hope this will be interesting to people here: CPython running
> on the web,
>
> http://syntensity.com/static/python.html
>
> That isn't a new implementation of Python, but rather CPython 2.7.1,
> compiled from C to JavaScript using Emscripten and LLVM. For more
> details on the conversion process, see http://emscripten.org
>
> This is a work in progress, main issues right now are that the code
> isn't optimized (so don't expect good performance), and importing non-
> static modules doesn't work. Otherwise, though, it seems to run
> properly, in particular it runs all the examples in
> http://wiki.python.org/moin/SimplePrograms that don't rely on
> importing modules or receiving input from the user (with perhaps some
> minor formatting errors). The demo runs fine on recent versions of
> Firefox, Chrome and Safari, but has problems on IE9 and Opera
> (hopefully those will be resolved soon).
>
> The idea is that by compiling CPython itself, all the features of the
> language are immediately present, and at the latest version, unlike
> writing a new implementation which takes time and tends to lag behind.
> As to why run it on the web, there could be various uses, for example
> it could allow a simple learning environment for Python, which since
> it's on the web can be entered immediately without any download (and
> would run even in places where Python normally can't, like say an
> iPad).
>
> Feedback would be very welcome!
>
> - azakai
>   

Ok, visiting this page:

http://syntensity.com/static/python.html

I do not see anything happen when I click 'execute' button.  I'm running
Firefox 3.6.3.

Here is what I see both before and after clicking 'execute':
=

This is CPython, the standard Python 
implementation, compiled from C to JavaScript using Emscripten
, running in your browser (without any plugins).

* Most core language stuff should work, except for importing
  non-static modules (in other words, |import sys| will work, but
  other modules won't).
* Please report bugs if you find them!
* Tested on Firefox 4 and Chrome 10.
* The editor is Skywriter .


*Enter some Python*:
import sys print 'Hello world! This is Python {} on
{}'.format(sys.version, sys.platform) print 'Here are some numbers:',
[2*x for x in range(5)][:4]

=


So what is happening is that the whole Python interpreter has been
converted to Javascript and is running the browser, is that correct?

Ok, but the usual browser 'sandbox' constraints would still apply would
they not?

And what is the build toolchain that you need if you want to convert
your modules to be importable with this "CPython on the Web"?


Regards,
Gerry



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


Re: Tkinter: The good, the bad, and the ugly!

2011-01-02 Thread Tim Chase

On 01/01/2011 06:39 PM, rantingrick wrote:

On Jan 1, 5:39 pm, CM  wrote:


And I don't see this as a problem anyway.  I wanted to do GUI
programming in Python, so I read a bit, chose wxPython, downloaded it,
and started learning it.  Done.


I, I, I...Me,Me,Me.

Seems you are only concerned about yourself CM. However this a
community discussion. You must put your wants and needs in the
backseat before you can see what is best for the Python community as a
whole.


Pot? Meet Kettle...

Given that the community response has largely been an 
overwhelming "meh, show me some code" rather than an "I 
whole-heartedly agree with rantingrick", your use of "we" in your 
emails sounds more like a "royal we"[1] than a community-based 
concern.


"best for the Python community" seems to be something that 
doesn't break backwards compat. with existing code-bases, works 
across a multitude of platforms, has a minimal install footprint, 
and a proven track-record of meeting those needs.  Tkinter and wx 
both seem to satisfy most of those requirements, except that wx 
seems to have a larger footprint and not have been 
production-ready at the time a decision needed to be made for 
inclusion of a gui-library in Python.  (I also don't know if 
there are licensing concerns with wx vs. tk and their interplay 
with the Python license).


-tkc


[1]
http://en.wikipedia.org/wiki/Royal_we



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


Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 22:37, gervaz  wrote:
> On 2 Gen, 19:14, Emile van Sebille  wrote:
>
>
>
>
>
> > On 1/2/2011 9:43 AM gervaz said...
>
> > > On 31 Dic 2010, 16:43, Emile van Sebille  wrote:
> > >> On 12/31/2010 7:22 AM gervaz said...
>
> > >>> Hi all, I would like to ask you how I can use the more efficient join
> > >>> operation in a code like this:
>
> > >> class Test:
> > >>> ...     def __init__(self, v1, v2):
> > >>> ...         self.v1 = v1
> > >>> ...         self.v2 = v2
> > >>> ...
> > >> def prg(l):
> > >>> ...     txt = ""
> > >>> ...     for x in l:
> > >>> ...         if x.v1 is not None:
> > >>> ...             txt += x.v1 + "\n"
> > >>> ...         if x.v2 is not None:
> > >>> ...             txt += x.v2 + "\n"
> > >>> ...     return txt
> > >>> ...
> > >> t1 = Test("hello", None)
> > >> t2 = Test(None, "ciao")
> > >> t3 = Test("salut", "hallo")
> > >> t = [t1, t2, t3]
>
> > >> prg(t)
> > >>> 'hello\nciao\nsalut\nhallo\n'
>
> > >>> The idea would be create a new list with the values not None and then
> > >>> use the join function... but I don't know if it is really worth it.
> > >>> Any hint?
>
> > >> def prg2(l):
>
> > >>               return "\n".join([x for x in l if x])
>
> > >> Emile
>
> > >>> ...     e = []
> > >>> ...     for x in l:
> > >>> ...         if x.v1 is not None:
> > >>> ...             e.append(x.v1)
> > >>> ...         if x.v2 is not None:
> > >>> ...             e.append(x.v2)
> > >>> ...     return "\n".join(e)
> > >>> ...
> > >> prg2(t)
> > >>> 'hello\nciao\nsalut\nhallo'
>
> > >>> Thanks, Mattia- Nascondi testo citato
>
> > >> - Mostra testo citato -- Nascondi testo citato
>
> > >> - Mostra testo citato -
>
> > > Sorry, but it does not work
>
> > Oh -- you want a working solution, not a hint?  OK.
>
> > class Test:
> >       def __init__(self, v1, v2):
> >           self.v1 = v1
> >           self.v2 = v2
>
> > t1 = Test("hello", None)
> > t2 = Test(None, "ciao")
> > t3 = Test("salut", "hallo")
> > t = [t1, t2, t3]
>
> > "\n".join([y for x in t for y in [x.v1,x.v2] if y])
>
> > Emile
>
> >  def prg3(l):
> > > ...     return "\n".join([x for x in l if x])
> > > ...
> >  prg3(t)
> > > Traceback (most recent call last):
> > >    File "", line 1, in
> > >    File "", line 2, in prg3
> > > TypeError: sequence item 0: expected str instance, Test found- Nascondi 
> > > testo citato
>
> > - Mostra testo citato -- Nascondi testo citato
>
> > - Mostra testo citato -
>
> Thanks Emile, despite that now the solution runs in quadratic time I
> guess. I could also provide a __str__(self) representation, but in my
> real code I don't have access to the class. Also using str() on an
> empty object (i.e. None), the representation is 'None'.
>
> Ciao,
>
> Mattia- Nascondi testo citato
>
> - Mostra testo citato -

And this one is another working solution...

>>> def prg4(l):
... s = []
... for x in l:
... s.extend(set([x.v1, x.v2]) - set([None]))
... return "\n".join(s)
...
>>> prg4(t)
'hello\nciao\nhallo\nsalut'

My original question was just related to the fact that I read that the
string concatenation in expensive and it sould be used the join()
function but now probably it is better to stick with the first
implementation, the simplest one.

Ciao,

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


Re: CPython on the Web

2011-01-02 Thread azakai
On Jan 2, 1:01 pm, Gerry Reno  wrote:
>
> Ok, visiting this page:
>
> http://syntensity.com/static/python.html
>
> I do not see anything happen when I click 'execute' button.  I'm running
> Firefox 3.6.3.
>

I've only tested with Firefox 4. I'm surprised though that it wouldn't
work on 3.6.3. Can you see what errors appear in the error console
(control-shift-J)?

If no errors appear, it might be a failure due to limited script stack
space (which is fixed in FF4, and I guess is a problem in earlier
versions).

>
> So what is happening is that the whole Python interpreter has been
> converted to Javascript and is running the browser, is that correct?

Yes.

>
> Ok, but the usual browser 'sandbox' constraints would still apply would
> they not?

Yes, the JavaScript is limited in the usual ways. So Python is running
in a sandboxed manner.

>
> And what is the build toolchain that you need if you want to convert
> your modules to be importable with this "CPython on the Web"?
>

Note that loading modules isn't implemented yet, but I'll work on it
soon.

The toolchain will be to use your normal makefiles and such, but
replacing gcc with llvm-gcc or clang, so it generates LLVM bytecode
instead of a normal binary. Then one would run the generated LLVM
bytecode through Emscripten, which compiles it to JavaScript. So, the
process should be fairly simple.

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


Tiny4py [important update] a little python wrapper to make shorten urls and QRCodes

2011-01-02 Thread Andrea Stagi
Hi, I would announce you my new version of this python wrapper to make
shorten urls and QRCodes, using main used services: goo.gl, bit.ly and
tinyurl.
Please, visit http://code.google.com/p/tiny4py/
Bests
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-02 Thread Gerry Reno
On 01/02/2011 05:53 PM, azakai wrote:
> On Jan 2, 1:01 pm, Gerry Reno  wrote:
>   
>> Ok, visiting this page:
>>
>> http://syntensity.com/static/python.html
>>
>> I do not see anything happen when I click 'execute' button.  I'm running
>> Firefox 3.6.3.
>>
>> 
> I've only tested with Firefox 4. I'm surprised though that it wouldn't
> work on 3.6.3. Can you see what errors appear in the error console
> (control-shift-J)?
>
>   

Errors when using Firefox 3.6.3:

script stack space quota is exhausted
Module is not defined  ...  line 56


Regards,
Gerry



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


Re: Interrput a thread

2011-01-02 Thread Tim Roberts
gervaz  wrote:
>
>Ok, but then suppose I have multiple long running threads that I want
>to delete/suspend because they are tooking too much time, which
>solution do you propose?

The right solution is to write your threads so they have an escape hatch --
to periodically check a "should I die?" flag, and then commit suicide. That
is the ONLY clean way to handle this problem.  There is simply no clean way
to force another thread to die without its permission.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-02 Thread python
Azakai/Gerry,

> Errors when using Firefox 3.6.3:

I'm running Firefox 3.6.1.3 and the interpreter is running fine.

I'm on Windows 7 Pro 64-bit.

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


Re: CPython on the Web

2011-01-02 Thread azakai
On Jan 2, 3:14 pm, Gerry Reno  wrote:
> On 01/02/2011 05:53 PM, azakai wrote:
>
> > On Jan 2, 1:01 pm, Gerry Reno  wrote:
>
> >> Ok, visiting this page:
>
> >>http://syntensity.com/static/python.html
>
> >> I do not see anything happen when I click 'execute' button.  I'm running
> >> Firefox 3.6.3.
>
> > I've only tested with Firefox 4. I'm surprised though that it wouldn't
> > work on 3.6.3. Can you see what errors appear in the error console
> > (control-shift-J)?
>
> Errors when using Firefox 3.6.3:
>
> script stack space quota is exhausted

Ah, then yeah, it's the script stack issue I was afraid of. Then
there's not really a way to run the demo on Firefox 3.6.x. It will
work on Firefox 4 though, or other recent browsers.

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


Re: CPython on the Web

2011-01-02 Thread azakai
On Jan 2, 4:58 pm, pyt...@bdurham.com wrote:
> Azakai/Gerry,
>
> > Errors when using Firefox 3.6.3:
>
> I'm running Firefox 3.6.1.3 and the interpreter is running fine.
>
> I'm on Windows 7 Pro 64-bit.
>
> Malcolm

Thanks for the info. To be honest I'm surprised it works there. I
guess the error Gerry ran into depends on additional factors.

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


Re: CPython on the Web

2011-01-02 Thread Gerry Reno
I tried printing sys.path and here is the output:

['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/lib-dynload']

Now, those paths must be on your machine because they are not on my
client machine.  But the interpreter is now running on MY machine.  Well
in a sandbox really.  So how is that going to work?


Regards,
Gerry

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


Re: CPython on the Web

2011-01-02 Thread Wolfgang Strobl
azakai :

>On Jan 2, 4:58 pm, pyt...@bdurham.com wrote:
>> Azakai/Gerry,
>>
>> > Errors when using Firefox 3.6.3:
>>
>> I'm running Firefox 3.6.1.3 and the interpreter is running fine.

I guess that meant FIrefox 3.6.13 (without the last dot), the current
stable version.

I'm using Firefox 3.6.13 (german) on Windowx XP (32bit, german) here,
and the interpreter is running fine, too.  Same for Chrome 8.0.552.224.


-- 
Wir danken für die Beachtung aller Sicherheitsbestimmungen
-- 
http://mail.python.org/mailman/listinfo/python-list