If you define string
as a variable containing an actual string, either as a function argument or in your main program, your code should work, though, as LMC says, don't use it as a variable name. My guess is here you forgot to define it or it's not accessible in your function or something. Normally that would result in a NameError
, but since string is defined as a built-in, it instead throws the AttributeError
.