Re: Dictionary of Dicts question

2008-10-17 Thread George Sakkis
e in open(path): fields = line.split('\t') data[tuple(fields[:2])] = map(float,fields[2:]) return data d1 = read_data(sys.argv[1]) d2 = read_data(sys.argv[2]) for key in d1: if key in d2: diffs = map(sub, d1[key], d2[key]) print key, diffs HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: Need advice on python importing

2008-10-17 Thread George Sakkis
method signatures like this is worse than the problem they're trying (unsuccessfully) to solve. You should try to resolve the cyclic dependencies first. If it's not possible, that's probably a sign that they should live in the same module after all. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-10-17 Thread George Sakkis
n many other languages (C, Pascal, etc.), a ^ Methinks the only real disagreement in this thread is what's a "modern" language; Joe has made clear that he's not comparing Python to C, Pascal or Fortran. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a file with iterators

2008-10-17 Thread George Sakkis
f all the data lines must or should be given at once, append them in a list and feed them all as soon as the next section is found), something like: class parse_a(object): def __init__(self, metadata): print 'parser a', metadata def parse(self, line): print 'a', line # similar for parse_b and parse_c # ... def parse(lines): parse = None for line in lines: if test_for_type(line): type_id, metadata = line.split(' ', 1) parse = type2parser[type_id](metadata).parse else: parse(line) George -- http://mail.python.org/mailman/listinfo/python-list

Re: a new brawser (avant) it is very very good

2008-10-19 Thread George Sakkis
On Oct 17, 5:59 pm, Stef Mientki <[EMAIL PROTECTED]> wrote: > mina2020 wrote: > > what has this todo with Python ? Do you take the time to reply to every spam you receive ? -- http://mail.python.org/mailman/listinfo/python-list

Re: csv.reader problem tab-delimiter - newbie

2008-10-21 Thread George Sakkis
y the file is not tab delimited. If you used an editor to produce dummy.txt, check whether it uses soft tabs and disable it temporarily. HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: csv.reader problem tab-delimiter - newbie

2008-10-21 Thread George Sakkis
On Oct 21, 1:44 pm, [EMAIL PROTECTED] wrote: > > Most likely the file is not tab delimited. If you used an editor to > > produce dummy.txt, check whether it uses soft tabs and disable it > > temporarily. > > > HTH, > > George > > Most likely the file is not

Re: substitution of a method by a callable object

