Arguments and a return value of a C function call when using setprofile

2010-03-15 Thread Michal Kwiatkowski
Hi, I'm trying to write code that will trace arguments and return values of all function calls. Using sys.settrace with 'call' and 'return' events works great for Python functions, but now I want to extend that to C functions as well. Using sys.setprofile instead in theory gives me what I need ('c

Re: Distinguishing active generators from exhausted ones

2009-07-27 Thread Michal Kwiatkowski
On Jul 27, 10:47 pm, Terry Reedy wrote: > There are two possible definition of 'exhausted': 1) will raise > StopIteration on the next next() call; 2) has raised StopIteration at > least once. The wrapper converts 2) to 1), which is to say, it obeys > definition 1 once the underlying iteration has

Re: Distinguishing active generators from exhausted ones

2009-07-27 Thread Michal Kwiatkowski
On Jul 27, 1:56 am, a...@pythoncraft.com (Aahz) wrote: > >> Upon a cursory look, after a generator 'gen' is exhausted (meaning > >> gen.next() has raised StopIteration), it seems that gen.gi_frame will be > >> None. > > >Only in Python 2.5 or higher though. I need to support Python 2.3 and > >2.4 a

Re: Distinguishing active generators from exhausted ones

2009-07-26 Thread Michal Kwiatkowski
On Jul 26, 1:10 am, Ben Finney wrote: > Michal Kwiatkowski writes: > > I may be missing something obvious here. Is there a better way to tell > > if a given generator object is still active or not? > >     foo = the_generator_object >     try: >         do_interestin

Re: Distinguishing active generators from exhausted ones

2009-07-25 Thread Michal Kwiatkowski
On Jul 25, 10:00 pm, Jason Tackaberry wrote: > On Sat, 2009-07-25 at 11:30 -0700, Michal Kwiatkowski wrote: > > Is there a way to tell if a generator has been exhausted using pure > > Python code? I've looked at CPython sources and it seems that > > Upon a cursory look,

Distinguishing active generators from exhausted ones

2009-07-25 Thread Michal Kwiatkowski
Hi, Is there a way to tell if a generator has been exhausted using pure Python code? I've looked at CPython sources and it seems that something like "active"/"exhausted" attribute on genobject is missing from the API. For the time being I am using a simple C extension to look at f_stacktop pointer

Python AST preserving whitespace and comments

2008-08-27 Thread Michal Kwiatkowski
Hi, I'm working on Pythoscope[1], a unit test generator for Python and stumbled into the following problem. I need a way to analyze and modify Python AST tree, but without loosing source code formatting and comments. Standard library ast module discards those, so I started looking for other soluti

sys.settrace 'call' event behavior

2008-06-21 Thread Michal Kwiatkowski
I'm building a tool to trace all function calls using sys.settrace function from the standard library. One of the awkward behaviors of this facility is that the class definitions are reported as 'call' events.[1] Since I don't want to catch class definitions, only function calls, I'm looking for a

Re: list of lists of lists ....

2006-07-28 Thread Michal Kwiatkowski
faulkner wrote: > ok, so, recursion is just functional programming sugar for a loop. And a loop is a procedural programming sugar for tail recursion. 8-) Cheers, mk -- . o . >> http://joker.linuxstuff.pl << . . o It's easier to get forgiveness for being wrong o o o than forgivenes

Re: calling upper() on a string, not working?

2006-05-16 Thread Michal Kwiatkowski
John Salerno wrote: > def encrypt_quote(original): > original_letters = filter_letters(original) You call filter_letters() which makes upper() on all letters, so original_letters contain only uppercase letters. > new_letters = list(string.ascii_uppercase) > while True: > r

Performance of Python 2.3 and 2.4

