Python Forum
Convert string to float problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert string to float problem
#6
Oh, thank you. It works perfectly with try/except! Also I have one more question. I need to make value bigger (multiply), but this does not work. How can I do it?

from pynput.mouse import Button, Controller
import time
import serial

mouse = Controller()
ser = serial.Serial('COM3', baudrate=9600, timeout=1)


while True:
    try:
        arduinoData = ser.readline().decode('ascii')
        data = (arduinoData)/5
        print(data)
        mouse.position = (data, 100)
    except:
        print("fail")
        break
EDIT: Solved also this.
Reply


Messages In This Thread
Convert string to float problem - by vasik006 - May-27-2022, 07:15 PM
RE: Convert string to float problem - by ndc85430 - May-27-2022, 07:33 PM
RE: Convert string to float problem - by deanhystad - May-27-2022, 08:12 PM
RE: Convert string to float problem - by vasik006 - May-28-2022, 08:13 AM
RE: Convert string to float problem - by vasik006 - May-28-2022, 08:16 AM
RE: Convert string to float problem - by vasik006 - May-28-2022, 08:46 AM
RE: Convert string to float problem - by deanhystad - May-28-2022, 01:08 PM
RE: Convert string to float problem - by vasik006 - Jun-03-2022, 04:54 PM
RE: Convert string to float problem - by deanhystad - Jun-03-2022, 06:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert to bin problem kucingkembar 3 447 Apr-19-2024, 12:53 PM
Last Post: kucingkembar
  python calculate float plus float is incorrect? sirocawa 6 621 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Convert From PDf into JPEG Problem koklimabc 4 1,245 Sep-05-2023, 06:44 AM
Last Post: Gribouillis
  convert string to float in list jacklee26 6 2,120 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  openpyxl convert data to float jacklee26 13 6,624 Nov-19-2022, 11:59 AM
Last Post: deanhystad
  how to convert tuple value into string mg24 2 2,582 Oct-06-2022, 08:13 AM
Last Post: DeaD_EyE
  Convert SQLite Fetchone() Result to float for Math Extra 13 3,961 Aug-02-2022, 01:12 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 5,115 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Detecting float or int in a string Clunk_Head 15 5,071 May-26-2022, 11:39 PM
Last Post: Pedroski55
  Convert a string to a function mikepy 8 2,731 May-13-2022, 07:28 PM
Last Post: mikepy

Forum Jump:

User Panel Messages

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