Re: Regex driving me crazy...

2010-04-08 Thread Steven D'Aprano
On Wed, 07 Apr 2010 21:57:31 -0700, Patrick Maupin wrote: > On Apr 7, 9:51 pm, Steven D'Aprano > wrote: > > BTW, I don't know how you got 'True' here. > >> >>> re.split(' {2,}', s) == [x for x in s.split('  ') if x.strip()] >> True It was a copy and paste from the interactive interpreter. Her

Re: Performance of list vs. set equality operations

2010-04-08 Thread Steven D'Aprano
On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote: > [Raymond Hettinger] >> > If the two collections have unequal sizes, then both ways immediately >> > return unequal. > > [Steven D'Aprano] >> Perhaps I'm misinterpreting what you are saying, but I can't confirm >> that behaviour, at le

Re: Simple Cookie Script: Not recognising Cookie

2010-04-08 Thread Pierre Quentel
On 8 avr, 07:03, Jimbo wrote: > Hi I have a simple Python program that assigns a cookie to a web user > when they open the script the 1st time(in an internet browser). If > they open the script a second time the script should display the line > " You have been here 2 times." , if they open the scr

Re: pass object or use self.object?

2010-04-08 Thread Bruno Desthuilliers
Lie Ryan a écrit : On 04/07/10 18:34, Bruno Desthuilliers wrote: Lie Ryan a écrit : (snip) Since in function in python is a first-class object, you can instead do something like: def process(document): # note: document should encapsulate its own logic document.do_one_thing() Obvious

Re: Loading an imported module (C API)

2010-04-08 Thread CHEN Guang
PythoidC (http://pythoidc.sourceforge.net/) provides an easy way for developing and importing C modules into Python environment. There are some examples, may be of some help to you. With PythoidC, Python programmers can write, debug, commpile, C codes all in Python IDE, and do not have to tacke

Re: Translation docstrings with gettext

2010-04-08 Thread sapient
Thank you for your help. Solution with decorators looks well, will try it in near future. I will report here if I solve this problem. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Regular Expressions

2010-04-08 Thread Nobody
On Wed, 07 Apr 2010 18:25:36 -0700, Patrick Maupin wrote: >> Regular expressions != Parsers > > True, but lots of parsers *use* regular expressions in their > tokenizers. In fact, if you have a pure Python parser, you can often > get huge performance gains by rearranging your code slightly so th

Re: Loading an imported module (C API)

2010-04-08 Thread Christian Heimes
On 06.04.2010 15:58, booncw wrote: Hi, I am running a simulation where the python module has already been imported. Could you please tell me how to load it? I've been doing this (importing everytime), but it is too slow: pModule = PyImport_Import(pName); You can cache the module object in a

Re: Performance of list vs. set equality operations

2010-04-08 Thread Terry Reedy
On 4/8/2010 3:07 AM, Steven D'Aprano wrote: On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote: [Raymond Hettinger] If the two collections have unequal sizes, then both ways immediately return unequal. [Steven D'Aprano] Perhaps I'm misinterpreting what you are saying, but I can't c

python grep

2010-04-08 Thread Mag Gam
I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of GNU grep. Lets say I have this, 083828.441,AA 093828.441,AA 094028.441,AA 094058.441,CC 094828.441,AA 103828.441,

Re: Translation docstrings with gettext

2010-04-08 Thread Peter Otten
sapient wrote: > I found several discussions where this question was asked, but was not > answered. > > Now I am creating Python-API for my application, and want create it > with translation support, including documentation strings for modules, > classes, methods etc. > > It is simple to transla

Re: python grep

2010-04-08 Thread Stefan Behnel
Mag Gam, 08.04.2010 13:21: I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of GNU grep. Lets say I have this, 083828.441,AA 093828.441,AA 094028.441,AA 094058.441

Re: Python and Regular Expressions

2010-04-08 Thread Richard Lamboj
At the moment i have less time, so its painful to read about parsing, but it is quite interessting. I have taken a look at the different Parsing Modules and i'am reading the Source Code to understand how they Work. Since Yesterday i'am writing on my own small Engine - Just for Fun and understa

Re: Python and Regular Expressions

2010-04-08 Thread Charles
"Nobody" wrote in message news:pan.2010.04.08.10.12.59.594...@nowhere.com... > On Wed, 07 Apr 2010 18:25:36 -0700, Patrick Maupin wrote: > >>> Regular expressions != Parsers >> >> True, but lots of parsers *use* regular expressions in their >> tokenizers. In fact, if you have a pure Python pars

daemon.DaemonContext

2010-04-08 Thread Rebelo
i get : IOError: [Errno 9] Bad file descriptor when i have logging and using daemon.DaemonContext() i tried passing : fh = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, 'midnight', encoding='utf-8') with : context = daemon.DaemonContext() context.files_preserve=[fh] but no good what a

