View Single Post
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