SEQanswers

Go Back   SEQanswers > General



Similar Threads
Thread Thread Starter Forum Replies Last Post
Miso/Sashimi python error Hubertus RNA Sequencing 1 03-20-2014 12:57 PM
Error running oases_pipeline python script InesSoriguer Illumina/Solexa 4 05-21-2013 02:10 AM
Error in DESeq code drdna Bioinformatics 2 11-27-2012 01:22 PM
DEXSeq python script error message shilez Bioinformatics 4 09-08-2011 10:55 PM
GATK IndelRealigner Error:Code Exception HongxiangZheng Bioinformatics 1 12-14-2010 07:21 PM

Reply
 
Thread Tools
Old 10-22-2014, 08:14 AM   #1
bio_informatics
Senior Member
 
Location: USA

Join Date: Nov 2013
Posts: 182
Default Error while python code terse

Hi Members,

I am having a hard time with python code, making it terse. One liners. I see a lot on stackoverflow using lambda. I am unable to cope up with it.

Would really appreciate any input in this regard.

So here is how I am running the file.
Quote:
python read_pdb_file.py 1iw6.pdb 1m0l.pdb
Code:
def checkExtension2(*file_name):
# trying to shrink the code..
    [print i+" doesn't end with .pdb" for i in file_name if not i.endswith(".pdb")]


def checkExtension(*file_name): # this runs fine
    for i in file_name: 
        if not i.endswith(".pdb"):
            print i+" doesn't end with .pdb"
            sys.exit(1)

if __name__=="__main__":
    checkExtension2(sys.argv[1],sys.argv[2])
Error:
[print i+" doesn't end with .pdb" for i in file_name if not i.endswith(".pdb")]
^
SyntaxError: invalid syntax

Please advise.
bio_informatics is offline   Reply With Quote
Old 10-22-2014, 10:36 AM   #2
cliffbeall
Senior Member
 
Location: Ohio

Join Date: Jan 2010
Posts: 144
Default

It doesn't know what to do with the print inside the list comprehension.

If you really want it in one line, how about:

To print the first one:
Code:
print [i+" doesn't end with .pdb" for i in file_name if not i.endswith(".pdb")][0]
To print all:
Code:
print '\n'.join([i+" doesn't end with .pdb" for i in file_name if not i.endswith(".pdb")])

Last edited by cliffbeall; 10-22-2014 at 10:52 AM. Reason: To put in 2nd case
cliffbeall is offline   Reply With Quote
Old 10-22-2014, 11:18 AM   #3
bio_informatics
Senior Member
 
Location: USA

Join Date: Nov 2013
Posts: 182
Default

Thanks for replying.
Could you please elaborate why and what is happening?
I work a lot on file parsing. A lot of code is to check/verfify, and I want to polish my coding on them.
bio_informatics is offline   Reply With Quote
Reply

Tags
python

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 05:44 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO