[Tutor] small program, but I'm very confused

Melissa K. Surprenant msurprenant@siumed.edu
Tue Nov 5 17:10:02 2002


This is a multi-part message in MIME format.
--------------697C6D47E45A6C0D19405017
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I appreciate all the help.  I have made the recommended changes, and I still get
the error.  I suspected I might have been missing something with the re.findall,
but I didn't know what it was.

It is already one class period late (25% off), so I'm just going to turn it in
this way.

Everyone, thanks again!

Scott Widney wrote:

> > #creates the file
> > f=open('/tmp/listofusers', 'w')
>
> Sidebar: If you are only writing to the file in this process, and you intend
> to close it at the end of the process, then the following three lines are
> unnecessary
>
> > f.close()
> > #opens the file for writing
> > f=open('/tmp/listofusers', 'r+')
>
> Correct me if I am wrong here...:
>
> > # searches the password file, hopefully should write the second regexp to
> >   thefile
> >
> > for y in loginsList:
> >
> re.findall(('^loginsList[y]:x:[0-9]{4}:[0-9]{2,3}:)([A-Za-z]\s[A-Za-z])
> >                (.*?)(/n)','/etc/passwd')
>
> ...but it looks like this is discarding the results of re.findall (not
> assigning it to anything)...
>
> >     f.write('\2\n')
>
> ...and this is trying to write the hexadecimal value x02 and a newline to
> the file. Using \2 only applies within the regular expression. If you assign
> the results of re.findall() to a list variable, the second element should
> correspond to the second group in you regex.
>
> ### untested
> for y in loginsList:
>     groups = re.findall(('^loginsList[y]:x:[0-9]{4}:[0-9]{2,3}:)
>                         ([A-Za-z]\s[A-Za-z])(.*?)(/n)','/etc/passwd')
>     f.write("%s\n" % (groups[2],))
> ### or something like that
>
> Scott
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




--------------697C6D47E45A6C0D19405017
Content-Type: text/x-vcard; charset=us-ascii;
 name="msurprenant.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Melissa K. Surprenant
Content-Disposition: attachment;
 filename="msurprenant.vcf"

begin:vcard 
n:Surprenant;Melissa
tel;pager:217-467-3807
tel;fax:217-545-0192
tel;work:217-545-2132
x-mozilla-html:FALSE
org:SIU School of Medicine;Education & Curriculum
adr:;;801 N. Rutledge;Springfield;IL;62794-9622;United States
version:2.1
email;internet:msurprenant@siumed.edu
fn:Melissa K. Surprenant
end:vcard

--------------697C6D47E45A6C0D19405017--