Linux transcoding command line and python implementation, linuxpython

Source: Internet
Author: User

Linux transcoding command line and python implementation, linuxpython

The file copied from windows to linux is garbled today.File, iconvCommand transcoding is enough.

/* If it is implemented through a command line, it is also possible, and to some extent it may be more convenient */
File genghao. cpp/* You can find the approximate encoding type of this file */
Iconv-l
/* Check whether our iconv tool supports this encoding, but it does not. Just select a closer one */
Iconv-f XXXX
(Original encoding)-T YYY(The encoding you want)Genghao. cpp(Original file)Genhao. cpp(Target file)

If you want to learn more about the above instructions, you can refer to blog: http://blog.csdn.net/echoisland/article/details/6660619, which also mentionedFile tools may be misjudged..

As a restless person, a small function can be implemented using different tools. It is convenient to use scripts to implement transcoding.
What language? In fact, php, python, shell..., and even advanced C ++ and C can be implemented through corresponding file operations and some interfaces.

I want to use python for transcoding.

Import chardet

Fp = open ('genhao. cpp ', 'r + ')

/* Readlines reads the file, in a list of behavior units */
Content = '\ n'. join (fp. readlines ())
Print content
/* The file pointer returns to the beginning of the file */
Fp. seek (0)

/* Read the entire file */
Content = fp. read ()
Print content
Fp. seek (0)

/* Read 1 row in readline */
Tmp = fp. readline ()
While tmp:
Content + = tmp
Tmp = fp. readline ()
Print content

/* Determine the file encoding */
Charinfo = chardet. detect (content)
Encoding = charinfo ['encoding']
/* Convert to UTF-8 */
Content = content. decode (encoding). encode ('utf-8 ')
Print content

Get it done. Wait for time and write the implementation of other tools.

By convention,A sentence: language is just a tool, and ideas and problems are the key points.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.