[triangle-zpug] can't find font problem
david at handysoftware.com
Mon Mar 31 01:57:54 UTC 2008
On Sun, Mar 30, 2008 at 06:21:35AM -0700, Joseph Mack NA3T wrote:
> There's demo code out there eg
> (look for "arial.pil")
> that finds the font without doing anything special. I
> thought that maybe there was some font path or python path
> that allowed python to find the file without me having to do
In these examples, they are loading "arial.pil" from the current working
directory, whatever that happens to be at the time the script is run. That
is not production-quality code, it was simplified for demo purposes.
> I moved the files from directory to directory, hoping they'd
> be picked up by the load command. Their current location is
> just where they are now. If there's a canonical location,
> I'd be happy to move them there.
Typically, I put font files with my application. Any Python application
more complicated than a single .py file I usually put into a Python package
directory (a directory with an __init__.py file, see
http://docs.python.org/tut/node8.html#SECTION008400000000000000000). I throw
the fonts and other static data files in the same package directory as the
.py files, and then use the technique I described in my previous email to
locate the package directory, and load files relative to that directory.
Example file layout:
I don't know if this is "canonical", but I've seen a lot of Python
applications deployed this way. Using this technique, it is pretty easy to
make your applications cross-platform compatible. Just zip up
ApplicationHome and you've got something you can take to another machine and
Computer Programming is Fun!
Beginning Computer Programming with Python
More information about the triangle-zpug