Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange output
#1
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:
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 users
This is the group.example file...
users:x:100:kintaro,john,autossh,test
portage:x:250:portage
This 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']
Reply


Messages In This Thread
Strange output - by kintarowonders - May-08-2020, 04:30 PM
RE: Strange output - by buran - May-08-2020, 04:40 PM
RE: Strange output - by kintarowonders - May-08-2020, 05:01 PM
RE: Strange output - by bowlofred - May-08-2020, 05:13 PM
RE: Strange output - by kintarowonders - May-08-2020, 05:16 PM
RE: Strange output - by buran - May-08-2020, 05:18 PM
RE: Strange output - by buran - May-08-2020, 05:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  strange output KaliLinux 2 2,007 Nov-19-2019, 09:24 AM
Last Post: KaliLinux
  Strange output with regular expressions newbieAuggie2019 1 1,957 Nov-04-2019, 07:06 PM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020