0

I have a string called new_file that I read from a file with these contents:

;ASP718I
;AspA2I
;AspBHI 0 6 9 15 ...
;AspCNI
;AsuI 37 116 272 348
...

I am using name = raw_input ("enter the enzyme ") to get data from the user and I am trying to print the corresponding fields from the above file (new_file).

For the input ;AspBHI I'd like the program to print the corresponding line from the file:

;AspBHI 0 6 9 15 ...

How can I achieve this?

6
  • So, What's the problem? where did you get stuck ? Commented Sep 14, 2012 at 5:40
  • I dont know how to find the string after the user input is given .how will i be able to achieve ;AspS9I 37 116 272 348 Commented Sep 14, 2012 at 5:43
  • 2
    start with tutorialspoint.com/python/python_files_io.htm then check out stackoverflow.com/questions/3351218/python-string-match and you will have your soloution.... Commented Sep 14, 2012 at 5:52
  • how can I take the user input , search the string from the " new_file" and print it in a text file Commented Sep 14, 2012 at 5:57
  • If the user gives an input ;AspS9I , how can i search and print ;AspS9I 37 116 272 348 Commented Sep 14, 2012 at 6:00

1 Answer 1

1

This is a start:

db = dict((x.split(" ")[0], x) for x in new_file.split("\n"))
name = raw_input("enter the enzyme ")
print db[name]

Also try to be nice next time, people might help you with more enthusiasm and even explain their approach.

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

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.