Re: python grep

2010-04-08 Thread Mag Gam
Oh, thats nice to know! But I use the CSV module with gzip module. Is it still possible to do it with the subprocess? On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel wrote: > Mag Gam, 08.04.2010 13:21: >> >> I am in the process of reading a zipped file which is about 6gb. >> >> I would like to k

Re: daemon.DaemonContext

2010-04-08 Thread Rebelo
when i use this : context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, files_preserve=[fh], signal_map = {signal.SIGTERM: 'terminate',signal.SIGHUP: 'terminate'}) i don't get error but i still can't write to log file what am i doing wrong? -- http://mail.python.org/mailman/listinfo

Re: daemon.DaemonContext

2010-04-08 Thread Vinay Sajip
On Apr 8, 1:28 pm, Rebelo wrote: > when i use this : >  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, > files_preserve=[fh], signal_map = {signal.SIGTERM: > 'terminate',signal.SIGHUP: 'terminate'}) > > i don't get error but i still can't write to log file > what am i doing wro

Re: daemon.DaemonContext

2010-04-08 Thread Vinay Sajip
On Apr 8, 1:28 pm, Rebelo wrote: > when i use this : >  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, > files_preserve=[fh], signal_map = {signal.SIGTERM: > 'terminate',signal.SIGHUP: 'terminate'}) > > i don't get error but i still can't write to log file > what am i doing wro

Re: daemon.DaemonContext

2010-04-08 Thread Rebelo
Vinay Sajip wrote: On Apr 8, 1:28 pm, Rebelo wrote: when i use this : context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, files_preserve=[fh], signal_map = {signal.SIGTERM: 'terminate',signal.SIGHUP: 'terminate'}) i don't get error but i still can't write to log file what am i

Re: Profiling: Interpreting tottime

2010-04-08 Thread Nikolaus Rath
"Gabriel Genellina" writes: > En Wed, 07 Apr 2010 18:44:39 -0300, Nikolaus Rath > escribió: > >> def check_s3_refcounts(): >> """Check s3 object reference counts""" >> >> global found_errors >> log.info('Checking S3 object reference counts...') >> >> for (key, refcount) in conn.qu

Re: ftp and python

2010-04-08 Thread Simon
You could user FTP.voidcmd() E.G. ftp.voidcmd('RNFT filename.txt')ftp.voidcmd('RNTO newdir/filename.txt') >From the rfc: RENAME FROM (RNFR) This command specifies the old pathname of the file which is to be renamed. This command must be immediately followed by a "rename to" command spec

get objects from image

2010-04-08 Thread Jannis Syntychakis
Hallo Everybody, Maybe you can help me with this: i have a picture. The picture is black, with some white objects. Is there any way i can detect the automatically? Something like: if there white objects bigger than 3 pixels draw a box there or get their position! getting their position is more

Re: daemon.DaemonContext

2010-04-08 Thread Vinay Sajip
On Apr 8, 1:58 pm, Rebelo wrote: > Vinay Sajip wrote: > > On Apr 8, 1:28 pm, Rebelo wrote: > >> when i use this : > >>  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, > >> files_preserve=[fh], signal_map = {signal.SIGTERM: > >> 'terminate',signal.SIGHUP: 'terminate'}) > > >> i

Re: daemon.DaemonContext

2010-04-08 Thread Rebelo
i found a crude workaround: i wrote a function in which i start logging after deamon starts -- http://mail.python.org/mailman/listinfo/python-list

