linux - List of empty string returns non-zero length in python -


this question has answer here:

i have list of strings returned after command execution, split on '\n'.

listname = output.decode('utf8').rstrip().split('\n') 

when print using print(listname), get

[''] 

clearly it's list containing empty string

because of getting len(listname) 1.

how remove empty string

i think looking for:

filter(none,output.decode('utf8').rstrip().split('\n')) 

in details:

>>> filter(none, ["ford", "nissan", ""]) ['ford', 'nissan'] 

p.s. in python 3+ filter returns iterator, use list(filter(..)).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -