move up a level

R

rplobue

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.txt', 'r') but the ../ doesn't work. How do i
do it?
 
F

Fredrik Lundh

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.txt', 'r') but the ../ doesn't work.

that's how it's usually done. what does "doesn't work" mean in this case?

</F>
 
J

John Machin

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.txt', '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
 
G

Gabriel Genellina

At said:
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.txt', '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
 
M

Manuel Kaufmann

El Martes, 21 de Noviembre de 2006 03:07, (e-mail address removed) 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.txt', '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 sys
if __name__ == '__main__':
print 'manuel'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top