Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11525
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python': 0.08; '>>>>': 0.09; 'parsing': 0.09; 'subject:create': 0.09; 'am,': 0.12; 'def': 0.15; '16,': 0.15; 'subject:exists': 0.16; 'subject:user': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'language': 0.17; 'cheers,': 0.18; 'cc:no real name:2**0': 0.20; 'subject:not': 0.21; 'trying': 0.21; 'so.': 0.22; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'tue,': 0.23; 'received:209.85.213.46': 0.23; 'received:mail-yw0-f46.google.com': 0.23; 'aug': 0.24; 'subject: : ': 0.25; "i'm": 0.27; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.30; 'url:library': 0.31; 'chris': 0.32; 'there': 0.33; 'url:python': 0.36; 'doing': 0.36; 'another': 0.37; 'but': 0.37; 'think': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'user': 0.39; "it's": 0.40; 'skip:. 40': 0.67; '8bit%:93': 0.67; '"user': 0.84; '12:45': 0.84; 'sender:addr:chris': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Yoj+Fbbqj9bsycgk0czgOAzWZJF0syYXDzJH0jRnmHk=; b=aeLiHj0Y37djOoosjY0zLCdFSVJmIwmYgxOkQrhorBL4Bn6Oz1rXCROa+8TMo64euy zMPTKynVYx2RJ5GoG04d2fDpvv/A6jgiDC4tawlMpBKd88iUxeWOSB1ZYugTrvWk1zk/ muEiwA/oAEohv4Rm+bkF7OehKeVPXx/bQc83E= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <CA+zNewSOE1R4NRPQfg8edyDZ=ukwsCQnFkaTT9Ssu+5R5u5y9g@mail.gmail.com> |
| References | <CA+zNewSOE1R4NRPQfg8edyDZ=ukwsCQnFkaTT9Ssu+5R5u5y9g@mail.gmail.com> |
| Date | Tue, 16 Aug 2011 01:04:11 -0700 |
| X-Google-Sender-Auth | 5zZvg5AzHrlstbsSLEKYh4ovjd4 |
| Subject | Re: Linux : create a user if not exists |
| From | Chris Rebert <clp2@rebertia.com> |
| To | smain kahlouch <smainklh@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.46.1313481859.27778.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1313481859 news.xs4all.nl 23875 [2001:888:2000:d::a6]:45909 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:11525 |
Show key headers only | View raw
On Tue, Aug 16, 2011 at 12:45 AM, smain kahlouch <smainklh@gmail.com> wrote:
> 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
<snip>
> But i think it's a dirty way to do so. Is there another way to manage users
> with python ?
You can replace the /etc/passwd parsing with a call to pwd.getpwnam():
http://docs.python.org/library/pwd.html#pwd.getpwnam
Cheers,
Chris
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Linux : create a user if not exists Chris Rebert <clp2@rebertia.com> - 2011-08-16 01:04 -0700
csiph-web