'SyntaxError': 'return' outside function?
I have a super large file containing more than 1000 FASTA sequences merged. I want to extract the list of accession IDs from the file. But the following code got me an error. Can anybody tell me why and how to solve this? All my sequences contains a header file like this,
>NZ_QJRW01000001 (<'gap type:'>, <'description'>, 'gap start:', XXXXX, 'gap end:', XXXXX)**
Here is a snippet from the python script I have tried,
• 1,528 views
•
link
1 answer
Because the return keyword is only allowed inside function definitions:
def biggerthanfive(x):
if x > 5:
return True
else:
return False
In your example, you are only using a loop that you can break, but not return from. You can also write it way more succinct.
• 0 views
•
link
Log in to answer this question.
if you want to stop the loop at the first time, there is no match use "break". if you want to skip the line with no match and continue use "continue"
Any particular reason you are doing this with python (other than perhaps learning python)? Or is there more to this script than just accession recovery. That can be done with a simple
grepandcutotherwise.