944,183 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1177
  • Python RSS
Apr 20th, 2006
0

program to read print who you are, based on your user account in/etc/passwd.

Expand Post »
Python Syntax (Toggle Plain Text)
  1. import posix
  2. import string
  3. uid = `posix.getuid()`
  4. passwd = open('/etc/passwd')
  5. for line in passwd.readlines():
  6. rec = string.splitfields(line, ':')
  7. if rec[2] == uid:
  8. print 'hello', rec[0],
  9. print 'mind if we call you bruce?'
  10. break
  11. else:
  12. print "I can't find you in /etc/passwd"
  13. :)
Last edited by alc6379; Apr 22nd, 2006 at 9:13 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sharma_vivek82 is offline Offline
18 posts
since Mar 2006
Apr 20th, 2006
0

Re: program to read print who you are, based on your user account in/etc/passwd.

Indent it correctly, download posix and give it a try.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Apr 22nd, 2006
0

Re: program to read print who you are, based on your user account in/etc/passwd.

Looks like it should work, assuming you have posix there.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC