Re: How to decide if a object is instancemethod?

2012-03-26 Thread Jean-Michel Pichavant
Jon Clements wrote: On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: class Foo(object): def bar(self): return 'Something' func = Foo().bar if type(func) == : # This should be always true pass # do something here What should type at ? Thanks Cosmia impor

Re: How to decide if a object is instancemethod?

2012-03-14 Thread Steven D'Aprano
On Thu, 15 Mar 2012 08:26:22 +1100, Ben Finney wrote: > Jon Clements writes: > >> import inspect >> if inspect.ismethod(foo): >># ... >> >> Will return True if foo is a bound method. > > But under what other conditions will it return True? The name suggests > that *any* method – static meth

Re: How to decide if a object is instancemethod?

2012-03-14 Thread Ben Finney
Jon Clements writes: > import inspect > if inspect.ismethod(foo): ># ... > > Will return True if foo is a bound method. But under what other conditions will it return True? The name suggests that *any* method – static method, class method, bound method, unbound method – will also result in T

Re: How to decide if a object is instancemethod?

2012-03-14 Thread Jon Clements
On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > class Foo(object): > def bar(self): > return 'Something' > > func = Foo().bar > > if type(func) == : # This should be always true > pass # do something here > > What should type at ? > > Thanks > Cosmia import insp

How to decide if a object is instancemethod?

2012-03-14 Thread Cosmia Luna
class Foo(object): def bar(self): return 'Something' func = Foo().bar if type(func) == : # This should be always true pass # do something here What should type at ? Thanks Cosmia -- http://mail.python.org/mailman/listinfo/python-list

Re: Question regarding multiprocessing and error: Can't pickle : attribute lookup __builtin__.instancemethod failed

2009-10-13 Thread Tennessee
I have found a way around my problem. -Tennessee -- http://mail.python.org/mailman/listinfo/python-list

Question regarding multiprocessing and error: Can't pickle : attribute lookup __builtin__.instancemethod failed

2009-10-13 Thread tleeuwenb...@gmail.com
/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/work/tjl/apps/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed The c

Re: mapping a string to an instancemethod

