built-in-types

How to override the hash function for integers in python?

How to override the hash function for integers in python? Question: I’d like to know if there is a way to override the hash function that are already defined for builtin types like int. In python the hash of an int gives his own value and i’d like to avoid that in my project. The …

Total answers: 1

how can I use builtin function in my python divisor code?

how can I use builtin function in my python divisor code? Question: I’m getting error on the line with (if counter > max_count:). It says not supported between instances of ‘int’ and ‘builtin_function_or_method’. I can’t underestand what is the problem! def divisors(num): counter=1 for i in range(1,num): x = num%i if x==0: counter+=1 return counter …

Total answers: 1

How can I extend a built-in type in cython?

How can I extend a built-in type in cython? Question: I’m trying to extend the basic float in python with cython additional methods. I have a python implementation and I know I could create my own extended type by keeping an internal float value. But I’m trying to keep the same code base for interpreted …

Total answers: 1

Can I add custom methods/attributes to built-in Python types?

Can I add custom methods/attributes to built-in Python types? Question: For example—say I want to add a helloWorld() method to Python’s dict type. Can I do this? JavaScript has a prototype object that behaves this way. Maybe it’s bad design and I should subclass the dict object, but then it only works on the subclasses …

Total answers: 8

What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)?

What is the difference between isinstance('aaa', basestring) and isinstance('aaa', str)? Question: a=’aaaa’ print isinstance(a, basestring)#true print isinstance(a, str)#true Asked By: zjm1126 || Source Answers: All strings are basestrings, but unicode strings are not of type str. Try this instead: >>> a=u’aaaa’ >>> print isinstance(a, basestring) True >>> print isinstance(a, str) False Answered By: Mark Byers …

Total answers: 4