Script can't find input file despite being in the same directory
Christian Heimes
lists at cheimes.de
Fri Oct 17 13:37:05 EDT 2008
Robocop wrote:
> I have a simple little script that reads in postscript code, appends
> it, then writes it to a new postscript file. Everything worked fine a
> month ago, but after rearranging my directory tree a bit my script
> fails to find the base postscript file.
>
> The line in question is:
>
> for line in fileinput.input(['base.ps']):
> output.write(line)
>
> I'm kind of at a loss as the script is executing in the same directory
> as base.ps, yet it can't find it. I'm relatively new to python
> scripting, so i'm expecting it's just something i haven't learned
> about python that is causing the problem. Any suggestions would be
> greatly appreciated.
You can get the directory of the script with this useful snipplet:
import os
HERE = os.path.dirname(os.path.dirname(__file__))
PS_FILE = os.path.join(HERE, "base.ps")
Christian
More information about the Python-list
mailing list