title: How to get value from the output of a weighing scale
body: <p>I am trying to get the value of weight from the output of a weighing machine. I have connected the weighing machine with the windows PC using the RS232 to USB convertor. I am using python to connect and fetch the data. Following is the code used to fetch.</p>
  <pre><code>import time
  import serial
  import Tkinter
  import re
  
  window = Tkinter.Tk()
   
  def PrintWeight():
      ser = serial.Serial(
          port='COM6',
          baudrate=2400,
          timeout=None,
          parity=serial.PARITY_EVEN,
          stopbits=serial.STOPBITS_ONE,
          bytesize=serial.SEVENBITS
      )
      ser.isOpen()
      while 1 :
              bytesToRead = ser.inWaiting()
              data = ser.read(bytesToRead)
              time.sleep(1)
              print(str(data))
  
  MyTitle = Tkinter.Label(window, text=&quot;Weight Display&quot;,font=&quot;TimesRoman 16&quot;)
  MyTitle.pack()
  
  MyButton = Tkinter.Button(window, text=&quot;FETCH&quot;, command=PrintWeight)
  MyButton.pack()
   
  dice_thrown = Tkinter.Label(window, font=&quot;Helvetica 16 bold&quot;)
  dice_thrown.pack()
   
  window.mainloop()
  </code></pre>
  <p>I am getting the output as -
  <a href="https://i.stack.imgur.com/EKSpV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EKSpV.png" alt="enter image description here" /></a></p>
  <p>As you can see in the image attached , 000050 within the square brackets is the value of weight , i.e 50 grms. How can I get only the numeric data out of this long series of data, i.e only <em>50</em>.</p>
  <p>Even I used the following code to extract the numeric data from the string -</p>
  <pre><code>s = str(data)
  m = re.search(r&quot;\[([A-Za-z0-9_]+)\]&quot;, s)
  print m.group(1)
  </code></pre>
  <p>But this is giving error --
  <code>AttributeError: 'NoneType' object has no attribute 'group'</code></p>
  <p>Please help me out.</p>
  <p>Thanks.</p>