![]() |
wrapping problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: wrapping problem (/thread-19225.html) |
wrapping problem - ibaad1406 - Jun-19-2019 I have a text file which contain header as well as data section. I want to read the data section but when i wrap the data into 582 character and check the length of data i got different length.please help me to sort out this problem. I am attaching the file from textwrap import wrap filepath='/media/ibaad/IBAAD/ab010120.18n' with open(filepath) as fp: data=fp.read() # read all the data into single string data1=data.split('END OF HEADER') # split a string into list data_section=data1[1] data_section=data_section[1:] data_section=wrap(data_section,582) print(len(data_section[0])) print(len(data_section[1])) RE: wrapping problem - mcmxl22 - Jun-19-2019 could you try this? with open(filepath, 'r') as fp: data=fp.readlines() RE: wrapping problem - Gribouillis - Jun-19-2019 The documentation says The no more than 'width' columns could be the answer to your question. Textwrap.wrap() doesn't promise that every line has the same length.
|