954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Parsing a space delimited file

Hi,

I'm looking to break up a file with space delimiters. Its really just a list of numbers with spaces in between them, and I need to put each of the numbers in a list as separate entries. However, they are all on one line like so:

5 7 6 35 346 245 etc.

I have been told there is a command for this (like split or tokenize) but I cannot find it. Thanks!

echellwig
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
>>> line_of_numbers = "5 7 6 35 346 245"
>>> list_of_numbers = line_of_numbers.split()
>>> print list_of_numbers
['5', '7', '6', '35', '346', '245']
>>>
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 
numbers="12560 36520 1763"
numberlist= numbers.split()
print("First number is %i." % numberlist[0])
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

Thanks!

echellwig
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: