0

I got a Chinese file named 005大禹治水.lrc, and I want to print out the filename with its directory, like: /home/user/lrc/005大禹治水.lrc

Here is what I tried in Python 2.7:

# -*- coding: utf-8 -*-
from __future__ import print_function
import argparse
import os
from pydub import AudioSegment


def main():
    wd= os.path.split(os.path.realpath(__file__))[0]

    parser = argparse.ArgumentParser()
    parser.add_argument('--lrc', default=os.path.expanduser(wd + '/lrc'))
    args = parser.parse_args()

    '''
    saving lrc files path and name into list
    '''
    lrc_files_path = []

    for file in os.listdir(args.lrc):
        if file.endswith(".lrc"):
            lrc_files_path.append(os.path.join(args.lrc, file))
    print(lrc_files_path)
    print("*" * 38)

if __name__ == "__main__":
    main()

the output is:

['/home/user/lrc/005\xe5\xa4\xa7\xe7\xa6\xb9\xe6\xb2\xbb\xe6\xb0\xb4.lrc']

Which is not as I expected as run by Python 3.0+:

['/home/user/lrc/005大禹治水.lrc']

Actually, this problem will not be disturbed in Python 3.0+. However, the task I am handling is required using pydub (Not supports with Python 3.0+) in order to editing the mp3 file based on the time line from lrc file. :(

I did some researches about the UTF-8 converting of Chinese, and tried out some potential solutions, but nothing comes up at last. :(

Any suggestion greatly appreciate!

  • You're printing the representation of a list, which contains unicode in python3 and binary data in python2. Of course the result is different. The representation is intended to be something unambiguous, not something looking nice. If you want a specific output you need to format it yourself. – mata Apr 12 '18 at 10:33
  • 1
    pydub does support python 3 :) specifically: python 2.7+ and 3.3+ – Jiaaro Apr 12 '18 at 18:36

0 Answers0