Python Forum
Syntax error? I don't see it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error? I don't see it
#1
Python 3.9.2

I keep getting a syntax error and for the life of me, I don't see it:

Quote:root@piZERO:~/bin# ./npwAgent.py
File "/root/bin/npwAgent.py", line 559
getCLarguments()
^
SyntaxError: invalid syntax

From the file (lines 558 and 559):

    # Get command line arguments.
    getCLarguments()
Here's what it calls:

def getCLarguments():
    """
    Get command line arguments.  There are three possible arguments
        -d turns on debug mode
        -v turns on verbose mode
        -p sets the sensor query period
        -c sets the chart update period
    Returns: nothing
    """
    global debugMode, verboseMode, dataRequestInterval, chartUpdateInterval

    index = 1
    while index < len(sys.argv):
        if sys.argv[index] == '-v':
            verboseMode = True
        elif sys.argv[index] == '-d':
            debugMode = True
            verboseMode = True
        elif sys.argv[index] == '-p':
            try:
                dataRequestInterval = abs(int(sys.argv[index + 1]))
            except:
                print("invalid sensor query period")
                exit(-1)
            index += 1
        elif sys.argv[index] == '-c':
            try:
                chartUpdateInterval = abs(int(sys.argv[index + 1]))
            except:
                print("invalid chart update period")
                exit(-1)
            index += 1
        else:
            cmd_name = sys.argv[0].split('/')
            print("Usage: %s [-d | v] [-p seconds] [-c seconds]" \
                  % cmd_name[-1])
            exit(-1)
        index += 1
##end def
Reply
#2
What are the lines between 500 and 570?
Reply
#3
The error syntax error is probably on a previous line, or at least starts on a previous line. When I get a mysterious error I cannot see, I line comment out the line in question and see if the error moves to the next line. If it does, the error is somewhere earlier in the code.
Reply
#4
I have to admit I am new to Python 3.9.x and this is someone else's code

(Jan-15-2023, 07:20 PM)Gribouillis Wrote: What are the lines between 500 and 570?

def getCLarguments():
    """
    Get command line arguments.  There are three possible arguments
        -d turns on debug mode
        -v turns on verbose mode
        -p sets the sensor query period
        -c sets the chart update period
    Returns: nothing
    """
    global debugMode, verboseMode, dataRequestInterval, chartUpdateInterval

    index = 1
    while index < len(sys.argv):
        if sys.argv[index] == '-v':
            verboseMode = True
        elif sys.argv[index] == '-d':
            debugMode = True
            verboseMode = True
        elif sys.argv[index] == '-p':
            try:
                dataRequestInterval = abs(int(sys.argv[index + 1]))
            except:
                print("invalid sensor query period")
                exit(-1)
            index += 1
        elif sys.argv[index] == '-c':
            try:
                chartUpdateInterval = abs(int(sys.argv[index + 1]))
            except:
                print("invalid chart update period")
                exit(-1)
            index += 1
        else:
            cmd_name = sys.argv[0].split('/')
            print("Usage: %s [-d | v] [-p seconds] [-c seconds]" \
                  % cmd_name[-1])
            exit(-1)
        index += 1
##end def

def main_setup():
    """
    Handles timing of events and acts as executive routine managing
    all other functions.
    Parameters: none
    Returns: nothing
    """
    global power1, battemp, ambtemp, sms

    signal.signal(signal.SIGTERM, terminateAgentProcess)
    signal.signal(signal.SIGINT, terminateAgentProcess)

    # Log agent process startup time.
    print('===================\n'\
          '%s starting up node power agent process' % \
                  (getTimeStamp())
Reply
#5
The definition of the getCLarguments() function is irrelevant to the SyntaxError. The error is near the point where the interpreter indicates the error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  POST Syntax error amplay 0 656 Aug-07-2024, 02:43 PM
Last Post: amplay
  is this really a syntax error? Skaperen 4 1,640 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 1,125 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 6,568 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 1,334 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 5,041 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 3,035 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 2,677 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error tibbj001 2 1,860 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 4,015 Sep-17-2022, 04:09 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020