2008-08-01 Thread [EMAIL PROTECTED]
On Aug 1, 11:22 am, [EMAIL PROTECTED] wrote: > The following bit of code will allow an instance member to > be called by reference. How can I map a string (e.g. > "hello1" or "Foo.hello1" to a the instance member? > > class Foo: > def hello1(self, p): > print 'hello1', p > def hell

Re: mapping a string to an instancemethod

2008-08-01 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > The following bit of code will allow an instance member to > be called by reference. How can I map a string (e.g. > "hello1" or "Foo.hello1" to a the instance member? > > class Foo: > def hello1(self, p): > print 'hello1', p

mapping a string to an instancemethod

2008-08-01 Thread mh
The following bit of code will allow an instance member to be called by reference. How can I map a string (e.g. "hello1" or "Foo.hello1" to a the instance member? class Foo: def hello1(self, p): print 'hello1', p def hello2(self, p): print 'hello2', p def dispatch(self

Re: pickle error: can't pickle instancemethod objects

2008-05-23 Thread Michele Simionato
On May 23, 10:12 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Michele Simionato wrote: > > Can somebody explain what's happening with the following script? > >     def __gestate__(self): # should skip the bound methods attributes > > Must be __getstate__ ;) > > Peter Aaargh!!! I spent a couple of

Re: pickle error: can't pickle instancemethod objects

2008-05-23 Thread Peter Otten
Michele Simionato wrote: > Can somebody explain what's happening with the following script? > def __gestate__(self): # should skip the bound methods attributes Must be __getstate__ ;) Peter -- http://mail.python.org/mailman/listinfo/python-list

pickle error: can't pickle instancemethod objects

2008-05-23 Thread Michele Simionato
r/lib/python2.5/pickle.py", line 306, in save rv = reduce(self.proto) File "/usr/lib/python2.5/copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle instancemethod objects I know that inst

pickle error/instancemethod

2007-09-04 Thread Gregor Kling
Hello, I have some of these nefarious pickle errors I do not understand, maybe some of you have a clue. This is what I get (nd is the object which I want to pickle [cPickle.dumps(nd,2)], with the printout of nd.__dict__): ERROR Error: Can't pickle : attribute lookup __builtin__.instancem

Re: adding a docstring to an instancemethod

2007-07-27 Thread Steven D'Aprano
On Fri, 27 Jul 2007 06:24:48 -0300, Gabriel Genellina wrote: > En Thu, 26 Jul 2007 14:48:12 -0300, jelle <[EMAIL PROTECTED]> > escribió: > >> Hi Gabriella, >> thanks for pointing me in the right direction: > > Twice in a week... I'll have to revise my own masculinity... You need to spit and f

Re: adding a docstring to an instancemethod

2007-07-27 Thread Neil Cerutti
On 2007-07-27, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Thu, 26 Jul 2007 14:48:12 -0300, jelle <[EMAIL PROTECTED]> > escribió: > >> Hi Gabriella, >> thanks for pointing me in the right direction: > > Twice in a week... I'll have to revise my own masculinity... The trumpet shall sound!

Re: adding a docstring to an instancemethod

2007-07-27 Thread Gabriel Genellina
En Thu, 26 Jul 2007 14:48:12 -0300, jelle <[EMAIL PROTECTED]> escribió: > Hi Gabriella, > thanks for pointing me in the right direction: Twice in a week... I'll have to revise my own masculinity... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a docstring to an instancemethod

2007-07-26 Thread jelle
Hi Gabriella, thanks for pointing me in the right direction: eo.eoTruncatedSelectOne.setup.im_func.func_doc = 'method string goes here' works beautifully! cheers, -jelle -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a docstring to an instancemethod

2007-07-26 Thread jelle
> Set the __doc__ on the *function* from which you build the instance method. Thanks for you reply Gabriel, Though setting the docstring to the functions wouldn't be an option for me. The thing is that I have a wrappedCppModule.Class.Method I'd like to give a docstring, so there's no prior funct

Re: adding a docstring to an instancemethod

2007-07-25 Thread Gabriel Genellina
En Wed, 25 Jul 2007 08:05:37 -0300, jelle <[EMAIL PROTECTED]> escribió: > I'm working on documenting wrapped C++ methods. > The thing is that I'd like to add docstrings to a method, but python > won't allow me to: > TypeError: attribute '__doc__' of

adding a docstring to an instancemethod

2007-07-25 Thread jelle
Hi, I'm working on documenting wrapped C++ methods. The thing is that I'd like to add docstrings to a method, but python won't allow me to: TypeError: attribute '__doc__' of 'instancemethod' objects is not writable What would be an easy way to do so? I'

Re: instancemethod

2007-01-26 Thread Michele Simionato
On Jan 27, 6:39 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > > It seems that the description of __new__ is wrong. Since __new__ takes an > implicit first argument, the class, it is a class method, not a static > method. No: >>> class C(object): ...def __new__(cls): pass >>> C.__dict__['_

Re: instancemethod

2007-01-26 Thread Steven D'Aprano
On Sat, 27 Jan 2007 01:03:50 -0300, Gabriel Genellina wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> escribió en el > mensaje > news:[EMAIL PROTECTED] > >> On Fri, 26 Jan 2007 17:25:37 +0100, Bruno Desthuilliers wrote: def __del__(self): try: self.close() >>>

Re: instancemethod

2007-01-26 Thread Steven D'Aprano
On Fri, 26 Jan 2007 20:27:29 -0800, Michele Simionato wrote: > On Jan 22, 2:58 am, "Gert Cuykens" <[EMAIL PROTECTED]> wrote: > >> http://www.faqts.com/knowledge_base/view.phtml/aid/16824 > > There is a factual mistake on that reference. The last sentence > >> One final note: the single most com

Re: instancemethod

2007-01-26 Thread Michele Simionato
On Jan 22, 2:58 am, "Gert Cuykens" <[EMAIL PROTECTED]> wrote: > http://www.faqts.com/knowledge_base/view.phtml/aid/16824 There is a factual mistake on that reference. The last sentence > One final note: the single most common use for classmethod is probably > in overriding __new__(). It is alway

Re: instancemethod

2007-01-26 Thread Gabriel Genellina
"Steven D'Aprano" <[EMAIL PROTECTED]> escribió en el mensaje news:[EMAIL PROTECTED] > On Fri, 26 Jan 2007 17:25:37 +0100, Bruno Desthuilliers wrote: >>>def __del__(self): >>>try: >>>self.close() >>>finally: >>>pass >>>except: >>>pas

Re: instancemethod

2007-01-26 Thread Steven D'Aprano
On Fri, 26 Jan 2007 17:25:37 +0100, Bruno Desthuilliers wrote: >>def __del__(self): >>try: >>self.close() >>finally: >>pass >>except: >>pass > > The finally clause is useless here. In principle, closing a file could raise an except

Re: instancemethod

2007-01-26 Thread Gert Cuykens
> class Obj(object): >pass > > toto = tutu = tata = titi = Obj() > > What's an "instance name" ? > > -- > http://mail.python.org/mailman/listinfo/python-list i would say __object__.__name__[3] == toto And if your obj is a argument like something(Obj()) i would say __object__.__name__[0] ==

Re: instancemethod

2007-01-26 Thread Bruno Desthuilliers
Gert Cuykens a écrit : > import MySQLdb > > class Db(object): > >def __enter__(self): >pass > >def __init__(self,server,user,password,database): >self._db=MySQLdb.connect(server , user , password , database) >self._db.autocommit(True) >self.cursor=self._db

Re: instancemethod

2007-01-23 Thread Gert Cuykens
import MySQLdb class Db(object): def __enter__(self): pass def __init__(self,server,user,password,database): self._db=MySQLdb.connect(server , user , password , database) self._db.autocommit(True) self.cursor=self._db.cursor() def execute(self,cmd):

Re: instancemethod

2007-01-23 Thread Bruno Desthuilliers
Gert Cuykens a écrit : > Reading all of the above this is the most simple i can come too. > > import MySQLdb > > class Db: > >def __init__(self,server,user,password,database): >self._db=MySQLdb.connect(server , user , password , database) >self._db.autocommit(True) >s

Re: instancemethod

2007-01-22 Thread Gert Cuykens
Reading all of the above this is the most simple i can come too. import MySQLdb class Db: def __init__(self,server,user,password,database): self._db=MySQLdb.connect(server , user , password , database) self._db.autocommit(True) self.cursor=self._db.cursor() def e

Re: instancemethod

2007-01-22 Thread Bruno Desthuilliers
Gert Cuykens a écrit : > import MySQLdb > > class Db: (snip) >def excecute(self,cmd): >self._cursor.execute(cmd) >self._db.commit() > What about autocommit and automagic delegation ? import MySQLdb class Db(object): def __init__(self,server, user, password, database):

Re: instancemethod

2007-01-22 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Gert Cuykens wrote: >> > >gert.excecute('select * from person') >> > >for x in range(0,gert.rowcount): >> > >print gert.fetchone() >> > >gert.close() >> > > > […] > > python always seems to amaze me how other languages make a mess of > things that suppo

Re: instancemethod

2007-01-21 Thread Gert Cuykens
never mind i think i need some sleep lol i did the exact opposite this time .rowcount() -> .rowcount -- http://mail.python.org/mailman/listinfo/python-list

Re: instancemethod

2007-01-21 Thread Gert Cuykens
import MySQLdb class Db: _db=-1 _cursor=-1 rowcount=-1 def __init__(self,server,user,password,database): self._db=MySQLdb.connect(server , user , password , database) self._cursor=self._db.cursor() def excecute(self,cmd): self._cursor.execute(cmd)

Re: instancemethod

2007-01-21 Thread Gert Cuykens
On 1/22/07, Gert Cuykens <[EMAIL PROTECTED]> wrote: > On 1/22/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > "Gert Cuykens" <[EMAIL PROTECTED]> escribió en el mensaje > > news:[EMAIL PROTECTED] > > > > > class Db: > > > > > >_db=-1 > > >_cursor=-1 > > > > > >@classmethod > > >

Re: instancemethod

2007-01-21 Thread Gert Cuykens
On 1/22/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > "Gert Cuykens" <[EMAIL PROTECTED]> escribió en el mensaje > news:[EMAIL PROTECTED] > > > class Db: > > > >_db=-1 > >_cursor=-1 > > > >@classmethod > >def __init__(self,server,user,password,database): > >self._db=MySQ

Re: instancemethod

2007-01-21 Thread Gabriel Genellina
"Gert Cuykens" <[EMAIL PROTECTED]> escribió en el mensaje news:[EMAIL PROTECTED] > class Db: > >_db=-1 >_cursor=-1 > >@classmethod >def __init__(self,server,user,password,database): >self._db=MySQLdb.connect(server , user , password , database) >self._cursor=self._

Re: instancemethod

2007-01-21 Thread Gert Cuykens
; > for x in range(0,gert.rowcount): > > print gert.fetchone() > > gert.close() > > > > [EMAIL PROTECTED]:~$ python ./Desktop/svn/db/Py/db.py > > Traceback (most recent call last): > > File "./Desktop/svn/db/Py/db.py", line 3

Re: instancemethod

2007-01-21 Thread Nanjundi
gt; > [EMAIL PROTECTED]:~$ python ./Desktop/svn/db/Py/db.py > Traceback (most recent call last): > File "./Desktop/svn/db/Py/db.py", line 35, in > for x in range(0,gert.rowcount): > TypeError: range() integer end argument expected, got instancemethod. > [EM

instancemethod

2007-01-21 Thread Gert Cuykens
op/svn/db/Py/db.py Traceback (most recent call last): File "./Desktop/svn/db/Py/db.py", line 35, in for x in range(0,gert.rowcount): TypeError: range() integer end argument expected, got instancemethod. [EMAIL PROTECTED]:~$ Can anybody explain what i must do in order to get integ

Re: pickle and instancemethod objects

2006-09-13 Thread Steven Bethard
Martin v. Löwis wrote: > Steven Bethard schrieb: >> Does this approach seem sound? Am I going to run into some weird >> problems doing it this way? > > It's good, but I think rebuilding the object through > new.instancemethod should be even better. > > py> class A: > ... def f(self):print "A"

Re: pickle and instancemethod objects

2006-09-13 Thread Martin v. Löwis
Steven Bethard schrieb: > Does this approach seem sound? Am I going to run into some weird > problems doing it this way? It's good, but I think rebuilding the object through new.instancemethod should be even better. py> class A: ... def f(self):print "A" ... py> class B(A): ... def f(self):p

pickle and instancemethod objects

2006-09-13 Thread Steven Bethard
I'd like to be able to pickle instancemethod objects mainly because I want to be able to delay a call like ``foo(spam, badger)`` by dumping ``foo``, ``spam`` and ``badger`` to disk and loading them again later. Sometimes the callable ``foo`` is actually a bound method, e.g. ``bar.baz``, b

Re: can't pickle instancemethod objects

2006-07-09 Thread Jim Lewis
> Here's a thought: comment out every attribute in your class, and then try > pickling it. If it succeeds, uncomment just *one* attribute, and try > pickling again. Repeat until pickling fails. Was trying to avoid that but you motivated me to do so and now I found the probem. In a utility routine

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
On Sun, 09 Jul 2006 08:39:29 -0700, Jim Lewis wrote: >> I'd suggest that "pop" could be your culprit. ...What is pop? A function or >> an instance method? > > Neither. pop is an instance of a class, like: > class X: >... > pop = X () > > pop surely is the culprit but it has arrays of object

Re: can't pickle instancemethod objects

2006-07-09 Thread Jim Lewis
> I'd suggest that "pop" could be your culprit. ...What is pop? A function or > an instance method? Neither. pop is an instance of a class, like: class X: ... pop = X () pop surely is the culprit but it has arrays of objects, etc., and I don't know what to look for. -- http://mail.python.or

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
On Sun, 09 Jul 2006 07:06:25 -0700, Jim Lewis wrote: >> How about you post the complete stack trace of the exception? > > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\program files\python\lib\lib-tk\Tkinter.py", line 1345, in > __call__ > return self.func(*a

Re: can't pickle instancemethod objects

2006-07-09 Thread Jim Lewis
e_dict self._batch_setitems(obj.iteritems()) File "C:\program files\python\lib\pickle.py", line 677, in _batch_setitems save(v) File "C:\program files\python\lib\pickle.py", line 313, in save rv = reduce(self.proto) File "C:\program files\python\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle instancemethod objects -- http://mail.python.org/mailman/listinfo/python-list

Re: can't pickle instancemethod objects

2006-07-09 Thread Steven D'Aprano
On Sun, 09 Jul 2006 05:45:27 -0700, Jim Lewis wrote: > Pickling an instance of a class, gives "can't pickle instancemethod > objects". What does this mean? It means you can't pickle instance methods. > How do I find the class method creating the problem? How abou

can't pickle instancemethod objects

2006-07-09 Thread Jim Lewis
Pickling an instance of a class, gives "can't pickle instancemethod objects". What does this mean? How do I find the class method creating the problem? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is there no instancemethod builtin?

2005-06-20 Thread Raymond Hettinger
[George Sakkis] > The fact that strings don't have __iter__ is an implementation > detail. I can't think of any reason other than historic and perhaps > backwards compatibility for this; > iterables should IMHO by definition be exactly > the objects with __iter__). There would be no benefit other

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
"John Roth" wrote: > Unfortunately it doesn't work: getitem can be defined for > a class that acts like a dictionary: that is, the items are > not integers, let alone integers that extend in a strict > sequence from 0. This is true, but that's the current behaviour of iterators for classes that d

Re: Why is there no instancemethod builtin?

2005-06-19 Thread John Roth
"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Michele Simionato wrote: >> I think strings do not have __iter__ on purpose, exactly to distinguish >> them from other iterables, since sometimes it is nice to consider them >> atomic, but I am not sure of this. You shou

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
Michele Simionato wrote: > I think strings do not have __iter__ on purpose, exactly to distinguish > them from other iterables, since sometimes it is nice to consider them > atomic, but I am not sure of this. You should ask the developers. Anyway, the > right definition of iterable is (as I was tol

Re: Why is there no instancemethod builtin?

2005-06-19 Thread Michele Simionato
I think strings do not have __iter__ on purpose, exactly to distinguish them from other iterables, since sometimes it is nice to consider them atomic, but I am not sure of this. You should ask the developers. Anyway, the right definition of iterable is (as I was told) "an object X such that iter(X)

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
"Michele Simionato" wrote: > In this case I have used hasattr(obj, "__iter__") instead of > isinstance(obj, list) > (strings are iterable but do not have __iter__ method). I think hasattr > is much better > since it works for tuples and custom iterables too. The fact that strings don't have __ite

Re: Why is there no instancemethod builtin?

2005-06-19 Thread Michele Simionato
In this case I have used hasattr(obj, "__iter__") instead of isinstance(obj, list) (strings are iterable but do not have __iter__ method). I think hasattr is much better since it works for tuples and custom iterables too. Michele Simionato -- http://mail.python.org/mailman/listinfo/pyt

See Pep 294. was: Re: Why is there no instancemethod builtin?

2005-06-19 Thread John Roth
"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > John Roth wrote: > >> you need _both_ isinstance and the types module to do a correct >> check for any string type: isinstance(fubar, types.StringTypes). >> That's because both string and unicode are subtypes of one

Re: Why is there no instancemethod builtin?

2005-06-19 Thread Michael Hoffman
John Roth wrote: > you need _both_ isinstance and the types module to do a correct > check for any string type: isinstance(fubar, types.StringTypes). > That's because both string and unicode are subtypes of one base. But basestring, their base class is a built-in. -- Michael Hoffman -- http://

Re: Why is there no instancemethod builtin?

2005-06-18 Thread George Sakkis
"Steven Bethard" wrote: > John Reese wrote: > > I now do: > > > > if isinstance(x, list): > > > > It is my understanding that this is what people do nowadays. > > I wouldn't go that far. I don't have an isinstance check for lists > anywhere in my entire codebase. Why do you think you need to c

Re: Why is there no instancemethod builtin?

2005-06-18 Thread John Roth
l, buffer, complex, dict, file, float, list, long, > object, slice, str, tuple, type, unicode, xrange, NoneType, > NotImplementedType > > And the following are not: > > dictproxy, ellipsis, frame, function, instancemethod, module, > traceback, instancemethod, NoneType

Re: Why is there no instancemethod builtin?

2005-06-17 Thread Steven Bethard
John Reese wrote: > I now do: > if isinstance(x, list): [snip] > > I'm not saying I do it a lot, but sometimes it's useful to write > methods with interfaces like, well, isinstance's, whose second argument > can be a single type object or a sequence of class objects. Personally, I'd just write t

Re: Why is there no instancemethod builtin?

2005-06-17 Thread John Reese
On Fri, 17 Jun 2005 16:40:56 -0600, <[EMAIL PROTECTED]> wrote: > John Reese wrote: >> I now do: >> >> if isinstance(x, list): >> >> It is my understanding that this is what people do nowadays. > > I wouldn't go that far. I don't have an isinstance check for lists > anywhere in my entire cod

Re: Why is there no instancemethod builtin?

2005-06-17 Thread Steven Bethard
John Reese wrote: > I now do: > > if isinstance(x, list): > > It is my understanding that this is what people do nowadays. I wouldn't go that far. I don't have an isinstance check for lists anywhere in my entire codebase. Why do you think you need to check to see if something is of type

Re: Why is there no instancemethod builtin?

2005-06-17 Thread John Machin
John Reese wrote: > Why hello there ha ha. [snip] Just looking through the types declared in types, the > following are builtins: > [snip] > ... NoneType, > NotImplementedType > > And the following are not: > [snip] > ... NoneType, NotImplementedType > > So for any in the latter batch, I have

Why is there no instancemethod builtin?

2005-06-17 Thread John Reese
, tuple, type, unicode, xrange, NoneType, NotImplementedType And the following are not: dictproxy, ellipsis, frame, function, instancemethod, module, traceback, instancemethod, NoneType, NotImplementedType So for any in the latter batch, I have to import types after all. I assume the