Re: Testing if an index is in a slice

2009-01-03 Thread ajaksu
On Jan 3, 8:53 pm, Bryan Olson wrote: > If we add a parameter for the length of the list to which the slice is > applied, then inslice() is well-defined. Cool! > I thought it would easy to write, Heh, I gave up on the example I mentioned above :) > but that was hours ago when I knew > less abo

Re: why cannot assign to function call

2009-01-03 Thread Steven D'Aprano
I'm answering both John and Aaron's comments in the following. Mostly John at the start, Aaron toward the end. On Sat, 03 Jan 2009 15:42:47 -0800, Aaron Brady wrote: > On Jan 3, 11:25 am, John O'Hagan wrote: [...] > > >According to this, when you replace every floorboard on a porch, one > >

Re: simple turn-based multiplayer game via TCP server/client

2009-01-03 Thread alex goretoy
Since we are on the subject of Rock, Paper, Scissors. I've recntly watched this one video on how to make a .deb out of .py files and the tutor was using a rock, paper scissors game. Not sure how this may come of use to you but, I'll post it anyway for you to look at. May help somehow. http://www.

Memoizing and WeakValueDictionary

2009-01-03 Thread Paul McGuire
Just wanted to share some experience I had in doing some memory and performance tuning of a graphics script. I've been running some long- running scripts on high-resolution images, and added memoizing to optimize/minimize object creation (my objects are immutable, so better to reuse objects from a

Re: Port of python stdlib to other languages.

2009-01-03 Thread Mensanator
On Jan 3, 10:15�pm, vk wrote: > > AFAIK not. You could try elmer > > Elmer looks very interesting, but not really what I was getting at. > > > What do you need C for anyway? Or, to put it the other way round - why > > not expose whatever you need in C as python extension, and write your > > app in

Re: Doubt on creating threads

2009-01-03 Thread koranthala
On Jan 4, 4:59 am, Bryan Olson wrote: > koranth...@gmail.com wrote: > > I am creating an application and it creates ~1-2 threads every second > > and kill it within 10 seconds. After reading this I am worried. Is > > creating a thread a very costly operation? > > Compared to a procedure call it's

Re: Port of python stdlib to other languages.

2009-01-03 Thread vk
> AFAIK not. You could try elmer Elmer looks very interesting, but not really what I was getting at. > What do you need C for anyway? Or, to put it the other way round - why > not expose whatever you need in C as python extension, and write your > app in Python? I'm not looking to write a Python

Re: win32gui

2009-01-03 Thread Tim Roberts
Gandalf wrote: > >I'm trying to capture the text word under the user cursor, >so I was searching the win32 lib for functions I can use. You should know that, in the general case, this is impossible. Remember that the screen image you are looking at is just a big array of dots. If the window und

simple turn-based multiplayer game via TCP server/client

2009-01-03 Thread greyw...@gmail.com
Hi everyone, I'm learning python to get a multiplayer roleplaying game up and running. I didn't see any simple examples of multiplayer games on the web so I thought I'd post mine here. I choose Rock, Paper, Scissors as a first game to experiment with as the game logic/options are easy to impleme

Re: When does python 3.1, 3.2 version out?

2009-01-03 Thread Benjamin
On Jan 3, 8:47 pm, 叮叮当当 wrote: > Now, the 3.0 version is out for a time. > > I wonder when the python 3.1 is out, and what change is in python 3.1. There's no schedule yet. Hopefully, one will come into being around PyCon. -- http://mail.python.org/mailman/listinfo/python-list

Re: strange behavior of math.sqrt() in new 3.0 version

2009-01-03 Thread Eric Kemp
Tim Roberts wrote: Scott David Daniels wrote: I avoid using single-letter variables except where I know the types from the name (so I use i, j, k, l, m, n as integers, s as string, and w, x, y, and z I am a little looser with (but usually float or complex). It's amazing to me that Fortran con

Re: Ideas to optimize this getitem/eval call?

2009-01-03 Thread Steven D'Aprano
On Sat, 03 Jan 2009 04:14:14 -0800, mario wrote: > On Jan 3, 7:16 am, Steven D'Aprano cybersource.com.au> wrote: [...] >> I must say though, your choice of builtins to prohibit seems rather >> arbitrary. What is dangerous about (e.g.) id() and isinstance()? > > Preventive, probably. I also feel

Re: Why not Ruby?

2009-01-03 Thread Jack.Chu
On Jan 1, 3:55 am, Roger wrote: > On Dec 31, 12:55 pm, Xah Lee wrote: > > > Just spent 3 hours looking into Ruby today. Here's my short impression > > for those interested. > > Who are you? > > In case no one tells you, you are a cocky, egotistical windbag with > opinions that border constructi

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread Steven D'Aprano
On Sat, 03 Jan 2009 16:19:58 +0100, Bruno Desthuilliers wrote: > But indeed, you obviously cannot add strings with numerics nor > concatenate numerics with strings. This would make no sense. The OP comes from a Perl background, which AFAIK allows you to concat numbers to strings and add strings

Re: math module for Decimals

2009-01-03 Thread Steven D'Aprano
On Sat, 03 Jan 2009 13:34:11 -0800, Mark Dickinson wrote: > On Jan 3, 9:27 pm, Mark Dickinson wrote: >> Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 >> and Python 3.1, within 72 hours of Steven submitting the feature >> request.  If only all issues could be resolved this q

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread Steven D'Aprano
On Sat, 03 Jan 2009 20:35:25 +, alex goretoy wrote: > for each his own. Please don't top-post. Please don't quote the ENTIRE body of text (PLUS doubling it by including a completely useless HTML version) just to add a trivial comment. Trim the text you are replying to. > Any more word on

Re: Doubt on creating threads

2009-01-03 Thread Bryan Olson
koranth...@gmail.com wrote: I am creating an application and it creates ~1-2 threads every second and kill it within 10 seconds. After reading this I am worried. Is creating a thread a very costly operation? Compared to a procedure call it's expensive, but a couple threads per second is insig

Re: socket send help

2009-01-03 Thread Bryan Olson
Gabriel Genellina wrote: greyw...@gmail.com escribió: [...] A simple server: from socket import * myHost = '' Try with myHost = '127.0.0.1' instead - a firewall might be blocking your server. Just a nit: I'd say the reason to use '127.0.0.1' instead of the empty string is that a firewall

Re: why cannot assign to function call

2009-01-03 Thread Aaron Brady
On Jan 3, 11:25 am, John O'Hagan wrote: > On Tue, 30th Dec 2008, Aaron Brady wrote: > >Accepting that, I'll adopt the terms John proposed, 'change' vs. > >'exchange', the former when the material configuration changes, the > >latter when the communication axioms change. > > >b= [2, 3] > >b= [3, 4]

Re: Testing if an index is in a slice

2009-01-03 Thread Bryan Olson
ajaksu wrote: On Jan 1, 4:12 pm, mma...@gmx.net wrote: I would like to check if an index is in a slice or not without iterating over the slice. Something like: isinslice(36, slice(None, 34, -1)) True I think it'd be feasible for slices that can be mapped to ranges[1], but slices are more f

Re: deleting a method

2009-01-03 Thread Ben Finney
MRAB writes: > Filip Gruszczyński wrote: > > Traceback (most recent call last): > > File "", line 1, in > > AttributeError: A instance has no attribute 'foo' > > > > Why is it so and how may still delete it? > > > 'a' is an instance of class A. You're trying to delete 'foo' from > the instance

Re: deleting a method

2009-01-03 Thread MRAB
Filip Gruszczyński wrote: I am trying to delete a method from a class. It's easy to delete other attributes, but when I try: class A: ... def foo(): ... pass ... a = A() del a.foo I get Traceback (most recent call last): File "", line 1, in AttributeError: A instance has

deleting a method

2009-01-03 Thread Filip Gruszczyński
I am trying to delete a method from a class. It's easy to delete other attributes, but when I try: >>> class A: ... def foo(): ... pass ... >>> a = A() >>> del a.foo I get Traceback (most recent call last): File "", line 1, in AttributeError: A instance has no attribute 'foo'

Re: Reverse order of bit in repeating seqence of byte string

2009-01-03 Thread John Machin
On Jan 4, 7:10 am, imageguy wrote: > On Jan 2, 7:33 pm, John Machin wrote: > > > For some very strange definition of "works". You say you have 'bgr' > > and want to convert it to 'rbg'. The following code converts 'bgr' to > > 'rgb', which is somewhat more plausible, but not what you said you > >

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Jan 3, 9:27 pm, Mark Dickinson wrote: > Decimal.from_float() implemented by Raymond Hettinger for Python 2.7 > and Python 3.1, within 72 hours of Steven submitting the feature > request.  If only all issues could be resolved this quickly. :-) Rats. I left out the crucial line of that post, na