2006-04-22 Thread Michal Kwiatkowski
Hi! I was just wondering... Python 2.3.5 (#2, Mar 6 2006, 10:12:24) [GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> a = timeit.Timer('2**1') >>> b = timeit.Timer('112233445566778899

Re: My Generator Paradox!

2006-03-16 Thread Michal Kwiatkowski
vbgunz wrote: > def generatorFunction(sequence=['item1', 'item2', 'item3']): > for item in sequence: > yield item > > yieldedValue = generatorFunction() You're creating an iterator here and binding it to name yieldedValue (which is bogus, it should be named valueGenerator or sth like

Re: Why property works only for objects?

2006-03-12 Thread Michal Kwiatkowski
Alex Martelli napisał(a): >> IMHO that's not very consistent. > > How so? Given the lower-level semantics of descriptors (and the > distinction between overriding and non), are you suggesting that > property should not be a type but a factory function able to return > instances of either overridi

Re: Why property works only for objects?

2006-03-12 Thread Michal Kwiatkowski
Alex Martelli napisał(a): >> Can you also check my reasoning for getting attributes? >> >> value = obj.attr >> * if instance class has __getattribute__, call it >> * else: lookup "attr" in all parent classes using class __mro__; >> if it's a descriptor call its __get__ method, return its va

Re: Why property works only for objects?

2006-03-11 Thread Michal Kwiatkowski
Alex Martelli napisał(a): >> It still bugs me. What's the actual procedure when doing attribute >> assignment? I understand it like this: >> >> obj.attr = value >> * if instance class has __setattr__, call it >>* else: if class has an attribute with name "attr" check if it's a >> descript

Re: Why property works only for objects?

2006-03-11 Thread Michal Kwiatkowski
Shalabh Chaturvedi napisał(a): > Here is a step-by-step description of what happens when you set or get > an attribute on an object: > > http://cafepy.com/article/python_attributes_and_methods/ch01s05.html This description doesn't take __getattr__/__getattribute__/__setattr__ in count. mk -- .

Re: Why property works only for objects?

2006-03-11 Thread Michal Kwiatkowski
Alex Martelli napisał(a): obj.__dict__ > {} > > ...the presence of '__dict__' as an entry in C is confusing the issue, > because that's what you get in this case as obj.__dict__. It still bugs me. What's the actual procedure when doing attribute assignment? I understand it like this: obj.at

Re: Why property works only for objects?

2006-03-11 Thread Michal Kwiatkowski
Alex Martelli napisał(a): > First, let's forget legacy-style classes, existing only for backwards > compatibility, and focus on new-style ones exclusively -- never use > legacy classes if you can avoid that. Ok, let's cover only new-style classes in our discussion. I've read your comments and am

Re: Why property works only for objects?

2006-03-10 Thread Michal Kwiatkowski
Bruno Desthuilliers napisał(a): >> Let me understand it clearly. If I change __class__ of an object, >> existing attributes (so methods as well) of an object are still >> accessible the same way and don't change its values. Only resolution of >> attributes/methods not found in object is changed, as

Re: Why python doesn't use syntax like function(,,x) for default parameters?

2006-03-10 Thread Michal Kwiatkowski
Dmitry Anikin napisał(a): > Some example (from real life). > def ChooseItems(StartDate, EndDate, Filter): > #function returns a set of some items in chronological order > #from required interval possibly using filter > > ChooseItems() #get everything > ChooseItems('01.01.2000', ,SomeFilter) #get e

Re: Why property works only for objects?

2006-03-10 Thread Michal Kwiatkowski
Alex Martelli napisał(a): >> So another question arise. Is it possible to make function a method (so >> it will receive calling object as first argument)? > > Sure, impor types then call types.MethodType: > > f = types.MethodType(f, obj, someclass) > > (f.__get__ is also fine for Python-coded fu

Re: Why property works only for objects?

2006-03-10 Thread Michal Kwiatkowski
Alex Martelli napisał(a): > Wrong! Of _course_ it's an option -- why do you think it matters at all > whether you're the creator of this object?! Statically typed languages background. Sorry. ;) >> Code below doesn't work, but shows my >> intention: >> >> # obj is instance of BaseClass >> def ge

Re: Why property works only for objects?

2006-03-09 Thread Michal Kwiatkowski
Steven Bethard napisał(a): >> Is there any method of making descriptors on per-object basis? > > I'm still not convinced that you actually want to, but you can write > your own descriptor to dispatch to the instance object (instead of the > type): Ok, this works for attributes I know a name of at

Why property works only for objects?

2006-03-09 Thread Michal Kwiatkowski
Hi, Code below shows that property() works only if you use it within a class. class A(object): pass a = A() a.y = 7 def method_get(self): return self.y a.x = property(method_get) print a.x # => A.x = property(method_get) print a.x # =>

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Michal Kwiatkowski wrote: > def init_arguments(fun): > def new_f(self): > var_one = self.attr_one > var_two = self.attr_two.another_attr > empty_list = [] > > fun(self, var_one, var_two, empty_list) > > return new_f > >

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Alex Martelli wrote: > But of course, then the method's body would have to use _.one rather > than var_one, _.two rather than var_two, and _.empty_list rather than > empty_list (what a strange name -- does it STAY empty throughout the > method's execution?!). To me this looks like a small price to

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Alex Martelli wrote: > Michal Kwiatkowski <[EMAIL PROTECTED]> wrote: >... >> def method(self): >> var_one = self.attr_one >> var_two = self.attr_two.another_attr >> empty_list = [] >> # significant code goes here >... > Pe

Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Hi! I'm building a class that most of methods have similar intro, something like this: def method(self): var_one = self.attr_one var_two = self.attr_two.another_attr empty_list = [] # significant code goes here # ... It's done for clarity reasons, aliasing most used variabl