these days just started to learn Python, today in the Python file access to the output of Chinese garbled problem. Of course , as a python technology small white, but also only through the search results on Baidu. By importing the ' OS ' module, as follows:
Username = input (' username: ')
os .system ( "Cd.>test.txt" )
FP = open ' test.txt ' ' w+ '
The input username string can be written to the file Text.txt, which exists under this item. In the output of knowledge encountered in the Chinese output garbled problem, and then have the following import ' codecs ' module, examples are as follows:
ImportCodecs
Username =input(' username ')
Text = Codecs.open (' Test.txt ',' W ',' Utf-8 ')
Text.write (username)
Text = Codecs.open (' Test.txt ',' R ',' Utf-8 ')
s = Text.read ()
Print(s)
Successfully solve Chinese garbled problem.
I hope there are any problems we can discuss together, the wrong place directly point out.
A way to solve the language of Python read file garbled