python: create variable from loop that reads text file and extracts single column -


i'm new python , hoping assistance please.

i have small script reads text file , prints fist column using loop:

list = open("/etc/jbstorelist") column in list:     print(column.split()[0]) 

but take lines printed in loop , create 1 single variable it.

in other words, text file /etc/jbstorelist has 3 columns , want list first column, in form of single variable.

any guidance appreciated. thank you.

since you're new python may want come , refernce answer later.

#don't override python builtins. (i.e. don't use `list` variable name) list_ = []  #use statement when opening file, automatically close if #for when exit block open("/etc/jbstorelist") filestream:     #when loop on list you're not looping on columns you're     #looping on rows or lines     line in filestream:         #there side effect here may not aware of. calling `.split()`         #with no arguments split on amount of whitespace if         #want split on single white space character can pass `.split()`         #a <space> character `.split(' ')`         list_.append(line.split()[0]) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -