【问题标题】:Python 2: Vague syntax Error on "continue" command [closed]Python 2:“继续”命令上的模糊语法错误[关闭]
【发布时间】:2021-04-30 19:14:04
【问题描述】:

我正在编写一个在 ESRI arcmap 10.8 中创建地图的脚本。我目前只创建了创建地理数据库的脚本并询问创建地图所​​需的基本信息。脚本询问信息,然后循环询问用户信息是否正确。

直到(我认为)我将第 27 行的打印功能从 )、wksp 更改为 ) + wksp 之前它工作正常(只是看起来更好)。

现在我收到一条错误消息:

文件“h:/mystuff/python 代码/ExA_temp_code/variable_test_string.py”,第 29 行 继续 ^ SyntaxError:无效的语法 PS C:\Users\kvidal.IDIR>

这是我的代码。请记住,我还是 python 的新手,并且这个脚本还没有在我的 raw_input 行中清理。我在第 29 行的左侧写了 29 以便于查找。我正在使用 Visual Studio 代码。

    import time, os.path, arcpy
    from os import path
    #   Asking for the information that I will use in the sql query 
    #   that will be used to create the tenure feature class
    print("""NOTE: Please make sure your workspace path goes to your working
    folder. Use file explorer or something that allows you to copy the path then
    paste the path below. This will prevent you typing an incorrect path.\n""")
    #   Pause the program for 2s to allow user to realize that there is 
    #   something to read before the input.
    time.sleep(2)
    
    #   Setting the variables
    wksp = raw_input("Please enter the path to the working folder. >> ")
    arcpy.env.workspace= r"wksp"
    print("You have input as your file path: ")+ wksp 
    chk_wksp = raw_input("Please check your path and confirm y/n. >>")
    while True:
        while True:
            if chk_wksp in ('y', 'n'):
                break
            chk_wksp = raw_input("That is not a valid response Please enter y/n. >> ")
        if chk_wksp == 'y':
            print("Thank you")
            break
        else:
            wksp = raw_input("Please re-enter the path. >> ")
            print("Is this the correct path? >> ") + wksp
            chk_wksp = raw_input("Please confirm y/n: >>" 
29          continue
    
    gdb = raw_input("Please enter the new geodatabase name. >> ")
    arcpy.CreateFileGDB_management(wksp, gdb, "10")
    
    gdb = raw_input("What do you want to name the geodatabase? >> ")
    permitType = raw_input("Is this a road permit y/n. >> ")
    fileNo = raw_input("What is the file number you are looking up? >> ")
    
    #   here I am saying if this is a road permit (permitType = y)
    #   then ask for the section names. if it is not a road permit
    #   then ask for block names
    if permitType is "y":
        secNo = raw_input("Please enter the road sections divided by a space. >> ")
    else:
        secNo = raw_input("Please enter the cut blocks divided by a space. >> ")
    
    #   Here I am splitting the list into individual strings for the sql
    #   sequence I will use for the select too.
    input_list = secNo.split()
    
    #   Here I am confirming that the information is correct.
    print ("Please confirm that this is correct. >> "),fileNo, " ",input_list
    yORn = raw_input("Is this correct y/n? >> ")
    #   This is where I want to look at their answer and provide 
    #   an appropriate answer.
    while True:
        while True:
            if yORn in ('y', 'n'):
                break
            print("invalid input")
            yORn = raw_input("Please select \"y\" if correct or \"n\" if incorrect.")
        if yORn == 'n':
            fileNo = raw_input("What is the file number you are looking up? >> ")
            if permitType is "y":
                secNo = raw_input("Please enter the road sections divided by a space. >> ")
                input_list = secNo.split()
                print ("Please confirm that this is correct. >> "),fileNo, " ",input_list
                yORn = raw_input("Is this correct y/n? >> ")
            else:
                secNo = raw_input("Please enter the cut blocks divided by a space. >> ")
                input_list = secNo.split()           
                print ("Please confirm that this is correct. >> "),fileNo, " ",input_list
                yORn = raw_input("Is this correct y/n? >> ")
            continue
        else:
            print("Thank you, I will begin map generation. ")
            print ("...")
            print("...")
            print("...")
            break

【问题讨论】:

  • 嗨,continue 之前的行似乎缺少右括号。
  • 问题是上面的未闭合括号。我投票结束这只是一个错字
  • 总是上面一行缺少右括号。

标签: syntax-error python-2.x continue


【解决方案1】:

语法错误是第 28 行:

chk_wksp = raw_input("Please confirm y/n: >>"
continue

->

chk_wksp = raw_input("Please confirm y/n: >>")
continue

你应该考虑使用 Python3,因为 Python2 已经结束了

【讨论】:

  • 谢谢。我盯着这段代码看了很久,它是一个括号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-23
  • 2021-10-13
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多