pombreda / python-xmp-toolkit

Automatically exported from code.google.com/p/python-xmp-toolkit
Other
0 stars 1 forks source link

Using file objects instead of path. #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'am currently using your library and I am wondering : Is there a good reason 
for not offering the possibility to have the choice between a filepath and a 
file object for functions like `file_to_dict` ?

I have checked the sources and  try to figure out how to provide a patch but 
this is a lot of refactoring in the `files.py` module. Many functions rely on 
the path (_encode_as_utf8 etc) and the file is closed.

Any thought ? 

Cheers.

Stanislas.

Original issue reported on code.google.com by stanisla...@gmail.com on 30 Aug 2011 at 10:04

GoogleCodeExporter commented 9 years ago
Hi Stanislas,

The main reason for not taking a file object is that the underlying C library 
exempi expects a file path. What you can do as a work-around now is to call 
file_to_dict like this:

fp = open( '/path/to/somefile','r')
file_to_dict( fp.name )

This will however reopen the file which is probably not desirable.

Best regards,
Lars

Original comment by lniel...@spacetelescope.org on 1 Sep 2011 at 7:08

GoogleCodeExporter commented 9 years ago
Hi Lars,

In my context (a uploaded file via a web-application) I have a StringIO object. 
My workaround is to open a NamedTemporaryFile and read/write the StringIO in 
it. This is a bit of overhead but it works !

Cheers,

Stanislas. 

Original comment by stanisla...@gmail.com on 1 Sep 2011 at 7:15