byte-order-mark

Removing BOM from gzip'ed CSV in Python

十年热恋 提交于 2019-11-28 00:31:10
I'm using the following code to unzip and save a CSV file: with gzip.open(filename_gz) as f: file = open(filename, "w"); output = csv.writer(file, delimiter = ',') output.writerows(csv.reader(f, dialect='excel', delimiter = ';')) Everything seems to work, except for the fact that the first characters in the file are unexpected. Googling around seems to indicate that it is due to BOM in the file. I've read that encoding the content in utf-8-sig should fix the issue. However, adding: .read().encoding('utf-8-sig') to f in csv.reader fails with: File "ckan_gz_datastore.py", line 16, in <module>

heroku not loading language file

本小妞迷上赌 提交于 2019-11-28 00:14:46
Heroku does not seem to be loading config/locales/pt.yml . (Language is being set correctly to pt .) I18n is working perfectly on localhost, but not on my heroku server . Code is at https://github.com/aneves/deficit-puzzle localhost: $ rails console Loading development environment (Rails 3.0.5) irb(main):001:0> I18n.t(:Edit) => "Editar" heroku: $ heroku console Ruby console for deficit-puzzle.heroku.com >> I18n.t(:Edit) => "translation missing: pt.Edit" possible dups: There are SO matches for my problem, but those are dead threads. I do not want to open a bounty on a thread whose OP left

How can I remove the BOM from XmlTextWriter using C#?

坚强是说给别人听的谎言 提交于 2019-11-27 22:16:55
How do remove the BOM from an XML file that is being created? I have tried using the new UTF8Encoding(false) method, but it doesn't work. Here is the code I have: XmlDocument xmlDoc = new XmlDocument(); XmlTextWriter xmlWriter = new XmlTextWriter(filename, new UTF8Encoding(false)); xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); xmlWriter.WriteStartElement("items"); xmlWriter.Close(); xmlDoc.Load(filename); XmlNode root = xmlDoc.DocumentElement; XmlElement item = xmlDoc.CreateElement("item"); root.AppendChild(item);

Export UTF-8 BOM to .csv in R

北慕城南 提交于 2019-11-27 20:52:30
I am reading a file through RJDBC from a MySQL database and it correctly displays all letters in R (e.g., נווה שאנן). However, even when exporting it using write.csv and fileEncoding="UTF-8" the output looks like <U+0436>.<U+043A>. <U+041B><U+043E><U+0437><U+0435><U+043D><U+0435><U+0446> (in this case this is not the string above but a Bulgarian one) for Bulgarian, Hebrew, Chinese and so on. Other special characters like ã,ç etc work fine. I suspect this is because of UTF-8 BOM but I did not find a solution on the net My OS is a German Windows7. edit: I tried con<-file("file.csv",encoding="UTF

UTF-8 HTML and CSS files with BOM (and how to remove the BOM with Python)

旧城冷巷雨未停 提交于 2019-11-27 15:31:11
First, some background: I'm developing a web application using Python. All of my (text) files are currently stored in UTF-8 with the BOM. This includes all my HTML templates and CSS files. These resources are stored as binary data (BOM and all) in my DB. When I retrieve the templates from the DB, I decode them using template.decode('utf-8') . When the HTML arrives in the browser, the BOM is present at the beginning of the HTTP response body. This generates a very interesting error in Chrome: Extra <html> encountered. Migrating attributes back to the original <html> element and ignoring the tag

Create Text File Without BOM

久未见 提交于 2019-11-27 12:33:39
I tried this aproach without any success the code I'm using: // File name String filename = String.Format("{0:ddMMyyHHmm}", dtFileCreated); String filePath = Path.Combine(Server.MapPath("App_Data"), filename + ".txt"); // Process myObject pbs = new myObject(); pbs.GenerateFile(); // pbs.GeneratedFile is a StringBuilder object // Save file Encoding utf8WithoutBom = new UTF8Encoding(true); TextWriter tw = new StreamWriter(filePath, false, utf8WithoutBom); foreach (string s in pbs.GeneratedFile.ToArray()) tw.WriteLine(s); tw.Close(); // Push Generated File into Client Response.Clear(); Response

Is there a way to remove the BOM from a UTF-8 encoded file?

☆樱花仙子☆ 提交于 2019-11-27 12:22:56
Is there a way to remove the BOM from a UTF-8 encoded file? I know that all of my JSON files are encoded in UTF-8, but the data entry person who edited the JSON files saved it as UTF-8 with the BOM. When I run my Ruby scripts to parse the JSON, it is failing with an error. I don't want to manually open 58+ JSON files and convert to UTF-8 without the BOM. With ruby >= 1.9.2 you can use the mode r:bom|utf-8 This should work (I haven't test it in combination with json): json = nil #define the variable outside the block to keep the data File.open('file.txt', "r:bom|utf-8"){|file| json = JSON.parse

VBA Output to file using UTF-16

我是研究僧i 提交于 2019-11-27 09:46:47
I have a very complex problem that is difficult to explain properly. There is LOTS of discussion about this across the internet, but nothing definitive. Any help, or better explanation than mine, is greatly appreciated. Essentially, I'm just trying to write an XML file using UTF-16 with VBA. If I do this: sXML = "<?xml version='1.0' encoding='utf-8'?>" sXML = sXML & rest_of_xml_document Print #iFile, sXML then I get a file that is valid XML. However, if I change the "encoding=" to "utf-16", I get this error from my XML validator: Switch from current encoding to specified encoding not supported

Python read csv - BOM embedded into the first key

為{幸葍}努か 提交于 2019-11-27 09:03:13
I'm using Python 2.7.12. With this code snippet I'm saving a utf-8 csv file. I wrote the BOM ( byte order mark ) at the beginning of the file. import codecs import csv outputFile = open("test.csv", "wb") outputFile.write(codecs.BOM_UTF8) fieldnames = ["a", "b"] writer = csv.DictWriter(outputFile, fieldnames, delimiter=";") writer.writeheader() row = dict([]) for i in range(10): row["a"] = str(i).encode("utf-8") row["b"] = str(i*2).encode("utf-8") writer.writerow(row) outputFile.close() I want to load that csv file: import codecs import csv inputFile = open("test.csv", "rb") reader = csv

XDocument: saving XML to file without BOM

喜你入骨 提交于 2019-11-27 08:13:47
I'm generating an utf-8 XML file using XDocument . XDocument xml_document = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement(ROOT_NAME, new XAttribute("note", note) ) ); ... xml_document.Save(@file_path); The file is generated correctly and validated with an xsd file with success. When I try to upload the XML file to an online service, the service says that my file is wrong at line 1 ; I have discovered that the problem is caused by the BOM on the first bytes of the file. Do you know why the BOM is appended to the file and how can I save the file without it? As stated in