Fantastic, <div>Thanks Hugo that makes 100% sense now! Testing both regex for including / and doing split and when done throwing both away and using the default module.</div><div><br></div><div>Regards<br><br><div class="gmail_quote">
On Wed, Oct 12, 2011 at 2:49 PM, Hugo Arts <span dir="ltr">&lt;<a href="mailto:hugo.yoshi@gmail.com">hugo.yoshi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Wed, Oct 12, 2011 at 3:41 PM, Gerhardus Geldenhuis<br>
&lt;<a href="mailto:gerhardus.geldenhuis@gmail.com">gerhardus.geldenhuis@gmail.com</a>&gt; wrote:<br>
&gt; Hi<br>
&gt; I wrote the following code:<br>
&gt;   f = open(&#39;/etc/passwd&#39;, &#39;r&#39;)<br>
&gt;   users = f.read()<br>
&gt;   userelements = re.findall(r&#39;(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)&#39;,<br>
&gt; users)<br>
&gt;   print userelements<br>
&gt;   for user in userelements:<br>
&gt;     (username, encrypwd, uid, gid, gecos, homedir, usershell) = user  #<br>
&gt; unpack the tuple into 7 vars<br>
&gt;     print username<br>
&gt;<br>
&gt; but I get no results so my parsing must be wrong but I am not sure why.<br>
&gt; Incidentally while googling I found the<br>
&gt; module <a href="http://docs.python.org/library/pwd.html" target="_blank">http://docs.python.org/library/pwd.html</a> which I will eventually use<br>
&gt; but I am first curious to fix and understand the problem before I throw away<br>
&gt; this code.<br>
&gt; Regards<br>
&gt;<br>
<br>
</div></div>the homedir and usershell parts are paths. Paths will contain slashes.<br>
The \w character class captures only [A-Za-z0-9_],  that is, letters,<br>
numbers, and the underscore. That means slashes will not match, and so<br>
the entire match fails.<br>
<br>
On another note, the structure of the /etc/passwd file is pretty<br>
simple, I don&#39;t think you need regexes. Simply use split:<br>
<br>
users = f.readlines()<br>
for user in users:<br>
    (username, encrypwd, uid, gid, gecos, homedir, usershell) = user.split(&#39;:&#39;)<br>
<br>
HTH,<br>
<font color="#888888">Hugo<br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>Gerhardus Geldenhuis<br>
</div>