Hi all,<br><br>Have a question which is making me unrest:<br><br>-Calling
a method say aMethod() from another method where i mistakenly
initialised a variable with name same as the called method like aMethod
= 'string'. When i run this py script triggered "Unbound Local error".
<br>can any  one explain me whats going here ? curios to learn from my mistake :)<br clear="all"><br>-- <br>Warm Regards,<br><span class="sg"><br>Hari<br></span><br><br><div><span class="gmail_quote">On 6/27/07, <b class="gmail_sendername">
<a href="mailto:python-list-request@python.org">python-list-request@python.org</a></b> <<a href="mailto:python-list-request@python.org">python-list-request@python.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Send Python-list mailing list submissions to<br>        <a href="mailto:python-list@python.org">python-list@python.org</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit<br>        <a href="http://mail.python.org/mailman/listinfo/python-list">
http://mail.python.org/mailman/listinfo/python-list</a><br>or, via email, send a message with subject or body 'help' to<br>        <a href="mailto:python-list-request@python.org">python-list-request@python.org</a>
<br><br>You can reach the person managing the list at<br>        <a href="mailto:python-list-owner@python.org">python-list-owner@python.org</a><br><br>When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Python-list digest..."<br><br>Today's Topics:<br><br>   1. Re: Collections of non-arbitrary objects ? (Bruno Desthuilliers)<br>   2. Re: Return name of caller function? (Matthew Peter)<br>
   3. Re: ANN: PyDAO - Python Hibernate-like Object-Relational<br>      Mapper (Luis M. Gonz?lez)<br>   4. Re: Zip File Woes (Dave Kuhlman)<br>   5. Re: Too many 'self' in python.That's a big flaw in this<br>      language. (Bruno Desthuilliers)
