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
  Syntax error for "root = Tk()" dlwaddel 15 1,183 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 388 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,589 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,231 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,318 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error tibbj001 2 893 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,853 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,364 May-18-2022, 06:50 AM
Last Post: ibreeden
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 1,964 Feb-21-2022, 08:58 AM
Last Post: deanhystad
  Query Syntax Error hammer 2 1,627 Jan-03-2022, 02:30 PM
Last Post: hammer

Forum Jump:

User Panel Messages

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