文件wri出错

2024-04-25 11:57:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到一个错误,在(w)处意外缩进打开

    def run():
        """execute the TraCI control loop"""
        traci.init(PORT)#
        programPointer = len(PROGRAM)-1
        step = 0#
    with open("harsh1.txt","w") as harsh1:
        print >> harsh1, """hello"""
    while traci.simulation.getMinExpectedNumber() > 0:#
        traci.simulationStep()#
        programPointer = min(programPointer+1, len(PROGRAM)-1)
        no = traci.inductionloop.getLastStepVehicleNumber("0")#"0" is the detector id
        if no > 0:#
            programPointer = (0 if programPointer == len(PROGRAM)-1 else 3)
            traci.trafficlights.setRedYellowGreenState("0", PROGRAM[programPointer])#
        step += 1#
    traci.close()#
    sys.stdout.flush()#

我用相扑模拟器进行微观交通模拟


Tags: thenorunexecutelenifdefstep
1条回答
网友
1楼 · 发布于 2024-04-25 11:57:43

Python将制表符视为8个空格,但许多文本编辑器将其视为4个空格。从不混合制表符和空格。标准是使用四个空格,而不是制表符。你知道吗

除以下两行外,您在每行中都使用了空格:

with open("harsh1.txt","w") as harsh1:
    print >> harsh1, """hello"""

这些行用制表符缩进。将它们替换为空格。你知道吗

相关问题 更多 >

    热门问题