Not all of arguments converted during string formatting

后端 未结 2 1361
自闭症患者
自闭症患者 2021-02-13 01:41

Im wrtiting a script which saves the current date and time as a filename but I get an error stating \"TypeError: not all arguments converted during string formatting\" I am new

2条回答
  •  醉话见心
    2021-02-13 02:18

    You're putting the string formatting in the wrong place; it needs to be right after the string that's being formatted:

    f = open("%s.sql" % (today), "w")
    

    It's legal to not pass any formatting arguments, like you did with "%s.sql", but it's not legal to pass arguments but not the right amount ("w" % (today) passes one, but there's no string formatting in "w", so you get an error that not all of the arguments were used)

提交回复
热议问题