Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Py 3: Terminal script can't find relative path

1 view
Skip to first unread message

Gnarlodious

unread,
Jan 18, 2010, 5:43:54 PM1/18/10
to
I am running a script in a browser that finds the file in subfolder
Data:

Content=Plist('Data/Content.plist')

However, running the same script in Terminal errors:

IOError: [Errno 2] No such file or directory: 'Data/Content.plist'

Is Py 3 unable to find relative paths? I tried all kinds of tricks to
no avail. What is wrong?

-- Gnarlie

John Bokma

unread,
Jan 18, 2010, 6:21:48 PM1/18/10
to
Gnarlodious <gnarl...@gmail.com> writes:

> I am running a script in a browser that finds the file in subfolder
> Data:
>
> Content=Plist('Data/Content.plist')
>
> However, running the same script in Terminal errors:
>
> IOError: [Errno 2] No such file or directory: 'Data/Content.plist'

What does:

ls -l Data/Content.plist

in the terminal give?

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development

Gnarlodious

unread,
Jan 19, 2010, 8:03:52 AM1/19/10
to
On Jan 18, 4:21 pm, John Bokma <j...@castleamber.com> wrote:

> Gnarlodious <gnarlodi...@gmail.com> writes:
> > I am running a script in a browser that finds the file in subfolder
> > Data:
>
> > Content=Plist('Data/Content.plist')
>
> > However, running the same script in Terminal errors:
>
> > IOError: [Errno 2] No such file or directory: 'Data/Content.plist'
>
> What does:
>
> ls -l Data/Content.plist
>
> in the terminal give?

I can replace with absolute paths and it works as expected. Could this
be a Python 3 bug? Where as a CGI script it finds the relative path
but not in Terminal?

-- Gnarlie

nn

unread,
Jan 19, 2010, 11:18:17 AM1/19/10
to

Stop and think for a second what you are saying: It works with
absolute paths, it works as CGI script with relative paths, it doesn't
work in the terminal. What is different? Do you know for sure what
folder you are starting at when using the relative path? Most likely
the terminal starts in a different place than the CGI script.

Gnarlodious

unread,
Jan 19, 2010, 2:29:00 PM1/19/10
to
OK I guess that is normal, I fixed it with this:

path=os.path.dirname(__file__)+"/Data/"

-- Gnarlie

Aahz

unread,
Jan 26, 2010, 2:35:06 PM1/26/10
to
In article <98c70d6f-5872-436b...@a32g2000yqm.googlegroups.com>,

Gnarlodious <gnarl...@gmail.com> wrote:
>
>OK I guess that is normal, I fixed it with this:
>path=os.path.dirname(__file__)+"/Data/"

Use os.path.join() instead -- just in case you ever port to Windows
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

import antigravity

0 new messages