Re: math module for Decimals

2009-01-03 Thread Mark Dickinson
On Dec 31 2008, 11:02 pm, Steven D'Aprano wrote: > On Sun, 28 Dec 2008 06:38:32 -0800, Mark Dickinson wrote: > > On Dec 28, 7:28 am, Steven D'Aprano > cybersource.com.au> wrote: > >> Ah crap, I forgot that from_float() has been left out of the decimal > >> API. That's very annoying. > > > Agreed.

Re: select.select and socket.setblocking

2009-01-03 Thread Roy Smith
Bryan Olson wrote: > There are cases where a socket can select() as readable, but not be > readable by the time of a following recv() or accept() call. All such > cases with which I'm familiar call for a non-blocking socket. I used to believe that if select() said data was ready for reading, a

compiling python2.5 on linux under wine

2009-01-03 Thread Luke Kenneth Casson Leighton
hey, has anyone investigated compiling python2.5 using winegcc, under wine? i'm presently working my way through it, just for kicks, and was wondering if anyone would like to pitch in or stare at the mess under a microscope. it's not as crazed as it sounds. cross-compiling python2.5 for win32 wit

Re: ResponseNotReady exception

2009-01-03 Thread asit
On Jan 4, 1:59 am, "Chris Rebert" wrote: > On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > > import httplib > > > class Server: > >    #server class > >    def __init__(self, host): > >        self.host = host > >    def fetch(self, path): > >        http = httplib.HTTPConnection(self.host) > >  

win32gui

2009-01-03 Thread Gandalf
Hi, I'm trying to capture the text word under the user cursor, so I was searching the win32 lib for functions I can use. i used this to fined the controller under the cursor win32gui.WindowFromPoint(win32gui.GetCursorPos()) to get the controller, but then when I try to read the text with this GetW

Re: Port of python stdlib to other languages.

2009-01-03 Thread Diez B. Roggisch
vk schrieb: Have there been ports of the Python standard library to other languages? I would imagine using pickle, urllib, and sys in C (with pythonic naming conventions) would be easier than using other libraries to do the same thing. AFAIK not. You could try elmer (found on SF) to expose the

Port of python stdlib to other languages.

2009-01-03 Thread vk
Have there been ports of the Python standard library to other languages? I would imagine using pickle, urllib, and sys in C (with pythonic naming conventions) would be easier than using other libraries to do the same thing. -- http://mail.python.org/mailman/listinfo/python-list

Re: ResponseNotReady exception

2009-01-03 Thread Chris Rebert
On Sat, Jan 3, 2009 at 12:38 PM, asit wrote: > import httplib > > class Server: >#server class >def __init__(self, host): >self.host = host >def fetch(self, path): >http = httplib.HTTPConnection(self.host) >http.putrequest("GET", path) According to the docs, if

Re: strange thing after call PyObject_CallMethod

