current position:Home>Using function to store and read text file test TXT

Using function to store and read text file test TXT

2022-02-02 12:21:07 CSDN Q & A

A text file test txt One row storage 5 The integers are as follows ,1,3,56,67,34, Numbers are separated directly by spaces ,
To read these integers , How to use functions to realize .




Refer to the answer 1:

txt Document and python The files are in the same directory

with open('1.txt','r') as f:    file_str = f.read()    data = [int(i) for i in file_str.split() if i]print(data)

img

img




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021221059609.html