Re: ftp and python

2010-04-08 Thread Tim Chase
Simon wrote: You could user FTP.voidcmd() E.G. ftp.voidcmd('RNFT filename.txt')ftp.voidcmd('RNTO newdir/filename.txt') From the rfc: RENAME FROM (RNFR) This command specifies the old pathname of the file which is to be renamed. This command must be immediately followed by a "rename

Re: daemon.DaemonContext

2010-04-08 Thread Rebelo
Vinay Sajip wrote: On Apr 8, 1:58 pm, Rebelo wrote: Vinay Sajip wrote: On Apr 8, 1:28 pm, Rebelo wrote: when i use this : context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout, files_preserve=[fh], signal_map = {signal.SIGTERM: 'terminate',signal.SIGHUP: 'terminate'}) i don't ge

Re: Regex driving me crazy...

2010-04-08 Thread J
On Thu, Apr 8, 2010 at 01:16, Kushal Kumaran wrote: > > Is there any particular reason you absolutely must extract the status > message?  If you already have a list of possible status messages, you > could just test which one of those is present in the line... Yes and no... Mostly, it's for the

Re: get objects from image

2010-04-08 Thread Chris Hulan
On Apr 8, 9:17 am, Jannis Syntychakis wrote: > Hallo Everybody, > > Maybe you can help me with this: > > i have a picture. The picture is black, with some white objects. > > Is there any way i can detect the automatically? Something like: > if there white objects bigger than 3 pixels draw a box th

How to call application in the background with subprocess.call

