May-08-2020, 04:30 PM
(This post was last modified: May-08-2020, 04:59 PM by kintarowonders.)
I am writing a method and it outputs unexpected results. It is supposed to break up some strings and create lists from them. Yet the lists don't contain everything I expected.
Here is my code:
Here is my code:
def get_group_users():
f = open('group.example', 'r') #f is file
users = [] #obvious
for l in f:
g = l.split(':') #g is group
if (g[0] == "users"):
for ul in g[3]: #ul is userline
gu = ul.split(',') #gu is groupuser
for u in gu: #u is user
users.append(u)
return usersThis is the group.example file...users:x:100:kintaro,john,autossh,test portage:x:250:portageThis is the output which I did not expect...
>>> import shadowssh >>> shadowssh.get_group_users() ['k', 'i', 'n', 't', 'a', 'r', 'o', '', '', 'j', 'o', 'h', 'n', '', '', 'a', 'u', 't', 'o', 's', 's', 'h', '', '', 't', 'e', 's', 't', '\n']The output I want...
['kintaro', 'john', 'autossh', 'test']
