Problem reading static file

View: New views
3 Messages — Rating Filter:   Alert me  

Problem reading static file

by www.raj.net@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I am trying to convert a CGI application into TG

*) One of my method in a controller needs to read some static data
from file (text , xml etc) residing in the same directory of my
controller.
*) I tried to open the file using fp=open('filename.xml','rb')
*) I got the following error when the controller method is invoked:
                           IOError: [Errno 2] No such file or
directory: 'filename.xml'
*) I guess, if the file is stored in a static directory, it could be
opened. (i am not sure)
   But, I don't wish to serve this file through my application. I just
want to process it using a controller method.

Do anyone suggest me a solution?

Thanks for reading this post...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Problem reading static file

by Florent Aide :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


the file names are relative to the dir you launch the app (not
reliable) not to you controller.

You should either define a data_dir (with full path) in the config file and use:

os.path.join(data_dir, myfilename)

or use pkg_resources to get a stream of the file inside your egg.

Florent.

On Sat, Jul 5, 2008 at 11:05 AM, Raj <www.raj.net@...> wrote:

>
> I am trying to convert a CGI application into TG
>
> *) One of my method in a controller needs to read some static data
> from file (text , xml etc) residing in the same directory of my
> controller.
> *) I tried to open the file using fp=open('filename.xml','rb')
> *) I got the following error when the controller method is invoked:
>                           IOError: [Errno 2] No such file or
> directory: 'filename.xml'
> *) I guess, if the file is stored in a static directory, it could be
> opened. (i am not sure)
>   But, I don't wish to serve this file through my application. I just
> want to process it using a controller method.
>
> Do anyone suggest me a solution?
>
> Thanks for reading this post...
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Problem reading static file

by www.raj.net@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks Florent...
I gave the file name with relative path   starting from the directory
in which start-myprojectname.py resides. Now it works.
I will try the method you suggested.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price