ANN: PyTables 1.2
PyTables is a library to deal with very large datasets. It leverages the excellent HDF5 and numarray libraries to allow doing that in a very efficient way using the Python language. More info in: http://pytables.sourceforge.net/ = Announcing PyTables 1.2 = The PyTables development team is happy to announce the availability of a new major version of PyTables package. This version sports a completely new in-memory tree implementation based around a *node cache system*. This system loads nodes only when needed and unloads them when they are rarely used. The new feature allows the opening and creation of HDF5 files with large hierarchies very quickly and with a low memory consumption (the object tree is no longer completely loaded in-memory), while retaining all the powerful browsing capabilities of the previous implementation of the object tree. You can read more about the dings and bells of the new cache system in: http://www.carabos.com/downloads/pytables/NewObjectTreeCache.pdf Also, Jeff Whitaker has kindly contributed a new module called tables.NetCDF. It is designed to be used as a drop-in replacement for Scientific.IO.NetCDF, with only minor actions to existing code. Also, if you have the Scientific.IO.NetCDF module installed, it allows to do conversions between HDF5 -- NetCDF3 formats. Go to the PyTables web site for downloading the beast: http://pytables.sourceforge.net/ If you want more info about this release, please check out the more comprehensive announcement message available in: http://www.carabos.com/downloads/pytables/ANNOUNCE-1.2.html Acknowledgments === Thanks to the users who provided feature improvements, patches, bug reports, support and suggestions. See THANKS file in distribution package for a (incomplete) list of contributors. Many thanks also to SourceForge who have helped to make and distribute this package! And last but not least, a big thank you to THG (http://www.hdfgroup.org/) for sponsoring many of the new features recently introduced in PyTables. --- **Enjoy data!** -- The PyTables Team -- 0,0 Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data - -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Porcupine Web Application Server 0.0.5 released
Sorry for posting this again but the new release is the 0.0.5 and not the 0.0.4. QuiX now supports radio buttons and timers (timeouts and intervals). This release also introduces a couple of useful desktop enhancements. The task bar context menu allows the user to minimize all windows or activate the desired window at once. Each user is also capable of choosing the task bar position (top or bottom). The object query language (POQL) is enriched by adding a new function named instanceof. This function returns true if an object is a subclass of a given type. Finally a new dictionary data type is added to the list of the primary data types and the user content class has a new attribute used for keeping his/her preferences. One step closer to our vision; the WebOS. Resources = What is Porcupine? http://www.innoscript.org/content/view/30/42/ Porcupine online demo: http://www.innoscript.org/content/view/21/43/ Porcupine tutorials: http://wiki.innoscript.org/index.php/Developers/Tutorials Developer resources: http://www.innoscript.org/component/option,com_remository/Itemid,33/func,selectcat/cat,3/ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Anyway to clarify this code? (dictionaries)
javuchi wrote: I want to avoid converting the dictionary to a list and then to a dictionay. Are there speed penalties for such a conversion? You mean, is it faster to write, test, debug and execute slow Python code rather than letting Python's built-in routines written in fast C do the job? I have no idea. Perhaps you should try it and see. Write some code to do it all manually, and time it. Make sure you use realistic test data: if your users will be using dictionaries with 10,000 items, there is no point in testing only dictionaries with 10 items. For accuracy, run (say) 20 tests, and look at the average speed. Of better still, use the timeit module. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke wrote: This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an ordered dictionary class at least in the standard list? Time and again I am missing that feature. Maybe there is something wrong with my programming style, but I rather think it is generally useful. I fully agree with the following posting where somebody complains why so very basic and useful things are not part of the standard library: http://groups.google.com/group/comp.lang.python/msg/e652d2f771a49857 Are there plans to get it into the standard lib sometime? We're always encouraging new posters to use good subject lines. Several hundred posts after your original question I think everyone can agree that this was a *very* good subject line :-) Perhaps now the answer top your question is more obvious: there is by no means universal agreement on what an ordered dictionary should do. Given the ease with which Python allows you to implement your chosen functionality it would be presumptuous of the core developers to favour any one of the several reasonable alternatives that might be chosen. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What a curious assignment.
[EMAIL PROTECTED] wrote: Is there somthing wrong Kids today, don't they learn about inheritence? :-) Python's object model is that instances inherit both methods and attributes from the class (and superclasses). Methods are just a special case of attributes: the method is a callable attribute. When you reference an attribute, Python first checks the instance by looking up instance.__dict__, and if that fails, it looks up instance.__class__.__dict__. (This is a simplification, e.g. it isn't exactly true for objects with slots.) For attribute lookup (that is, the attribute reference is on the right hand side of an assignment), the lookup may fail and so the class attribute may be retrieved. This is by design. For attribute assignment (that is, the attribute reference is on the left hand side of an assignment), the assignment will never fail. (Again, ignoring slots and any other special cases I have't thought of.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
SelfExtract with zipfile
Hi, I need to compress files in self-extract archive. I use the zipfile module. Is there an option or parameter to do that? Thanks in advance, Catalin -- http://mail.python.org/mailman/listinfo/python-list
Re: What a curious assignment.
Steven D'Aprano wrote: [EMAIL PROTECTED] wrote: Is there somthing wrong Kids today, don't they learn about inheritence? :-) Python's object model is that instances inherit both methods and attributes from the class (and superclasses). Methods are just a special case of attributes: the method is a callable attribute. When you reference an attribute, Python first checks the instance by looking up instance.__dict__, and if that fails, it looks up instance.__class__.__dict__. (This is a simplification, e.g. it isn't exactly true for objects with slots.) For attribute lookup (that is, the attribute reference is on the right hand side of an assignment), the lookup may fail and so the class attribute may be retrieved. This is by design. For attribute assignment (that is, the attribute reference is on the left hand side of an assignment), the assignment will never fail. (Again, ignoring slots and any other special cases I have't thought of.) I believe he knows about inheritance, but not about the behaviour of the assignment. In many other OO languages, I believe you cannot have the same name for both instance variable and class variable. javascript has similar behaviour. -- http://mail.python.org/mailman/listinfo/python-list
Re: python gui using boa
Ashok wrote: hi, i am trying to develop a small gui app using boa constructor. say this app has one frame which has one static text control. i want the frame to resize itself to the width of the text contrl when i change the label of the text control via SetLabel(). how can i do this in boa constructor? can anybody guide me to a good source for learning the use of sizers in boa? Sizers are a tricky topic, and there doesn't appear to be much that's specific to Boa. You could take a look in the wxPython wiki at http://wiki.wxpython.org/index.cgi/UsingSizers but whether this will help you with Boa I'm not sure. I have tried Glade and Boa as well as Python Card, and all I can really say is that I found it worth spending the money to *buy* wxDesigner. It's not a perfect product, but it fits my brain. Sorry if this isn't an option for you. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Cmd Module
Godwin Burby wrote: I was just curious about using the cmd module for building my own command line interface. i saw a problem. The script is as follows: it helps if you include the code you were running, instead of some approximation of it. File test, line 10 if passwd = 'godwin': print You are a valid user ^ SyntaxError: invalid syntax Traceback (most recent call last): File stdin, line 4, in ? NameError: name 'cmd' is not defined The interpreter reports that the first argument to super should be a type rather than a class object and for the do_login function it says that function needs only one argument but two are given. I solved the above errors by adding the following code: Cmd.__init__(self) def do_login(self,passwd='godwin') But i know that my first code should work without any problems or is there a problem with it. super() only works for new-style classes. the second argument problem is because do_ methods are called with a second argument: import cmd help(cmd) Help on module cmd: ... 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method is passed a single argument consisting of the remainder of the line. ... (if you type login, you get an empty string. if you type login foo, you get the string foo. etc). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke wrote: I still believe that the concept of an ordered dictionary (behave like dict, only keep the order of the keys) is intuitive and doesn't give you so much scope for ambiguity. But probably I need to work on an implementation to become more clear about possible hidden subtleties. Bengt Richter schrieb: Does that mean that the Larosa/Foord odict.py implementation in PyPI does not do what you want? Basically, it is what I had in mind. But I'm now seeing some things that could be improved/supplemented, e.g. - performance improvements Implementation changes to follow, based on suggestions in this thread. For *optimal* performance it needs to be implemented in C of course. :-) As F points out, a list of tuples may give you a data structure that can be accessed quicker (although some operations will be slower). An ordered dictionary will be a lot easier to use and make your code more readable though. - the internal keys list should be hidden I disagree. It is exposed so that you can manually change the order (e.g. to create a sorted dict, rather than one ordered by key insertion). What do you *gain* by hiding it ? - list methods should be mixed in instead Hmm... I did consider this. Which list methods would you consider appropriate ? The difficulty is that integers are valid keys for a dictionary. Perhaps a subclass that uses integers as indexes instead... You can always perform list operations on the ``sequence`` attribute of course. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Bengt Richter wrote: On 22 Nov 2005 02:16:22 -0800, Fuzzyman [EMAIL PROTECTED] wrote: Kay Schluehr wrote: Christoph Zwerschke wrote: That would be also biased (in favour of Python) by the fact that probably very little people would look for and use the package in the cheese shop if they were looking for ordered dicts. Does anyone actually use this site? While the Vaults offered a nice place and a nice interface the Cheese Shop has the appeal of a code slum. Hmmm.. it's *the* repository for Python code. I expect quite a few people use it... :-) I hadn't realized how much stuff was there. I generally google for stuff, but I will be looking directly now. BTW, I made a mod[1] to your odict that I think/hope is going to be generally faster. It requires 2.4 though. It passes the same doctest, so its probably close to the same. It stores the ordering info differently, but is also a dict subclass. odict maintains compatibility with Python 2.2 - so it's not a change we'd put back into the module I don't think. Changes that keep compatibility are very welcoemd though. Do you happen to have a timing test that exercises various aspects, so I can try it before I embarrass myself? Otherwise I guess I'll write something. The only tests we have are the ones in the module. If you create some timing tests we'd be interested in having access to them though. They would be a useful addition. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml Would the would-be users chime in with some idea of what kinds of operations are most important timing-wise? Which would get the most use? How dynamic would ordering typically be? [1] fairly pervasive little mods actually [ 9:15] C:\pywk\clpdiffodict.py odictb.py |wc 146458 4948 [ 9:15] C:\pywk\clpwc odict*.py 467 1228 12483 odict.py 511 1500 14728 odictb.py 978 2728 27211 Totals Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: mxODBC sql MSAccess
BartlebyScrivener wrote: Hello, I'm new to python and trying to get records from an MSAccess database using mxODBC. It works, but the output is not formatted the way I want it. Here's the script: import mx.ODBC.Windows as odbc driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Access Databases/Quotations2005' conn = odbc.DriverConnect(driv) c = conn.cursor() c.execute (SELECT Author, Topic1, Topic2, Quote FROM QuotesToTxt WHERE Author LIKE 'Mencken%') rows = c.fetchall() for r in rows: print r And here's what I get: ('Mencken, H.L.', 'Americans', 'Democracy', 'Democracy is the theory that the common people know what they want, and deserve to get it good and hard.') ('Mencken, H.L.', 'Conscience', 'Mother-In-Law', 'Conscience is a mother-in-law whose visit never ends. The inner voice which warns us that someone may be looking.') Where are the parenthese and single quotes coming from? SQL or mxODBC? And how can I get just simple tab-delimited records with a standard carriage return separating the records? Thanks so much for any help. bs Well you know that answer now. You might also consider using the recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 to give you the column titles and so on. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Cmd Module
Sorry! I just retyped my script instead of copy pasting it. well thank u once again for clearing my confusion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Steve Holden wrote: Perhaps now the answer top your question is more obvious: there is by no means universal agreement on what an ordered dictionary should do. Given the ease with which Python allows you to implement your chosen functionality it would be presumptuous of the core developers to favour any one of the several reasonable alternatives that might be chosen. It seems to be though as ordered dictionary are slowly to be confined to only ordered on order of change to the dictionary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke wrote: One implementation detail that I think needs further consideration is in which way to expose the keys and to mix in list methods for ordered dictionaries. In http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747 the keys are exposed via the keys() method which is bad. It should be a copy only, like for ordinary dicts (one comment also mentions that). In Foord/Larosa's odict, the keys are exposed as a public member which also seems to be a bad idea (If you alter the sequence list so that it no longer reflects the contents of the dictionary, you have broken your OrderedDict). So don't do it. ;-) I think it would be probably the best to hide the keys list from the public, but to provide list methods for reordering them (sorting, slicing etc.). For instance: d1 = OrderedDict( (1, 11), (2, 12), 3, 13) ) d1[1:] == OrderedDict( (2, 12), 3, 13) ) So what do you want returned when you ask for d1[1] ? The member keyed by 1, or the item in position 1 ? You can access the members using list operations on the sequence attribute. E.g. d1[d1.sequence[index]] This could probably be made more convenient. d1[0] + d1[2] == OrderedDict( (1, 11), (3, 13) ) d1.reverse() == OrderedDict( (3, 13), (2, 12), 1, 11) ) Interesting idea. d1.insert(1, (4, 14)) == OrderedDict( (1, 11), (4, 14), (2, 12), 3, 13) ) Also an interesting idea. etc. But no other way to directly manipulate the keys should be provided. Why - don't trust yourself with it ? All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
There is already an update method of course. :-) Slicing an ordered dictionary is interesting - but how many people are actually going to use it ? (What's your use case) You can already slice the sequence atribute and iterate over that. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
While we're on the subject, it would be useful to be able to paste in a changelog as well as a description. Currently when updating versions you have to include the changelog in the description - or not at all... All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
Bengt Richter wrote: Though it looks nice, it's an implementation dependant solution. What if someone changes zip to fetch the second item first? That would be a counter-intuitive thing to do. Most things go left-right in order as the default assumption. it's not only the order that matters, but also the number of items read from the source iterators on each iteration. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
[EMAIL PROTECTED] wrote: Personally, I would like to see it as [('a',1,'b',2), ('c',3, None,None)], as a list of tuple of equal length is easier to be dealt with. i = iter(aList) zip(i,chain(i,repeat(None)), chain(i,repeat(None)),chain(i,repeat(None))) Here's some more: it = iter(range(5)) map(None, it, it) [(0, 1), (2, 3), (4, None)] N = 3 it = chain(range(10), repeat(MISSING, N-1)) zip(*(it,)*N) [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 'MISSING', 'MISSING')] Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)
[EMAIL PROTECTED] wrote: led to more serious flaws like the missing if-then-else expression, something I use in virtually every piece of code I write, and which increases readability. you obviously need to learn more Python idioms. Python works better if you use it to write Python code; not when you mechanically translate stuff written in other languages to Python. (Well, ok that is not the end of the world either but it's lack is irritating as hell, and yes, I know that it is now back in favor.) the thing that's in favour is then-if-else, not if-then-else. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
Bengt Richter wrote: On Tue, 22 Nov 2005 13:26:45 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Duncan Booth wrote: it = iter(aList) zip(it, it) [('a', 1), ('b', 2), ('c', 3)] snip is relying on undefined behaviour perhaps the new black ? Is it really undefined? If so, IMO it should be defined to do what it apparently does. snip Hm, actually, something tells me I've seen some variation of this before, but I can't think of the context off hand. Yes, the subject does come up occasionally. Perhaps you are thinking of this thread: http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/83baa4bd42fc9b69/d933c7333d3863ce In that thread, I was the one arguing that the behaviour was undefined. My memory was that I was forced to back down on that one, but looking back at the thread I now think it was only itertools.izip I was forced to admit defines its behaviour as working that way. More googling will show that it was proposed that zip should be defined as working with this, but that proposal was rejected. See: http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/a6ba37b0fb0fa69e/f8a3d3b6d1a9fcbd So scratch my original suggestion and substitute this for defined behaviour: it = iter(aList) list(itertools.izip(it, it)) [('a', 1), ('b', 2), ('c', 3)] -- http://mail.python.org/mailman/listinfo/python-list
Re: sort the list
Neil Hodgson wrote: Since no-one mentioned it and its a favourite of mine, you can use the decorate-sort-undecorate method, or Schwartzian Transform That is what the aforementioned key argument to sort is: a built-in decorate-sort-undecorate. And crucially it is a built-in DSU which gets it right more often than naive DSU implementations. e.g. it is stable when you reverse the order: lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] list(reversed([ x[-1] for x in sorted([ (x[0],x) for x in lst ]) ])) [[9, 3], [5, 4], [4, 2], [4, 1], [2, 5]] l1 = list(lst) l1.sort(key=operator.itemgetter(0), reverse=True) l1 [[9, 3], [5, 4], [4, 1], [4, 2], [2, 5]] and it gets incomparable objects right: lst = [4+1j, 4+2j, 9+3j, 5+4j, 2+5j] [ x[-1] for x in sorted([ (x.real,x) for x in lst ]) ] Traceback (most recent call last): File pyshell#39, line 1, in -toplevel- [ x[-1] for x in sorted([ (x.real,x) for x in lst ]) ] TypeError: no ordering relation is defined for complex numbers l1 = list(lst) l1.sort(key=operator.attrgetter('real')) l1 [(2+5j), (4+1j), (4+2j), (5+4j), (9+3j)] -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot to split string literals that will across two or more lines ?
I tried to use this method in my code like this:- - #!/usr/bin/python def print_sql(): sql = '''aaa bbb'''.replace(\n,) print sql print_sql() - the ouput of this is spacetab.. I can always do this :- - #!/usr/bin/python def print_sql(): sql = '''aaa bbb'''.replace(\n,) print sql print_sql() - but it looks ugly On 11/22/05, Mohammad Jeffry [EMAIL PROTECTED] wrote: On 11/22/05, Paul McGuire [EMAIL PROTECTED] wrote: Or for a large literal string:lots of text hundreds of characters long more text on another line but we really don't want any line breaksin our final stringso we replace newlines in this multiline stringwith an empty string thus.replace('\n','') -- Paul I love your method. The only drawbacks for this method is I can't tell whether there is blank space at the end of each lines. For EG: the above string might be lots of text hundreds of characters longmore text on another. ^ or lots of text hundreds of characters long more text on another. ^ -- And whoever does an atom's weight of evil will see it. -- And whoever does an atom's weight of evil will see it. -- http://mail.python.org/mailman/listinfo/python-list
Re: What a curious assignment.
[EMAIL PROTECTED] wrote: [test 1] class A: ...i = 1 ... a = A() A.i 1 a.i 1 A.i = 2 A.i 2 a.i 2 [test2] class A: ...i = 1 ... a = A() A.i 1 a.i 1 a.i = 2 A.i 1 a.i 2 Is there somthing wrong No. -- 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: a new design pattern for Python Library?
The Eternal Squire wrote: I tend to use this design pattern a lot in order to aid in compartmentalizing interchangeable features in a central class that depend on the central class's data. I'm afraid I've read this paragraph and the code 3 times and I still have no idea what you're trying to convey. Perhaps it's just because your example is too abstract to me. It does look like it obscures the role of the classes involved however, which doesn't seem like a good thing to me. What do you consider a 'friendship dependency'? Is this just the Strategy pattern? -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
PyQt QGridLayout question
Once again a maybe silly question, but I find no solution, neither in the documentation nor in examples. I have got some different layouts to change place by the help of a QGridLayout in its parent widget. To make it nice I use row/col spacing and stretch respectively as well as multicell widgets. There is no problem if the layout next to come uses more rows and columns than the former one. But if it is the other way round, the grid seems to take those now unused rows and columns into account and uses more space than expected. Before changing to another layout I remove and delete all widgets within the grid and set spacing and stretch of all used rows and columns to 0: for c in self.gridContents.values(): self.grid.removeChild(c) self.gridContents.clear() for i in range(20): self.grid.addColSpacing(i,0) self.grid.addRowSpacing(i,0) self.grid.setColStretch(i,0) self.grid.setRowStretch(i,0) Only if I do a total resection and remove the grid and the parent widget, too, to set them up again, all is fine but for the flicker on the screen. Is there a more convenient way? Remove rows/columns as can be done in tables? Best wishes Volker -- Volker Lenhardt E-Mail: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot to split string literals that will across two or more lines ?
Mohammad Jeffry wrote: I tried to use this method in my code like this:- - #!/usr/bin/python def print_sql(): sql = '''aaa bbb'''.replace(\n,) print sql print_sql() - the ouput of this is spacetab.. I can always do this :- - #!/usr/bin/python def print_sql(): sql = '''aaa bbb'''.replace(\n,) print sql print_sql() - but it looks ugly [...] In your particular case, if it really is SQL you're dealing with then you shouldn't worry about what it looks like when you print it - the SQL interpreter certainly won't care. Many SQL statements are so long that it actually helps readability to have newlines in them. There have been plenty of solutions presented in the earlier posts in this thread if you really do need to represent multi-line strings. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot to split string literals that will across two or more lines ?
Mohammad Jeffry wrote: I can always do this :- - #!/usr/bin/python def print_sql(): sql = '''aaa bbb'''.replace(\n,) print sql print_sql() - sql = ( 'aaa' 'bbb' ) print sql or, perhaps more realistic: cursor.execute( 'aaa' 'bbb', a, b, c ) e.g. cursor.execute( 'select * from foo' ' where bar=%s' ' limit 100', bar ) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I package a python script and modules into a single script?
You could use my includer script. http://www.voidspace.org.uk/python/recipebook.shtml#includer It effectively adds an include direct to python scripts. ##include module.py from module import * You then run ``includer.py infilename outfilename`` This replaces the ``##include ..`` with the source of the included module and *removes* the import statement. This makes it possible to maintain modules separately, but distribute as a single script. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: sort the list
[EMAIL PROTECTED] wrote: Duncan Booth wrote: e.g. it is stable when you reverse the order: lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] list(reversed([ x[-1] for x in sorted([ (x[0],x) for x in lst ]) ])) [[9, 3], [5, 4], [4, 2], [4, 1], [2, 5]] l1 = list(lst) l1.sort(key=operator.itemgetter(0), reverse=True) l1 [[9, 3], [5, 4], [4, 1], [4, 2], [2, 5]] Just curious, which one is supposed to be the right answer ? and why the second one is preferable over the first one(if both is right, assume we only care about x[0]). Of course, there is no reason to DIY when the built-in can do the job. Stability means items with the same key preserve their relative position. In the original list of the example [4, 1] and [4, 2] both have the same key. Therefore [4, 1] should stay before [4, 2], so the second is the right answer. The practical advantage is that if e. g. you sort items first by color and then by size, items of the same size will appear sorted by color. In particular, sorting a list by the same key a second time does not change the list. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: sort the list
Peter Otten wrote: [EMAIL PROTECTED] wrote: Duncan Booth wrote: e.g. it is stable when you reverse the order: lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] list(reversed([ x[-1] for x in sorted([ (x[0],x) for x in lst ]) ])) [[9, 3], [5, 4], [4, 2], [4, 1], [2, 5]] l1 = list(lst) l1.sort(key=operator.itemgetter(0), reverse=True) l1 [[9, 3], [5, 4], [4, 1], [4, 2], [2, 5]] Just curious, which one is supposed to be the right answer ? and why the second one is preferable over the first one(if both is right, assume we only care about x[0]). Of course, there is no reason to DIY when the built-in can do the job. Stability means items with the same key preserve their relative position. In the original list of the example [4, 1] and [4, 2] both have the same key. Therefore [4, 1] should stay before [4, 2], so the second is the right answer. The practical advantage is that if e. g. you sort items first by color and then by size, items of the same size will appear sorted by color. In particular, sorting a list by the same key a second time does not change the list. Ah, thanks. That clear things up. -- http://mail.python.org/mailman/listinfo/python-list
Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)
Op 2005-11-23, Fredrik Lundh schreef [EMAIL PROTECTED]: [EMAIL PROTECTED] wrote: led to more serious flaws like the missing if-then-else expression, something I use in virtually every piece of code I write, and which increases readability. you obviously need to learn more Python idioms. Python works better if you use it to write Python code; not when you mechanically translate stuff written in other languages to Python. What does this mean? It could mean that python works better with those concepts that are already implemented in python. That seems obvious, but isn't an argument for or against implementing a particular language feature. It could also mean that some language feature will never work well in python even when implemented. Are you arguing that a conditional expression is such a feature? (Well, ok that is not the end of the world either but it's lack is irritating as hell, and yes, I know that it is now back in favor.) the thing that's in favour is then-if-else, not if-then-else. Well I don't know about the previous poster, but I'm mostly interesseted in a conditional expression. Whether it is then-if-else or if-then-else seems less important to me. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
[EMAIL PROTECTED] wrote: Steve Holden wrote: Perhaps now the answer top your question is more obvious: there is by no means universal agreement on what an ordered dictionary should do. Given the ease with which Python allows you to implement your chosen functionality it would be presumptuous of the core developers to favour any one of the several reasonable alternatives that might be chosen. It seems to be though as ordered dictionary are slowly to be confined to only ordered on order of change to the dictionary. While I'm only +0 for a standard odict I'm wondering that discussing this topic leads to the auctoritative conclusion that it is unsolvable, we have to accept infinite diversity etc. where people like me seeing a classification immediately ( mathematical education? ) . Of course this matter is trivial but we already know about monster-threads revolving around decorator syntax ( including hurt souls and semi-scientific papers ) and abandoning the print statement in Python 3.0. -- http://mail.python.org/mailman/listinfo/python-list
strange behaviour when writing a large amount of data on stdout
Regards. On my system: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32, Windows XP I have this problem: n = 61409 + 1 data = 'x' * n print data Traceback (most recent call last): File xxx, line xxx, in ? print data IOError: [Errno 12] Not enough space Can someone reproduce this bug? I begin to think that my system is messed up... Thanks Manlio Perillo -- http://mail.python.org/mailman/listinfo/python-list
Re: user-defined operators: a very modest proposal
Joseph Garvin wrote: Jeff Epler's proposal to use unicode operators would synergise most excellently with this, allowing python to finally reach, and even surpass, the level of expressiveness found in languages such as perl, APL and INTERCAL. What do you mean by unicode operators? Link? a few messages earlier in the thead you're posting to. if your mail or news provider is dropping messages, you can read the group via e.g. http://news.gmane.org/gmane.comp.python.general jeff's proposal is here: http://article.gmane.org/gmane.comp.python.general/433247 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Christoph Zwerschke wrote: Ok, I just did a little research an compared support for ordered dicts in some other languages: Just to add to your list: In Javascript Object properties (often used as an associative array) are defined as unordered although as IE seems to always store them in the order of original insertion it wouldn't surprise me if there are a lot of websites depending on that behaviour. Javascript Array indexes are also stored as properties and are therefore also unordered. -- http://mail.python.org/mailman/listinfo/python-list
Re: bsddb185 question
thakadu wrote: However the line: del db[key] results in an error: (1, 'Operation not permitted') (only tested on Python 2.3.5) Did you open the dbm file for read-write? This should work, and is implemented. Could this be because the .del() method of the dictionary has not been implemented either? In fact in my tests any attempt at altering the db by use of normal dictionary methods fails with the same error. e.g. db['newkey']='newvalue' causes the same error. Ah, so you definitely should pass the w argument to the open function. Thanks for your info on the rules for interface implementation in Python. That is an interesting difference. I have grown to like the rules for java interface implementation because you are guaranteed that all defined methods for the interface have been implemented. That is what is meant by implementing an interface in java. In Python, there is also the notion of implementing an interface. However, the interface is just specified in English text, and the interpreter never checks whether all of them are implemented. For mapping types, http://www.python.org/doc/current/lib/typesmapping.html gives the list of operations they ought to support. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: sort in the list
On Tue, 22 Nov 2005 14:03:32 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Shi Mu wrote: I use Python 2.3 to run the following code: a=[[1,2],[4,8],[0,3]] a.sort() a [[0, 3], [1, 2], [4, 8]] I wonder whether the sort function automatically consider the first element in the list of list as the sorting criteria or it just happens to be? the documentation has the answer: http://docs.python.org/ref/comparisons.html Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length. If not equal, the sequences are ordered the same as their first differing elements. IMO it could be good to mention that this first means that the rest are then ignored, and this fact means that you can safely decorate in DSU if you do it with unique comparable values. I.e., (1, 1j) (2, 1j) True (1, 1j) (1, 1j) False (1, 1j) (1, 2j) Traceback (most recent call last): File stdin, line 1, in ? TypeError: cannot compare complex numbers using , =, , = Interestingly, that False apparently means equality is detected before ordering is tested? (1, 1j, 1) (1, 1j, 2) True IOW, element-pair comparisons are evaluated until you get a True or reach the end, and same_complex same_complex can return a legititmate False if they're equal ;-) Or so I thought ;-/ What do you make of 1j 1j Traceback (most recent call last): File stdin, line 1, in ? TypeError: cannot compare complex numbers using , =, , = (1j,) (1j,) False Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: sort the list
Duncan Booth wrote: e.g. it is stable when you reverse the order: lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] list(reversed([ x[-1] for x in sorted([ (x[0],x) for x in lst ]) ])) [[9, 3], [5, 4], [4, 2], [4, 1], [2, 5]] l1 = list(lst) l1.sort(key=operator.itemgetter(0), reverse=True) l1 [[9, 3], [5, 4], [4, 1], [4, 2], [2, 5]] Just curious, which one is supposed to be the right answer ? and why the second one is preferable over the first one(if both is right, assume we only care about x[0]). Of course, there is no reason to DIY when the built-in can do the job. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyway to clarify this code? (dictionaries)
On 22 Nov 2005 19:52:40 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: def my_search(another, keys, x): return dict((k,another[k]) for k in keys if another[k]x) ... my_search(another, 'cb', .3) {'b': 0.35806602909756235} my_search(another, 'abcd', .4) {'a': 0.60649466203365532, 'd': 0.77440643221840166} Do you need to guard the case k not in another ? Good catch ;-) What did the OP want as a value if any for that case? None? or no entry at all? Taking a cue from Mike, I like the set method of getting the common keys, to eliminate the entry (untested) def my_search(another, keys, x): return dict((k,another[k]) for k in (set(another)set(keys)) if another[k]x) otherwise, to get Nones, maybe (untested) def my_search(another, keys, x): return dict((k,another.get(k)) for k in keys if k not in another or another[k]x) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Missing /usr/lib/python2.3/config
Hallo, when trying to run the script ez_setup.py, I fail with unable to open /usr/lib/python2.3/config/Makefile This is true. There is no /usr/lib/python2.3/config directory. A check on groups.google revealed that this is a bug in my debian distro or something. Is this true? Is there a work-around? I can't reinstall debian because it is not my server. Any clues appreciated, thanks Tin -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing /usr/lib/python2.3/config
Hi. when trying to run the script ez_setup.py, I fail with unable to open /usr/lib/python2.3/config/Makefile This is true. There is no /usr/lib/python2.3/config directory. A check on groups.google revealed that this is a bug in my debian distro or something. Is this true? Is there a work-around? I can't reinstall debian because it is not my server. Install the python-dev package: apt-get install python-dev -- Zoli -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing /usr/lib/python2.3/config
Tin Gherdanarra wrote: when trying to run the script ez_setup.py, I fail with unable to open /usr/lib/python2.3/config/Makefile This is true. There is no /usr/lib/python2.3/config directory. A check on groups.google revealed that this is a bug in my debian distro or something. Is this true? to build Python extensions, you need the developer extensions: http://packages.debian.org/stable/python/python-dev Is there a work-around? I can't reinstall debian because it is not my server. have you looked for prebuilt versions of whatever package it is you're trying to install? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
On 23 Nov 2005 01:24:46 -0800, Kay Schluehr [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Steve Holden wrote: Perhaps now the answer top your question is more obvious: there is by no means universal agreement on what an ordered dictionary should do. Given the ease with which Python allows you to implement your chosen functionality it would be presumptuous of the core developers to favour any one of the several reasonable alternatives that might be chosen. It seems to be though as ordered dictionary are slowly to be confined to only ordered on order of change to the dictionary. While I'm only +0 for a standard odict I'm wondering that discussing this topic leads to the auctoritative conclusion that it is unsolvable, we have to accept infinite diversity etc. where people like me seeing a classification immediately ( mathematical education? ) . Of course this matter is trivial but we already know about monster-threads revolving around decorator syntax ( including hurt souls and semi-scientific papers ) and abandoning the print statement in Python 3.0. I think the concept has converged to a replace-or-append-by-key ordering of key:value items with methods approximately like a dict. We're now into usability aspects such as syntactic sugar vs essential primitives, and default behaviour vs selectable modes, ISTM. E.g., it might be nice to have a mode that assumes d[key] is d.items()[k][1] when key is an integer, and otherwise uses dict lookup, for cases where the use case is just string dict keys. But feature creep is sure a threat to clean design. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)
Fredrik Lundh wrote: (Well, ok that is not the end of the world either but it's lack is irritating as hell, and yes, I know that it is now back in favor.) the thing that's in favour is then-if-else, not if-then-else. there it comes :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
On Wed, 23 Nov 2005 09:54:46 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Bengt Richter wrote: Though it looks nice, it's an implementation dependant solution. What if someone changes zip to fetch the second item first? That would be a counter-intuitive thing to do. Most things go left-right in order as the default assumption. it's not only the order that matters, but also the number of items read from the source iterators on each iteration. Not sure I understand. Are you thinking of something like lines from a file, where there might be chunky buffering? ISTM that wouldn't matter if the same next method was called. Here we have multiple references to the same iterator. Isn't e.g. buiding a plain tuple defined with evaluation one element at a time left to right? So an iterator it = xrange(4) can't know that it's being used in a context like (it.next(), it.next()), so why should zip be any different? Zip _is_ building tuples after all, and it's perfectly clear where they are coming from (or am I missing something?) Why not left to right like a normal tuple? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: user-defined operators: a very modest proposal
On 23/11/05, Joseph Garvin [EMAIL PROTECTED] wrote: What do you mean by unicode operators? Link? http://fishbowl.pastiche.org/2003/03/19/jsr666_extended_operator_set -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot to split string literals that will across two or more lines ?
Magnus Lycka wrote: Fredrik Lundh wrote: cursor.execute( 'select * from foo' ' where bar=%s' ' limit 100', bar ) The disavantage with this is that it's easy to make a mistake, like this... cursor.execute( 'select * from foo ' 'where bar=%s' 'limit 100', bar ) that's why I prefer to put the spaces first. if you do that, you'll spot the mistakes immediately. (on the other hand, the chance that the SQL engine won't notice this typo is pretty slim). That might be a reason to prefer triple quoting instead: cursor.execute( '''select * from foo where bar=%s limit 100''', bar ) but it looks ugly (as usual, threads like this goes round and round and round ;-) This last version will obviously contain some extra whitespace in the SQL text, and that could possibly have performance implications, but in general, I prefer to reduce the risk of errors (and I've made mistakes with missing spaces in adjacent string literals). absolutely. but if you don't want newlines and whitespace in your strings, using auto-catenated plain literals is a good alternative, at least if you combine with a little indentation discipline. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
Bengt Richter wrote: Are you thinking of something like lines from a file, where there might be chunky buffering? ISTM that wouldn't matter if the same next method was called. Here we have multiple references to the same iterator. Isn't e.g. buiding a plain tuple defined with evaluation one element at a time left to right? yeah, but what says that the iterator has to be called during tuple construction? while 1: for each sequence: # optimize cache behaviour! grab up to N items from each iterator M = length of shortest output list for i in range(M): build tuple and append if M != N: break /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot to split string literals that will across two or more lines ?
Fredrik Lundh wrote: cursor.execute( 'select * from foo' ' where bar=%s' ' limit 100', bar ) The disavantage with this is that it's easy to make a mistake, like this... cursor.execute( 'select * from foo ' 'where bar=%s' 'limit 100', bar ) That might be a reason to prefer triple quoting instead: cursor.execute( '''select * from foo where bar=%s limit 100''', bar ) This last version will obviously contain some extra whitespace in the SQL text, and that could possibly have performance implications, but in general, I prefer to reduce the risk of errors (and I've made mistakes with missing spaces in adjacent string literals). -- http://mail.python.org/mailman/listinfo/python-list
Re: user-defined operators: a very modest proposal
Simon Brunning wrote: What do you mean by unicode operators? Link? http://fishbowl.pastiche.org/2003/03/19/jsr666_extended_operator_set see also: http://www.brunningonline.net/simon/blog/archives/000666.html http://www.python.org/peps/pep-0666.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
On 22/11/05, Bengt Richter [EMAIL PROTECTED] wrote: That would be a counter-intuitive thing to do. Most things go left-right in order as the default assumption. +1 -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing /usr/lib/python2.3/config
Zoli wrote: Hi. when trying to run the script ez_setup.py, I fail with unable to open /usr/lib/python2.3/config/Makefile This is true. There is no /usr/lib/python2.3/config directory. A check on groups.google revealed that this is a bug in my debian distro or something. Is this true? Is there a work-around? I can't reinstall debian because it is not my server. Install the python-dev package: apt-get install python-dev This did it, thanks. Tin -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
Bengt Richter wrote: it's not only the order that matters, but also the number of items read from the source iterators on each iteration. Not sure I understand. Are you thinking of something like lines from a file, where there might be chunky buffering? ISTM that wouldn't matter if the same next method was called. Here we have multiple references to the same iterator. Isn't e.g. buiding a plain tuple defined with evaluation one element at a time left to right? So an iterator it = xrange(4) can't know that it's being used in a context like (it.next(), it.next()), so why should zip be any different? Zip _is_ building tuples after all, and it's perfectly clear where they are coming from (or am I missing something?) Why not left to right like a normal tuple? The implementor of zip() may select to buffer the iterables so instead of it.next(), it may loop it for a number of tmes, or emit multiple threads making it async and all those kind of thing. However, I would say this is highly unlikely or like a extremely remote scenario to prove that this usage is wrong and we are bad boys ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: SelfExtract with zipfile
On 23/11/05, Catalin Lungu [EMAIL PROTECTED] wrote: Hi, I need to compress files in self-extract archive. I use the zipfile module. Is there an option or parameter to do that? No, AFAIK. If you have a command line tool, perhaps you could try driving that. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a flat list to a list of tuples
Fredrik Lundh wrote: Bengt Richter wrote: Are you thinking of something like lines from a file, where there might be chunky buffering? ISTM that wouldn't matter if the same next method was called. Here we have multiple references to the same iterator. Isn't e.g. buiding a plain tuple defined with evaluation one element at a time left to right? yeah, but what says that the iterator has to be called during tuple construction? while 1: for each sequence: # optimize cache behaviour! grab up to N items from each iterator M = length of shortest output list for i in range(M): build tuple and append if M != N: break Wouldn't every attempt to introduce such an optimization be shot down by the likes of def exponential(): for i in xrange(sys.maxint): time.sleep(2**i) yield whatever def const(): for i in xrange(5): yield i zip(exponential(), const()) To say it another way, aren't the problems that can be created by not specifying zip() behaviour in a way that allows the zip(it, it) trick worse than those you want to prevent? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: OKB (not okblacke) wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: [ ... ] so what would an entry-level Python programmer expect from this piece of code? for item in a.reverse(): print item for item in a.reverse(): print item I would expect it to first print a in reverse then a as it was. a=[1,2,3] I expect it to print 3 2 1 1 2 3 really? wouldn't 3 2 1 3 2 1 make a lot more sense ? Yes. The unintuitive thing is that the list is sorted in place at all. intuitive seems to be a very subjective matter, depends on once background etc :-) A quick straw-poll of some non-Pythonistas (two sysadmins, two programmers) suggests that reversing in place is unintuitive -- all four expected: 3 2 1 3 2 1 as suggested by Fredrik. It was less clear-cut, talking through it, whether they found sorting inplace was intuitive or not, but it was agreed that it would be odd if sort() and reverse() behaved differently. All of which is to say I'm convinced by the current behaviour: 1. sort() in place makes sense in terms of space, and is not completely unintuitive. 2. reverse() should do what sort() does. 3. The inexperienced user is most likely to expect the above code to print 3 2 1 3 2 1, and is more likely to have difficulty tracking down the problem if reverse() returns self and they get unexpected results than if it returns None and they get a TypeError: iteration over non-sequence. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Fuzzyman [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Christoph Zwerschke wrote: - the internal keys list should be hidden I disagree. It is exposed so that you can manually change the order (e.g. to create a sorted dict, rather than one ordered by key insertion). What do you *gain* by hiding it ? The internal list should be 'hidden' in the sense that it itself would not be modifiable, though it should be routine to obtain a copy of it at any time. That copy could then be arranged as needed. Any rearrangement of the original list's order destroys the reason for having an entry- or change-ordered dict in the first place. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: user-defined operators: a very modest proposal
On 23/11/05, Fredrik Lundh [EMAIL PROTECTED] wrote: see also: http://www.brunningonline.net/simon/blog/archives/000666.html http://www.python.org/peps/pep-0666.html PEP 666 should have been left open. There are a number of ideas that come up here that should be added to it - and i'm sure there'll be more. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
Ganesan Rajagopal wrote: [EMAIL PROTECTED] com [EMAIL PROTECTED] writes: what would be the definition of sorted and ordered, before we can go on ? Sorted would be ordered by key comparison. Iterating over such a container will give you the keys in sorted order. Java calls this a SortedMap. See http://java.sun.com/j2se/1.4.2/docs/api/java/util/SortedMap.html C++ STL map container is also a Sorted Associative container. See http://www.sgi.com/tech/stl/Map.html Ganesan In Python it's simple to keep a list sorted using bisect.insort. import bisect l=[] bisect.insort(l,4) bisect.insort(l,3) bisect.insort(l,5) bisect.insort(l,1) bisect.insort(l,6) bisect.insort(l,2) l [1, 2, 3, 4, 5, 6] Assuming a list with n tuples, where the first m elements in each tuple is the key, we can also fetch elements through keys (interval matches as well as exact matches) with O(log n) performance. I guess those who thinks this isn't enough should push for placing something like Zope's BTree classes in the standard library. Fredrik already showed how simple and cheap it was to make a dict out of a list. I think this is a superior solution to odicts as suggested, but by all means, if people want odicts, make sure that there is a good implementation available, use it, show that it's useful to others, and maybe, some time in the future, it will be considered for inclusion in the standard library. -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
Sion Arrowsmith wrote: 1. sort() in place makes sense in terms of space, and is not completely unintuitive. 2. reverse() should do what sort() does. 3. The inexperienced user is most likely to expect the above code to print 3 2 1 3 2 1, and is more likely to have difficulty tracking down the problem if reverse() returns self and they get unexpected results than if it returns None and they get a TypeError: iteration over non-sequence. In other words, the None is used as a you are guranteed to get error when you loop it, assuming you don't read the documentation and don't do the simple trial and error in the interactive shell before doing real thing and would read the manual afterwards then found out sort()/reverse() is in place. That as a way to teach, never thought about that kind of intend. But isn't develop by test the general preference ? If that is the case, a unit test would definitely catch the error and I doubt tracking down the error is that hard. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behaviour when writing a large amount of data on stdout
Manlio Perillo wrote: Regards. On my system: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32, Windows XP I have this problem: n = 61409 + 1 data = 'x' * n print data Traceback (most recent call last): File xxx, line xxx, in ? print data IOError: [Errno 12] Not enough space Can someone reproduce this bug? Not here, but it's a bipro amd64 with a couple Mb of ram !-) (for the record, it works fine for far greater values, ie n = 12800) I begin to think that my system is messed up... troll OF course it's messed up, else it wouldn't be a real Windows box !-) /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: syntax errors while building pypgsql
Tin Gherdanarra wrote: [EMAIL PROTECTED] wrote: Have you tried apt-get build-dep pypgsql ? It could be that you lacks the necessary packages to build it. funny you'd mention it, I did. pypgsql does not seem to be an apt-get package, however. It did not work because E: Couldn't find package pypgsql The fact that there is a PyObject_HEAD PGconn *conn; throws an error can't be relieved by another package, I guess... If that is the case, you need to read the pypgsql for what it is needed. As an alternative, you may try apt-get build-dep celementtree which may pull in the necessary files. But this is really WAG. -- http://mail.python.org/mailman/listinfo/python-list
Re: bsddb185 question
Martin you are great! If I had just opened the file with f=bsddb185.hashopen('filename',''w') it would have worked the first time. So now I will create wrapper classes around the file classes of bsddb185 and create the methods that I need to keep it consistent with bsddb. Another small difference I noted is that bsddb seems to auto sync() while bsddb185 does not, this is not a big issue though. Thanks very much for all your input! -- http://mail.python.org/mailman/listinfo/python-list
Tutorials for Python + PostgreSQL
I want to learn more about enterprise-level programming using Python and PostgreSQL. From what I've searched, it seems that psycho is interesting to improve runtime too. Do you have tutorials, articles and tips to learn this combination? I've been working with PostgreSQL for 2 years, and with Python for 6 months. Thank you, -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
[EMAIL PROTECTED] wrote: Have you tried apt-get build-dep pypgsql ? It could be that you lacks the necessary packages to build it. funny you'd mention it, I did. pypgsql does not seem to be an apt-get package, however. It did not work because E: Couldn't find package pypgsql The fact that there is a PyObject_HEAD PGconn *conn; throws an error can't be relieved by another package, I guess... Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ PGconn *conn; PyObject *host; PyObject *port; PyObject *db; PyObject *options; PyObject *tty; PyObject *user; PyObject *pass; PyObject *bePID; PyObject *socket; PyObject *version; PyObject *notices; PyObject *cinfo; int showQuery; } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD /* Here is the syntax error */ PGconn *conn; The setup.py-settings look good to me, I use debian sarge stable. Installation of PostgreSQL ran without any problems. -- http://mail.python.org/mailman/listinfo/python-list
syntax errors while building pypgsql
Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ PGconn *conn; PyObject *host; PyObject *port; PyObject *db; PyObject *options; PyObject *tty; PyObject *user; PyObject *pass; PyObject *bePID; PyObject *socket; PyObject *version; PyObject *notices; PyObject *cinfo; int showQuery; } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD /* Here is the syntax error */ PGconn *conn; The setup.py-settings look good to me, I use debian sarge stable. Installation of PostgreSQL ran without any problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are there no ordered dictionaries?
On Tue, 2005-11-22 at 20:44, Tom Anderson wrote: On Tue, 22 Nov 2005, Carsten Haese wrote: On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote: In Foord/Larosa's odict, the keys are exposed as a public member which also seems to be a bad idea (If you alter the sequence list so that it no longer reflects the contents of the dictionary, you have broken your OrderedDict). That could easily be fixed by making the sequence a managed property whose setter raises a ValueError if you try to set it to something that's not a permutation of what it was. I'm not a managed property expert (although there's a lovely studio in Bayswater you might be interested in), but how does this stop you doing: my_odict.sequence[0] = Shrubbery() It would only break if the getter returns the internal list directly. The getter should return a copy instead, which is what the keys() method already does anyway. This would ensure that the only way to alter the sequence is by replacing it in its entirety. -Carsten. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mac OSX oddities (compiling Python plus tkinter)
MichaelW wrote: I've been Python (2.3.4) plus Tkinter happily under MacOX 10.3, having compiled them from scatch. (Tkinter is based on tcl/tk 8.4.1, which were compiled from source via Fink). I then moved my laptop over the 10.4, and things are now breaking. Using the Python shipped with 10.4 (which has Tkinter based on tcl/tk 8.4.7) the window in a particular application looks completely different (more Apple-like) and the buttons no longer work properly. (Oddly, some icons have fallen off the buttons.) I therefore thought I might compile Python from scratch and that fell over with messages: sem_init: Function not implemented sem_wait: Bad file descriptor sem_post: Bad file descriptor reported at intervals. I assume the odd Tkinter behaviour is due to problems Apple created Apple-ising it? Is that correct, or has there been a major change to the API between 8,4 and 8.7?. Is there any work-around? Secondly, can I assume that the compiler messages indicate a problem with the compiler (gcc select 3.3 makes no difference, BTW). Your ideas would be appreciated. Cheers MichaelW There were not huge changes between Tk 8.4.1 and 8.4.7. However, if you were using Tk from Fink before and now are using the Apple version of Tk, that may account for the difference. Tk from Fink is targeted for X11, while the Apple-installed Tk is targeted to the Aqua windowing environment. Tk itself is portable, but some of the extension packages for it (such as BLT, and presumably any Pythonesque wrappers for them) do not work on Aqua. Similarly, some bugs have arisen in Aqua's implementation of Tk (pixmaps do not display in menus, tearoff menus do not work properly), etc. Also, did you compile Python as a Carbon framework build (makes use of the Apple's windowing environment)? What version are you now running? -- Cheers, Kevin Walzer, PhD WordTech Software - Tame the Terminal http://www.wordtech-software.com sw at wordtech-software.com -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behaviour when writing a large amount of data on stdout
That code works here. Python2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 It's Windows XP, Pentium 4, unknown amount of RAM. I'm running python.exe in a console window. It also worked in IDLE. Jeff pgptwrbVpG8CR.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ [...] I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: [...] I don't think that's the real error. Are there any error messages *before* that? Like the compiler can't find Python.h or something? That would be an indication that you do not have the python-devel package installed. Btw. the Debian package of pyPgSQL is called python-pgsql, so an apt-get install python-pgsql should do. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
On Wed, 2005-11-23 at 08:01, Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ PGconn *conn; PyObject *host; PyObject *port; PyObject *db; PyObject *options; PyObject *tty; PyObject *user; PyObject *pass; PyObject *bePID; PyObject *socket; PyObject *version; PyObject *notices; PyObject *cinfo; int showQuery; } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD is not a type, it is a macro that defines struct members that all Python objects have in common. The macro definition has a semicolon at the end, so when the macro is expanded, the result is syntactically correct, even though the above looks wrong on the surface. What error messages are you actually getting? If you are getting a long list of errors, please give us the first few rather than the last few. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behaviour when writing a large amount of data on stdout
Manlio Perillo wrote: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32, Windows XP I have this problem: n = 61409 + 1 data = 'x' * n print data Traceback (most recent call last): File xxx, line xxx, in ? print data IOError: [Errno 12] Not enough space errno 12 is ENOMEM (that is, the system did not have enough memory to finish an operation). is the above a complete interpreter session? if it is, why did you xxx out the filename (stdin) and line number? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing a database from a multithreaded application
Alan Kemp [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, Can someone suggest a better (ie, valid) strategy for this? Pass the connection to the thread as a parameter and use it to create a cursor local to the thread. You may have to create a connection per thread also - in some database implementations connections are global like cursors are. Cursors are throwaway things anyway. Should I be using a Queue to make a list of db requests/results to get accross the thread boundary (erg, that sounds nasty)? Maybe - it is safest to limit the amount of threads/cursors/connections that can be created by people one does not know. Should each client thread create its own connection/cursor to the database? Would that even work, wont there be locking issues? Yes, and maybe; one connection/cursor for each thread will always work. Any suggestions or pointers in the direction of more information would be greatly appreciated. Maybe use queues to pass the requests to a pool of threads; there might be a limit to how many connection/cursors that can be created at the same time -- and some DOS tool will find it. Thanks for your time, Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
Have you tried apt-get build-dep pypgsql ? It could be that you lacks the necessary packages to build it. Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ PGconn *conn; PyObject *host; PyObject *port; PyObject *db; PyObject *options; PyObject *tty; PyObject *user; PyObject *pass; PyObject *bePID; PyObject *socket; PyObject *version; PyObject *notices; PyObject *cinfo; int showQuery; } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD /* Here is the syntax error */ PGconn *conn; The setup.py-settings look good to me, I use debian sarge stable. Installation of PostgreSQL ran without any problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: user-defined operators: a very modest proposal
Joseph Garvin wrote: Tom Anderson wrote: Jeff Epler's proposal to use unicode operators would synergise most excellently with this, allowing python to finally reach, and even surpass, the level of expressiveness found in languages such as perl, APL and INTERCAL. s/expressiveness/unreadability/ -- 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: syntax errors while building pypgsql
Tin Gherdanarra wrote: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ [snip] } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD /* Here is the syntax error */ PGconn *conn; PyObject_HEAD is a macro defined in the Python headers. It provides the internal fields common to all Python objects to provide garbage collection and other services. If that's throwing errors, then your compiler isn't finding the headers. Check to see if you have the file /usr/include/python*/Python.h on your system. -- David -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with threaded Hotkey application
And just to confirm, it does in fact work. If you move the RegisterHotKey line to within the thread's run method, the thread's message loop picks up the hotkey press. -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Licence vs GPL
John Perks and Sarah Mount [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] we have some Python code we're planning to GPL. However, bits of it were (This assumes the wxPython Licence is compatible with the GPL -- if not, do we just cosmetically change any remaining lines, so none remain from the orignal?) What makes you think that cosmetic changes in a copyrighted work affect the copyright? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with threaded Hotkey application
One obvious point is that, according to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefWM_HOTKEY.asp the WM_HOTKEY message is posted to the queue *of the thread which registered the hotkey*. I haven't yet tried it myself to see, but in your example the main thread registers the hotkey, and the KeyCatch thread is waiting to receive it. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: a new design pattern for Python Library?
Ben Sizer wrote: The Eternal Squire wrote: I tend to use this design pattern a lot in order to aid in compartmentalizing interchangeable features in a central class that depend on the central class's data. I'm afraid I've read this paragraph and the code 3 times and I still have no idea what you're trying to convey. aol -- 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: about sort and dictionary
[EMAIL PROTECTED] wrote: a reminder that the change is inplace. How arrogant! While I'm sure the designers had kindly intentions. my memory, though bad, is not that bad, and I object to being forced to write code that is more clunky than need be, because the designers thought they needed to help me with my memory. Such as being arm-twisted into writing horrible things like x = sorted(l) instead of x = l.sort()? It sounds a bit as if someone locked you into a cellar and forced you to program Python, just to torture you. I guess the next step will be the comfy armchair! ;) Python has its roots in ABC, a language intended for teaching programming to beginners, and it goes to great lengths to make it easy to do things right. In my opinion, it also avoids the mistake of introducing hurdles in a vain attempts to prevent programmer mistakes. Such hurdles typically lead to ugly workarounds. There are a few cases when things don't work as some people would expect them to work, but I think there are good resons for that. I'm surprised that you don't complain about not being able to do while x = f(): ... while you're at it. That's also a restriction of the kind you seem to rebel against. I'm pretty sure Guido didn't think a bit about *your* memory capacity when he designed Python, but rather wanted to avoid spending his and other programmers' time on helping people with yet another set of silly bugs. There is much about Perl's rich functionality that is very worthy. Unfortunately, as you know, it's syntax leaves a lot to be desired. Which is mainly a consequence of TMTOWTDI... If you want something more perlish, but with somewhat more sane syntax, you might want to try Ruby. -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
[EMAIL PROTECTED] wrote: Alex Martelli wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: ... intuitive seems to be a very subjective matter, depends on once background etc :-) That's a strong point of Ruby, actually -- allowing an exclamation mark at the end of a method name, which conventionally is always used to indicate that the method is a mutator. So, you can have a.reverse [NOT mutating a since no !] _and_ a.reverse! [mutating a]. Probably too much of a change even for Python 3000, alas... but, it DOES make it obvious when an object's getting mutated, and when not... Except when it isn't obvious. What constitutes mutation of an object? C++ handles this with 'const', and lets the programmer cheat by using transient member variables, since there are cases when you actually want to mutate objects a little, but claim that you don't... Perhaps we need a.reverse? for just-mutating-a-little reverse as well? ;^) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Licence vs GPL
Andrea Gavana wrote: IIRC, wxPython license has nothing to do with GPL. Its license is far more free than GPL is. That would be free as in freeloading, right? (And no, I'm not intending to start a licensing flame war with that remark, but I think it's inappropriate to ignore central licensing concepts such as end-user freedoms, and then to make sweeping statements about how free the GPL is or isn't. If people want to use the GPL as a convenient punchbag, I think they have to work a bit harder justifying their gym subscription.) If you want to create commercial apps with wxPython, you can do it without messing with licenses. With GPL code is somewhat harder. That's confusing commercial with proprietary or closed source, by the way. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorials for Python + PostgreSQL
Steve: I want to learn more about enterprise-level programming using Python and PostgreSQL. From what I've searched, it seems that psycho is interesting to improve runtime too. Do you have tutorials, articles and tips to learn this combination? I've been working with PostgreSQL for 2 years, and with Python for 6 months. Thank you, Since Psyco is meant to speedup Python code, whereas the psycopg adapter is C-coded, I strongly doubt you will get any improvement from the combination. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)
On Tue, 22 Nov 2005 23:17:31 -0700 in comp.lang.python, Steven Bethard [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: [...] IIRC, this was discussednd rejected in an SF bug report. It should not be a defined behavior for severals reasons: [snip arguments about how confusing zip(it, it) is] Overall, I think anyone using zip(it,it) is living in a state of sin, drawn to the tempations of one-liners and premature optimization. They are forsaking obvious code in favor of screwy special cases. The behavior has been left undefined for a reason. Then why document itertools.izip() as it is? The documentation there is explicit enough to know that izip(it, it) will work as intended. Should we make the documentation there less explicit to discourage people from using the izip(it, it) idiom? ISTM that one would use itertools.izip in order to get some functionality not available from zip. Perhaps this is one of those bits of functionality. But I admit, I'm not all that familiar with itertools... In any case, the solution seems obvious: if you want the guarantee, use the tool that provides it. Regards, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
[EMAIL PROTECTED] wrote: Tin Gherdanarra wrote: [EMAIL PROTECTED] wrote: Have you tried apt-get build-dep pypgsql ? It could be that you lacks the necessary packages to build it. funny you'd mention it, I did. pypgsql does not seem to be an apt-get package, however. It did not work because E: Couldn't find package pypgsql The fact that there is a PyObject_HEAD PGconn *conn; throws an error can't be relieved by another package, I guess... If that is the case, you need to read the pypgsql for what it is needed. As an alternative, you may try apt-get build-dep celementtree which may pull in the necessary files. But this is really WAG. Thanks, but what is WAG? This came right in: Confusingly, it's not apt-get pypgsql, it is python-pgsql. After doing a apt-get python-pgsql. I'm not yet one happy camper, but getting there. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: the PHP ternary operator equivalent on Python
WHY WHY WHY the obsession with one-liners? What is wrong with the good old fashioned way? if cond: x = true_value else: x = false_value Let me tell you something: I'm not a one-liner coder, but sometimes It is necesary. For example: I need to translate data from a DataField to Another. def Evaluate(condition,truepart,falsepart): if condition: return truepart else: return falsepart dOldDataFields = {} dNewDataFields = {} dNewDataFields = { 'CODE': dOldDataFields['CODEDATA'], 'DATE': dOldDataFields['DATE'], 'CONTACT': Evaluate(dOldDataFields['CONTACTTYPE']==2, dOldDataFields['FIRSTCONTACT'], dOldDataFields['SECONDCONTACT']) } With this, I created a new dic very easy, saving in dNewDataFields['CONTACT'] the value of dOldDataFields['FIRSTCONTACT'] or the value of dOldDataFields['SECONDCONTACT'] depending on dOldDataFields['CONTACTTYPE']. How you do this in a practic way without the use of one-line code? It is needed! You can't avoid it! Even using a = [if_false_expr, if_true_expr][predicate] or a function, you'll always have to use a one-line code (for this purpose, of course). Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorials for Python + PostgreSQL
Michele Simionato wrote: Steve: I want to learn more about enterprise-level programming using Python and PostgreSQL. From what I've searched, it seems that psycho is interesting to improve runtime too. Do you have tutorials, articles and tips to learn this combination? I've been working with PostgreSQL for 2 years, and with Python for 6 months. Thank you, Since Psyco is meant to speedup Python code, whereas the psycopg adapter is C-coded, I strongly doubt you will get any improvement from the combination. Michele Simionato I think he's referring to psycopg, a python postgre database adapter http://initd.org/projects/psycopg1 -- http://mail.python.org/mailman/listinfo/python-list
Re: the PHP ternary operator equivalent on Python
This could be done easier this way: L = [('odd','even')[n%2] for i in range(8)] -- http://mail.python.org/mailman/listinfo/python-list
Re: the PHP ternary operator equivalent on Python
This could be done easier this way: L = [('even','odd')[n%2] for n in range(8)] -- http://mail.python.org/mailman/listinfo/python-list
Re: best cumulative sum
David Isaac wrote: Michael Spencer wrote: This can be written more concisely as a generator: [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] If iterable has no elements, I believe the behaviour should be [init], there is also the case of init=None that needs to be handled. Right. So it is more concise only by being incomplete, right? What other advantages might it have? otherwise, that is more or less what I wrote for my scanl/scanl1. I didn't see a post with that code. Alan Isaac def scanl1(func, seq): def my_func(x): my_func.init = func(my_func.init, x) return my_func.init i = iter(seq) try: my_func.init = i.next() except StopIteration: return [] return (chain([my_func.init], (my_func(y) for y in i))) def scanl(func, seq, init): def my_func(x): my_func.init = func(my_func.init, x) return my_func.init my_func.init = init return (chain([my_func.init], (my_func(y) for y in seq))) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Licence vs GPL
Paul Boddie [EMAIL PROTECTED] wrote: That would be free as in freeloading, right? (And no, I'm not intending to start a licensing flame war with that remark, but I think it's inappropriate to ignore central licensing concepts such as end-user freedoms, and then to make sweeping statements about how free the GPL is or isn't. If people want to use the GPL as a convenient punchbag, I think they have to work a bit harder justifying their gym subscription.) Blame the GPL and FSF for the confusion. Try this little experiment: Walk up, at random, to 100 people on the street. Show them a software CD-ROM -- a game, a word processor, whatever. Tell them it's free. Then ask them what they think that means. 99 times out of 100, they'll think it means it's free-as-in-beer. They *won't* think it means they'll get the source code, and the right to tweak that source code. They *won't* think it means they have the right to infinitely redistribute it. At best, the GPL/FSF engaged in what I consider false advertising. Free Software (note the capital 'F' and 'S') *isn't*, by the most widely understood and assumed definition of free. They should have called it liberated software or share and share alike software or free as in herpes software. Free Software is certainly not free software, since it comes heavily encumbered by licensing issues. The success of things like Python -- which is not GPL licensed, afaik -- pretty much proves the GPL is unnecessary for the success of free projects. The GPL is just some bizarre social agenda being pushed by some crazies, and a lot of programmers (who are not lawyers) fell for the hippie nonsense. So, you may like to bandy around the mildly offensive free as in freeloading, but then that gives me the right to refer to GPL'd software as free as in pushing my personal social agenda. -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout for regular expression
On Tue, 22 Nov 2005 18:49:15 +0100 Fredrik Lundh [EMAIL PROTECTED] wrote: not directly. the only reliable way is to run it in a separate process, and use the resource module to set necessary limits. Wow. Thank you Mr. Lundh, I never noticed that module. I think I have an application for that. Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: drawline
Ben Bush wrote: I had the following code and when I clicked the left mouse button one time. I got green line and the second click got a purple line and the green disappeared. I was confused by two questions: It's good that these postings are archived, so that teachers can check them before grading their students. After all, the grades belong to those who solved the problems, not to those who handed them in... -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
Gerhard Häring wrote: Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ [...] I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: [...] I don't think that's the real error. Well, I don't know what's going on in that struct def, but to me it looks a little weird. Are there any error messages *before* that? Nope. First error. Like the compiler can't find Python.h or something? That would be an indication that you do not have the python-devel package installed. This provokes different errors. Your idea is good, though, because this was the first problem another correspondent pointed out. Btw. the Debian package of pyPgSQL is called python-pgsql, so an apt-get install python-pgsql should do. Thanks, this I have found out already (see previous post). It is in the fine print of the documentation. Thanks Tin -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
ANNOUNCE: Mod_python 3.2.5 Beta
The Apache Software Foundation and The Apache HTTP Server Project are pleased to announce the 3.2.5 Beta release mod_python. Version 3.2.5b of mod_python features several new functions and attributes providing better access to apache internals, file-based sessions and other session improvements, as well as many bug fixes and various performance and security improvements. A detailed description of the changes is available in Appendix A of the mod_python manual, also available here: http://www.modpython.org/live/mod_python-3.2.5b/doc-html/node97.html Beta releases are NOT considered stable and usually contain bugs. This release is intended to solicit widespread testing of the code. We strongly recommend that you try out your existing applications and experiment with new features in a non-production environment using this version and report any problems you may encounter so that they can be addressed before the final release. Preferred method of reporting problems is the mod_python user list [EMAIL PROTECTED] Mod_python 3.2.5b is available for download from: http://httpd.apache.org/modules/python-download.cgi For more information about mod_python visit http://www.modpython.org/ Regards, Grisha Trubetskoy and the Apache mod_python team. -- http://mail.python.org/mailman/listinfo/python-list
Re: the PHP ternary operator equivalent on Python
Luis M. Gonzalez wrote: This could be done easier this way: L = [('even','odd')[n%2] for n in range(8)] That is even/odd, his(created to demonstrate the uglies of ternary) has 4 states, zero, -/+ then even/odd. -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax errors while building pypgsql
Carsten Haese wrote: On Wed, 2005-11-23 at 08:01, Tin Gherdanarra wrote: Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct { PyObject_HEAD /* Here is the syntax error, and rightly so */ PGconn *conn; PyObject *host; PyObject *port; PyObject *db; PyObject *options; PyObject *tty; PyObject *user; PyObject *pass; PyObject *bePID; PyObject *socket; PyObject *version; PyObject *notices; PyObject *cinfo; int showQuery; } PgConnection; I don't know what PyObject_HEAD or PGconn is, but if they are types, a syntax error is justified here: PyObject_HEAD is not a type, it is a macro that defines struct members that all Python objects have in common. The macro definition has a semicolon at the end, so when the macro is expanded, the result is syntactically correct, even though the above looks wrong on the surface. Aha! Weird! What error messages are you actually getting? If you are getting a long list of errors, please give us the first few rather than the last few. The aforementioned error was the first one. I fixed it by delegating the installation/build to apt-get python-pgsql. That did it for me. Unfortunately, I can't duplicate the errors now. This probably means that apt-get automatically failed to install some stuff I failed to do. However, I don't think that you miss anything interesting, i.e. a bug in pysql or so. This was just a newbie problem. Thanks all the same Tin -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: about sort and dictionary
Magnus Lycka [EMAIL PROTECTED] wrote: ... indicate that the method is a mutator. So, you can have a.reverse [NOT mutating a since no !] _and_ a.reverse! [mutating a]. Probably too much of a change even for Python 3000, alas... but, it DOES make it obvious when an object's getting mutated, and when not... Except when it isn't obvious. What constitutes mutation of an object? Potential alteration of the object's state. [2,2,2] -- a list with three identical items -- may be subject to any permutation in-place, including sorting and reversing, without _actual_ alteration of state, just as, say, L[2]=2 MAY happen not to alter state if L[2] was already 2 before the assignment. However, such corner cases do not constitute any deep conceptual blockage to the notion of mutation, any more than, say, the possibility of state being empty (e.g in an empty tuple) constitues any to the notion of state. I classify list and dict methods as mutating and non-mutating in the Nutshell, for example, and nobody's quibbled about their usefulness. If you want to get more formal, you can focus on the post-condition (either in programming-by-contract terms, or the more formal Hoare and Djikstra ideas that preceded Pbc) using X' to mean X as it was on entry: for any type T, a method M of T is said to be non-mutating iff, for any instance t of T, the strongest postcondition of calling M on t includes t == t' a method M is said to be mutating if it is not non-mutating Note how cleanly this deals (by delegating to ==, if you will;-) with the issue of whether 'non-observable state' (e.g. a cache) counts as state (answer: if it cannot influence the result of == it does not matter regarding this definition). Objects which cannot be compared for equality with their peers, or for which it is conceptually absurd to talk of as it was, are always going to be problematic for any system of formal reasoning about programming, but the problem is with the formalization under such conditions (it's hard to do most any formal reasoning without equality, for example) and not with the pragmatics of the situation. C++ handles this with 'const', and lets the programmer cheat by using transient member variables, since there are cases when you actually want to mutate objects a little, but claim that you don't... I think you mean volatile or mutable rather than transient? transient is not a keyword in C++, while both volatile and mutable are, with different semantics. Anyway, C++'s 'const' is a mess both theoretical AND practical. I'm told Ruby's object-freezing works better (but I have no practical experience). Perhaps we need a.reverse? for just-mutating-a-little reverse as well? ;^) I don't see the alleged humor in this ill-defined concept. Anyway, a trailing question mark is used in Ruby to indicate a predicate (a non mutator which returns a boolean result); a convention similar to that of exclamation for mutators, though not quite as important IMHO. I do see some nice symmetry, supposing for example that S is a mutable string, in being able to name some of S's methods as: upper return an uppercased copy of S, not mutating S upper! mutate S in-place to be uppercased upper? return True iff S is already uppercased, not mutating S but (maybe because I have no extensive Ruby real-life experience) the predicate case, while nice, doesn't seem compelling to me (having to name it, say, isupper, doesn't appear to cause practical problems). Alex -- http://mail.python.org/mailman/listinfo/python-list