Reputation: 3557
I'm trying to split the lines in the data file I'm playing with. This was originally someone else's code, just trying to 'fix it'. They have it splitting on a semi-colon, but I realized that they actually need it to split on excess whitespace as well. I've singled my problem out to the expression in line 28. I was trying some suggestions from other users, but when I use a regex command I get an invalid literal for int()
warning. This is confusing because it works if I don't use the regex. Any suggestions? Thanks.
EDIT: Edited for full code link.
Upvotes: 1
Views: 549
Reputation: 133544
No, .split
with no arguments is the only form that splits on any whitespace.
Use a regex like this:
re.split(r'[\s;]+', text)
Upvotes: 5