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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robocop

    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(li ne)

    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.
  • Chris Rebert

    #2
    Re: Script can't find input file despite being in the same directory

    On Fri, Oct 17, 2008 at 10:07 AM, Robocop <bthayre@physic s.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(li ne)
    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...

    >
    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.
    --

    >

    Comment

    • Philip Semanchuk

      #3
      Re: Script can't find input file despite being in the same directory


      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(li ne)
      >
      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

      Comment

      • Robocop

        #4
        Re: Script can't find input file despite being in the same directory

        On Oct 17, 10:27 am, "Chris Rebert" <creb...@ucsd.e duwrote:
        On Fri, Oct 17, 2008 at 10:07 AM, Robocop <btha...@physic s.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(li ne)
        >
        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

        Comment

        • Robocop

          #5
          Re: Script can't find input file despite being in the same directory

          On Oct 17, 10:27 am, "Chris Rebert" <creb...@ucsd.e duwrote:
          On Fri, Oct 17, 2008 at 10:07 AM, Robocop <btha...@physic s.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(li ne)
          >
          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")


          Comment

          • Christian Heimes

            #6
            Re: Script can't find input file despite being in the same directory

            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(li ne)
            >
            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.dirnam e(__file__))
            PS_FILE = os.path.join(HE RE, "base.ps")

            Christian

            Comment

            • Robocop

              #7
              Re: Script can't find input file despite being in the same directory

              I'm kind of an idiot, i just realized the problem. Sorry for wasting
              your time, and thanks for the help!

              Comment

              Working...