Search code examples
pythonstringcsvstrip

Saving stripped text from csv file as a string object with Python


I'd like to be able to save text from a file that I had to retrieve from online and decompress (part of an assignment), in order to carry on with my next steps. Specifically, I'd like to save it as its own string object.

I can see the exact text I need when I print it in the following manner.

for line in seq:
    print(line.strip())

I just can't seem to figure out how to assign the stripped text to a variable.


Solution

  • You could use a list, and append each line of text to the list.

    my_text = []
    for line in seq:
        my_text.append(line.strip())