如果语句语法错误

时间:2016-06-09 15:25:22

标签: python file syntax-error

我有这段代码可以写文件:

Try like this
--------------
code
------
    <!-- THIS IS FOR THE SECOND LINK-->
    $(document).keyup(function(e) {
        x = document.getElementById("show_photo");
        y = document.getElementById("full_photo");
        if(e.keyCode == 27){
            if(x){
                if(x.style.display !== "block"){
                    $("#all_photo").css('display', 'none');
                }
            }
            if(y){
                if(y.style.display == "block"){
                    $("#full_photo").css('display', 'none');
                }
            }
        }
    });

我的Python编译器不断抱怨并抛出此错误:

with open('key.txt', 'w+') as key:
       counter += 1
       key.write(k + str(counter)
       contents = key.read()
       if contents == 'ran 1':
           print('Can\'t run twice!')
       else:
           writeFiles()

我真的不明白这意味着什么,我通常不会得到这样的错误。帮助将不胜感激。

2 个答案:

答案 0 :(得分:9)

缺少右括号:

key.write(k + str(counter)
                          ^ here

应该是

key.write(k + str(counter))

每当您看到这些 mystery 语法错误时,请查看前面的行

答案 1 :(得分:4)

key.write

中的遗嘱遗失了
with open('key.txt', 'w+') as key:
   counter += 1
   key.write(k + str(counter))
   contents = key.read()
   if contents == 'ran 1':
       print('Can\'t run twice!')
   else:
       writeFiles()