1

Here is a sample of code (python 3.6):

n = 2
x = 2**n
Q = str(x)
print(q)

This yields an error "str object is not callable". But I didn't understand why? I am working with much larger numbers (integers), and I need to convert them to a string before I can work with them. How can I do that?

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
  • 2
    Because somewhere you've done an assignment of the form `str = "..."` effectively masking the name `str`. Use `del str` to get the default behavior back. – Dimitris Fasarakis Hilliard Dec 03 '17 at 20:12
  • OK, I should clarify. I found I have been running this inside of jupyter notebooks. I don't get the error when I run it in a terminal session. – Barry Barron Dec 03 '17 at 20:21
  • 1
    Well somewhere in the previous cells of the notebook a redefinition has been made. – Dimitris Fasarakis Hilliard Dec 03 '17 at 20:22
  • You are correct. Even though I had deleted the code, Jupyter kept it internally. Your trick of reassigning (del str). Fixed the problem. Thank you. This problem is answered, but I don't know how to mark it answered (sorry, I am a newbie). – Barry Barron Dec 03 '17 at 20:27
  • Notice that I marked your question as a duplicate of an existing one (since there, the same situation had appeared). Since I didn't create an answer but, rather, just added a comment, there's no way to accept. You can either delete this question or leave it here as a sign-post for similar questions. The choice is yours :-) – Dimitris Fasarakis Hilliard Dec 03 '17 at 20:36
  • Learning all the time! Thank you! – Barry Barron Dec 04 '17 at 22:27

0 Answers0