2009-01-03 Thread Bug Hunter
Thank you for so amazing debugging tutorial :). I owe you a beer. I found source of problem: then unhandled in python code exception occurs frame_dealloc() (Objects/frameobject.c:422) not called. Even if I call PyErr_Print(). But! If I call PyErr_Clear() then all okay! Docs says that both this f

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread vk
> Any more word on userio? None yet, I'm afraid. Should've started a different thread for it - but it's stuck here (in obscurity) forever xd. -- http://mail.python.org/mailman/listinfo/python-list

Re: select.select and socket.setblocking

2009-01-03 Thread Saju Pillai
Bryan Olson wrote: > >Where does this come up? Suppose that to take advantage of multi-core >processors, our server runs as four processes, each with a single thread >that responds to events via select(). Clients all connect to the same >server port, so the socket listening on that port is sh

ResponseNotReady exception

2009-01-03 Thread asit
import httplib class Server: #server class def __init__(self, host): self.host = host def fetch(self, path): http = httplib.HTTPConnection(self.host) http.putrequest("GET", path) r = http.getresponse() print str(r.status) + " : " + r.reason s

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread alex goretoy
for each his own. Any more word on userio? On Sat, Jan 3, 2009 at 6:14 PM, Russ P. wrote: > On Jan 2, 10:50 pm, Ben Finney > > > > wrote: > > s0s...@gmail.com writes: > > > On Jan 2, 7:20 pm, Ben Finney > > > > > > > > wrote: > > > > They don't need to be creative; they merely need to confo

Re: Reverse order of bit in repeating seqence of byte string

2009-01-03 Thread imageguy
On Jan 2, 7:33 pm, John Machin wrote: > For some very strange definition of "works". You say you have 'bgr' > and want to convert it to 'rbg'. The following code converts 'bgr' to > 'rgb', which is somewhat more plausible, but not what you said you > wanted. Well that's embarrassing ... you are

Re: Returning a string

2009-01-03 Thread Kless
On 3 ene, 19:51, "Diez B. Roggisch" wrote: > Kless schrieb: > > > > > On 3 ene, 19:40, Simon Forman wrote: > >> On Jan 3, 11:20 am, Kless wrote: > > >>> Afghanistan > >>> AF > >>> Out[19]: u'AF' > >>> AFG > >>> Out[19]: u'AFG' > >>> 004 > >>> Out[19]: u'004' > >> What? > > > That's the output go

Re: Returning a string

2009-01-03 Thread Marc 'BlackJack' Rintsch
On Sat, 03 Jan 2009 11:46:10 -0800, Kless wrote: > On 3 ene, 19:40, Simon Forman wrote: >> On Jan 3, 11:20 am, Kless wrote: >> >> > Afghanistan >> > AF >> > Out[19]: u'AF' >> > AFG >> > Out[19]: u'AFG' >> > 004 >> > Out[19]: u'004' >> >> What? > > That's the output got from ipython. As you can

Re: Returning a string

2009-01-03 Thread Diez B. Roggisch
Kless schrieb: On 3 ene, 19:40, Simon Forman wrote: On Jan 3, 11:20 am, Kless wrote: Afghanistan AF Out[19]: u'AF' AFG Out[19]: u'AFG' 004 Out[19]: u'004' What? That's the output got from ipython. As you can see, it prints 'Afghanistan' but it can not returns it. In change, the another st

Re: Returning a string

2009-01-03 Thread Diez B. Roggisch
Kless schrieb: On 3 ene, 19:12, "Diez B. Roggisch" wrote: Kless schrieb: How is possible that I can print a variable, but when I use *return var* it returns an empty string http://paste.pocoo.org/show/97588/ I don't see anything that indicates that the returned object is the empty string. Si

Re: Returning a string

2009-01-03 Thread Kless
On 3 ene, 19:40, Simon Forman wrote: > On Jan 3, 11:20 am, Kless wrote: > > > Afghanistan > > AF > > Out[19]: u'AF' > > AFG > > Out[19]: u'AFG' > > 004 > > Out[19]: u'004' > > What? That's the output got from ipython. As you can see, it prints 'Afghanistan' but it can not returns it. In change,

Re: Returning a string

