The problem of os.walk File name Encoding in python2.7

-sharp -*- coding: utf-8 -*-
import os 
    
def file_name(file_dir):   
        L=[]   
        for root, dirs, files in os.walk(file_dir):  
            print files

def main():
    path = os.getcwd()
    file_list = file_name(path+"\img")

main()

Code as above
get the picture of the folder and print out the file name
the result shows the encoding

the results are as follows:

"2017\xd3\xc8\xc3\xdb\xdc\xf6\xb0\xd9\xc6\xda\xba\xcf\xbc\xaf \xc3\xc0\xc5\xae\xc8\xe7\xd4\xc6\xd6\xd8\xb0\xf5\xb8\xa3\xc0\xfb_0.jpg", "2017\xd3\xc8\xc3\xdb\xdc\xf6\xb0\xd9\xc6\xda\xba\xcf\xbc\xaf \xc3\xc0\xc5\xae\xc8\xe7\xd4\xc6\xd6\xd8\xb0\xf5\xb8\xa3\xc0\xfb_1.jpg",

I have found a lot of information about this on the Internet, but I still can"t solve it. Please give me some advice.

Mar.31,2021

I usually use json to solve

when I print the Chinese garbled in the list in

Python2.


for file in os.listdir('./img'):
    print file.decode('gbk').encode('utf-8')
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e596c1-45533.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e596c1-45533.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?