Re: Mining strings from a HTML document.
I'm battling to understand this. I am switching to python while in a production environment so I am tossed into the deep end. Python seems easier to learn than other languages, but some of the conventions still trip me up. Thanks for the link - I'll have to go through all the previous chapters to understand this one though... I suppose very few books on python start off with HTML processing in stead of 'hello world' :p Could you give me an example of how to use it to extract basic information from the web page? I need a bit of a hit-the-ground-running approach to python. You'll see that the data in my example isn't encapsulated in tags - is there still an easy way to extract it using the parser module? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to extract an item from a set of len 1
Alex Martelli wrote: Rene Pijlman [EMAIL PROTECTED] wrote: Peter Otten: s = set([one-and-only]) item, = s ... The comma may easily be missed, though. You could write: (item,) = s But I'm not sure if this introduces additional overhead. Naah...: helen:~ alex$ python -mtimeit -s's=set([23])' 'x,=s' 100 loops, best of 3: 0.689 usec per loop helen:~ alex$ python -mtimeit -s's=set([23])' '(x,)=s' 100 loops, best of 3: 0.652 usec per loop helen:~ alex$ python -mtimeit -s's=set([23])' '[x]=s' 100 loops, best of 3: 0.651 usec per loop ...much of a muchness. And that is no coincidence. All three variants are compiled to the same bytecode: import dis def a(): x, = s ... def b(): (x,) = s ... def c(): [x] = s ... dis.dis(a) 1 0 LOAD_GLOBAL 0 (s) 3 UNPACK_SEQUENCE 1 6 STORE_FAST 0 (x) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE dis.dis(b) 1 0 LOAD_GLOBAL 0 (s) 3 UNPACK_SEQUENCE 1 6 STORE_FAST 0 (x) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE dis.dis(c) 1 0 LOAD_GLOBAL 0 (s) 3 UNPACK_SEQUENCE 1 6 STORE_FAST 0 (x) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem compiling Tkinter program with bmp images using py2
[EMAIL PROTECTED] wrote: and put them on the widgets like this: Label(win, text=message, background=rgb(150,150,120), image=photo2).pack() ... Now, I want the same program to run as exe file on another computer, so I compiled it with py2exe. I copied the bmp's to the same folder as my executable. When I try to run the compiled exe i get: Traceback (most recent call last): File make_ma2.py, line 461, in ? File PIL\Image.pyo, line 1745, in open IOError: cannot identify image file (did you try googling for the error message?) Are there specific things to take care of when compiling a tkinter program with bitmap backgrounds? it's PIL that's complaining, not Tkinter. PIL uses dynamic loading of format drivers, which means that py2exe won't find them. the easiest way to fix this is to import the drivers you need in your main program; see e.g. http://starship.python.net/crew/theller/moin.cgi/PIL_20and_20py2exe /F -- http://mail.python.org/mailman/listinfo/python-list
Assigning to self.__class__
I have some places in pyparsing where I've found that the most straightforward way to adjust an instance's behavior is to change its class. I do this by assigning to self.__class__, and things all work fine. (Converting to use of __new__ is not an option - in one case, the change is temporary, and before the end of the function, I change it back again.) Any comments on this practice? Is this intended capability for Python objects, or am I taking advantage of a fortuitous accident, which may get undone at a future time? -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning to self.__class__
Paul McGuire wrote: I have some places in pyparsing where I've found that the most straightforward way to adjust an instance's behavior is to change its class. Hooray ! You've just (re)discovered the state pattern... for which the most stupid simple implementation in Python is to : (snip) assigning to self.__class__, (snip) !-) Any comments on this practice? It can be very confusing for newbies and peoples having no experience with *dynamic* languages, and I guess control-freaks and static-typing-addicts would runaway screaming. But I like it anyway !-) Is this intended capability for Python objects, AFAIK, yes. or am I taking advantage of a fortuitous accident, which may get undone at a future time? It's certainly not a fortuitous accident. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Fred wrote: I hope someone can help me with the below problem... Thanks, Fred My enviroment: -- Slackware Linux 10.2 Python 2.4.2 MySql version 4.1.14 MySql-Python 1.2.0 What I am trying to do: --- Using MySQL, Python, My-Sql-Python module and CGI create a simple database that can be accesed with a webpage. Everything worked great up to this error when trying to load the webpage: ImportError: No module name MySQLdb Note that I do NOT get the error when running the script normally from Python. So I'd say it has something to do with sys.path Is there anything non-standard with your config ? Like modules installed as a user and/or outside of /usr/lib/pythonXXX/site-packages/ ? I have read much but can not seem to nail the problem down, I am thinking a path error. +1 add this at the beginning of your script, *before* trying to import anything else. import sys print sys.path is, sys.path (snip code) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning to self.__class__
bruno at modulix wrote: Paul McGuire wrote: or am I taking advantage of a fortuitous accident, which may get undone at a future time? It's certainly not a fortuitous accident. And even the (printed) cookbook has examples which assign to self.__class__... I guess this means this feature isn't going to go away soo. ;-) --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
history
Dear all, another little question, I use idle 1.1.2, is there a way to use a history for the command line? thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: good library for pdf
Take a look at www.reportlab.org. The ReportLab library includes a graphics module that might well do what you need. I'm not sure at present if it allows one to set alpha-channels to achieve transparency. Also, if you have access to a mac running OS X 10.4, the Automator application has a prebuilt action that applies a watermark to pdfs. Transparency, size and placement are all editable. Obviously, no use if you want to do this with Python, but it might suit your needs. Rob C -- http://mail.python.org/mailman/listinfo/python-list
good library for pdf
Hi all, I want to take an existing pdf and add it a non-opaque watermark. I have tried it in postscript but postscript hava an opaque imaging model. Pdf allows it. I can do it with acrobat 6.0, but i need to add the watermark in batch mode or inside an application. I've found lowagie library for java. Anyone knows if there is something similar for python?? must i begin to learn java?? Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Mining strings from a HTML document.
Runsun Pan helped me out with the following: You can also try the following very primitive solution that I sometimes use to extract simple information in a quick and dirty way: def extract(text,s1,s2): ''' Extract strings wrapped between s1 and s2. t=this is a spantest/span for spanextract()/span that spandoes multiple extract/span extract(t,'span','/span') ['test', 'extract()', 'does multiple extract'] ''' beg = [1,0][text.startswith(s1)] tmp = text.split(s1)[beg:] end = [len(tmp), len(tmp)+1][ text.endswith(s2)] return [ x.split(s2)[0] for x in tmp if len(x.split(s2))1][:end] This will help out a *lot*! Thank you. This is a better bet than the parser in this particular implementation because the data I need is not encapsulated in tags! Field names are within b/b tags followed by plain text data and ended with a br tag. This was my main problem with a parser, but your extract fuction solves it beautifully! I'm posting back to the NG in just in case it is of value to anyone else. Could you/anyone explain the 4 lines of code to me though? A crash course in Python shorthand? What does it mean when you use two sets of brackets as in : beg = [1,0][text.startswith(s1)] ? Thanks for the help! -d- -- http://mail.python.org/mailman/listinfo/python-list
Re: good library for pdf
Rob Cowie wrote: Take a look at www.reportlab.org. The ReportLab library includes a graphics module that might well do what you need. I'm not sure at present if it allows one to set alpha-channels to achieve transparency. ReportLab allows one to set a transparent image colour mask which is equivalent to transparency. I believe this isn't yet implemented for jpeg. You can also use an auto mask to get the transparency info from those image formats which support it. Also, if you have access to a mac running OS X 10.4, the Automator application has a prebuilt action that applies a watermark to pdfs. Transparency, size and placement are all editable. Obviously, no use if you want to do this with Python, but it might suit your needs. Rob C -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: How to handle two-level option processing with optparse
R. Bernstein wrote: Giovanni Bajo suggests: If you call OptionParser.disable_interspersed_args() on your parser, it will stop parsing at the first positional argument, leaving other options unparsed. Wow - that was a quick answer! Thanks - it works great! I see how I missed this. Neither disable_.. or enable_.. have document strings. And neither seem to described in the optparser section (6.21) of the Python Library (http://docs.python.org/lib/module-optparse.html). I wonder if something like this might be added to the Python Cookbook. Well you are just as capable of adding it as anyone else, so knock yourself out! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Fred wrote: I hope someone can help me with the below problem... Thanks, Fred My enviroment: -- Slackware Linux 10.2 Python 2.4.2 MySql version 4.1.14 MySql-Python 1.2.0 What I am trying to do: --- Using MySQL, Python, My-Sql-Python module and CGI create a simple database that can be accesed with a webpage. Everything worked great up to this error when trying to load the webpage: ImportError: No module name MySQLdb I hesitate to offer what seems like a simplistic solution: are the web browser and the server running on the same computer? Normally when you install MySQLdb it will install inside the site-packages directory, and so would be available to scripts whether they were run from a command line or a web CGI script. I therefore suspect you need to repeat the installation of MySQLdb on your server machine. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
While loop - print several times but on 1 line.
Hello there. I'm creating a little text changer in Python. In the program there is a while loop. The problem is that a while loop will have 1 print statement and it will loop until it gets to the end of the text. Example: num = 5 // Set num to 5 while num = 1: // loop 5 times. print text num = num-1 // end. The programs output will be: text text (etc) How could I make this print: texttexttexttexttext? Ive researched and looked through google and so far I can't find anything that will help (or revelent for that matter). Thanks for looking. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code written in 1998, how to improve/change it?
On Wed, 25 Jan 2006 15:50:27 -0600, [EMAIL PROTECTED] wrote: If they need to resume their calculations from where they left off after the last yield. Wolfgang Well, no, independently from that. Wolfgang Just to avoid to inital overhead of the function call. How do you pass in parameters? Consider: def square(x): return x*x vs def square(x) while True: yield x*x How do you get another value of x into the generator? def square(x): ... while True: ... yield x*x ... g = square(2) g generator object at 0x3b9d28 g.next() 4 g.next() 4 g.next(3) Traceback (most recent call last): File stdin, line 1, in module TypeError: expected 0 arguments, got 1 def square(xbox): ... while True: yield xbox[0]*xbox[0] ... xbox = [3] g = square(xbox) g.next() 9 xbox[0]=4 g.next() 16 [g.next() for xbox[0] in xrange(10)] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] One way to answer your question literally, whatever it may do to your gag reflex ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: Hello there. I'm creating a little text changer in Python. In the program there is a while loop. The problem is that a while loop will have 1 print statement and it will loop until it gets to the end of the text. Example: num = 5 // Set num to 5 while num = 1: // loop 5 times. print text num = num-1 // end. Don't use while for that, this is considered unpythonix. Use a for-loop with xrange instead. If you need the nums in that order, use xrange with a negative step: Use sys.stdout.write: import sys for i in xrange(num, 0, -1): sys.stdout.write(text) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: good library for pdf
Enrique Palomo Jiménez wrote: Hi all, I want to take an existing pdf and add it a non-opaque watermark. I have tried it in postscript but postscript hava an opaque imaging model. Pdf allows it. I can do it with acrobat 6.0, but i need to add the watermark in batch mode or inside an application. I've found lowagie library for java. Anyone knows if there is something similar for python?? must i begin to learn java?? Regards For what it's worth, if you use PostScript correctly there will be no need to migrate to PDF (though it can have advantages). PostScript doesn't have an opaque imaging model at all. You can define arbitrary paths, and draw on top of existing graphics. Problems may occur if you want your watermark to appear behind your main content if the main content draws with an opaque background (because that would obscure the watermark and render it invisible), but that's nothing to do with PostScript per se, so you might be trying to walk a hundred miles when a trip round the corner would do. The ReportLab functionality (PageCatcher) to read existing PDFs and incorporate them as a part of other PDF documents is not, unfortunately, a part of the open source toolkit. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: snip As a shortcut: print text*5 --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
Steven D'Aprano wrote: Of course. I was just trying to make a point about string accumulation being O(n) and not O(n^2). But according to Fredrik, string accumulation is still quadratic, even with the optimizations added to Python 2.4. Quoting: it only means that if the interpreter can make sure that else is using the target string, it's modified in place. however, the string type doesn't use overallocation (beyond the 8-byte alignment provided by the memory allocator), so this fix only avoids extra copying in a few specific cases. O(n*n/8) is still quadratic... I presume Fredrik meant to say nothing else. correct. the only way to get amortized O(n) behaviour is by adding small strings to the end of a larger string, and hope that the memory allocator can satisfy all reallocations without too much copying. the list implementation, in contrast, uses controlled overallocation and can therefore guarantee amortized O(n) even if realloc always fails to reallocate in place. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: How could I make this print: texttexttexttexttext? Ive researched and looked through google and so far I can't find anything that will help (or revelent for that matter). I am not quite sure, if I simplify the problem but i thought about something like that: print text*5 texttexttexttexttext cheers Stefan pgp470Yem6sNX.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
I think I should paste some of the programs code a little more of what I want... var = 0 while var = 5: print a[t[var]] var = var +1 a is a dectionary (very big) and t is a string of text. (if that's important right now). I'm just trying to make the value of a[t[var]] print on one line if that makes any sense... Sorry if I'm not explaining this very well and if my examples aren't very good, I am trying. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: I think I should paste some of the programs code a little more of what I want... var = 0 while var = 5: print a[t[var]] var = var +1 a is a dectionary (very big) and t is a string of text. (if that's important right now). I'm just trying to make the value of a[t[var]] print on one line if that makes any sense... Sorry if I'm not explaining this very well and if my examples aren't very good, I am trying. I mean that what you are looking for is: print a[t[var]], Notice the last comma in the line above. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Great! It's been solved. The line, as Glaudio said has a , at the end and that makes it go onto one line, thanks so much man! var = 0 while = 5: print a[t[var]], var = var +1 prints perfectly, thanks so much guys. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: I think I should paste some of the programs code a little more of what I want... var = 0 while var = 5: print a[t[var]] var = var +1 a is a dectionary (very big) and t is a string of text. (if that's important right now). I'm just trying to make the value of a[t[var]] print on one line if that makes any sense... if you don't want print's behaviour, you can print directly to the stdout stream: import sys for var in range(5): sys.stdout.write(a[t[var]]) write only accepts strings, so if the dictionary may contain other stuff, you need to use the str() function to convert the data on the way out: for var in range(5): sys.stdout.write(str(a[t[var]])) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: Great! It's been solved. The line, as Glaudio said has a , at the end and that makes it go onto one line, thanks so much man! var = 0 while = 5: print a[t[var]], var = var +1 prints perfectly, thanks so much guys. if you wanted spaces between the items, why didn't you say that ? How could I make this print: texttexttexttexttext? for i in range(5): ... print text ... text text text text text for i in range(5): ... print text, ... text text text text text import sys for i in range(5): ... sys.stdout.write(text) ... texttexttexttexttext oh well. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: ZODB and Zope on one Linux machine, how?
Terry Hancock: Rene Pijlman: Option 1: Install ZODB in the Python installation in the usual way. Should I expect problems when I install and run zope with that Python installation? I think this should work, actually. ZODB is just like other databases in that each application is going to make its own database. That is, there is a different top-level object. At least I think this is true. The databases will be separate of course. But I'd expect namespace conflicts with two ZODB's being installed when starting Zope (one in Python's site-packages, one in Zope's lib/python). ZODB's README says: This version of ZODB can be used with Zope 2.7.3 or later, but you must replace the version of ZODB that comes packaged with Zope. It should be possible, for example, to install this code into a Zope 2.7 software home. But I'm not quite sure how that would work. Also, should be possible leaves room for doubt :-) -- René Pijlman Wat wil jij worden? http://www.carrieretijger.nl -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny [EMAIL PROTECTED] wrote: The programs output will be: text text (etc) How could I make this print: texttexttexttexttext? Ive researched and looked through google and so far I can't find anything that will help (or revelent for that matter). I'm kind of surprised this isn't a FAQ (if it's in the FAQs, I can't find it). http://docs.python.org/tut/node5.html#SECTION00520 tells you how to use print text, # Note the comma. Oh, and the correct comment character. to get text text text text text http://docs.python.org/tut/node9.html#SECTION00910 hints that what you want may be sys.stdout.write(text) to get texttexttexttexttext Beware that in either case you'll need an additional print at the end of the loop to get the final newline back. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: Great! It's been solved. The line, as Glaudio said has a , at the end and that makes it go onto one line, thanks so much man! var = 0 while = 5: print a[t[var]], var = var +1 prints perfectly, thanks so much guys. Looping over indexes is kinda unpythonic in its own right. Is there something magical about the number 5? for e in t: print a[e], -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: I think I should paste some of the programs code a little more of what I want... probably... var = 0 while var = 5: print a[t[var]] var = var +1 a is a dectionary (very big) and t is a string of text. (if that's important right now). It might be important... I'm just trying to make the value of a[t[var]] print on one line if that makes any sense... Sorry if I'm not explaining this very well and if my examples aren't very good, I am trying. If I understand correctly, you have - a dict 'a' which may look like this: a = {'a': 1, 'b' : 2, 'c' : 3, #etc 'z' : 26 } that is, keys of this dict are one-letter-strings (we dont actually care what the real values are, enough to know that it's what you want to print out). - a string 't' which may look like this : t = 'abcdefghijklmnopqrstuvwxyz' And you want to print someting like: 12345 (that is, the dict values which have one of the 5 fisrt letters of t as keys) Is that what you actually want ? -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting date to milliseconds since 1-1-70
NateM wrote: Thank you! If I am reading in dates as strings from a text file, like 5/11/1998, how do I convert that to a format I can pass into mktime? Thanks again. Check time.strptime() -- http://mail.python.org/mailman/listinfo/python-list
en la misma linea
Hola, Aca con una pregunta basica: A veces veo que hay programas que tienen varias instrucciones en la misma linea, cuando lo que aprendi de Python era que se usaba el espaciado para mantener la estructura (indent). Por ejemplo: if name != 'comic': return Hay un return despues de los dos puntos, no se que significa. -- Bioinformatics news: http://www.bioinformatica.info Lriser: http://www.linspire.com/lraiser_success.php?serial=318 -- http://mail.python.org/mailman/listinfo/python-list
isplit
I have a file of lines that contains some extraneous chars, this the basic version of code to process it: IDtable = .join(map(chr, xrange(256))) text = file(..., rb).read().translate(IDtable, toRemove) for raw_line in file(file_name): line = raw_line.translate(IDtable, toRemove) ... A faster alternative: IDtable = .join(map(chr, xrange(256))) text = file(file_name).read().translate(IDtable, toRemove) for line in text.split(/n): ... But text.split requires some memory if the text isn't small. Probably there are simpler solutions (solutions with the language as it is now), but one seems the following, an: str.isplit() or str.itersplit() or str.xsplit() Like split, but iterative. (Or even making str.split() itself an iterator (for Py3.0), and str.listsplit() to generate lists.) (At the moment a simple RE can probably work as the isplit.) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Re-reading my message I noticed a stupid error, not effecting my problem but annoying, I assigned variables and then did not use them, then included import cgi for my regular script. This is how the command line script should look: #!/usr/bin/python import MySQLdb db=MySQLdb.connect(host = '192.168.0.112', db = 'phone') cursor=db.cursor() cursor.execute(Select * from phone) result = cursor.fetchall() for record in result: print record[0],record[1],record[2] -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Jeffrey Schwab wrote: Danny wrote: Great! It's been solved. The line, as Glaudio said has a , at the end and that makes it go onto one line, thanks so much man! var = 0 while = 5: print a[t[var]], var = var +1 prints perfectly, thanks so much guys. Looping over indexes is kinda unpythonic in its own right. Is there something magical about the number 5? for e in t: print a[e], Or if you want to just iterate over a part of t: start = 0 end = 6 # end is not included for e in t[start:end]: print a[e]* -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
This is the result of print sys.path: print sys.path ['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages'] MySQLdb lives here but is not in the path: /usr/local/lib/python2.4/site-packages/MySQLdb Everything is running on the same machine here in my house, everything was installed and is launched as root. Thanks. Fred -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Here is the complete error from my Apache error log: Traceback (most recent call last): File /var/www/cgi-bin/mysqld_script_test.py, line 7, in ? import MySQLdb ImportError: No module named MySQLdb [Thu Jan 26 07:25:16 2006] [error] [client 127.0.0.1] malformed header from script. Bad header=['/var/www/cgi-bin', '/usr/lib: /var/www/cgi-bin/mysqld_script_test.py -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
From what I can tell everything seems right. Here are the results of the sys.path: print sys.path ['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux2', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages'] MySQLdb lives here: /usr/local/lib/python2.4/site-packages/MySQLdb but is not in the path I installed and am trying to run everything as root, and it is all on the same computer right here with me. If I can ever get this simplistic problem solved maybe you guys can help me to get Zope running, it is not cooperating either... :-) Fred -- http://mail.python.org/mailman/listinfo/python-list
Nitpicking - slightly misleading traceback
if ((data[x][y] 0) or (datadict.has_key[key])): Traceback (most recent call last): File reduce.py, line 524, in remove_badvalues if ((data[x][y] 0) or TypeError: unsubscriptable object However, the bug sits on the next line. I used square brackets when normal brackets were needed - should have written datadict.has_key(key) as the old code had datadict[key]. In the real code variable names are so long that I must split the line. I feel the traceback is misleading. I guess the best solution is to write code without bugs... -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert a long XML string into indented format
Jim wrote: You want to pretty print. Have a look at http://www.boddie.org.uk/python/XML_intro.html for example. Thank you to Paul, I've found that page useful, Let me know if there's anything else that you think it should cover! After updating the HTML parsing page and rediscovering some things (I'd forgotten that PyXML supported HTML parsing, for example), it could well be the case that the XML introduction needs some modernising, too. Still, both documents are like reminders of forgotten Python library functionality. ;-) Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Fred wrote: Here is the complete error from my Apache error log: Traceback (most recent call last): File /var/www/cgi-bin/mysqld_script_test.py, line 7, in ? import MySQLdb ImportError: No module named MySQLdb [Thu Jan 26 07:25:16 2006] [error] [client 127.0.0.1] malformed header from script. Bad header=['/var/www/cgi-bin', '/usr/lib: /var/www/cgi-bin/mysqld_script_test.py I think you can ignore this error: it's happening because of your debug output of syst.path, which presumably takes place before the script prints out Content-Type: text/html or similar. If your program doesn't do that it'll likely not produce what you expect anyway. Finally, you might want to think about adding import cgitb; cgitb.enable() to your existing scripts. This will give you a much more acceptable traceback from web conditions. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Mining strings from a HTML document.
In article [EMAIL PROTECTED], Derick van Niekerk [EMAIL PROTECTED] wrote: . . . I suppose very few books on python start off with HTML processing in stead of 'hello world' :p . . . ... very few, perhaps, but how many do you need when the one example is so strong? In any case, you'll want to look into *Text Processing in Python* URL: http://gnosis.cx/TPiP/ . -- http://mail.python.org/mailman/listinfo/python-list
Match First Sequence in Regular Expression?
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Does such a regular expression exist? If so, any ideas as to what it could be? -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Hello Roger, I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. import sys, re, os if __name__=='__main__': m = re.search('a{3}', 'xyz123aaabbaaaabaaabb') print m.group(0) print Preceded by: \ + m.string[0:m.start(0)] + \ Best wishes, Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Nitpicking - slightly misleading traceback
Juho Schultz enlightened us with: However, the bug sits on the next line. [...] I feel the traceback is misleading. Well, the bug sits in the command starting on the line indicated. Nitpick back: Learn about operator precedence and Python syntax rules. You don't need so many brackets: if data[x][y] 0 or datadict.has_key(key): This might even make things fit on one line again ;-) Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Roger L. Cauvin enlightened us with: I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Your request is ambiguous: 1) You're looking for the first, and only the first, sequence of the letter 'a'. If the length of this first, and only the first, sequence of the letter 'a' is not 3, no match is made at all. 2) You're looking for the first, and only the first, sequence of length 3 of the letter 'a'. What is it? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
replacing \n characters in a hash
Hello, I am currently trying to write some scripts to get information from the xmlrpc for redhat network. One of the issues I am having is trying to strip off the special characters in the hash that is returned. Here is an example of the information returned within the hash : ===SNIP=== {'errata_update_date': '2005-12-06', 'errata_topic': 'Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team.', 'errata_type': 'Security Advisory', 'errata_notes': '', 'errata_synopsis': 'Moderate: libc-client security update', 'errata_references': '', 'errata_last_modified_date': '2006-01-25 10:37:24', 'errata_issue_date': '2005-12-06', 'errata_description': 'C-client is a common API for accessing mailboxes.\n\nA buffer overflow flaw was discovered in the way C-client parses user\nsupplied mailboxes. If an authenticated user requests a specially crafted\nmailbox name, it may be possible to execute arbitrary code on a server that\nuses C-client to access mailboxes. The Common Vulnerabilities and Exposures\nproject has assigned the name CVE-2005-2933 to this issue.\n\nAll users of libc-client should upgrade to these updated packages, which\ncontain a backported patch that resolves this issue.'} ===SNIP=== What I would like to do is remove the \n characters from 'errata_topic'. Which is this section of the hash. Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team. What I had attempted to do is use the replace() function but it consistantly comes up with the following errors: Traceback (most recent call last): File rhn_errata.py, line 63, in ? errata_package = errata_package.strip('\n','') AttributeError: 'dict' object has no attribute 'strip' where errata_package is JUST the errata_topic hash value. Any advice would be great on how to do that. Regards, Johhny -- http://mail.python.org/mailman/listinfo/python-list
Re: Possible memory leak?
The times that I posted was the time that it took to perform ONE row iteration. As you can see, the time was going up, fairly dramatically. Why on earth could it be doing this? I understand the the time will fluctuate somewhat depending upon what else the CPU is doing, but, why is the base time increasing so much for one machine doing something one way, and not for another machine appearently identically configured doing the same operation? That is the great question I have. Still, it seems as though it cannot be solved as to why its doing this. The only thing I can think of that might be different is perhaps these results came off of a slightly newer version of python. One great problem is the data is read in streamlining, ei, the data enters this function as a list (Or tuple, I always mix those two up, but the one that uses []'s. not ()'s). Oh well, the solution will come, eventually. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list
Re: www.mywebsite.py
Simon Brunning wrote: On 1/24/06, Cyril Bazin [EMAIL PROTECTED] wrote: Does someone ever tried (and succeed) to make an address like www.website.py. I found that the .py extension is given to the paraguay. I found this link ( http://www.nic.py/) but I don't speak spanish... If someone has more informations... Last time I saw, the domains were very expension (about $500) and only available to those resident in Paraguay... :-( All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
sockets programming with python on mobile phones
Hi everyone, Is it possible to write applications using sockets for network programming on MOBILE Phones( using Python on mobile phones such as nokia 66* series ) actually i want my mobile to 'TALK' to my pc 'WIRELESSLY' so i can send data between the two I think it works over the GPRS stack. PLEASE PLEASE help it is crucial for my major project and my guide dont have much(actually any) idea on this Thank You. -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Does such a regular expression exist? If so, any ideas as to what it could be? I'm not quite sure what your intent here is, as the resulting find would obviously be aaa, of length 3. If you mean that you want to test against a number of things, and only find items where aaa is the first a on the line, you might try something like import re listOfStringsToTest = [ 'helloworld', 'xyz123aaabbaabababbab', 'cantalopeaaabababa', 'baabbbaaab', 'xyzaa123aaabbabbabababaa'] r = re.compile([^a]*(a{3})b+(a+b+)*) matches = [s for s in listOfStringsToTest if r.match(s)] print repr(matches) If you just want the *first* triad of aaa, you can change the regexp to r = re.compile(.*?(a{3})b+(a+b+)*) With a little more detail as to the gist of the problem, perhaps a better solution can be found. In particular, are there items in the listOfStringsToTest that should be found but aren't with either of the regexps? -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: history
yqyq22 wrote: Dear all, another little question, I use idle 1.1.2, is there a way to use a history for the command line? Cursor up to a previously entered line and hit return. The line will be repeated, allowing editing. If the line was an entire block, the entire block will be repeated. thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
On Thu, 2006-01-26 at 09:24, Johhny wrote: Hello, I am currently trying to write some scripts to get information from the xmlrpc for redhat network. One of the issues I am having is trying to strip off the special characters in the hash that is returned. Here is an example of the information returned within the hash : ===SNIP=== {'errata_update_date': '2005-12-06', 'errata_topic': 'Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team.', [...] What I had attempted to do is use the replace() function but it consistantly comes up with the following errors: Traceback (most recent call last): File rhn_errata.py, line 63, in ? errata_package = errata_package.strip('\n','') AttributeError: 'dict' object has no attribute 'strip' where errata_package is JUST the errata_topic hash value. errata_package is obviously not just the errata_topic hash value, because that would be a string, and python for some reason seems to believe that errata_package is a dictionary. Also note that once you correct that problem, python will complain that strip() doesn't take 2 parameters, since you actually mean replace(). -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Nitpicking - slightly misleading traceback
Sybren Stuvel [EMAIL PROTECTED] wrote: ... if data[x][y] 0 or datadict.has_key(key): This might even make things fit on one line again ;-) Particularly if you code it idiomatically: if data[x][y] 0 or key in datadict: Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning to self.__class__
Heiko Wundram [EMAIL PROTECTED] wrote: bruno at modulix wrote: Paul McGuire wrote: or am I taking advantage of a fortuitous accident, which may get undone at a future time? It's certainly not a fortuitous accident. And even the (printed) cookbook has examples which assign to self.__class__... I guess this means this feature isn't going to go away Hmmm, I'm the main decision-maker for what goes in the printed cookbook, but it's Guido who decides what stays or goes in the language, and it's not as if we always agree (though I will admit that when we disagree it later usually turns out he's right, but that's another issue;-). Still, in this case I don't think we disagree!-) Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, Thankyou for your response, If I check that the errara_package value is with a print I get the following. ===SNIP=== Updated libc-client packages that fix a buffer overflow issue are now available. This update has been rated as having moderate security impact by the Red Hat Security Response Team. ===SNIP=== Notice that it has formatted the output with the \n's. So i dont understand why its reporting as a dictionary rather than just the string. -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Tim Chase [EMAIL PROTECTED] wrote: ... I'm not quite sure what your intent here is, as the resulting find would obviously be aaa, of length 3. But that would also match ''; I think he wants negative loobehind and lookahead assertions around the 'aaa' part. But then there's the spec about matching only if the sequence is the first occurrence of 'a's, so maybe he wants '$[^a]*' instead of the lookbehind (and maybe parentheses around the 'aaa' to somehow 'match' is specially?). It's definitely not very clear what exactly the intent is, no... Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Pulling numbers from ASCII filename not working
On Thu, 26 Jan 2006 06:39:20 GMT in comp.lang.python, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On 25 Jan 2006 12:42:20 -0800, IamIan [EMAIL PROTECTED] declaimed the following in comp.lang.python: [...] I tried print repr(filename) and it returned the actual filename: 'n16w099.asc' , 'n17w062.asc' , etc. You may have problems with the longitude... those leading zeroes may be taken as Octal notation... Shouldn't be a problem unless you make it one. Int defaults to decimal, unless you specify a base or tell it to infer the base from the number format by specifying a base of zero. a = int(062) a 62 a = int(062,0) a 50 Hard to interpret 099 as an octal number in any case: a = int(099,0) Traceback (most recent call last): File pyshell#59, line 1, in -toplevel- a = int(099,0) ValueError: invalid literal for int(): 099 Regards, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
On Thu, 2006-01-26 at 09:49, Johhny wrote: Hello, Thankyou for your response, If I check that the errara_package value is with a print I get the following. ===SNIP=== Updated libc-client packages that fix a buffer overflow issue are now available. This update has been rated as having moderate security impact by the Red Hat Security Response Team. ===SNIP=== Notice that it has formatted the output with the \n's. So i dont understand why its reporting as a dictionary rather than just the string. Posting relevant bits of your code might help. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Mining strings from a HTML document.
Derick van Niekerk wrote: Could you/anyone explain the 4 lines of code to me though? A crash course in Python shorthand? What does it mean when you use two sets of brackets as in : beg = [1,0][text.startswith(s1)] ? It's not as strange as it looks. [1,0] is a list. If you put [] after a list, it's for indexing, right? (Unless there's one or two ':' somehere, in which case it's slicing.) text.startswith(s1) evaluates to True or False, which is equivalent to 1 or 0 in a numerical context. [1,0][0] is 1, and [1,0][1] is 0, so you could say that it's a somewhat contrieved way of writing beg = int(not text.startswith(s1)) or beg = 1 - text.startswith(s1) -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Fred wrote: Slackware Linux 10.2 Heh, Slackware was my first Linux distro. Version 2.2 I think. 1993 maybe? Everything worked great up to this error when trying to load the webpage: ImportError: No module name MySQLdb Some suggestions: Start python interactively and try import MySQLdb. Stuff in a subdirectory to site-packages are normally available. If this doesn't work, it seems something is fishy with your MySQLdb install, provided you are using it right. There might be an __init__.py missing or something, but this is a mature product which ought to have a stable install procedure. If things work interactively, but not in the CGI script, you might want to add import sys print sys.path to your CGI script and see what that gives you. Finally, the cgitb module is pretty useful. I suggest that you look it up: http://docs.python.org/lib/module-cgitb.html -- http://mail.python.org/mailman/listinfo/python-list
Re: How to handle two-level option processing with optparse
R. Bernstein wrote: I see how I missed this. Neither disable_.. or enable_.. have document strings. And neither seem to described in the optparser section (6.21) of the Python Library (http://docs.python.org/lib/module-optparse.html). http://docs.python.org/lib/optparse-other-methods.html -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
Magnus Lycka wrote: Fred wrote: Slackware Linux 10.2 Heh, Slackware was my first Linux distro. Version 2.2 I think. 1993 maybe? I have been using Slackware since 1995, version 3.0 kernel 1.2.13 Some suggestions: Finally, the cgitb module is pretty useful. I suggest that you look it up: http://docs.python.org/lib/module-cgitb.html Will check it out... I bet this is something really simple and possibly related to my use of Slackware, although hours of searching has not produced an answer.. Fred -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, Here is the code (minus my details section). server = xmlrpclib.ServerProxy(url) session = server.auth.login(username,password) #functions. def getErrata(): channel_label = 'rhel-i386-as-4' errata = server.channel.software.list_errata(session,channel_label,start_date,end_date) return errata def getPackage(advisory): Package = server.errata.get_details(session,advisory) return Package errata = getErrata() for vals in errata: print %s\t\t%s\t\t%s\t%s\t%s % (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'],) errata_info = getPackage(vals['errata_advisory'],) print errata_info['errata_topic'] errata_package = errata_info['errata_topic'] print getPackage(vals['errata_advisory']) I have not got any of the section in to replace the \n's as I was trying to work out why its not seeing what I thought was a string as a dict. -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Johhny wrote: Hello, I am currently trying to write some scripts to get information from the xmlrpc for redhat network. One of the issues I am having is trying to strip off the special characters in the hash that is returned. Here is an example of the information returned within the hash : ===SNIP=== {'errata_update_date': '2005-12-06', 'errata_topic': 'Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team.', 'errata_type': 'Security Advisory', 'errata_notes': '', 'errata_synopsis': 'Moderate: libc-client security update', 'errata_references': '', 'errata_last_modified_date': '2006-01-25 10:37:24', 'errata_issue_date': '2005-12-06', 'errata_description': 'C-client is a common API for accessing mailboxes.\n\nA buffer overflow flaw was discovered in the way C-client parses user\nsupplied mailboxes. If an authenticated user requests a specially crafted\nmailbox name, it may be possible to execute arbitrary code on a server that\nuses C-client to access mailboxes. The Common Vulnerabilities and Exposures\nproject has assigned the name CVE-2005-2933 to this issue.\n\nAll users of libc-client should upgrade to these updated packages, which\ncontain a backported patch that resolves this issue.'} ===SNIP=== What I would like to do is remove the \n characters from 'errata_topic'. Which is this section of the hash. Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team. What I had attempted to do is use the replace() function but it consistantly comes up with the following errors: Traceback (most recent call last): File rhn_errata.py, line 63, in ? errata_package = errata_package.strip('\n','') AttributeError: 'dict' object has no attribute 'strip' where errata_package is JUST the errata_topic hash value. Any advice would be great on how to do that. Regards, Johhny You must use 'errata_topic' as index into your dictionary to get the string and then replace the \n chars. Example assumes that the dict is pointed to by d): errata_topic_text=d['errata_topic'].replace('\n',' ') Hope this helps. Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Christoph Conrad [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello Roger, I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. import sys, re, os if __name__=='__main__': m = re.search('a{3}', 'xyz123aaabbaaaabaaabb') print m.group(0) print Preceded by: \ + m.string[0:m.start(0)] + \ The correct pattern should reject the string: 'xyz123aabbaaab' since the length of the first sequence of the letter 'a' is 2. Yours accepts it, right? -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Using non-ascii symbols
On Thu, 26 Jan 2006 01:12:10 -0600 Runsun Pan [EMAIL PROTECTED] wrote: For the tests that I tried earlier, using han characters as the variable names doesn't seem to be possible (Syntax Error) in python. I'd love to see if I can use han char for all those keywords like import, but it doesn't work. Yeah, I'm pretty sure we're talking about the future here. :-) That depends. People with ages in the middle or older probably have very rare experience of typing han characters. But with the popularity of computer as well as the development of excellent input packages, and most importantly, the online-chats that many teenagers hooking to, next several geneartions can type han char easily and comfortably. That's interesting. I think many people in the West tend to imagine han/kanji characters as archaisms that will disappear (because to most Westerners they seem impossibly complex to learn and use, not suited for the modern world). I used to think this was likely, although I always thought the characters were beautiful, so it would be a shame. After taking a couple of semesters of Japanese, though, I've come to appreciate why they are preferred. Getting rid of them would be like convincing English people to kunvurt to pur fonetik spelin'. Which isn't happening either, I can assure you. ;-) One thing that is lack in other languages is the phrase input almost every han input package provides this customizable feature. With all these combined, many of youngesters can type as fast as they talk. I believe many of them input han characters much faster than inputting English. I guess this is like Canna/SKK server for typing Japanese. I've never tried to localize my desktop to Japanese (and I don't think I want to -- I can't read it all that well!), but I've used kanji input in Yudit and a kanji-enabled terminal. I'm not sure I understand how this works, but surely if Python can provide readline support in the interactive shell, it ought to be able to handle phrase input/kanji input. Come to think of it, you probably can do this by running the interpreter in a kanji terminal -- but Python just doesn't know what to do with the characters yet. The side effect of this technology advance might be that in the future the simplified chinese characters might deprecate, 'cos there's no need to simplify any more. Heh. I must say the traditional characters are easier for *me* to read. But that's probably because the Japanese kanji are based on them, and that's what I learned. I never could get the hang of grass hand or the cursive Chinese han character style. I would like to point out also, that as long as Chinese programmers don't go hog wild and use obscure characters, I suspect that I would have much better luck reading their programs with han characters, than with, say, the Chinese phonetic names! Possibly even better than what they thought were the correct English words, if their English isn't that good. Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Alex Martelli [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Tim Chase [EMAIL PROTECTED] wrote: ... I'm not quite sure what your intent here is, as the resulting find would obviously be aaa, of length 3. But that would also match ''; I think he wants negative loobehind and lookahead assertions around the 'aaa' part. But then there's the spec about matching only if the sequence is the first occurrence of 'a's, so maybe he wants '$[^a]*' instead of the lookbehind (and maybe parentheses around the 'aaa' to somehow 'match' is specially?). It's definitely not very clear what exactly the intent is, no... Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Hope that's clearer . . . . -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Johhny wrote: for vals in errata: print %s\t\t%s\t\t%s\t%s\t%s % (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'], ) errata_info = getPackage(vals['errata_advisory'],) print errata_info['errata_topic'] errata_package = errata_info['errata_topic'] add print type(errata_package), repr(errata_package) here, and let us know what it prints. print getPackage(vals['errata_advisory']) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Johhny wrote: Hello, Here is the code (minus my details section). server = xmlrpclib.ServerProxy(url) session = server.auth.login(username,password) #functions. def getErrata(): channel_label = 'rhel-i386-as-4' errata = server.channel.software.list_errata(session,channel_label,start_date,end_date) return errata def getPackage(advisory): Package = server.errata.get_details(session,advisory) return Package errata = getErrata() for vals in errata: print %s\t\t%s\t\t%s\t%s\t%s % (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'],) errata_info = getPackage(vals['errata_advisory'],) print errata_info['errata_topic'] errata_package = errata_info['errata_topic'] errata_package = errata_info['errata_topic'].replace('\n', ) print getPackage(vals['errata_advisory']) I have not got any of the section in to replace the \n's as I was trying to work out why its not seeing what I thought was a string as a dict. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that Roger L. Cauvin [EMAIL PROTECTED] might have written: Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Does such a regular expression exist? If so, any ideas as to what it could be? Is this what you mean? ^[^a]*(a{3})(?:[^a].*)?$ This fits your description. -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: customized instance dictionaries, anyone?
On 25 Jan 2006 09:35:50 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: thx! indeed, it worked -- took me some time to figure out how to implement the setting of attributes, too. i finally managed to get that done using super: Seems good. snip the ``~.__setattr__()`` method tests for the special name ``_dict`` and defers execution to the super of the ``X`` instance, ``object``. other stuff is handled by the instance itself. seems a clean way to do it. testing that with :: x = X() print x.__dict__[ 'foo' ] print x.__dict__[ 'bar' ] print x.foo print x.bar print x.__dict__ x.oops = 42 print x.__dict__ yields :: bar THIS ITEM NOT AVAILABLE bar THIS ITEM NOT AVAILABLE {'foo': 'bar'} {'foo': 'bar', 'oops': 42} as expected. i tried to reason *why* the usage of a property makes this particular piece of code work, but i seemingly can't find out. anyone around who has thoughts on that? I had an inspiration and I think succeeded in doing what you were originally trying to do (replace the actual instance dict with your custom dict), which I tried to do but didn't realize at first that the __init__ setting of x.__dict__ was really setting x.__dict__['__dict__'] not setting the initial x.__dict__ itself. __dict__ is a peculiar animal, and looking for an instance's attribute dict doesn't start at the instance. If you look for instance.__dict__, it is just like looking for any other attribute, and it starts at type(instance).mro()[0] looking for a descriptor (which a method also is). But the first thing found is a dict proxy for looking up attributes, and when it looks up '__dict__' it returns a descriptor, which then gets its __get__ method called with the instance whose '__dict__' is being sought. You have to use the corresponding __set__ method to set the value of '__dict__' (in this case the CustomDict instance). Otherwise instance.__dict__ will automatically be set to {} and then used so you have {'__dict__':CustomDict()} instead of CustomDict() itself. Once this is initialized correctly, then all the machinery works, except we still need to intercept __getattr__ for some reason. I suspect this is another symptom of some optimization. One of these days I will have to look in the source ;-) You would think it could give up on the mro method search and get the __dict__ normally to get the attribute, but some mechanism is not finding the custom dict, or else maybe it's bypassing the __getitem__ and going directly to the base dict method. Someday I'll have to look in the source ;-) customdict as before class CustomDict( dict ): ... defaultValue = 'THIS ITEM NOT AVAILABLE' ... def __getitem__( self, name ): ... try: ... return super( CustomDict, self ).__getitem__( name ) ... except KeyError: ... return self.defaultValue ... def __contains__( self, name ): ... return True ... def has_key( self, name ): ... return True ... class X( object ): ... def __getattr__(self, attr): ... return self.__dict__[attr] ... #return type(self).__dict__['__dict__'].__get__(self)[attr] ... def __init__( self, *args, **kw ): ... type(self).__dict__['__dict__'].__set__(self, CustomDict(*args, **kw) ... x = X(foo='bar') print x.__dict__['foo'] bar print x.__dict__['bar'] THIS ITEM NOT AVAILABLE print x.foo bar print x.bar THIS ITEM NOT AVAILABLE x.oops = 42 print x.__dict__ {'foo': 'bar', 'oops': 42} Looking at a few things of interest: vars(x) {'foo': 'bar', 'oops': 42} type(vars(x)) class '__main__.CustomDict' type(x.__dict__) class '__main__.CustomDict' vars(x)['?'] 'THIS ITEM NOT AVAILABLE' type(x) class '__main__.X' type(x).__dict__ dictproxy object at 0x02E81554 type(x).__dict__['__dict__'] attribute '__dict__' of 'X' objects type(x).__dict__['__dict__'].__get__ method-wrapper object at 0x02EF3B6C type(x).__dict__['__dict__'].__get__(x) {'foo': 'bar', 'oops': 42} type(type(x).__dict__['__dict__'].__get__(x)) class '__main__.CustomDict' The reason the property was needed before was really several reasons. First was that x.__dict__ wasn't being set properly, so the internal machinery wasn't finding the custom dict. I changed the name to _dict and let it be an ordinary attribute, but then used property to fake what normal stuff would do if x.__dict__ itself was set, not x.__dict__['__dict__'] Wasted a bunch of time trying to get rid of that __getattr__ ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: sockets programming with python on mobile phones
On 2006-01-26, al pacino [EMAIL PROTECTED] wrote: Is it possible to write applications using sockets for network programming on MOBILE Phones( using Python on mobile phones such as nokia 66* series ) actually i want my mobile to 'TALK' to my pc 'WIRELESSLY' so i can send data between the two Mr. Pacino, I just saw Donnie Brasco and thought you were brilliant. However, I must say that you're chewing the SCENERY here a bit with the semi-random SHOUTING. I think it works over the GPRS stack. PLEASE PLEASE help it is crucial for my major project and my guide dont have much(actually any) idea on this Pretty brave leaving acting and starting a new career at your age, but if you're determined to give it a go, try here: http://www.forum.nokia.com/python Amazing what you can find by googling for python+nokia, eh? -- Grant Edwards grante Yow! In Newark the at laundromats are open 24 visi.comhours a day! -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Hello Roger, since the length of the first sequence of the letter 'a' is 2. Yours accepts it, right? Yes, i misunderstood your requirements. So it must be modified essentially to that what Tim Chase wrote: m = re.search('^[^a]*a{3}b', 'xyz123aabbaaab') Best wishes from germany, Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Sybren Stuvel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Roger L. Cauvin enlightened us with: I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Your request is ambiguous: 1) You're looking for the first, and only the first, sequence of the letter 'a'. If the length of this first, and only the first, sequence of the letter 'a' is not 3, no match is made at all. 2) You're looking for the first, and only the first, sequence of length 3 of the letter 'a'. What is it? The first option describes what I want, with the additional restriction that the first sequence of the letter 'a' is defined as 1 or more consecutive occurrences of the letter 'a', followed directly by the letter 'b'. -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Ah...a little more clear. r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] or (as you've only got 3 of 'em) r = re.compile([^a]*aaab+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] should do the trick. To exposit: [^a]* a bunch of stuff that's not a a{3} or aaa three letter as b+ one or more bs (a+b*) any number of as followed optionally by bs Hope this helps, -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Pulling numbers from ASCII filename not working
On 25 Jan 2006 12:42:20 -0800, IamIan [EMAIL PROTECTED] wrote: Thank you for the replies, I'm new to Python and appreciate your patience. I'm using Python 2.1. To reiterate, the ASCII files in the workspace are being read correctly and their latitude values (coming from the filenames) are successfully being converted to string. Even doing LatInt = int(LatString) works, however the second I try to print LatInt's value or use it in mathematical operations, the code chokes in ArcGIS. My full code: # Import system modules import sys, os, win32com.client # Create the geoprocessor object gp = win32com.client.Dispatch(esriGeoprocessing.GpDispatch.1) print gp.usage(Hillshade_sa) print gp.usage(RasterToOtherFormat_conversion) print gp.usage(DefineProjection_management) # Check license availability gp.AddMessage (ArcInfo license is + str(gp.CheckProduct(ArcInfo))) gp.SetProduct(ArcInfo) gp.CheckOutExtension(Spatial) # Set workspace workspace = E:\\GISTest gp.workspace = workspace gp.AddMessage(Workspace = + gp.workspace) filenames = os.listdir(gp.workspace) filenames = [filename.lower() for filename in filenames if (filename[-4:].lower() == .asc and filename[0] != - )] for filename in filenames: # For each ASCII file, create Hillshade. # account for latitude by computing Z units using radians Latitude = filename[1:3] LatString = str(Latitude) LatInt = int(LatString) ^^--here you set LatInt to an integer gp.AddMessage(LatInt is + LatInt) radians = LatInt * 0.0174532925 zFactor = 1/(113200 * (cos(radians))) The complete traceback: Traceback (most recent call last): File e:\python21\pythonwin\pywin\framework\scriptutils.py, line 310, in RunScript exec codeObject in __main__.__dict__ File E:\Documents and Settings\Administrator\Desktop\Ian\GIS\Python\zOnly.py, line 32, in ? gp.AddMessage(LatInt is + LatInt) string-- ^^--integer (LatString in place of LatInt might work, since it's a string (so is Latitude)) TypeError: cannot add type int to string ^^ ^^^ ^^ This is not lying ;-) I tried print repr(filename) and it returned the actual filename: 'n16w099.asc' , 'n17w062.asc' , etc. So you can see Latitude would be '16' '17' etc. right? On to the next traceback ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, In response to that the output is this : type 'str' 'Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Using non-ascii symbols
Terry Hancock wrote: One thing that I also think would be good is to open up the operator set for Python. Right now you can overload the existing operators, but you can't easily define new ones. And even if you do, you are very limited in what you can use, and understandability suffers. One of the issues that would need to be dealt with in allowing new operators to be defined is how to work out precedence rules for the new operators. Right now you can redefine the meaning of addition and multiplication, but you can't change the order of operations. (Witness %, and that it must have the same precedence in both multiplication and string replacement.) If you allow (semi)arbitrary characters to be used as operators, some scheme must be chosen for assigning a place in the precedence hierarchy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing script with embedded python
Farshid Lashkari [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The problem is that PyObject_CallObject always returns NULL. Is this the correct return value for simply executing a script, as there is no function return value involved? The documentation for PyObject_CallObject states the following: Returns the result of the call on success, or NULL on failure. So it seems like the call is failing. My guess would be that modules are not callable objects. Also, this seems somewhat redundant since your module is effectively executed when you import it using the PyImport_Import function. -Farshid Thanks for the reply. The script does execute and do what I want it to do, without any problems. The only problem is that I get the NULL result. So I think it is callable. Andy -- http://mail.python.org/mailman/listinfo/python-list
urllib2 chunked encoding
I am trying to download some html using mechanize:br=Browser()r = br.open(url)b = r.read()print bI have used this code successfully many times and now I have run across an instance where it fails. It opens the url without error but then prints nothing. Looking at the http headers when it works fine it has a Content-Length: XAnd when it does not work it has no Content-Length and it has Transfer-Encoding: chunkedIt could be that I am doing something else wrong (like maybe that site needs some different headers or something), but I had never seen this before so it made me suspicious. Does urllib2 and mechanize deal with chunked encoding properly? Is there something else that I need to do to make it work?Thanks,Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
(since this is a newsgroup, can you please quote the message you're replying to). Johhny wrote: In response to that the output is this : type 'str' 'Updated libc-client packages that fix a buffer overflow issue are now\navailable.\n\nThis update has been rated as having moderate security impact by the Red\nHat Security Response Team.' type 'str means that it *is* a string, after all. looks like you didn't post the code you were using :-( replacing the print statement with errata_package = errata_package.replace(\n, ) should do what you want. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb - Query/fetch don't return result when it *theorically* should
On Wed, 18 Jan 2006 18:31:39 -0500, Bernard Lebel [EMAIL PROTECTED] wrote: I'm absolutely flabbergasted. Your suggestion worked, the loop now picks up the changed values, and without the need to reconnect. It's the first time I have to commit after a query, up until I wrote this program, I used commit() was for UPDATE/INSERT types of commands only, and always got proper fetch results. I found a similar problem occurred when I upgrade MySQL to some of the 4.1.x versions and the newest 5.x. The default table type now seems to be InnoDB which activates transactions, so now the autocommit has to be turned on in mysqldb or explicit commit's have to be placed into the code. --Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Tim Chase [EMAIL PROTECTED] wrote: Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Ah...a little more clear. r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Unfortunately, the OP's spec is even more complex than this, if we are to take to the letter what you just quoted; e.g. aazaaab SHOULD match, because the sequence 'aaz' (being 'a' NOT followed by the letter 'b') should not invalidate the match that follows. I don't think he means the strings contain only a's and b's. Locating 'the first sequence of a followed by b' is easy, and reasonably easy to check the sequence is exactly of length 3 (e.g. with a negative lookbehind) -- but I don't know how to tell a RE to *stop* searching for more if the check fails. If a little more than just REs and matching was allowed, it would be reasonably easy, but I don't know how to fashion a RE r such that r.match(s) will succeed if and only if s meets those very precise and complicated specs. That doesn't mean it just can't be done, just that I can't do it so far. Perhaps the OP can tell us what constrains him to use r.match ONLY, rather than a little bit of logic around it, so we can see if we're trying to work in an artificially overconstrained domain? Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Hallo Alex, r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Unfortunately, the OP's spec is even more complex than this, if we are to take to the letter what you just quoted; e.g. aazaaab SHOULD match, Then it's again a{3}b, isn't it? Freundliche Grüße, Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Tim Chase [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Ah...a little more clear. r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Wow, I like it, but it allows some strings it shouldn't. For example: xyz123aabbaaab (It skips over the two-letter sequence of 'a' and matches 'bbaaab'.) -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: history
yqyq22 wrote: Dear all, another little question, I use idle 1.1.2, is there a way to use a history for the command line? thanks in advance Another possibility beside going to any of the previous lines and hitting [Return]: [Alt]+p Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Christos Georgiou [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that Roger L. Cauvin [EMAIL PROTECTED] might have written: Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Does such a regular expression exist? If so, any ideas as to what it could be? Is this what you mean? ^[^a]*(a{3})(?:[^a].*)?$ Close, but the pattern should allow arbitrary sequence of characters that precede the alternating a's and b's to contain the letter 'a'. In other words, the pattern should accept: xayz123aaabbab since the 'a' between the 'x' and 'y' is not directly followed by a 'b'. Your proposed pattern rejects this string. -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Wow, I like it, but it allows some strings it shouldn't. For example: xyz123aabbaaab (It skips over the two-letter sequence of 'a' and matches 'bbaaab'.) Anchoring it to the beginning/end might solve that: r = re.compile(^[^a]*a{3}b+(a+b*)*$) this ensures that no as come before the first 3xa and nothing but b and a follows it. -tkc (who's translating from vim regexps which are just diff. enough to throw a wrench in works...) -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Roger L. Cauvin wrote: Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Hope that's clearer . . . . Examples are a *really* good way to clarify ambiguous or complex requirements. In fact, when made executable they're called test cases :-), and supplying a few of those (showing input values and expected output values) would help, not only to clarify your goals for the humans, but also to let the proposed solutions easily be tested. (After all, are you going to just trust that whatever you are handed here is correctly implemented, and based on a perfect understanding of your apparently unclear requirements?) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Tim Chase [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Wow, I like it, but it allows some strings it shouldn't. For example: xyz123aabbaaab (It skips over the two-letter sequence of 'a' and matches 'bbaaab'.) Anchoring it to the beginning/end might solve that: r = re.compile(^[^a]*a{3}b+(a+b*)*$) this ensures that no as come before the first 3xa and nothing but b and a follows it. Anchoring may be the key here, but this pattern rejects xayz123aaabab which it should accept, since the 'a' between the 'x' and the 'y' is not directly followed by the letter 'b'. -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: SPE 0.8.2.a Python IDE: configure styles, interactive terminals ubuntu
SPE - Stani's Python Editor wrote: Release news from http://pythonide.stani.be This is an important a bugfix release for all platforms. As new features it can customize your fonts and colors (styles), supports interactive terminals and has improved support for Ubuntu. Thanks to Marco Ferreira there will be very soon a debian package to install SPE easily and create an entry in the start menu on debian based linux distro's such as Ubuntu. I'm also in contact with Matthias Klose to make an updated SPE available with the Ubuntu Dapper Drake release. :**New features**: - Configurable style editor for fonts and colors (Idle, ...) (PreferencesEditorConfigure styles) - Inspect interactively after running script in terminal (ToolsRun in terminal F9) - Debian installer for Ubuntu, Xandros, etc... by Marco Ferreira :**Fixes**: - dot bug after ')' - prevent unsplitting by double clicking sidebar sash - tar.gz archive shrinked to 65% of its original size (only 833kb!) - Linux: fix for the Browser (tested on Ubuntu) - Linux: added firefox to webbrowser list and is default browser if present - Linux: run in terminal for konsole and gnome-terminal - Linux: sidebar fits better around it contents - Mac: sash is enlarged to 6 pixels - Mac: new feature: browser in sidebar (for wxPython 2.6.2+) - Linux amp; Mac: a lot of visual glitches are fixed - Windows: SPE shortcut in Windows start menu works again - Windows: Run in terminal input - Windows: NotebookCtrl fixed :**Manual**: - Installation: added section for Ubuntu and Debian systems. - Tutorial: the SPE tutorial has been completely rewritten by Dimitri to be up to date with the latest version (review and leave your comments at http://www.serpia.org/spe ...) From: http://www.serpia.org/spe switching to http://www.serpia.org/sorry please enable javascript in your browser to visit serpia.org if you think that sucks, please contact me about it if not, enable javascript and click here If you would like to know how much people find, it sucks, this is sure a way of getting the wrong picture: A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: [EMAIL PROTECTED] SMTP error from remote mail server after RCPT TO:[EMAIL PROTECTED]: host serpia.org [207.210.219.100]: 550 [EMAIL PROTECTED]: Recipient address rejected: User unknown in local recipient table Subject: This js thing sucks Claudio - global revision :**Donations**: - Marco Ferreira (Debian installers) :**Donations**: These donators can request the pdf manual: - Harry Miktarian (16.10 euro) - Amit Antebi (10 euro) - Steven Hepple (10 euro) The development of SPE is driven by donations. :**Installation**: - See http://pythonide.stani.be/manual/html/manual2.html - For ubuntu: dpkg -i spe.deb (be sure to have pythonX.X-dev installed) :**Development**: - http://developer.berlios.de/mail/?group_id=4161 About SPE: SPE is a python IDE with auto-indentation, auto completion, call tips, syntax coloring, uml viewer, syntax highlighting, class explorer, source index, auto todo list, sticky notes, integrated pycrust shell, python file browser, recent file browser, dragdrop, context help, ... Special is its blender support with a blender 3d object browser and its ability to run interactively inside blender. Spe integrates with XRCed (gui designer) and ships with wxGlade (gui designer), PyChecker (source code doctor), Kiki (regular expression console) and WinPdb (remote, multi-threaded debugger). The development of SPE is driven by its donations. Anyone who donates can ask for an nice pdf version of the manual without ads (74 pages). -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Peter Hansen [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Roger L. Cauvin wrote: Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Hope that's clearer . . . . Examples are a *really* good way to clarify ambiguous or complex requirements. In fact, when made executable they're called test cases :-), and supplying a few of those (showing input values and expected output values) would help, not only to clarify your goals for the humans, but also to let the proposed solutions easily be tested. Good suggestion. Here are some test cases: xyz123aaabbab accept xyz123aabbaab reject xayz123aaabab accept xaaayz123abab reject xaaayz123aaabab accept -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Christoph Conrad [EMAIL PROTECTED] wrote: Hello Roger, since the length of the first sequence of the letter 'a' is 2. Yours accepts it, right? Yes, i misunderstood your requirements. So it must be modified essentially to that what Tim Chase wrote: m = re.search('^[^a]*a{3}b', 'xyz123aabbaaab') ...but that rejects 'aazaaab' which should apparently be accepted. Alex -- http://mail.python.org/mailman/listinfo/python-list
Tkinter listener thread?
I have a Python UDP listener socket that waits for incoming data. The socket runs as an endless loop. I would like to pop the incoming data into an existing Tkinter app that I have created. What's the easiest/most efficient way of handling this? Would I create a separate thread that has the listener set a certain Tkinter variable if there is incoming data? Any suggestions would be tremendously appreciated :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
On Thu, 26 Jan 2006 16:26:57 GMT, rumours say that Roger L. Cauvin [EMAIL PROTECTED] might have written: Christos Georgiou [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that Roger L. Cauvin [EMAIL PROTECTED] might have written: Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. xyz123aaabbaaabaaaabb I'm looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3. Does such a regular expression exist? If so, any ideas as to what it could be? Is this what you mean? ^[^a]*(a{3})(?:[^a].*)?$ Close, but the pattern should allow arbitrary sequence of characters that precede the alternating a's and b's to contain the letter 'a'. In other words, the pattern should accept: xayz123aaabbab since the 'a' between the 'x' and 'y' is not directly followed by a 'b'. Your proposed pattern rejects this string. 1. (a{3})(?:b[ab]*)?$ This finds the first (leftmost) aaa either at the end of the string or followed by 'b' and then arbitrary sequences of 'a' and 'b'. This will also match (from second position on). 2. If you insist in only three 'a's and you can add the constraint that: * let s be the arbitrary sequence of characters at the start of your searched text * len(s) = 1 and not s.endswith('a') then you'll have this reg.ex. (?=[^a])(a{3})(?:b[ab]*)?$ 3. If you want to allow for a possible empty arbitrary sequence of characters at the start and you don't mind search speed ^(?:.?*[^a])?(a{3})(?:b[ab]*)?$ This should cover you: s=xayzbaaa123aaabbab r=re.compile(r^(?:.*?[^a])?(a{3})(?:b[ab]*)?$) m= r.match(s) m.group(1) 'aaa' m.start(1) 11 s[11:] 'aaabbab' -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: Using non-ascii symbols
Rocco Moretti wrote: Terry Hancock wrote: One thing that I also think would be good is to open up the operator set for Python. Right now you can overload the existing operators, but you can't easily define new ones. And even if you do, you are very limited in what you can use, and understandability suffers. One of the issues that would need to be dealt with in allowing new operators to be defined is how to work out precedence rules for the new operators. Right now you can redefine the meaning of addition and multiplication, but you can't change the order of operations. (Witness %, and that it must have the same precedence in both multiplication and string replacement.) If you allow (semi)arbitrary characters to be used as operators, some scheme must be chosen for assigning a place in the precedence hierarchy. Speaking maybe only for myself: I don't like implicit rules, so I don't like also any precedence hierarchy being in action, so for safety reasons I always write even 8+6*2 (==20) as 8+(6*2) to be sure all will go the way I expect it. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
Alex Martelli [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Tim Chase [EMAIL PROTECTED] wrote: Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. ... ... If a little more than just REs and matching was allowed, it would be reasonably easy, but I don't know how to fashion a RE r such that r.match(s) will succeed if and only if s meets those very precise and complicated specs. That doesn't mean it just can't be done, just that I can't do it so far. Perhaps the OP can tell us what constrains him to use r.match ONLY, rather than a little bit of logic around it, so we can see if we're trying to work in an artificially overconstrained domain? Alex, you seem to grasp exactly what the requirements are in this case. I of course don't *have* to use regular expressions only, but I'm working with an infrastructure that uses regexps in configuration files so that the code doesn't have to change to add or change patterns. Before throwing up my hands and re-architecting, I wanted to see if regexps would handle the job (they have in every case but one). -- Roger L. Cauvin [EMAIL PROTECTED] (omit the nospam_ part) Cauvin, Inc. Product Management / Market Research http://www.cauvin-inc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Match First Sequence in Regular Expression?
On Thu, 26 Jan 2006 16:41:08 GMT, rumours say that Roger L. Cauvin [EMAIL PROTECTED] might have written: Good suggestion. Here are some test cases: xyz123aaabbab accept xyz123aabbaab reject xayz123aaabab accept xaaayz123abab reject xaaayz123aaabab accept Applying my last regex to your test cases: r.match(xyz123aaabbab) _sre.SRE_Match object at 0x00B47F60 r.match(xyz123aabbaab) r.match(xayz123aaabab) _sre.SRE_Match object at 0x00B50020 r.match(xaaayz123abab) r.match(xaaayz123aaabab) _sre.SRE_Match object at 0x00B47F60 print r.pattern ^(?:.*?[^a])?(a{3})(?:b[ab]*)?$ You should also remember to check the (match_object).start(1) to verify that it matches the aaa you want. -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: ImportError: No module name MySQLdb
I have discovered the possible problem (I can't check this until later when I am home) I think when I upgraded to Python 2.4.2 it created my problem. Below is what is going on: Default Slackware 10.2 install - 2.4.1 installed into /usr/lib/python2.4 Python 2.4.1 upgraded to 2.4.2 Upgrade downloaded from Python.org compiled and installed - 2.4.2 installed into /usr/local/lib/python2.4 Bin files are in: /usr/bin/python and /usr/local/bin/python MySQLdb instatlled after the 2.4.2 upgrade works fine at the command line I am betting that when I launch the script from the webpage it is looking for /usr/bin/python I should be able to make a symlink in /usr/bin/python -- /usr/local/bin/python And of course change #!/usr/bin/python to #!/usr/local/bin/python in the script What do you think? Fred -- http://mail.python.org/mailman/listinfo/python-list