markinglevfx Posted February 22, 2020 Share Posted February 22, 2020 In the Python SOP, I've run into a wall trying to get an integer converted to a string. In the larger picture, I'm trying to subtract 1 from a value which is currently part of a string. There are probably neater ways to write these steps, but I'm fairly new to Python so I'm writing it all out to make things easier to follow. I start with a string such as: string = "f27" Then remove the 'f' like so: string = string[1:] Convert it to an integer: integer = int(string) Subtract 1 from the value: integer -= 1 set new string string_new = "f" + str(integer) The last line returns an error on the Python SOP: TypeError: str() object is not callable. This is confusing because these same steps work just fine in the Python shell. Is there an alternative to str(), or am I using it wrong? Quote Link to comment Share on other sites More sharing options...
anim Posted February 22, 2020 Share Posted February 22, 2020 should work, unless you overwrote str with something else higher in the script, like str = "something" Quote Link to comment Share on other sites More sharing options...
Noobini Posted February 22, 2020 Share Posted February 22, 2020 got f26 Indie 18.0.287 Quote Link to comment Share on other sites More sharing options...
markinglevfx Posted February 22, 2020 Author Share Posted February 22, 2020 I did have 'str' set as a variable elsewhere in the code. But even after I got rid of it, the error persisted. But I have managed to get it working now. I solved it by making a new Python SOP and using the same code - initially I was copy/pasting lines and seeing where it broke. Weird how I now have two python nodes side by side with the same inputs, the old one errors and the new one is fine. Quote Link to comment Share on other sites More sharing options...
anim Posted February 22, 2020 Share Posted February 22, 2020 Just cut/paste the old node or save your scene and reopen, it probably has your str still overwritten and cached somewhere Quote Link to comment Share on other sites More sharing options...
markinglevfx Posted February 22, 2020 Author Share Posted February 22, 2020 Bingo. Thanks for the help guys! Quote Link to comment Share on other sites More sharing options...
underscoreus Posted March 1, 2020 Share Posted March 1, 2020 Don't know if this is a thing in python but I guess it might be worth mentioning, its probably a good idea to refrain from naming your variables stuff like string, int/integer, float, vector etc because this be messing with the internal classes and structs of your coding language and give you hassle later. Don't know if you just named them that in your example for demonstration purposes or not but figured I'd add my 2 cents. Quote Link to comment Share on other sites More sharing options...
larabrian Posted May 1, 2020 Share Posted May 1, 2020 TypeError: 'str' object is not callable usually means you are using your () notation on a string, and Python tries to use that str object as a function. e.g. "hello world"(), or "hello"("world"). Or, if you have variable str and trying to call str() function. Finally: Do not declare python variable name same with python built-in function name, keyword etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.