Why is Python giving me “an integer is required” when it shouldn't be?

前端 未结 4 1107
自闭症患者
自闭症患者 2020-12-19 06:28

I have a save function within my Python program which looks like this:

def Save(n):
    print(\"S3\")
    global BF
    global WF
    global PBList
    globa         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 06:45

    You probably did a star import from the os module:

    >>> open("test.dat","w")
    
    >>> from os import *
    >>> open("test.dat","w")
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: an integer is required
    

    so you're using the wrong open function. (I suppose you could've simply done from os import open, but that's less likely.) In general this import style should be avoided, as should use of global, where practical.

提交回复
热议问题