Re: UTF Questions
Thanks Serge. Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
For me, one of the reasons for using Python is the ease and the intuivity of reading its code. I have a problem with intuitively getting what is going on when using a pattern like (x,y,z=0) - (x,y,z) where I expect at the first glance some C code with access to class members. At least I must start looking at the code more closely thinking why is someone using such a construct. Already lambda x,y,z=0:(x,y,z) is a problem for me. Why not: try: (x,y,z) except NameError: z=0 (x,y,z) ? Watching the last piece of code can even directly be seen, that there is eventually a NameError problem with z to handle, so where is the gain of using lambda or the mapping? My current conclusion (I can't see any gain): No, thanks. Claudio Kay Schluehr [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] Since George Sakkis proposed a new way of doing list comprehensions http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ac5023ad18b2835f/d3ff1b81fa70c8a7#d3ff1b81fa70c8a7 letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) i.e. mapping tuples on other tuples. This is equivalent to lambda x,y,z=0:(x,y,z) But regarding tuples as actions by means of an arrow - would generalize this idea: Mappings like that: ((x,y),z) - x+y-z ((x,y=0),z) - None should be valid actions too. What is the audience thinking about that? Regards Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Save passwords in scripts
Florian Lindner wrote: Paul Rubin wrote: - sort of similar: have a separate process running that knows the password (administrator enters it at startup time). That process listens on a unix socket and checks the ID of the client. It reveals the password to authorized clients, i.e. your readable script running under sudo. This keeps the password from ever being stored on disk. - Modify the script itself to run as a long-running service instead of as something that gets started and restarted all the time. Have an admin start it and type the password into it at startup time. Users then connect to it (maybe with a web browser) and send it commands. - Move the user operations from the script to server side database procedures that do their own validity checking. Then you don't need a password. I'll evaluate the 3 ideas above further. I'm surprised there are no building blocks for a sudo replacement in the UNIX world, at least I googled and couldn't find them. Basically you need to split you script into two parts: priveledged server and user client. They can talk xml-rpc over unix socket. If you need performance you can also open another socket for sending huge binary objects. With regards to clear text password and admin, you can only obfuscate or make it hard to obtain the password. It's just to keep honest admins honest. Same story on windows, btw. Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help for Python programming
[EMAIL PROTECTED] wrote: (snip) The PRINT code is for my testing. My problem is bytemsg will be omitted some records. For example, my text file have 53 records about username. After byteDict = users1[user1], Which, from your previous snippet, should raise a KeyError... If it does, then first understand why and fix it. If it does not, then the code you posted is absolutely useless for us to help you. it remains 50 records in the output file. There is nothing about reading and parsing file in the code you posted. I'm afraid you did not follow Diez's advice, nor mine. Please re-read my previous post, take appropriate action, and re-post with the minimum *working* snippet that exhibit your problem. I would like to know how to culmulate some data by users. data.txt user1;aaa;000 user2;aab;001 user3;aac;002 user1;aad;004 user3;aae;005 user1;aaf;006 user2;aag;007 user2;aah;008 user2;aak;009 user1;zzz;999 accu.py import sys import pprint try: f = open('data.txt', 'r') except IOError, e: print sys.stderr, Cannot open file data.txt for reading : %s % e sys.exit(1) users = {} for line in f: try: user, data1, data2 = line.strip().split(';') except ValueError: print sys.stderr, wrong file format f.close() sys.exit(1) try: users[user].append(%s : %s % (data1, data2)) except KeyError: users[user] = [%s : %s % (data1, data2)] f.close() print collected data:; pprint.pprint(users) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Begniner Question
Glen wrote: #!/usr/local/bin/python import sys print 1.\tDo Something print 2.\tDo Something print 3.\tDo Something print 4.\tDo Something print 5.\tDo Something print 6.\tExit choice=raw_input(Please Enter Choice: ) if int(choice)==1: print Here else: pass if int(choice)==2: else: pass (snip) File ./Code.py, line 20 else: ^ IndentationError: expeted an indented block What am I doing wrong? Err... I'm not totally sure, but I think it could be possible that you perhaps should insert an indented block between lines 19 and 20 !-) Thank-you You're welcome !-) A bit more seriously, now... the construct: if some_condition: else: pass is syntactically incorrect. Python expects an indented block between the 'if' line and the 'else' line. If you don't have the needed code yet, you need to put a 'pass' here : if some_condition: pass else: pass This will of course do nothing else than useless tests, but it will at least satisfy the language's rules. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Claudio Grondi wrote: For me, one of the reasons for using Python is the ease and the intuivity of reading its code. I guess this is true for many of us. Now 'ease and intuitivity' stronly depends on one's background... I have a problem with intuitively getting what is going on when using a pattern like (x,y,z=0) - (x,y,z) where I expect at the first glance some C code with access to class members. pedantic There are nothing like a class or a class member in C. /pedantic At least I must start looking at the code more closely thinking why is someone using such a construct. Already lambda x,y,z=0:(x,y,z) is a problem for me. Not for me. It's clearly a function that takes 2 mandatory and one optional argument (which default to 0), and returns a tuple of it's argument. it's named equivalent is: def make_three_tuple(x, y, z=0): return (x, y, z) Why not: try: (x,y,z) except NameError: z=0 (x,y,z) ? Because it does not do the same thing ?-) Because, if it did, it would still require 5 times more lines of code to do the same thing (hence it's more error-prone by a factor a 5) ? Because it uses an exception, which is far less efficient than using a default argument ? Because the name error could be on x and/or y too, and the try:except clause would hide it ? I stop here, but I think I could think of more good (IMHO) reason to prefer the lambda form. Watching the last piece of code can even directly be seen, that there is eventually a NameError problem with z to handle, No. AFAICT, the name error could be with x and/or y and/or z. so where is the gain of using lambda or the mapping? See upper... -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Kay Schluehr wrote: Since George Sakkis proposed a new way of doing list comprehensions http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ac5023ad18b2835f/d3ff1b81fa70c8a7#d3ff1b81fa70c8a7 letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) i.e. mapping tuples on other tuples. This is equivalent to lambda x,y,z=0:(x,y,z) But regarding tuples as actions by means of an arrow - would generalize this idea: Mappings like that: ((x,y),z) - x+y-z ((x,y=0),z) - None should be valid actions too. What is the audience thinking about that? IMHO, it's just lambda in disguise, and I'm not sure it's more readable than lambda. You'll have to provide more arguments (sorry for the pun !-) to gain my adhesion. (NB : I could use this syntax without problem, it's just that we already have a syntax for this). -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Op 2005-03-22, Claudio Grondi schreef [EMAIL PROTECTED]: For me, one of the reasons for using Python is the ease and the intuivity of reading its code. I have a problem with intuitively getting what is going on when using a pattern like (x,y,z=0) - (x,y,z) where I expect at the first glance some C code with access to class members. At least I must start looking at the code more closely thinking why is someone using such a construct. Already lambda x,y,z=0:(x,y,z) is a problem for me. Why not: try: (x,y,z) except NameError: z=0 (x,y,z) ? Because they are not equivallent. Watching the last piece of code can even directly be seen, that there is eventually a NameError problem with z to handle, And suppose there is a NameError with x, your piece of code will then assign 0 to z. Do you think that is what the original code wanted? so where is the gain of using lambda or the mapping? Is is usable as an argument. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Using default a empty dictionary as a default value
Dear All, I ran my code through pylint to clean it up and one of the (many) errors it through up was Dangerous default value {} as argument Bascially, I have: class NewClass: def __init__(self, myDict={}): for key, value in myDict: print key, value Obviously, this is not the way it should be done. Should I have a default value of None for myDict and test for it? Or is there some other way? Thanks Colin -- http://mail.python.org/mailman/listinfo/python-list
Re: Using default a empty dictionary as a default value
C Gillespie wrote: Dear All, I ran my code through pylint to clean it up and one of the (many) errors it through up was Dangerous default value {} as argument Bascially, I have: class NewClass: def __init__(self, myDict={}): for key, value in myDict: print key, value Obviously, this is not the way it should be done. Should I have a default value of None for myDict and test for it? Or is there some other way? Yes. That's the way to go. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: Using default a empty dictionary as a default value
C Gillespie wrote: Dear All, I ran my code through pylint to clean it up and one of the (many) errors it through up was Dangerous default value {} as argument Bascially, I have: class NewClass: def __init__(self, myDict={}): for key, value in myDict: print key, value Obviously, this is not the way it should be done. Should I have a default value of None for myDict and test for it? Or is there some other way? Take a look at: http://www.python.org/doc/2.4/tut/node6.html#SECTION00671 look for Important warning HTH -- (@ @) oOO(_)OOo-- Ojo por ojo y el mundo acabara ciego /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) --- -- http://mail.python.org/mailman/listinfo/python-list
(noob alert) why doesn't this work?
Hi, I'm a bit stuck with this python script. It's aim is to encode all flac files to wav and then to mp3. The only problem I have is to preserve the tags. The code works when there's just one flac file in a directory but fails for more. I can't see why the for loop fails here (flactags). The error thrown is: UnboundLocalError: local variable 'title' referenced before assignment I don't understand why this isn't assigned. I suspect that self.wav2mp3 doesn't wait for the first part to finish, but how to force it to wait? Can somebody help please? The code: #!/usr/bin/env python import os import glob import sys class program: def makewavdir(self): if os.path.isdir('wav'): print There already exists a directory named wav print The album is probably already decoded to wav else: os.mkdir('wav') def flac2wav(self): flacfiles = glob.glob('*flac') for flac in flacfiles: print '*' * 70 print 'Starting decoding %s to wav' % flac os.system('flac -d -s %s -o wav/%s.wav' % (flac, flac[0:-5])) print '*' * 70 print All files are decoded to wav in the folder wav print '*' * 70 print def makemp3dir(self): if os.path.isdir('mp3'): print There already exists a directory named mp3 print The album is probably already encoded in mp3 else: os.mkdir('mp3') def wav2mp3(self, flac, title, artist, album, year, number, genre): os.system('lame --preset standard -V 2 --tt %s --ta %s --tl %s --ty \ %s --tn %s --tg %s --id3v2-only wav/%s.wav mp3/%s.mp3' %(title, \ artist, album, year, number, genre, flac[:-5], flac[:-5])) def flactags(self): flacfiles = glob.glob('*flac') flacfiles.sort() for flac in flacfiles: cmd = 'metaflac --export-tags=- %s' % flac for line in os.popen(cmd).readlines(): if 'Artist' in line: artist = line[7:-1] if 'Album' in line: album = line[6:-1] if 'Date' in line: year = line[5:-1] if 'Title' in line: title = line[6:-1] if 'Tracknumber' in line: number = line[12:-1] if 'Genre' in line: genre = line[6:-1] self.wav2mp3(flac, title, artist, album, year, number, genre) x = program() x.makewavdir() x.flac2wav() x.makemp3dir() x.flactags() -- http://mail.python.org/mailman/listinfo/python-list
Re: (noob alert) why doesn't this work?
On Tue, 22 Mar 2005 12:10:50 +0100, Bouke Woudstra [EMAIL PROTECTED] wrote: Hi, I'm a bit stuck with this python script. It's aim is to encode all flac files to wav and then to mp3. The only problem I have is to preserve the tags. The code works when there's just one flac file in a directory but fails for more. I can't see why the for loop fails here (flactags). The error thrown is: UnboundLocalError: local variable 'title' referenced before assignment Perhaps you get to line 56 without having gone through line 51? Might one of your flac files not have a title line? I don't understand why this isn't assigned. I suspect that self.wav2mp3 doesn't wait for the first part to finish, but how to force it to wait? Nope. Looks asynchronous to me. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Why not: try: (x,y,z) except NameError: z=0 (x,y,z) ? instead of lambda x,y,z=0:(x,y,z) Because it does not do the same thing ?-) Haven't got the idea why? (pedantic?) Because, if it did, it would still require 5 times more lines of code to do the same thing (hence it's more error-prone by a factor a 5) ? I don't like to mix the idea of compression with the idea of programming. The amount of code doesn't matter much to me, when readability suffers. This becomes obvious, when one skips any comments and name all variables with two letter codes in the script, making it much more compact. By the way, I could also write: try:(x,yz) except NameError:z=0;(x,y,z) reducing the number of lines to two, but I don't, because in my eyes I can read the code better if spread over five lines and because of this, the code becomes in my opinion even less error-prone. Actually I would write in my code: try: (x,y,z) except NameError: z=0 (x,y,z) #:try/except inreasing the number of lines to six in order to see directly, where the end of try:/except construct is. Because it uses an exception, which is far less efficient than using a default argument ? Efficiency is not the key point for me. If I need efficiency I go to C(C++) anyway. From my past experience I know, that defaults lead very often to problems, because one tends to forget, that there is a default value and is confused by the outcome in which values not explicitly mentioned in the code occure, leading to deep confusion (especially if hidden in modules and libraries). So I try to avoid defaults where it is possible, using them if they don't harm the outcome i.e. are related to internal way of processing within a function or are really obvious and can be expected. If the exception is the problem, why not setting somewhere at the early beginning of the code z=0 and then use (x,y,z) ? Does the lambda in this case just not try to get straight what was caused by the bad concept and therefore bad design of the script code flow? Because the name error could be on x and/or y too, and the try:except clause would hide it ? I can't see why try:except hides it? at least at the next line with (x,y,z) the problem with x or y will cause an error. Watching the last piece of code can even directly be seen, that there is eventually a NameError problem with z to handle, No. AFAICT, the name error could be with x and/or y and/or z. see upper. so where is the gain of using lambda or the mapping? Sorry, but I still can't see the advantage of lambda, at least not in this example. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: (noob alert) why doesn't this work?
The error thrown is: UnboundLocalError: local variable 'title' referenced before assignment That should be pretty obvious: The UnboundLocalError comes up when you try to access a variable that hasn't been assigned a value before. E.g try this in an interactive python session: foo = hello print foo print bar # This will raise UnboundLocalError Now in your code, you have a conditional setting of diverse variables. So only if if 'Title' in line: title = line[6:-1] executes, a title is there. Later, you _always_ use title. So you have to do it like this: title = Unknown # or empty or whatever if 'Title' in line: title = line[6:-1] Then title will always be there. The reason that it works for _one_ but not for all is simply that by chance the one file _had_ a title, but at least one of all the files hadn't. So it crashes. If you'd only try that file, it would also crash with only one file. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: Constructor class problem
Diez B. Roggisch wrote: Wolfgang wrote: Hi, I am a newbie and have to modify some python moduls. I get the followin error: TypeError: __init__() takes exactly 3 arguments (2 given) Here the code snippet: class gXconv: def __init__(self, pathValue): self.pathValue=pathValue self.__sections = {} self.__spalten = {} self.labelfiles=[] etc. call: try: gx=gXconv.gXconv(gXconfPath) except gXconv.gXconvertError, msg: print msg sys.exit(1) That error can't appear in the above code - is the line in the stacktrace amongst the shown ones? I doubt it. The error means that you tried to call a function with less arguments than it expected. As in __init__ the first argument is implicit on creation of an object, the above errormessage indicates that there is an __init__ of the form class Foo: def __init__(self, arg1, arg2) pass called like this Foo(bar) But as the only constructor you show _has_ only one additional argument besides self and line gx=gXconv.gXconv(gXconfPath) shows that you called it properly, the error must come from somewhere else. And the easiest way to track it down is to add some temporary print I am in some function or method name. debug messages through your code. By looking at which messages pop up, you can trace what happens just before your program bombs. Joal -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Already lambda x,y,z=0:(x,y,z) is a problem for me. Why not: try: (x,y,z) except NameError: z=0 (x,y,z) ? Because they are not equivallent. Watching the last piece of code can even directly be seen, that there is eventually a NameError problem with z to handle, And suppose there is a NameError with x, your piece of code will then assign 0 to z. Do you think that is what the original code wanted? Ok, I see. But inspite of the fact, that I have overseen this while writing the code, this bad assignment won't much matter, because the script will fail anyway in (x,y,z), so there will be no effect on the subsequent code. If I had written: try: z except NameError: z=0 #:try/except (x,y,z) I would be closer to the original idea behind lambda x,y,z=0:(x,y,z) right? [lambda] It is usable as an argument. I have to admit, that I still don't understand the concept behind lambda, because this construct in new to me. Maybe it is because I still haven't seen any example making it clear, why lambda is the only or at least the better way to go. Even if I am very interested in understanding and discussing lambda related matters here, I see, that with discussing it we are probably far away from the original intent of Kay who expects in this thread postings expressing an opinion about introduction of the (x,y,z=0) - (x,y,z) construct in Python. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Getting the word to conventional programmers
*DevSource* profiles The State of the Scripting Universe in URL: http://www.devsource.com/article2/0,1759,1778141,00.asp . -- http://mail.python.org/mailman/listinfo/python-list
Re: Using default a empty dictionary as a default value
C Gillespie wrote: Dear All, I ran my code through pylint to clean it up and one of the (many) errors it through up was Dangerous default value {} as argument Bascially, I have: class NewClass: def __init__(self, myDict={}): for key, value in myDict: print key, value Obviously, this is not the way it should be done. Should I have a default value of None for myDict and test for it? Or is there some other way? If you *know* you will not be modifying the contents of myDict, and you *know* you will not be modifying the function in the future to do so, then it's completely safe as written... -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting the word to conventional programmers
Cameron Laird wrote: *DevSource* profiles The State of the Scripting Universe in URL: http://www.devsource.com/article2/0,1759,1778141,00.asp . Which, sadly, doesn't seem to work with Firefox here, though IE shows it fine. :-( -- http://mail.python.org/mailman/listinfo/python-list
Re: Python becoming less Lisp-like
Op 2005-03-21, Jeff Shannon schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-03-18, Jeff Shannon schreef [EMAIL PROTECTED]: I find it odd that you start by saying you still find them very consistent and here state there is a slight inconsistency. I said that the way that binding a name on a class instance always creates an instance attribute regardless of the presence of a similarly-named class attribute is consistent with the way that name binding works in any scope. This is true. Binding of a name within a function-local scope works the same way -- bindings are always created within the narrowest scope unless something is explicitly done to force other behavior. But bindings in function scope happen earlier. There already happens some kind of binding at call time. If it wouldn't you wouldn't get an UnboundLocalError but just a NameError. What seems to happen is that at call time all local variable get prebound to somekind of illegal value and if they still have this illegal value when you acces them, python raises the UnboundLocalError To have something consistent with that with instances and classes would mean that the interpreter would find out what attributes could possible be created and do the samekind of prebindind so that if you accessed such an attribute you wouldn't get an AttributeError but something like an UnboundAttributeError. You pointed out a case in which class/instance attributes behave slightly differently than local/global names do, and I agree with you that there is a difference in behavior there. However, that difference is in the way that bare names are resolved into local/global references, and *not* in the way that name binding works. Well I don't agree. If name binding would work the same, I would expect other exceptions. The name binding rules are consistent; the inconsistency is in name *lookups*, I'm not convinced. The lookup can find out about such cases on intermediate scopes. I doubt that the lookup knows at the start at what level he is going to find the name. So either he keeps the name of local variables of each function somewhere, to do the special case if the variable is local on that level or the name has to be prebound somehow. and is a case of strong optimization of the standard case affecting the behavior of an unusual (and strongly discouraged) case. That only affects the behaviour of an unusual (and strongly discouraged) case, doesn't make it consistent. It may be a good argument for choosing to do it this way despite it being (slightly) inconsisten. It is not an argument for it being consistent. There is a slight inconsistency in something *other* than what the O.P. was complaining about being inconsistent; I'm recognizing that inconsistency at the same time as I'm attempting to point out that the other inconsistency really *is* consistent. (I'm also pointing out that this name-lookup inconsistency is a good example of practicality beats purity, because the value of the optimization is, IMO, much greater than the cost of the inconsistency.) I'm not so sure, but I'm not going to argue this. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Dabo 0.3.2 Released
Just in time for PyCon DC 2005, we'd like to announce the release of Dabo 0.3.2. A summary of what's changed since the last release can be found at http://dabodev.com/announcements/changeLog-0.3.2. Source code is available for download at http://dabodev.com/download. ___/ / __/ / / Ed Leafe http://leafe.com/ http://dabodev.com/ Come to PyCon http://www.python.org/pycon/2005/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting the word to conventional programmers
Peter Hansen schrieb: Cameron Laird wrote: *DevSource* profiles The State of the Scripting Universe in URL: http://www.devsource.com/article2/0,1759,1778141,00.asp . Which, sadly, doesn't seem to work with Firefox here, though IE shows it fine. :-( Mozilla 1.7.3 shows it fine, too. FF bug or config issue? -- --- 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: Getting the word to conventional programmers
Peter Maas wrote: Peter Hansen schrieb: Cameron Laird wrote: *DevSource* profiles The State of the Scripting Universe in URL: http://www.devsource.com/article2/0,1759,1778141,00.asp . Which, sadly, doesn't seem to work with Firefox here, though IE shows it fine. :-( Mozilla 1.7.3 shows it fine, too. FF bug or config issue? FF didn't show it to me earlier, but it seems to work now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python becoming less Lisp-like
Antoon Pardon wrote: Op 2005-03-21, Jeff Shannon schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-03-18, Jeff Shannon schreef [EMAIL PROTECTED]: I find it odd that you start by saying you still find them very consistent and here state there is a slight inconsistency. I said that the way that binding a name on a class instance always creates an instance attribute regardless of the presence of a similarly-named class attribute is consistent with the way that name binding works in any scope. This is true. Binding of a name within a function-local scope works the same way -- bindings are always created within the narrowest scope unless something is explicitly done to force other behavior. But bindings in function scope happen earlier. There already happens some kind of binding at call time. If it wouldn't you wouldn't get an UnboundLocalError but just a NameError. What seems to happen is that at call time all local variable get prebound to somekind of illegal value and if they still have this illegal value when you acces them, python raises the UnboundLocalError They don't get pre-bound to some kind of illegal value. The parser determines due to the presence in the function's code of an assignment with that name as object - by STATIC analysis - that the name is local, and therefore generates local references for it. It's the failure of a local read that gives rise to the UnboundLocalError. If you want to talk about this as a binding you can, I suppose. In actual fact, though, it's the code object's co_names attribute that says which names are to be regarded as local, as far as I understand it. To have something consistent with that with instances and classes would mean that the interpreter would find out what attributes could possible be created and do the samekind of prebindind so that if you accessed such an attribute you wouldn't get an AttributeError but something like an UnboundAttributeError. You appear to be asking for a very explicit (and extremely ambitious) type of optimization here. You pointed out a case in which class/instance attributes behave slightly differently than local/global names do, and I agree with you that there is a difference in behavior there. However, that difference is in the way that bare names are resolved into local/global references, and *not* in the way that name binding works. Well I don't agree. If name binding would work the same, I would expect other exceptions. The name binding rules are consistent; the inconsistency is in name *lookups*, I'm not convinced. The lookup can find out about such cases on intermediate scopes. I doubt that the lookup knows at the start at what level he is going to find the name. So either he keeps the name of local variables of each function somewhere, to do the special case if the variable is local on that level or the name has to be prebound somehow. and is a case of strong optimization of the standard case affecting the behavior of an unusual (and strongly discouraged) case. That only affects the behaviour of an unusual (and strongly discouraged) case, doesn't make it consistent. It may be a good argument for choosing to do it this way despite it being (slightly) inconsisten. It is not an argument for it being consistent. There is a slight inconsistency in something *other* than what the O.P. was complaining about being inconsistent; I'm recognizing that inconsistency at the same time as I'm attempting to point out that the other inconsistency really *is* consistent. (I'm also pointing out that this name-lookup inconsistency is a good example of practicality beats purity, because the value of the optimization is, IMO, much greater than the cost of the inconsistency.) I'm not so sure, but I'm not going to argue this. Great. I though you were going to start up with the snails again ... :-) regards Steve -- Meet the Python developers and your c.l.py favorites March 23-25 Come to PyCon DC 2005 http://www.pycon.org/ Steve Holden http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpc with Python and large datases
writeson wrote: Duncan, Thanks for the reply. We are running this on an Apache server on the linux box, and an iPlanet4.1 server on the solaris machines. However, both these servers are strictly 'inside' the firewall. I checked the apache configuration and there is no limitrequestbody parameter in the file at all. So I'm assuming from what you've said that our configuration would be unlimited. However, I will test that by inserting limitrequestbody and setting it to 0 for unlimited to see if that changes things. Thanks, Doug Usually a broken pipe message is to do with disruption of a Unix pipeline rather than a network connection. I've seen the message mostly, IIRC, in BSD-based environments. A pipeline connects the standard output of one process to the standard input of another. If this second process terminated while the first is still writing its output the broken pipe message will be raised. It's therefore probable that some consumer process is terminating before its producer. Whether this is due to timeouts in the server environment is open to question, but at least you'll be looking for the right problem :-) regards Steve -- Meet the Python developers and your c.l.py favorites March 23-25 Come to PyCon DC 2005 http://www.pycon.org/ Steve Holden http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Op 2005-03-22, Claudio Grondi schreef [EMAIL PROTECTED]: reducing the number of lines to two, but I don't, because in my eyes I can read the code better if spread over five lines and because of this, the code becomes in my opinion even less error-prone. Actually I would write in my code: try: (x,y,z) except NameError: z=0 (x,y,z) #:try/except inreasing the number of lines to six in order to see directly, where the end of try:/except construct is. Because it uses an exception, which is far less efficient than using a default argument ? Efficiency is not the key point for me. If I need efficiency I go to C(C++) anyway. From my past experience I know, that defaults lead very often to problems, because one tends to forget, that there is a default value and is confused by the outcome in which values not explicitly mentioned in the code occure, leading to deep confusion (especially if hidden in modules and libraries). So I try to avoid defaults where it is possible, using them if they don't harm the outcome i.e. are related to internal way of processing within a function or are really obvious and can be expected. If the exception is the problem, why not setting somewhere at the early beginning of the code z=0 and then use (x,y,z) ? Because that wouldn't work with the kind of code that was being discussed being: for x,y,z in some_iterator: If some_iterator produces at some time a tuple with only two elements this will raise an exception no matter whether you assigned z already or not. Does the lambda in this case just not try to get straight what was caused by the bad concept and therefore bad design of the script code flow? Why should we assume the concept or design was bad? Suppose we have an algoritme that works with 3d points. Now we find out the algorithm works equally fine with 2d points if we assume this 2d points lie in the z plane. Wouldn't giving z the value 0 in the case of only two elements perfectly allow us to use this 3d algorthm with 2d points? Just because you can't imagine were this would be helpfull doesn't make it a bad concept or design. so where is the gain of using lambda or the mapping? Sorry, but I still can't see the advantage of lambda, at least not in this example. The lambda would allow us to insert the functionallity locally without the need to an function that is define somewhere else. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: (noob alert) why doesn't this work?
Thanks for all suggestions. Your first point I knew, but was too lazy to type it. It made no difference for the test files had all tags. Knowing that it was not a asynchrous thing helped me a lot though. There had to be something wrong with the command line for metaflac. It turned out that some flac files have tags like Artist=artistname and others have artist=artistname. Therefore it couldn't find the artist! So now I just look for 'rtist=' which works great. Thanks for all the help! Op dinsdag 22 maart 2005 12:18, schreef Simon Brunning: On Tue, 22 Mar 2005 12:10:50 +0100, Bouke Woudstra [EMAIL PROTECTED] wrote: Hi, I'm a bit stuck with this python script. It's aim is to encode all flac files to wav and then to mp3. The only problem I have is to preserve the tags. The code works when there's just one flac file in a directory but fails for more. I can't see why the for loop fails here (flactags). The error thrown is: UnboundLocalError: local variable 'title' referenced before assignment Perhaps you get to line 56 without having gone through line 51? Might one of your flac files not have a title line? I don't understand why this isn't assigned. I suspect that self.wav2mp3 doesn't wait for the first part to finish, but how to force it to wait? Nope. Looks asynchronous to me. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pre-PEP: Dictionary accumulator methods
Greg Ewing wrote: Michele Simionato wrote: def defaultdict(defaultfactory, dictclass=dict): class defdict(dictclass): def __getitem__(self, key): try: return super(defdict, self).__getitem__(key) except KeyError: return self.setdefault(key, defaultfactory()) return defdict That looks really nice! I'd prefer a more elegant name than 'defaultdict', though. How about 'table'? By obvious analogy with Icon (where the dictionary-like object was created with the option of a default value) this gets my +1. regards Steve -- Meet the Python developers and your c.l.py favorites March 23-25 Come to PyCon DC 2005 http://www.pycon.org/ Steve Holden http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpc with Python and large datases
Steve Holden wrote: Usually a broken pipe message is to do with disruption of a Unix pipeline rather than a network connection. I've seen the message mostly, IIRC, in BSD-based environments. the socket layer uses EPIPE to indicate that a socket has been shut down by the remote end. /F -- http://mail.python.org/mailman/listinfo/python-list
Doubt regarding exec function
Dear All, Php has exec function to run system commands and this function return last line of system command result. But in Python I can see only os.system() function to run system command but it doesn't return any result like php exec function. I want to know about php equivalent exec function in Python. So If anyone know regarding this Kindly Mail me. with regards prabahar Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help for Python programming
Terry, This was posted from google groups, can you see the indents? # code snippet convertpage = 0 form = None for o, a in opts: if o in [-h, --help]: Usage() sys.exit() if o in [-o, --output, --out]: output = a if o in [-i, --input, --in]: input = a if input in [., cwd]: input = os.getcwd() Notice the 'fixed font / proportional font' link in the top right corner. I think they have fixed the problem. M.E.Farmer Terry Reedy wrote: This is what I see (minus the ' '): while 1: user, serviceType, msgType, inOut, date, time, numBytes = aLog.GetNextMessage() [etc] Advice: use spaces, not tabs, to indent posted code (some readers discard tabs). Don't use google groups to post code (it deletes initial spaces and won't, apparently, fix this bug). Use news.gmane.org group gmane.comp.python.genral instead (I believe they also have web interface in addition to newsreader interface). If you really, really must post thru google, prefix lines with char such as '|', even tho this kill cut and pastability. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
On 21 Mar 2005 22:37:42 -0800, Kay Schluehr [EMAIL PROTECTED] wrote: Mappings like that: ((x,y),z) - x+y-z ((x,y=0),z) - None should be valid actions too. What is the audience thinking about that? I think that there's too much implied, and that in the long run it, if we keep addding in special shortcuts, it will lead to very dificult to read code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python becoming less Lisp-like
Op 2005-03-22, Steve Holden schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-03-21, Jeff Shannon schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-03-18, Jeff Shannon schreef [EMAIL PROTECTED]: I find it odd that you start by saying you still find them very consistent and here state there is a slight inconsistency. I said that the way that binding a name on a class instance always creates an instance attribute regardless of the presence of a similarly-named class attribute is consistent with the way that name binding works in any scope. This is true. Binding of a name within a function-local scope works the same way -- bindings are always created within the narrowest scope unless something is explicitly done to force other behavior. But bindings in function scope happen earlier. There already happens some kind of binding at call time. If it wouldn't you wouldn't get an UnboundLocalError but just a NameError. What seems to happen is that at call time all local variable get prebound to somekind of illegal value and if they still have this illegal value when you acces them, python raises the UnboundLocalError They don't get pre-bound to some kind of illegal value. The parser determines due to the presence in the function's code of an assignment with that name as object - by STATIC analysis - that the name is local, and therefore generates local references for it. It's the failure of a local read that gives rise to the UnboundLocalError. If you want to talk about this as a binding you can, I suppose. In actual fact, though, it's the code object's co_names attribute that says which names are to be regarded as local, as far as I understand it. And does this code object know which non-local names are on an intermediate level and which are global? If not it seems the binding has to be more than just the code object's co_names attribute. To have something consistent with that with instances and classes would mean that the interpreter would find out what attributes could possible be created and do the samekind of prebindind so that if you accessed such an attribute you wouldn't get an AttributeError but something like an UnboundAttributeError. You appear to be asking for a very explicit (and extremely ambitious) type of optimization here. You misunderstand. I don't ask for this. I just argue that this is what should happen in order to make what happens in function scope and what happens with attributes (more) consistent with each other. What I was wondering, doesn't __slots__ do something like this? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt regarding exec function
Mosas wrote: Dear All, Php has exec function to run system commands and this function return last line of system command result. But in Python I can see only os.system() function to run system command but it doesn't return any result like php exec function. I want to know about php equivalent exec function in Python. So If anyone know regarding this Kindly Mail me. with regards prabahar os.popen or the popen2 module are what you are looking for. In python2.4 there is also subprocess I believe. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
regarding ignore case sensitive of a string using regular expressions
Dear All In Perl when we are checking some conditions using regular expression we can ignore the case sensitive of a string using the following regular expression /(^[^a-z])|/|(\.\.)/i. But If I try to do this in Python I couldn't get any result. So Any body know regarding this Kindly mail me with example. regards Prabahar Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony -- http://mail.python.org/mailman/listinfo/python-list
PythonWin (build 203) for Python 2.3 causes Windows 2000 to grind to a halt?
Hi, I am having the same problem and wondering if anyone was able to fix it? or provide an alternative to ActiveState pythonwin -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) i.e. mapping tuples on other tuples. This is equivalent to lambda x,y,z=0:(x,y,z) As you say for yourself, that's just lambda in disguise. So I guess the same arguments about the in- or exclusion of lambda apply here. I personally like lambda, but _can_ live without it. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: regarding ignore case sensitive of a string using regular expressions
Mosas wrote: In Perl when we are checking some conditions using regular expression we can ignore the case sensitive of a string using the following regular expression /(^[^a-z])|/|(\.\.)/i. But If I try to do this in Python I couldn't get any result. So Any body know regarding this Kindly mail me with example. RTFM: http://www.python.org/doc/2.3.4/lib/re-syntax.html (What you want is described under the (?iLmsux) heading) or http://www.python.org/doc/2.3.4/lib/node106.html Maarten -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
bruno modulix wrote: Kay Schluehr wrote: Since George Sakkis proposed a new way of doing list comprehensions http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ac5023ad18b2835f/d3ff1b81fa70c8a7#d3ff1b81fa70c8a7 letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) i.e. mapping tuples on other tuples. This is equivalent to lambda x,y,z=0:(x,y,z) which is in fact not a valid solution in the context of Georges' problem... (or I failed to get it to work !-) But regarding tuples as actions by means of an arrow - would generalize this idea: Mappings like that: ((x,y),z) - x+y-z ((x,y=0),z) - None should be valid actions too. What is the audience thinking about that? IMHO, it's just lambda in disguise, and I'm not sure it's more readable than lambda. You'll have to provide more arguments (sorry for the pun !-) to gain my adhesion. (NB : I could use this syntax without problem, it's just that we already have a syntax for this). Changing my mind after a more torough re-reading of the original thread and few tests... The original problem is about tuple unpacking. The proposed solution solves this problem, *and* can (could ?) be a replacement for lambdas. hmmm... I like the idea of having a more flexible tuple unpacking with a function-call-like semantic, but I'm still not sure to like the idea of replacing lambda with the proposed syntax. needs-some-more-thinking-on-this-ly'yrs -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
possible bug?
I've been having trouble with a program hanging when using the subprocess modules wait() method. Replacing it with with a loop that used poll() solved the problem. Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 | 7.3 The for statement
brainsucker wrote: Python 2.4 | 7.3 The for statement: --- for_stmt ::= for target_list in expression_list : suite [else : suite] New for statement: -- for_stmt ::= for target_list in expression_list [ and expression ] : suite [else : suite] ** If the expression evaluates to False before entering the for, jump else. ** If the expression is evaluated to False after the first iteration, break. I think that your idea is good but as others said the and literal could be confusing. ¿Maybe we can use another word instead of and? The for definition could be like this: for_stmt ::= for target_list in expression_list [ until expression ] : suite [else : suite] or some other word that clarifies the work of the expression leave_cond_1 = False leave_cond_2 = False mylist = [1,2,3,4,5] for item in mylist until leave_cond_1 or leave_cond_2: print item -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 | 7.3 The for statement
On 22 Mar 2005 06:32:38 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The for definition could be like this: for_stmt ::= for target_list in expression_list [ until expression ] : suite [else : suite] or some other word that clarifies the work of the expression leave_cond_1 = False leave_cond_2 = False mylist = [1,2,3,4,5] for item in mylist until leave_cond_1 or leave_cond_2: print item Still, this can be acomplished with the break statement, in a more clear way, with less variables (which implies less work for the gc and everybody). In your example, instead of verifying some condition and setting leave_cond_n to True, you just check the same condition, and use break. .Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://pyar.decode.com.ar/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
for x,y,z in some_iterator: If some_iterator produces at some time a tuple with only two elements this will raise an exception no matter whether you assigned z already or not. So if I now understand it right, the core of the whole proposal is to find a way to make unpacking of tuples work also in case the tuples have not the appropriate number of elements, right? So to achieve the same effect I need currently (not tested): for x,y,z in [getMyTargetTupleFrom(currentTuple) for currentTuple in tupleList] where getMyTargetTupleFrom(currentTuple) is: def getMyTargetTupleFrom(currentTuple): if len(currentTuple) = 3: return (currentTuple[0], currentTuple[1], currentTuple[2]) if len(currentTuple) == 2: return (currentTuple[0], currentTuple[1], 0) right? Is it really worth it? Isn't it much easier to convert the list of tuples explicit to appropriate format, first? It seems, that my attitude to the proposal is originated from bad experience with default values. To get it tracked down to the point: In my opinion default values are evil and it is enough trouble that function defintions allow them. I have seen already postings of confused newbies expecting the default values beeing set during function execution not during definition and I have also faced this problem starting on Python myself . Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Claudio Grondi wrote: for x,y,z in some_iterator: If some_iterator produces at some time a tuple with only two elements this will raise an exception no matter whether you assigned z already or not. So if I now understand it right, the core of the whole proposal is to find a way to make unpacking of tuples work also in case the tuples have not the appropriate number of elements, right? That's the original problem at least. Kay seems to be wanting to extend a possible solution to this problem to a lambda replacement, which is IMHO another point. So to achieve the same effect I need currently (not tested): for x,y,z in [getMyTargetTupleFrom(currentTuple) for currentTuple in tupleList] where getMyTargetTupleFrom(currentTuple) is: def getMyTargetTupleFrom(currentTuple): if len(currentTuple) = 3: return (currentTuple[0], currentTuple[1], currentTuple[2]) if len(currentTuple) == 2: return (currentTuple[0], currentTuple[1], 0) right? Yes Is it really worth it? I think so. The problem of unpacking tuple of the wrong size is a common one (at least for me), and having to write a special function to handle the case, or use try:except blocks, dont make for more readable code IMHO. The possibility to clearly and cleanly handle the case *when it's an expected case* and *as close as possible* to where it happens would (always IMHO) improve readability. What do you find most readable: your version, with an ad-hoc function defined somewhere else, far away in the code, or a simpler: for (x,y,z=0) in tupleList: do_whatever_with_it() Isn't it much easier to convert the list of tuples explicit to appropriate format, first? This *is* an explicit conversion. Much more explicit than a function buried xxx lines of code away IMHO. (and BTW, It also avoid to have to build two lists.) It seems, that my attitude to the proposal is originated from bad experience with default values. To get it tracked down to the point: In my opinion default values are evil and it is enough trouble that function defintions allow them. Python would barely be usable without. I have seen already postings of confused newbies expecting the default values beeing set during function execution not during definition and I have also faced this problem starting on Python myself . There are a lot of features in any language that are at first sight confusing, specially when these features look like features existing in another language but fail to behave like in the other language. half-troll Removing anything that could confuse anyone having only experience with language X or Y leads to Java - an average language designed for average programmers, where the lack of expressive power leads to overly complicated code to get simple things done. /half-troll -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: compiled open source Windows lisp (was Re: Python becoming less Lisp-like)
On 16 Mar 2005 06:37:45 -0500, Carl Shapiro [EMAIL PROTECTED] wrote: I have a virtually completed port of CMUCL to Win32. And, if I was not busy organizing a Lisp conference, it would be publicly available by now. If it's the conference I think, then the deadline for papers was about a week ago. I suspect that most of the other routine parts have been taken care of leaving scheduling. IOW your time is freeing up. OTOH it may just be wishful thinking on my part. Any idea how much longer? The reply-to email address is [EMAIL PROTECTED] This is an address I ignore. To reply via email, remove 2002 and change yahoo to interaccess, ** Thaddeus L. Olczyk, PhD There is a difference between *thinking* you know something, and *knowing* you know something. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Diez B. Roggisch wrote: letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) i.e. mapping tuples on other tuples. This is equivalent to lambda x,y,z=0:(x,y,z) As you say for yourself, that's just lambda in disguise. Not exactly in fact - unless I messed something. There are 2 problems here: a more flexible tuple unpacking, *and* a lambda in disguise. Actually, I'd go + 1 for the first, -1 for the second So I guess the same arguments about the in- or exclusion of lambda apply here. For the second part, yes. Not for the first one. I personally like lambda, but _can_ live without it. Yes, one can live without... troll ...and without list comprehensions, __call__ and other special methods, descriptors, metaclasses, first class functions, builtin datatypes like lists and dicts, exceptions, dynamic typing, garbage collection, etc too. Hurray, let's all happily program in assembly !-) /troll -- bruno desthuilliers ruby -e print '[EMAIL PROTECTED]'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@') -- http://mail.python.org/mailman/listinfo/python-list
Best IDE
If money is not an issue, what are the best options for a Professional IDE for Python that includes all the normal stuff PLUS a GUI Builder?? Its an open ended question but I need some opinions from those that have actually used some stuff. This is for a business producing in house programs for use within only. Thanks, Tom :. CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.-- http://mail.python.org/mailman/listinfo/python-list
Submission for Python Limmerick Contest
My submission for P.L.C. A mathematican named van Rossum went hunting for opossum he could not find one all eaten by Python to her his language he named as a blossum wish me luck Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
On Tue, Mar 22, 2005 at 07:16:11AM -0700, Earl Eiland wrote: I've been having trouble with a program hanging when using the subprocess modules wait() method. Replacing it with with a loop that used poll() solved the problem. Please include an example, and more information about what platforn you're using This simple program worked fine for me on Linux with Python 2.4: # import subprocess, time s = subprocess.Popen(['sleep', '2']) while 1: time.sleep(.1) if s.poll() is not None: break print polling wait done, s.returncode s = subprocess.Popen(['sleep', '2']) s.wait() print blocking wait done, s.returncode # Jeff pgpq6ATZLp4Bp.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Not exactly in fact - unless I messed something. There are 2 problems here: a more flexible tuple unpacking, *and* a lambda in disguise. Actually, I'd go + 1 for the first, -1 for the second The proposed syntax from Kay is lambda in disguise. To make it work like George want it is modifying the unpacking behaviour. Actually while Kay proposed his syntax as result of the discussion started by George it won't work for that case. The reason is simply that the lambda form returns a tuple, but does not make any revelations about the variable names that tuple shall be unpacked to. So they are in fact unrelated - at least if introduced as declared. An augmentation to fulfill George's wishes could look like this: [a,b,c for a,b,c: (x,y,z=0)- x,y,z) in values] Yes, one can live without... troll ...and without list comprehensions, __call__ and other special methods, descriptors, metaclasses, first class functions, builtin datatypes like lists and dicts, exceptions, dynamic typing, garbage collection, etc too. Hurray, let's all happily program in assembly !-) /troll You are right, but for lambda in its current limited form short, named functions are a good replacement. I don't want to get rid of lambda - but since listcomps got introduced, 95% of my usages of them disappeared. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: Submission for Python Limmerick Contest
A tuple, a dict, and a list, And whitespace which mus'n't be missed. Imported together, And stirred with a feather, Yields a language whose name must be hissed! -- http://mail.python.org/mailman/listinfo/python-list
Re: pyopengl and py2exe
You excluded them, so they're going to be missing as far as it is concerned. When you copy the OpenGL directory as per the instructions, it should work fine. Does it? -- http://mail.python.org/mailman/listinfo/python-list
[perl-python] sorting matrixes
Today we'll write a program that can sort a matrix in all possible ways. Here's the Perl documentation. I'll post a Perl and Python version in 2 days. --- sort_matrix( $matrix, [[$n1, $stringQ, $directionQ], [$n2, $stringQ, $directionQ], ...]) sorts a matrix by $n1 th column then $n2 th...and so on. $matrix must be a reference to references of arrays, having the form [[$e1, $e2,...], [...], ...]. $stringQ is a boolean indicating whether to treat corresponding columns as a strings instead of as number in the sorting process. True means string. $directionQ is a boolean indicating ascending sort or not for the correpsonding column. In the column spec $n1 $n2 ..., index counting starts at 0. Example: my $ref_matrix = [ [3, 99, 'a'], [2, 77, 'a'], [1, 77, 'a'] ]; sort_matrix( $ref_matrix, [ [2,1,1], [1,0,1] ]); # this means sort by third column, regarding it as strings, # and in ascending order. If tie, sort by second column, # regarding it as number, in ascending order. # returns [[2,77,'a'],[1,77,'a'],[3,99,'a']]; -- Note: in the above, ignore the must be a reference to references of arrays. That's technical point, because Perl the language do nested lists thru workaround of references. http://xahlee.org/perl-python/sort_matrix.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
On Tue, 22 Mar 2005 15:05:55 +0100, bruno modulix [EMAIL PROTECTED] wrote: bruno modulix wrote: Kay Schluehr wrote: Since George Sakkis proposed a new way of doing list comprehensions letting tuples-like objects (x,y,z=0) acting as functions on other tuples I wonder why this would not be a good starting point of rethinking anonymus functions? In Georges proposition the action is (x,y,z=0) - (x,y,z) What about a safe exec as a replacement to lamba but witht he flexability of exec in a safe and limeted way? safe_exec ( (*inputs) , (expressionstring) , ( *outputs) ) Functon to return a default value: def dfv( arg = value): return arg Safe exec command: x, y = 1, 2 safeexec ( (x, y, dfv(z=0)), # do nothing, ( x, y, z) ) (1, 2, 0) What could we do, not do with this? * I actually started this reply here, so below is how I got to the above exression. I'm trying to put my finger on the basic inconsistency here. It has something to do with the z=0 as a way to defining a default . Then there's the lamba which I hear may be removed, but is difficult to understand for beginners, and isn't readable in that the name doesn't say what it does. An alternative name, and possibly a simpler syntax would be a plus. Another concept that this touches is the indirect execution of an expression. Exec and eval do that, but then you introduce security issues. I'm wondering if there's a fundamental concept under these issues such as a base function class or command that can evaluate the contents of a tuple in a secure way? value = fn(arg, returnvalue) x = 1 fn( x, x*2) 2 Use lists or tuples for multiple arguments and return expressions: x, y, z = 1, 2, 3 fn( (x,y,z=0), (x,y,z) ) (1, 2, 3) But it's that z=0 causes problems here. In a tuple it's equivalent to saying 1=2. or 'a'='b' So we need a way to say 'if name is undefined, bind it to object'. # function to give a default value def dfv( arg = value): return arg x, y = 1, 2 fn( (x, y, dfv(x=0)), ( x, y, z )) (1, 2, 3) Now since this could execute in it's own private space, it might also offer a way to use exec or eval() indirectly in a very limited and safe way. estring = \ result = '' data = 'abcdefghigklmnop' for ch in data: if ch != filterc: result.join(ch) fn( ( dfv(filterc='d'), evalstring), (exec estring) ) So we need to use a three item tuple: safe_exec ( (*inputs) , (expressionstring) , ( *outputs) ) def dfv( arg = value): return arg x, y = 1, 2 safeexec( (x, y, dfv(z=0)), # do nothing, ( x, y, z) ) (1, 2, 0) Long way around to here, but is this something that has potential? It would have to be a built in to ensure it's safe to use. But with an exec string, it can possibly do a lot more than lamba, and it probably wouldn't be as fast. But the flexibility could be useful. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: (noob alert) why doesn't this work?
Bouke Woudstra wrote: It turned out that some flac files have tags like Artist=artistname and others have artist=artistname. Therefore it couldn't find the artist! So now I just look for 'rtist=' which works great. You might want try using something like this: wanted = set('artist album date title tracknumber genre'.split()) ... def read_and_call(self, flac, source): parts = {} for line in source: try: head, remainder = line.split('=', 1) except ValueError: pass # No equal sign in the line else: head = head.strip().lower() if head in wanted: parts[head] = remainder.strip() self.wav2mp3(flac, **parts) -- http://mail.python.org/mailman/listinfo/python-list
The Running Time of +=
What is the running time of conactination on character strings. i.e. joe=123 joe+=9 is it Amortized Constant time? I don't think it would be O((number of chars)^2) but i really don't know. Teach me how to fish, where would i find out more about the internal representations of data types in python (and guarenteed run times, im think of something like sgi.com 's info on the STL) . I have looked through the docs but i don't seem to see these types of specifications. thanks * 100 - Haz -- http://mail.python.org/mailman/listinfo/python-list
.pth files?
I'm unclear on how .pth files work. Some posts imply they can be arbitrarily named, as long as they include the .pth extension, and can exist anywhere in the current sys.path. Other documentation seems to imply that they must be named package.pth, although I'm not sure what package it would be named after. I used strace to see if I could see which files it was looking for, but the output didn't show a single attempted stat() or open() of any .pth files. I may be barking up the wrong tree with the .pth files, anyway. Is there a general best practice for appending additional directories to search for modules? Specifically, I frequently write utilities that depend on a shared module or two that I don't particularly want to stick in the site-packages directory. The layout I generally prefer is a lib dir in the same directory as the assorted scripts. Clearly, I could just do a 'sys.path.append[./lib]', but that seems kludgy. Any clarifications or recommendations? Thanks! -Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
What do you find most readable: your version, with an ad-hoc function defined somewhere else, far away in the code, or a simpler: for (x,y,z=0) in tupleList: do_whatever_with_it() I came up with the ad-hoc function to give a kind of replacement for the used syntax, in order not to ask why not immediately: for tuple in tupleList: do_whatever_with_it() ? Sure I like the syntax as long as I think in terms of unpacking tuples, but at the first glance I thought that the intention was to get only x, y from the tuple setting all z in the yielded tuples to zero (as suggested in this thread by giving the example of going from 3D down to 2D where with all z=0 the algorithm will remain the same). What about for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList ? What if the tupleList is empty? Should existing z be set to zero or not after the line with the for loop was executed? Should for (,y) in tupleList: do_whatever_with_it() give only the y and for (,,z) in tupleList: only the z values? If it should become possible to use the for (x,y,z=0) in tupleList syntax, I would sure like also to have: for (,,z) in tupleList for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList for (x,y,if z not in tupleList: z=0 else: z=2*x*z) in tupleList and sure also: for (x,y,z=0, *r) in tupleList etc. My only objections are: Is it worth the effort? Would it not be confusing? Maybe starting with e.g. a xlistcomprehension module where xlistcomprehension.execute( [for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList] ) or just xl(...) to keep it short provides the desired functionality is a good idea? Then it can be seen if this module becomes widely used and therefore worth to be integrated? I think it would be nice to have, but I can't imagine it to be really very helpful. It is sure a long way before the concept of it becomes so mature, that all who see it say: Wow, why was it not from the very beginning there? Claudio -- http://mail.python.org/mailman/listinfo/python-list
C type buffer copy
Hello, How does Python deal with C type memory buffers. Does Python return everything as an object irrespective of the data type? Here's what i am trying to achieve? testCode(unsigned char buf, unsigned long len) { unsigned long data=0x0; while (len--) { *buf++ = (unsigned char)data++ } } What's the best way to deal with this in python? -Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Claudio Grondi wrote: What do you find most readable: your version, with an ad-hoc function defined somewhere else, far away in the code, or a simpler: for (x,y,z=0) in tupleList: do_whatever_with_it() I came up with the ad-hoc function to give a kind of replacement for the used syntax, in order not to ask why not immediately: for tuple in tupleList: do_whatever_with_it() ? What if do_whatever_with_it() waits for a triplet, we have a list of mixed pairs and triplets, and augmenting pairs with a 0 would do for us? As I said, there's always a way to do it as long as the language is turing complete. The problem is with is of use and readiblity - expressive power - which, I agree, is at least somewhat subjective !-) Sure I like the syntax as long as I think in terms of unpacking tuples, but at the first glance I thought that the intention was to get only x, y from the tuple setting all z in the yielded tuples to zero (as suggested in this thread by giving the example of going from 3D down to 2D where with all z=0 the algorithm will remain the same). What about for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList ? Should be: for x, y, if [???]:z=0 else:z=1 in tupleList: # etc This Would do for me. But since we're not going to have a ternary woperator (or everything's-an-expression for that matter)... What if the tupleList is empty? No iteration. Should existing z be set to zero or not after the line with the for loop was executed? should follow the same rule as for other vars. Should for (,y) in tupleList: do_whatever_with_it() give only the y and for (,,z) in tupleList: only the z values? Don't know. Didn't think of it. If it should become possible to use the for (x,y,z=0) in tupleList syntax, I would sure like also to have: for (,,z) in tupleList Sounds coherent... but then you already have: for dont_care, ignore, y in tupleList: # etc for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList for (x,y,if z not in tupleList: z=0 else: z=2*x*z) in tupleList and sure also: for (x,y,z=0, *r) in tupleList etc. My only objections are: Is it worth the effort? Would it not be confusing? Maybe starting with e.g. a xlistcomprehension module where xlistcomprehension.execute( [for (x,y,if z not in tupleList: z=0 else: z=1) in tupleList] ) or just xl(...) to keep it short provides the desired functionality is a good idea? Then it can be seen if this module becomes widely used and therefore worth to be integrated? I don't think this would be possible. What is proposed requires modification to the language itself AFAICT. I think it would be nice to have, but I can't imagine it to be really very helpful. I once had the same feeling about first class functions, higher-order functions, lambdas, list comprehension, __call__ special method, descriptors, metaclasses, and a whole lot of other constructs for that matter. Now I woul be very unhappy not to have them !-) Regards, -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: getting text from WinXP console
Popen(args='c:\\WINDOWS\\system32\\command.com' Don't launch command.com, try running the actual program you are interested in in capturing the text for. Although you should be able to run the command interpreter too- I don't know why that didn't work. There are several variations of popen, so you may want to explore them all to see which suits your needs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Submission for Python Limmerick Contest
On 22 Mar 2005 11:44:03 -0500, Roy Smith wrote: A tuple, a dict, and a list, And whitespace which mus'n't be missed. Imported together, And stirred with a feather, Yields a language whose name must be hissed! Nice! +1 -- Swaroop C H Blog: http://www.swaroopch.info Book: http://www.byteofpython.info -- http://mail.python.org/mailman/listinfo/python-list
Re: Wikipedia - conversion of in SQL database stored data to HTML
$main_prefix = u:/WikiMedia-Static-HTML/; $wiki_language = pl; The script is running now for over half an hour and has created yet 1.555 folders and generated 527 files with a total size of 6 MBytes consuming only 16 seconds of CPU time. I estimate the time until the script is ready to appr. 6 hours for a 100 MByte file, which gives 120 hours for a 2 GByte file of the english dump ... Any further hints? What am I doing wrong? Inbetween I have noticed, that the script started to download media files from the Internet. Setting $include_media = 2; in the script solved the problem. Thank you Leif for pointing me to http://tinyurl.com/692pt What I am still missing is a binary of texvc for Windows. Have maybe someone a ready-to-use compiled version or can point me to one? Conversion from Perl to Python seems (except a service provided by http://www.crazy-compilers.com/bridgekeeper/ ) to be not (yet) available and Perl syntax is for me so far away from what I already know, that I see currently no chance to come up with a Python version of http://www.tommasoconforti.com/wiki/wiki2static.tar.gz Claudio -- http://mail.python.org/mailman/listinfo/python-list
FW: Python help group
Can someone help me with below ? Its not my question but I will forward any answers to my friend who I am sending this for. Mark -Original Message- From: Tan, Heap Ho Sent: Tuesday, March 22, 2005 1:11 PM To: Leeds, Mark Subject: Python help group I want to do a sort on a list of objects based on a similar attributes in each object for example time of creation of this object. Is there a simple way to do this? Thank -Original Message- From: Leeds, Mark Sent: Monday, March 21, 2005 5:35 PM To: Tan, Heap Ho Cc: Leeds, Mark Subject: crontab -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] sorting matrixes
On 22 Mar 2005 09:02:51 -0800, rumours say that Xah Lee [EMAIL PROTECTED] might have written: Today we'll write a program that can sort a matrix in all possible ways. Here's the Perl documentation. I'll post a Perl and Python version in 2 days. Don't bother writing a Python version... list.sort and its arguments are fine and send their greetings. -- 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
urllib versus IIS
I started experimenting with SOAPpy yesterday and immediately hit a snag. Both web services I tried simply hung and never replied. After a lot of digging, I found out what was going wrong: urllib.urlopen() is issuing an HTTP/1.0 request, but Microsoft IIS 5 ignores the client HTTP version and replies with an HTTP/1.1 response. This is a problem because while HTTP/1.0 servers are expected to close the connection once the response is finished, HTTP/1.1 servers are allowed keep the connection open. urllib assumes that the connection always closes. Therefore, when urllib receives an HTTP/1.1 response, it hangs until the server feels inclined to close the connection. Obviously the server is wrong, since HTTP/1.0 requests should only receive HTTP/1.0 responses, but I can't do anything about that. Now, there is actually code in httplib that would allow urllib to correctly understand HTTP/1.1 responses, if only urllib used it. After the headers have been parsed, urllib calls getfile(), but I think it should call getresponse() instead. The result of getresponse() is almost like a file; it just needs readline(s) and iteration. In fact, perhaps httplib's getfile() should be deprecated, since HTTP/1.1 has several options for encoding the response body (chunking and compression) and users of httplib shouldn't have to know about those encodings. Users should use getresponse() instead. So, is it worth my time to fix urllib and httplib, making urllib use getresponse() instead of getfile()? Would the changes be accepted? Is anyone else working on something similar? BTW, this is on Python 2.3.5, but I haven't spotted any changes between Python 2.3.5 and current CVS that would have fixed the problem. I'll start trying Python CVS in a moment. Shane -- http://mail.python.org/mailman/listinfo/python-list
Re: Building Time Based Bins
Ok, thanks Michael, I got it sorted out now. It was just a question of placing the append statement and the new list in the right place. I also added a delete command so the list doesn't become too huge, especially when there's no need to keep it. Here's the corrected code: if bintm == : bintm = newbintm binlo = a lastbinlo = [binlo]## new bin creation elif bintm == newbintm: binlo = min(binl, t) else: if len(lastbinlo) 1: ## check for append data del lastbinlo(0) ## delete extras lastbinlo.append(binlo) ## append new data here print lastbinlo[-2] print == %04d %2d % (bintm, binl) ## this is the bin bintm = newbintm binlo = a Anyway, many thanks to everyone who helped with this code. Best regards, Marcus -- http://mail.python.org/mailman/listinfo/python-list
Re: .pth files?
Ben I'm unclear on how .pth files work. Some posts imply they can be Ben arbitrarily named, as long as they include the .pth extension, and Ben can exist anywhere in the current sys.path. Other documentation Ben seems to imply that they must be named package.pth, although I'm Ben not sure what package it would be named after. package.pth naming is just a convention so you can easily sort out the association for each of multiple pth files. I have a mojam.pth file but no mojam package on my server. Works just fine. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Confirm: compiled re(gexps) are thread safe?
Johan Subject says it all, really. Yes, searching using a compiled regular expression is thread-safe. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Confirm: compiled re(gexps) are thread safe?
Johan Ovlinger wrote: Can someone please confirm that I can safely do something like the below, without needing a thread-local compiled regexp? yes. global_var = re.compile( foo ) for str in manystrings: def domatch(str): if global_var.search(str): print yahooo! threading.thread(target = domatch, args = [str]).start() Alternately, what is the overhead in compilation? Neglible? the compiler uses a cache, so even if you call compile inside each thread, all threads end up getting the same pattern object. on the other hand, make sure you google for global interpreter lock before you spend too much time implementing parallell searches... /F -- http://mail.python.org/mailman/listinfo/python-list
FW: FW: Python help group
This is a follow up question To the previous question About sorting that I sent for my friend. -Original Message- From: Tan, Heap Ho Sent: Tuesday, March 22, 2005 2:06 PM To: Leeds, Mark Subject: RE: FW: Python help group How can you speed it? Does anyone know if pytable can take non-homogeneous objects type? -Original Message- From: Leeds, Mark Sent: Tuesday, March 22, 2005 1:39 PM To: Tan, Heap Ho Subject: FW: FW: Python help group -Original Message- From: Swaroop C H [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 22, 2005 1:25 PM To: Leeds, Mark Cc: python-list@python.org Subject: Re: FW: Python help group On Tue, 22 Mar 2005 13:15:15 -0500, Leeds, Mark wrote: I want to do a sort on a list of objects based on a similar attributes in each object for example time of creation of this object. class Student: ... def __init__(self, name, age): ... self.name = name ... self.age = age ... students = [Student('John', 18), Student('Jill', 17)] students.sort(lambda x,y: cmp(x.age, y.age)) [student.name for student in students] ['Jill', 'John'] See `help(list.sort)` for details. -- Swaroop C H Blog: http://www.swaroopch.info Book: http://www.byteofpython.info -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
I'm running the following code on Windows 2000, 5.00.2195: for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = subprocess.Popen(Command_String) PROC.wait() ... # process WinRK output This hangs occasionally, and is not repeatable - it never hangs on the same file. Replacing the PROC.wait() command with the loop while PROC.poll() == None: time.sleep(1) has not hung on approximately 7,000 calls to WinRK. Earl On Tue, 2005-03-22 at 09:35, Jeff Epler wrote: On Tue, Mar 22, 2005 at 07:16:11AM -0700, Earl Eiland wrote: I've been having trouble with a program hanging when using the subprocess modules wait() method. Replacing it with with a loop that used poll() solved the problem. Please include an example, and more information about what platforn you're using This simple program worked fine for me on Linux with Python 2.4: # import subprocess, time s = subprocess.Popen(['sleep', '2']) while 1: time.sleep(.1) if s.poll() is not None: break print polling wait done, s.returncode s = subprocess.Popen(['sleep', '2']) s.wait() print blocking wait done, s.returncode # Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: The Running Time of +=
Haz == MyHaz [EMAIL PROTECTED] writes: Haz Teach me how to fish, where would i find out more about the Haz internal representations of data types in python The source. Experimentally you can use the timeit command to see how it performs: % for i in 10 20 40 80 160 320 640 1280 ; do timeit.py -s 'a = a*'$i' ; b = b*10' 'a += b' done 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.826 usec per loop % for i in 10 20 40 80 160 320 640 1280 ; do timeit.py -s 'a = a*10 ; b = b*'$i 'a += b' done 100 loops, best of 3: 0.826 usec per loop 100 loops, best of 3: 0.909 usec per loop 100 loops, best of 3: 1.11 usec per loop 100 loops, best of 3: 1.52 usec per loop 10 loops, best of 3: 1.97 usec per loop 10 loops, best of 3: 3.18 usec per loop 10 loops, best of 3: 5.54 usec per loop 10 loops, best of 3: 10.5 usec per loop Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: C type buffer copy
Hi All-- def testCode(data): buf=data[:] # and I hope you're going to do something with buf, # because otherwise this function's a bit of a waste;-) [EMAIL PROTECTED] wrote: Hello, How does Python deal with C type memory buffers. Does Python return everything as an object irrespective of the data type? Here's what i am trying to achieve? testCode(unsigned char buf, unsigned long len) { unsigned long data=0x0; while (len--) { *buf++ = (unsigned char)data++ } } What's the best way to deal with this in python? Metta, Ivan -- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
I wrote a program to use subprocess.Popen 1 times, and never had .wait() hang. If this is a bug, it may be Windows specific. Here's the program I ran: #- import subprocess, signal def timeout(*args): print Timed out waiting on, i raise SystemExit, 1 signal.signal(signal.SIGALRM, timeout) for i in xrange(1): signal.alarm(5) subprocess.Popen(['/bin/true']).wait() if i % 100 == 0: print done with, i print done! #- If the wait method ever hangs, the signal handler shuld be invoked. On Unix, /bin/true is a very simple program that does nothing, so it's virtually guaranteed to run in less than 5 seconds. On Windows, maybe you want something like subprocess.popen('cmd.exe /c rem') as a command that will do nothing and terminate quickly. What happens if you run my program with that change to the Popen line? Jeff pgpxqq83N7cWo.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
XML/RPC server with SSL in Python
Are there any alternatives to using M2Crypto for an XML/RPC server in SSL in Python? Come to think of it, what pythonesque XML/RPC servers do you recommend (you know, beyond SimpleXMLRPCServer.py) -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help for Python programming
M.E.Farmer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Terry, This was posted from google groups, can you see the indents? Yes, looks good # code snippet convertpage = 0 form = None for o, a in opts: if o in [-h, --help]: Usage() sys.exit() if o in [-o, --output, --out]: output = a if o in [-i, --input, --in]: input = a if input in [., cwd]: input = os.getcwd() Notice the 'fixed font / proportional font' link in the top right corner. I presume this is on the Google page. I think they have fixed the problem. Great. Now people have to learn to use the fixed font choice. TJR -- http://mail.python.org/mailman/listinfo/python-list
Re: .pth files?
On Tue, 22 Mar 2005 12:52:28 -0600, Skip Montanaro [EMAIL PROTECTED] wrote: package.pth naming is just a convention so you can easily sort out the association for each of multiple pth files. I have a mojam.pth file but no mojam package on my server. Works just fine. Interesting. Where does it call home? site-packages? -Ben -- http://mail.python.org/mailman/listinfo/python-list
problems with  character
I have a mysql database with characters like   » in it. I'm trying to write a python script to remove these, but I'm having a really hard time. These strings are coming out as type 'str' not 'unicode' so I tried to just record[4].replace('Â', '') but this does nothing. However the following code works #!/usr/bin/python s = 'a  aaa' print type(s) print s print s.find('Â') This returns type 'str' a  aaa 6 The other odd thing is that the  character shows up as two spaces if I print it to the terminal from mysql, but it shows up as  when I print from the simple script above. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF Questions
Fuzzyman wrote: Thanks Serge. You're welcome. While we at it, iconvcodec supports utf-32 and more. I have sent a 2.4 windows build of iconvcodec module to the author. He promised to publish it soon. Serge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python becoming less Lisp-like
Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] And does this code object know which non-local names are on an intermediate level and which are global? Yes (from 2.2): import dis x = 1 def f(): ... y = 2 ... def g(): ...z = 3 ...print x,y,z ... return g ... dis.dis(f) 0 SET_LINENO 1 3 SET_LINENO 2 6 LOAD_CONST 1 (2) 9 STORE_DEREF 0 (y) 12 SET_LINENO 3 15 LOAD_CLOSURE 0 (y) 18 LOAD_CONST 2 (code object g at 008BA060, file stdin , line 3) 21 MAKE_CLOSURE 0 24 STORE_FAST 1 (g) 27 SET_LINENO 6 30 LOAD_FAST1 (g) 33 RETURN_VALUE 34 LOAD_CONST 0 (None) 37 RETURN_VALUE g = f() dis.dis(g) 0 SET_LINENO 3 3 SET_LINENO 4 6 LOAD_CONST 1 (3) 9 STORE_FAST 0 (z) 12 SET_LINENO 5 15 LOAD_GLOBAL 1 (x) 18 PRINT_ITEM 19 LOAD_DEREF 0 (y) # intermediate value 22 PRINT_ITEM 23 LOAD_FAST0 (z) 26 PRINT_ITEM 27 PRINT_NEWLINE 28 LOAD_CONST 0 (None) 31 RETURN_VALUE Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: C pointers/Python
len is a built-in function in Python, so you probably don't want to use it as a variable name. What is this C code actually trying to do? Don't try to transliterate it; instead, read up on how lists and slicing work, and rewrite it in Python starting from a higher level of abstraction. One hint- you can copy the same datum many times without a while loop... # reassign sub-list interval [i, j-1] buffer[i:j] = [data] * (j-i) # reassign the entire list buffer[:] = [data] * len(buffer) -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
I'm running ActivePython PythonWin 2.4, and get the error message'AributeError: 'module' object has no attribute 'SIGALRM'. The example provided in the ActivePython documents use signal.SIGALRM, so I'm not sure what's going on... Earl On Tue, 2005-03-22 at 12:43, Jeff Epler wrote: I wrote a program to use subprocess.Popen 1 times, and never had .wait() hang. If this is a bug, it may be Windows specific. Here's the program I ran: #- import subprocess, signal def timeout(*args): print Timed out waiting on, i raise SystemExit, 1 signal.signal(signal.SIGALRM, timeout) for i in xrange(1): signal.alarm(5) subprocess.Popen(['/bin/true']).wait() if i % 100 == 0: print done with, i print done! #- If the wait method ever hangs, the signal handler shuld be invoked. On Unix, /bin/true is a very simple program that does nothing, so it's virtually guaranteed to run in less than 5 seconds. On Windows, maybe you want something like subprocess.popen('cmd.exe /c rem') as a command that will do nothing and terminate quickly. What happens if you run my program with that change to the Popen line? Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: Confirm: compiled re(gexps) are thread safe?
Skip Montanaro wrote: Johan Subject says it all, really. Yes, searching using a compiled regular expression is thread-safe. Skip Great. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: XML/RPC server with SSL in Python
[EMAIL PROTECTED] (Gerson Kurz) writes: Are there any alternatives to using M2Crypto for an XML/RPC server in SSL in Python? stunnel? (www.stunnel.org) -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with  character
jdonnell wrote: I have a mysql database with characters like   » in it. I'm trying to write a python script to remove these, but I'm having a really hard time. use the hammer recipe. i'm using it to create URL-friendly fragment from latin-1 album titles: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871 (check the last comment, a cleaner solution for a better implementation). it basically hammers down accented chars like à and  to the most near ASCII representation. since you receive string data as str from mysql object first convert them as unicode with: u = unicode('Â', 'latin-1') then feed u to the hammer function (the fix_unicode at the end). HTH, deelan -- Però è bello sapere che, di questi tempi spietati, almeno un mistero sopravvive: l'età di Afef Jnifen. -- dagospia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with  character
s = 'a  aaa' What am I doing wrong? First get rid of characters not allowed in Python code. Replace  with appropriate escape sequence: /x## where ## is the hexadecimal code of the ASCII character. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Ron a écrit : (snip) def dfv( arg = value): return arg def dfv( arg = value): ... return arg ... Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'value' is not defined And sorry, but -1 for using exec here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Ron a écrit : On 21 Mar 2005 22:37:42 -0800, Kay Schluehr [EMAIL PROTECTED] wrote: Mappings like that: ((x,y),z) - x+y-z ((x,y=0),z) - None should be valid actions too. What is the audience thinking about that? I think that there's too much implied, and that in the long run it, if we keep addding in special shortcuts, it will lead to very dificult to read code. Don't like Perl ?-) The problem here is that Kay's proposition mixes two points: flexible tuple unpacking and a new syntax for anonymous functions. -- http://mail.python.org/mailman/listinfo/python-list
How to use subprocess
Hi, I want to use the subprocess module (or any standard Python module) to run a process: - which stdout and stderr can each be redirected to any file-like object (no fileno function). - can be cancelled with a threading.Event. My problem is that the subprocess.Popen constructor doesn't seem to support file-like objects (only file objects with fileno()). If I use subprocess.PIPE, I have the problem that the read functions of of the subprocess objects stdout and stderr are blocking (and I want to redirect them to different file-like objects, so I definitely need non-blocking access). How am I supposed to do it? Thx and regards, Nicolas It something like that that I would need to make work (but supporting file-like objects): class CancellationException(Exception): pass class CancellableCommand: def __init__(self, command, stdout=nullFile, stderr=nullFile, refreshDelay=0.1, raiseIfNonZero=True): self.command = command self.stdout = stdout self.stderr = stderr self.refreshDelay = refreshDelay def execute(self, cancelEvent=None): if cancelEvent is None: cancelEvent = threading.Event() # dummy exitCode = None cmd = subprocess.Popen( self.command, stdout=self.stdout, stderr=self.stderr) while exitCode is None: # Wait for event to be set for a specific delay cancelEvent.wait(self.refreshDelay) if cancelEvent.isSet(): kill(cmd.pid) # implemented as in FAQ raise CancellationException( 'Process ' + self.command + ' cancelled') exitCode = cmd.poll() return exitCode -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
Diez B. Roggisch a écrit : (snip) You are right, but for lambda in its current limited form short, named functions are a good replacement. -inf on this !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with  character
Claudio Grondi [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] s = 'a  aaa' What am I doing wrong? First get rid of characters not allowed in Python code. Replace  with appropriate escape sequence: /x## where ## is the (should be \x##) hexadecimal code of the ASCII character. Claudio i.e. probably instead of 'a  aaa' 'a \xC2 aaa' In my ASCII table 'Â' is '\xC2' Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Submission for Python Limmerick Contest
A tuple, a dict, and a list, And whitespace which mus'n't be missed. Imported together, And stirred with a feather, Yields a language whose name must be hissed! A char, an integer and a float, And a decimal which precision is fixed Computerised altogether Then shaked down with a mixer Asserts a community whose goal must be attained! -- -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
hm, I guess SIGALRM doesn't exist on Windows. You can run the program without the 'signal.signal' line or the 'signal.alarm' line, and you'll be stuck with a hung Python if subprocess.Popen exhibits the bug. Jeff pgp80TDX5i7qo.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
MinGW building with Python 2.4
Ok, I know there are already a million posts on this group about getting Python to build with MinGW. I've been through many of them, and have still not found a good comprehensive way to accomplish this. I've got Cygwin 5.1 with GCC 3.3.3 on it. I'm using Python 2.4. Note: You invoke the mingwin compiler *indirectly*, by running gcc with the -mno-cygwin option. So first of all, I tried exporting CC='gcc -mno-cygwin', configuring, and making. You end up getting file-not-found errors, because some of the include files aren't present for mingw. Next: I tried pymingw: didn't work :( Any ideas? Thanks in advance, --Steve ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting the word to conventional programmers
Cameron Laird [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] *DevSource* profiles The State of the Scripting Universe in URL: http://www.devsource.com/article2/0,1759,1778141,00.asp . Interesting quote from Guido: If the same effort were poured into speeding up Python as Sun devoted to Java, Python would be better than Java in every respect. TJR -- http://mail.python.org/mailman/listinfo/python-list
Httplib request method
Hi, For some reason, httplib request() method splits the request packet into two packets, the first packet contains only HTTP headers, the body in the second packet. The first packet size is way below the MTU size. Is there a way I can send everything in one packet? Below is a piece of my code: self.conn.request(method, url, msg, headers) response = self.conn.getresponse() data = response.read() -- http://mail.python.org/mailman/listinfo/python-list
wanted: visual report templating system
I am looking for a client/server reporting tool to use with a web application built in Python. It would consist of three parts: 1. a data definition retrieval engine that interfaces to RDBMS or other data files 2. a visual designer in which a nontechnical person can create a report layout template (supporting charts, text, graphics, etc.) 3. a server engine to merge the two and create on-the-fly reports when requested programmatically. A similar application would be the ReportMill product for Java: http://www.reportmill.com/product/ Price should not exceed 4 figures (in US$). Seems like a reasonable expectation, but all I am readily aware of in this market is ReportLab. Any suggestions? -- robin -- http://mail.python.org/mailman/listinfo/python-list
(,) Do You Want To Know For Sure You Are Going To Heaven?
http://www.want-to-be-sure.blogspot.com Click On Link -- http://mail.python.org/mailman/listinfo/python-list