473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

distutils - distributing non-python data files

I really appreciate the ease that the distutils make distributing
Python modules. However, I have a question about using them to
distribute non-Python (i.e. text) data files that support Python
modules. Currently when I have data of this type, I parse it into
python objects and make a python module from it. In other words, given
a data file like

% cat grocery_list.txt
eggs
spam
cheese

I would make a data structure like
grocery_list = ['eggs', 'spam', 'cheese']
which can be easily imported from a python file, and which the
distutils installation programs make it easy for me to find on the
Python path.

Of course, the data I'm using is much more complex than this, but you
get the idea. I'm starting to feel like this is a Bad Thing, because if
the data file is distributed as a plain text file (e.g. data values in
columns), I'm putting a barrier to updating the data if I have to parse
a new file into Python. But I don't know whether there is a better way
to include a file like 'grocery_list.txt' in my python
distutils-distributed module so that I can get it from my other python
modules?

Oct 25 '05 #1
2 2645
On Oct 25, RickMuller wrote:
I really appreciate the ease that the distutils make distributing
Python modules. However, I have a question about using them to
distribute non-Python (i.e. text) data files that support Python
modules.
It's not clear from your questions whether this is user-configuration
data for your program, or just data files that your program generates.

If the latter, you might look into pickle'ing. Often the best place
to look for examples is in your Python distribution itself. My
cursory scan didn't show much this time, but the Ft module might be
worthy of note. It installs a Share directory
(.../site-packages/Ft/Share) that contains some XML files.
Currently when I have data of this type, I parse it into
python objects and make a python module from it.
Sometimes this is a reasonable approach, and you might get away with
just storing it as Python code with no conversion. Mailman (and one
of my projects) uses config files that are actually treated as Python
modules. For configuration data Python is such a readable language
that even users unfamiliar with it can often safely edit a config
file.
In other words,
given a data file like

% cat grocery_list.txt
eggs
spam
cheese

I would make a data structure like
grocery_list = ['eggs', 'spam', 'cheese']
which can be easily imported from a python file, and which the
distutils installation programs make it easy for me to find on the
Python path.

Of course, the data I'm using is much more complex than this, but
you get the idea.
Then you might consider going to an XML format, and let
SAX/DOM/whatever do the work for you. Or maybe use the Configuration
Parser <http://www.python.org/doc/2.4.2/lib/module-ConfigParser.html>,
depending on your needs.
I'm starting to feel like this is a Bad Thing, because if the data
file is distributed as a plain text file (e.g. data values in
columns), I'm putting a barrier to updating the data if I have to
parse a new file into Python.
Text, binary, columnar, XML... whatever the format, if it changes you
will always be susceptible to changing your parser.
But I don't know whether there is a better way to include a file
like 'grocery_list.txt' in my python distutils-distributed module so
that I can get it from my other python modules?


If it's configuration data not stored within your distribution, you
could have some places to auto-check, e.g.: $HOME/somerc.py,
/etc. And/or you could support an environment variable.

--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
Oct 26 '05 #2
On 25 Oct 2005 10:35:53 -0700, RickMuller <rp******@gmail.com> wrote:
I really appreciate the ease that the distutils make distributing
Python modules. However, I have a question about using them to
distribute non-Python (i.e. text) data files that support Python
modules.


I think you forgot to explain why you cannot simply use distutil's
data_files parameter. Do you have trouble finding the file at runtime?

http://docs.python.org/dist/node12.html

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Harrison | last post by:
afternoon pythonic gurus, quick question about distutils. Im compiling on solaris 9 and am having problems with the linking (I loathe solaris these days ;-), and if I call gcc by hand and...
2
by: Skip Montanaro | last post by:
I would like to override the distutils install class. It doesn't look like it was designed for that. Do I have to import distutils.command and overwrite its install attribute? I didn't see...
0
by: William Trenker | last post by:
I believe I recently read that distutils is in the process of being enhanced. Is that correct? Does anyone know if their is an "uninstall" command in the works for distutils? Thanks, Bill
1
by: Rick Muller | last post by:
Is there a simple way of toggling the -DNDEBUG flag in the distutils builds? I just realized that all of my assert statements were being skipped because by default the distutils put in -DNDEBUG. ...
1
by: Jens Thiede | last post by:
Pardon the silly question, but can one use distutils to install somewhere other than site-packages, or is distutils only ment for this kind of a job. I'd like to use it to make the distribution of...
0
by: Andrew Wilkinson | last post by:
Hi, I've have some example scripts that I'd like to install under /usr/share along with my documentation. Currently I'm doing this using... data_files= ....in my setup.py. This doesn't treat...
0
by: Jorge Godoy | last post by:
Hi! For the following setup.py, I get this error: byte-compiling /var/tmp/bhsys-buildroot/usr/lib/python2.3/site-packages/bhsys/Impressao.py to Impressao.pyc byte-compiling...
1
by: Bengt Richter | last post by:
I'd like to override the default d:\Python23\Lib\site-packages\ destination, at least as an option. I have used installshield in the past, which gives extensive control over just about...
2
by: Mike Meyer | last post by:
Ok, I give up. I searched the CVS code, and can't find the place that turns an include_dirs option in setup.cfg into a list of directories. The reason I was looking for it is that I can't figure...
2
by: Mardy | last post by:
Hi, the bdist_wininst command of distutils allows me to specify a script to be executed at the end of the installation. That's great, but how can I know the installation path from inside the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.