Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'attribute': 0.07; 'class,': 0.07; 'suppose': 0.07; '8bit%:30': 0.09; 'arguments': 0.09; 'caller': 0.09; 'main()': 0.09; 'obj': 0.09; 'skip:# 60': 0.09; '*function*': 0.16; 'arg2,': 0.16; 'attribute,': 0.16; 'finney': 0.16; 'func': 0.16; 'function;': 0.16; 'name)': 0.16; 'skip:[ 30': 0.16; 'subject:usage': 0.16; 'typeerror:': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'wed,': 0.18; 'all,': 0.19; 'example': 0.22; 'now?': 0.24; 'question': 0.24; 'shown': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:p 30': 0.29; "doesn't": 0.30; 'code': 0.31; '+0100,': 0.31; 'writes:': 0.31; 'file': 0.32; 'url:python': 0.33; '(most': 0.33; 'sense': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'object,': 0.36; 'skip:" 50': 0.36; 'yours,': 0.36; 'possible': 0.36; 'url:org': 0.36; 'thank': 0.38; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'recent': 0.39; 'help,': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'is.': 0.60; 'free': 0.61; 'name': 0.63; 'such': 0.63; 'choose': 0.64; 'dear': 0.65; '8bit%:24': 0.84; 'you...': 0.96 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pahlevanzadeh.org; s=default; h=Content-Transfer-Encoding:Mime-Version:Content-Type:References:In-Reply-To:Date:To:From:Subject:Message-ID; bh=OCpSQKw6i9+TMXswwlEJuU1ah15wivKBwOrGQDyhgQQ=; b=VPkL0iMjFpcJ/GPuiKfGrGm9TfUrG49j1hy3L92V1lcQOwEZCc7ejq6xN3m27fILyT8/ZeRiWO9uCPMSqSHtpFAvhCfhVqe+Uv8j+CDPUxGW7Z20ZxMy0Sj7UM6K1vb6lTsEIupO+rP2PCYU5OlQIBNbawxazLImE1DdG+3Xvl8=; Subject: Re: functools and objective usage From: Mohsen Pahlevanzadeh To: python-list@python.org Date: Wed, 23 Oct 2013 20:18:47 +0330 In-Reply-To: <5267109D.5040803@mrabarnett.plus.com> References: <1382478989.4873.6.camel@debian> <7w8uxleyya.fsf@benfinney.id.au> <5267109D.5040803@mrabarnett.plus.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.8.5-2+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - part7.royal-servers.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pahlevanzadeh.org X-Get-Message-Sender-Via: part7.royal-servers.com: authenticated_id: mohsen@pahlevanzadeh.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 77 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382550929 news.xs4all.nl 15920 [2001:888:2000:d::a6]:43193 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57375 Dear all, I have the following code in each steps of loop: #################################################### obj = partial(self.myinstance.myfunc) obj.func = self.myinstance.myfunc obj.arg = ["TWCH",self,key,val.checkState(),val] obj.keywords = self.myinstance ######################################################## But i get the following traceback: ############################################ Traceback (most recent call last): File "./main.py", line 117, in main() File "./main.py", line 104, in main x.showFindProjects() File "/home/mohsen/codes/amlak/amlak/src/UIInterface.py", line 101, in showFindProjects self.uiProjectsFind.setupUi(self.projectsFind) File "/home/mohsen/codes/amlak/amlak/src/projectsFind.py", line 288, in setupUi obj.func = self.myinstance.myfunc TypeError: readonly attribute ############################################################### Before any help, Thank you... Yours, Mohsen On Wed, 2013-10-23 at 00:56 +0100, MRAB wrote: > On 22/10/2013 23:13, Ben Finney wrote: > > Mohsen Pahlevanzadeh writes: > > > >> Suppose i have function name, 3 arguments for it, and object of its > >> caller such as self.blahbalah > > > > This doesn't make much sense to me. I think you mean: You have an > > object, ‘self.blahblah’, which has a function attribute, ‘name’. > > > Perhaps the OP means that 'name' is a variable which is bound to the > name of the function/method, which is an attribute of self.blahbalah. > > > (Aside: Please choose better example names, these make it rather > > difficult to talk about.) > > > >> So: > >> my function is: > >> self.blahblah.name(arg1,arg2,arg3) > > > > Your *function* is ‘self.blahblah.name’. > > > > One possible way to express a *call* that function is > > ‘self.blahblah.name(arg1, arg2, arg3)’. > > > If 'name' is bound to the name, then: > > func = getattr(self.blahblah, name) > func(arg1, arg2, arg3) > > or just: > > getattr(self.blahblah, name)(arg1, arg2, arg3) > > >> I read functools documentations, may be objictive usage and > >> functionality differ, Do you have experience with objective usage ? > >> http://docs.python.org/2/library/functools.html#partial-objects > > > > I don't understand what the question is. You have shown a way to call > > your function; what do you want to do now? > > > >> I need to use it in my class, > > > > Feel free :-) > > >