encoding

How to write UTF-8 in a CSV file

折月煮酒 提交于 2019-12-27 12:17:12
问题 I am trying to create a text file in csv format out of a PyQt4 QTableWidget . I want to write the text with a UTF-8 encoding because it contains special characters. I use following code: import codecs ... myfile = codecs.open(filename, 'w','utf-8') ... f = result.table.item(i,c).text() myfile.write(f+";") It works until the cell contains a special character. I tried also with myfile = open(filename, 'w') ... f = unicode(result.table.item(i,c).text(), "utf-8") But it also stops when a special

How do you remove invalid hexadecimal characters from an XML-based data source prior to constructing an XmlReader or XPathDocument that uses the data?

时间秒杀一切 提交于 2019-12-27 11:01:35
问题 Is there any easy/general way to clean an XML based data source prior to using it in an XmlReader so that I can gracefully consume XML data that is non-conformant to the hexadecimal character restrictions placed on XML? Note: The solution needs to handle XML data sources that use character encodings other than UTF-8, e.g. by specifying the character encoding at the XML document declaration. Not mangling the character encoding of the source while stripping invalid hexadecimal characters has

Java properties UTF-8 encoding in Eclipse

五迷三道 提交于 2019-12-27 11:00:29
问题 I've recently had to switch encoding of webapp I'm working on from ISO-xx to utf8 . Everything went smooth, except properties files. I added -Dfile.encoding=UTF-8 in eclipse.ini and normal files work fine. Properties however show some strange behaviour. If I copy utf8 encoded properties from Notepad++ and paste them in Eclipse, they show and work fine. When I reopen properties file, I see some Unicode characters instead of proper ones, like: Zur\u00EF\u00BF\u00BDck instead of Zurück but app

Convert C# model to plain json-string

一笑奈何 提交于 2019-12-26 16:31:22
问题 Is there any simple way to convert an C# -object into a plain string that is escaped and can be used by javascript? I try to pass the string into a jQuery-function which will replace some parts of this string with real values to pass them as request-object via $.ajax . Whatever I tried (found in the internet) doesn't work. Currently I have: var jsVariable = "@Html.Raw(Json.Encode(new MyClass()))" but this throws an Uncaught SyntaxError: Unexpected identifier as of the " are not escaped

Cannot run python script [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-25 18:43:23
问题 This question already has answers here : Syntax error on print with Python 3 [duplicate] (3 answers) Closed 4 years ago . I am trying to run this python script: https://gist.githubusercontent.com/nk9/b150542ef72abc7974cb/raw/4a1e249976c6c330116fc068fb7001e3443c5b8d/largestFiles.py but for some reason it contains a bunch of illegal characters and gives this error: C:\tools\inspect>python largestFiles.py File "largestFiles.py", line 28 print "Finding objects larger than {}kB\u2026".format(args

Concatenate two Base64 encoded strings

点点圈 提交于 2019-12-25 18:21:32
问题 I want to decode two Base64 encoded strings and combine them to make one 128 bit string. I am able to decode the Base64 encoded strings. Can some one guide me on how to combine these two decoded strings? This is the code I used for decoding the two encoded strings. NSData *decodedData_contentKey = [[NSData alloc] initWithBase64EncodedString:str_content options:0]; NSString *decodedString_contentKey = [[NSString alloc] initWithData:decodedData_contentKey encoding:NSUTF8StringEncoding]; NSLog(@

c# file encoding and decoding, unreadable

家住魔仙堡 提交于 2019-12-25 17:20:31
问题 When you open some file with txt editor the encoding type can not be read and its just a mess of characters, I want to use this with my program when saving a file and how to do this in c# with: BinaryWriter bw = new BinaryWriter(File.Create(path), Encoder.SOME_ENCODING); and then decode it when loading. So what encoding should I use for this? 回答1: I want to save some string e.g "Sweet" to a file and if you open the file in a text edit you will see somthing like "nfgkdn@{3!" Just a simple

c# file encoding and decoding, unreadable

旧城冷巷雨未停 提交于 2019-12-25 17:20:04
问题 When you open some file with txt editor the encoding type can not be read and its just a mess of characters, I want to use this with my program when saving a file and how to do this in c# with: BinaryWriter bw = new BinaryWriter(File.Create(path), Encoder.SOME_ENCODING); and then decode it when loading. So what encoding should I use for this? 回答1: I want to save some string e.g "Sweet" to a file and if you open the file in a text edit you will see somthing like "nfgkdn@{3!" Just a simple

Python - how to open a text file that has emojis in it

我只是一个虾纸丫 提交于 2019-12-25 14:40:58
问题 I´m trying to do the simplest thing, open a file, read and close it in python. Simple. Well this is the code: name_file = open("Forever.txt", encoding='UTF-8') data = name_file.read() name_file.close() print (data) I know that this texts has emojis in it like hearts, etc. The thing is that this emojis are not in there unicode syntax like U+2600 , they are placed as little images. I think the following error is because of this little images: return codecs.charmap_encode(input,self.errors

Python - how to open a text file that has emojis in it

僤鯓⒐⒋嵵緔 提交于 2019-12-25 14:40:41
问题 I´m trying to do the simplest thing, open a file, read and close it in python. Simple. Well this is the code: name_file = open("Forever.txt", encoding='UTF-8') data = name_file.read() name_file.close() print (data) I know that this texts has emojis in it like hearts, etc. The thing is that this emojis are not in there unicode syntax like U+2600 , they are placed as little images. I think the following error is because of this little images: return codecs.charmap_encode(input,self.errors