2008-10-22 Thread George Sakkis
ypeError: __call__() takes exactly 2 arguments (1 > given) You have to wrap it as an (unbound) instance method explicitly: from types import MethodType Foo.meth = MethodType(Obj(), None, Foo) f.meth() For normal functions this seems to be done implicitly (of course you can do it explicitly if you w

Re: Database specialized in storing directed graphs?

2008-10-28 Thread George Sakkis
maintained any more. For commercial solutions, Star-P [3] seems an interesting platform, with bindings to Matlab and Python. Freebase [4] is apparently built on a special graph database but unfortunately only the stored data are available, not the DB source code. George [1] http://www.boost.org/

Replacing cmp with key for sorting

2008-11-03 Thread George Sakkis
', 'bcb', 'bc', 'bd']. Currently I do it with: s.sort(cmp=lambda x,y: 0 if x==y else -1 if x.startswith(y) else +1 if y.startswith(x) else cmp(x,y)) Can this be done with an equivalent key function instead of cmp ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: Tiny yet useful utility

2008-11-03 Thread George Sakkis
On Nov 3, 12:55 pm, [EMAIL PROTECTED] wrote: >     Mariyam> Process Manager for Windows >     Mariyam> (http://processpriority.wiki.sourceforge.net/) It has always >     Mariyam> been a pain to use applications like >     Mariyam> Office/Outlook/Matlab/Delphi/Mozilla...Image editing s/w >     Mariy

Re: Replacing cmp with key for sorting

2008-11-03 Thread George Sakkis
ngs too: > > print sorted(s, key=lambda x: [-ord(l) for l in x], reverse=True) > > Bye, > bearophile Awesome! I tested it on a sample list of ~61K words [1] and it's almost 40% faster, from ~1.05s dropped to ~0.62s. That's still >15 times slower than the default sorting (0

Re: Structures

2008-11-03 Thread George Sakkis
vate fields/methods. Technically there are no private attributes in (pure) Python so the answer is still classes. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread George Sakkis
optimizations, you can define a class with __slots__: >>> class MyStruct(object): ... __slots__ = ('x', 'y') ... >>> s = MyStruct() >>> s.x = 3 >>> s.y = 4 >>> s.z= 5 Traceback (most recent call last): File "", line 1,

Re: Structures

2008-11-04 Thread George Sakkis
t; missed having an equivalent to the Pascal record or C > struct: essentially a named mutable tuple. +1. FWIW, I posted a recipe along these lines, following closely the functionality and implementation of namedtuple: http://code.activestate.com/recipes/576555/ George -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse each line by character location

2008-11-04 Thread George Sakkis
t = 0 ... for i,size in enumerate(sizes): ... stop = start+size ... slices[i] = slice(start,stop) ... start = stop ... return lambda string: [string[s].strip() for s in slices] ... >>> order_slicer = slicer(10,1,10,4) >>> order_slicer('__2345H30_NC_'.replace('_',' ')) ['2345', 'H', '30', 'NC'] HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Regexp parser and generator

2008-11-04 Thread George Sakkis
ator is infinite, and although it can be artificially constrained by, say, a maxdepth parameter, for now I'm interested in finite regexps only. It shouldn't be too hard to write one from scratch but just in case someone has already done it, so much the better. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-04 Thread George Sakkis
elf is copied while in Java (and Python) only the reference ("handler") is copied. By the way, passing a (copied) reference is *not* equivalent to call by reference: in the former case, the assignment of the reference to a different object has only a local effect, i.e. it is not reflected to the caller's frame, whine in call by ref it does. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Regexp parser and generator

2008-11-05 Thread George Sakkis
On Nov 4, 9:56 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Nov 4, 1:34 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > Is there any package that parses regular expressions and returns an > > AST ? Something like: > > > >&g

Re: Regexp parser and generator

2008-11-05 Thread George Sakkis
On Nov 4, 3:30 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > Is there any package that parses regular expressions and returns an > > AST ? Something like: > > >>>> parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') >

Re: using exec() to instantiate a new object.

2008-11-10 Thread George Sakkis
old data structures (e.g. [default]dicts and [named]tuples). George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 - is this true?

2008-11-10 Thread George Sakkis
would be no need to copy the sequence: def freeze(self): self.__class__ = frozenlist George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 - is this true?

2008-11-10 Thread George Sakkis
an error. Given that in SQL "NULL `op` something" is False for all comparison operators (even NULL=NULL), raising an error seems a much lesser evil George -- http://mail.python.org/mailman/listinfo/python-list

Re: First post, recursive references with pickle.

2008-11-10 Thread George Sakkis
the object you're trying to pickle until you find the problematic one(s) ? Something like: class MyClass(object): ... def __getstate__(self): del self.foo return self.__dict__ Then do the same to the class of self.foo, and so on recursively, until you find the real culprit. HT

Re: Python 3.0 - is this true?

2008-11-11 Thread George Sakkis
ject in Python. > > I'm not sure why this special case was dropped in Python 3.0. None > is generally used to be a place holder for a n/a-value and as > such will pop up in lists on a regular basis. > > I think the special case for None should be readded to Python 3.0. On p

Re: duck-type-checking?

2008-11-12 Thread George Sakkis
rue if the object responds to that > > method, False otherwise. > > Too hard. For methods, which are what define duck species, and any > attribute guaranteed to not be null, "assert ob.name" is equivalent to > "assert hasattr(ob, 'name')". As you just sh

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-12 Thread George Sakkis
general sense, e.g. for Java including both primitives and object references), i.e. there's the following approximate mapping in terminology: Python jargon Non-python jargon === object value (primitive or composite) value state (

Re: duck-type-checking?

2008-11-13 Thread George Sakkis
implications. To me this seems it combines the worst of both worlds: the explicitness of LBYL with the heuristic nature of duck typing.. might as well call it "doyoufeellucky typing". If you are going to Look Before You Leap, try to stick to isinstance/issubclass checks (especially in 2.6+ that they can be overriden) instead of crafting ad- hoc rules of what makes an object be X-like. George -- http://mail.python.org/mailman/listinfo/python-list

Re: using "private" parameters as static storage?

2008-11-13 Thread George Sakkis
is it possible that there could be any   > language feature Python doesn't have, which might be useful to anyone   > in any situation? Sure; true multithreading, macros, non-crippled lambda, optional static typing are some reasonable features people miss in Python. The topic of this thread just isn't one of them. George -- http://mail.python.org/mailman/listinfo/python-list

Re: duck-type-checking?

2008-11-13 Thread George Sakkis
Zope and Twisted had to come up with interfaces to manage their massive (for Python at least) complexity. George -- http://mail.python.org/mailman/listinfo/python-list

Re: duck-type-checking?

2008-11-14 Thread George Sakkis
gt; cases would not be this complex, of course, but would be closer to > >         assert(fits(foo, strlike)) > > But this is still pretty ugly.  Hmm.  Maybe I'd better wait for   > ABCs.  :) You might also be interested in the typecheck module whose syntax looks nicer, at least for the common cases: http://oakwinter.com/code/typecheck/dev/ George -- http://mail.python.org/mailman/listinfo/python-list

Re: object creation

2008-11-14 Thread George Sakkis
tantiate a new x object for > each iteration of the FOR loop What is box()? Pasting its definition would help. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-16 Thread George Sakkis
end(6) where `expr` would mean "evaluate the expression in the function body". Apart from the obvious usage for mutable objects, an added benefit would be to have default arguments that depend on previous arguments: def foo(x, y=`x*x`, z=`x+y`): return x+y+z as opposed to the more verbos

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-16 Thread George Sakkis
... > However I can see > far more justification for the behavior Python currently exhibits than > the semantic time-bomb you are proposing. I didn't propose replacing the current behavior (that would cause way too much breakage), only adding a new syntax which is now invalid, so one would have to specify it explicitly. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help in understanding a python code

2008-11-16 Thread George Sakkis
When quoting wikipedia became the new Godwin's law ?? :) George -- http://mail.python.org/mailman/listinfo/python-list

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-16 Thread George Sakkis
On Nov 16, 2:30 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Sun, Nov 16, 2008 at 11:02 AM, George Sakkis <[EMAIL PROTECTED]> wrote: > > On Nov 16, 8:28 am, Steve Holden <[EMAIL PROTECTED]> wrote: > > >> "Less obvious" is entirel

Re: Python and Its Libraries--Who's on First?

2008-11-17 Thread George Sakkis
On Nov 17, 12:25 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: > Is there some repository that says something like for Python 2.5 it works > with: > > Win OSes: W2K, XP, Vista > numpy vers y, matplotlib vers x. scipy z, etc. http://www.catb.org/~esr/faqs/smart-questions.html#writewell -- http://mai

Re: Python-URL! - weekly Python news and links (Nov 17)

2008-11-17 Thread George Sakkis
d a PhD in denotational semantics or ontology to use Python effectively. The current discussion on that thread may be interesting to language lawyers and philosophers but it's pretty much irrelevant in understanding how Python works. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread George Sakkis
e the language 10 years from now, > so why not change it now? You probably messed up with your time machine; "now" is 2008, not 1991 ;-) George -- http://mail.python.org/mailman/listinfo/python-list

Re: More elegant way to try running a function X times?

2008-11-19 Thread George Sakkis
t, just decorate it explicitly at runtime: def CheckIP(): ... n = int(raw_input('Give number of retries:')) CheckIP = retry(n)(CheckIP) HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: python vs smalltalk 80

2008-11-19 Thread George Sakkis
On Nov 19, 1:53 am, gavino <[EMAIL PROTECTED]> wrote: > python vs smalltalk 80 > > which is nicer? Dunno but there's an interesting talk about this: http://www.youtube.com/watch?v=oHg5SJYRHA0 -- http://mail.python.org/mailman/listinfo/python-list

Re: Optional parameter object re-used when instantiating multiple objects

2008-11-19 Thread George Sakkis
> > Traceback (most recent call last): >   File "", line 1, in > NameError: name 'd1' is not defined > >         Do you really want a "default" argument that changes value depending > upon actions performed in the /surrounding/ scope? Yes, the surrounding scope in this case is the global scope; changing or deleting globals has by definition global reach. Regardless, how common is this usage in real code ? I believe an order of magnitude less than the need for fresh mutable objects. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Using eval, or something like it...

2008-11-19 Thread George Sakkis
t; class Foo(): >   bar = 1 >   gum = 2 > > mylist = ['bar','gum'] > > a = Foo() > for each in mylist: >   a.eval(each) = 999 > > If so, what is the proper syntax/method for this. for each in mylist: setattr(a, each, 999) HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: help with comparison

2008-11-19 Thread George Sakkis
boolean option, pass action="store_true" to p.add_option(). The test then is reduced to "if zipfile" and the program is to be called by "myscript.py -c". Read the docs [1] for more details. HTH, George [1] http://docs.python.org/library/optparse.html#standard-option-actions -- http://mail.python.org/mailman/listinfo/python-list

Re: function parameter scope python 2.5.2

2008-11-20 Thread George Sakkis
s to explicitly create a copy of the object > > property befor passing it to recursive_func, but if it's used more than > > once inside various parts of the class that could get messy. > > > Any thoughts? Am I crazy and this is supposed to be the way python works? > > Of course, providing a shallow (or deep as necessary) copy makes it > work, I'm curious as to why the value passed as a parameter to a > function outside the class is passed a reference rather than a copy. Why should it be a copy by default ? In Python all copies have to be explicit. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3 __cmp__ semantic change?

2008-11-20 Thread George Sakkis
On Nov 20, 6:58 pm, [EMAIL PROTECTED] wrote: >     Johannes> Seems it was removed on purpose - I'm sure there was a good >     Johannes> reason for that, but may I ask why? > > Start here: > >     http://www.mail-archive.com/[EMAIL PROTECTED]/msg11474.html > > Also, a comment to this blog post sug

Re: Using eval, or something like it...

2008-11-20 Thread George Sakkis
#x27;attributes' to avoid confusion? > > Is this correct enough for me to avoid the aforementioned bug pile? No, a class can have attributes just like a instance can, and you can use setattr() to set an attribute for a class just like you do it for instances: class Foo(): bar = 1 gum =

Re: Need help converting text to csv format

2008-11-21 Thread George Sakkis
On Nov 21, 10:18 am, Chuck Connors <[EMAIL PROTECTED]> wrote: > Any help, pseudo code, or whatever push in the right direction would > be most appreciated.  I am a novice Python programmer but I do have a > good bit of PHP programming experience. I'm wondering if PHP experience precludes the abil

Re: Dynamic features used

2008-11-21 Thread George Sakkis
tion, provided that (1) it *is* still possible to write dynamic code if necessary and (2) the extra effort in writing and reading it is not off-putting (e.g. no C++ template metaprogramming atrocities) George -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help converting text to csv format

2008-11-21 Thread George Sakkis
On Nov 21, 11:05 am, Steve Holden <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > On Nov 21, 10:18 am, Chuck Connors <[EMAIL PROTECTED]> wrote: > > >> Any help, pseudo code, or whatever push in the right direction would > >> be most appreciated.  I a

Re: Need help converting text to csv format

2008-11-21 Thread George Sakkis
On Nov 21, 2:01 pm, Richard Riley <[EMAIL PROTECTED]> wrote: > George Sakkis <[EMAIL PROTECTED]> writes: > > On Nov 21, 11:05 am, Steve Holden <[EMAIL PROTECTED]> wrote: > >> George Sakkis wrote: > >> > On Nov 21, 10:18 am, Chuck Connors <[EMAIL

Re: initialization in argument definitions

2008-11-21 Thread George Sakkis
#append to the list generated before. > while num <= 10: > aList.append(num) > num +=1 > else: > return aList > > Why is this? Thanks, hope its not a stupid quesiton. Sigh.. no it's not stupid at all; actually it is (and will probably remain, unfortunately) the most FA

Re: matching exactly a 4 digit number in python

2008-11-21 Thread George Sakkis
.compile(r''' (?:\D|\b)# find a non-digit or word boundary.. (\d{4}) # .. followed by the 4 digits to be matched as group #1.. (?:\D|\b)# .. which are followed by non-digit or word boundary ''', re.VERBOSE) HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-21 Thread George Sakkis
, dynamically. > > Is this possible?  If so, how? Easily: derived_cls = type('Derived', (cls1, cls2, *rest_classes), {}) item = derived_cls(**itemArgs) You will probably want to cache the generated classes so that at most one class is created for each combination of mixins. HTH, George -- http://mail.python.org/mailman/listinfo/python-list

FW: Anyone read "Python Interview Questions: Python Certification Review"?

2009-03-04 Thread Grimes, George
coherent presentation. It sounds like the sort of thing to avoid. I'm just learning Python myself and I'll look elsewhere. George George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell "The major difference between a thing that might go wrong and a thing that cannot possi

Stopping SocketServer on Python 2.5

2009-03-10 Thread David George
Hi guys, I've been developing some code for a university project using Python. We've been working on an existing codebase, cleaning it up and removing dead wood. We decided to make some changes to internal message handling by using a SocketServer, which worked great when we were using 2.6, a

Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread David George
On 2009-03-11 04:36:29 +, "Mark Tolonen" said: "David George" wrote in message news:00150e67$0$27956$c3e8...@news.astraweb.com... Hi guys, I've been developing some code for a university project using Python. We've been working on an existing codebas

Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread David George
On 2009-03-11 19:02:26 +, Falcolas said: On Mar 11, 12:28 pm, David George wrote: On 2009-03-11 04:36:29 +, "Mark Tolonen" s aid: "David George" wrote in message news:00150e67$0$27956$c3e8...@news.astraweb.com... Hi guys, I've been developing s

Re: Stopping SocketServer on Python 2.5

2009-03-12 Thread David George
On 2009-03-12 08:03:06 +, "Mark Tolonen" said: "Falcolas" wrote in message news:1b6a95a4-5680-442e-8ad0-47aa9ea08...@w1g2000prk.googlegroups.com... On Mar 11, 1:11 pm, David George wrote: Again, problem here is the issue of being unable to kill the server whi

supervisor 3.0a6 and Python2.6

2009-03-17 Thread George Trojan
above behaviour? If not, what would be a reasonable alternative to supervisor? I know of upstart and daemontools. George -- http://mail.python.org/mailman/listinfo/python-list

Disable automatic interning

2009-03-18 Thread George Sakkis
27;x' is 'x'+'' True >>> 'x' is ''+'x' True >>> 'x' is 'x'*1 True >>> 'x' is str('x') True >>> 'x' is str('x')+str('') True >>> 'x' is str.__new__(str,'x') True George -- http://mail.python.org/mailman/listinfo/python-list

Re: How complex is complex?

2009-03-18 Thread George Sakkis
adable (took me 10 seconds to parse vs 1 for the former). - slower (makes a function call on every round). - broken (creates a new dict instead of modifying the original in place). Really, there's not much of a dilemma here. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Disable automatic interning

2009-03-18 Thread George Sakkis
On Mar 18, 2:13 pm, "R. David Murray" wrote: > George Sakkis wrote: > > Is there a way to turn off (either globally or explicitly per > > instance) the automatic interning optimization that happens for small > > integers and strings (and perhaps other types) ? I tr

Re: Disable automatic interning

2009-03-18 Thread George Sakkis
rtin mentioned, this is easy even without str.new(), simply by wrapping each url in an instance of a small Node class. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Disable automatic interning

2009-03-18 Thread George Sakkis
On Mar 18, 4:50 pm, "andrew cooke" wrote: > this is completely normal (i do exactly this all the time), BUT you should > use "==", not "is".   Typically, but not always; for example check out the identity map [1] pattern used in SQLAlchemy [2]. George [1

Re: Candidate for a new itertool

2009-03-18 Thread George Sakkis
if is_boundary(cur,next): yield group group = [] group.append(next) cur = next yield group George [1] http://code.activestate.com/recipes/521877/ -- http://mail.python.org/mailman/listinfo/python-list

Re: supervisor 3.0a6 and Python2.6

2009-03-19 Thread George Trojan
Raymond Cote wrote: George Trojan wrote: 1. Is supervisor still developed? I note that, although the information on the site is pretty old, there have been some respository checkins in Feb and March of this year: <http://lists.supervisord.org/pipermail/supervisor-checkins/> -r I

RE: make money!!!!

2009-03-31 Thread Grimes, George
April fools day is not until tomorrow. Your joke is a day early. George A. Grimes 972-995-0190 - Desk 214-205-0244 - Cell -Original Message- From: filmmaker [mailto:centrixfi...@gmail.com] Sent: Tuesday, March 31, 2009 3:47 PM To: python-list@python.org Subject: make money

Re: simple iterator question

2009-04-02 Thread George Sakkis
es/528936/ HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to extract from regex in if statement

2009-04-03 Thread George Sakkis
groups())), ... } If not, you can combine the handler definition with the mapping update by using a simple decorator factory such as the following (untested): def rxhandler(rx, mapping): rx = re.compile(rx) def deco(func): mapping[rx] = func return func return deco d = {} @rxhandler("^DATASET:\s*(.+) ", d) def handle_dataset(match): ... @rxhandler("^AUTHORS:\s*(.+) ", d) def handle_authors(match): ... HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: "Pythoner",Wish me luck!

