Note that there are some explanatory texts on larger screens.

plurals
  1. POinvalid syntax - python
    primarykey
    data
    text
    <p>I have a set of arguments and all of their dest is 'search_and', 'search_not', 'search_start', 'search_then', and 'filename'</p> <p>The code that I have to catch the error is</p> <pre><code> if ( options.filename is None) and ( (options.search_and is None) or (options.search_not is None) or (options.search_start is None) or (options.search_then is None): parser.error(usage) sys.exit() </code></pre> <p>It may seem like a silly mistake, can someone tell me what is going on?</p> <p>EDIT#1: I added the ')' at the end to make sure it closes properly but it still says invalid syntax.</p> <pre><code> if ( options.filename is None) and ( (options.search_and is None) or (options.search_not is None) or (options.search_start is None) or (options.search_then is None)): </code></pre> <p>EDIT#2: Here is what I have so far.</p> <pre><code> import optparse from OptionParser usage = "useage: %prog [options]" parser = OptionParser(usage) parser.add_option("-a", "--all", type="string", dest="search_and", help="find ALL lines in the file for the word1 AND word2") parser.add_option("-b", "--all", type="string", dest="search_not", help="search and find the lines that contain words1 not word2") parser.add_option("-c", "--all", type="string", dest="search_start", help="search and find a line that starts with word1 or word2") parser.add_option("-d", "--all", type="string", dest="search_then", help="search and find a line that has word1 followed by word2") parser.add_option("-f", "--file", type="string", dest="filename", help="file name" if ( options.filename is None) and ( (options.search_and is None) or (options.search_not is None) or (options.search_start is None) or (options.search_then is None)): </code></pre> <p>After the code is run by: python script.py -a hi bye</p> <p>I get invalid syntax with the if statement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload