I'm wanting a script that will store the first word from each line from an input file into a variable.
Current code only stores the last name.
def func(file):
global user
with open(file) as iFile:
for line in iFile:
string = line.split(',')
user = string[0]
func(sys.argv[1])
print user
The text file input is:
string1,string2,string3
string1,string2,string3
string1,string2,string3
I want the variable user to store the all of the string1's on each line from the text file.
userandusernamein your code. Last but not least, did you want a list of strings perhaps?user.append( string[0])