11

The line causing the error is

totalR = totalR + (float(string.replace(contri[0][5],",","")) + float(string.replace(contri[0][6],",","")))

contri[0][5] and [6] are strings that contain numbers formatted as 1,000.00. I'm removing the commas before I cast the strings as floats in order to add them to totalR, which is a float. (Created as totalR = 0.0) I also tried using Decimal, but the error happened there too. I did "import string". The program fails with error:

File "mine.py", line 43, in fillDonorData
totalR = totalR + (float(string.replace(contri[0][5],",","")) + float(string.replace(contri[0][6],",","")))
AttributeError: 'module' object has no attribute 'replace'
2
  • I have used '10,000' instead of 'contri[0][5]' and 'contri[0][6]' in your code and everything works fine. I am on Python 2.7. If you are trying this on python 3 you should read this Commented Dec 24, 2013 at 18:59
  • I'm assuming you're on Python 3.x? If so, you should include that tag in your question. Also, you should paste the entire traceback, not just the error itself. Commented Dec 24, 2013 at 19:03

3 Answers 3

13

Methods in the string module have been deprecated for years. You should call replace directly on your string, or contri[6].

Sign up to request clarification or add additional context in comments.

1 Comment

In 2.x, the Deprecated string functions still work despite being deprecated. In 3.x, most of them (including replace) no longer exist. However, there are still plenty of non-deprecated functions, constants, and classes in string.
5

It is now on str.replace on Python 3.

Looks like the same thing renamed, have the same signature and a docstring with the same meaning.

Comments

0

If you made changes to your module, just exit python shell and enter again and import your module again

1 Comment

string is a builtin module. But this is correct, you would have to reload if changes are made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.