Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python @Property vs direct access
# -*- coding: utf-8 -*-
from timeit import timeit
setup = """\
class Test(object):
def __init__(self, something):
self._something = something
def something(self):
return self._something
test_obj = Test('dupa')
without_accessor = timeit('a = test_obj._something', setup)
print 'Without accessor: ' + str(without_accessor)
with_accessor = timeit('a = test_obj.something', setup)
print 'With accessor: ' + str(with_accessor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.