string.replace non-ascii characters

2007-02-11 Thread Samuel Karl Peterson
Greetings Pythonistas. I have recently discovered a strange anomoly with string.replace. It seemingly, randomly does not deal with characters of ordinal value > 127. I ran into this problem while downloading auction web pages from ebay and trying to replace the "\xa0" (dec 160, nbsp char in iso-

Re: About getattr()

2007-02-11 Thread Leif K-Brooks
Jm lists wrote: > Since I can write the statement like: > print os.path.isdir.__doc__ > Test whether a path is a directory > > Why do I still need the getattr() func as below? > print getattr(os.path,"isdir").__doc__ > Test whether a path is a directory You don't. getattr() is only us

Re: About getattr()

2007-02-11 Thread Samuel Karl Peterson
"Jm lists" <[EMAIL PROTECTED]> on Mon, 12 Feb 2007 12:36:10 +0800 didst step forth and proclaim thus: > Hello, > > Since I can write the statement like: > > >>> print os.path.isdir.__doc__ > Test whether a path is a directory > > Why do I still need the getattr() func as below? > > >>> print g

Re: string.replace non-ascii characters

2007-02-11 Thread Steven Bethard
Samuel Karl Peterson wrote: > Greetings Pythonistas. I have recently discovered a strange anomoly > with string.replace. It seemingly, randomly does not deal with > characters of ordinal value > 127. I ran into this problem while > downloading auction web pages from ebay and trying to replace th

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Samuel Karl Peterson
James Stroud <[EMAIL PROTECTED]> on Sun, 11 Feb 2007 16:53:16 -0800 didst step forth and proclaim thus: > agent-s wrote: > > Basically I'm programming a board game and I have to use a list of > > lists to represent the board (a list of 8 lists with 8 elements each). > > I have to search the adjace

message processing/threads

2007-02-11 Thread Jonathan Curran
I've been thinking about this for a bit and wanted some input as to the design of it. The problem is as such: I need a program running in the background to process messages (FIFO order) which I would send using soap/xmlrpc/pyro (haven't decided yet). According to my thinking I would need to mak

Re: No module named pyExcelerator Error

2007-02-11 Thread Gabriel Genellina
En Mon, 12 Feb 2007 01:46:51 -0300, susan <[EMAIL PROTECTED]> escribió: >> > $ python ./pyExcelerator/setup.py install >> >> Try this instead: >> $ cdpyExcelerator >> $ python ./setup.py install > I still wonder why my way didn't work. I think maybe there's some hard > code of installation dire

Re: string.replace non-ascii characters

2007-02-11 Thread Samuel Karl Peterson
Steven Bethard <[EMAIL PROTECTED]> on Sun, 11 Feb 2007 22:23:59 -0700 didst step forth and proclaim thus: > Samuel Karl Peterson wrote: > > Greetings Pythonistas. I have recently discovered a strange anomoly > > with string.replace. It seemingly, randomly does not deal with > > characters of ord

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Gabriel Genellina
En Mon, 12 Feb 2007 02:24:54 -0300, Samuel Karl Peterson <[EMAIL PROTECTED]> escribió: > James Stroud <[EMAIL PROTECTED]> on Sun, 11 Feb 2007 16:53:16 -0800 > didst step forth and proclaim thus: > >> agent-s wrote: >> > Basically I'm programming a board game and I have to use a list of >> > list

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Paul Rubin
"agent-s" <[EMAIL PROTECTED]> writes: > Basically I'm programming a board game and I have to use a list of > lists to represent the board (a list of 8 lists with 8 elements each). > I have to search the adjacent cells for existing pieces and I was > wondering how I would go about doing this efficie

Re: string.replace non-ascii characters

2007-02-11 Thread Gabriel Genellina
En Mon, 12 Feb 2007 02:38:29 -0300, Samuel Karl Peterson <[EMAIL PROTECTED]> escribió: Sorry to steal the thread! This is only related to your signature: > "if programmers were paid to remove code instead of adding it, > software would be much better" -- unknown I just did that last week. Arou

Re: randomly generate n of each of two types

2007-02-11 Thread Steven D'Aprano
On Mon, 12 Feb 2007 00:57:35 +, Alan Isaac wrote: > "Stargaming" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> ... types *= n >> ... shuffle(types) > > This again has the "costs" I referred to: > creating a potentially large sequence, > and shuffling it. (Additionally,

Re: randomly generate n of each of two types

2007-02-11 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > If you want to avoid shuffle, here's an alternative: > > def random_values(n, valuelist=[True, False]): > N = len(valuelist) > for _ in range(N*n): > yield valuelist[random.randrange(0, N)] That is not guaranteed to yield exactly equa

Re: string.replace non-ascii characters

2007-02-11 Thread Steven D'Aprano
On Mon, 12 Feb 2007 03:01:55 -0300, Gabriel Genellina wrote: > En Mon, 12 Feb 2007 02:38:29 -0300, Samuel Karl Peterson > <[EMAIL PROTECTED]> escribió: > > Sorry to steal the thread! This is only related to your signature: > >> "if programmers were paid to remove code instead of adding it, >>

Re: randomly generate n of each of two types

2007-02-11 Thread Steven D'Aprano
On Sun, 11 Feb 2007 22:20:24 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> If you want to avoid shuffle, here's an alternative: >> >> def random_values(n, valuelist=[True, False]): >> N = len(valuelist) >> for _ in range(N*n): >> yield valuelist[random

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread James Stroud
Paul Rubin wrote: > "agent-s" <[EMAIL PROTECTED]> writes: > >>Basically I'm programming a board game and I have to use a list of >>lists to represent the board (a list of 8 lists with 8 elements each). >>I have to search the adjacent cells for existing pieces and I was >>wondering how I would go a

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread bearophileHUGS
James Stroud: > import operator > srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] > is_adj = reduce(operator.or_, [ary[row+i][col+j] for (i,j) in srch]]) Or maybe (untested), Python V.2.5: srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] is_adj = any(ary[r

Re: randomly generate n of each of two types

2007-02-11 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Ah, I see what you mean... you're reminding me that the Original Poster > seems to want a biased set of almost-but-not-quite-randomly chosen > values, so that random_values(1) must return one each of True and False > and never True, True or False, False

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread John Machin
On Feb 12, 4:24 pm, Samuel Karl Peterson <[EMAIL PROTECTED]> wrote: > C-like way to do it, (warning, untested in python): > > for i in range(8): > for j in range(8): > for offset_i in range(-1,2): > for offset_j in range(-1, 2): > row = i + offset_i >

<    1   2