How can I check how long a line is in python?

Viewed 22

The plan is for the user to paste a huge list, that will be divided in a lot of lines, The huge variable will be recorded as "raw_text", I want to take out the first line, which will be saved as "line_to_convert", analyse that one and then start again, but for that I need to know how long a line is

1 Answers

Does len(raw_text.split()[0]) work for you?

In general, what you need is str.split().

str.split(sep=None, maxsplit=- 1)

Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).

Related