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'
Jeff
  • 497
  • 3
  • 5
  • 14
  • 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](http://stackoverflow.com/questions/9452108/how-to-use-string-replace-in-python-3-x) – skamsie Dec 24 '13 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. – abarnert Dec 24 '13 at 19:03

3 Answers3

12

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

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 2
    In 2.x, the [Deprecated string functions](http://docs.python.org/2/library/string.html#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`. – abarnert Dec 24 '13 at 19:04
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.

alanjds
  • 3,972
  • 2
  • 35
  • 43
0

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

Humoyun Ahmad
  • 2,875
  • 4
  • 28
  • 46