2010-04-08 Thread jorma kala
Hi, I'd like to call an external application (firefox) from a python program (a PyQT GUI), but I want the external application to run in the background, I mean I do not want my python calling program to wait till the external subprocess terminates. I've tried this: call(["firefox", "http://www.py

Re: The Regex Story

2010-04-08 Thread Tim Chase
Lie Ryan wrote: Why am I seeing a lot of this pattern lately: OP: Got problem with string +- A: Suggested a regex-based solution +- B: Quoted "Some people ... regex ... two problems." or OP: Writes some regex, found problem +- A: Quoted "Some people ... regex ... two problems." +- B: Sup

Re: How to call application in the background with subprocess.call

2010-04-08 Thread Kushal Kumaran
On Thu, Apr 8, 2010 at 7:39 PM, jorma kala wrote: > Hi, > > I'd like to call an external application (firefox) from a python program (a > PyQT GUI), but I want the external application to run in the background, I > mean I do not want my python calling program to wait till the external > subprocess

Re: Regex driving me crazy...

2010-04-08 Thread Grant Edwards
On 2010-04-08, Steven D'Aprano wrote: > Even in 2010, there are plenty of programs that export data using fixed > width fields. If you want the columns to line up as the data changes, that's pretty much the only way to go. -- Grant Edwards grant.b.edwardsYow! But was he

Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
Attempting to read a file containing Unicode characters such as ±: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 5007: ordinal not in range(128) I did succeed by converting all the characters to HTML entities such as "±", but I want the characters to be the actual font in th

Re: get objects from image

2010-04-08 Thread Chris Colbert
lookup "connected component labeling" in a machine vision book. On Thu, Apr 8, 2010 at 9:57 AM, Chris Hulan wrote: > On Apr 8, 9:17 am, Jannis Syntychakis wrote: >> Hallo Everybody, >> >> Maybe you can help me with this: >> >> i have a picture. The picture is black, with some white objects. >> >

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Martin v. Loewis
Gnarlodious wrote: > Attempting to read a file containing Unicode characters such as ±: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 5007: ordinal not in range(128) > > I did succeed by converting all the characters to HTML entities such > as "±", but I want the charact

Re: Performance of list vs. set equality operations

2010-04-08 Thread Raymond Hettinger
[Steven D'Aprano] > So what happens in my example with a subclass that (falsely) reports a > different length even when the lists are the same? > > I can guess that perhaps Py_SIZE does not call the subclass __len__ > method, and therefore is not fooled by it lying. Is that the case? Yes. Py_SIZE

Replacing Periods with Backspaces

2010-04-08 Thread Booter
All, I am trying to replace a series of periods in a sting with backspaces that way I can easily parse information from a Windows command. the current statement I have for this is ***Statement capture = re.sub('\.*', '\b', capture) ===

How to open and read an unknown extension file

2010-04-08 Thread varnikat t
I am trying to do this if os.path.exists("*.*.txt"): file=open("*.*.txt") self.text_view.get_buffer().set_text(file.read()) else: file=open("*.*.html") self.text_view.get_buffer().set_text(file.read()) It gives error *.*.txt not existingThere are

Re: python grep

2010-04-08 Thread Stefan Behnel
Mag Gam, 08.04.2010 14:21: On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel wrote: Mag Gam, 08.04.2010 13:21: I am in the process of reading a zipped file which is about 6gb. I would like to know if there is a command similar to grep in python because I would like to emulate, -A -B option of GNU

Re: How to open and read an unknown extension file

2010-04-08 Thread Kushal Kumaran
On Thu, Apr 8, 2010 at 9:00 PM, varnikat t wrote: > I am trying to do this > if os.path.exists("*.*.txt"): >             file=open("*.*.txt") >             self.text_view.get_buffer().set_text(file.read()) > else: >             file=open("*.*.html") >             self.text_view.get_buffer().set_te

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
On Apr 8, 9:14 am, "Martin v. Loewis" wrote: > When opening the file, you need to specify the file encoding. OK, I had tried this: open(path, 'r').read().encode('utf-8') however I get error TypeError: Can't convert 'bytes' object to str implicitly I had assumed a Unicode string was a Unicode

Re: fcntl, serial ports and serial signals on RS232.

2010-04-08 Thread Anssi Saari
Max Kotasek writes: > Hello to all out there, > > I'm trying to figure out how to parse the responses from fcntl.ioctl() > calls that modify the serial lines in a way that asserts that the line > is now changed. For example I may want to drop RTS explicitly, and > assert that the line has been d

Re: How to open and read an unknown extension file

2010-04-08 Thread Chris Colbert
On Thu, Apr 8, 2010 at 11:42 AM, Kushal Kumaran wrote: > On Thu, Apr 8, 2010 at 9:00 PM, varnikat t wrote: >> I am trying to do this >> if os.path.exists("*.*.txt"): >>             file=open("*.*.txt") >>             self.text_view.get_buffer().set_text(file.read()) >> else: >>             file=o

catch clipboard status in gnome

2010-04-08 Thread Tracubik
Hi all, i'ld like to create an gnome applet in python that, if left-clicked, perform a particular operation using the text of the clipboard. i've found this example: import pygtk pygtk.require('2.0') import gtk # get the clipboard clipboard = gtk.clipboard_get() # read the clipboard text data.

Re: ftp and python

2010-04-08 Thread Anssi Saari
John Nagle writes: > In theory, the FTP spec supports "three-way transfers", where the > source, destination, and control can all be on different machines. > But no modern implementation supports that. I remember even using that way back when, Unix machines in the 1990s. But, server to ser

Re: fcntl, serial ports and serial signals on RS232.

2010-04-08 Thread Grant Edwards
On 2010-04-07, Max Kotasek wrote: > I'm trying to figure out how to parse the responses from fcntl.ioctl() > calls that modify the serial lines in a way that asserts that the line > is now changed. Two comments: 1) None of the Linux serial drivers I've worked on return line states except

Re: fcntl, serial ports and serial signals on RS232.

2010-04-08 Thread Grant Edwards
On 2010-04-08, Anssi Saari wrote: > It seems to me also that RTS is always on after the port has been > opened. I didn't dig out my voltmeter or anything to check this, > though. IIRC, that's generally true: RTS and DTR are both set to "on" by the tty layer's open() handler _if_ the device's use

Re: How to open and read an unknown extension file

2010-04-08 Thread Steven Howe
On 04/08/2010 08:57 AM, Chris Colbert wrote: On Thu, Apr 8, 2010 at 11:42 AM, Kushal Kumaran wrote: On Thu, Apr 8, 2010 at 9:00 PM, varnikat t wrote: I am trying to do this if os.path.exists("*.*.txt"): file=open("*.*.txt") self.text_view.get_buffer().set_

Generating a rainbow?

2010-04-08 Thread Tobiah
I'm having a difficult time with this. I want to display a continuous range of hues using HTML hex representation (#RRGGBB). How would I go about scanning through the hues in order to make a rainbow? Thanks, Toby -- http://mail.python.org/mailman/listinfo/python-list

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Martin v. Loewis
Gnarlodious wrote: > On Apr 8, 9:14 am, "Martin v. Loewis" wrote: > >> When opening the file, you need to specify the file encoding. > > OK, I had tried this: > > open(path, 'r').read().encode('utf-8') No, when *opening* the file, you need to specify the encoding: open(path, 'r', encoding='utf

Re: Generating a rainbow?

2010-04-08 Thread Chris Colbert
On Thu, Apr 8, 2010 at 12:46 PM, Tobiah wrote: > I'm having a difficult time with this.  I want > to display a continuous range of hues using HTML > hex representation (#RRGGBB).  How would I go > about scanning through the hues in order to > make a rainbow? > > Thanks, > > Toby > -- > http://mail

Re: Generating a rainbow?

2010-04-08 Thread Richard Thomas
On Apr 8, 5:46 pm, Tobiah wrote: > I'm having a difficult time with this.  I want > to display a continuous range of hues using HTML > hex representation (#RRGGBB).  How would I go > about scanning through the hues in order to > make a rainbow? > > Thanks, > > Toby Look at the colorsys module. h

Re: Generating a rainbow?

2010-04-08 Thread Tobiah
> Look at the colorsys module. > > http://docs.python.org/library/colorsys.html?highlight=colorsys#module- colorsys That so rocks. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

How to open and read an unknown extension file

2010-04-08 Thread varnikat t
Hey, Thanks for the help.it detects now using glob.glob("*.*.txt") Can u suggest how to open and read file this way? *if glob.glob("*.*.txt"): file=open(glob.glob("*.*.txt")) self.text_view.get_buffer().set_text(file.read()) else: file=open(glob.glob("*

Re: How to open and read an unknown extension file

2010-04-08 Thread varnikat t
it gives me this error TypeError: coercing to Unicode: need string or buffer, list found On Thu, Apr 8, 2010 at 10:48 PM, varnikat t wrote: > > > > > Hey, > Thanks for the help.it detects now using glob.glob("*.*.txt") > Can u suggest how to open and read file this way? > > *if glob.glob("*.*.

Re: Generating a rainbow?

2010-04-08 Thread Gary Herron
Tobiah wrote: I'm having a difficult time with this. I want to display a continuous range of hues using HTML hex representation (#RRGGBB). How would I go about scanning through the hues in order to make a rainbow? Thanks, Toby Use the hue-saturation-value color space, and call hsv_to_r

Re: Generating a rainbow?

2010-04-08 Thread Chris Colbert
On Thu, Apr 8, 2010 at 1:14 PM, Tobiah wrote: >> Look at the colorsys module. >> >> http://docs.python.org/library/colorsys.html?highlight=colorsys#module- > colorsys > > That so rocks.  Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > How does that answer your original questi

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
On Apr 8, 11:04 am, "Martin v. Loewis" wrote: > That's because you need to re-learn some things. Apparently so, every little item is a lesson. Thank you. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing Periods with Backspaces

2010-04-08 Thread Gabriel Genellina
En Thu, 08 Apr 2010 12:26:56 -0300, Booter escribió: I am trying to replace a series of periods in a sting with backspaces that way I can easily parse information from a Windows command. the current statement I have for this is ***Statement*

Why these don't work??

2010-04-08 Thread M. Hamed
I'm trying the following statements that I found here and there on Google, but none of them works on my Python 2.5, are they too old? or newer? "abc".reverse() import numpy -- http://mail.python.org/mailman/listinfo/python-list

Re: pass object or use self.object?

2010-04-08 Thread Tim Arnold
On Apr 8, 4:20 am, Bruno Desthuilliers wrote: > Lie Ryan a écrit : > > > > > > > On 04/07/10 18:34, Bruno Desthuilliers wrote: > >> Lie Ryan a écrit : > >> (snip) > > >>> Since in function in python is a first-class object, you can instead do > >>> something like: > > >>> def process(document): >

Re: How to open and read an unknown extension file

2010-04-08 Thread Kushal Kumaran
On Thu, Apr 8, 2010 at 10:39 PM, varnikat t wrote: > Hey, > Thanks for the help.it detects now using glob.glob("*.*.txt") > Can u suggest how to open and read file this way? > > if glob.glob("*.*.txt"): >             file=open(glob.glob("*.*.txt")) >             self.text_view.get_buffer().set_tex

Re: Why these don't work??

2010-04-08 Thread nn
M. Hamed wrote: > I'm trying the following statements that I found here and there on > Google, but none of them works on my Python 2.5, are they too old? or > newer? > > "abc".reverse() > import numpy reverse does not work on strings but does work on lists: >>> x=list("abc") >>> x.reverse() >>>

Re: Why these don't work??

2010-04-08 Thread Mark Dickinson
On Apr 8, 7:10 pm, "M. Hamed" wrote: > I'm trying the following statements that I found here and there on > Google, but none of them works on my Python 2.5, are they too old? or > newer? > > "abc".reverse() This isn't valid Python in any version that I'm aware of. Where did you see it? It would

Re: Generating a rainbow?

2010-04-08 Thread Tobiah
> How does that answer your original question? I was able to do this: import colorsys sat = 1 value = 1 length = 1000 for x in range(0, length + 1): hue = x / float(length) color = list(colorsys.hsv_to_rgb(hue, sat, value)) for x in range(3): color[x] = in

Re: Why these don't work??

2010-04-08 Thread MRAB
M. Hamed wrote: I'm trying the following statements that I found here and there on Google, but none of them works on my Python 2.5, are they too old? or newer? "abc".reverse() Lists have a .reverse() method which reverses the list elements in-place, but strings don't because they're immutable.

Re: ftp and python

2010-04-08 Thread John Nagle
Anssi Saari wrote: John Nagle writes: In theory, the FTP spec supports "three-way transfers", where the source, destination, and control can all be on different machines. But no modern implementation supports that. I remember even using that way back when, Unix machines in the 1990s.

regex help: splitting string gets weird groups

2010-04-08 Thread gry
[ python3.1.1, re.__version__='2.2.1' ] I'm trying to use re to split a string into (any number of) pieces of these kinds: 1) contiguous runs of letters 2) contiguous runs of digits 3) single other characters e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain', '.', 'in', '#', '=

Re: regex help: splitting string gets weird groups

2010-04-08 Thread MRAB
gry wrote: [ python3.1.1, re.__version__='2.2.1' ] I'm trying to use re to split a string into (any number of) pieces of these kinds: 1) contiguous runs of letters 2) contiguous runs of digits 3) single other characters e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain', '.',

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Jon Clements
On 8 Apr, 19:49, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:  

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 1:49 pm, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Tim Chase
gry wrote: [ python3.1.1, re.__version__='2.2.1' ] I'm trying to use re to split a string into (any number of) pieces of these kinds: 1) contiguous runs of letters 2) contiguous runs of digits 3) single other characters e.g. 555tHe-rain.in#=1234 should give: [555, 'tHe', '-', 'rain', '.',

Re: Why these don't work??

2010-04-08 Thread M. Hamed
Thanks All. That clears alot of confusion. It seems I assumed that everything that works for lists works for strings (the immutable vs mutable hasn't sunken in yet). On the other hand (other than installing NumPy) is there a built-in way to do an array full of zeros or one just like the numpy.zero

Dynamically growing an array to implement a stack

2010-04-08 Thread M. Hamed
I have trouble with some Python concept. The fact that you can not assign to a non-existent index in an array. For example: a = [0,1] a[2] => Generates an error I can use a.append(2) but that always appends to the end. Sometimes I want to use this array as a stack and hence my indexing lo

Re: Why these don't work??

2010-04-08 Thread Emile van Sebille
On 4/8/2010 1:08 PM M. Hamed said... On the other hand (other than installing NumPy) is there a built-in way to do an array full of zeros or one just like the numpy.zeros()? I know I can do it with list comprehension (like [0 for i in range(0,20)] but these are too many keystrokes for python :) I

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread Paul McGuire
On Apr 8, 3:21 pm, "M. Hamed" wrote: > I have trouble with some Python concept. The fact that you can not > assign to a non-existent index in an array. For example: > > a = [0,1] > a[2] => Generates an error > > I can use a.append(2) but that always appends to the end. Sometimes I > want t

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:21 pm, "M. Hamed" wrote: > I have trouble with some Python concept. The fact that you can not > assign to a non-existent index in an array. For example: > > a = [0,1] > a[2] => Generates an error > > I can use a.append(2) but that always appends to the end. Sometimes I > want t

Re: Recommend Commercial graphing library

2010-04-08 Thread Giacomo Boffi
Grant Edwards writes: > If it's 2D data, you don't need to use a 3D graph. if it's tabular data, you don't need an uber-histogram -- giampippetto, coso, come si chiama? ah si` "MMAX" ha scritto: > Tra il trascendente e l'interpretazione prevalente del dato come > assioma ne passa... -- http://

Re: Why these don't work??

2010-04-08 Thread Robert Kern
On 2010-04-08 15:08 PM, M. Hamed wrote: On the other hand (other than installing NumPy) is there a built-in way to do an array full of zeros or one just like the numpy.zeros()? I know I can do it with list comprehension (like [0 for i in range(0,20)] but these are too many keystrokes for python

Re: regex help: splitting string gets weird groups

2010-04-08 Thread gry
On Apr 8, 3:40 pm, MRAB wrote: ... > Group 1 and group 4 match '='. > Group 1 and group 3 match '1234'. > > If a group matches then any earlier match of that group is discarded, Wow, that makes this much clearer! I wonder if this behaviour shouldn't be mentioned in some form in the python docs?

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Jon Clements
On 8 Apr, 19:49, gry wrote: > [ python3.1.1, re.__version__='2.2.1' ] > I'm trying to use re to split a string into (any number of) pieces of > these kinds: > 1) contiguous runs of letters > 2) contiguous runs of digits > 3) single other characters > > e.g.   555tHe-rain.in#=1234   should give:  

Re: Why these don't work??

2010-04-08 Thread Joaquin Abian
On Apr 8, 10:08 pm, "M. Hamed" wrote: > Thanks All. That clears alot of confusion. It seems I assumed that > everything that works for lists works for strings (the immutable vs > mutable hasn't sunken in yet). > > On the other hand (other than installing NumPy) is there a built-in > way to do an a

Re: python as pen and paper substitute

2010-04-08 Thread Giacomo Boffi
Manuel Graune writes: > Hello everyone, > > I am looking for ways to use a python file as a substitute for simple > pen and paper calculations. search("embedded calc mode") if manuel in emacs_fellows_set or sys.exit(1) -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating a rainbow?

2010-04-08 Thread Peter Parker
Tobiah wrote: How does that answer your original question? I was able to do this: import colorsys sat = 1 value = 1 length = 1000 for x in range(0, length + 1): hue = x / float(length) color = list(colorsys.hsv_to_rgb(hue, sat, value)) for x in range(3):

Re: regex help: splitting string gets weird groups

2010-04-08 Thread gry
>    >>> s='555tHe-rain.in#=1234' >    >>> import re >    >>> r=re.compile(r'([a-zA-Z]+|\d+|.)') >    >>> r.findall(s) >    ['555', 'tHe', '-', 'rain', '.', 'in', '#', '=', '1234'] This is nice and simple and has the invertible property that Patrick mentioned above. Thanks much! -- http://mail.py

Re: python as pen and paper substitute

2010-04-08 Thread Manuel Graune
Giacomo Boffi writes: > Manuel Graune writes: > >> Hello everyone, >> >> I am looking for ways to use a python file as a substitute for simple >> pen and paper calculations. > > search("embedded calc mode") if manuel in emacs_fellows_set or sys.exit(1) Well, the subject does say python and not

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread M. Hamed
Thanks Patrick, that is what I was exactly looking for. Paul, thanks for your example. wasn't familiar with the stack class. I feel Patrick's method is a lot simpler for my purpose. Regards. On Apr 8, 1:29 pm, Patrick Maupin wrote: > On Apr 8, 3:21 pm, "M. Hamed" wrote: > > > > > I have troubl

Re: Why these don't work??

2010-04-08 Thread M. Hamed
OMG! That's beautiful! I loved the [0]*n how simple and how it never occurred to me! Robert I agree with your comment. I feel though that since I'm not very experienced yet with Python, it's useful to learn about all those simple yet powerful methods so I can use them when I really need them. Plus

Re: regex help: splitting string gets weird groups

2010-04-08 Thread Patrick Maupin
On Apr 8, 3:40 pm, gry wrote: > >    >>> s='555tHe-rain.in#=1234' > >    >>> import re > >    >>> r=re.compile(r'([a-zA-Z]+|\d+|.)') > >    >>> r.findall(s) > >    ['555', 'tHe', '-', 'rain', '.', 'in', '#', '=', '1234'] > > This is nice and simple and has the invertible property that Patrick > me

Re: The Regex Story

2010-04-08 Thread Lie Ryan
On 4/9/10, Tim Chase wrote: > Lie Ryan wrote: >> Why am I seeing a lot of this pattern lately: >> >> OP: Got problem with string >> +- A: Suggested a regex-based solution >>+- B: Quoted "Some people ... regex ... two problems." >> >> or >> >> OP: Writes some regex, found problem >> +- A: Quote

Re: Generating a rainbow?

2010-04-08 Thread Neil Hodgson
Tobiah: > for x in range(0, length + 1): > ... > for x in range(3): You should use different variables for the two loops. Neil -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating a rainbow?

2010-04-08 Thread Neil Hodgson
Me: >You should use different variables for the two loops. Actually it is closing the divs that makes it work in FireFox: import colorsys sat = 1 value = 1 length = 1000 for h in range(0, length + 1): hue = h / float(length) color = list(colorsys.hsv_to_rgb(hue, sat, value

Re: Generating a rainbow?

2010-04-08 Thread Chris Colbert
On Thu, Apr 8, 2010 at 2:34 PM, Tobiah wrote: >> How does that answer your original question? > > I was able to do this: > > import colorsys > > sat = 1 > value = 1 > length = 1000 > for x in range(0, length + 1): >        hue = x / float(length) >        color = list(colorsys.hsv_to_rgb(hue, sat,

Pythonic list reordering

2010-04-08 Thread Ben Racine
I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic list reordering

2010-04-08 Thread Chris Rebert
On Thu, Apr 8, 2010 at 3:52 PM, Ben Racine wrote: > I have a list... > > ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', > 'dir_330_error.dat'] > > I want to sort it based upon the numerical value only. a = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.

Re: Pythonic list reordering

2010-04-08 Thread Gary Herron
Ben Racine wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. How about a one liner? L.sort(key=lambda s: int

Re: Pythonic list reordering

2010-04-08 Thread Joaquin Abian
On Apr 9, 12:52 am, Ben Racine wrote: > I have a list... > > ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', > 'dir_330_error.dat'] > > I want to sort it based upon the numerical value only. > > Does someone have an elegant solution to this? > > Thanks, > Ben R. not sure about elega

Re: lambda with floats

2010-04-08 Thread monkeys paw
On 4/7/2010 1:08 PM, Peter Pearson wrote: On Tue, 06 Apr 2010 23:16:18 -0400, monkeys paw wrote: I have the following acre meter which works for integers, how do i convert this to float? I tried return float ((208.0 * 208.0) * n) def s(n): ... return lambda x: (208 * 208) * n ... f = s

Re: lambda with floats

2010-04-08 Thread Patrick Maupin
On Apr 8, 6:06 pm, monkeys paw wrote: > On 4/7/2010 1:08 PM, Peter Pearson wrote: > > > > > On Tue, 06 Apr 2010 23:16:18 -0400, monkeys paw  wrote: > >> I have the following acre meter which works for integers, > >> how do i convert this to float? I tried > > >> return float ((208.0 * 208.0) * n)

  1   2   >