Are you running the WebDev server from Visual Studio? If so, that
directory is the default "working directory" for the
WebDev.WebServer.exe (the ASP.NET server), and thus where IronPython
will look for files when you use 'open'.

By default, IronPython doesn't know that you're running in a web app
and thus follows the system rules for locating files. The same thing
happens in C#/ASP.NET as well, by the way, if you don't handle it
properly..

You need to use Server.MapPath to get a path that 'open' can handle.
It'll look something like

   open(Server.MapPath('~/t2.pkl'), 'rb')

Server.MapPath converts a webapp-relative path to a filesystem path
the open will understand; the '~/' just means the root of the web app.

- Jeff

On Tue, Jun 29, 2010 at 3:44 PM, William Johnston <[email protected]> wrote:
>
>
> Hello,
>
>
>
> The following Python code snippet causes a FileNotFound exception from an
> ASP.NET Web application:
>
>
>
> input = open('t2.pkl', 'rb')
>
>
>
> The exception message is:
>
>
>
> [Could not find file 'C:\Program Files (x86)\Common Files\Microsoft
> Shared\DevServer\10.0\t2.pkl'.]
>
>
>
> The same code works for a console project.
>
>
>
> Any suggestions?
>
>
>
> Thanks,
>
> William Johnston
>
>
>
>
>
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to