question about python

2008-09-13 Thread fishfin
I was working through a tutorial about how to write a server using
python (the url is bellow). I am sure that the server is working to
some degree because when the server is running localhost:8080 just
keeps trying to load until it times out. I would like to know how to
send information through the server to my browser?

I was working through this tutorial:
http://python.about.com/od/networkingwithpython/ss/PythonWebServer.htm


and my final code is like this:

import socket

host = ''
port = 8080

c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

c.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

c.bind((host, port))

c.listen(1)

while 1:
csock, caddr = c.accept()
cfile = csock.makefile('rw', 0)

line = cfile.readline().strip()

cfile.write('HTTP/1.0 200 OK\n\n')
cfile.write('Welcome %s!' %
(str(caddr)))
cfile.write('Follow the link...')
cfile.write('All the server needs to do is ')
cfile.write('to deliver the text to the socket. ')
cfile.write('It delivers the HTML code for a link, ')
cfile.write('and the web browser converts it. ')
cfile.write(' http://python.about.com/
index.html">Click me! ')
cfile.write('The wording of your request was: "%s"' %(line))
cfile.write('')

cfile.close()
csock.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: question about python

2008-09-13 Thread Diez B. Roggisch

fishfin schrieb:

I was working through a tutorial about how to write a server using
python (the url is bellow). I am sure that the server is working to
some degree because when the server is running localhost:8080 just
keeps trying to load until it times out. I would like to know how to
send information through the server to my browser?

I was working through this tutorial:
http://python.about.com/od/networkingwithpython/ss/PythonWebServer.htm


and my final code is like this:

import socket

host = ''
port = 8080

c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

c.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

c.bind((host, port))

c.listen(1)

while 1:
csock, caddr = c.accept()
cfile = csock.makefile('rw', 0)

line = cfile.readline().strip()

cfile.write('HTTP/1.0 200 OK\n\n')
cfile.write('Welcome %s!' %
(str(caddr)))
cfile.write('Follow the link...')
cfile.write('All the server needs to do is ')
cfile.write('to deliver the text to the socket. ')
cfile.write('It delivers the HTML code for a link, ')
cfile.write('and the web browser converts it. ')
cfile.write(' http://python.about.com/
index.html">Click me! ')
cfile.write('The wording of your request was: "%s"' %(line))
cfile.write('')

cfile.close()
csock.close()


Do yourself a favor and look into the various python webframeworks such 
as TurboGears, Django and what not.


Or at least into the module SimpleHTTPServer.

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


Re: XML RPC Problem....

2008-09-13 Thread Usman Ajmal
Please explain the arguments of send_request. What exactly are the
connection, handler and request_body? It will be really helpful if you give
an example of how do i call send_request

On Thu, Sep 11, 2008 at 7:18 AM, Fredrik Lundh <[EMAIL PROTECTED]>wrote:

> Usman Ajmal wrote:
>
>  And i also fount that a typical system.auth call will look like:
>>
>> POST /xmlrpc/clarens_server.py HTTP/1.0
>> Host: localhost
>> User-Agent: xmlrpclib.py/0.9.9 (by www.pythonware.com <
>> http://www.pythonware.com>)
>>
>> Content-Type: text/xml
>> Content-Length: 105
>> AUTHORIZATION: Basic MkhVTm9VazYxbXArVEZLS0dCY2tIRlA3bjVzPQo6RnJvbSBi
>> 
>> 
>>  system.auth
>>
>>  
>>  
>> 
>>
>>
>> Problem is that i don't know how do i generate above xml system.auth call.
>> Can anyone please tell me how do call a function, setting the header of the
>> call too?
>>
>
> you need to plugin a custom transport.  see this page for an example:
>
>http://www.python.org/doc/lib/xmlrpc-client-example.html
>
> in your case, it should be sufficient to override send_request, e.g.
> (untested):
>
>class SecureTransport(xmlrpclib.Transport):
>
>def set_authorization(self, ustring, text_ucert):
>self.authoriation = encodestring(
>"%s:%s" % (ustring,text_ucert)
>)
>
>def send_request(self, connection, handler, request_body):
>connection.putrequest("POST", handler)
>connection.putheader("Authorization",
>"Basic %s" % self.authorization
>)
>
> and instantiate the transport by doing
>
>t = SecureTransport()
>t.set_authorization(ustring, text_ucert)
>
> before passing to the server proxy.
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: question about python

2008-09-13 Thread Carl Banks
On Sep 13, 12:15 am, fishfin <[EMAIL PROTECTED]> wrote:
> I was working through a tutorial about how to write a server using
> python (the url is bellow). I am sure that the server is working to
> some degree because when the server is running localhost:8080 just
> keeps trying to load until it times out. I would like to know how to
> send information through the server to my browser?
>
> I was working through this 
> tutorial:http://python.about.com/od/networkingwithpython/ss/PythonWebServer.htm
>
> and my final code is like this:
>
> import socket
>
> host = ''
> port = 8080
>
> c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> c.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>
> c.bind((host, port))
>
> c.listen(1)
>
> while 1:
> csock, caddr = c.accept()
> cfile = csock.makefile('rw', 0)

It looks like everything after this line needs to be indented.
Besides that, nothing jumps out at me, though I don't do direct socket
programming a lot.

> line = cfile.readline().strip()
>
> cfile.write('HTTP/1.0 200 OK\n\n')
> cfile.write('Welcome %s!' %
> (str(caddr)))
> cfile.write('Follow the link...')
> cfile.write('All the server needs to do is ')
> cfile.write('to deliver the text to the socket. ')
> cfile.write('It delivers the HTML code for a link, ')
> cfile.write('and the web browser converts it. ')
> cfile.write(' http://python.about.com/
> index.html">Click me! ')
> cfile.write('The wording of your request was: "%s"' %(line))
> cfile.write('')
>
> cfile.close()
> csock.close()


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


Re: Checking the boolean value of a collection

2008-09-13 Thread Marco Bizzarri
On Fri, Sep 12, 2008 at 6:07 PM, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Marco Bizzarri a écrit :
> (snip)
>>
>> I'm afraid this have another problem for me...
>>
>>
>> [EMAIL PROTECTED]:/var/local/zope28/porting/Products/PAFlow$ python2.3
>> Python 2.3.5 (#2, Oct 18 2006, 23:04:45)
>> [GCC 4.1.2 20061015 (prerelease) (Debian 4.1.1-16.1)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>
> def any(iterable): pass
>>
>> ...
>
> any(x for x in [1, 2, 3])
>>
>>  File "", line 1
>>any(x for x in [1, 2, 3])
>>^
>> SyntaxError: invalid syntax
>>
> any([x for x in [1, 2, 3]])
>
>>
>> I mean, I'm afraid I can't use an expression like that without
>> building a list... not at least in python2.3
>
> Err... a list being an iterable, you just need any([1, 2, 3]).

Ehm, yes, of course... I was trying just to show from a command line
what were my results.

>
> But this wont be enough to solve your real use case, indeed.


Yes, that's the point.



-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: question about python

2008-09-13 Thread fishfin
@ Carl: Yes, I think your right now that I look at it (or at least all
except for the last two lines need to be indented). I'm still not sure
how to send the stuff to the web browser though. Thanks for pointing
it out!

@ Diez: I'll start googling those right away.

Carl Banks wrote:
> On Sep 13, 12:15 am, fishfin <[EMAIL PROTECTED]> wrote:
> > I was working through a tutorial about how to write a server using
> > python (the url is bellow). I am sure that the server is working to
> > some degree because when the server is running localhost:8080 just
> > keeps trying to load until it times out. I would like to know how to
> > send information through the server to my browser?
> >
> > I was working through this 
> > tutorial:http://python.about.com/od/networkingwithpython/ss/PythonWebServer.htm
> >
> > and my final code is like this:
> >
> > import socket
> >
> > host = ''
> > port = 8080
> >
> > c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >
> > c.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> >
> > c.bind((host, port))
> >
> > c.listen(1)
> >
> > while 1:
> > csock, caddr = c.accept()
> > cfile = csock.makefile('rw', 0)
>
> It looks like everything after this line needs to be indented.
> Besides that, nothing jumps out at me, though I don't do direct socket
> programming a lot.
>
> > line = cfile.readline().strip()
> >
> > cfile.write('HTTP/1.0 200 OK\n\n')
> > cfile.write('Welcome %s!' %
> > (str(caddr)))
> > cfile.write('Follow the link...')
> > cfile.write('All the server needs to do is ')
> > cfile.write('to deliver the text to the socket. ')
> > cfile.write('It delivers the HTML code for a link, ')
> > cfile.write('and the web browser converts it. ')
> > cfile.write(' http://python.about.com/
> > index.html">Click me! ')
> > cfile.write('The wording of your request was: "%s"' %(line))
> > cfile.write('')
> >
> > cfile.close()
> > csock.close()
>
>
> Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list


Profiling, sum-comprehension vs reduce

2008-09-13 Thread cnb
This must be because of implementation right? Shouldn't reduce be
faster since it iterates once over the list?
doesnt sum first construct the list then sum it?

---

>>>  RESTART 
>>>
reduce with named function:  37.9864357062
reduce with nested, named function:  39.4710288598
reduce with lambda:  39.2463927678
sum comprehension:  25.9530121845
>>>  RESTART 
>>>
reduce with named function:  36.4529584067
reduce with nested, named function:  37.6278529813
reduce with lambda:  38.2629448715
sum comprehension:  26.0197561422
>>>



from timeit import Timer

def add(x,y):
return x+y

def rednamed(lst):
return reduce(add, lst)

def rednn(lst):
def add2(x,y):
return x+y
return reduce(add2, lst)

def redlambda(lst):
return reduce(lambda x,y:x+y, lst)

def com(lst):
return sum(x for x in lst)

s = xrange(101)

t1 = Timer('rednamed(s)', 'from __main__ import rednamed, s')
t2 = Timer('rednn(s)', 'from __main__ import rednn, s')
t3 = Timer('redlambda(s)', 'from __main__ import redlambda, s')
t4 = Timer('com(s)', 'from __main__ import com, s')

print "reduce with named function: ", t1.timeit()
print "reduce with nested, named function: ", t2.timeit()
print "reduce with lambda: ", t3.timeit()
print "sum comprehension: ", t4.timeit()


---
also, using range instead of xrange doesnt seem to generate a
performance-penalty:

>>>
reduce with named function:  36.7560729087
reduce with nested, named function:  38.5393266463
reduce with lambda:  38.3852953378
sum comprehension:  27.9001007111
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: n00b question: Better Syntax for Coroutines?

2008-09-13 Thread Arnaud Delobelle
On Sep 13, 2:08 am, [EMAIL PROTECTED] wrote:
> First off, I'm a python n00b, so feel free to comment on anything if
> I'm doing it "the wrong way." I'm building a discrete event simulation
> tool. I wanted to use coroutines. However, I want to know if there's
> any way to hide a yield statement.
>
> I have a class that I'd like to look like this:
>
> class Pinger(Actor):
>     def go(self):
>         success = True
>         while success:
>             result = self.ping("128.111.41.38")
>             if result != "success":
>                 success = False
>         print "Pinger done"
>
> But because I can't hide yield inside ping, and because I can't find a
> convenient way to get a self reference to the coroutine (which is used
> by the event queue to pass back results), my code looks like this:
>
> class Pinger(Actor):
>     def go(self):
>         # I dislike this next line
>         self.this_pointer = (yield None)
>         success = True
>         while success:
>             # I want to get rid of the yield in the next line
>             result = (yield self.ping("128.111.41.38"))
>             if result != "success":
>                 success = False
>         print "Pinger done"
>
> I posted a more detailed version of this as a rant 
> here:http://illusorygoals.com/post/49926627/
>
> I'd like to know, is there a way to get the syntax I want? After
> staying up late last night to get a proof-of-concept working with
> coroutines, my boss expressed disappointment in the ugliness of the
> Pinger code (we agreed on the desired syntax above). I spent almost 2
> hours today to migrate the system over to threads. That made my boss
> happy, but I'm still curious if I can do something to salvage the
> coroutine version.
>
> Regards,
> IG

You can't avoid the yield, and generators are not coroutines.  A
little while ago when thinking about this kind of problem I defined
"cogenerators", which roughly are to generators what coroutines are to
routines, i.e. they can pass "yielding control" on to another
cogenerator [1].

[1] http://www.marooned.org.uk/~arno/python/cogenerator.html

--
Arnaud

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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Marc 'BlackJack' Rintsch
On Sat, 13 Sep 2008 01:06:22 -0700, cnb wrote:

> This must be because of implementation right? Shouldn't reduce be faster
> since it iterates once over the list? doesnt sum first construct the
> list then sum it?

No it doesn't.  Why should it?

> also, using range instead of xrange doesnt seem to generate a
> performance-penalty:

(De)Allocating a list of length 100 isn't very slow.  Try some million 
elements.  And watch the memory consumption too.

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


Re: question about python

2008-09-13 Thread Carl Banks
On Sep 13, 1:00 am, fishfin <[EMAIL PROTECTED]> wrote:
> @ Carl: Yes, I think your right now that I look at it (or at least all
> except for the last two lines need to be indented). I'm still not sure
> how to send the stuff to the web browser though. Thanks for pointing
> it out!

Try reading in the whole HTTP request instead of just the first line.
Change

line = cfile.readline().strip()

to

line = cfile.read()

And see if that helps.  (Outputting the document so that it formats
the request well is left as an exercise.  Also, as a heads up: in real
programs you should never output anything you receive through the
network without checking it or escaping it to prevent malicious uses.)


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


Re: question about python

2008-09-13 Thread Tino Wildenhain

fishfin wrote:

@ Carl: Yes, I think your right now that I look at it (or at least all
except for the last two lines need to be indented). 


> I'm still not sure
how to send the stuff to the web browser though. 


what do you think is the cfile.write() doing?

As a hint, beside having a look at rfc2616 and friends,
get something like wiresharc to see how HTTP requests
work in real world.

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: XML RPC Problem....

2008-09-13 Thread Fredrik Lundh

Usman Ajmal wrote:

Please explain the arguments of send_request. What exactly are the 
connection, handler and request_body? It will be really helpful if you 
give an example of how do i call send_request


you don't call send_request.  you should pass the SecureTransport 
instance as an argument to the ServerProxy, which will then use it to 
talk to the server.  see the "custom transport" example in the library 
reference that I pointed you to.


  http://www.python.org/doc/lib/xmlrpc-client-example.html



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


Re: book example confusion

2008-09-13 Thread Fredrik Lundh

byron wrote:


Being that each function is an object, a name assignment to
(tmp1,tmp2) doesn't actually evaluate or run the function itself until
the name is called..


the above would be true if the code had been

   tmp1, tmp2 = f1, f2

but it isn't.  look again.



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


Re: SSH using PEXPECT

2008-09-13 Thread nntpman68

Hi,

[EMAIL PROTECTED] wrote:

On Sep 10, 7:01 pm, Sean DiZazzo <[EMAIL PROTECTED]> wrote:



I am using windows and for reason it wont let me use pexpect even tho
I have CYGWIN installed


I get the following error

Traceback (most recent call last):
  File "new.py", line 1, in 
import ssh_session
  File "C:\Python25\lib\ssh_session.py", line 7, in 
from pexpect import *
  File "C:\Python25\lib\site-packages\pexpect.py", line 85, in

support it. Pexpect is intended for UNIX-like operating
systems.""")
ImportError: No module named resource



You might have cygwin installed,
but the error mesage sems to indicatem that you don't use cygwin's 
pythonm but the normal windows python,


You see, that it complains about pexpcet in 
C:\Python25\lib\site-packages\pexpect.py




just open a cygwin window:

then cd to the directory containign your script and type
python new.py.

you should have at least another error message


bye

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


Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic

Tino Wildenhain wrote:

Hi,

Luis Zarrabeitia wrote:

Quoting Laszlo Nagy <[EMAIL PROTECTED]>:


...

Even better:

help(sum) shows

===
sum(...)
sum(sequence, start=0) -> value
Returns the sum of a sequence of numbers (NOT strings) plus 
the value

of parameter 'start'.  When the sequence is empty, returns start.
===

so the fact that sum([]) returns zero is just because the start value 
is zero...

sum([],object()) would return an object().

BTW, the original code:


sum(s for s in ["a", "b"] if len(s) > 2)


wouldn't work anyway... it seems that sum doesn't like to sum strings:


sum(['a','b'],'')


: sum() can't sum strings [use 
''.join(seq) instead]


Yes which is a bit bad anyway. I don't think hard wiring it is such a 
nice idea. You know, walks like a duck, smells like a duck...

If it makes sense to handle things differently for performance, then
please have it doing it silently, e.g. when it detects strings just
use join() internally.

Cheers
Tino


+1

''.join is horrible. And it adds insult to injury that S.join(S.split(T)) != T 
as a rule. The interpreter has no business to patronize us into this shamefully 
contorted neighborhood while it understands what we want.


Cheers, BB

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


Re: XML RPC Problem....

2008-09-13 Thread Usman Ajmal
Where exactly should i call ServerProxy? Following is the code from my
client.py

t = SecureTransport()

   t.set_authorization(ustring, text_ucert)
server = xmlrpclib.Server('http://localhost:8000/',transport=t)
print server.s()

Note: Full code for client is here at http://privatepaste.com/b56oS1Xa7P

and following is my server code

import SimpleXMLRPCServer
#server = ServerProxy("http://betty.userland.com";)
class AuthenticationFunctions:

def s(self):
print "something..."

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(AuthenticationFunctions())

server.serve_forever()


On Sat, Sep 13, 2008 at 8:44 AM, Fredrik Lundh <[EMAIL PROTECTED]>wrote:

> Usman Ajmal wrote:
>
>  Please explain the arguments of send_request. What exactly are the
>> connection, handler and request_body? It will be really helpful if you give
>> an example of how do i call send_request
>>
>
> you don't call send_request.  you should pass the SecureTransport instance
> as an argument to the ServerProxy, which will then use it to talk to the
> server.  see the "custom transport" example in the library reference that I
> pointed you to.
>
>  http://www.python.org/doc/lib/xmlrpc-client-example.html
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: question about python

2008-09-13 Thread fishfin
On Sep 13, 4:25 pm, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Sep 13, 1:00 am, fishfin <[EMAIL PROTECTED]> wrote:
>
> > @ Carl: Yes, I think your right now that I look at it (or at least all
> > except for the last two lines need to be indented). I'm still not sure
> > how to send the stuff to the web browser though. Thanks for pointing
> > it out!
>
> Try reading in the whole HTTP request instead of just the first line.
> Change
>
> line = cfile.readline().strip()
>
> to
>
> line = cfile.read()
>
> And see if that helps.  (Outputting the document so that it formats
> the request well is left as an exercise.  Also, as a heads up: in real
> programs you should never output anything you receive through the
> network without checking it or escaping it to prevent malicious uses.)
>
> Carl Banks

I figured out what the problem was. When you had suggested that I
indent the lines at first I did all of them, but when I did that there
must have been an nonindented line before the last two lines which I
had indented, so ending the 'while 1:'. Because of that, that code
just flat out didn't work so I assumed that they must be not be
indented which is why it hasn't been working all along. Thanks for
your help! I don't think I would have every figured it out if you last
post hadn't gotten me to thinking about little tweeks like that.
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML RPC Problem....

2008-09-13 Thread Fredrik Lundh

Usman Ajmal wrote:

Where exactly should i call ServerProxy? Following is the code from my 
client.py


ServerProxy is the preferred name.  Server is an old alias for the same 
class.



t = SecureTransport()
   
t.set_authorization(ustring, text_ucert)

server = xmlrpclib.Server('http://localhost:8000/',transport=t)
print server.s()


that code looks correct.  so what's the problem?



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


''.join woes - Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic

I wrote:

Tino Wildenhain wrote:

[...]

sum(['a','b'],'')


: sum() can't sum strings [use 
''.join(seq) instead]


Yes which is a bit bad anyway. I don't think hard wiring it is such a 
nice idea. You know, walks like a duck, smells like a duck...

If it makes sense to handle things differently for performance, then
please have it doing it silently, e.g. when it detects strings just
use join() internally.

Cheers
Tino


+1

''.join is horrible. And it adds insult to injury that 
S.join(S.split(T)) != T as a rule. The interpreter has no business to 
patronize us into this shamefully contorted neighborhood while it 
understands what we want.


What makes ''.join particularly horrible is that we find ourselves forced to use 
it not only for concatenating arbitrary-length strings in a list, but also to 
convert to a str what's already a sequence of single characters. IOW string 
types fail to satisfy a natural expectation for any S of sequence type :


S == type(S)(item for item in S) == type(S)(list(S))

And this, even though strings are sequence types deep-down-ly enough that they 
achieve to act as such in far-fetched corner cases like


(lambda *x : x)(*'abc')==('a','b','c')

...and even though strings offer not one but two distinct constructors that play 
nicely in back-and-forth conversions with types to which they are much less 
closely related, ie.


'1j' == repr(complex('1j') == str(complex('1j'))
1j == complex(repr(1j)) == complex(str(1j))

Not-so-cheerfully-yours, BB

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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Harold Fellermann
> doesnt sum first construct the list then sum it?

> def com(lst):
> return sum(x for x in lst)

You construct a generator over an existing list in your code.
Try sum([x for x in lst]) to see the effect of additional list
construction. And while you're at it, try the simple sum(lst).

Cheers,

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


Has any one worked with Rpyc

2008-09-13 Thread Blubaugh, David A.
To All,


Has anyone out there worked much with Rpyc?  


Thanks,


David




This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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


I cannot find where Numpy 1.2 is located

2008-09-13 Thread Blubaugh, David A.
To All,


I have been trying to locate as to where Numpy 1.2 can be downloaded.  I
will need this update.  The only version available at the Numpy website
for download is only 1.1.1 not the required 1.2 that I definitely need
at this time.

David Blubaugh


 

This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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


Has any one out there ever worked with the Rpyc, which is a remote process call for python

2008-09-13 Thread Blubaugh, David A.
To All,


Has any one out there ever worked with the Rpyc, which is a remote
process call for python?


David Blubaugh



This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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


Re: Injecting new names into the above frame

2008-09-13 Thread Peter Waller
On Sep 12, 2:30 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> The answer to why this doesn't work lies in the disassembly of that
> function:

This makes me want to ask: is it difficult to modify a function's
code? Even if it weren't possible whilst the function was executing
(because then I would be returning to a function I just created, I
guess?) Could I make another function which converted this LOAD_GLOBAL
to LOAD_FAST?

I agree that in general a function should have no side effects and I
would like to know exactly what it is going to do, and that what I'm
doing is unpythonic.

My curiosity extends because I would like to get to know a bit more
about python's internals. My gut tells me there has to be a way to
achieve what I'm after - even if it the result is extremely ugly.
Maybe it might involve applying a decorator to functions who use this
functionality, who change the code so that these calls work?

Cheers for your reply,

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


Re: Injecting new names into the above frame

2008-09-13 Thread Michele Simionato
On Sep 13, 1:35 pm, Peter Waller <[EMAIL PROTECTED]> wrote:
> This makes me want to ask: is it difficult to modify a function's
> code?

No, it is not difficult. Look at the byteplay module:
it makes possible all kinds of dirty hacks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML RPC Problem....

2008-09-13 Thread Usman Ajmal
Problem is that when i start client (while the server is already running), i
get an error i.e.
Error 500 Internal Server Error

On Sat, Sep 13, 2008 at 3:58 PM, Fredrik Lundh <[EMAIL PROTECTED]>wrote:

> Usman Ajmal wrote:
>
>  Where exactly should i call ServerProxy? Following is the code from my
>> client.py
>>
>
> ServerProxy is the preferred name.  Server is an old alias for the same
> class.
>
>  t = SecureTransport()
>>  t.set_authorization(ustring, text_ucert)
>>server = xmlrpclib.Server('http://localhost:8000/',transport=t)
>>print server.s()
>>
>
> that code looks correct.  so what's the problem?
>
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Has any one out there ever worked with the Rpyc, which is a remote process call for python

2008-09-13 Thread Stef Mientki

Blubaugh, David A. wrote:

To All,


Has any one out there ever worked with the Rpyc, which is a remote
process call for python?

  

Yes

David Blubaugh



This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.


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


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


Re: XML RPC Problem....

2008-09-13 Thread Fredrik Lundh

Usman Ajmal wrote:

Problem is that when i start client (while the server is already 
running), i get an error i.e.

Error 500 Internal Server Error


that's a server error, not a client error.  check the server logs (e.g. 
error.log or similar).




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


Re: XML RPC Problem....

2008-09-13 Thread Usman Ajmal
Yeah right but i don't see something wrong in my server's code. Following is
my server's simple code

import SimpleXMLRPCServer
#server = ServerProxy("http://betty.userland.com";)
class AuthenticationFunctions:

def s(self):
print "something..."

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(AuthenticationFunctions())

server.serve_forever()

and following is what i get when i run my client.

Traceback (most recent call last):
  File "ppkey.py", line 48, in 
caller()
  File "ppkey.py", line 45, in caller
print server.s()
  File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in __call__
return self.__send(self.__name, args)
  File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request
verbose=self.__verbose
  File "/usr/lib/python2.5/xmlrpclib.py", line 1191, in request
headers
xmlrpclib.ProtocolError: 


On Sat, Sep 13, 2008 at 12:37 PM, Fredrik Lundh <[EMAIL PROTECTED]>wrote:

> Usman Ajmal wrote:
>
>  Problem is that when i start client (while the server is already running),
>> i get an error i.e.
>> Error 500 Internal Server Error
>>
>
> that's a server error, not a client error.  check the server logs (e.g.
> error.log or similar).
>
>
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

A service for testing Python code on multiple platforms and versions

2008-09-13 Thread David Moss
Hopefully a service like this already exists and I just haven't found
it yet. If not it could be an idea for some kind soul(s) to pick up
and run with ;-)

As someone who writes and releases Python modules for the community, I
find it difficult to have a decent level of confidence in the efficacy
of my code on platforms and Python versions other than those that I
own or use regularly. My documentation states that I support Python
2.3 or higher. This ends up being more of a statement of good
intentions than a one of fact.

A case in point. A bug (in Python), that I believed to have been
killed off after Python 2.2, resurfaced in a 2.4.x release of Python
on PowerPC recently. As I don't own any PowerPC kit, it was very
difficult to a) investigate the bug and b) create an effective fix for
it in a timely fashion. Fortunately I'd come across it before so the
fix was easy but it might not have been.

While I realise one's code can never be perfect, you can cover for
these sorts of eventualities fairly easily by running your software
and unit tests under different environments. You'd also like to be
able to do this on a continual basis rather than just once or twice.
If this was done with some kind of automated testing and reporting so
much the better. Bigger projects that take code quality seriously
probably already have this sort of thing in place for their own
purposes, but for smaller ones it just isn't possible.

Wouldn't it be great to have a service/setup out there available for
Python developers to access that covered a fairly broad base of
possible Python installations for the purpose of improve overall code
quality? Am I the only one that would find something like this useful?

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


Re: Injecting new names into the above frame

2008-09-13 Thread Boris Borcic
Why don't you use import and __import__() ? - They seem designed for such an 
application.


I mean, I am not against vicious hacks for the fun of them, but not if they 
serve the illusion that what they do can't (easily) be achieved other ways.


Cheers, BB

Peter Waller wrote:

Dear Pythoners,

I know this will probably be perceived as 'evil voodoo', and fair
enough: it probably is. I guess it is unpythonic.

.. but I want to know how to do it anyway - mostly for my own
interest.

Consider the following snippet of code:

---
def Get( *names ):
if not names: return None

frame = sys._getframe(1)
prevFrameLocals = frame.f_locals

for name in names:
prevFrameLocals[ name ] = FetchObjectNamed( name )

Get("a", "b", "c")

print a, b, c
---

FetchObjectNamed() is an arbitrary function which takes a string and
returns an object it got from some store somewhere.

This works fine at the module level, because names in the locals/
globals dictionary can be played with in this way. The idea is to save
lots of typing, i.e.

a, b, c = Get("a","b","c")

..gets frustrating after much typing for many objects with long names.
This is just an example, there are other instances I have where it
would be nice to inject names into the frame above.

Of course, we hit a road block when we call 'Get' from a function
rather than a module, because the locals dictionary does not get
copied back into the code object automatically, so we have to add this
snippet before the Get() function returns:

from ctypes import pythonapi, py_object, c_int
pythonapi.PyFrame_LocalsToFast( py_object( frame ), 1 )

This copies back the names into the code object, and works fine.. that
is, if the names already exist within the code object.

def MyFunction():
a = None
Get("a")
print a # Works
Get("b")
print b # Name error, b is undefined

Is there any way for Get() to define a new variable within
MyFunction's code object? Or is there any programmatic way to, at
runtime, insert new names into functions?

I don't care how hacky it is and whether it requires making calls to
python's internals with ctypes - maybe the whole code object needs to
be replaced? is it even possible to do that when the Get() function is
about to return to this new code object?

Cheers,

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



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


Re: A service for testing Python code on multiple platforms and versions

2008-09-13 Thread Stef Mientki

David Moss wrote:

Hopefully a service like this already exists and I just haven't found
it yet. If not it could be an idea for some kind soul(s) to pick up
and run with ;-)

As someone who writes and releases Python modules for the community, I
find it difficult to have a decent level of confidence in the efficacy
of my code on platforms and Python versions other than those that I
own or use regularly. My documentation states that I support Python
2.3 or higher. This ends up being more of a statement of good
intentions than a one of fact.

A case in point. A bug (in Python), that I believed to have been
killed off after Python 2.2, resurfaced in a 2.4.x release of Python
on PowerPC recently. As I don't own any PowerPC kit, it was very
difficult to a) investigate the bug and b) create an effective fix for
it in a timely fashion. Fortunately I'd come across it before so the
fix was easy but it might not have been.

While I realise one's code can never be perfect, you can cover for
these sorts of eventualities fairly easily by running your software
and unit tests under different environments. You'd also like to be
able to do this on a continual basis rather than just once or twice.
If this was done with some kind of automated testing and reporting so
much the better. Bigger projects that take code quality seriously
probably already have this sort of thing in place for their own
purposes, but for smaller ones it just isn't possible.

Wouldn't it be great to have a service/setup out there available for
Python developers to access that covered a fairly broad base of
possible Python installations for the purpose of improve overall code
quality? Am I the only one that would find something like this useful?
  
I would love to have such a tool, but have no idea how to create 
something like that.
Something like a multi-virtual machine on a web server, that you launch 
in the night,
and in the morning you would get a full report of all problems on the 
specific OSs
(probably someone is going to say that this is impossible, but 
fortunately I'm not hindered by any knowledge ;-)


cheers,
Stef


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


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


Re: How to run PyOS_InputHook from python code (i.e. yield to event loops)

2008-09-13 Thread ville
Sean DiZazzo <[EMAIL PROTECTED]> writes:


>> My eventual code would be something like:
>>
>> launch_process_in_thread('bzr pull')
>>
>> while not is_done:
>>   pyos_inputhook()
>>   time.sleep(0.1)
>>
>> print "Done!"
>
> I'm still recovering from a hangover, so don't quote me.  I think you
> want the "after" function:
>
> launch_process_in_thread('bzr pull')
> self.update()
>
> def update(self):
> while not self.is_done:
> self.after(2000, self.update)

That's tk-specific, right? I'm looking for a snippet that

- Would not be tied to tk

- Would run sequentially, i.e. the next command would not be entered
  before the process has finished. Just like os.system()




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

Re: How to run PyOS_InputHook from python code (i.e. yield to event loops)

2008-09-13 Thread Fredrik Lundh

ville wrote:


That's tk-specific, right? I'm looking for a snippet that

- Would not be tied to tk


upstream, you said:

   "My actual use case is to keep a tkinter application responsive"



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


Re: Checking the boolean value of a collection

2008-09-13 Thread Marco Bizzarri
On Fri, Sep 12, 2008 at 4:09 PM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

>
> You should also consider using PEP8 style naming.
>
>
> Diez


class FolderInUse:

def __init__(self, core):
self.core = core

def true_for(self, archivefolder):
return any([instance.forbid_to_close(archivefolder) for instance in
self.core.active_outgoing_registration_instances()])

Is this any better? The true_for name does not satisfy me a lot...
maybe because it is too similar to True. Anyway, I'm trying a good
naming so that code is readable, like:

specification = FolderInUse(core)

if specification.true_for(folder):
   ...

Any thought about this?

Regards
Marco


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: A service for testing Python code on multiple platforms and versions

2008-09-13 Thread skip

David> As someone who writes and releases Python modules for the community, 
I
David> find it difficult to have a decent level of confidence in the 
efficacy
David> of my code on platforms and Python versions other than those that I
David> own or use regularly. My documentation states that I support Python
David> 2.3 or higher. This ends up being more of a statement of good
David> intentions than a one of fact.

How about Buildbot?  Here are some Python examples:

http://www.python.org/dev/buildbot/

And the Buildbot home page:

http://buildbot.net/trac

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


Re: A service for testing Python code on multiple platforms and versions

2008-09-13 Thread skip

Stef> Something like a multi-virtual machine on a web server, that you
Stef> launch in the night, and in the morning you would get a full
Stef> report of all problems on the specific OSs (probably someone is
Stef> going to say that this is impossible, but fortunately I'm not
Stef> hindered by any knowledge ;-)

You could run Buildbot on a bunch of virtual machines on your computer
(assuming your computer is x86 and its OS is supported by something like
Sun's VirtualBox or VMWare's offerings).

Skip

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


Code example that will make a Skype connection?

2008-09-13 Thread Al Dykes

Can some post a Python code fragment that will to make a PC with Skpye
installed to make a Skype call, given a valid phone # string.

I'm not asking for code that handles the audio once the connection is
made.






-- 
Al Dykes
 News is something someone wants to suppress, everything else is advertising.
- Lord Northcliffe, publisher of the Daily Mail

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


Re: Checking the boolean value of a collection

2008-09-13 Thread Fredrik Lundh

Marco Bizzarri wrote:


class FolderInUse:

>

def true_for(self, archivefolder):
return any([instance.forbid_to_close(archivefolder) for instance in
self.core.active_outgoing_registration_instances()])

Is this any better? The true_for name does not satisfy me a lot...


well, "true_for" is indeed pretty inscrutable, but I'm not sure that 
would be the first thing I'd complain about in that verbose mess...


(when you pick method names, keep in mind that the reader will see the 
context, the instance, and the arguments at the same time as they see 
the name.  there's no need to use complete sentences; pick short short 
descriptive names instead.)




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


Re: lacking follow-through

2008-09-13 Thread Paul Boddie
On 13 Sep, 08:38, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> His recent posts have generally been quite different from those of some
> months ago.  Even he recognizes that they were somewhat weird and has
> tried to do better.

And I think we should at least go along with people if they're willing
to raise their level of discussion. I'd much rather read messages at
the level of the one which initiated this thread than idiotic,
supposedly humorous responses about contributors being "bots".

> Did he ever make any degrading attacks on people like the above, to
> deserve receiving such?  This reminds me of my elementary school, where
> people who made social mistakes were sometimes never allowed to recover
> but were dumped on for years.

I get this impression as well: that "seniority" gives some kind of
right to dump on anyone, and that we should all find this a source of
amusement. It seems more like American high school, Hollywood style,
if you ask me.

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


code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Marco Bizzarri
On Sat, Sep 13, 2008 at 4:11 PM, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Marco Bizzarri wrote:
>
>> class FolderInUse:
>
>>
>>
>>def true_for(self, archivefolder):
>>return any([instance.forbid_to_close(archivefolder) for instance in
>>self.core.active_outgoing_registration_instances()])
>>
>> Is this any better? The true_for name does not satisfy me a lot...
>
> well, "true_for" is indeed pretty inscrutable, but I'm not sure that would
> be the first thing I'd complain about in that verbose mess...

"verbose mess".

It is always frustrating when you do what you think is your best and
you read that.

Anyway: I'm here to learn, and, of course, part of it is to listen
those who've been there much longer than you.

So, thanks for your sincere evaluation, Fredrik :-).

> (when you pick method names, keep in mind that the reader will see the
> context, the instance, and the arguments at the same time as they see the
> name.  there's no need to use complete sentences; pick short short
> descriptive names instead.)

Maybe I'm looking at the wrong direction, right now. From the point of
view of the FolderInUse clients, they will do:

condition = FolderInUse(core)

condition.true_for(folder)

Is this too verbose? This is not a polemic statement, I'm really
asking your opionion.

The expression inside the true_for is indeed complex, and maybe I can
simplify it; however, I'm deeply convinced that

instance.forbid_to_close(folder)

has some good points on it; I mean, once I read this kind of code, I
can hope to understand it without looking at what forbid_to_close
does.


> 
>

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: testing if another instance of a script is already running

2008-09-13 Thread Larry Bates

Strato wrote:

Hi folks,

I want to write some kind of test to check at startup if another 
instance of my script is already running.


I don't want to handle writing of a PID file because it is too 
Unix/Linux specific way to do this, and I need to keep the code to be 
cross-platform.


I think the better way to achieve this is to use some process control, 
but I'm a neebie and I don't see how to do this in a safe and clean way.


Any idea ?

Best regards,
Strato


Here is a recipe for Linux version of singleinstance class:

http://code.activestate.com/recipes/546512/

and I wrote and contributed the equivalent Windows version:

http://code.activestate.com/recipes/474070/

Hope this helps.

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


Re: testing if another instance of a script is already running

2008-09-13 Thread Larry Bates

Strato wrote:

Hi folks,

I want to write some kind of test to check at startup if another 
instance of my script is already running.


I don't want to handle writing of a PID file because it is too 
Unix/Linux specific way to do this, and I need to keep the code to be 
cross-platform.


I think the better way to achieve this is to use some process control, 
but I'm a neebie and I don't see how to do this in a safe and clean way.


Any idea ?

Best regards,
Strato


Here is a recipe for Windows version of singleinstance class:

http://code.activestate.com/recipes/474070/

and I wrote and contributed the equivalent Linux version:

http://code.activestate.com/recipes/546512/

Hope this helps.

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


Re: Code example that will make a Skype connection?

2008-09-13 Thread nntpman68

Hi,

Just some thoughts / now answer :-(

The solution might vary on the platform / OS.

Would it be acceptable for you to
control for example  firefox from python and firefox would control skype 
via the skype plugin. (should exist for multiple platforms)


Do you search a native python solution or would you accept, that some 
C-code had to be compiled.



bye


N


Al Dykes wrote:

Can some post a Python code fragment that will to make a PC with Skpye
installed to make a Skype call, given a valid phone # string.

I'm not asking for code that handles the audio once the connection is
made.







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


Re: Code example that will make a Skype connection?

2008-09-13 Thread Marco Bizzarri
On Sat, Sep 13, 2008 at 4:09 PM, Al Dykes <[EMAIL PROTECTED]> wrote:
>
> Can some post a Python code fragment that will to make a PC with Skpye
> installed to make a Skype call, given a valid phone # string.
>
> I'm not asking for code that handles the audio once the connection is
> made.
>
>

Maybe you can find this useful?


https://developer.skype.com/wiki/Skype4Py/examples/s4p_call_py


Regards
Marco

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Larry Bates

Marco Bizzarri wrote:

On Sat, Sep 13, 2008 at 4:11 PM, Fredrik Lundh <[EMAIL PROTECTED]> wrote:

Marco Bizzarri wrote:


class FolderInUse:

   def true_for(self, archivefolder):
   return any([instance.forbid_to_close(archivefolder) for instance in
   self.core.active_outgoing_registration_instances()])

Is this any better? The true_for name does not satisfy me a lot...

well, "true_for" is indeed pretty inscrutable, but I'm not sure that would
be the first thing I'd complain about in that verbose mess...


"verbose mess".

It is always frustrating when you do what you think is your best and
you read that.

Anyway: I'm here to learn, and, of course, part of it is to listen
those who've been there much longer than you.

So, thanks for your sincere evaluation, Fredrik :-).


(when you pick method names, keep in mind that the reader will see the
context, the instance, and the arguments at the same time as they see the
name.  there's no need to use complete sentences; pick short short
descriptive names instead.)


Maybe I'm looking at the wrong direction, right now. From the point of
view of the FolderInUse clients, they will do:

condition = FolderInUse(core)

condition.true_for(folder)

Is this too verbose? This is not a polemic statement, I'm really
asking your opionion.

The expression inside the true_for is indeed complex, and maybe I can
simplify it; however, I'm deeply convinced that

instance.forbid_to_close(folder)

has some good points on it; I mean, once I read this kind of code, I
can hope to understand it without looking at what forbid_to_close
does.









>>> class FolderInUse:
>>>
>>>def true_for(self, archivefolder):
>>>return any([instance.forbid_to_close(archivefolder) for instance in
>>>self.core.active_outgoing_registration_instances()])

IMHO it reads better if you use the __call__ method of the class to return the 
value and rewrite it as a regular loop for clarity.  Sometimes the simplest way 
is the easiest to read.


class FolderInUse:
   def __call__(self, archivefolder):
   result = False
   for instance in self.core.active_outgoing_registration_instances():
   if instance.forbid_to_close(archivefolder):
   result = True
   break

   return result


Then it can be called with:

if FolderInUse(archivefolder):
...

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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Bas
On Sep 13, 10:06 am, cnb <[EMAIL PROTECTED]> wrote:
> This must be because of implementation right? Shouldn't reduce be
> faster since it iterates once over the list?
> doesnt sum first construct the list then sum it?

No, sum also iterates the sequence just once and doesn't create a
list. It is probably implemented similar to

def sum(sequence, start=0):
it = iter(sequence)
total = start
for i in it:
total += i
return i

but then implemented in C for speed. Reduce is probably implemented
pretty similar, but then with a random function instead of addition.
Make sure that you understand the difference between generator
expression and list comprehension, and that [f(x) for x in something]
is (almost) equal to list(f(x) for x in something), so you can emulate
a LC by using the list constructor on the equivalent GE.

HTH,
Bas
--
http://mail.python.org/mailman/listinfo/python-list


Re: n00b question: Better Syntax for Coroutines?

2008-09-13 Thread Paul McGuire
On Sep 12, 8:08 pm, [EMAIL PROTECTED] wrote:
> First off, I'm a python n00b, so feel free to comment on anything if
> I'm doing it "the wrong way." I'm building a discrete event simulation
> tool. I wanted to use coroutines. However, I want to know if there's

You could "look in the back of the book" - download SimPy and see how
they does this.

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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Steven D'Aprano
On Sat, 13 Sep 2008 01:06:22 -0700, cnb wrote:

> This must be because of implementation right? Shouldn't reduce be faster
> since it iterates once over the list? doesnt sum first construct the
> list then sum it?

What makes you think that?

Given the speed of sum(), it sure doesn't look like it's generating a 
full list before summing. Why would it?


> reduce with named function:  37.9864357062 
> reduce with nested, named function:  39.4710288598 
> reduce with lambda:  39.2463927678
> sum comprehension:  25.9530121845

If you want to see reduce really shine, time it with a C-based function 
rather than one written in pure Python:

>>> Timer('reduce(add, xrange(1))', 
... 'from operator import add').repeat(number=1)
[19.724750995635986, 19.410486936569214, 19.614511013031006]
>>>
>>> Timer('reduce(add, xrange(1))', 
... 'def add(x, y): return x+y').repeat(number=1)
[45.210143089294434, 44.814558982849121, 46.906874895095825]


You probably won't see much (if any) benefit for small lists, so make 
sure your test is on a significantly-sized input list.

Of course, sum() is even faster than reduce:

>>> Timer('sum(xrange(1))').repeat(number=1)
[9.814924955368042, 8.7169640064239502, 9.5062401294708252]



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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Bruno Desthuilliers

Larry Bates a écrit :
(snip)
IMHO it reads better if you use the __call__ method of the class to 
return the value 


IMHO, it makes no sense at all to abuse the __call__ magic method here.

and rewrite it as a regular loop for clarity.  
Sometimes the simplest way is the easiest to read.


class FolderInUse:
   def __call__(self, archivefolder):
   result = False
   for instance in self.core.active_outgoing_registration_instances():
   if instance.forbid_to_close(archivefolder):
   result = True
   break

   return result



the loop would be simpler with an early return:


  for instance in self.core.active_outgoing_registration_instances():
if instance.forbid_to_close(archivefolder):
  return True
  return False




Then it can be called with:

if FolderInUse(archivefolder):
...


This will call the class constructor and initializer and return a new 
instance, not the *instance method* __call__.


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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Bruno Desthuilliers

Marco Bizzarri a écrit :

On Sat, Sep 13, 2008 at 4:11 PM, Fredrik Lundh <[EMAIL PROTECTED]> wrote:

Marco Bizzarri wrote:


class FolderInUse:

   def true_for(self, archivefolder):
   return any([instance.forbid_to_close(archivefolder) for instance in
   self.core.active_outgoing_registration_instances()])

Is this any better? The true_for name does not satisfy me a lot...

well, "true_for" is indeed pretty inscrutable, but I'm not sure that would
be the first thing I'd complain about in that verbose mess...


"verbose mess".

It is always frustrating when you do what you think is your best and
you read that.


The effbot is sometimes a bit abrupt in his formulations, for sure !-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: I cannot find where Numpy 1.2 is located

2008-09-13 Thread Gabriel Genellina
En Fri, 12 Sep 2008 17:02:44 -0300, Blubaugh, David A.  
<[EMAIL PROTECTED]> escribió:



I have been trying to locate as to where Numpy 1.2 can be downloaded.  I
will need this update.  The only version available at the Numpy website
for download is only 1.1.1 not the required 1.2 that I definitely need
at this time.


Try asking Guido for his time machine. 1.1.1 is the latest release.

--
Gabriel Genellina

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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Bruno Desthuilliers

Bruno Desthuilliers a écrit :

Larry Bates a écrit :
(snip)
IMHO it reads better if you use the __call__ method of the class to 
return the value 


IMHO, it makes no sense at all to abuse the __call__ magic method here.


Sorry - after a more careful re-read of other posts in the thread, it 
might make sense, given the use case :


condition = FolderInUse(core)
if condition.true_for(folder):
   # code here


but then, a plain function (or a partial) might be even better - that 
is, if the FolderInUse class doesn't have other responsabilities.



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


Re: Code example that will make a Skype connection?

2008-09-13 Thread Al Dykes
In article <[EMAIL PROTECTED]>,
nntpman68  <[EMAIL PROTECTED]> wrote:
>Hi,
>
>Just some thoughts / now answer :-(
>
>The solution might vary on the platform / OS.
>
>Would it be acceptable for you to
>control for example  firefox from python and firefox would control skype 
>via the skype plugin. (should exist for multiple platforms)
>
>Do you search a native python solution or would you accept, that some 
>C-code had to be compiled.
>

Building a C module is fine as long as I don't have to debug it.

I know that FF can do Skype so, I guess, if I write a Python app that
runs in a browser, I've solved my problem.  I'm about to learn Python,
so I haven't given any thought to how to do that.  


Thanks for the response. 

What would be picked for a portable Firebox-based app? 







-- 
Al Dykes
 News is something someone wants to suppress, everything else is advertising.
- Lord Northcliffe, publisher of the Daily Mail

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


Re: Checking the boolean value of a collection

2008-09-13 Thread Terry Reedy



Marco Bizzarri wrote:

On Fri, Sep 12, 2008 at 4:09 PM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:


You should also consider using PEP8 style naming.


Diez



class FolderInUse:

def __init__(self, core):
self.core = core

def true_for(self, archivefolder):
return any([instance.forbid_to_close(archivefolder) for instance in
self.core.active_outgoing_registration_instances()])

Is this any better?


Yes.  Now I can read it to suggest shorter names (I agree with FL here).
I would consider 'outgoing' for 'a_o_r_i' and perhaps 'no_close' or 
'stay_open' or suggestions below for 'f_t_c'



The true_for name does not satisfy me a lot...
maybe because it is too similar to True.


Does one of 'locked', 'forbidden', 'untouchable' express the essence of 
the condition being tested?  I would consider using the same adjective 
to name the test on instances and the collection of instances, or maybe 
'x' and 'any_x'.



 Anyway, I'm trying a good

naming so that code is readable, like:

specification = FolderInUse(core)

if specification.true_for(folder):
   ...

Any thought about this?


tjr

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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Terry Reedy



Steven D'Aprano wrote:

If you want to see reduce really shine, time it with a C-based function 
rather than one written in pure Python:


Timer('reduce(add, xrange(1))', 

... 'from operator import add').repeat(number=1)
[19.724750995635986, 19.410486936569214, 19.614511013031006]
Timer('reduce(add, xrange(1))', 

... 'def add(x, y): return x+y').repeat(number=1)
[45.210143089294434, 44.814558982849121, 46.906874895095825]

...

Of course, sum() is even faster than reduce:


Timer('sum(xrange(1))').repeat(number=1)

[9.814924955368042, 8.7169640064239502, 9.5062401294708252]


'Of course', because the irreducible difference between reduce(add.seq) 
and sum(seq) is that reduce has to call an add function while sum has 
the operation built-in in place of a call.


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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Larry Bates

Bruno Desthuilliers wrote:

Bruno Desthuilliers a écrit :

Larry Bates a écrit :
(snip)
IMHO it reads better if you use the __call__ method of the class to 
return the value 


IMHO, it makes no sense at all to abuse the __call__ magic method here.


Sorry - after a more careful re-read of other posts in the thread, it 
might make sense, given the use case :


condition = FolderInUse(core)
if condition.true_for(folder):
   # code here


but then, a plain function (or a partial) might be even better - that 
is, if the FolderInUse class doesn't have other responsabilities.





Sorry but I respectfully disagree that this is "abuse" of the __call__ method. 
I do agree that a plain function probably makes more sense but it appears that 
the class does "other"things because of references to other class instances, etc.


I also have a personal dislike for early returns because I've found it makes it 
harder insert execution trace logging into the code.  Just my experience.


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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Bruno Desthuilliers

Larry Bates a écrit :

Bruno Desthuilliers wrote:

Bruno Desthuilliers a écrit :

Larry Bates a écrit :
(snip)
IMHO it reads better if you use the __call__ method of the class to 
return the value 


IMHO, it makes no sense at all to abuse the __call__ magic method here.


Sorry - after a more careful re-read of other posts in the thread, it 
might make sense, given the use case :


condition = FolderInUse(core)
if condition.true_for(folder):
   # code here


but then, a plain function (or a partial) might be even better - that 
is, if the FolderInUse class doesn't have other responsabilities.





Sorry but I respectfully disagree that this is "abuse" of the __call__ 
method. 


As long as we respectfully agree to disagree...

!-)

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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Bruno Desthuilliers

Bruno Desthuilliers a écrit :

Larry Bates a écrit :

(snip)

Sorry but I respectfully disagree that this is "abuse" of the __call__ 
method. 


As long as we respectfully agree to disagree...

!-)


Anyway, I don't think we have enough background to seriously agree or 
disagree on what would make more sense here...

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


Re: lxml build error in sun

2008-09-13 Thread Stefan Behnel
Owen Zhang wrote:
> I am trying to build lxml package in SunOS 5.10. I got the following
> errors.

Could you report this on the lxml mailing list?

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


Re: code style and readability [was: Re: Checking the boolean value of a collection]

2008-09-13 Thread Fredrik Lundh

Larry Bates wrote:

I also have a personal dislike for early returns because I've found it 
makes it harder insert execution trace logging into the code.


in a language that makes it trivial to wrap arbitrary callables in 
tracing wrappers?




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


Re: Profiling, sum-comprehension vs reduce

2008-09-13 Thread Hrvoje Niksic
Terry Reedy <[EMAIL PROTECTED]> writes:

>> Of course, sum() is even faster than reduce:
>>
> Timer('sum(xrange(1))').repeat(number=1)
>> [9.814924955368042, 8.7169640064239502, 9.5062401294708252]
>
> 'Of course', because the irreducible difference between
> reduce(add.seq) and sum(seq) is that reduce has to call an add
> function while sum has the operation built-in in place of a call.

Note that, despite appearances, it's not as built-in as one might
wish.  sum(seq) is still completely generic and works on all
number-like objects (in fact on all objects that define an __add__
operation except strings, which are explicitly forbidden).  This means
that it can't just go ahead and execute a C addition, it must properly
call PyNumber_Add (the C API call equivalent to Python's "+"
operator), which will then inspect the objects and invoke the
appropriate implementation of addition.  On the other hand,
operator.add is defined to do exactly that -- call PyNumber_Add on its
arguments and return the result.

It's not entirely obvious why summing numbers using the same method,
repeatedly calling PyNumber_Add, would be significantly slower for
reduce than for sum.  Admittedly reduce has to execute a Python-level
function call which requires allocating and filling out a tuple, only
to reach PyNumber_Add, which sum calls immediately.  But
builtin_reduce() is actually careful to optimize those repeated
function calls, for example by reusing the same tuple across the loop.
--
http://mail.python.org/mailman/listinfo/python-list


Re: testing if another instance of a script is already running

2008-09-13 Thread Aaron "Castironpi" Brady
On Sep 12, 7:08 am, Strato <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I want to write some kind of test to check at startup if another
> instance of my script is already running.
>
> I don't want to handle writing of a PID file because it is too
> Unix/Linux specific way to do this, and I need to keep the code to be
> cross-platform.
>
> I think the better way to achieve this is to use some process control,
> but I'm a neebie and I don't see how to do this in a safe and clean way.
>
> Any idea ?
>
> Best regards,
> Strato

You could use msvcrt.locking, and just lock the script file.  I am not
sure about this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Code example that will make a Skype connection?

2008-09-13 Thread Al Dykes
In article <[EMAIL PROTECTED]>,
Marco Bizzarri <[EMAIL PROTECTED]> wrote:
>On Sat, Sep 13, 2008 at 4:09 PM, Al Dykes <[EMAIL PROTECTED]> wrote:
>>
>> Can some post a Python code fragment that will to make a PC with Skpye
>> installed to make a Skype call, given a valid phone # string.
>>
>> I'm not asking for code that handles the audio once the connection is
>> made.
>>
>>
>
>Maybe you can find this useful?
>
>
>https://developer.skype.com/wiki/Skype4Py/examples/s4p_call_py
>
>
>Regards
>Marco


Thanks for helping me get started.  I'm new to Skype and Python. 



-- 
Al Dykes
 News is something someone wants to suppress, everything else is advertising.
- Lord Northcliffe, publisher of the Daily Mail

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


Re: I cannot find where Numpy 1.2 is located

2008-09-13 Thread Robert Kern

Blubaugh, David A. wrote:

To All,


I have been trying to locate as to where Numpy 1.2 can be downloaded.  I
will need this update.  The only version available at the Numpy website
for download is only 1.1.1 not the required 1.2 that I definitely need
at this time.


For the last time, Jarrod Millman already told you where to get it on 
numpy-discussion. Please stop bothering python-list with this stuff.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: testing if another instance of a script is already running

2008-09-13 Thread skip

>> I don't want to handle writing of a PID file because it is too
>> Unix/Linux specific way to do this, and I need to keep the code to be
>> cross-platform.
>> 
>> I think the better way to achieve this is to use some process
>> control, but I'm a neebie and I don't see how to do this in a safe
>> and clean way.

Aaron> You could use msvcrt.locking, and just lock the script file.  I
Aaron> am not sure about this.

If you want a cross-platform solution, you might try the lockfile module
instead:

http://pypi.python.org/pypi/lockfile

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


Re: I cannot find where Numpy 1.2 is located

2008-09-13 Thread Robert Kern

Gabriel Genellina wrote:
En Fri, 12 Sep 2008 17:02:44 -0300, Blubaugh, David A. 
<[EMAIL PROTECTED]> escribió:



I have been trying to locate as to where Numpy 1.2 can be downloaded.  I
will need this update.  The only version available at the Numpy website
for download is only 1.1.1 not the required 1.2 that I definitely need
at this time.


Try asking Guido for his time machine. 1.1.1 is the latest release.


It contains a bug affecting him which is fixed in SVN and the numpy 1.2.0rc1, 
the location of which he has already been informed of. Why he persists in 
starting new threads in off-topic fora escapes me.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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

Re: testing if another instance of a script is already running

2008-09-13 Thread Aaron "Castironpi" Brady
On Sep 13, 5:34 pm, [EMAIL PROTECTED] wrote:
>     >> I don't want to handle writing of a PID file because it is too
>     >> Unix/Linux specific way to do this, and I need to keep the code to be
>     >> cross-platform.
>     >>
>     >> I think the better way to achieve this is to use some process
>     >> control, but I'm a neebie and I don't see how to do this in a safe
>     >> and clean way.
>
>     Aaron> You could use msvcrt.locking, and just lock the script file.  I
>     Aaron> am not sure about this.
>
> If you want a cross-platform solution, you might try the lockfile module
> instead:
>
>    http://pypi.python.org/pypi/lockfile
>
> Skip

Would it suffice to call 'os.open' with flags=  _O_CREAT| _O_EXCL ?
Would that be platform-independent?

Windows docs (_open):

_O_CREAT| _O_EXCL
Returns an error value if the file specified by filename exists.
Applies only when used with _O_CREAT.

man page:

O_EXCL
If O_EXCL and O_CREAT are set, open will fail if the file exists.
The check for the existence of the file and the creation of the file
if it does not exist is atomic with respect to other processes
executing open naming the same filename in the same directory with
O_EXCL and O_CREAT set.

CreateDirectory:

The CreateDirectory function does seem to guarantee this as well,
though is not as explicit:

Possible errors include the following.
ERROR_ALREADY_EXISTS
 The specified directory already exists.

But the lock operation wouldn't need the 'if hasattr(os, "link")' test.
--
http://mail.python.org/mailman/listinfo/python-list


How to emit Cyrillic and Chinese via unicode from console mode?

2008-09-13 Thread Siegfried Heintze
Can someone point me to an example of a little program that emits non-ascii 
Unicode characters (Russian or Chinese perhaps)? The unicode 
Russian/Cyrillic alphabet starts at 0x410. Is this possible to do in a 
console mode program? If not, I guess I would want to use pywin32 to create 
a window and a message pump and display it there. I anticipate using pywin32 
for some other function calls.

Thanks!
Siegfried 


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


Re: Python a good choice for experimenting with Win32 API?

2008-09-13 Thread Siegfried Heintze
I found this but have not tried it yet: 
http://aspn.activestate.com/ASPN/Mail/Message/ActivePython/1775844

How different is ActiveState Python from CPython? Can they both be used with 
pywin32 and the other packages?

Thanks!
Siegfried 


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


Stuck connection in Python 3.0b2 http.server

2008-09-13 Thread rs387
Hi All

I've encountered a weird issue when migrating a web server to Python 3
- the browser would wait forever without showing a page, displaying
"Transferring data" in the status bar. I tracked it down to a
reference cycle in my BaseHTTPRequestHandler descendant - one of the
attributes stored a dict of methods. Removing the cycle made the
problem go away.

In Python 2.5.2 the code works fine either way.

Here's a minimal example which runs in both 2.5 and 3.0 - to see stuck
connections run as-is in 3.0 and navigate to http://localhost:8123; to
fix this comment out "self.dummy = self" (alternatively reset
self.dummy = None at the end of the __init__ method).

Am I doing it wrong, or is this a bug?


try:
import http.server
httpmodule = http.server
except:
import BaseHTTPServer
httpmodule = BaseHTTPServer

class BreakageRequest(httpmodule.BaseHTTPRequestHandler):
def __init__(self, request, client_address, server):
self.dummy = self # COMMENT THIS OUT to see the connection
become unstuck
httpmodule.BaseHTTPRequestHandler.__init__(self, request,
client_address, server)
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "application/xml")
self.end_headers()
self.wfile.write("".encode('utf-8'))

srv = httpmodule.HTTPServer(('', 8123), BreakageRequest)
srv.serve_forever()
--
http://mail.python.org/mailman/listinfo/python-list


How does python call OS?

2008-09-13 Thread Siegfried Heintze
I just finished reading a chapter in "Python Programming on Win32" and tried 
out the pythonwin scribble application. I'm not sure if I got it right 
because I could not open a new document. I tried to download the source code 
as referenced in the chm file but it is corrupted. I cut and pasted from my 
softcopy of the book.

I see the next sub-chapter on wxWindows for python and the previous 
sub-chapter on TK. This is looking a lot like other scripting languages 
(such as perl and groovy and even java). Can python call anything directly 
or does someone have to write a DLL in C/C++ that calls the function first?
Thanks!
Siegfried


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


[SJN] Re: Selamat berahir pekan.

2008-09-13 Thread Neni Saleh
whohhhee ... *baru bangun ... :-))
selamat bersiap-siap untuk ngabuburit ya ...
saya lagi siap-siap mau sepedaan.
ada yang mau ikut???

2008/9/12 Mantri SJN <[EMAIL PROTECTED]>

> Iya om sama sama
>
> Salam dari Gunung
>
>  --
> *From*: "Rachmad Padma" <[EMAIL PROTECTED]>
> *Date*: Sat, 13 Sep 2008 11:37:33 +0800
>
> *To*: 
> *Subject*: [SJN] Re: Selamat berahir pekan.
>
>   oke deh selamat berpuasa dan sampai nunggu Bedug Magribnya
>
> 2008/9/13 Mantri SJN <[EMAIL PROTECTED]>
>
>> Lg mbangkong juga om di kosan
>>
>> Salam dari Gunung
>>
>>  --
>> *From*: "Rachmad Padma" <[EMAIL PROTECTED]>
>> *Date*: Sat, 13 Sep 2008 11:31:56 +0800
>> *To*: 
>> *Subject*: [SJN] Re: Selamat berahir pekan.
>>   Wah .lg di Offie apa di rumah nih Om ...
>>
>> 2008/9/13 Mantri SJN <[EMAIL PROTECTED]>
>>
>>> Pagi om
>>>
>>> Salam dari Gunung
>>>
>>> --
>>> *From*: "Rachmad Padma" <[EMAIL PROTECTED]>
>>> *Date*: Sat, 13 Sep 2008 11:23:57 +0800
>>> *To*: 
>>> *Subject*: [SJN] Re: Selamat berahir pekan.
>>>   Selamat pagi menjelang siang yg di KL baru bangun tidur lumayan bisa
>>> mbangkong 
>>>
>>> Salam
>>> MB
>>>
>>> 2008/9/13 eppysumadji <[EMAIL PROTECTED]>
>>>

 Hari ini hari Sabtu  biasanya millist sepi..
 Selamat pagi semua
 Saya lagi di Garut..he,he,he. ...tapi enggak bawa sepeda...puasa
 sih. Kalau NR sendirian takuuutnyasar.


>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
>
>
> >
>

--~--~-~--~~~---~--~~
FOTO SJN SERI 8 lihat di : http://www.flickr.com/photos/sjn8/
FOTO SJN SERI 7 lihat di : http://www.flickr.com/photos/sjn7/
Untuk keluar dari grup ini, kirim email kosong ke [EMAIL PROTECTED]
Sistem secara otomatis akan menghentikan langanan ke millist ini. Untuk pilihan 
lainnya, lihat grup ini pada 
http://groups.google.com/group/penggemar-sepeda-jelajah-nusantara/
-~--~~~~--~~--~--~---