select lines in python

Krishnakant hackingkk at gmail.com
Wed Jul 15 04:22:24 EDT 2009


On Tue, 2009-07-14 at 23:03 +0530, amrita at iisermohali.ac.in wrote:
> Dear all,
> 
> Can anyone tell me that suppose i have a file having content like:
> 
>     _Atom_name
>       _Atom_type
>       _Chem_shift_value
>       _Chem_shift_value_error
>       _Chem_shift_ambiguity_code
>      1     1   PHE       H     H      8.49     0.02     1
>      2     1   PHE       HA    H      4.60     0.02     1
>      3     1   PHE       CA    C     57.83      0.3     1
>      4     2   LEU       H     H      8.23     0.02     1
>      5     2   LEU       HA    H      4.25     0.02     1
>      6     2   LEU       HB2   H      1.54     0.02     1
>      7     3   ASP       H     H      8.10     0.02     1
>      8     3   ASP       HA    H      4.52     0.02     1
>      9     3   ASP       HB2   H      2.65     0.02     1
> stop
> 
> 
> now what i want that instead of copying all the lines it will just write
> the information about PHE and ASP then how i acn do that using python
> programming.Kindly tell me the command for that.

Dear Amrita,
No one will tell you commands for your program.
We can give you logic and the way to implement it.
It is recommended that you write the code your self.
For our problem you keep a list and do a readlines() function and get
the content in your list variable.
then start looping through that list like for line in lines: where the
lines variable is your list.
Now keep comparing each line against your expected phrase and the moment
you find one, do the actions you need such as writing to a file.

happy hacking.
Krishnakant.
 




More information about the Python-list mailing list