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
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
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
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
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
I have found a way around my problem.
-Tennessee
--
http://mail.python.org/mailman/listinfo/python-list
/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
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
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
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
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
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
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
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
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
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!
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
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
> 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
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
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'
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__['_
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()
>>>
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
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
"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
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
> 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] ==
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
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):
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
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
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):
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
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
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)
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
> > >
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
"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._
; > 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
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
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
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"
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
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
> 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
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
> 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
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
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
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
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
[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
"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
"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
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
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)
"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
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
"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
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://
"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
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
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
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
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
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
, 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
68 matches
Mail list logo