Could you please provide me with the code that Python would like to list the output from the following text file?
Expected output:
["株式会社〇〇〇 帯広太郎様","株式会社〇〇〇","営業部","帯広太郎","オビヒロタロウ","123-4567","株式会社〇〇〇","0120-111-111","000-000-000","obihirotaro.com","紙について","代表者様へのご提案【相談したい】"]
I made the code below, and I processed it line by line, but it stopped.
Current State Code:
fileobj=open(r"000.txt", encoding="utf_8")
while True:
line=fileobj.readline()
if line:
row_no+=1
print(row_no, ":", line)
else:
break
List the contents of the text file in Python and output it in CSV
If the specification is the same as the one mentioned in the comment, you can refer to @metropolis's answer in the above article and do the following:
#### To allow multiple lines of 'Contact Us' only read data once
with open(r'000.txt', encoding='utf-8') asf:
d=f.read()
#### Delete blank and blank lines at the end of the file
d = d.rstrip()
#### Create a dictionary by processing only the lines where ':' exists
records=dict(j.split(':') for jind.split('\n') if':'in j)
#### Cut out the last ':' and insert it into 'Contact details'
contents=d [(d.rindex(':')+1:]
records ['Contact Us'] = contents
#### list only the values in the dictionary values
result=list(records.values())
However, in the Python 3.10.4 environment in Windows (I don't know if it's caused by), the full-width blank character of By the way, a single quotation is used instead of a double quotation.\u3000
is \u3000
and is displayed as
d=f.read()
.
© 2024 OneMinuteCode. All rights reserved.