remove last 76 letters from string

Xavier Ho contact at xavierho.com
Thu Aug 6 04:44:45 EDT 2009


On Thu, Aug 6, 2009 at 6:28 PM, Iain King <iainking at gmail.com> wrote:

> >      print >>nucleotides, seq[-76]
>
> >      last_part = line.rstrip()[-76 : ]
>
> You all mean:   seq[:-76]   , right? (assuming you've already stripped
> any junk off the end of the string)
>

I think so, probably both of them typo'd. (What are the probabilities of
that?)

It looks to me like you have two lines per DNA sequence. What you could do
instead, is to alternate the line reading with a with statement, as
suggested by Jan. Although I don't know why he's nesting two of them.
(explanation would be neat.)

Here's my version of approach, given the sample data the OP posted:

with open('NodeList.txt', 'r') as file:
    for line in file.readlines():
        line = line.rstrip()
        if line[0] == '>':
            # Do for New DNA Sequence
            # ...
        else:
            line = line[:-76]
            # ...

Should do what you need.

Best regards,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
Website: http://xavierho.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090806/5946d51f/attachment.html>


More information about the Python-list mailing list