Re: [DB-SIG] dbf files and compact indices
If you can read c code, have a look at the Harbour (clipper) open source project. It works with CDX files. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a maximum size to a Python program?
Thanks for the reply, > Sounds like a needlessly complicated way of doing things. Surely > replicating data from a database is a solved problem? The data is coming from a legacy system and going into SQLalchemy to give database independence. We will probably update the legacy apps in the future but it is a massive job for little benefit. > I don't understand what you mean by "with no current data". Do you mean > that you generate 5MG of source code when the original postcode table is > empty? Or 5MB of source code when the *replicated* table is empty? Or > something else? 5MB of source code when the replicated table is empty > Perhaps you could explain what the 5MB of code is supposed to do it, and > how you generate the code, and show a *small* number of sample lines. Here is a generated file that works. Other files are essentially the same but with more entries. This one only adds if the record does not exist, the next stage was to update an existing record with changes. !/usr/bin/python # -*- coding: utf-8 -*- import schema import time from datetime import * from sqlalchemy import * from sqlalchemy.orm import * engine = create_engine('sqlite:///tutorial.db', echo=False) Session = sessionmaker(bind=engine) session = Session() entry = schema.BILLS() exists = session.query(schema.BILLS).filter(schema.BILLS.REFNO==u"1") if exists.count == 0: entry.REFNO = u"1" entry.THRDPTY = u"""C5""" entry.AMOUNT = 0 entry.TIMESTAMP = 0 entry.ALLOCATED = 0 session.add(entry) session.commit() session.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a maximum size to a Python program?
Thanks John, I understand where you are coming from and will try and digest it all. One problem though that I didn't mention in my original posting was that the replication may only require updating one or more fields, that is a problem with a generating a single SQL statement to cover all requests. I am having a look at eval and exec to see if they will give me a little more flexibility in runtime generation of the code. "John Machin" wrote in message news:1ac0545d-71e7-46c4-9458-1117d3b8c...@k19g2000prh.googlegroups.com... On Apr 27, 1:01 pm, "Carbon Man" wrote: > I have a program that is generated from a generic process. It's job is to > check to see whether records (replicated from another system) exist in a > local table, and if it doesn't, to add them. I have 1 of these programs > for > every table in the database. Everything works well until I do the postcode > table. The generated code is 5MB for a system with no current data. > Normally > the file would not be this big as only the changes are copied over. Python > just quits, I have tried stepping through the code in the debugger but it > doesn't even start. > I am thinking that dynamically generating the programs to run might not be > such a good idea. I tend to agree with that line of thinking. What you need is: (a) ONE program. That's not one per table, that's one and only one, period/full-stop. (b) Per-table config info like column names and types -- you have this already. The idea is that instead of reading a data file and generating SQL per row, you generate SQL once, with parameter markers for the data values. Then you read the data file and execute the prepared SQL for each row More detail: At the start, build an INSERT statement that's tailored for the table that you are updating: insert_sql = "INSERT INTO table_name VALUES (?,?,?,?)" or (if you are paranoid) "INSERT INTO table_name(col1,col2,col3,col4) VALUES (?,?,?,?)" Notes: (a) assumes four columns as an example (b) Lower-case stuff has to be replaced with the correct table name and column name(s) (c) "?" is the parameter marker for the DB module you are using For each row read from the data file, transform the input into a tuple of suitable data types, and then do the insert: import yourdbmodule # much later: try: cursor.execute(insert_sql, data_tuple) except yourdbmodule.IntegrityError: # if it's the primary key not unique exception: pass # ignoring this is part of your requirement else: raise # probably never happen, but should be checked > It would be a shame to drop it because the system needs to > be generic OTOH it would be a shame to continue with a process where the amount of code lying around is O(N_update_rows) instead of O(1) and the number of programs is O(N_tables) instead of O(1). > and it runs from an XML file so the resulting code could be > pretty complex, and I am new to Python. The above advice is in general language-agnostic; I'm just using Python code because you asked in this newsgroup. The fact that other languages may give you more rope with which to hang yourself is also immaterial :-) HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a maximum size to a Python program?
The reason I started down this path is that the program is grinding to a halt (my PC as well) and the only way to get it going again is: >>>import gc >>>gc.collect() 2524104 Memory used by the process is around 500MB, I have posted about this problem before on this newsgroup but I didn't get a resolution. So I was trying to separate the logic into different files and finish each one with gc.collect(). Sorry I didn't post the original problem as well but I really just wanted the thing to work and not cloud the issue again. I have implemented your approach and the code is much cleaner (except for another problem that I have posted to sqlAlchemy). It doesn't solve my original problem with the memory, but I really need SOMETHING to work. So I will keep plodding away and then maybe move the XML processing to lxml and see if that resolves the memory problem. "John Machin" wrote in message news:3215638c-2408-4cf6-9321-f85f560e6...@u39g2000pru.googlegroups.com... On Apr 27, 3:31 pm, "Paul Hemans" wrote: > Thanks John, I understand where you are coming from and will try and > digest > it all. One problem though that I didn't mention in my original posting > was > that the replication may only require updating one or more fields, that is > a > problem with a generating a single SQL statement to cover all requests. OK so you need TWO programs -- one tailored for initial loading of a table, the other for subsequent updates. Still O(1) :-) OR you could still do it in one, by using the prepared whole-row SQL statement if appropriate, or building an SQL statement on the fly if it's an update. > I am > having a look at eval and exec WRONG WAY GO BACK > to see if they will give me a little more > flexibility in runtime generation of the code. And another thing that you didn't mention was that you are using SQLAlchemy -- perhaps you might like to ask your question on that package's forum ... including a few more facts than heretofore :-) HTH John -- http://mail.python.org/mailman/listinfo/python-list
The whole story
Hi Andrew, The reason I am using mapped objects is that I need to abstract from the database implementation allowing the replication to target a number of different platforms. This will definitely slow things down. > process a whole pile in memory and then (perhaps every 10,000 - when your > memory is about to run out and start paging) flush the session. Under windows how can I tell when memory is about to run out? I guess there is no cross-platform solution to this. Writing external files has all come about from a post titled "Memory problems (garbage collection) by Carbon Man" which I never got a resolution to. I was trying to execute gc.collect() when a process was complete because I was having huge problems with memory (though the problem still remains). If I stop at "import schema" There are 2524104 objects processed by gc.collect() There is a new issue in the code (marked with Problem with SQLalchemy), but here is the program as it now stands: #!/usr/bin/python # -*- coding: utf-8 -*- # Reads an XML file and creates schema.py from the TABLES branch (very simplistic table structures) # Processes the nodes within the DATA branch, into SQLalchemy from xml.dom import minidom import os import codecs from cStringIO import StringIO import time from datetime import * from sqlalchemy import * from sqlalchemy.orm import * class xmlProcessing: """ General class for XML processing""" def process(self, filename="", xmlString=""): if xmlString: pass elif filename: xmldoc = minidom.parse(filename) self.parse( xmldoc.documentElement ) def parseBranch(self, parentNode): """ Process an XML branch """ for node in parentNode.childNodes: try: parseMethod = getattr(self, "parse_%s" % node.__class__.__name__) except AttributeError: continue if parseMethod(node): continue self.parseBranch(node) def parse_Document(self, node): pass def parse_Text(self, node): pass def parse_Comment(self, node): pass def parse_Element(self, node): try: handlerMethod = getattr(self, "do_%s" % node.tagName) except AttributeError: return False handlerMethod(node) return True class reptorParsing(xmlProcessing): """ Specific class for generating a SQLalchemy program to create tables and populate them with data""" def __init__(self): self.schemaPreface = StringIO() self.schemaPreface.write("""from sqlalchemy import * import time from datetime import * from sqlalchemy.ext.declarative import declarative_base #engine = create_engine('sqlite:///tutorial.db', echo=False) #metadata = MetaData() Base = declarative_base()""") self.schemaTables = StringIO() self.schemaTablesCreate = StringIO() self.schemaFields = StringIO() self.tableDict = {} self.tableName = StringIO() self.tables = StringIO() def parse(self, parentNode): """Main entry point to begin processing a XML document""" self.parseBranch(parentNode) # Properties such as schemaTables and .tables are populated by the various methods below fupdate=codecs.open(os.path.join(os.getcwd(), "update.py"), 'w', 'UTF-8') if self.schemaTables: f=codecs.open(os.path.join(os.getcwd(), "schema.py"), 'w', 'UTF-8') f.write(self.schemaPreface.getvalue()+u"\n"+self.schemaTables.getvalue()+ u"if __name__ == '__main__':\n" + self.schemaTablesCreate.getvalue() + u"\nengine = create_engine('sqlite:///tutorial.db', echo=False)\n" + u"metadata = Base.metadata\n" + u"metadata.create_all(engine)\n") f.close() if self.tables: fupdate.write(self.tables.getvalue()) fupdate.close() def do_TABLES(self, tableNode): """Process schema for tables""" for node in tableNode.childNodes: self.tableName = node.tagName # Define a declaritive mapping class self.schemaTables.write("""\nclass %s(Base): __tablename__ = '%s' """ % (self.tableName, self.tableName)) self.schemaTablesCreate.write("\ntableDef = "+self.tableName+"()") self.schemaFields = StringIO() # allow for userA = users("Billy","Bob") via a __init__() self.schemaInitPreface = StringIO() self.schemaInitPreface.write("def __init__(self") self.schemaInitBody = StringIO() self.parseBranch(node) self.schemaInitPreface.write("):\n") self.schemaTables.write(self.schemaFields.getvalue() + "\n" + \ self.schemaInitPreface.getvalue() + \ self.schemaInitBody.getvalue() + "\n") # Need a way to execute schema so
Re: Is there a maximum size to a Python program?
Hi, Please see my post titled "The whole story" "Martin P. Hellwig" wrote in message news:qokdnqz7zfefw2junz2dnuvz8jqdn...@bt.com... > Carbon Man wrote: >> I have a program that is generated from a generic process. It's job is to >> check to see whether records (replicated from another system) exist in a >> local table, and if it doesn't, to add them. > > To answer the topic question, it would be limited to the memory your > platform can allocate and I guess that the most critical part would be if > you run out of memory for handling the namespace references. > > However my magic 8 ball whispers to me that the provided solution tries to > be smarter than the given problem requires, which is not a good thing. If > so and if possible, please provide a more detailed explanation of the > actual problem you want to solve instead of the problem you currently have > with the provided solution. > > -- > MPH > http://blog.dcuktec.com -- http://mail.python.org/mailman/listinfo/python-list
Problems resolved
Thanks to everyone for all the suggestions. Here's what I did: Stuck with sqlAlchemy because I like the idea of ORMs and I like being able to abstract from the database vendor. Left the schema definitions to be generated in a separate file, so that it could be re-used Dumped xml.dom and went to lxml Brought the data processing into the main program Works like a charm and the code is poetry. Great community. -- http://mail.python.org/mailman/listinfo/python-list
Memory problems - fixed!
Taking into account that I am very new to Python and so must be missing something important dumping xml.dom and going to lxml made a WORLD of difference to the performance of the application. -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you think of ShowMeDo
I also am new to Python and found the site. The main barrier to me was the price. Pay as you use with credits might be less of a problem in an community environment where so much is available. The interface did not lead me to understand where I could find the free stuff, I also did not realize how much of it was available. With so much information on the web you tend to spend a very short amount of time trying to understand what a site is about. If it is available, I would have a look at your crawl stats and see how long people are staying on a particular page before leaving the site. I think Google has introduced some analytics that will allow you to compare different site layouts and the pattern of traffic. In regards to the negative comments, I think you are right to defend against them as they have been recorded in the anals of the web, however I certainly wouldn't let it discourage you. It is obviously a great resource. So my few suggestions are (at a penny a pop): 1. Simplify the home page so that newcomers know what they are going to get for free and what isn't 2. The learning maps are a great idea, unfortunately the first one I looked at http://showmedo.com/static/images/LPs/networks/10.png I couldn't read. 3. Let people buy credits. Start at roughly 10 - 20 cents per commercial video, step the rating so that the more you use the service the less you pay per view. Don't worry about the Open ID thing too much, most people use the same U/N and P/W for all their different logins anyway. Might be nice later on though, when some bright spark decides that people's personal learning plans should be hosted in the cloud and you want to hook into that. All in all great site (do I get any credits for saying that?). "Astley Le Jasper" wrote in message news:b6671f88-bc04-42eb-aad1-5b212bcab...@z23g2000prd.googlegroups.com... > Hi, > > I've just stumbled over this (http://showmedo.com/) and being the very > visual person I am, it seems like it could be a good way to learn > about python. However, before I smack down $60, I wondered if anyone > had any opinions on it. My gut feel is that it could be pretty good. > > ALJ -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you think of ShowMeDo
I also am new to Python and found the site. The main barrier to me was the price. Pay as you use with credits might be less of a problem in an community environment where so much is available. The interface did not lead me to understand where I could find the free stuff, I also did not realize how much of it was available. With so much information on the web you tend to spend a very short amount of time trying to understand what a site is about. If it is available, I would have a look at your crawl stats and see how long people are staying on a particular page before leaving the site. I think Google has introduced some analytics that will allow you to compare different site layouts and the pattern of traffic. In regards to the negative comments, I think you are right to defend against them as they have been recorded in the anals of the web, however I certainly wouldn't let it discourage you. It is obviously a great resource. So my few suggestions are (at a penny a pop): 1. Simplify the home page so that newcomers know what they are going to get for free and what isn't 2. The learning maps are a great idea, unfortunately the first one I looked at http://showmedo.com/static/images/LPs/networks/10.png I couldn't read. 3. Let people buy credits. Start at roughly 10 - 20 cents per commercial video, step the rating so that the more you use the service the less you pay per view. Don't worry about the Open ID thing too much, most people use the same U/N and P/W for all their different logins anyway. Might be nice later on though, when some bright spark decides that people's personal learning plans should be hosted in the cloud and you want to hook into that. All in all great site (do I get any credits for saying that?). -- http://mail.python.org/mailman/listinfo/python-list
Re: What do you think of ShowMeDo
I was fishing for a response, by posting multiple replies Inadvertantly, I have offended one of the Python rabbis For this misdemeanor I am most contrite But I still got a fish to bite. "Peter Pearson" wrote in message news:760gejf1af7r...@mid.individual.net... > On Fri, 1 May 2009 07:53:35 +1000, Paul Hemans wrote: > [snip] >> them as they have been recorded in the anals of the web, however I > .^ > > That's the second time in this thread. The first might have been > deliberate gross wordplay, but now it's time for somebody to point > out that maybe this word doesn't mean what you think it means. > > -- > To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Help with a HTTP GET request
I am trying to build a HTTP request that looks like: http://localhost/common/foxisapi.dll/tmsmail.x2.isapi? Works in a browser. lxml.parse() gives me: failed to load external entity urllib2.urlopen() gives me: Bad request So I am trying httplib I have encoded the GET request with urllib.quote () and now I am attempting to use HTTPConnection >>> conn = httplib.HTTPConnection("localhost") >>> print x %3CPROCESS%20sync%3D%27%27%20schema%3D%27%27%20class%3D %27replicateApplication.getChanges%27%20/%3E >>> this = conn.putrequest("GET",x) >>> conn.endheaders() >>> r = conn.getresponse() >>> print r.read() ErrorThe parameter is incorrect. Any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
distutils and building an distribution that includes other packages
Hi, I am new to Python, and after a lot of sweat and tears, I have my first app. Now I need to deploy it to end-users. The application includes the use of lxml and sqlAlchemy so I need those to install automatically as part of the installation process. I really don't want the users having to download various modules and install them. Is this facility (to download and install other packages seamlessly) part of distutils? If so, I have been looking around for a simple tutorial on the topic but haven't found anything yet. Can anyone point me to some information? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils and building an distribution that includes other packages
Hi Chris, Yes I do intend to use py2exe for windows installation but I don't understand how it will help me distribute lxml and sqlAlchemy as part of the install, or am I missing something? "Chris Rebert" wrote in message news:mailman.426.1242792992.8015.python-l...@python.org... > On Tue, May 19, 2009 at 8:55 PM, Paul Hemans wrote: >> Hi, >> I am new to Python, and after a lot of sweat and tears, I have my first >> app. >> Now I need to deploy it to end-users. The application includes the use of >> lxml and sqlAlchemy so I need those to install automatically as part of >> the >> installation process. I really don't want the users having to download >> various modules and install them. Is this facility (to download and >> install >> other packages seamlessly) part of distutils? If so, I have been looking >> around for a simple tutorial on the topic but haven't found anything yet. >> Can anyone point me to some information? > > Since I'm guessing your platform is Windows, you'll probably be > interested in py2exe - http://www.py2exe.org/ > > Cheers, > Chris > -- > http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils and building an distribution that includes other packages
On May 20, 3:01 pm, Chris Rebert wrote: > > "Chris Rebert" wrote in message > >news:mailman.426.1242792992.8015.python-l...@python.org... > >> On Tue, May 19, 2009 at 8:55 PM, Paul Hemans wrote: > >>> Hi, > >>> I am new to Python, and after a lot of sweat and tears, I have my first > >>> app. > >>> Now I need to deploy it to end-users. The application includes the use of > >>> lxml and sqlAlchemy so I need those to install automatically as part of > >>> the > >>> installation process. I really don't want the users having to download > >>> various modules and install them. Is this facility (to download and > >>> install > >>> other packages seamlessly) part of distutils? If so, I have been looking > >>> around for a simple tutorial on the topic but haven't found anything yet. > >>> Can anyone point me to some information? > > >> Since I'm guessing your platform is Windows, you'll probably be > >> interested in py2exe -http://www.py2exe.org/ > > >> Cheers, > >> Chris > On Tue, May 19, 2009 at 9:31 PM, Paul Hemans wrote: > > Hi Chris, > > Yes I do intend to use py2exe for windows installation but I don't > > understand how it will help me distribute lxml and sqlAlchemy as part of the > > install, or am I missing something? > > Granted I haven't used Windows (and thus py2exe) in a while, but last > I recall the executable it produced was a self-contained Python > executable containing the main script and all its necessary > modules/libraries. I think there were some issues getting it to > include certain finnicky third-party libraries, but once tweaked > properly it could be coaxed to include them. > > Thus, you don't need to install/distribute the libraries at all; > they'll be included as part of the generated executable. Then to > distribute/install your program, you just copy the executable (and > maybe a DLL or two, again it's been a while). > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - Ah, I was overcomplicating things (again). Thanks -- http://mail.python.org/mailman/listinfo/python-list
Extract a bordered, skewed rectangle from an image
We have a scanned document on which a label has been attached. The label has been designed to have a border that makes it easy to determine the correct orientation and area of the label. The label portion of the scanned image needs to be extracted and deskewed as an image. The contents of the label will change, but the border won't I originally posted this onto RentAcoder as a project, but I am not getting a lot of responses. It might be that I requested it be done in Python, its too hard or I am too stingy. You can see the project here: http://www.RentACoder.com/RentACoder/misc/BidRequests/ShowBidRequest.asp?lngBidRequestId=1402446 It may not be feasible to do this project without the use of an image processing engine such as openCV. There is a routine in openCV called cvMinAreaRect2() that may do the job of returning a matching rectangle that is inclined. There is a Python to openCV interface available. So I think all the pieces are there, but this is out of my league as I have had very little experience with image processing. I am wondering whether there are any people here that have experience with openCV and Python. If so, could you either give me some pointers on how to approach this, or if you feel so inclined, bid on the project. There are 2 problems: How do I get openCV to ignore the contents of the label and just focus on the border? How to do this through Python into openCV? I am a newbie to Python, not strong in Maths and ignorant of the usage of openCV. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extract a bordered, skewed rectangle from an image
Thanks David, that is a 'tonne' of information. I am going to have a play with it, probably looking at masking out the contents of the label and finding the label border within the scanned document is the place to start. Looks like there is going to be a learning curve here. Thanks again for your help you really put a lot of effort into this. -- http://mail.python.org/mailman/listinfo/python-list
Newbie: Win32 COM problem
Simple class to wrap the xlwt module for COM access pyXLS.py: from xlwt import Workbook class WrapXLS: _reg_clsid_ = "{c94df6f0-b001-11df-8d63-00e09103a9a0}" _reg_desc_ = "XLwt wrapper" _reg_progid_ = "PyXLS.Write" _public_methods_ = ['createBook','createSheet','writeSheetCell','saveBook'] # _public_attrs_ = ['book'] def __init__(self): self.book = None def createBook(self): self.book = Workbook() def createSheet(self,sheetName): self.book.add_sheet(sheetName) def writeSheetCell(self, sheet, row, col, value, style=""): sheet = self.book.get_sheet(sheet) sheet.write(row,col,value,style) def saveBook(self,fileName): self.book.save(fileName) if __name__=='__main__': import win32com.server.register win32com.server.register.UseCommandLine(WrapXLS) It registers ok with --debug. Code executing within Foxpro (no comments pls): oPyXLS = CREATEOBJECT("PyXLS.Write") oPyXLS.createBook() oPyXLS.createSheet("Sheet 1")-- Error here Output in Python Trace Collector (PythonWin): ... in _GetIDsOfNames_ with '(u'createsheet',)' and '1033' in _Invoke_ with 1001 1033 3 (u'Sheet 1',) Traceback (most recent call last): File "C:\Python26\lib\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_ return self.policy._Invoke_(dispid, lcid, wFlags, args) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 277, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 282, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_ return func(*args) File "C:\development\PyXLS\pyXLS.py", line 13, in createSheet def createBook(self): AttributeError: WrapXLS instance has no attribute '_book' pythoncom error: Python error invoking COM method. Can anyone help? -- http://mail.python.org/mailman/listinfo/python-list
Managing a multiple threaded service
Hi, New to Python I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site for data. I want to run the program as a windows service. My questions are: Should both of them run as threads and then just have an infinite loop with a sleep in the main thread in order to stop the main program from just terminating? Or should I choose one of the threads to run as the main program and spawn the other off? That was my original intention, but I am concerned that if I use SimpleHTTPRequestHandler in the main thread, will it block any attempt to terminate the service. Just looking for pointers to the best practice approach. This is where I am at: if __name__=="__main__": import SocketServer import threading import monitor ## Monitor changes on the server (separate thread) monitor = monitor.monitor(fnLog=self.logStatus) monitor.start() ## Service interface port = 8081 server=SocketServer.TCPServer(('',port),ScriptRequestHandler) server.serve_forever() ## To run the web server on a different thread... ##t = threading.Thread(target=server.serve_forever) ##t.setDaemon(True) # don't hang on exit ##t.start() server.socket.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: Win32 COM problem
Yes, that was it. I just needed to restart the host process. Thanks "Mark Hammond" wrote in message news:mailman.51.1282784920.29448.python-l...@python.org... > On 25/08/2010 10:33 PM, Paul Hemans wrote: >>File "C:\development\PyXLS\pyXLS.py", line 13, in createSheet >> def createBook(self): >> AttributeError: WrapXLS instance has no attribute '_book' >> pythoncom error: Python error invoking COM method. >> >> Can anyone help? > > That line seems an unlikely source of the error. Note that as win32com > uses an in-process model by default, your problem may be that you changed > your implementation but didn't restart the hosting process - and therefore > are still using an earlier implementation. > > HTH, > > Mark -- http://mail.python.org/mailman/listinfo/python-list
Regular expression
I need to extract the quoted text from : _("get this") The following works: re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) However, I don't want to match if there is A-Z or a-z or 0-9 or _ immediately preceding the "_" so I have tried: "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" "[^\w]{0,1}_\(['\"]([^'\"]+)['\"]\)" "\W*_\(['\"]([^'\"]+)['\"]\)" to match against: skip this text _("get this") Thanks -- http://mail.python.org/mailman/listinfo/python-list