Hướng dẫn python ansi library - thư viện python ansi


Tôi có khoảng 600.000 tệp được mã hóa trong

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
5 và tôi muốn chuyển đổi chúng thành
blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
6. Tôi có thể làm điều đó riêng lẻ trong
blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
7, nhưng tôi có thể làm điều đó với 600.000 tệp. Tôi có thể làm điều này trong ____10 hoặc

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
1 không?

Tôi đã tìm thấy liên kết này nhưng tập lệnh

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
1 không chạy: Notepad ++ chuyển đổi tệp được mã hóa ANSI sang UTF-8

hỏi ngày 17 tháng 7 năm 2015 lúc 8:05Jul 17, 2015 at 8:05Jul 17, 2015 at 8:05

Hướng dẫn python ansi library - thư viện python ansi


Hướng dẫn python ansi đến utf-8

6

Tại sao bạn không đọc tệp và viết nó là UTF-8? Bạn có thể làm điều đó trong Python.

#to support encodingsimport codecs#read input filewith codecs.open(path, 'r', encoding = 'utf8') as file: lines = file.read()#write output filewith codecs.open(path, 'w', encoding = 'utf8') as file: file.write(lines)

Đã trả lời ngày 17 tháng 7 năm 2015 lúc 8:13Jul 17, 2015 at 8:13Jul 17, 2015 at 8:13


Hướng dẫn python ansi đến utf-8

Tại sao bạn không đọc tệp và viết nó là UTF-8? Bạn có thể làm điều đó trong Python.3Ducker

Đã trả lời ngày 17 tháng 7 năm 2015 lúc 8:13Jul 17, 2015 at 8:131 silver badge9 bronze badges

3


Hướng dẫn python ansi đến utf-8

Tại sao bạn không đọc tệp và viết nó là UTF-8? Bạn có thể làm điều đó trong Python.

#to support encodingsimport codecs#read input filewith codecs.open(path, 'r', encoding = 'utf8') as file: lines = file.read()#write output filewith codecs.open(path, 'w', encoding = 'utf8') as file: file.write(lines)

Đã trả lời ngày 17 tháng 7 năm 2015 lúc 8:13Jul 17, 2015 at 8:13

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)

Tại sao bạn không đọc tệp và viết nó là UTF-8? Bạn có thể làm điều đó trong Python.3Ducker

#to support encodingsimport codecs#read input filewith codecs.open(path, 'r', encoding = 'utf8') as file: lines = file.read()#write output filewith codecs.open(path, 'w', encoding = 'utf8') as file: file.write(lines)
1 silver badge9 bronze badges

Đã trả lời ngày 17 tháng 7 năm 2015 lúc 8:13Dec 19, 2018 at 17:27

3Ducker3Ducker

3231 Huy hiệu bạc9 Huy hiệu đồng

Tôi đánh giá cao rằng đây là một câu hỏi cũ nhưng vừa giải quyết một vấn đề tương tự gần đây, tôi nghĩ rằng tôi sẽ chia sẻ giải pháp của mình.Dec 19, 2018 at 17:27

Tôi đã có một tệp được chuẩn bị bởi một chương trình mà tôi cần nhập vào cơ sở dữ liệu SQLite3 nhưng tệp văn bản luôn là ‘ANSI, và SQLite3 yêu cầu UTF-8.

Mã hóa ANSI được công nhận là ‘MBCS, trong Python và do đó mã tôi đã sử dụng, xé toạc thứ khác tôi tìm thấy là:

cp874 Thaicp932 Japanese cp936 Unified Chinese (P.R. China, Singapore)cp949 Korean cp950 Traditional Chinese (Taiwan, Hong Kong, Macao(?))cp1250 Central and Eastern Europe cp1251 Cyrillic ( Belarusian, Bulgarian, Macedonian, Russian, Serbian, Ukrainian)cp1252 Western European languagescp1253 Greek cp1254 Turkish cp1255 Hebrew cp1256 Arabic scriptcp1257 Baltic languages cp1258 Vietnamesecp???? languages/scripts of India 

Liên kết dưới đây chứa một số thông tin về các loại mã hóa mà tôi tìm thấy trong nghiên cứu của mình

https://docs.python.org/2.4/lib/standard-encodings.html

Đã trả lời ngày 19 tháng 12 năm 2018 lúc 17:27

MS Notepad cung cấp cho người dùng lựa chọn 4 mã hóa, được thể hiện bằng thuật ngữ khó hiểu vụng về:

UN UNICode là UTF-16, viết Little-endian. Unicode Unicode Big Endian là UTF-16, được viết lớn. Trong cả hai trường hợp UTF-16, điều này có nghĩa là BOM thích hợp sẽ được viết. Sử dụng

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
3 để giải mã một tệp như vậy.

The quick brown fox jumped over the lazy dogs.àáâãäå

UTF-8 là UTF-8; Notepad viết rõ ràng một BOM UTF-8. Sử dụng

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
0

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
4 để giải mã một tệp như vậy.

Một số người gây sốc. Đây là thuật ngữ MS cho bất cứ điều gì mã hóa di sản mặc định trên máy tính này.

Dưới đây là danh sách các mã hóa Windows mà tôi biết và các ngôn ngữ/tập lệnh mà chúng được sử dụng cho:

Nếu tệp đã được tạo trên máy tính nơi nó đang được đọc, thì bạn có thể có được mã hóa ANSI ANSI bằng cách

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
5. Mặt khác, nếu bạn biết nó đến từ đâu, bạn có thể chỉ định mã hóa để sử dụng nếu nó không phải là UTF-16. Thất bại điều đó, đoán.
blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
2

blockSize = 1048576with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
4

Hãy cẩn thận bằng cách sử dụng