list - How to dislpay only the names of the users when opening /etc/group in Python? -
this code:
grouplist = open("/etc/group" , "r") grouplist f2: open("group" , "w+") f1: f1.write(f2.read()) f1.seek(0,0) command = f1.read() print print command
what command can use make display names of users without ":x:1000:"
you achieved target. little fix in code, here solution.
open("/etc/group" , "r") source: open("./group" , "w+") destination: destination.write(source.read()) source.seek(0,0) user in source.readlines(): print user[: user.index(':')]
nevertheless, show names, still copy original file.
this way write names in new file.
with open("/etc/group" , "r") source: open("./group" , "w+") destination: user in source.readlines(): u = user[: user.index(':')] destination.write('%s\n' % u) print u
Comments
Post a Comment