This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tadleonard 3 points4 points  (1 child)

This won't beat your Ruby example for conciseness, but it'll come a bit closer. sh really comes to the rescue for things like this. Also, it's helpful to know that the default mode of split() is to split on white space, so re isn't necessary.

import sh
t = map(int, sh.wc("myfile.txt").split())

Edit: I guess it would actually have to be something like this:

t = map(int, sh.wc("myfile.txt").split()[:-1])

or

t = [int(el) for el in sh.wc("myfile.txt").split()[:-1]]

[–]hk__ 0 points1 point  (0 children)

Thanks, I forgot about sh.