Comments (7)
Sure. With the implemented codecs it should be as simple as:
import iconvcodec
with open("input.txt", mode="r", encoding="utf-8") as infile, \
open("output.txt", mode="w", encoding="ASCII/TRANSLIT") as outfile:
for line in infile:
print(line, file=outfile, end="")
Some care would have to be taken if the file is not line-based, but given that this is a text file, that should rarely happen.
from python-iconv.
Your are in luck :-D. I have compiled the available options on stackoverflow.
I would suggest to use the native integration of libmagic
(i.e. the file
utility), then you donβt need to install any additional python packages.
from python-iconv.
Ah, found it, the code in your first reply should be without a print but with a write:
with open(infilename, mode='r', encoding=inencoding) as infile, \
open(outfilename, mode='w', encoding=outencoding) as outfile:
for line in infile:
outfile.write(line)
from python-iconv.
Thanks. Related question, do you also happen to know a Python implementation for /usr/bin/file
?
from python-iconv.
Thanks, that page is very useful. Last related question, if you don't mind. π
I need flip -ub
in Python and have
def dos2unix(infilename, outfilename):
with open(infilename, 'br') as infile, \
open(outfilename, 'bw') as outfile:
for line in infile:
outfile.write(line.replace(b'\r\n', b'\n'))
but it is inserting \n
too many for each line. Any pointers there? I see a lot of examples that load the entire file in memory and use readlines, but I would like a line by line aproach.
from python-iconv.
It seems to work for me π€
from python-iconv.
The issue is on a file ISO-8859 text, with CRLF, LF line terminators
(e.g. /usr/share/hunspell/ru_RU.dic
from hunspell-ru
)
from python-iconv.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-iconv.