Dec-25-2018, 05:13 PM
Hi,
I am trying to read data from a text file and split it into six parts.
I the code is not able to perform intended function for reasons unidentified.Please help.
The text file has below data:
Data_Val5 12/25/2018 15:15 406 1 43459635537
Data_Val6 12/25/2018 15:15 379 1 43459635537
Data_Val7 12/25/2018 15:15 352 1 43459635537
Data_Val8 12/25/2018 15:15 325 1 43459635537
Data_Val9 12/25/2018 15:15 298 1 43459635537
Data_Val10 12/25/2018 15:15 270 1 43459635537
Data_Val1 12/25/2018 15:15 514 1 43459635537
The code is as below:
I am trying to read data from a text file and split it into six parts.
I the code is not able to perform intended function for reasons unidentified.Please help.
The text file has below data:
Data_Val5 12/25/2018 15:15 406 1 43459635537
Data_Val6 12/25/2018 15:15 379 1 43459635537
Data_Val7 12/25/2018 15:15 352 1 43459635537
Data_Val8 12/25/2018 15:15 325 1 43459635537
Data_Val9 12/25/2018 15:15 298 1 43459635537
Data_Val10 12/25/2018 15:15 270 1 43459635537
Data_Val1 12/25/2018 15:15 514 1 43459635537
The code is as below:
#open file dataFile = open('C:\\Users\\USER1\\Desktop\\PyWork\\DataFile_1.txt') for dataStr in dataFile: (d1,d2,d3,d4,d5,d6)=dataStr.split()#split data into six parts. #close file dataFile.close()The output is as below:
Output:"C:\Users\USER1\Google Drive\Books\Python\Task\TASK1\venv\Scripts\python.exe" "C:/Users/USER1/Google Drive/Books/Python/Task/TASK1/KTP700_Logfile_Mgr.py"
Traceback (most recent call last):
File "C:/Users/USER1/Google Drive/Books/Python/Task/TASK1/KTP700_Logfile_Mgr.py", line 6, in <module>
(d1,d2,d3,d4,d5,d6)=dataStr.split()
ValueError: not enough values to unpack (expected 6, got 1)
Process finished with exit code 1