python connect to db2
hi,all i am python newbie,i try to connect to db2 use python,i find it on python-db2 doc: $ python import DB2 conn = DB2.connect(dsn='sample', uid='db2inst1', pwd='ibmdb2') curs = conn.cursor() but i don't know about dsn, i think a way like python connect to mysql : db=_mysql.connect(localhost,joebob,moonpie,thangs) anyone can help me ? thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda
Op 2005-01-13, hanz schreef [EMAIL PROTECTED]: Antoon Pardon wrote: So if I have a call with an expression that takes more than one line, I should assign the expression to a variable and use the variable in the call? Yes, that's sometimes a good practice and can clarify the call. But wait if I do that, people will tell me how bad that it is, because it will keep a reference to the value which will prevent the garbage collector from harvesting this memory. Nobody will tell you that it's bad. Sorry, someone already did. If I recall correctly it was Alex Martelli. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Paul Rubin wrote: Huh? Expressions are not statements except when they're expression statements? What kind of expression is not an expression statement? any expression that is used in a content that is not an expression statement, of course. Come on, that is vacuous. The claim was expressions are not statements. But it turns out that expressions ARE statements. no, expressions CAN BE USED as statements. that doesn't mean that they ARE statements, unless you're applying belgian logic. (if you have a problem figuring this out, try substituting other things for expressions and statements, and see if you still think that can be used as and are are always the same thing. try fish and pillow, for example). It's just an artifact. Whether the artifact is a desirable one is a matter of discussion. no, it's Python, and it's designed this way on purpose. go read the language reference. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Op 2005-01-13, Terry Reedy schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Op 2005-01-13, Fredrik Lundh schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Well, it seems that Guido is wrong then. The documentation clearly states that an expression is a statement. no, it says that an expression statement is a statement. if you don't understand the difference, please *plonk* yourself. And what else is an expression statement but an expression (list) used as a statement. Whereas an expression used within a statement is not a statement, and that is the difference. And of course, statements, in general, are not expressions and are not used within statements (except within compound statements). Here you are stating the opposite of what Guido is supposed to have said. IMO we have a: dogs are mamals kind of relationship in Python. Every expression can be used where a statement is expected. (And this can be worded as: every expression is a statement.) Not every statement can be used where an expression is expected. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamically inserting function into an object
*damn* it :-) python rocks. thx michael .oO (resetting c/c++/java crap collected over the years) -- http://mail.python.org/mailman/listinfo/python-list
Re: Unclear On Class Variables
Pierre Barbier de Reuille a écrit : Antoon Pardon a écrit : Well I find this a confusing behaviour on python's part. The fact that instance.field can mean something different, depending on where in a statement you find it, makes the behaviour inconsistent. I know people in general here are against declarations, but declarations could IMO provide more consistency here and thus more obvious behaviour. Well just to show how confusing python can be, the following piece of code. | class Spam: | eggs = [2, 3] | | | sp1 = Spam() | sp2 = Spam() | | print sp1.eggs, id(sp1.eggs) | print sp2.eggs, id(sp2.eggs) | print '' | | sp1.eggs += [4,] | | print sp1.eggs, id(sp1.eggs) | print sp2.eggs, id(sp2.eggs) | print '' | | Spam.eggs = [3,5] | | print sp1.eggs, id(sp1.eggs) | print sp2.eggs, id(sp2.eggs) | print '' Which produces: [2, 3] 1075958860 [2, 3] 1075958860 [2, 3, 4] 1075958860 [2, 3, 4] 1075958860 [2, 3, 4] 1075958860 [3, 5] 1075959084 Well ... and could someone explain this behaviour ? I don't catch it ! Pierre Ok, I think I got it ! I speak with friends working with Python too ... It seems that a += l if a and l are lists is equivalent to : a.extend(l) a = a The second line could seem meaningless but it is not ! Indeed, in the example above, the first sp1.eggs (the one with the extend) is a class variable but, the second sp1.eggs (the one before the =) is an instance variable ! So, at the end, we append to get sp1.eggs and Spam.eggs references to the same structure. But sp1.eggs is an instance variable of sp1 and no more the class variable. To test that, it's possible to modify slightly the code with : |sp1.eggs += [4,] |del sp1.eggs Then, sp1.eggs still exists !!! But it's again the class variable ... Ok, back to the documentation ... In the doc, there is a special case for the use of += with the class members. IMHO, this should not be !!! But, it says that : ob.a += b is translated into : ob.__setattr__( a, ob.__getattr__(a).__iadd__(b) ) My opinion is : it would be much more simpler to explain than : a += b = a.__iadd__(b); a = a and not give any special case for class members. In both cases, the resulting behaviour is the same, but it would be less confusing. Then, this change of scope of variables in python is very very annoying. Both for new and old programmers (we have both in my lab ...). Well, I hope I got it write this time ... but this is a feature to fear !!! Pierre -- http://mail.python.org/mailman/listinfo/python-list
Re: python connect to db2
yuzx wrote: i try to connect to db2 use python,i find it on python-db2 doc: $ python import DB2 conn = DB2.connect(dsn='sample', uid='db2inst1', pwd='ibmdb2') curs = conn.cursor() but i don't know about dsn, It's the host name. In a former project (using module DB2 together with 'IBM DB2 Connect' to access OS/390 database via TCP/IP) I had to invoke a special catalog db2 script before being able to use the host name. Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: What strategy for random accession of records in massive FASTA file?
Jeff Shannon wrote: Chris Lasher wrote: And besides, for long-term archiving purposes, I'd expect that zip et al on a character-stream would provide significantly better compression than a 4:1 packed format, and that zipping the packed format wouldn't be all that much more efficient than zipping the character stream. This 105MB FASTA file is 8.3 MB gzip-ed. And a 4:1 packed-format file would be ~26MB. It'd be interesting to see how that packed-format file would compress, but I don't care enough to write a script to convert the FASTA file into a packed-format file to experiment with... ;) Short version, then, is that yes, size concerns (such as they may be) are outweighed by speed and conceptual simplicity (i.e. avoiding a huge mess of bit-masking every time a single base needs to be examined, or a human-(semi-)readable display is needed). (Plus, if this format might be used for RNA sequences as well as DNA sequences, you've got at least a fifth base to represent, which means you need at least three bits per base, which means only two bases per byte (or else base-encodings split across byte-boundaries) That gets ugly real fast.) Jeff Shannon Technician/Programmer Credit International Hello, Just to clear up a few things on the topic : If the file denotes DNA sequences there are five basic identifiers AGCT and X (where X means 'dunno!'). If the files denoites RNA sequences, you will still only need five basic indentifiers the issue is that the T is replaced by a U. One very good way I have found to parse large files of this nature (I've done it with many a use case) is to write a sax parser for the file. Therefore you can register a content handler, receive events from the sax parser and do whatever you like with it. Basically, using the sax framework to read the files - if your write the sax parser carefully then you stream the files and remove old lines from memory, therefore you have a scalable solution (rather than keeping everything in memory). As an aside, I would seriously consider parsing your files and putting this information in a small local db - it's really not much work to do and the 'pure' python thing is a misnomer, whichever persistence mechanism you use (file,DB,etching it on the floor with a small robot accepting logo commands,etc) is unlikely to be pure python. The advantage of putting it in a DB will show up later when you have fast and powerful retrieval capability. Cheers, Neil -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : [EMAIL PROTECTED] Cenix Website : http://www.cenix-bioscience.com -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils linux script installation broken? Sorted
Problem solved. I was actually using scipy_distutils and not distutils, without good reason. Changing setup.py to use distutils made the problem go away. Cory. Cory Davis wrote: Hi all, I have been successfully deploying my own python package with distutils for some time now, but lately, with Python 2.4, the build_scripts command has been behaving badly. In the part where it is supposed to adjust the first line of the script it now produces #!None instead of #!/whereverpythonis/python Has anyone else encountered this? Cheers, Cory. -- http://mail.python.org/mailman/listinfo/python-list
Re: Debian says Warning! you are running an untested version of Python. on 2.3
rbt wrote: Nick Craig-Wood wrote: Alex Stapleton [EMAIL PROTECTED] wrote: Whenever I run python I get Warning! you are running an untested version of Python. prepended to the start of any output on stdout. This is with Debian and python 2.3 (running the debian 2.1 and 2.2 binaries doesn't have this effect) What version of a) Debian and b) python are you running? I don't have that problem here (I'm running testing/sarge) Same here... Debian testing with Python2.3 no problem. Perhaps he's running Debian unstable? Same result here on unstable, no problem. And experimental has no python2.3 package. However, I remember vaguely about something like this. Perhaps the OP is running an old unstable version, never upgraded ? -- Amand Tihon -- http://mail.python.org/mailman/listinfo/python-list
Re: import problems *newbie*
Le 13 Jan 2005 21:58:36 -0800, mike kreiner a écrit : I am having trouble importing a module I created. I'm running PythonWin on Windows XP if that helps. I saved my module in a folder called my_scripts in the site-packages directory. I edited the python path to include the my_scripts folder (it now reads C:\Python23\Lib;C:\Python23\DLLs;C:\Python23\Lib\lib-tk;C:\Python23\Lib\site-packages\my_scripts). Not a very godd idea to mess with the python path When I try to import the module, I get this error: from PolyDraw import * Traceback (most recent call last): File interactive input, line 1, in ? ImportError: No module named PolyDraw When I select Browse PythonPath from the tools menu, I'm able to locate my module, PolyDraw.py. The problem goes away if I open PolyDraw.py from PythonWin, which I'm assuming is because opening the module makes my_scripts the current working directory. This is just a quick workaround, but I'd like to know how to fix the problem. Thanks. A quick fix is to promote your my_scripts folder to be a python package, by creating a python module (file) named __init__.py right in the package directory. The content of __init__.py can be for instance #!/usr/bin/env python # -*- coding: Latin-1 -*- my_scripts package containing miscellaneous modules PolyDraw __author__ = 'mike kreiner' To import from this package the syntax is from my_scripts import PolyDraw -Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Op 2005-01-14, Fredrik Lundh schreef [EMAIL PROTECTED]: Paul Rubin wrote: Huh? Expressions are not statements except when they're expression statements? What kind of expression is not an expression statement? any expression that is used in a content that is not an expression statement, of course. Come on, that is vacuous. The claim was expressions are not statements. But it turns out that expressions ARE statements. no, expressions CAN BE USED as statements. that doesn't mean that they ARE statements, unless you're applying belgian logic. No I am applying set logic. Any string that is in the set of valid expressions is also in the set of valid statements. Like any animal that is in the set of dogs is also in the set of mamals. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
oddities in the datetime module
# -*- coding: latin-1 -*- I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it should be used? I can make a datetime easily enough datetime(2005, 1, 1) datetime.datetime(2005, 1, 1, 0, 0) What I find odd is that I cannot make a new datetime object from the timetuple() like this: d1 = datetime(2005, 1, 1, 12, 13, 10) d2 = datetime(*d1.timetuple()) Traceback (most recent call last): ... TypeError: function takes at most 8 arguments (9 given) d1.timetuple() (2005, 1, 1, 12, 13, 10, 5, 1, -1) Because if I subclass datetime, I often need to convert between my subclass and the built in datetime module. But there is no direct way to do it. Instead I have to do it in a somewhat more clunky way: datetime(* (d1.timetuple()[:6] + (0, d1.tzinfo))) datetime.datetime(2005, 1, 1, 12, 13, 10) if I want to convert a date to a datetime it is easy, even though I still have to truncate the timetuple. d = date(2005, 1, 1) datetime(*d.timetuple()[:6]) datetime.datetime(2005, 1, 1, 0, 0) The other way around is also easy. dt = datetime(2005, 1, 1, 12, 0, 0) date(*dt.timetuple()[:3]) datetime.date(2005, 1, 1) But it's a clunky design that I have to do it that way. I think it would be nice if date and datetime at least had a pair of datetimetuple() and from_datetimetuple() methods that could be used for easily converting between datetime types. Like the ones I have made below. That would make them a lot more symmetric. datetimetuple = (2005,1,1,12,0,0,0,None) datetime2.from_datetimetuple(datetimetuple) datetime2(2005, 1, 1, 12, 0) dtt = datetime2(2005,1, 1).datetimetuple() dtt (2005, 1, 1, 0, 0, 0, 0, None) d2 = date2.from_datetimetuple(dtt) d2 date2(2005, 1, 1) datetime2.from_datetimetuple(d2.datetimetuple()) datetime2(2005, 1, 1, 0, 0) from datetime import datetime, date class datetime2(datetime): def datetimetuple(self): return self.timetuple()[:6] + (0, self.tzinfo) def from_datetimetuple(dt_tuple): return datetime2(*dt_tuple) from_datetimetuple = staticmethod(from_datetimetuple) class date2(date): def datetimetuple(self): return self.timetuple()[:6] + (0, None) def from_datetimetuple(dt_tuple): return date2(*dt_tuple[:3]) from_datetimetuple = staticmethod(from_datetimetuple) #from datetime import datetime # #ical = Calendar() #print ical.ical() if __name__ == __main__: import os.path, doctest, x # import and test this file doctest.testmod(x) -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
On Thu, 13 Jan 2005 16:50:56 -0500, Leif K-Brooks [EMAIL PROTECTED] wrote: Tim Roberts wrote: Stephen Thorne [EMAIL PROTECTED] wrote: I would actually like to see pychecker pick up conceptual errors like this: import datetime datetime.datetime(2005, 04,04) Why is that a conceptual error? Syntactically, this could be a valid call to a function. Even if you have parsed and executed datetime, so that you know datetime.datetime is a class, it's quite possible that the creation and destruction of an object might have useful side effects. I'm guessing that Stephen is saying that PyChecker should have special knowledge of the datetime module and of the fact that dates are often specified with a leading zero, and therefor complain that they shouldn't be used that way in Python source code. It would be useful if PyChecker warned you when you specify an octal literal and where the value would differ from what you might expect if you didn't realise that you were specifying an octal literal. x = 04 # This doesn't need a warning: 04 == 4 #x = 09 # This doesn't need a warning: it will fail to compile x= 012 # This *does* need a warning: 012 == 10 -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Antoon Pardon wrote: no, expressions CAN BE USED as statements. that doesn't mean that they ARE statements, unless you're applying belgian logic. No I am applying set logic. Any string that is in the set of valid expressions is also in the set of valid statements. since you're arguing that one concept is identical to another concept, that operation has to work in both directions. Like any animal that is in the set of dogs is also in the set of mamals. and all mammals are dogs? it this a language problem? do you have problems parsing the statements you reply to? even when someone explictly says Given that we are having this discussion in the context of, you chose to ignore that context. what's wrong with you? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Op 2005-01-14, Nick Coghlan schreef [EMAIL PROTECTED]: Antoon Pardon wrote: No I am applying set logic. Any string that is in the set of valid expressions is also in the set of valid statements. According to Python's grammar, this is not the case. It requires a NEWLINE or ; token on the end to turn the expression into a statement. Actually appending either of those tokens means the string is no longer an expression. Well you are correct, but by the same logic an expression_stmt isn't a statement either. In point of fact none of the specifics_stmt is a statement including an assignment. But changing statements to simple statements seems to make the assertion correct. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: file uploading via urllib2 (multipart/form-data)
Clark C. Evans wrote: Hello. I was wondering if anyone has built a module that works with urllib2 to upload file content via POST multipart/form-data. I'm aware of ASPN 146306, however, I need to use urllib2 beacuse I'm using HTTP Digest over SSL. Cheers, Clark There is an example showing exactly that over at voidspace. I think it's on the cgi page, as it is a companion to the cgi demo showing how to receive file uploads. Try : http://www.voidspace.org.uk/python/cgi.shtml Regards, Fuzzy http://www.voidspac.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Fredrik no, expressions CAN BE USED as statements. that doesn't mean Fredrik that they ARE statements, unless you're applying belgian logic. Hmmm... I'd never heard the term belgian logic before. Googling provided a few uses, but no formal definition (maybe it's a European phrase so searching for it in English is futile). The closest thing I found was Or is it another case of Belgian logic, where you believe it because theres no evidence or motive whatsoever? Fredrik no, it's Python, and it's designed this way on purpose. go Fredrik read the language reference. What he said... While Python borrows stuff from other languages where they fit, it has a few core syntactic features that taken together distinguish it from other languages. Not allowing any statements to be used as expressions is one of them. Note that both expression and statement are context-sensitive terms. Fredrik applied them in their Python sense (go read the language reference), while Paul (perhaps naively, perhaps provocatively) seems bent on forcing a more general definition of the two words on the thread. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Op 2005-01-14, Fredrik Lundh schreef [EMAIL PROTECTED]: Antoon Pardon wrote: no, expressions CAN BE USED as statements. that doesn't mean that they ARE statements, unless you're applying belgian logic. No I am applying set logic. Any string that is in the set of valid expressions is also in the set of valid statements. since you're arguing that one concept is identical to another concept, that operation has to work in both directions. No I'm not. is doesn't mean the concepts are the same. Like any animal that is in the set of dogs is also in the set of mamals. and all mammals are dogs? No but every dog is a mammal, and saying that doesn't imply dog and mammal are identical concepts it this a language problem? do you have problems parsing the statements you reply to? even when someone explictly says Given that we are having this discussion in the context of, you chose to ignore that context. what's wrong with you? Well IMO I have explained clearly that I understood this in a set logical sense in my first response. It seems you chose to ignore that context. So what's wrong with you? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: finding/replacing a long binary pattern in a .bin file
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon [EMAIL PROTECTED] wrote: Bengt Richter wrote: BTW, I'm sure you could write a generator that would take a file name and oldbinstring and newbinstring as arguments, and read and yield nice os-file-system-friendly disk-sector-multiple chunks, so you could write fout = open('mynewbinfile', 'wb') for buf in updated_file_stream('myoldbinfile','rb', oldbinstring, newbinstring): fout.write(buf) fout.close() What happens when the bytes to be replaced are broken across a block boundary? ISTM that neither half would be recognized I believe that this requires either reading the entire file into memory, to scan all at once, or else conditionally matching an arbitrary fragment of the end of a block against the beginning of the oldbinstring... Given that the file in question is only a few tens of kbytes, I'd think that doing it in one gulp is simpler. (For a large file, chunking it might be necessary, though...) Might as well post this, in case you're interested... warning, not very tested. You want to write a proper test? ;-) sreplace.py - def sreplace(sseq, old, new, retsize=4096): iterate through sseq input string chunk sequence treating it as a continuous stream, replacing each substring old with new, and generating a sequence of retsize returned strings, except that the last may be shorter depedning on available input. inbuf = '' endsseq = False out = [] start = 0 lenold = len(old) lennew = len(new) while not endsseq: start, endprev = old and inbuf.find(old, start) or -1, start if start0: start = endprev # restore find start pos for chunk in sseq: inbuf+= chunk; break else: out.append(inbuf[start:]) endsseq = True else: out.append(inbuf[endprev:start]) start += lenold out.append(new) if endsseq or sum(map(len, out))=retsize: s = ''.join(out) while len(s)= retsize: yield s[:retsize] s = s[retsize:] if endsseq: if s: yield s else: out = [s] if __name__ == '__main__': import sys args = sys.argv[:] usage = Test usage: [python] sreplace.py old new retsize [rest of args is string chunks for test] where old is old string to find in chunked stream and new is replacement and retsize is returned buffer size, except that last may be shorter if not args[1:]: raise SystemExit, usage try: args[3] = int(args[3]) args[0] = iter(sys.argv[4:]) print '%r\n---\n%s\n' %(sys.argv[1:], '\n'.join(sreplace(*args[:4]))) except Exception, e: print '%s: %s' %(e.__class__.__name__, e) raise SystemExit, usage As mentioned, not tested very much beyond what you see: [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 20 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '20', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- Thisis_XX_andabc_XX_ def012_XX_345zz_XX__ XX_zzz_XX_ [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 80 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- Thisis_XX_andabc_XX_def012_XX_345zz_XX__XX_zzz_XX_ [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 4 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '4', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- This is_X X_an dabc _XX_ def0 12_X X_34 5zz_ XX__ XX_z zz_X X_ [ 2:44] C:\pywk\utpy24 sreplace.py def DEF 80 This is x and abcxdef 012x345 zzxx zzz x ['def', 'DEF', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- ThisisxandabcxDEF012x345zzxxzzzx If you wanted to change a binary file, you'd use it something like (although probably let the default buffer size be at 4096, not 20, which is pretty silly other than demoing. At least the input chunks are 512 ;-) from sreplace import sreplace fw = open('sreplace.py.txt','wb') for buf in sreplace(iter(lambda f=open('sreplace.py','rb'):f.read(512), ''),'out','OUT',20): ... fw.write(buf) ... fw.close() ^Z [ 3:00] C:\pywk\utdiff -u sreplace.py sreplace.py.txt --- sreplace.py Fri Jan 14 02:39:52 2005 +++ sreplace.py.txt Fri Jan 14 03:00:01 2005 @@ -7,7 +7,7 @@ inbuf = '' endsseq = False -out = [] +OUT = [] start = 0 lenold = len(old) lennew = len(new) @@ -17,21 +17,21 @@ start = endprev # restore find start pos for chunk in sseq: inbuf+= chunk; break
huygens lands on titan
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ -- http://mail.python.org/mailman/listinfo/python-list
Re: query python env
David Bear wrote: How does one query the python environment, ie pythonhome sys.prefix pythonpath sys.path etc. sys.etc also, are there any HOWTO's on keeping multiple versions of python happy? I think it is sufficiently trivial that none is needed. Just make sure the distributions are installed in different directories. What problems are you having? -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Skip Montanaro wrote: Fredrik no, expressions CAN BE USED as statements. that doesn't mean Fredrik that they ARE statements, unless you're applying belgian logic. Hmmm... I'd never heard the term belgian logic before. Googling provided a few uses, but no formal definition (maybe it's a European phrase so searching for it in English is futile). The closest thing I found was Or is it another case of Belgian logic, where you believe it because theres no evidence or motive whatsoever? Maybe it's Belgain logic, as opposed to Dutch logic. -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list
Re: (objects as) mutable dictionary keys
I have summarized the discussion about the usability of lists (and and other mutable types) as dictionary keys and put it into the Python wiki.URL: http://www.python.org/moin/DictionaryKeys. This summary might be used as a reference should the 'mutable dictionary keys' issue come up again in c.l.py. -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Using Sqlite with Python under Windows
Hello guys, I succeeded in convincing my CS teacher to use Python and Sqlite instead of Microsoft Access to get started with databases. We are working on a windows terminal server to which I have no admin access, so I'd like to ask you which module is best suited to use Sqlite with Python under windows. The best would be a module which is easy to install without further dependencies. Thanks in advance, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Python.org, Website of Satan
Peter Renzland wrote: What is the simplest/fastest Python program to determine how many IP addresses sum up to 666? The simplest/fastest enumerator? The simplest/fastest that determines which ones of them are home pages? This seems to work although it could be made more efficient or elegant. Also, the failed gethostbyaddr() calls take forever. from socket import gethostbyaddr, herror for a in xrange(256): if a 666-255*3: continue for b in xrange(256): if a+b 666-255*2: continue for c in xrange(256): if a+b+c 666-255: continue for d in xrange(256): if a + b + c + d == 666: ip_address = %d.%d.%d.%d % (a, b, c, d) try: hostname, aliaslist, ipaddrlist = gethostbyaddr(ip_address) except herror: hostname = NONE print hostname, ip_address break -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Statement local namespaces summary (was Re: python3: 'where' keyword)
Nick Coghlan wrote: as equivalent to: def __use_stmt(): use-suite def _in_clause(): in-suite return names return _in_clause() __use_stmt_args = {} names = __use_stmt() del __use_stmt The more I think about this return-based approach, the less I like it. It could probably be made to work, but it just feels like a kludge to work around the fact that the only mechanisms available for altering the bindings of local names are assignment and definition statements. For class namespaces, getattr(), setattr() and delattr() work a treat, and globals() works fine for module level name binding. locals() is an unfortunate second class citizen, since it writes to it aren't propagated back to the executing frame. Programmatic interrogation of locals is fine, but update is impossible. What would be interesting is if locals() returned a dictionary whose __setitem__ method invoked PyFrame_LocalsToFast on the relevant frame, instead of a vanilla dictionary as it does now. Then locals()[x] = foo would actually work properly. Notice that you can get this effect today, by using exec to force invocation of PyFrame_LocalsToFast: Py def f(): ... n = 1 ... def g(outer=locals()): ...outer[n] += 1 ... g() # Does not affect n ... print n ... exec g() # DOES affect n ... print n ... Py f() 1 2 (The call to g() has to be inside the exec statement, since the exec statement evaluation starts with a call to PyFrame_FastToLocals). Assuming a writeable locals(), the semantics for the normal case are given by: def __use_stmt(__outer): use-suite in-suite __inner = locals() for name in names: __outer[name] = __inner[name] __use_stmt(locals()) del __use_stmt And for the 'delayed execution' case: def __named_use_stmt(__outer): use-suite def __delayed_block(): in-suite __inner = locals() for name in names: __outer[name] = __inner[name] return __delayed_block in-name = __named_use_stmt(locals()) del __named_use_stmt Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop google from messing Python code
Xah Lee wrote: gmane is great! its renaming of newsgroups is quite a headache. i found that comp.lang.python corresponds to gmane.comp.python.general. do you know which one corresponds to comp.lang.perl.misc? there's no .misc or .general... -- i thought there a strick like preceding a line by -- or something that prevents google from reformating the post. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html I guess that most people use google to post to newsgroups is that they don't have nntp access. Telling htem to use a newsreader is facetious and unhelpful. Google strips leading whitespace. Putting *anything* before indentation stops the formatting getting messed up. It doesn't stop long lines being wrapped of course. Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: huygens lands on titan
John Thingstad wrote: -- huygens lands on titan Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ I bet it didn't... Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Craig Ringer schrieb: And then we have iteration (generator expressions, list comprehensions, for loops, ...?) over (sequences, iterators, generators) Just sequences and iterators. Generators are functions which return iterators. Sequences and iterators provide two ways to build containers. My use cases: finite, can be defined by enumeration: use sequence infinite, must be defined algorithmically: use iterator generator: neat way to produce an iterator, can also be viewed as a persistent function call (better than static local variables). Once defined, sequences and iterators have nearly the same interface. To have list comprehensions but no equivalent for iterators would be strange. I happen to be extremely fond of the flexibility this provides, but one obvious way to do it there is not. Development of the language, backward compatibility and obviousness are diverging goals. You can't satisfy them all at the same time. And goals provide a direction but are rarely reached. :) -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Static executable with shared modules
Is there any way to build the python executable statically and still be able to load modules built as shared libraries? I'm trying to run python scripts on a stripped down FreeBSD (4.9) machine which has no shared system libraries so I want to link it statically against libc et al, but it would be nice to still be able to load modules which were built as shared libraries. In particular I have a library for which I've generated a wrapper with swig which I'd like to import. I've googled up and down but can't find anyone who has tried this particular combination. Just adding a -static to the Makefile seems to remove the ability to load shared libraries altogether as I get a ImportError: Service unavailable exception. /r -- http://mail.python.org/mailman/listinfo/python-list
Re: porting C code
Peter Hansen wrote: Lucas Raab wrote: I have the statement: typedef unsigned long int word32 and later on: word32 b[3] referencing the third bit of the integer. If that's really exactly what you have, then you actually have something defining an array of three unsigned long integers named b. And even if you didn't have precisely word32 b[3], but merely a b[3] reference somewhere, it would be referencing the third element of an array called b, which is possibly a byte, maybe a long, but definitely not a bit. Maybe showing it as code rather than inline in your text would avoid the possibility of confusion. -Peter Sorry, the third byte is what I meant. As for code samples, I hope the following will work: typedef unsigned long int word32 ; void mu(word32 *a) { int i ; word32 b[3] ; b[0] = b[1] = b[2] = 0 ; for( i=0 ; i32 ; i++ ) { b[0] = 1 ; b[1] = 1 ; b[2] = 1 ; if(a[0]1) b[2] |= 1 ; if(a[1]1) b[1] |= 1 ; if(a[2]1) b[0] |= 1 ; a[0] = 1 ; a[1] = 1 ; a[2] = 1 ; } a[0] = b[0] ; a[1] = b[1] ; a[2] = b[2] ; } The a[#] and b[#] are the parts that are giving me trouble. -- http://mail.python.org/mailman/listinfo/python-list
Re: porting C code
Lucas Raab wrote: Sorry, the third byte is what I meant. As for code samples, I hope the following will work: typedef unsigned long int word32 ; void mu(word32 *a) { int i ; word32 b[3] ; b[0] = b[1] = b[2] = 0 ; for( i=0 ; i32 ; i++ ) { b[0] = 1 ; b[1] = 1 ; b[2] = 1 ; if(a[0]1) b[2] |= 1 ; if(a[1]1) b[1] |= 1 ; if(a[2]1) b[0] |= 1 ; a[0] = 1 ; a[1] = 1 ; a[2] = 1 ; } a[0] = b[0] ; a[1] = b[1] ; a[2] = b[2] ; } The a[#] and b[#] are the parts that are giving me trouble. So far as I can tell, the function takes an array of 3 32bit values, reverses the order of the bits in each value, and swaps the first and last elements of the array. All of this seems to be being done in an attempt to make the process as obscure and inefficient as possible both by using meaningless names, and by doing both operations simultaneously. To convert this to Python I might try something like: rev2 = [ 0, 0x02, 0x01, 0x03 ] rev4 = [ (lo|hi2) for lo in rev2 for hi in rev2 ] rev8 = [ (lo|hi4) for lo in rev4 for hi in rev4 ] def rev32(n): '''Reverse the low 32bits of an integer''' return (rev8[(n24)0xff]| (rev8[(n16)0xff]8)| (rev8[(n8)0xff]16)| (rev8[n0xff]24)) def mu(a): '''Reverse the bit order of a list of 32bit integers while also reversing the list itself''' return [rev32(n) for n in reversed(a)] print [hex(n) for n in mu([0x10203040, 0x50607080, 0x90a0b0c0])] Although if 'a' really is just being used as a 96 bit integer I could add a 96 bit variant of the reversal function and use it directly: def rev96(n): '''Reverse the low 96bits of an integer''' return rev32(n64)|(rev32(n32)32)|(rev32(n)64) print hex(rev96(0x102030405060708090a0b0c0L)) -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie q
On Fri, 14 Jan 2005 00:08:09 GMT, rumours say that [EMAIL PROTECTED] (Bengt Richter) might have written: As I'm sure you know, with 2.4's generator expressions you don't have to build the temporary list. Which could be important if 'something' is (or generates) a huge sequence. for i in (x[0] for x in something): and for some functional fun: from itertools import imap from operator import itemgetter for i in imap(itemgetter(0), something): -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickled text file causing ValueError (dos/unix issue)
[Aki Niimura] I started to use pickle to store the latest user settings for the tool I wrote. It writes out a pickled text file when it terminates and it restores the settings when it starts. ... I guess DOS text format is creating this problem. Yes. My question is Is there any elegant way to deal with this?. Yes: regardless of platform, always open files used for pickles in binary mode. That is, pass rb to open() when reading a pickle file, and wb to open() when writing a pickle file. Then your pickle files will work unchanged on all platforms. The same is true of files containing binary data of any kind (and despite that pickle protocol 0 was called text mode for years, it's still binary data). -- http://mail.python.org/mailman/listinfo/python-list
[Fwd: Re: Embedding Multiplr Python interpreter in C++]
Yogesh Sharma [EMAIL PROTECTED] wrote: one more question to add: Is there a way to have 2 local copies of python interpreter ? Yogesh Sharma wrote: Hi, I have following setup: OS Linux Fedora Core 3 Python 2.3.4 How can I embed two python interpreters in one C++ program ? Thanks Take a look at mod_python's code: that allows several independent interpreters in the same Apache process using Py_NewInterpreter(), which may well be what you want - initially, see http://www.modpython.org/live/mod_python-3.1.3/doc-html/pyapi-interps.html regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Skip Montanaro wrote: Fredrik no, expressions CAN BE USED as statements. that doesn't mean Fredrik that they ARE statements, unless you're applying belgian logic. Hmmm... I'd never heard the term belgian logic before. Googling provided a few uses, but no formal definition (maybe it's a European phrase so searching for it in English is futile). The closest thing I found was Or is it another case of Belgian logic, where you believe it because theres no evidence or motive whatsoever? Fredrik no, it's Python, and it's designed this way on purpose. go Fredrik read the language reference. snip IANA French person, but I believe that Belgians are traditionally regarded as stupid in French culture, so Belgian logic would be similar to Irish logic for an English person. (Feel free to insert your own cultural stereotypes as required. :) -- Website: www DOT jarmania FULLSTOP com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to list the global functions from a C program
On Fri, Jan 14, 2005 at 04:01:13PM +0100, Francesco Montorsi wrote: snip PyObject *list = PyObject_Dir(m_pGlobals); if (!list || PyList_Check(list) == FALSE) return; for (int i=0,max=PyList_Size(list); imax; i++) { PyObject *elem = PyList_GetItem(list, i); if (PyCallable_Check(elem) != 0) { /* this should be a function.. */ /* HERE IS THE PROBLEM: this code is never reached */ PyObject *str = PyObject_GetAttrString(elem, func_name); } } == Everything seems to work but then when scanning the list returned by PyObject_Dir() I never find any callable object what am I doing wrong ? You are checking the list of strings returned from the dir() to see if any of them are callable (they aren't). You mean to check the thing that the string is a name for, so instead of # callable(name) PyCallable_Check(elem) use # callable(globals()[name]) PyCallable_Check(PyDict_GetItem(m_pGlobals, elem)) -Jack -- http://mail.python.org/mailman/listinfo/python-list
Re: import problems *newbie*
F. Petitjean wrote: Le 13 Jan 2005 21:58:36 -0800, mike kreiner a écrit : I am having trouble importing a module I created. I'm running PythonWin on Windows XP if that helps. I saved my module in a folder called my_scripts in the site-packages directory. I edited the python path to include the my_scripts folder (it now reads C:\Python23\Lib;C:\Python23\DLLs;C:\Python23\Lib\lib-tk;C:\Python23\Lib\site-packages\my_scripts). Not a very godd idea to mess with the python path Furthermore it should not be necessary! When I try to import the module, I get this error: from PolyDraw import * Traceback (most recent call last): File interactive input, line 1, in ? ImportError: No module named PolyDraw OK, have your modifications to the path worked? Try adding import sys print sys.path before the import statement to verify what Python is actually using as the path. When I select Browse PythonPath from the tools menu, I'm able to locate my module, PolyDraw.py. The problem goes away if I open PolyDraw.py from PythonWin, which I'm assuming is because opening the module makes my_scripts the current working directory. This is just a quick workaround, but I'd like to know how to fix the problem. Thanks. A quick fix is to promote your my_scripts folder to be a python package, by creating a python module (file) named __init__.py right in the package directory. The content of __init__.py can be for instance The __init__.py can actually be completely empty, but surely then you'd have to import the module by from my_scripts import PolyDraw which is a little less convenient. It would be easier (and also easier than modifying the PYTHONPATH) just to create a .pth file (say C:\Python23\Lib\site-packages\my.pth) containing the single line my_scripts and that should ensure that the directory really *is* on your path. The *name* of the .pth file is irrelevant, and you can actually have several lines naming different directories (whose paths can be absolute, or relative to the directory containing the .pth file). Obviously you should check that the path's setting is correct using the technique allowed above. #!/usr/bin/env python # -*- coding: Latin-1 -*- my_scripts package containing miscellaneous modules PolyDraw __author__ = 'mike kreiner' To import from this package the syntax is from my_scripts import PolyDraw Let's not recommend this as a way around the problem - let's find out what the problem actually *is* and fix it ;-) regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: Integration with java
Joachim Boomberschloss wrote: the code is already written in Python, using the standard libraries and several extension modules One thing to keep in mind is that Jython does not integrate CPython, instead it understands python code directly. So if you have a C extension that works with python it won't work with Jython. My feeling is that if you had a lot of Java code written and wanted to build on that with python Jython would be a better fit than vice versa. Istvan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing huge Sets() to disk
Tim Peters wrote: [Martin MOKREJ] ... I gave up the theoretical approach. Practically, I might need up to store maybe those 1E15 keys. We should work on our multiplication skills here wink. You don't have enough disk space to store 1E15 keys. If your keys were just one byte each, you would need to have 4 thousand disks of 250GB each to store 1E15 keys. How much disk space do you actually have? I'm betting you have no more than one 250GB disk. ... [Istvan Albert] On my system storing 1 million words of length 15 as keys of a python dictionary is around 75MB. Fine, that's what I wanted to hear. How do you improve the algorithm? Do you delay indexing to the very latest moment or do you let your computer index 999 999 times just for fun? It remains wholly unclear to me what the algorithm you want might be. As I mentioned before, if you store keys in sorted text files, you can do intersection and difference very efficiently just by using the Unix `comm` utiltity. This comm(1) approach doesn't work for me. It somehow fails to detect common entries when the offset is too big. file 1: A F G I K M N R V AA AI FG FR GF GI GR IG IK IN IV KI MA NG RA RI VF AIK FGR FRA GFG GIN GRI IGI IGR IKI ING IVF KIG MAI NGF RAA RIG file 2: W W W W W W W W W W AA AI FG FR GF GI GR IG IK IN IV KI MA NG RA RI VF A A A A A A A A A A A A -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing huge Sets() to disk
[Martin MOKREJ] This comm(1) approach doesn't work for me. It somehow fails to detect common entries when the offset is too big. file 1: A F G I K M N R V AA AI FG FR GF GI GR IG IK IN IV KI MA NG RA RI VF AIK FGR FRA GFG GIN GRI IGI IGR IKI ING IVF KIG MAI NGF RAA RIG file 2: W W W W W W W W W W AA AI FG FR GF GI GR IG IK IN IV KI MA NG RA RI VF A A A A A A A A A A A A I'll repeat: As I mentioned before, if you store keys in sorted text files ... Those files aren't in sorted order, so of course `comm` can't do anything useful with them. Do `man sort`; sorting is not optional here. -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050113 looking up syntax
Xah Lee wrote: - for perl syntax lookup, use perldoc in the command line. For example: perldoc perl Wrong. That command will give you a high-level overview of Perl but tell you nothing about the syntax. To lookup the Perl syntax you would have to use perldoc perlsyn use 'perldoc -f functionName' for specific function. example: perldoc -f qq BS. That will tell you what a function does, it doesn't tell you anything at all about the syntax of Perl. BTW: Why on earth are you using qq() as an example? That doc page just points you to 'perldoc perlop'. note that keywords cannot be looked up with -f. For basic keywords like if, while..., use perldoc perlop BS. What gave you the idea that keywords were operators? Of course keywords can be found where they belong, in the syntax definition of the language, but not in the operator section of the documentation. Why don't you just stop posting this nonsense? jue -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing huge Sets() to disk
Tim Peters wrote: [Martin MOKREJ] This comm(1) approach doesn't work for me. It somehow fails to detect common entries when the offset is too big. [...] I'll repeat: As I mentioned before, if you store keys in sorted text files ... Those files aren't in sorted order, so of course `comm` can't do anything useful with them. Do `man sort`; sorting is not optional here. I did read the manpage, but somehow it seems I did not execute sort(1) from within my python code, so it was unsorted and did did not realize it yet. Thanks! m. -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Skip Montanaro wrote: Fredrik no, expressions CAN BE USED as statements. that doesn't mean Fredrik that they ARE statements, unless you're applying belgian logic. Hmmm... I'd never heard the term belgian logic before. Googling provided a few uses, but no formal definition (maybe it's a European phrase so searching for it in English is futile). I'm from Belgium, and I've never heard it before either. Probably a public secret, very carefully being kept hidden from us Belgians ;) -- Codito ergo sum Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda
Antoon Pardon wrote: Op 2005-01-13, hanz schreef [EMAIL PROTECTED]: Antoon Pardon wrote: So if I have a call with an expression that takes more than one line, I should assign the expression to a variable and use the variable in the call? Yes, that's sometimes a good practice and can clarify the call. But wait if I do that, people will tell me how bad that it is, because it will keep a reference to the value which will prevent the garbage collector from harvesting this memory. Of course, unless that reference is in the global scope of the __main__ module its lifetime will be transient anyway. If the reference is stored in a function's local variable then unless its value is returned from the function it will become available for garbage collection when the function returns. Nobody will tell you that it's bad. Sorry, someone already did. If I recall correctly it was Alex Martelli. A foolish consistency is the hobgoblin of little minds. Rules are made to be broken. Besides which, if you don't understand the language environment, rules alone will do you very little good. Try to focus a little more on principles and a little less on minutiae. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Antoon Pardon wrote: IMO we have a: dogs are mamals kind of relationship in Python. I see what you mean, but I don't think it's true. Every expression can be used where a statement is expected. (And this can be worded as: every expression is a statement.) Not really. An expression statement is a statement that looks like an expression, but actually it's more than that: not only does it calculate the value of the expression, it also prints the value. Note that it would be perfectly possible to modify the syntax into expression_stmt ::= exprstmt expression_list so that you would have to write exprstmt 6*9 instead of just 6*9 That makes it clearer to see the distinction: 6*9 is an expression, exprstmt 6*9 is a statement. An expression statement, more precisely. Not every statement can be used where an expression is expected. AFAIK *no* statement can be used where an expression is expected. -- Codito ergo sum Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie ?s
Venkat B wrote: Hi folks, I'm looking build a CGI-capable SSL-enabled web-server around Python 2.4 on Linux. It is to handle ~25 hits possibly arriving at once. Content is non-static and built by the execution of py cgi-scripts talking to a few backend processes. 1) I was wondering if anyone has opinions on the ability of CGIHTTPServer (a forking variant) to be able to handle this. I wouldn't even consider it. The *HTTPServer modules aren't really intended to be much beyond a proof-of-concept, IMHO. Certainly you'd be likely to stress the system having 25 requests arrive in a bunch, though a modern computer would probably handle it. 2) If so, would something like pyOpenSSL be useful to make such a webserver SSL-enabled. There is a *lot* to do to SSL-enable a server. Since you advertise yourself as a newbie, I'd suggest there were better places to focus your efforts. I checked out John Goerzen's book: Foundations of Python Network Programming (ISBN 1590593715) and searched around. While I found how one can write py scripts that could communicate with SSL-enabled webservers, tips on building SSL-enabled webservers isn't obvious. I was hoping to build a cleaner solution around the CGIHTTPServer variant instead of say something like mini-httpd/OpenSSL/Python. I'd appreciate any pointers. I believe the Twisted package may be your best alternative, though this is at best hearsay since I am not (yet) an active user. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: import keyword behaviour - performance impact if used multiple times?
Nick Coghlan wrote: Is this something to do with system modules being singletons? They aren't singletons in the GoF design pattern sense. However, Python's import machinery operates in such a way that it takes effort to get multiple version of the same module into memory at the same time (it *can* be done, but you have to work at it). Given that this is exactly what I want, how can you do it? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie q
Bengt Richter wrote: On Thu, 13 Jan 2005 09:16:40 -0500, Steve Holden [EMAIL PROTECTED] wrote: [...] Any statement of the form for i in [x for x in something]: can be rewritten as for i in something: Note that this doesn't mean you never want to iterate over a list comprehension. It's the easiest way, for example, to iterate over the first item of each list in a list of lists: for i in [x[0] for x in something]: As I'm sure you know, with 2.4's generator expressions you don't have to build the temporary list. Which could be important if 'something' is (or generates) a huge sequence. for i in (x[0] for x in something): Yes. While I haven't yet done any more than play with generator sequences I do really feel that more of the best of Icon has arrived in Python with this new addition. something = ([x] for x in xrange(10,20)) something generator object at 0x02EF176C list(something) [[10], [11], [12], [13], [14], [15], [16], [17], [18], [19]] for i in (x[0] for x in something): print i, ... oops, that list() used it up ;-) something = [[x] for x in xrange(10,20)] for i in (x[0] for x in something): print i, ... 10 11 12 13 14 15 16 17 18 19 Really nice. I quite agree. It's particularly useful for infinite sequences :-) regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Op 2005-01-14, Roel Schroeven schreef [EMAIL PROTECTED]: Antoon Pardon wrote: IMO we have a: dogs are mamals kind of relationship in Python. I see what you mean, but I don't think it's true. Every expression can be used where a statement is expected. (And this can be worded as: every expression is a statement.) Not really. An expression statement is a statement that looks like an expression, but actually it's more than that: not only does it calculate the value of the expression, it also prints the value. 1) Only in an interactive environment. 2) That the semantics differ according to where the expression is used doesn't make a difference. That an expression decides which branch of an if statement is executed or what object is pass as an argument in a call are also semantic difference, yet we still have an expression in both cases. Note that it would be perfectly possible to modify the syntax into expression_stmt ::= exprstmt expression_list so that you would have to write exprstmt 6*9 instead of just 6*9 That makes it clearer to see the distinction: 6*9 is an expression, exprstmt 6*9 is a statement. An expression statement, more precisely. If you change the syntax, of course you will change the strings that will be accepted. I could change the syntax to: if_stmt ::= if ifexpr expression ... Have I now proved that expressions after an if are not normal expressions? Not every statement can be used where an expression is expected. AFAIK *no* statement can be used where an expression is expected. But that was not the implication of what Guido supposedly had said. So that this is not the case doesn't counter what I said. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop google from messing Python code
Fuzzyman [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Xah Lee wrote: gmane is great! I guess that most people use google to post to newsgroups is that they don't have nntp access. Anyone with a normal internet connection has nntp access. What some do not get from their ISP is 'free' access to a full newsite, and they may not feel like paying extra $$ to one when they can get free access to non-binary groups via Google that is better in regards to retention and search, Google just happens to not work well for posting Python code. What most of those people may not know is that there is free access to a restricted news site (gmane) which mirrors a large number of mailing lists, one of which is the Python mailing list, which mirrors the Python newsgroup. So I help them by giving them this information. Xah Lee used the information I shared, as have many other people, and even, in effect, thanked me for doing so. Gmane also gives a Pythoneer easy access to about 50 specialized Python-related mailing lists (and 1000s not related to Python). Telling htem to use a newsreader is facetious and unhelpful. Telling someone to stop sharing sharing useful information is nasty and unhelpful. You owe me an apology. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Antoon Pardon wrote: Well IMO I have explained clearly that I understood this in a set logical sense in my first response. what does first mean on your planet? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: (objects as) mutable dictionary keys
Peter Maas [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have summarized the discussion about the usability of lists (and and other mutable types) as dictionary keys and put it into the Python wiki.URL: http://www.python.org/moin/DictionaryKeys. This summary might be used as a reference should the 'mutable dictionary keys' issue come up again in c.l.py. The last piece has an incorrect conclusion. Lists are not safe _because_ the cmp function is NOT a compare of id(list), but is based on list contents, which can change at any time. It should also be emphasized that the default instance hash and cmp functions quoted make it impossible for two different instances to compare equal, thus there is no reason to store them as dictionary keys: it's simpler to make the value an attribute of the instance and bypass the additional complexity of the dictionary. John Roth -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode conversion in 'print'
Ricardo Bugalho wrote: thanks for the information. But what I was really looking for was informaion on when and why Python started doing it (previously, it always used sys.getdefaultencoding())) and why it was done only for 'print' when stdout is a terminal instead of always. It does that since 2.2, in response to many complains that you cannot print a Unicode string in interactive mode, unless the Unicode string contains only ASCII characters. It does that only if sys.stdout is a real terminal, because otherwise it is not possible to determine what the encoding of sys.stdout is. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Static executable with shared modules
Rickard Lind wrote: Is there any way to build the python executable statically and still be able to load modules built as shared libraries? I'm not what build statically means; if you talking about building a statically linked interpreter binary - then no, this is not possible. At a minimum, you need to link with -ldl, or else you cannot perform dlopen(3). I'm trying to run python scripts on a stripped down FreeBSD (4.9) machine which has no shared system libraries so I want to link it statically against libc et al, but it would be nice to still be able to load modules which were built as shared libraries. Does that system support shared libraries? What is the API for loading shared libraries, and finding a symbol in a dynamically-loaded shared library, on that system? In particular I have a library for which I've generated a wrapper with swig which I'd like to import. If shared libraries are not supported, you could link the swig module statically as well. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
python to mssql
can someone please give me some info regarding subject please advice regards brane -- http://mail.python.org/mailman/listinfo/python-list
RE: python to mssql
Brane wrote: can someone please give me some info regarding subject http://sourceforge.net/projects/mysql-python Ask a broad question... Robert Brewer MIS Amor Ministries [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Free python server.
[EMAIL PROTECTED] wrote: Your file probably need to (a) be in the cgi-bin, not public_html, (b) be flagged executable (chmod a+x file.py), and (c) begin with the line: '#!/usr/bin/env python' If the server doesn't provide you with CGI (or, strongly preferable, SCGI or mod_python), you're probably out of luck. You're probably right, this machine doesn't provide with CGI, I'll send an e-mail to administrator of arbornet.org and make sure. So, I ask once again: does anyone know where I can put my *.py files? Greetings. Rootshell. Hi, I just made a cgi script on rht earbornet machine. Process as follows mkdir public_html chmod 0755 public_html cd public_html mkdir cgi-bin chmod 0755 cgi-bin echo hello world index.html cd cgi-bin echo '#!/bin/sh echo content-type: text/html echo echo htmlhead/headbodyh1font color=redHello World!/font/h1/body/html ' hw.cgi chmod a+x hw.cgi then http://m-net.arbornet.org/~rgbecker/cgi-bin/hw.cgi gives a nice red hello world ie acts as a cgi script I also created the standard echo script pytestcgi.cgi as #!/usr/local/bin/python import cgi cgi.test() chmodded as before. See http://m-net.arbornet.org/~rgbecker/cgi-bin/pytestcgi.cgi Please don't misuse it's free and I'm no longer an American :) -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: module structure and import question
Thx Rob. yes i know it's related to search path, but i don't know how to set it in a practical way (beside hard coding). my concern is, if i want to create a custom module/library, i don't know what py file will import it and where the working directory should be. sometime like my example, even i don't know where the root directory of my module will place, and i expect it can place in anywhere, how should i set the sys.path? i know that maybe a stupid question, please forgive me, i'm just a newbie. i have read all online documents in python.org. but i wouldn't find the answer. yes, i'm asking is it normally only put one class in one py file. thanks for your advice. But if i put a set of classes in a py file as a module, will it increase the dependency of each class? back to my example, of course, i can put BaseA and ClassA together in one py file. what should i do when i need to add one more class later, ClassB, which also extend BaseA. Put it into the same file or in a new file? if put in in the same file, i think it should difficult to maintain versioning. i'm quite confuse in this, maybe because i learn Java before. Thx again, Rob. Rob Emmons [EMAIL PROTECTED] ??? news:[EMAIL PROTECTED] ???... hi all, i have question on how to design a module structure. for example, i have 3 files. [somewhere]/main.py [somewhere]/myLib/Base/BaseA.py [somewhere]/myLib/ClassA.py . It's fine when i run main.py. however when i run ClassA.py individually, it would fail in import statment since the import path is incorrect. I would like to know is something wrong in my design, or something i missed. I think your issue is your module search path. Take a look at the doc for sys.path in the library reference. These are the directories that python searchies for modules. Usually the . directory is included in this which makes python search the current working directory. Your example fails because your working directories are probably different when you ran the two modules. In any case always consider how you've setup sys.path and your libraries and modules. Also, in practical usage, is that one class in one py file? I'm not exactly clear what your asking -- but I think yor asking if you'd normally only put one class in one py file. My answer is no -- generally you'd put many functions and classes in each py file. Modules are high level and should be used to create libraries essentailly -- this means many fucntions and classes per module. Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))
Irmen de Jong wrote: Tim Peters wrote: Yes: regardless of platform, always open files used for pickles in binary mode. That is, pass rb to open() when reading a pickle file, and wb to open() when writing a pickle file. Then your pickle files will work unchanged on all platforms. The same is true of files containing binary data of any kind (and despite that pickle protocol 0 was called text mode for years, it's still binary data). I've been wondering why there even is the choice between binary mode and text mode. Why can't we just do away with the 'text mode' ? We can't because characters and bytes are not the same things. But I believe what you're really complaining about is that t mode sometimes mysteriously corrupts data if processed by the code that expects binary files. In Python 3.0 it will be fixed because file.read will have to return different objects: bytes for b mode, str for t mode. It would be great if file type was split into binfile and textfile, removing need for cryptic b and t modes but I'm afraid that's too much of a change even for Python 3.0 Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
[EMAIL PROTECTED] wrote: ... In Mythical Future Python I would like to be able to use any base in integer literals, which would be better. Example random syntax: flags= 2x00011010101001 umask= 8x664 answer= 10x42 addr= 16x0E84 # 16x == 0x gunk= 36x8H6Z9A0X I'd prefer using the leftmost character as a two's complement extension bit. 0x1 : 1 in hex notation 1xf : -1 in hex notation, or conceptually an infinitely long string of 1s 0c12 : 10 in octal noataion 1c12 : -54 in octal (I think) 0d12 : 12 in decimal 0b10 : 2 in binary etc I leave it to the reader to decide whether I'm joking. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why 'r' mode anyway?
Tim Peters wrote: That differences may exist is reflected in the C standard, and the rules for text-mode files are more restrictive than most people would believe. Apparently. Because I know only about the Unix - Windows difference (windows converts \r\n -- \n when using 'r' mode, right). So it's in the line endings. Is there more obscure stuff going on on the other systems you mentioned (Mac OS, VAX) ? (That means that the bug in Simplehttpserver that my patch 839496 addressed, also occured on those systems? Or that the patch may be incorrect after all??) While your argument about why Python doesn't use its own platform- independent file format is sound ofcourse, I find it often a nuisance that platform specific things tricle trough into Python itself and ultimately in the programs you write. I sometimes feel that some parts of Python expose the underlying C/os implementation a bit too much. Python never claimed write once run anywhere (as that other language does) but it would have been nice nevertheless ;-) In practice it's just not possible I guess. Thanks, --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Com port interrupts again
A search on google gave me this library, I haven't tested it though: http://groups-beta.google.com/group/comp.lang.python.announce/browse_frm/thread/6d3263250ed65816/291074d7bd94be63?q=com+port+python_done=%2Fgroups%3Fhl%3Den%26lr%3D%26safe%3Doff%26q%3Dcom+port+python%26qt_s%3DSearch+Groups%26_doneTitle=Back+to+Searchd#291074d7bd94be63 -- http://mail.python.org/mailman/listinfo/python-list
Re: python to mssql
Brane wrote: can someone please give me some info regarding subject From Windows machine: http://adodbapi.sourceforge.net/ From elsewhere: FreeTDS + unixODBC + mxODBC is one of possible solutions. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ -- http://mail.python.org/mailman/listinfo/python-list
reusing Tkinter Canvases
I'd like to save one Tkinter Canvas in order to use it on another Canvas later. The problem is that it gets saved as EPS but it needs to be GIF to be reuseable. How can I convert that format? Peace, STM -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Sqlite with Python under Windows
Thanks, for the link -- http://mail.python.org/mailman/listinfo/python-list
Re: python to mssql
Robert Brewer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Brane wrote: can someone please give me some info regarding subject http://sourceforge.net/projects/mysql-python Ask a broad question... Robert Brewer Robert, the question was about 'mssql', not 'mysql'. As for mssql, a search on google will give you the following as the first result: http://pymssql.sourceforge.net/ with others on the page that include: http://www.object-craft.com.au/projects/mssql/ http://www.egenix.com/files/python/eGenix-mx-Extensions.html Don't be lazy, Brane. Your first point of reference should _always_ be google. The fact that I'm Feeling Lucky points you to pymssql shows that you didn't do any research before posting here. -Noah -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickled text file causing ValueError (dos/unix issue)
On Fri, 14 Jan 2005 09:12:49 -0500, Tim Peters [EMAIL PROTECTED] wrote: [Aki Niimura] I started to use pickle to store the latest user settings for the tool I wrote. It writes out a pickled text file when it terminates and it restores the settings when it starts. ... I guess DOS text format is creating this problem. Yes. My question is Is there any elegant way to deal with this?. Yes: regardless of platform, always open files used for pickles in binary mode. That is, pass rb to open() when reading a pickle file, and wb to open() when writing a pickle file. Then your pickle files will work unchanged on all platforms. The same is true of files containing binary data of any kind (and despite that pickle protocol 0 was called text mode for years, it's still binary data). Tim, the manual as of version 2.4 does _not_ mention the need to use 'b' on OSes where it makes a difference, not even in the examples at the end of the chapter. Further, it still refers to protocol 0 as 'text' in several places. There is also a reference to protocol 0 files being viewable in a text editor. In other words, enough to lead even the most careful Reader of TFM up the garden path :-) Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Index server
Is there an Index server available in Python? For example: I have large intranet with several servers and I would like to index documents like search engines do. Users then can search for a domument in ALL intranet servers like I do on Google. Thanks for answers L.A. -- http://mail.python.org/mailman/listinfo/python-list
Re: oddities in the datetime module
Max M wrote: # -*- coding: latin-1 -*- I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it should be used? Yes, you did. datetime.timetuple is those who want *time module* format, you should use datetime.data, datetime.time, datetime.year and so on... [snip a lot of timetuple wrestling] The other way around is also easy. dt = datetime(2005, 1, 1, 12, 0, 0) date(*dt.timetuple()[:3]) datetime.date(2005, 1, 1) As they say, if the only tool you have is timetuple, everything looks like tuple wink Try this: dt = datetime(2005, 1, 1, 12, 0, 0) dt.date() datetime.date(2005, 1, 1) Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why would I get a TypeEror?
Say again??? Reinhold Birkenfeld [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] It's me wrote: Sorry if my question was a little lazy and yes, I was asking about the lazy evaluation. :=) I am surprised about this (and this can be dangerous, I guess). If this is true, I would run into trouble real quick if I do a: (1/x,1.0e99)[x==0] and that's not good. Something to keep in mind. :-( Lazy evaluation: use the (x==0 and 1e99 or 1/x) form! Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading Or Other Suggestions?!?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: I have a wxPython application that does a lot of things. One of them, in particular, I have doubts on how to implement it. Essentially, this part of my application calls an external executable (an oil reservoir simulator). What I would like to do, is to give the user the possibility to run more than 1 simulation at the same time. This means: 1) Writing the executable data file needed by the simulator 2) Run the executable file (and wait until completion) 3) Examine the simulation results For this, I was thinking about threads... does anyone have other/better suggestion(s)? Does anyone see any difficulty/memory problems in using threads? If you're not on Windows, this will be much easier with multiple processes. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ 19. A language that doesn't affect the way you think about programming, is not worth knowing. --Alan Perlis -- http://mail.python.org/mailman/listinfo/python-list
Re: Python.org, Website of Satan
Brian Eable wrote: perl -e '$a=194.109.137.226; @a = reverse split /\./, $a; for $i (0..3) { $sum += $a[$i]*(256**$i) } print sum = $sum\n' 226 + 35072 + 7143424 + 3254779904 = 3261958626 http://3261958626/ Which is NOT 666. Comrade, why perl here? :) Are you afraid python? :) -- http://mail.python.org/mailman/listinfo/python-list
Re: why are people still using classic classes?
Peter Hansen wrote: Paul Rubin wrote: Simon Wittber [EMAIL PROTECTED] writes: Is there a reason NOT to use them? If a classic class works fine, what incentive is there to switch to new style classes? Perhaps classic classes will eventually disappear? It just means that the formerly classic syntax will define a new-style class. Try to write code that works either way. Unfortunately, if we should follow the recent advice about always using super() in the __init__ method, it's hard to do what you suggest (though it sounds like good advice) without resorting to extreme ugliness: class Classic: def __init__(self): super(Classic, self).__init__() c = Classic() Traceback (most recent call last): File stdin, line 1, in ? File stdin, line 3, in __init__ TypeError: super() argument 1 must be type, not classobj Could classic classes ever be removed without us having manually to fix all __init__ calls to the superclass? That's not really an issue unless there's a diamond-shaped inheritance graph and linearisation of the the super classes is required to ensure that things stay sane. Remembering that the MO for classic classes and types are rather different, how many cases do you think it will matter? regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: oddities in the datetime module
Serge Orlov wrote: Max M wrote: Yes, you did. datetime.timetuple is those who want *time module* format, you should use datetime.data, datetime.time, datetime.year and so on... As they say, if the only tool you have is timetuple, everything looks like tuple wink Try this: dt = datetime(2005, 1, 1, 12, 0, 0) dt.date() datetime.date(2005, 1, 1) This doesn't solve it. I don't think you understand my issue. First of, it should be possible to easily convert between the datetime objects. And eg. the date object doesn't have a datetime() method. Which it could easily have. Neither does time. They could have. But I don't think that is the way to solve it. It is a problem if you make a subclass of datetime. Often you will ned to make datetime arithmetics with the new class. Like: datetime_subclass_1 + datetime_subclass_2 The result of that is a plain datetime In that case you will rather want your own subclass returned. But subclasses of datetime returns datetime objects. Not the subclass. So to do an add of your own objects you must convert the output to your own class manually class my_datetime(datetime): def __add__(self, other): result = datetime.__add__(self, other) return my_datetime(result.timetuple()[:6]) datetime(), time() etc. methods will not help with this. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Re: Why would I get a TypeEror?
Steven Bethard wrote: It's me wrote: Say again??? Please stop top-posting -- it makes it hard to reply in context. Reinhold Birkenfeld wrote... It's me wrote: If this is true, I would run into trouble real quick if I do a: (1/x,1.0e99)[x==0] Lazy evaluation: use the (x==0 and 1e99 or 1/x) form! If you want short-circuting behavior, where only one of the two branches gets executed, you should use Python's short-circuiting boolean operators. For example, (x == 0 and 1.0e99 or 1/x) says something like: Check if x == 0. If so, check if 1.0e99 is non-zero. It is, so return it. If x != 0, see if 1/x is non-zero. It is, so return it. Note that if you're not comfortable with short-circuiting behavior, you can also code this using lazy evaluation: (lambda: 1/x, lambda: 1.0e99)[x==0]() Or even (x==0 and lambda: 1e99 or lambda: 1/x)() Or ... Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Com port interrupts again
Thanks much..:) On 14 Jan 2005 12:25:43 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: A search on google gave me this library, I haven't tested it though: http://groups-beta.google.com/group/comp.lang.python.announce/browse_frm/thread/6d3263250ed65816/291074d7bd94be63?q=com+port+python_done=%2Fgroups%3Fhl%3Den%26lr%3D%26safe%3Doff%26q%3Dcom+port+python%26qt_s%3DSearch+Groups%26_doneTitle=Back+to+Searchd#291074d7bd94be63 -- http://mail.python.org/mailman/listinfo/python-list
Re: query python env
David Bear wrote: How does one query the python environment, ie pythonhome, pythonpath, etc. also, are there any HOWTO's on keeping multiple versions of python happy? In general, (and in this case) the answer is system-specific. You need to explain (A) what operating system, and (B) what you mean by multiple Python versions. For example, for Windows 2K/XP, As long as you try for only distinct major versions (2.2.x, 2.3.x, 2.4.x). There should not be a problem. The primary issues are where (and how) does your system get to the python files. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: win32net help
Have you tried using UDP instead of TCP? Also, it is common practice to choose a random port over 1024 for opening a connection to a remote server. -- http://mail.python.org/mailman/listinfo/python-list
Producer/consumer Queue trick
WEBoggle needs a new game board every three minutes. Boards take an unpredictable (much less than 3min, but non-trivial) amount of time to generate. The system is driven by web requests, and I don't want the request that happens to trigger the need for the new board to have to pay the time cost of generating it. I set up a producer thread that does nothing but generate boards and put them into a length-two Queue (blocking). At the rate that boards are pulled from the Queue, it's almost always full, but my poor consumer thread was still being blocked for a long time each time it fetched a board. At this point I realized that q.get() on a full Queue immediately wakes up the producer, which has been blocked waiting to add a board to the Queue. It sets about generating the next board, and the consumer doesn't get to run again until the producer blocks again or is preempted. The solution was simple: have the producer time.sleep(0.001) when q.put(board) returns. Cheers, Evan @ 4-am -- http://mail.python.org/mailman/listinfo/python-list
Re: Python.org, Website of Satan
Lucas Saab wrote: Arich Chanachai wrote: Jane wrote: Lucas Raab [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jane wrote: [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] python.org = 194.109.137.226 194 + 109 + 137 + 226 = 666 What is this website with such a demonic name and IP address? What evils are the programmers who use this language up to? Some people have too much time on their hands... Jane Better get some ointment for that burn!! Huh??? Jane You said that people have too much time on their hands, so he suggested ointment to prevent the irritation etc... He was probably also getting at the topic of this thread (hint: Satan = Hell = Fire), so the ointment puts out the burn. Have fun folks! - Arich I'd also like to add that the term burn means to be made look stupid or be insulted. And here was me just thinking that the burn would result from the inevitable flames. Newsgroups really re a continual surprise. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
On Fri, 14 Jan 2005 20:13:48 +0100, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: In Mythical Future Python I would like to be able to use any base in integer literals, which would be better. Example random syntax: flags= 2x00011010101001 umask= 8x664 answer= 10x42 addr= 16x0E84 # 16x == 0x gunk= 36x8H6Z9A0X I think I kinda like this idea. Allowing arbitrary values, however, would probably be pointless, as there are very few bases in common enough use that a language should make it easy to write literals in any of them. So I think 36x is silly, and would suggest limiting this to 2, 8, 10, and 16. At the very least, a range of 2-16 should be used. (It would be cute but pointless to allow 1x0. :-) My concern is negative numbers when you are interested in the bits of a typical twos-complement number. (BTW, please don't tell me that's platform-specific hardware oriented stuff: Two's complement is a fine abstraction for interpreting a bit vector, which is another fine abstraction ;-) One way to do it consistently is to have a sign digit as the first digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be 2x011 2x101 8x03 8x75 16x03 16xfd 10x03 10x97 Why not just -2x11? IMHO, Py2.4 does not produce negative values out of hex or oct literals any longer, so your proposal would be inconsistent. Inconsistent with what? This is a new based-literal representation, not the old hex or octal representation. It is separate and self-consistent, and can live along side the old. The fact that there is no longer a way to represent negative numbers with traditional octal or hex is due to getting away from the platform-dependent assumptions that bit 31 was a sign bit of a 32-bit two-s complement machine represenentation. That was a good thing to get away from. But it means you now have to write a unary minus expression for negative numbers, not a self-contained literal. Re your question, -2x11 is the same as -(2x11) so you have to decide what you want 2x11 to mean. If it means +3, we are back to the original problem of having no way to see any of the 101 or fd of a -3 ;-) (Except of course by '%02x'%(-0x30xff) -- ick) I am not proposing a change to the new Py2.4 positive-only hex and octal literals. I just want to be able to write literals for both positive and negative numbers as self-contained literals (not expressions) without a '-' sign, and have the representation be a readable representation of typical twos-complement representation. You can't do that with -0x3, because (though the expression equals -3) it doesn't show the information about the bits that you get with 16xfd or 2x101. Note that -16xfd == 16x03 and -2x101 == 2x011 and -16x03 == 16xfd and -2x011 == 2x101. The '-' sign is not part of the literal. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Index server
[EMAIL PROTECTED] wrote: Is there an Index server available in Python? For example: I have large intranet with several servers and I would like to index documents like search engines do. Users then can search for a domument in ALL intranet servers like I do on Google. Thanks for answers L.A. Take a look at the following URLs: http://www.methods.co.nz/docindexer/ http://www.divmod.org/Home/Projects/Lupy/index.html http://www.divmod.org/Home/Projects/Pyndex/index.html HTH, -- Marcel -- http://mail.python.org/mailman/listinfo/python-list
Re: (objects as) mutable dictionary keys
Antoon Pardon wrote: Op 2005-01-14, Peter Maas schreef [EMAIL PROTECTED]: I have summarized the discussion about the usability of lists (and and other mutable types) as dictionary keys and put it into the Python wiki.URL: http://www.python.org/moin/DictionaryKeys. This summary might be used as a reference should the 'mutable dictionary keys' issue come up again in c.l.py. I had a look and I think you should correct the followingr: Dictionary lookup with mutable types like lists is a source of unpleasant surprises for the programmer and therefore impossible in Python. Better, perhaps, to say: Dictionary lookup with mutable types like lists can be a source of unpleasant surprises for the programmer and therefore not recommended in Python. It is not impossible in Python. It may be discouraged but it is not impossible since I have already done so. If I discouraged you from shooting yourself in the foot would you do that too? some-people-just-won't-be-told-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: oddities in the datetime module
Max M wrote: Serge Orlov wrote: Max M wrote: Yes, you did. datetime.timetuple is those who want *time module* format, you should use datetime.data, datetime.time, datetime.year and so on... As they say, if the only tool you have is timetuple, everything looks like tuple wink Try this: dt = datetime(2005, 1, 1, 12, 0, 0) dt.date() datetime.date(2005, 1, 1) This doesn't solve it. I don't think you understand my issue. I understand, but I don't think it's something that should be solved. Especially date(*dt.timetuple()[:3]) class my_datetime(datetime): def __add__(self, other): result = datetime.__add__(self, other) return my_datetime(result.timetuple()[:6]) What about: def __add__(self, other): result = datetime.__add__(self, other) return my_datetime.fromdatetime(result) Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: What strategy for random accession of records in massive FASTA file?
Bengt Richter wrote: On 12 Jan 2005 14:46:07 -0800, Chris Lasher [EMAIL PROTECTED] wrote: [...] Others have probably solved your basic problem, or pointed the way. I'm just curious. Given that the information content is 2 bits per character that is taking up 8 bits of storage, there must be a good reason for storing and/or transmitting them this way? I.e., it it easy to think up a count-prefixed compressed format packing 4:1 in subsequent data bytes (except for the last byte which have less than 4 2-bit codes). I'm wondering how the data is actually used once records are retrieved. (but I'm too lazy to explore the biopython.org link). Revealingly honest. Of course, adopting an encoding that only used two bits per base would make it impossible to use the re module to search for patterns in them, for example. So the work of continuously translating between representations might militate against more efficient representations. Or, of course, it might not :-) it's-only-storage-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: What strategy for random accession of records in massive FASTA file?
Jeff Shannon wrote: Chris Lasher wrote: And besides, for long-term archiving purposes, I'd expect that zip et al on a character-stream would provide significantly better compression than a 4:1 packed format, and that zipping the packed format wouldn't be all that much more efficient than zipping the character stream. This 105MB FASTA file is 8.3 MB gzip-ed. And a 4:1 packed-format file would be ~26MB. It'd be interesting to see how that packed-format file would compress, but I don't care enough to write a script to convert the FASTA file into a packed-format file to experiment with... ;) If your compression algorithm's any good then both, when compressed, should be approximately equal in size, since the size should be determined by the information content rather than the representation. Short version, then, is that yes, size concerns (such as they may be) are outweighed by speed and conceptual simplicity (i.e. avoiding a huge mess of bit-masking every time a single base needs to be examined, or a human-(semi-)readable display is needed). (Plus, if this format might be used for RNA sequences as well as DNA sequences, you've got at least a fifth base to represent, which means you need at least three bits per base, which means only two bases per byte (or else base-encodings split across byte-boundaries) That gets ugly real fast.) Right! regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: What strategy for random accession of records in massive FASTA file?
In article [EMAIL PROTECTED], Chris Lasher [EMAIL PROTECTED] wrote: Hello, I have a rather large (100+ MB) FASTA file from which I need to access records in a random order. The FASTA format is a standard format for storing molecular biological sequences. Each record contains a header line for describing the sequence that begins with a '' (right-angle bracket) followed by lines that contain the actual sequence data. Three example FASTA records are below: CW127_A01 TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA GCATTAAACAT CW127_A02 TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA GCATTAAACATTCCGCCTAGTACGGTCGCAAGATTCTCAAAGGAATAGACGG CW127_A03 TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA GCATTAAACATTCCGCCTGGG ... Since the file I'm working with contains tens of thousands of these records, I believe I need to find a way to hash this file such that I can retrieve the respective sequence more quickly than I could by parsing through the file request-by-request. First, before embarking on any major project, take a look at http://www.biopython.org/ to at least familiarize yourself with what other people have done in the field. The easiest thing I think would be to use the gdbm module. You can write a simple parser to parse the FASTA file (or, I would imagine, find one already written on biopython), and then store the data in a gdbm map, using the tag lines as the keys and the sequences as the values. Even for a Python neophyte, this should be a pretty simple project. The most complex part might getting the gdbm module built if your copy of Python doesn't already have it, but gdbm is so convenient, it's worth the effort. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding/replacing a long binary pattern in a .bin file
Bengt, and all, Thanks for all the good input. The problems seems to be that .find() is good for text files on Windows, but is not much use when it is binary data. The script is for a Assy Language build tool, so I know the exact seek address of the binary data that I need to replace, so maybe I'll just go that way. It just seemed a little more general to do a search and replace rather than having to type in a seek address. Of course I could use a Lib function to convert the binary data to ascii and back, but seems a little over the top in this case. Cheers, --Alan Bengt Richter wrote: On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon [EMAIL PROTECTED] wrote: Bengt Richter wrote: BTW, I'm sure you could write a generator that would take a file name and oldbinstring and newbinstring as arguments, and read and yield nice os-file-system-friendly disk-sector-multiple chunks, so you could write fout = open('mynewbinfile', 'wb') for buf in updated_file_stream('myoldbinfile','rb', oldbinstring, newbinstring): fout.write(buf) fout.close() What happens when the bytes to be replaced are broken across a block boundary? ISTM that neither half would be recognized I believe that this requires either reading the entire file into memory, to scan all at once, or else conditionally matching an arbitrary fragment of the end of a block against the beginning of the oldbinstring... Given that the file in question is only a few tens of kbytes, I'd think that doing it in one gulp is simpler. (For a large file, chunking it might be necessary, though...) Might as well post this, in case you're interested... warning, not very tested. You want to write a proper test? ;-) sreplace.py - def sreplace(sseq, old, new, retsize=4096): iterate through sseq input string chunk sequence treating it as a continuous stream, replacing each substring old with new, and generating a sequence of retsize returned strings, except that the last may be shorter depedning on available input. inbuf = '' endsseq = False out = [] start = 0 lenold = len(old) lennew = len(new) while not endsseq: start, endprev = old and inbuf.find(old, start) or -1, start if start0: start = endprev # restore find start pos for chunk in sseq: inbuf+= chunk; break else: out.append(inbuf[start:]) endsseq = True else: out.append(inbuf[endprev:start]) start += lenold out.append(new) if endsseq or sum(map(len, out))=retsize: s = ''.join(out) while len(s)= retsize: yield s[:retsize] s = s[retsize:] if endsseq: if s: yield s else: out = [s] if __name__ == '__main__': import sys args = sys.argv[:] usage = Test usage: [python] sreplace.py old new retsize [rest of args is string chunks for test] where old is old string to find in chunked stream and new is replacement and retsize is returned buffer size, except that last may be shorter if not args[1:]: raise SystemExit, usage try: args[3] = int(args[3]) args[0] = iter(sys.argv[4:]) print '%r\n---\n%s\n' %(sys.argv[1:], '\n'.join(sreplace(*args[:4]))) except Exception, e: print '%s: %s' %(e.__class__.__name__, e) raise SystemExit, usage As mentioned, not tested very much beyond what you see: [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 20 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '20', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- Thisis_XX_andabc_XX_ def012_XX_345zz_XX__ XX_zzz_XX_ [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 80 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- Thisis_XX_andabc_XX_def012_XX_345zz_XX__XX_zzz_XX_ [ 2:43] C:\pywk\utpy24 sreplace.py x _XX_ 4 This is x and abcxdef 012x345 zzxx zzz x ['x', '_XX_', '4', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- This is_X X_an dabc _XX_ def0 12_X X_34 5zz_ XX__ XX_z zz_X X_ [ 2:44] C:\pywk\utpy24 sreplace.py def DEF 80 This is x and abcxdef 012x345 zzxx zzz x ['def', 'DEF', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345', 'zzxx', 'zzz', 'x'] --- ThisisxandabcxDEF012x345zzxxzzzx If you wanted to change a binary file, you'd use it something like (although probably let the default buffer size be at 4096, not 20, which is pretty silly other than
Re: Python.org, Website of Satan
Denis S. Otkidach wrote: Certainly, it can be done more efficient: Yes, of course. I should have thought about the logic of my code before posting. But I didn't want to spend any more time on it than I had to. ;-) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Operating System???
jtauber schreef: see http://cleese.sourceforge.net/ There is not much to see there, most of the wiki is filled with spam... -- JanC Be strict when sending and tolerant when receiving. RFC 1958 - Architectural Principles of the Internet - section 3.9 -- http://mail.python.org/mailman/listinfo/python-list
[perl-python] 20050114 if statement
. # here's an example of if statement in python. . . x=-1 . if x0: . print 'neg' . elif x==0: . print 'zero' . elif x==1: . print 'one' . else: . print 'other' . . # the elif can be omitted. . -- . # here's an example of if statement in perl . . $x=31; . if ($x0) { . print 'neg' . } elsif ($x==0) { . print 'zero' . } elsif ($x==1) { . print 'one' . } else { . print 'other' . } . . . --- . . Note: this post is from the Perl-Python a-day mailing list at . http://groups.yahoo.com/group/perl-python/ . to subscribe, send an email to [EMAIL PROTECTED] . if you are reading it on a web page, program examples may not run . because html conversion often breaks the code. . . Xah . [EMAIL PROTECTED] . http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list
Re: finding/replacing a long binary pattern in a .bin file
On 14 Jan 2005 15:40:27 -0800, yaipa [EMAIL PROTECTED] wrote: Bengt, and all, Thanks for all the good input. The problems seems to be that .find() is good for text files on Windows, but is not much use when it is binary data. The script is for a Assy Language build tool, so I know Did you try it? Why shouldn't find work for binary data?? At the end of this, I showed an example of opening and modding a text file _in binary_. s= ''.join(chr(i) for i in xrange(256)) s '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\ x19\x1a\x1b\x1c\x1d\x1e\x1f !#$%\'()*+,-./0123456789:;=[EMAIL PROTECTED] cdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f \x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7 \xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf \xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7 \xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef \xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' for i in xrange(256): ... assert i == s.find(chr(i)) ... I.e., all the finds succeded for all 256 possible bytes. Why wouldn't you think that would work fine for data from a binary file? Of course, find is case sensitive and fixed, not a regex, so it's not very flexible. It wouldn't be that hard to expand to a list of old,new pairs as a change spec though. Of course that would slow it down some. the exact seek address of the binary data that I need to replace, so maybe I'll just go that way. It just seemed a little more general to do a search and replace rather than having to type in a seek address. Except you run the risk of not having a unique search result, unless you have a really guaranteed unique pattern. Of course I could use a Lib function to convert the binary data to ascii and back, but seems a little over the top in this case. I think you misunderstand Python strings. There is no need to convert the result of open(filename, 'rb').read(chunksize). Re-read the example below ;-) [...] If you wanted to change a binary file, you'd use it something like ^^^ (although probably let the default buffer size be at 4096, not 20, which is pretty silly other than demoing. At least the input chunks are 512 ;-) from sreplace import sreplace fw = open('sreplace.py.txt','wb') opens a binary output file for buf in sreplace(iter(lambda f=open('sreplace.py','rb'):f.read(512), ''),'out','OUT',20): iter(f, sentinel) is the format above. I creates an iterator that keeps calling f() until f()==sentinel, which it doesn't return, and that ends the sequence f in this case is lambda f=open(inputfilename):f.read(inputchunksize) and the sentinel is '' -- which is what is returned at EOF. The old thing to find was 'out', to be changed to 'OUT', and the 20 was a silly small return chunks size for the sreplace(...) iterator. Alll these chunks were simply passed to ... fw.write(buf) ... fw.close() and closing the file explicitly wrapped it up. ^Z I just typed that in interactively to demo the file change process with the source itself, so the diff could show the changes. I guess I should have made sreplace.py runnable as a binary file updater, rather than a cute demo using command line text. The files are no worry, but what is the source of your old and new binary patterns that you want use for find and replace? You can't enter them in unescaped format on a command line, so you may want to specify them in separate binary files, or you could specify them as Python strings in a module that could be imported. E.g., --- old2new.py -- # example of various ways to specify binary bytes in strings from binascii import unhexlify as hex2chr old = ( 'This is plain text.' + ''.join(map(chr,[33,44,55, 0xaa])) + '-- arbitrary list of binary bytes specified in numerically if desired' + chr(33)+chr(44)+chr(55)+ '-- though this is plainer for a short sequence' + hex2chr('4142433031320001ff') + r'-- should be ABC012\x00\x01\xff' ) new = '\x00'*len(old) # replace with zero bytes --- BTW: Note: changing binaries can be dangerous! Do so at your own risk!! And this has not been tested worth a darn, so caveat**n. --- binfupd.py -- from sreplace import sreplace def main(infnam, outfnam, old, new): infile = open(infnam, 'rb') inseq = iter(lambda: infile.read(4096), '') outfile = open(outfnam, 'wb') try: try: for buf in sreplace(inseq, old, new): outfile.write(buf) finally: infile.close() outfile.close() except Exception, e: print '%s:%s' %(e.__class__.__name__, e)
Re: Python.org, Website of Satan
Michael Hoffman wrote: Denis S. Otkidach wrote: Certainly, it can be done more efficient: Yes, of course. I should have thought about the logic of my code before posting. But I didn't want to spend any more time on it than I had to. ;-) Bah, you satanic types are so lazy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Com port interrupts again
engsol wrote: I didn't fully think through my application before posting my question. Async com port routines to handle com port interrups only work well if one has access to the low level operating system. In that case the receive buffer interrupt would cause a jump to an interrupt service routine.. I don't believe that Python provides that capabilty directly. The solution then would be to write a C extention? Maybe, but I doubt that you can or would really want to do this with modern operating systems anyway. With DOS, and similar primitive things, glomming onto an interrupt or hooking yourself into the interrupt table was pretty easy. I don't think either Windows or Linux is structured such that you just write a C extension to intercept interrupts. Instead, you must write relatively complicated drivers which have to be loaded at system startup (more or less) and be tied into the kernel at a relatively low level. Think rocket science, at least in comparison to writing a simple C extension. :-) The suggestions offered by respondents to my original post were almost all of a Use threads, and poll as needed flavor. You're right...I need to learn threads as applied to com ports. At least on Windows, I'm fairly sure you can configure the read timeouts so that you get behaviour on reads that for all intents and purposes is about as good as an interrupt, without the difficulties inherent in that approach, but provided you are willing to dedicate a thread to the task. On Linux, it's possible the read timeouts capabilities are a little less flexible (but I've only just barely glanced at this area), but as I recall you were on Windows anyway. BTW, another post pointed you to USPP. As far as I know, it hasn't been updated recently and, while I can't say how it compares to PySerial, I believe it's fair to say at this point in time that PySerial is the _de facto_ standard way to do serial port stuff in Python. If it doesn't do what you need, it's probably a good idea to at least point that out in its mailing list so that it can be improved. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: finding/replacing a long binary pattern in a .bin file
On Wed, Jan 12, 2005 at 10:36:54PM -0800, yaipa wrote: What would be the common sense way of finding a binary pattern in a .bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the search/replacement is very important. ok, after having read the answers, I feel I must, once again, bring mmap into the discussion. It's not that I'm any kind of mmap expert, that I twirl mmaps for a living; in fact I barely have cause to use it in my work, but give me a break! this is the kind of thing mmap *shines* at! Let's say m is your mmap handle, a is the pattern you want to find, b is the pattern you want to replace, and n is the size of both a and b. You do this: p = m.find(a) m[p:p+n] = b and that is *it*. Ok, so getting m to be a mmap handle takes more work than open() (*) A *lot* more work, in fact, so maybe you're justified in not using it; some people can't afford the extra s = os.stat(fn).st_size m = mmap.mmap(f.fileno(), s) and now I'm all out of single-letter variables. *) why isn't mmap easier to use? I've never used it with something other than the file size as its second argument, and with its access argument in sync with open()'s second arg. -- John Lenton ([EMAIL PROTECTED]) -- Random fortune: If the aborigine drafted an IQ test, all of Western civilization would presumably flunk it. -- Stanley Garn signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: porting C code
Lucas Raab wrote: Sorry, the third byte is what I meant. Fair enough. Note, however, that as someone pointed out, it's actually the *fourth* of something, and it would not necessarily be a byte. In fact, in your case, it's not: typedef unsigned long int word32 ; void mu(word32 *a) { int i ; word32 b[3] ; This defines an array of *3* long (32-bit) integers. b[0] = b[1] = b[2] = 0 ; Each of these is just indexing into that array, starting as Python does with an index origin of zero. The a[#] and b[#] are the parts that are giving me trouble. Between the clarifications you've got and Duncan's post, you shouldn't have much more trouble now. :-) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: XPath and XQuery in Python?
Interesting discussion. My own thoughts: http://www.oreillynet.com/pub/wlg/6224 http://www.oreillynet.com/pub/wlg/6225 Meanwhile, please don't make the mistake of bothering with XQuery. It's despicable crap. And a huge impedance mismatch with Python. --Uche -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050113 looking up syntax
Peter Hansen wrote: So why duplicate the posts by posting them to the newsgroups? Because he's a well-known pest. -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis Yes I'm / Learning from falling / Hard lessons -- Lamya -- http://mail.python.org/mailman/listinfo/python-list