From: Josip <jo...@pi...> - 2010-02-22 19:03:26
|
On 22.02.2010 18:05, Peter Landgren wrote: > Hi > > I have a silly string conversion question: > > When I, in Windows, drag and drop an image to the Media View or to a gallery I get a file reference > like: > "C:\Documents%20and%20Settings\P%C3%A4r\Mina dokument\Mina bilder\IMG_1662.JPG" > (%20 is only replaced in Gramps mediaview.py now.) > > The file reference string is of type 'unicode' and the sequence %C3%A4 represents the letter "ä". > The directory name is "Pär", which in a Python 'str' is represented by 'P\xc3\xa4r' > and in a Python unicode is represented by u'P\xe4r'. > > I can covert the original string to a 'str' so that I only need to replace % by \x and > then convert back to unicode before using it as a path. > > So, my silly question how do I get the '%' to '\x'? > Or is there a another way to handle this situation? > It looks like URL so: urllib.url2pathname(UPATH.encode(sys.getfilesystemencoding())) -- Josip |