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. -- 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: cxOracle for python 2.4
Thanks a lot! :-) [EMAIL PROTECTED] wrote: does anybody knows where I can get the DB interface cx_Oracle for Python 2.4 with win32. > http://starship.python.net/crew/atuining/cx_Oracle/ Link is saved for some time. Volker -- 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 "", 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: What strategy for random accession of records in massive FASTA file?
On Thu, Jan 13, 2005 at 04:41:45PM -0800, Robert Kern wrote: Jeff Shannon wrote: (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.) Not to mention all the IUPAC symbols for incompletely specified bases (e.g. R = A or G). http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html Or, for those of us working with proteins as well, all the single letter codes for proteins: http://www.chem.qmul.ac.uk/iupac/AminoAcid/A2021.html lots more bits. I have a db with approx 3 million proteins in it and would not want to be using a pure python approach :) Michael -- 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: python and macros (again) [Was: python3: 'where' keyword]
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. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- 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? -- http://mail.python.org/mailman/listinfo/python-list
Threading Or Other Suggestions?!?
Hello NG, 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? Thanks to you all for every suggestion. Andrea. -- Message for the recipient only, if received in error, please notify the sender and read http://www.eni.it/disclaimer/ -- http://mail.python.org/mailman/listinfo/python-list
[perl-python] 20050113 looking up syntax
while programing in Python, one can lookup syntax or info for keywords or modules within Python. In the command line, type python to get into the python interactive program. then type help() >From there one can type any keyword or module name to find out the syntax or info. Everything is self-contained and self-explanatory. to exit help, type control-d. if you haven't tried already, you can type 1+1 while running python. The result will be displayed interactively. So in this way, Python can be used as a calculator. - for perl syntax lookup, use perldoc in the command line. For example: perldoc perl use 'perldoc -f functionName' for specific function. example: perldoc -f qq note that keywords cannot be looked up with -f. For basic keywords like if, while..., use perldoc perlop Master 'perldoc perl' as a way to get familiar of what info are available and what subroutine or aspect of perl is in what section of the documentation associated with what documentation name abbreviation. Master 'perldoc perldoc' to know all its power of options and flexibility. If you use emacs, in particular you want to add the -t option. Master the unix text editor vi to learn the navigation system of perldoc. The basics are: control-f for page down, control-v for page up, q for exit. Also, one may wish to peruse 'perldoc perlfaq' to acquaint yourself about the preamble of nine volumes of perl's FAQ. --- 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 they've been changed by yahoo.com or google.com. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- 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 _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 start<0: 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\ut>py24 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\ut>py24 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\ut>py24 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\ut>py24 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\ut>diff -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 st
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(): def _in_clause(): return return _in_clause() __use_stmt_args = {} = __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): __inner = locals() for name in : __outer[name] = __inner[name] __use_stmt(locals()) del __use_stmt And for the 'delayed execution' case: def __named_use_stmt(__outer): def __delayed_block(): __inner = locals() for name in : __outer[name] = __inner[name] return __delayed_block = __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
Re: [perl-python] 20050113 looking up syntax
Xah Lee wrote: [snip] 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] So why duplicate the posts by posting them to the newsgroups? Now that you've advertised the mailing list (and thank you, I'll be sure to hurry off now and subscribe) there's no longer any reason to post to the newsgroups, is there? Please? -Peter -- 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 ; i<32 ; 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 ; i<32 ; 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|hi<<2) for lo in rev2 for hi in rev2 ] rev8 = [ (lo|hi<<4) for lo in rev4 for hi in rev4 ] def rev32(n): '''Reverse the low 32bits of an integer''' return (rev8[(n>>24)&0xff]| (rev8[(n>>16)&0xff]<<8)| (rev8[(n>>8)&0xff]<<16)| (rev8[n&0xff]<<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(n>>64)|(rev32(n>>32)<<32)|(rev32(n)<<64) print hex(rev96(0x102030405060708090a0b0c0L)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Sqlite with Python under Windows
Michael Goettsche wrote: > 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. Michael, I posted this morning but I don't know what happened to my post! In any case, PySqlite is the distribution I have used and is available at pysqlite.org. I believe there is another module called APSW (Another Python Sqlite Wrapper) available, that I stumbled upon just today, after reading your post. Home page : http://www.rogerbinns.com/apsw.html Please read the section "pysqlite differences" to see which one you want to install. As for installation, it should be as simple as downloading the win32 binaries for your Python distro and executing it. I do not have admin rights on my Win2K PC at work, but it installed and worked just fine. So, you should not have any problem. You will not have to install anything additional other the python-sqlite module itself. Good choice on selecting Sqlite..I love it and hope you will enjoy it too! Thanks, --Kartic -- 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
Re: Python.org, Website of Satan
In article <[EMAIL PROTECTED]>, Michael Hoffman <[EMAIL PROTECTED]> wrote: > 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 I'm not sure what you meant to do, but note that 'a < 666-255*3' is false for all values of 'a' generated by the xrange() call. Removing that test would make the code more efficient. Hard to say if it would make it more elegant :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode conversion in 'print'
Ricardo Bugalho wrote: > Hi, > 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())) I don't have access to any other version except 2.2 at the moment but I believe it happened between 2.2 and 2.3 for Windows and UNIX terminals. On other unsupported terminals I suspect sys.getdefaultencoding is still used. The reason for the change is proper support of unicode input/output. > and why it was done only for 'print' when > stdout is a terminal instead of always. The real question is why not *never* use sys.getdefaultencoding() for printing. If you leave sys.getdefaultencoding() at Python default value ('ascii') you won't need to worry about it sys.getdefaultencoding() is a temporary measure for big projects to use within one Python version. Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class initialization from a dictionary, how best?
On 13 Jan 2005 20:36:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: ># ># My problem is that I want to create a ># class, but the variables aren't known ># all at once. So, I use a dictionary to ># store the values in temporarily. Why? ># Then when I have a complete set, I want to ># init a class from that dictionary. Why do it that way? ># However, I don't want to specify the ># dictionary gets by hand ># since it is error prone. ># Thanks for any ideas, Brian > > > So I have a class defined that accepts a number of variables ># and they must be all present at object creation time. Why? Why not a method to check if it's valid yet, and then add the attributes as they're available, without intermediaries. You can make Test "smart" so it won't accept any other names than a,b,c and will automatically convert to str, str, and int. Etc. What are you actually doing? Is this a toy example of a more complex class? >class Test: >def __init__(self, a, b, c): >self.a = a >self.b = b >self.c = c >def __str__(self): >return '%s, %s, %d' % (self.a, self.b, self.c) > ># For example: >t1 = Test('asd', 'sdf', 9) >print t1 > ># However, due to parsing XML, I am ># creating the values incrementally ># and I want to store them in a dictionary ># and then map them easily to a class Why store them in a dictionary? Why not create an empty Test instance, and incrementally add the attributes directly as they're available? What are you going to do with t1 and other instances? > >dictionary = {} > ># a mapping from source to destination >mapping = { >'a': str, >'b': str, >'c': int, >} > ># a sample source of values >test_source = { >'a': 'test', >'b': 'asdf', >'c': 45 >} > ># now we go through and extract the values ># from our source and build the dictionary Just the three items in the test_source dictionary? Is that just a 3-item holding place until you > >for attr_name, function in mapping.items(): >dictionary[attr_name] = function(test_source.get(attr_name)) > >print dictionary > ># Here is the problem I want to avoid: ># Having to list the variable names ># as strings in multiple places. It is enought to ># have them in the 'mapping' ># dictionary above > >t2 = Test(dictionary.get('a'), dictionary.get('b'), >dictionary.get('c')) >print t2 > Why don't you just let Test do all the work, and update it incrementally until it is complete. You can use descriptors to manage state. You could do any number of things. The main problem is defining the _requirements_ without premature implementation, never mind premature optimization ;-) You may have good reasons for wanting to do what you seem to want to do, but the picture is not clear to me ;-) Regards, Bengt Richter -- 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.org, Website of Satan
On Fri, 14 Jan 2005 11:16:59 + Michael Hoffman <[EMAIL PROTECTED]> wrote: > 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: Certainly, it can be done more efficient: for a in xrange(256): for b in xrange(max(0, (666-255*2)-a), 256): for c in xrange(max(0, (666-255)-a-b), min(666-a-b+1, 256)): d = 666-a-b-c ... I've checked these IPs with ip2cc (which can miss entries registered last month): there are 2907248 "evil" addresses, most of them (1568430) in USA. Too many to resolve. -- Denis S. Otkidach http://www.python.ru/ [ru] -- http://mail.python.org/mailman/listinfo/python-list
How to list the global functions from a C program
Hi all, I'm a Python newbie and I'm trying to add to my C++ program a limited support for scripts written in python. In particular, I'd like to load user scripts written in python, list all the functions he defined in the script file and then call them. To begin I wrote into my C++ program (correctly linked to python 2.3.2): == /* create the main module */ m_pModule = PyImport_AddModule("__main__"); m_pDict = PyModule_GetDict(m_pModule); m_pGlobals = m_pDict; m_pLocals = m_pDict;// is this right (globals==locals) ?? /* to try out python, I want just to force the creation of a simple function and then call it from C */ PyRun_StringFlags("def donothing():\n\treturn 'hello'\n", Py_file_input, m_pGlobals, m_pLocals, 0); /* scan all the contents of the __main__ module... */ PyObject *list = PyObject_Dir(m_pGlobals); if (!list || PyList_Check(list) == FALSE) return; for (int i=0,max=PyList_Size(list); 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 ? Thanks indeed, Francesco Montorsi == The perverse principle of programming: there is always another bug. (Murphy) == -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Sqlite with Python under Windows
On Friday 14 January 2005 14:56, Kartic wrote: > > I posted this morning but I don't know what happened to my post! > > In any case, PySqlite is the distribution I have used and is available > at pysqlite.org. > > I believe there is another module called APSW (Another Python Sqlite > Wrapper) available, that I stumbled upon just today, after reading your > post. Home page : http://www.rogerbinns.com/apsw.html > > Please read the section "pysqlite differences" to see which one you > want to install. > > As for installation, it should be as simple as downloading the win32 > binaries for your Python distro and executing it. I do not have admin > rights on my Win2K PC at work, but it installed and worked just fine. > So, you should not have any problem. You will not have to install > anything additional other the python-sqlite module itself. > > Good choice on selecting Sqlite..I love it and hope you will enjoy it > too! > > Thanks, > --Kartic Hi Kartic, thanks for your answer. I've installed PySqlite on my system at home and will look into the docs now. I think it's good for our purposes. Thanks, Michael -- 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. > 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: Class initialization from a dictionary, how best?
Yes, my examle here is a tiny part of a larger more complex issue. My application is an DOM XML parser that is reading attributes one at a time. My class that I am creating is used elsewhere and must have certain arguments for those uses to continue working. So, I seem to be left with creating an intermediate object. Before, I was simply creating an object: t = Test() for attr_name in mapping.keys(): setattr(t, attr_name, value_from_source) This I feel was ellegant, efficient and clear. However, what I have now works but is not clear. BTW, t1 is just for example and was just being printed Thanks, Brian -- http://mail.python.org/mailman/listinfo/python-list
Integration with java
Hello, I am working on a project in Python, and I"m currently looking into the possibiliy of writing some of the project"s modules in Java. Given that a large part of the code is already written in Python, using the standard libraries and several extension modules, I am trying to gauge the viability of integration with Java via Jython with minimal impact on present code, on the complexity of future code, and on deadlines! I need to know in general how dirty it will be to combine the two languages, and what the costs I should take into account are. I"m also interested to know if there are any commonly accepted strategies to fully switch project languages (I"m considering, in the extreme case, to change it all into Java), and if writing some modules in Java and replacing the rest gradually makes sense. Three more specific questions I thought of: 1. Is is possible to pack a Jython/Java program in a py2exe-like fashion? Is it possible to pack in such a way both Python, Jython and Java code? 2. Does transferring large data structures between Java and Python code running by Jython have a significant effect on memory? For example, would passing the result of a large database query from Java to Jython, for further processing, cause the entire data to be duplicated or something similar? 3. Did I miss anything fundemental? Thanks! Joe. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: (objects as) mutable dictionary keys
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. It is not impossible in Python. It may be discouraged but it is not impossible since I have already done so. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: XPath and XQuery in Python?
Nelson Minar <[EMAIL PROTECTED]> writes: > Could someone help me get started using XPath or XQuery in Python? I figured this out. Thanks for the help, John! Examples below. I used this exercise as an opportunity to get something off my chest about XML and Python - it's kind of a mess! More here: http://www.nelson.monkey.org/~nelson/weblog/tech/python/xpath.html Here are my samples, in three libraries: # PyXML from xml.dom.ext.reader import Sax2 from xml import xpath doc = Sax2.FromXmlFile('foo.opml').documentElement for url in xpath.Evaluate('//@xmlUrl', doc): print url.value # libxml2 import libxml2 doc = libxml2.parseFile('foo.opml') for url in doc.xpathEval('//@xmlUrl'): print url.content # ElementTree from elementtree import ElementTree tree = ElementTree.parse("foo.opml") for outline in tree.findall("//outline"): print outline.get('xmlUrl') Please see my blog entry for more commentary http://www.nelson.monkey.org/~nelson/weblog/tech/python/xpath.html -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Tim Jarman wrote: > 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. :) Ok. http://www.urbandictionary.com/define.php?term=belgian&r=f -- CARL BANKS -- 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: > PyObject *list = PyObject_Dir(m_pGlobals); > if (!list || PyList_Check(list) == FALSE) > return; > > for (int i=0,max=PyList_Size(list); 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 "", 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 . 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 >>> 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: Free python server.
> 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. -- 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? -- 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: Integration with java
It is possible, though possibly painful, to call java modules from CPython using JNI. This is more difficult than Jython integration, but probably required if you want to keep using your extension modules. The JNI tutorial is available at http://java.sun.com/docs/books/tutorial/native1.1/index.html . I probably would not take this approach unless java offered some incredibly substantial benefit or I was integrating a complex python system with a complex java sytem. I would also probably start by creating a good C API to access the required java modules via JNI and then use SWIG (http://www.swig.org/) to generate the python wrapper. Of course if you can drop the extension modules you have already written, accessing Java from Jython is just an import statement away. Good luck, Chris -- 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 "Hello World!" > ' > 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
Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))
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' ? What does it do, anyways? At least, if it does something, I'm sure that it isn't something that can be done in Python itself if really required to do so... --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Integration with java
How about this? http://jpype.sourceforge.net/ (I haven't used it myself) -- 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] > 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' ? > What does it do, anyways? At least, if it does something, I'm sure > that it isn't something that can be done in Python itself if > really required to do so... It's not Python's decision, it's the operating system's. Whether there's an actual difference between text mode and binary mode is up to the operating system, and, if there is an actual difference, every detail about what the difference(s) consists of is also up to the operating system. 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. On Unixish systems, there's no difference. On Windows boxes, there are conceptually small differences with huge consequences, and the distinction appears to be kept just for backward-compatibility reasons. On some other systems, text and binary files are entirely different kinds of beasts. If Python didn't offer text mode then it would be clumsy at best to use Python to write ordinary human-readable text files in the format that native software on Windows, and Mac Classic, and VAX (and ...) expects (and the native format for text mode differs across all of them). If Python didn't offer binary mode then it wouldn't be possible to use Python to process data in binary files on Windows and Mac Classic and VAX (and ...). If Python used its own platform-independent file format, then it would end up creating files that other programs wouldn't be able to deal with. Live with it . -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop google from messing Python code
Fuzzyman wrote: > 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. if you have internet access, you have NNTP access. gmane.org provides access to more than 6,500 mailing lists via NNTP, including all relevant Python forums. -- http://mail.python.org/mailman/listinfo/python-list
Re: python and macros (again) [Was: python3: 'where' keyword]
Antoon Pardon wrote: 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. True, I wanted to add that but forgot it. Doesn't change what I'm saying though. 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. In both cases we have an expression, in both cases we have a statement, in both cases the expression is a part of the statement. In one case the expression is the only statement, in the other case the statement has other parts too. Note that it would be perfectly possible to modify the syntax into expression_stmt ::= "exprstmt" expression_list ... 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? No, you still have a statement with one or more parts, one of which is an expression. In OOP terms: I think that an expression statement 'has an' expression (I agree that is a very thin wrapper though), not that an expression statement 'is an' expression. 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. Whether statements can be used in the place of expressions is indeed not relevant to the discussion. Regarding what Guido apparently said: Op 2005-01-12, Steve Holden schreef <[EMAIL PROTECTED]>: >> Given that Guido is on record as saying that expressions aren't >> statements because he wants those things to be separate Antoon Pardon wrote: > Well, it seems that Guido is wrong then. The documentation clearly > states that an expression is a statement. I don't think it says that at all. > More specifically, everywhere you can use a statement, you can > simply use an expression according to the python syntax. If you use an expression where a statement is expected, you really write an expression statement that contains the expression (and nothing else, but that doesn't matter). -- "Codito ergo sum" Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Com port interrupts again
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? 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. Norm B -- http://mail.python.org/mailman/listinfo/python-list
Re: python connect to db2
yuzx wrote: anyone can help me ? this might help: http://www6.software.ibm.com/reg/devworks/dw-db2pylnx-i?S_TACT=104AHW03&S_CMP=EDU jacek -- http://mail.python.org/mailman/listinfo/python-list
Re: Integration with java
In article <[EMAIL PROTECTED]>, Istvan Albert <[EMAIL PROTECTED]> wrote: >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. There are other possibilities, though, including JPE http://jpe.sourceforge.net >. I recommend the original poster consider the latter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
Simon Brunning wrote: > 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 Well, this would generate warnings for all octal literals except 01, 02, 03, 04, 05, 06 and 07. However, I would vote +1 for adding such an option to PyChecker. For code that explicitly uses octals, it can be turned off and it is _very_ confusing to newbies... Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
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. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050113 looking up syntax
Jürgen Exner wrote: Why don't you just stop posting this nonsense? He will, fairly soon. I'm suspecting that the original intent behind these posts was to stir up a perl vs python flamewar. That is unlikely to materialize since the poster does not seem to understand neither of these languages. I. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why would I get a TypeEror?
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: 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
Free NNTP (was Re: how to stop google from messing Python code)
In article <[EMAIL PROTECTED]>, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Fuzzyman wrote: >> >> 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. Most people use Gooja to post because they're lazy. >if you have internet access, you have NNTP access. gmane.org provides >access to more than 6,500 mailing lists via NNTP, including all >relevant Python forums. You also have access to the free netnews server http://news.cis.dfn.de/ -- 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: 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+Search&&d#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
Re: What strategy for random accession of records in massive FASTA file?
Forgive my ignorance, but what does using mmap do for the script? My guess is that it improves performance, but I'm not sure how. I read the module documentation and the module appears to be a way to read out information from memory (RAM maybe?). -- 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