I'm having difficulties splitting up a string (that I read from a textfile) into three parts in a list (that I will then use in a function).

The issue I'm having is that the 3rd element of the string is not always one word (sometimes its multiple words, but I want them to be counted as ONE)
ex for one line:
1200 90 Class
ex for another line:
1900 120 Date Night

I can get the first instance to work just fine by using split() on my string, but when I try the second instance, I get '1900' , '120', 'Date', 'Night'...when I want it to read '1900', '120', 'Date Night'.

Is there a way to specify the split to be a space for the first two parts of the string and then the third part is everything up until the new line?

Or how how should I go about this?

Thank you

You can use a second argument to split

>>> "1900 120 Date Night".split(" ", 2)
['1900', '120', 'Date Night']

Otherwise, use a regular expression (the re module).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.