2009-04-03 Thread George Sakkis
 The > > immediate result is that you'll see any errors and be able to fix them > > before they end up in your script. > > > Nick Ballardhttp://90daysofpython.blogspot.com > > thanks, i'll give it a try Or even better, install IPython [1], a python interpreter on steroids. It's the first 3rd party python package I install on every new system I work on; it's so powerful and versatile, it has almost displaced the regular linux shell for me. I highly recommend it. George [1] http://ipython.scipy.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: object knows which object called it?

2009-04-06 Thread George Sakkis
A in this way? > > Note that I'm looking for the calling object and NOT the calling > function. Read up on descriptors [1], it seems that's what you're looking for. HTH, George [1] http://users.rcn.com/python/download/Descriptor.htm -- http://mail.python.org/mailman/listinfo/python-list

Returning different types based on input parameters

2009-04-06 Thread George Sakkis
lt`, confidence) tuples, or it might be a justifiable cost ? Any other API extension approaches that are applicable to such situations ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning different types based on input parameters

2009-04-06 Thread George Sakkis
ppealing if `Result` happens to be a builtin (e.g. float or list). Technically you can subclass builtins but I think, in this case at least, the cure is worse than the disease. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning different types based on input parameters

2009-04-06 Thread George Sakkis
On Apr 6, 7:57 pm, "andrew cooke" wrote: > andrew cooke wrote: > > George Sakkis wrote: > >> That's more of a general API design question but I'd like to get an > >> idea if and how things are different in Python context. AFAIK it's > &g

Re: Returning different types based on input parameters

2009-04-08 Thread George Sakkis
On Apr 7, 3:18 pm, Adam Olsen wrote: > On Apr 6, 3:02 pm, George Sakkis wrote: > > > For example, it is common for a function f(x) to expect x to be simply > > iterable, without caring of its exact type. Is it ok though for f to > > return a list for some types/values

Re: Unsupported operand types in if/else list comprehension

2009-04-11 Thread George Sakkis
kits built for exactly this purpose instead of putting together an ad-hoc, informally-specified bug-ridden slow implementation of half of their feature set. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Unsupported operand types in if/else list comprehension

2009-04-11 Thread George Sakkis
On Apr 11, 4:26 pm, Mike H wrote: > George, > > I'd love to. Can you give me an idea of where to start looking? I've > gone through a couple of books, and Googled a ton of websites. Maybe > I'm just not using the right terms. My background is definitely not >

Re: absolute newbie: divide a list into sublists (nested lists?) of fixed length

2009-04-11 Thread George Sakkis
5675]) >>> # convert to a 4by3 array in place >>> s.shape = (4,3) >>> s array([[ 0.84971586, 0.05786009, 0.9645675 ], [ 0.84971586, 0.05786009, 0.9645675 ], [ 0.84971586, 0.05786009, 0.9645675 ], [ 0.84971586, 0.05786009, 0.9645675 ]]) HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: absolute newbie: divide a list into sublists (nested lists?) of fixed length

2009-04-11 Thread George Sakkis
On Apr 11, 6:05 pm, ergconce...@googlemail.com wrote: > On Apr 11, 11:18 pm, George Sakkis wrote: > > > > > The numpy import *is* important if you want to use numpy-specific > > features; there are many "tricks" you can do easily with numpy arrays > >

Re: Overriding methods per-object

2009-04-17 Thread George Sakkis
r the involved classes and don't care about Python 3.x (where old-style classes are gone), you may choose to downgrade GeneralTypeOfObject to old-style. George -- http://mail.python.org/mailman/listinfo/python-list

Re: The Python standard library and PEP8

2009-04-20 Thread George Sakkis
On Apr 19, 6:01 pm, "Martin P. Hellwig" > Besides, calling Python Object-Orientated is a bit of an insult :-). I > would say that Python is Ego-Orientated, it allows me to do what I want. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: ActiveState Komodo Edit?

2009-04-26 Thread George Sakkis
void tabs if you can. George -- http://mail.python.org/mailman/listinfo/python-list

call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
hi, I'm a Python beginner with a basic question. I'm writing a game where I have keyboard input handling defined in one class, and command execution defined in another class. The keyboard handler class contains a dictionary that maps a key to a command string (like 'h': 'left') and the command hand

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 9:01 am, Chris Rebert wrote: > On Tue, May 5, 2009 at 8:52 AM, George Oliver > wrote: > > I create instances of these classes in a list attached to a third, > > 'brain' class. > > You could exploit Python's dynamism by using the getattr() fu

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
On May 5, 11:59 am, Dave Angel wrote: > 1) forget about getattr() unless you have hundreds of methods in your > map. The real question is why you need two maps. What good is the > "command string" doing you? Why not just map the keyvalues directly > into function objects? Thanks for the repl

Re: call function of class instance with no assigned name?

2009-05-05 Thread George Oliver
Thanks for the suggestions so far. I've taken the advice to keep things simple so currently I'm just creating one instance of the commandHandler and assigning it a name with command = commandHandler (). This makes it easy to call it from any of the other handlers, and I think this will work for wha

Re: call function of class instance with no assigned name?

2009-05-06 Thread George Oliver
On May 6, 3:07 pm, Carl Banks wrote: > I'm going to guess that you want the keyboardHandler to call method of > commandHandler. There's no reason for commandHandler to be a handler > at all then: keyboardHandler is already handling it. Thanks Carl, you've got it right and your following exampl

Re: Self function

2009-05-09 Thread George Sakkis
you saw http://code.activestate.com/recipes/277940/ ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorating methods - where do my arguments go?

2009-05-09 Thread George Sakkis
, args >>> cls.meth <__main__.test_decorator object at 0x87663cc> >>> cls.meth2 >>> cls().meth2(1,2,3) Decorator2: (<__main__.cls object at 0x8766ecc>, 1, 2, 3) Method2:(1, 2, 3) The reason this works is that functions are already descriptors, so you don't have to explicitly define __get__() as you would for a new callable class (see Peter's example). HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: Nimrod programming language

2009-05-12 Thread George Sakkis
On May 12, 12:49 pm, Mensanator wrote: > On May 12, 8:27 am, rump...@web.de wrote: > > > > > > The language and library are missing arbitrary precision integer > > > > > arithmetic, using GMP or something like that. > > > > > True, but currently not a high priority for me. > > > > Too bad. That ma

Re: introspection question: get return type

2009-05-14 Thread George Sakkis
e() I tried it: >>> "Nohtyp".reverse() Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'reverse' This newfangled Nohtyp language is no good, I want my money back. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a Par construct to Python?

2009-05-18 Thread George Sakkis
e almost zero chances of adding syntax support for this. Besides, Guido and other py-devs are not particularly keen on threads as a parallelization mechanism. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping methods of built-in dict

2009-05-21 Thread George Sakkis
/instance, let alone all the special methods (e.g. __getattribute__ very rarely needs to be overridden). Do you have an actual use case or are you just playing around ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread George Sakkis
ts so that they sum up to 1. 2. Form the cumulative sequence S = [0, w0, w0+w1, w0+w1+w2, ..., sum (w)==1.0] 3. Call random.random() -> x 4. Find the bucket in S that x belongs to, i.e. the i so that s[i] <= x < s[i+1] (you can do this fast using the bisect module). 5. Return choice[i] 6.

Re: question about python statements

2008-05-12 Thread George Sakkis
ot access by __builtins__ or locals() > | (like ["assert","break","class",...]) > > You appear to want the keywords that begin statements.  Look at the keyword > list in the language reference and pick those you want.  Then build that > list into

Re: Is using range() in for loops really Pythonic?

2008-05-12 Thread George Sakkis
anywhere else. Saving time for the reader is a very important job of > the writer of code. If you push this logic too far, you should del every name immediately after the last statement it is used in the scope. I would generally find less readable some code spread with del every few l

Re: how to get information of a running prog in python

2008-05-12 Thread George Sakkis
se for most programs since they don't play music anyway. Your best bet is if the *specific* program you're interested in (e.g. audacious) exposes this information programmatically in some way. It's up to the developers of this application if and how they choose to do it. Even

Re: Some comparison operators gone in Python 3.0?

2008-05-13 Thread George Sakkis
gt;    (is greater than) > > <= (is less than or equals) > >> = (is greater than or equals) > > > Is it true? > > May I ask *where* did you read that crazy idea? My guess is that he heard about the TypeErrors to be raised when comparing values of different types and he mi

Re: I'm stuck in Python!

2008-05-13 Thread George Sakkis
On May 13, 9:46 am, Sanoski <[EMAIL PROTECTED]> wrote: > Any programming that helps you solve a problem is fun and > recreational. At least, that's how I look at it. I suppose it really > depends on why you're doing it, what your objective is, etc. But I'd > say, why not? You must be new here. It

<    7   8   9   10   11   12   13   14   15   16   >