Are the python built-in methods available to reference in a package somewhere?
Let me explain. In my early(ier) days of python I made a django model similar to this:
class MyModel(models.Model):
first_name = models.CharField(max_length=100, null=True, blank=True)
last_name = models.CharField(max_length=100, null=True, blank=True)
property = models.ForeignKey("Property")
I have since needed to add a property to it. This leaves me with this model:
class MyModel(models.Model):
first_name = models.CharField(max_length=100, null=True, blank=True)
last_name = models.CharField(max_length=100, null=True, blank=True)
property = models.ForeignKey("Property")
@property
def name(self):
return "{} {}".format(first_name, last_name)
So now at runtime I get the error: TypeError: 'ForeignKey' object is not callable
. This is happening because the ForeignKey for property has replaced the built-in identifier property. What I would like to be able to do is, instead of @property
use @sys.property
(or something similar).
Note: I already know about the workaround of moving the name property above the declaration of the property field. I am not so concerned about this particular case as I am the main question of alternative locations for referencing the python built-ins.
Use builtins
, or __builtin__
if you're on Python 2.
def open():
pass
import __builtin__
print open
print __builtin__.open
This gives you:
<function open at 0x011E8670>
<built-in function open>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With