Hi all,

I'm learning the python language and i'm trying to create a user if it is
not found in the system.
I figured it out by doing the following thing :

>>> def finduser(user):
...     for line in open('/etc/passwd'):
...             if line.startswith(user):
...                     print user, "user exists"
...                     return True
...     return False

>>> if not finduser('myuser'):
...     print "Creating user myuser"
...     os.system('/usr/sbin/useradd myuser')

But i think it's a dirty way to do so. Is there another way to manage users
with python ?

Thank you :)
Sam
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to