the 'right way' to distribute and access data files in a packaged Python module
Hi, I'm the author of netaddr :- http://pypi.python.org/pypi/netaddr/0.6 For release 0.6 I've added setuptools support so it can be distributed as a Python egg package using the easy_install tool. In 0.6, I've started bundling some data files from IEEE and IANA with the code below the site-packages install path (lib/site-packages/ netaddr/...). netaddr accesses and parses these files on module load to provide various IP and MAC address related information via its API. This mechanism works for the setuptools based packages because on install they extract to the filesystem and can be accessed using something like :- >>> index = open(os.path.join(__file__, 'oui.idx')) However, setuptools seems to perform some magic for module imports which prevents me from accessing these files directly as they are bundled inside an egg (zip) file :-( Two questions arise out of this situation :- 1) is there a better way to distribute the files, i.e. should I be using a different more correct path instead of site-packages for data? If so, where is this and how do I add it to my setup scripts and code? 2) is there an easy (and portable) way for me to dive inside an egg file to access the data I required (ugly but workable). I'm assuming I'd need to check for the presence of setuptools available with the Python interpreter etc. My users and I would be grateful for and help and advice. Many thanks, Dave M. -- http://mail.python.org/mailman/listinfo/python-list
Re: the 'right way' to distribute and access data files in a packaged Python module
> There is a zip-safe flag that you can specify that tells setuptools that > installing your egg only works if it is unarchived. However, there is also > the pkg_resources-package that allows you to access streams from within a > package, even if it is zipped. You should investigate these two options. > > Diez Exactly what I was looking for. Thanks Diez! -- http://mail.python.org/mailman/listinfo/python-list
property() usage - is this as good as it gets?
Hi,
I want to manage and control access to several important attributes in
a class and override the behaviour of some of them in various
subclasses.
Below is a stripped version of how I've implemented this in my current
bit of work.
It works well enough, but I can't help feeling there a cleaner more
readable way of doing this (with less duplication, etc).
Is this as good as it gets or can this be refined and improved
especially if I was to add in a couple more attributes some fairly
complex over-ride logic?
#!/usr/bin/env python
class A(object):
def __init__(self):
self._x = None
self._y = None
def _set_x(self, value):
self._x = value
def _get_x(self):
return self._x
x = property(_get_x, _set_x)
def _set_y(self, value):
self._y = value
def _get_y(self):
return self._y
y = property(_get_y, _set_y)
class B(A):
def __init__(self):
self._z = None
super(B, self).__init__()
def _set_x(self, x):
# An example subclass 'set' override.
if x == 10:
raise Exception('%r is invalid!' % x)
self._x = x
x = property(A._get_x, _set_x)
def _set_z(self, value):
self._z = value
def _get_z(self):
return self._z
z = property(_get_z, _set_z)
del A._get_x, A._set_x, A._get_y, A._set_y
del B._set_x, B._get_z, B._set_z
--
http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
Venerable Pythonistas, Looks like a pretty unanimous vote in favour of custom descriptor usage rather than the more generic property() BIF for my purposes. This is going to tidy and firm up my library code very nicely ;-) Thanks very much for your responses. Your assistance is greatly appreciated! P.S. How did my post manage to ignite a mini flame war?! -- http://mail.python.org/mailman/listinfo/python-list
A service for testing Python code on multiple platforms and versions
Hopefully a service like this already exists and I just haven't found it yet. If not it could be an idea for some kind soul(s) to pick up and run with ;-) As someone who writes and releases Python modules for the community, I find it difficult to have a decent level of confidence in the efficacy of my code on platforms and Python versions other than those that I own or use regularly. My documentation states that I support Python 2.3 or higher. This ends up being more of a statement of good intentions than a one of fact. A case in point. A bug (in Python), that I believed to have been killed off after Python 2.2, resurfaced in a 2.4.x release of Python on PowerPC recently. As I don't own any PowerPC kit, it was very difficult to a) investigate the bug and b) create an effective fix for it in a timely fashion. Fortunately I'd come across it before so the fix was easy but it might not have been. While I realise one's code can never be perfect, you can cover for these sorts of eventualities fairly easily by running your software and unit tests under different environments. You'd also like to be able to do this on a continual basis rather than just once or twice. If this was done with some kind of automated testing and reporting so much the better. Bigger projects that take code quality seriously probably already have this sort of thing in place for their own purposes, but for smaller ones it just isn't possible. Wouldn't it be great to have a service/setup out there available for Python developers to access that covered a fairly broad base of possible Python installations for the purpose of improve overall code quality? Am I the only one that would find something like this useful? Dave M. -- http://mail.python.org/mailman/listinfo/python-list
