how to make a script for this case?
Chris Barker
Chris.Barker at noaa.gov
Thu Aug 15 18:58:50 EDT 2002
D99 wrote:
> I am using linux platform and have a file which contain the
> following data
>
> #####################################################
> a:admin99
> b:admin at company.com
> password:123321
> e:456789
-etc:
lummert wrote:
> read the file line by line with a loop
for line in file.xreadlines()
> using regular expressions like "^a:(.*)", "^b:(.*)",
> "^password:(.*)", "^e:(.*)".
I'd not bother with the REs. You data looks pretty simply formated, so
you can do:
key,data = line.split(":",1) # or something like that
if key == "a":
alias = data
elif key == ...
> u should be sure about the rules, your input file was
> written with (e.g one newline -> new field, two
> newlines -> new dataset).
absolutely. you have to know that the format is consistent
> save strings found with re's to an appropriate
> sequence and write to output file with an
you might want to build a dictionary like:
people[account] = (alias,possword,.....
then you can sort the keys of the dict, and output in order if you want.
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Python-list
mailing list