topic description
define the data extracted from txt as five tuples: (name, class, subject, score, unit), saved as list list
data in TXT: Xiao Ming: class A001, Chinese, 50 points
:B002,,100
:A001,,80
:C003,,20
sources of topics and their own ideas
re.split "" ":" XX XX
A well-intentioned boss can easily give instructions on how to solve the output information: ("xefxbbxbfxe5xb0x8fxe6x98x8e"," A001xe7x8fxaddish, "xe8xafxadxe6x96x87"," 50xe5x88x86n") correct should be: ("Xiaoming", "A001 class", "Chinese","50", "score")
Thank you very much
related codes
/ / Please paste the code text below (do not replace the code with pictures)
< H1 >--coding:utf-8- -< / H1 > import re
filename = file (r "D:PyCharm01data.txt","r")
content = []
for line in filename.readlines ():
print line
people = tuple(re.split(r",|:",line,))
content.append(people)
print content
what result do you expect? What is the error message actually seen?
the current result is: print content [0]
output: ("xefxbbxbfxe5xb0x8fxe6x98x8e"," A001xe7x8fxaddish, "xe8xafxadxe6x96x87"," 50xe5x88x86n")
the correct result should be: print content [0]
"" "A001" "" "50" ""