Hi,
in a PyQt application I'm writing, the user can select a filename with a
FileDialog. Then I would like to open this file. This works fine if there
are no "special symbols" in the filename, such as the german umlauts: "ÖÄÜ"
Currently I convert the returned, of what I'm pretty sure its a utf-8 string
object, to a normal string using the str() function. But then my string
contains garbage and I cannot find that file on my ext3 fs (which uses
latin-1).
So my first question is wether you *can* convert it without loosing
something and secondly: how?
Thanks for any pointers -
Ciao
Uwe 4 6104
Uwe Mayer <me*****@hadiko.de> pisze: in a PyQt application I'm writing, the user can select a filename with a FileDialog. Then I would like to open this file. This works fine if there are no "special symbols" in the filename, such as the german umlauts: "ÖÄÜ"
Currently I convert the returned, of what I'm pretty sure its a utf-8 string object, to a normal string using the str() function. But then my string contains garbage and I cannot find that file on my ext3 fs (which uses latin-1).
So my first question is wether you *can* convert it without loosing something and secondly: how?
I use unicode() to convert QString returned by Qt widgets to unicode
object, then encode it in latin2. Qt uses its own string class, not
ordinary strings.
--
Jarek Zgoda
Unregistered Linux User #-1 http://www.zgoda.biz/ JID:zgoda-a-chrome.pl http://zgoda.jogger.pl/
Uwe Mayer wrote: in a PyQt application I'm writing, the user can select a filename with a FileDialog. Then I would like to open this file. This works fine if there are no "special symbols" in the filename, such as the german umlauts: "ÖÄÜ"
Currently I convert the returned, of what I'm pretty sure its a utf-8 string object, to a normal string using the str() function. But then my string contains garbage and I cannot find that file on my ext3 fs (which uses latin-1).
Decode the string to unicode and then encode it to latin-1: filename_latin1 = unicode(filename_utf8, 'utf-8').encode('latin-1')
Markus
Uwe Mayer wrote: Currently I convert the returned, of what I'm pretty sure its a utf-8 string object, to a normal string using the str() function.
Try converting the object to a Unicode object. I don't know what you
mean by "utf-8 string object"; Python has no such thing (but PyQt may).
Then, pass the unicode object to open().
So my first question is wether you *can* convert it without loosing something and secondly: how?
In Python 2.3, you best use unicode strings to represent file names;
Python should know how to map them to the local representation,
depending on operating system conventions.
Regards,
Martin
Martin v. Löwis <ma****@v.loewis.de> pisze: Currently I convert the returned, of what I'm pretty sure its a utf-8 string object, to a normal string using the str() function.
Try converting the object to a Unicode object. I don't know what you mean by "utf-8 string object"; Python has no such thing (but PyQt may).
Any "string value" is returned by PyQt as QString, which is "compatible
with UTF-8 strings", as Qt documentation states. In programming practice
this means that you can use str() only when you expect receiving pure
ASCII text. In any other case you should use unicode() to convert
QString to unicode object. This fairly means taht you should *always*
use unicode().
Unless you write software that is allowed to run only in US.
--
Jarek Zgoda
Unregistered Linux User #-1 http://www.zgoda.biz/ JID:zgoda-a-chrome.pl http://zgoda.jogger.pl/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Oliver Kurz |
last post by:
Hello,
could someone tell me the best way to convert a string to utf, for example
to utf-8?
The problem: I have no controll about the source where the string comes
from. It could have any...
|
by: hunterb |
last post by:
I have a file which has no BOM and contains mostly single byte chars. There
are numerous double byte chars (Japanese) which appear throughout. I need to
take the resulting Unicode and store it in a...
|
by: Du Dang |
last post by:
I tried to convert a block of text from iso-8859-1 to utf-8 but all I got
after the convertion is gibberish.
===============================
FileStream fs = File.Open("text.txt",...
|
by: davihigh |
last post by:
My Friends:
I am using std::ofstream (as well as ifstream), I hope that when i
wrote in some std::string(...) with locale, ofstream can convert to
UTF-8 encoding and save file to disk. So does...
|
by: thinktwice |
last post by:
i'm using VC++6 IDE
i know i could use macros like A2T, T2A,
but is there any way more decent way to do this?
|
by: GM |
last post by:
Dear all,
Could you all give me some guide on how to convert my big5 string to
unicode using python? I already knew that I might use cjkcodecs or
python 2.4 but I still don't have idea on what...
|
by: Jared Wiltshire |
last post by:
I'm trying to convert a wstring (actually a BSTR) to UTF-8.
This is what I've currently got:
size_t arraySize;
setlocale(LC_CTYPE,"C-UTF-8");
arraySize = wcstombs(NULL, wstr, 0);
char...
|
by: shapper |
last post by:
Hello,
Could someone tell me how to convert a XML file into another XML file
using a XSL file with a parameter? I created the code to do it, and it
seems ok, but it is not working.
Could...
|
by: Zmische |
last post by:
Platform: IIS6, windows 2000 Server, ASP + VBSCRIPT
I have an ASP application that posts FORM via XMLHttprequest (javascript) so that all data is posted in UTF-8.
So I have an ASP that get data in...
|
by: est |
last post by:
From python manual
str( )
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
with repr(object) is that...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |