名称'f'未定义(Pycharm IDE)

时间:2016-08-03 00:12:46

标签: python pycharm

Pycharm一直说f是未定义的,即使它是。 我做错了什么?

def Main():

    f = open("C:\Users\Donna\Desktop\myfile.txt","w")

for i in range(4):
    f.write=(raw_input("Enter a word here")+'\n')
if __name__ =="__main__":
 Main()

1 个答案:

答案 0 :(得分:1)

def Main():

    f = open("C:\Users\Donna\Desktop\myfile.txt","w")

    for i in range(4):
        f.write=(raw_input("Enter a word here")+'\n')

缩进有问题