Python Forum
coult not convert string to float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coult not convert string to float
#10
(Oct-10-2016, 10:31 PM)metulburr Wrote:
(Oct-10-2016, 10:24 PM)kentman234 Wrote:
self.datayf.append(float(y.strip().replace(',', '')))

Remove all text formatting before putting it in python tags. Select the text, and there is a button with an "A" with a minus symbol. You need to do this for code within python tags.

So then it will be
self.datayf.append(float(y.strip().replace(',', '')))

OK, I try now:
print(y.strip().replace(',', ''))

(Oct-10-2016, 10:32 PM)Yoriz Wrote: The idea is that you see what the output of the print line was.
If that is an empty string it is not possible for float to turn that into a number, so you need to decide if it should of been possible to be an empty string or if you need to deal with the exception caused by there being an empty string.

So I think that our discussion has finished right? Because now I need to deal with the code itself.
Reply


Messages In This Thread
coult not convert string to float - by kentman234 - Oct-10-2016, 09:34 PM
RE: coult not convert string to float - by Yoriz - Oct-10-2016, 09:43 PM
RE: coult not convert string to float - by Yoriz - Oct-10-2016, 09:58 PM
RE: coult not convert string to float - by Yoriz - Oct-10-2016, 10:17 PM
RE: coult not convert string to float - by kentman234 - Oct-10-2016, 10:36 PM
RE: coult not convert string to float - by Yoriz - Oct-10-2016, 10:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 2,145 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  convert string to float in list jacklee26 6 3,481 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  openpyxl convert data to float jacklee26 13 12,348 Nov-19-2022, 11:59 AM
Last Post: deanhystad
  how to convert tuple value into string mg24 2 4,065 Oct-06-2022, 08:13 AM
Last Post: DeaD_EyE
  Convert SQLite Fetchone() Result to float for Math Extra 13 6,440 Aug-02-2022, 01:12 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 6,731 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Convert string to float problem vasik006 8 5,389 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Detecting float or int in a string Clunk_Head 15 9,949 May-26-2022, 11:39 PM
Last Post: Pedroski55
  Convert a string to a function mikepy 8 4,621 May-13-2022, 07:28 PM
Last Post: mikepy
Question How to convert string to variable? chatguy 5 4,915 Apr-12-2022, 08:31 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020