Hi,
I'm making a project into my first package, mainly for organization, but
also to learn how to do it. I have a number of data files, both
experimental results and PNG files. My project is organized as a root
directory, with two subdirectories, src and data, and directory trees
below them. I put the root directory in my pythonpath, and I've no
trouble accessing the modules, but for the data, I'm giving relative
paths, that depend on the current working directory.
This has obvious drawbacks, and hard-coding a directory path is worse.
Where the data files are numbers, I can simply incorporate them in
python scripts that initialize data structures , but what can I do with
the image files?
What is the usual way of dealing with this?
Thanks,
Saul 3 1003
On Sun, Jun 22, 2008 at 4:07 PM, Saul Spatz <ss****@kcnet.c omwrote:
Hi,
I'm making a project into my first package, mainly for organization, but
also to learn how to do it. I have a number of data files, both
experimental results and PNG files. My project is organized as a root
directory, with two subdirectories, src and data, and directory trees below
them. I put the root directory in my pythonpath, and I've no trouble
accessing the modules, but for the data, I'm giving relative paths, that
depend on the current working directory.
This has obvious drawbacks, and hard-coding a directory path is worse. Where
the data files are numbers, I can simply incorporate them in python scripts
that initialize data structures , but what can I do with the image files?
What is the usual way of dealing with this?
The usual method (afaik) is to use relative paths, and to not change
into the script dirs before running them.
eg, instead of:
cd src/dir1/dir2/dir3
../script.py
You run it like this:
../src/dir1/dir2/dir3/script.py
And then all the scripts under src can load data files using a path
like this: './data/datafile'
Another method is to use a file-finder func which looks in various
places (using PATH, PYHONPATH, etc), and returns the first-found path
to the file.
Le Sunday 22 June 2008 16:07:37 Saul Spatz, vous avez écrit*:
Hi,
I'm making a project into my first package, mainly for organization, but
also to learn how to do it. I have a number of data files, both
experimental results and PNG files. My project is organized as a root
directory, with two subdirectories, src and data, and directory trees
below them. I put the root directory in my pythonpath, and I've no
trouble accessing the modules, but for the data, I'm giving relative
paths, that depend on the current working directory.
This has obvious drawbacks, and hard-coding a directory path is worse.
Where the data files are numbers, I can simply incorporate them in
python scripts that initialize data structures , but what can I do with
the image files?
For a small project you can do the same with images or any kind of data, for
instance by serializing your objects with pickle in ascii mode and putting
the result in a string constant (well, I never did it and can't guarantee it
will work, this is only an example of what people do in many situations)
>
What is the usual way of dealing with this?
A more conventional way is to provide a configure script to run before
compiling/installing. That script should let the user choose where to install
datafiles with a command line option such as --datadir=/path or provide a
reasonable default value. Then it will auto-generate some code defining this
value as a global variable, to make it accessible to the rest of your own
code. Ideally, your app would also provide a command line option or an
environment variable to override this hard-coded setting at runtime.
But maybe the distutils tools have some features for this, I don't know enough
of them to tell that.
--
Cédric Lucantis
Cédric Lucantis wrote:
Le Sunday 22 June 2008 16:07:37 Saul Spatz, vous avez écrit :
>Hi,
I'm making a project into my first package, mainly for organization, but also to learn how to do it. I have a number of data files, both experimental results and PNG files. My project is organized as a root directory, with two subdirectories, src and data, and directory trees below them. I put the root directory in my pythonpath, and I've no trouble accessing the modules, but for the data, I'm giving relative paths, that depend on the current working directory.
This has obvious drawbacks, and hard-coding a directory path is worse. Where the data files are numbers, I can simply incorporate them in python scripts that initialize data structures , but what can I do with the image files?
For a small project you can do the same with images or any kind of data, for
instance by serializing your objects with pickle in ascii mode and putting
the result in a string constant (well, I never did it and can't guarantee it
will work, this is only an example of what people do in many situations)
>What is the usual way of dealing with this?
A more conventional way is to provide a configure script to run before
compiling/installing. That script should let the user choose where to install
datafiles with a command line option such as --datadir=/path or provide a
reasonable default value. Then it will auto-generate some code defining this
value as a global variable, to make it accessible to the rest of your own
code. Ideally, your app would also provide a command line option or an
environment variable to override this hard-coded setting at runtime.
But maybe the distutils tools have some features for this, I don't know enough
of them to tell that.
A couple of good ideas here. Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Samantha |
last post by:
I am attempting to extract the Font Names from the installed windows fonts.
I am having a heck of a time getting these rather than the file names.
Examples can be seen by going to Control Panel > Fonts
Any help or direction is appreciated.
S
|
by: Peter Saffrey |
last post by:
(apologies for starting a new thread - Google can't retrieve the other
message for some reason)
Yes, /usr/lib/python/site-packages is in sys.path. This series of
commands should explain what I mean: I've put the Python ID3 module in
a sub-directory of site-packages as an illustration.
pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/
ID3.py ID3.pyc ID3.pyo README apt_inst.so apt_pkg.so apt_proxy
bsddb3 debconf.py debconf.pyc ...
|
by: Rich Burridge |
last post by:
Hi,
I work in the Accessibility Program Office at Sun Microsystems. I'm
part of a team that is using Python to create a screen reader called
Orca, that'll help blind people (and people with low vision) have
access to the GNOME desktop for Solaris and Linux.
See:
http://cvs.gnome.org/viewcvs/*checkout*/orca/docs/doc-set/orca.html
|
by: Iain King |
last post by:
I've installed ctypes and FreeImagePy. When I do this:
>>> import FreeImagePy
>>> f = FreeImagePy.Image()
I get:
find
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python\Lib\site-packages\FreeImagePy\FreeImagePy.py", line
|
by: metaperl |
last post by:
Email to Kevin Smith regarding his plastex package failed. I hope he
read this group. The tarball that he needs to reproduce the error is
here:
http://arc.livingcosmos.org/wolfram-fruit2/wolfram-fruit.tar.gz
Hi, when attempting to type plastex wolfram-fruit.tex on the attached
latex document, I got some errors. Also, I think the default HTML font
for plastex could be "nicer" ...either that or some ready made easy to
choose CSS for some...
| |
by: erikcw |
last post by:
Hi all,
When trying to run this python script from cron, I get the following
error:
Traceback (most recent call last):
File "/home/lybp/public_html/wa/wa.py", line 14, in ?
import MySQLdb
ImportError: No module named MySQLdb
|
by: Chris Carlen |
last post by:
Hi:
From what I've read of OOP, I don't get it. I have also found some
articles profoundly critical of OOP. I tend to relate to these articles.
However, those articles were no more objective than the descriptions of
OOP I've read in making a case. Ie., what objective
data/studies/research indicates that a particular problem can be solved
more quickly by the programmer, or that the solution is more efficient
in execution time/memory...
|
by: SPE - Stani's Python Editor |
last post by:
Hi All,
If you wrote some python code that you want to package or know a cool
python application of which you like to make a deb installer, the
python packaging session is all for you! Do you develop some cross-
platform open source software and you want to give its popularity a
boost by bringing it to Ubuntu and Debian, read on! (Packages are what
installers are for Windows.)
This session will be hosted by the respected Emilio...
|
by: Michael Matthews |
last post by:
Hello,
I'm fairly new to Python, and have run into dead ends in trying to
figure out what is going on. The basic thing I am trying to do is get
pylibpcap working on a Python installation. More precisely, I want to
get it working on an ActiveState Python installation.
I have it working on cygwin (Windows XP). I was hoping to just be able
to copy the pcap.py and _pcapmodule.dll file to a directory in the
ActiveState install's sys.path...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |