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 6200
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(filenam e_utf8, 'utf-8').encode('lat in-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.loewi s.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 possible characterset. And I have to convert it for
example to utf-8.
Is there a good way to do this? And when, how?
|
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 DB and display it onscreen. No
matter which way I open the file, convert it to Unicode/leave it as is or
what ever, I see all single bytes ok, but double bytes become 2 seperate
single bytes. Surely there is an easy way to convert these mixed...
|
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", FileMode.Open, FileAccess.Read);
byte b = new byte;
fs.Read(b, 0, length);
b = Encoding.Convert(Encoding.GetEncoding(28591), Encoding.UTF8, b);
|
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 ifstream.
Something I found shows that, I need to have a proper codecvt to set
it. I need more information, maybe a small piece of code sample. Thank
you!
|
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 exactly I should do.
Please give me some sample code if you could. Thanks a lot
Regards,
Gary
|
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 utf8string;
wcstombs(utf8string, Name, arraySize + 1);
|
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 somebody, please, help me out? I am on this for days.
My code is as follows:
|
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 UTF-8 charset and I should convert it into WINDOWS-1251 charset to send data to DB via ADO.
I tried to use Chilcat Charset ActiveX module, but it didnt work for me because I need to convert from UTF-8 to win1251 into variable, not using...
|
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 str(object) does not always attempt to
return a string that is acceptable to eval(); its goal is to return a
printable string. If no argument is given, returns the empty string,
''.
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |