Re: Pythonic style involves lots of lightweight classes (for me)
Hi, I think that tuples are the best and simplest approach for small structures. songs = [(Paranoid, http://...;), (Christian Woman, http://...;)] for title, url in songs: ... print %s: %s % (title, url) ... Paranoid: http://... Christian Woman: http://... I think that python's unpacking and builtin data types very useful. I prefer it a lot to over-object-oriented-programming. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing from a List in Place
I'm going to assume that it's supposed to work like this, but could someone tell me the reasoning behind it? I.E. why is 3 skipped? Because: alist[2] 3 You are removing the third item, not the second. -- http://mail.python.org/mailman/listinfo/python-list
Re: threading support in python
Hi, GIL won't go. You might want to read http://blog.ianbicking.org/gil-of-doom.html . Regards, -Justin -- http://mail.python.org/mailman/listinfo/python-list
Re: threading support in python
Hi, You might want to split your calculation onto different worker-processes. Then you can use POSH [1] to share data and objects. You might even want to go a step further and share the data via Sockets/XML-RPC or something like that. That makes it easy to throw aditional boxes at a specific calculation, because it can be set up in about no time. You can even use Twisted Spread [2] and its perspective broker to do this on a higher level. If that's not what you want, you are left with Java I guess. Regards, -Justin [1] http://poshmodule.sourceforge.net/ [2] http://twistedmatrix.com/projects/core/documentation/howto/pb.html -- http://mail.python.org/mailman/listinfo/python-list
Re: function v. method
I guess the python devs are not interested in implementing something that would require new syntax and does not give something entirely new to the language. The good thing about python is, that the devs are only implementing ideas that are very cool. There are a lot of cool (!= very cool) ideas in rejected peps - but they were never implemented for good reasons. If you *really* need privates, just use the naming convention. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate all permutations of a string?
Mind, that Lawrence's solution may contain doubles: [ i for i in permute(aa) ] [('a', 'a'), ('a', 'a')] If you don't want this, use sets. -- http://mail.python.org/mailman/listinfo/python-list
Registry of Methods via Decorators
I want to make a registry of methods of a class during creation. My attempt was this classdecorators.py Author: Justin Bayer Creation Date: 2006-06-22 Copyright (c) 2006 Chess Pattern Soft, All rights reserved. class decorated(object): methods = [] @classmethod def collect_methods(cls, method): cls.methods.append(method.__name__) return method class dec2(decorated): @collect_methods def first_func(self): pass @collect_methods def second_func(self): pass def main(): print dec2.methods if __name__ == '__main__': main() This does not work and exits with NameError: (name 'collect_methods' is not defined,). Which is understandable due to the fact that the class dec2 is not complete. Anyone can give me a hint how to work around this? -- http://mail.python.org/mailman/listinfo/python-list
Re: learning python idioms
Hi, If you switched from java to python the best point to start is http://dirtsimple.org/2004/12/python-is-not-java.html. Greets, -Justin -- http://mail.python.org/mailman/listinfo/python-list
Re: learning python idioms
yup, you could spend weeks reading the Language Wars: Actually, that link is not about language wars. It's about making the switch from java to python. Nothing more, nothing less. -- http://mail.python.org/mailman/listinfo/python-list
Re: Argument Decorators Enhancement?
Hi, -1 because I find it extremly hard to read and not necessary in that scale. Actually, there are a lot of recipes in the Cookbook [1] on how to use decorators for type-checking. On example is: @require(int, int) def add(x,y): return x + y Which I find much more readable, easier to implement and even backwards compatible: def add(x,y): return x + y add = require(int, int)(add) g2g, Justin [1] http://aspn.activestate.com/ASPN/Cookbook/Python/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Property In Python
print property.__doc__ property(fget=None, fset=None, fdel=None, doc=None) - property attribute fget is a function to be used for getting an attribute value, and likewise fset is a function for setting, and fdel a function for del'ing, an attribute. Typical use is to define a managed attribute x: class C(object): def getx(self): return self.__x def setx(self, value): self.__x = value def delx(self): del self.__x x = property(getx, setx, delx, I'm the 'x' property.) -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you guys print out a binary tree?
The problem is that you cannot represent a matrix as a tree, due to the fact that there are more than one tree for a matrix. First you have to decide, how you will turn the matrix into a tree. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you guys print out a binary tree?
Hi, 1 2 3 4 5 0 7 8 9 10 0 0 13 14 15 0 0 0 19 20 0 0 0 0 25 Look at the triangle represented by the non-zero integers. This triangle is a binary tree if we take 5 as the root and walk down on both sides. Are you sure? Is 9 a child of 4 or 10? A binary tree can have up to 2^n - 1 nodes. A matrix can have up to n^2 values, in your case of a half-empty matrix about (n-1)^2. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you guys print out a binary tree?
A half-empty matrix will of course have (n+1)* n * 1/2 elements. -- http://mail.python.org/mailman/listinfo/python-list
Re: print() in Python 3000 return value?
Sorry? 2+2 here returns 4, and certainly should with your Python. Err. Never mind. I was thinking about assignments, like x += 2 which returns None. -- http://mail.python.org/mailman/listinfo/python-list
Re: print() in Python 3000 return value?
Expressions like 2 + 2 return None, too. I am not certain, but as far as I know this has some major design reasons. Thus I am certain, that print() will return None also. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search HUGE XML with DOM?
Mind, that XML documents are not more flexible than RDBMS. You can represent any XML document in a RDBMS. You cannot represent any RDBMS in an XML document. RDBMS are (strictly spoken) relations and XML documents are trees. Relations are superior to trees, at least mathematically speaking. Once you have set up your system in a practicable way (e.G. not needing to create a new table via SQL Queries for a new type of node, which would be a pain) SQL is far superior to XML. Anyway, cElementTree seems to be the best way to go for you now. Its performance is untopped by any other python xml library, as far as I know. -- http://mail.python.org/mailman/listinfo/python-list