Python 2:“继续”命令上的模糊语法错误

问题描述

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

它一直工作正常,直到(我认为)当我将第 27 行的打印功能),wksp 更改为 ) + wksp (它看起来更好)。

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

文件“h:/mystuff/python code/ExA_temp_code/variable_test_string.py”,第 29 行 继续 ^ 语法错误:无效语法 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. >> "),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. >> "),input_list
                yORn = raw_input("Is this correct y/n? >> ")
            continue
        else:
            print("Thank you,I will begin map generation. ")
            print ("...")
            print("...")
            print("...")
            break

解决方法

语法错误是第 28 行:

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

->

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

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