<br>   6. listing the type of an object (Stef Mientki)<br>   7. Re: equality & comparison by default (was Re: Too many 'self'<br>      in        python.That's a big flaw in this language.) (Aahz)<br>   8. Re: listing the type of an object (Thomas Jollans)
<br>   9. Re: Too many 'self' in python.That's a big flaw in this<br>      language. (John Nagle)<br>  10. log caller (Matthew Peter)<br><br><br>---------- Forwarded message ----------<br>From: Bruno Desthuilliers <
<a href="mailto:bdesth.quelquechose@free.quelquepart.fr">bdesth.quelquechose@free.quelquepart.fr</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Thu, 28 Jun 2007 06:36:25 +0200<br>
Subject: Re: Collections of non-arbitrary objects ?<br>walterbyrd a écrit :<br>> On Jun 26, 8:23 am, Bruno Desthuilliers <bruno.<br>> <a href="mailto:42.desthuilli...@wtf.websiteburo.oops.com">42.desthuilli...@wtf.websiteburo.oops.com
</a>> wrote:<br>><br>>>walterbyrda écrit :<br>>><br>>><br>>>>>You do program carefully, don't you ?-)<br>>><br>>>>I try. But things like typos are a normal part a life.
<br>>><br>>>So are they in any language. I fail to see much difference here.<br>>><br>><br>><br>> For example: if I mis-type a variable name in C, the program will<br>> probably not even compile.
<br><br>It sometimes happens - but chances are low, for sure.<br><br>> Whereas, with Python, the program will<br>> probably run, but may give unexpected results.<br>><br>Yes, true. Well, in some cases. In one case, to be true: the use of the
<br>'=' operator. IIRC, any other use of an undefined symbol will raise an<br>exception. But this has to do with how symbols are defined in Python<br>(ie: the fact that binding => definition), and has nothing to do with
<br>static (compile-time) type checking.<br><br>><br>>>>Guido<br>>>>must think python has a lot of room for improvement since he's<br>>>>completely throwing out backward compatibility with python 3000.
<br>>><br>>>Not "completely throwing out". Just allowing *some* major breakages -<br>>>the kind you usually get with each major release of other languages, but<br>>>that Python managed to avoid as much as possible so far.
<br>><br>><br>> I don't know, but here is a direct quote from Guido's blog: "Python<br>> 3.0 will break backwards compatibility. Totally."<br>><br>> <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208549">
http://www.artima.com/weblogs/viewpost.jsp?thread=208549</a><br><br>Please take it with a grain of the salt. This is mostly about getting<br>rid of long-time deprecated features.<br><br>><br>>>>It seems to me that tuple are essentially immutable lists.
<br>>><br>>>They are not (even if you can use them that way too). FWIW and IIRC,<br>>>this is a FAQ.<br>><br>> A few posters here have stated that tuples are not just immutable but<br>> when I compare lists, to tuples, I notice that both are ordered
<br>> collections of arbitrary objects, with the primary difference being<br>> that list are mutable, and tuples are not.<br><br>This is of course technically true. And you forgot to compare to sets,<br>while we're at it. But the answer to your questions about tuples is not
<br>technical - it's about use case.<br><br>> It seems to me that if a<br>> list were immutable, it would be a tuple. That is the one big<br>> difference.<br> ><br>> Tuples have been compared to records/structures in other languages.
<br>> But, in general, I can not use a for loop to loop through the fields<br>> in a record,<br><br>For which definition of "in general" ? I can do this with at least<br>Python, PHP, Javascript, Ruby, and probably Java (IIRC).
<br><br>> and I can not sort those fields either.<br><br>Did you try to sort a tuple ?<br><br> >>> (1, "aaa").sort()<br>Traceback (most recent call last):<br>   File "<stdin>", line 1, in ?
<br>AttributeError: 'tuple' object has no attribute 'sort'<br><br><br><br><br><br><br><br>---------- Forwarded message ----------<br>From: Matthew Peter <<a href="mailto:survivedsushi@yahoo.com">survivedsushi@yahoo.com
</a>><br>To: Jay Loden <<a href="mailto:python@jayloden.com">python@jayloden.com</a>><br>Date: Wed, 27 Jun 2007 13:44:57 -0700 (PDT)<br>Subject: Re: Return name of caller function?<br><br>--- Jay Loden <<a href="mailto:python@jayloden.com">
python@jayloden.com</a>> wrote:<br><br>><br>> Matthew Peter wrote:<br>> > For example, how do I get this to work?<br>> ><br>> > def func():<br>> >     print "This is", __?__<br>> >     return __caller__
<br>> ><br>> > def echo():<br>> >     print "This is ", __?__<br>> >     return func()<br>> ><br>> ><br>> >>>> print echo()<br>> > This is echo<br>> > This is func
<br>> > echo<br>><br>> This may not be what you're looking for but here's the solution I ended up with<br>> after some help from the list. It's designed for getting the name of an instance<br>> method, but in case it applies to your particular situation:
<br>><br>> #!/usr/bin/python<br>><br>> import functools<br>><br>> class TestClass:<br>>   def __init__(self):<br>>     pass<br>><br>>   def __getattr__(self, name):<br>>     try:<br>>       return getattr(self.__class__, name)
<br>>     except AttributeError:<br>>       return functools.partial(self.foo, name)<br>><br>>   def foo(self, name, **args):<br>>     print "This is", name<br>><br>> test = TestClass()<br>> 
test.someMethod()<br>> test.anotherMethod()<br>><br>> Otherwise the inspect module may be the way to go, as Stephen already pointed out<br>> (though I must admit it seems a very inelegant route, especially compared to
<br>> Python's usually clean and clear style).<br>><br>> -Jay<br>><br><br><br>Thanks for the reply.<br><br>The goal is to get it working outside of a class. Overloading the method with<br>getattr semi-works but it doesn't work in the larger context of what I am trying to
<br>accomplish.<br><br>You could avoid the exception block in your example:<br><br><br>>   def __getattr__(self, name):<br>>     try:<br>>       return getattr(self.__class__, name)<br>>     except AttributeError:
<br>>       return functools.partial(self.foo, name)<br><br>to:<br><br>   def __getattr__(self, name, *args, **kw):<br>       return getattr(self.__class__, name, functools.partial(self.foo, name, *args,<br>**kw))<br><br>
   def foo(self, name, *args, **kw):<br>     print "This is", name, args, kw<br><br><br>print test.squeaky("I need oil")<br><br><br><br><br><br><br>____________________________________________________________________________________
<br>Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.<br><a href="http://farechase.yahoo.com/">http://farechase.yahoo.com/</a><br><br><br><br>---------- Forwarded message ----------<br>From: Luis M. González <
<a href="mailto:luismgz@gmail.com">luismgz@gmail.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Wed, 27 Jun 2007 20:43:55 -0000<br>Subject: Re: ANN: PyDAO - Python Hibernate-like Object-Relational Mapper
<br>On Jun 27, 4:08 pm, <a href="mailto:cieslak.dari...@gmail.com">cieslak.dari...@gmail.com</a> wrote:<br>> PyDAO is very thin object-relational mapper similar to Hibernate (but<br>> much simpler). It's created to speed-up application development. It's
<br>> very simple, but powerful, based on POPO (Plain Old Python Objects).<br>><br>>  <a href="http://aplikacja.info/PyDAO.html">http://aplikacja.info/PyDAO.html</a><br>><br>> Main features:<br>><br>>  - can use any database that has DB-API interface (MySQLdb, psycopg
<br>>    tested)<br>>  - can work without database at all (useful for early phases of<br>>    development)<br>>  - speeds up unit testing (dedicated in memory database)<br>><br>> What is not handled:<br>
><br>>  - automatic scheme generation<br>>  - separate query language<br>>  - automated handling of associations (replaced by filtering by<br>>    foreign keys)<br>><br>> Here's an example how to use PyDAO:
<br>><br>>     class User:<br>>         def __init__(self):<br>>             <a href="http://self.id">self.id</a> = None<br>>             self.login = None<br>>             self.password = None<br>><br>
>     dao = pydao.InMemoryDao()<br>><br>>     # filling database<br>>     user = User()<br>>     user.login = "user1"<br>>     user.password = "roh8OoPh"<br>>     dao.save(user)<br>
><br>>     # filtering based on example<br>>     userSearch = User()<br>>     userSearch.login = "user1"<br>>     userList = dao.list(userSearch)<br>><br>>     # updating<br>>     user.password
 = "eew8Me8g"<br>>     dao.update(user)<br>><br>> Enjoy!<br>><br>> --<br>> Dariusz Cieslakhttp://aplikacja.info- custom software systems<br><br><br>Interesting, but The link to AbstractDaoTest.py
 gives me an error<br>message...<br><br><br><br><br>---------- Forwarded message ----------<br>From: Dave Kuhlman <<a href="mailto:dkuhlman@rexx.com">dkuhlman@rexx.com</a>><br>To: <a href="mailto:python-list@python.org">
python-list@python.org</a><br>Date: Wed, 27 Jun 2007 20:56:17 GMT<br>Subject: Re: Zip File Woes<br>Jerry Hill wrote:<br><br>> On 6/27/07, Robert Rawlins - Think Blue<br>> <<a href="mailto:robert.rawlins@thinkbluemedia.co.uk">
robert.rawlins@thinkbluemedia.co.uk</a>> wrote:<br>>>               zip = zipfile.ZipFile('Media/Media.zip', 'r')<br>><br>> Shouldn't you open this file in binary mode?  It shouldn't make
<br>> any difference on unix machines, but will possibly break under<br>> windows. That may also explain why it works properly in one<br>> environment, and not in another.<br>><br><br>It wouldn't hurt, but ...
<br><br>Actually, it is the underlying file that should be opened in<br>binary mode.<br><br>I just looked at the source for the zipfile module.  It throws<br>away the 'b' if the mode contains a 'b'.<br><br>
If you pass it a file name, zipfile always opens the underlying<br>file in binary mode.  If you pass in a file, then it is your<br>responsibility to open that file in binary mode.<br><br>Dave<br><br>--<br><a href="http://www.rexx.com/~dkuhlman">
http://www.rexx.com/~dkuhlman</a><br><br><br><br>---------- Forwarded message ----------<br>From: Bruno Desthuilliers <<a href="mailto:bdesth.quelquechose@free.quelquepart.fr">bdesth.quelquechose@free.quelquepart.fr</a>
><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Thu, 28 Jun 2007 07:00:23 +0200<br>Subject: Re: Too many 'self' in python.That's a big flaw in this language.<br>Jorgen Bodde a écrit :
<br>> I had the same feeling when I started, coming from a C++ background, I<br>> forgot about self a lot, creating local copies of what should be an<br>> assign to a class instance, or methods that could not be found because
<br>> I forgot 'self' .<br>><br>> Now I am 'kinda' used to it, as every language has some draw backs<br>> (you can't please all). But, what about something in between like only<br>> using the dot (.) for a shorter notation?
<br>><br>> self.some_var = True<br>><br>> Could become:<br>><br>> .some_var = True<br>><br>> Which basically shows about the same thing, but you leave 'self' out<br>> of the syntax. Ofcourse it should not be allowed to break a line
<br>> between the dot and the keywords, else Python would never know what to<br>> do;<br>><br>> my_class()<br>> .my_var = True<br>><br>> Should not be parsed the same as;<br>><br>> my_class().my_var = True
<br>><br>> Just a suggestion. I am pretty happy with self, but I could settle for<br>> a shorter version if possible.<br>><br>What is nice with the required, explicit reference to the instance -<br>which BTW and so far is not required to be *named* 'self' - is that it
<br>avoids the need for distinct rules (and different implementations) for<br>functions and methods. The different 'method' types are just very thin<br>wrappers around function objects. Which in turn allow to use 'ordinary'
<br>functions (defined outside a class) as methods - IOW, to dynamically<br>extend classes (and instances) with plain functions. Uniformity can also<br>have very practical virtues...<br><br><br><br>---------- Forwarded message ----------
<br>From: Stef Mientki <<a href="mailto:S.Mientki-nospam@mailbox.kun.nl">S.Mientki-nospam@mailbox.kun.nl</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Wed, 27 Jun 2007 23:12:26 +0200
<br>Subject: listing the type of an object<br>How can I list a type of an object instance ?<br><br>I tried:<br><br>class tLED (tDevice):<br>   def some_proc(self):<br>     print 'type(self)', type(self)<br><br>But i gives me:
<br>   type(self) <type 'instance'><br><br>Moreover, I want even the type to be listed by it's ancestor, like this<br><br>class tDevice:<br>   def some_other_proc:<br>     print 'type(self)', type(self)
<br><br>thanks,<br>Stef Mientki<br><br><br><br><br>---------- Forwarded message ----------<br>From: <a href="mailto:aahz@pythoncraft.com">aahz@pythoncraft.com</a> (Aahz)<br>To: <a href="mailto:python-list@python.org">python-list@python.org
</a><br>Date: 27 Jun 2007 14:13:50 -0700<br>Subject: Re: equality & comparison by default (was Re: Too many 'self' in python.That's a big flaw in this language.)<br>In article <<a href="mailto:1i0cy8z.z94q5d1dxgexxN%aleax@mac.com">
1i0cy8z.z94q5d1dxgexxN%aleax@mac.com</a>>,<br>Alex Martelli <<a href="mailto:aleax@mac.com">aleax@mac.com</a>> wrote:<br>><br>>In Python 3000, ordering comparisons will not exist by default (sigh, a<br>>modest loss of practicality on the altar of purity -- ah well, saw it
<br>>coming, ever since complex numbers lost ordering comparisons), but<br>>equality and hashing should remain just like now (yay!).<br><br>While emotionally I agree with you, in practice I have come to agree<br>with the POV that allowing default ordering comparisons between disjoint
<br>types causes subtle bugs that are more difficult to fix than the small<br>amount of boilerplate needed to force comparisons when desired.<br>--<br>Aahz (<a href="mailto:aahz@pythoncraft.com">aahz@pythoncraft.com</a>)           <*>         
<a href="http://www.pythoncraft.com/">http://www.pythoncraft.com/</a><br><br>"as long as we like the same operating system, things are cool." --piranha<br><br><br><br>---------- Forwarded message ----------<br>From: Thomas Jollans <
<a href="mailto:thomas@jollans.com">thomas@jollans.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Wed, 27 Jun 2007 23:21:34 +0200<br>Subject: Re: listing the type of an object
<br>Stef Mientki wrote:<br>> How can I list a type of an object instance ?<br>><br>> I tried:<br>><br>> class tLED (tDevice):<br>>   def some_proc(self):<br>>     print 'type(self)', type(self)
<br>><br>> But i gives me:<br>>   type(self) <type 'instance'><br>><br>> Moreover, I want even the type to be listed by it's ancestor, like this<br>><br>> class tDevice:<br>>   def some_other_proc:
<br>>     print 'type(self)', type(self)<br>><br><br>Ahhh, history. At the moment (that is in  2.2 <= Python Version < 3.0 ),<br>there are two types of classes: old-style classes are the default and a<br>
load of WTF?, which new-style classes make sense and behave like you<br>(that is "one" in general and you, Stef, in particular) expect.<br><br>As I'm too lazy to explain what all this is about, I'll point you to a
<br>page with a promising title:<br><br><a href="http://wiki.python.org/moin/NewClassVsClassicClass">http://wiki.python.org/moin/NewClassVsClassicClass</a><br><br>Thomas Jollans<br><br><br><br>---------- Forwarded message ----------
<br>From: John Nagle <<a href="mailto:nagle@animats.com">nagle@animats.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Wed, 27 Jun 2007 14:54:36 -0700<br>Subject: Re: Too many 'self' in 
python.That's a big flaw in this language.<br>Bruno Desthuilliers wrote:<br>> Jorgen Bodde a écrit :<br>><br>>> But, what about something in between like only<br>>> using the dot (.) for a shorter notation?
<br><br>     How about "Mavis Beacon Teaches Typing"?<br><br>                                John Nagle<br><br><br><br>---------- Forwarded message ----------<br>From: Matthew Peter <<a href="mailto:survivedsushi@yahoo.com">
survivedsushi@yahoo.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Wed, 27 Jun 2007 14:42:45 -0700 (PDT)<br>Subject: log caller<br>Is it possible to print the function calls to a module? Like:
<br><br>test.py<br>import mymod<br>print mymod.x()<br><br><br>mymod.py<br># each time a function is called we print out the called function and module<br>print 'Func call: %s from %s' % (???, ???)<br><br>def x():<br>
     return 'hello'<br><br>Where would I pick up the ??? variables? A brief example would be nice too :) Thanks<br>in advance!<br><br><br><br>____________________________________________________________________________________
<br>The fish are biting.<br>Get more visitors on your site using Yahoo! Search Marketing.<br><a href="http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php">http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php
</a><br><br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br><br></blockquote></div><br><br clear="all"><br>-- <br>Warm Regards,<br><br>Hari
<br>617.770.1159