move up a level

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rplobue@yahoo.com

    move up a level

    alright, noob question: i want to open a file in a directory above the
    current one i'm in. I'm trying to use myfile =
    open('../thefileiwant.tx t', 'r') but the ../ doesn't work. How do i
    do it?

  • Fredrik Lundh

    #2
    Re: move up a level

    rplobue@yahoo.c om wrote:
    alright, noob question: i want to open a file in a directory above the
    current one i'm in. I'm trying to use myfile =
    open('../thefileiwant.tx t', 'r') but the ../ doesn't work.
    that's how it's usually done. what does "doesn't work" mean in this case?

    </F>

    Comment

    • John Machin

      #3
      Re: move up a level

      rplobue@yahoo.c om wrote:
      alright, noob question: i want to open a file in a directory above the
      current one i'm in. I'm trying to use myfile =
      open('../thefileiwant.tx t', 'r') but the ../ doesn't work. How do i
      do it?
      "Doesn't work" means what?
      Have you looked at the getcwd and chdir functions in the os module?
      You may wish to check that os.getcwd()'s notion of "current directory"
      is the same as yours.
      If you can't make any progress, ask again; do copy and paste the
      relevant parts of your script instead of trying to describe what you
      did. Also copy and paste output. Hint: use temporary print statements
      to show what is happening.

      HTH,
      John

      Comment

      • Gabriel Genellina

        #4
        Re: move up a level

        At Tuesday 21/11/2006 03:07, rplobue@yahoo.c om wrote:
        >alright, noob question: i want to open a file in a directory above the
        >current one i'm in. I'm trying to use myfile =
        >open('../thefileiwant.tx t', 'r') but the ../ doesn't work. How do i
        >do it?
        Above the process' current dir, or above the dir where the script resides?
        You get the latter with os.path.abspath (__file__)


        --
        Gabriel Genellina
        Softlab SRL

        _______________ _______________ _______________ _____
        Correo Yahoo!
        Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
        ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

        Comment

        • Manuel Kaufmann

          #5
          Re: move up a level

          El Martes, 21 de Noviembre de 2006 03:07, rplobue@yahoo.c om escribió:
          alright, noob question: i want to open a file in a directory above the
          current one i'm in. I'm trying to use myfile =
          open('../thefileiwant.tx t', 'r') but the ../ doesn't work. How do i
          do it?
          Hello, I proved your doubt in my PC and it works fine. This is the example:

          Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
          [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
          Type "help", "copyright" , "credits" or "license" for more information.
          >>import os
          >>os.getcwd()
          '/home/manuel/descargas'
          >>file = open('../proof.py')
          >>print file.read()
          import sys
          if __name__ == '__main__':
          print 'manuel'
          >>>
          --
          Kaufmann Manuel

          Comment

          Working...