0

I'm using somebody else's code that stores a sequence in an array in python:

blah=array(<Sequence: 2TPS (2TPS refined (label=2TPS) refined (label=2TPS, rowocc>=0.8, colocc>=0.8)[0]; length 196; 196 residues and 0 gaps)>, dtype=object)

I can print the sequence using the following:

print blah
    SVYFIMGSNNTKADPVTVVQKALKGGATLYQFREKGLTGEARIKFAEKAQAACREAGVPFIVNDDVELALNLKADGIHIGQEDANAKEVRAAIGDMILGVSAHTMSEVKQAEEDGADYVGLGPIYPTETKKDTRVQGVSLIEAVRRQISIPIVGIGGITIDNAAPVIQAGADGVSMISAISQAEDPESAARKFREE

However, I want to be able to call this sequence and save it to a text file without using the "print" function. I've tried blah[0] etc, but nothing works.

1
  • This just says "invalid syntax". Are you using numpy, scipy or something else ? Commented May 29, 2014 at 8:33

3 Answers 3

1

It seems your array is a numpy array (dtype...)

Have you already tried just parsing it to a string?

result = str(blah)

or

result = blah.tostring()

another option is to parse it to a list

result = list(blah)

Now you should be able to use the variable result and write it to a file or do whatever you want.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't you mean array.tofile() or looking at Bob's answer numpy.ndarray.tofile()?

Comments

0

I assume that you want to save a python list to a text file and you want to read it later.

You can write list to text file as:

with open('filename', 'wb') as a:
        pickle.dump(blah, a)

You can read the file and store each lines in a list:

with open('filename', 'rb') as a:
    blah = pickle.load(a)

you can access your data like: blah[0]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.