2009-01-03 Thread Simon Forman
On Jan 3, 11:20 am, Kless wrote: > On 3 ene, 19:12, "Diez B. Roggisch" wrote: > > > Kless schrieb: > > > > How is possible that I can print a variable, but when I use *return > > > var* it returns an empty string > > > >http://paste.pocoo.org/show/97588/ > > > I don't see anything that indicates

Re: Returning a string

2009-01-03 Thread Kless
On 3 ene, 19:12, "Diez B. Roggisch" wrote: > Kless schrieb: > > > How is possible that I can print a variable, but when I use *return > > var* it returns an empty string > > >http://paste.pocoo.org/show/97588/ > > I don't see anything that indicates that the returned object is the > empty string.

Re: Returning a string

2009-01-03 Thread Diez B. Roggisch
Kless schrieb: How is possible that I can print a variable, but when I use *return var* it returns an empty string http://paste.pocoo.org/show/97588/ I don't see anything that indicates that the returned object is the empty string. Simply because there is no code testing for that. And of cou

Re: Doubt on creating threads

2009-01-03 Thread Simon Forman
On Jan 3, 8:39 am, koranth...@gmail.com wrote: > I was going through Python posts and this post caught my > attentionhttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > >  You have missed an important point. A well designed application does >  neither create so many threa

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread Russ P.
On Jan 2, 10:50 pm, Ben Finney wrote: > s0s...@gmail.com writes: > > On Jan 2, 7:20 pm, Ben Finney > > wrote: > > > They don't need to be creative; they merely need to conform with > > > the naming scheme as laid out in the PEP. > > > If it's something to be included in the standard library, I ag

Re: strange thing after call PyObject_CallMethod

2009-01-03 Thread Martin v. Löwis
> Why this happenning and who makes Py_INCREF(self)? There are multiple possible explanations, but I think you have ruled out most of them: 1. on_recv might be returning self. So py_result would be the same as self, and hence be an additional reference. However, you said that on_recv raised

Re: Doubt on creating threads

2009-01-03 Thread Jean-Paul Calderone
On Sat, 3 Jan 2009 08:39:52 -0800 (PST), koranth...@gmail.com wrote: I was going through Python posts and this post caught my attention http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a You have missed an important point. A we

strange thing after call PyObject_CallMethod

2009-01-03 Thread Exe
Hello everybody! I'm in trouble. This code shows that ob_refcnt increased by python if "on_recv" method throws exception. This occurs only if base C-class subclassed in python code. == my_old_refcnt = Py_REFCNT(self); py_result = PyObject_CallMethod(self, "on_recv", "(y#)", recvbuf, result

Re: why cannot assign to function call

2009-01-03 Thread Grant Edwards
On 2009-01-03, Marc 'BlackJack' Rintsch wrote: > On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > >> What the Python community often overlooks, when this discussion again >> rears its ugly head (as it seems to every other hour or so), is that its >> assignment model is BIZARRE, as in it's

Re: select.select and socket.setblocking

