Formatting Results so that They Can be Nicely Imported into a Spreadsheet.

John Machin sjmachin at lexicon.net
Sat Aug 4 21:13:32 EDT 2007


On Aug 5, 9:35 am, SMERSH009 <SMERSH0... at gmail.com> wrote:
> Hi All.
> Let's say I have some badly formatted text called doc:
>
> doc=
> """
> friendid
> Female
>
>                             23 years old
>
>                             Los Gatos
>
>                             United States
> friendid
> Male
>
>                             24 years old
>
>                             San Francisco, California
>
>                             United States
> """
>
> How would I get these results to be displayed in a format similar to:
> friendid;Female;23 years old;Los Gatos;United States
> friendid;Male; 24 years old;San Francisco, California;United States
>
> The latter is a lot easier to organize and can be quickly imported
> into Excel's column format.
>

You write a script to read your input file and write it out either in
CSV format, using the Python csv module, or just use
';'.join(output_row) if you are sure that there are no ';' characters
in the data.

Is this a homework question?




More information about the Python-list mailing list