How to divide numbers and characters in tuples in Python

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"   "" 
Mar.28,2021

about extraction

just change the way of thinking. If all units are 'points', why not consider adding the word "points" to the extracted rules? For example,


python3 encoding=utf-8

import re
content = []
with open('D:PyCharm01data.txt', 'r', encoding='utf-8') as f:
    for line in f.readlines():
        people = tuple(re.split(r',|:',line,))
        content.append(people)
print(content[0])

the result is this

("'", 'B002', '', "100'")
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-1b2bb25-2bace.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-1b2bb25-2bace.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?