2009-01-03 Thread Bryan Olson
Laszlo Nagy wrote: [...] I have read the socket programming howto ( http://docs.python.org/howto/sockets.html#sockets ) but it does not explain how a blocking socket + select is different from a non blocking socket + select. Is there any difference? There is, but it may not effect you. There ar

Re: why cannot assign to function call

2009-01-03 Thread John O'Hagan
On Tue, 30th Dec 2008, Aaron Brady wrote: >Accepting that, I'll adopt the terms John proposed, 'change' vs. >'exchange', the former when the material configuration changes, the >latter when the communication axioms change. > >b= [2, 3] >b= [3, 4] > >'b' has exchanged. (Somewhat ungrammatical.) >

Doubt on creating threads

2009-01-03 Thread koranthala
I was going through Python posts and this post caught my attention http://groups.google.com/group/comp.lang.python/browse_thread/thread/f99326a4e5d394e/14cd708956bd1c1a#14cd708956bd1c1a You have missed an important point. A well designed application does neither create so many threads nor proce

Re: Noob question: Is all this typecasting normal?

2009-01-03 Thread Bruno Desthuilliers
sprad a écrit : I've done a good bit of Perl, but I'm new to Python. I find myself doing a lot of typecasting (or whatever this thing I'm about to show you is called), Actually, it's just plain object instanciation. and I'm wondering if it's normal, or if I'm missing an important idiom. For

Re: why cannot assign to function call

2009-01-03 Thread Bruno Desthuilliers
Derek Martin a écrit : On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: Python seems rather weird, and I think from the frequency with which these discussions occur on this list, clearly it *IS* difficult for a neophyte Python programmer to understand the assignment model. To

Re: greenlets and how they can be used

2009-01-03 Thread Mark Wooding
James Mills wrote: > The "greenlet" from http://codespeak.net/py/dist/greenlet.html > is a rather interesting way of handling flow of control. Ahh, yes. It's actually a rather old idea, but too rarely used. > What can "greenlet"'s be used for ? What use-cases have you guys used > them for (if

Re: multiprocessing vs thread performance

2009-01-03 Thread Nick Craig-Wood
mk wrote: > After reading http://www.python.org/dev/peps/pep-0371/ I was under > impression that performance of multiprocessing package is similar to > that of thread / threading. However, to familiarize myself with both > packages I wrote my own test of spawning and returning 100,000 empty

Re: Ideas to optimize this getitem/eval call?

2009-01-03 Thread mario
correction: the code posted in previous message should have been: def __getitem__(self, expr): try: return eval(self.codes[expr], self.globals, self.locals) except: # We want to catch **all** evaluation errors! # KeyError, NameError, Attribu

Re: ACL in python

2009-01-03 Thread Tino Wildenhain
John Boloshevich wrote: Hello, does anybody know about an ACL implementation for python, which is not tied to the filesystem? I would like to use ACL on different objects not on files, so the POSIX file access solution is not the one I am looking for. You mean something like the restricted e

Re: Ideas to optimize this getitem/eval call?

2009-01-03 Thread mario
On Jan 3, 7:16 am, Steven D'Aprano wrote: > I was about to make a comment about this being a security hole, Strange that you say this, as you are also implying that *all* the widely-used templating systems for python are security holes... Well, you would be right to say that of course ;-) Infact

Re: why cannot assign to function call

2009-01-03 Thread Marc 'BlackJack' Rintsch
On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: > On Tue, Dec 30, 2008 at 02:21:29PM +, John O'Hagan wrote: > What the Python community often overlooks, when this discussion again > rears its ugly head (as it seems to every other hour or so), is that its > assignment model is BIZARRE,

Re: Why not Ruby?

2009-01-03 Thread Marc 'BlackJack' Rintsch
On Fri, 02 Jan 2009 09:00:01 -0800, r wrote: > On Jan 2, 6:45 am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: >> > He was not cross posting. >> >> You don't actually know what cross-posting is, do you? >> >> You've just earned a plonking for the next

ACL in python

2009-01-03 Thread John Boloshevich
Hello, does anybody know about an ACL implementation for python, which is not tied to the filesystem? I would like to use ACL on different objects not on files, so the POSIX file access solution is not the one I am looking for. I would like to be able to define ACOs, AROs, but it would be even ni

patch

2009-01-03 Thread Pavel Kosina
Týká se to Pythonu okrajově, přesto to dávám sem. Myslím, že by se mohlo hodit i ostatním, kdo chtějí zkoušet pod Windows nové věci z development verze: Jak opatchovat (pythonýrský) soubor pod Windows? Co jsem udělal: 1/ stáhl jsem http://gnuwin32.sourceforge.net/packages/patch.htm 2/ nainstal

Re: Is there a better algorithm?

2009-01-03 Thread Hendrik van Rooyen
bearophile wrote: >Fuzzyman: > >> for i in l: >> u = None >> if len(i) == 2: >> k, v = i >> else: >> k, u, v = i > >That's the best solution I have seen in this thread so far (but I >suggest to improve indents and use better variable names). In >programming it's generally better to follow t