469,290 Members | 1,723 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Script can't find input file despite being in the same directory

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.
Oct 17 '08 #1
6 4306
On Fri, Oct 17, 2008 at 10:07 AM, Robocop <bt*****@physics.ucsd.eduwrote:
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)
What directory is output if you insert the lines:

from os import getcwd
print "CWD:", getcwd()

just before the line is question?

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>
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.
--
http://mail.python.org/mailman/listinfo/python-list
Oct 17 '08 #2

On Oct 17, 2008, at 1:07 PM, 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.
Put this before the line that fails and see what it tells you:
print os.getcwd()
getcwd = get current working directory
Oct 17 '08 #3
On Oct 17, 10:27*am, "Chris Rebert" <creb...@ucsd.eduwrote:
On Fri, Oct 17, 2008 at 10:07 AM, Robocop <btha...@physics.ucsd.eduwrote:
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)

What directory is output if you insert the lines:

from os import getcwd
print "CWD:", getcwd()

just before the line is question?

Cheers,
Chris
--
Follow the path of the Iguana...http://rebertia.com
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.
--
http://mail.python.org/mailman/listinfo/python-list

The output is /home/bruce/DEVadhc/attendance

which is the directory i expected, and the directory that contains
base.ps
Oct 17 '08 #4
On Oct 17, 10:27*am, "Chris Rebert" <creb...@ucsd.eduwrote:
On Fri, Oct 17, 2008 at 10:07 AM, Robocop <btha...@physics.ucsd.eduwrote:
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)

What directory is output if you insert the lines:

from os import getcwd
print "CWD:", getcwd()

just before the line is question?

Cheers,
Chris
--
Follow the path of the Iguana...http://rebertia.com
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.
--
http://mail.python.org/mailman/listinfo/python-list


Also i forgot this pertinent line: output = open("/home/bruce/attend/
media/ps/barcodes.ps", "w")
Oct 17 '08 #5
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

Oct 17 '08 #6
I'm kind of an idiot, i just realized the problem. Sorry for wasting
your time, and thanks for the help!
Oct 17 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Preston Crawford | last post: by
7 posts views Thread by Lowell Kirsh | last post: by
7 posts views Thread by pbd22 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.