Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:28:09+00:00 2026-06-12T21:28:09+00:00

I have a stupid python problem. I’m trying to read a line from a

  • 0

I have a stupid python problem.

I’m trying to read a line from a file everytime i get a ‘READY’ message from a serial connection so i wrote this :

import serial
from time import sleep

port = "/dev/tty.usbserial-A400fYTT"
speed = 57600
polarfile = 'polarfile.pg'

f = open(polarfile, 'r')

ser = serial.Serial(port, speed, timeout=0)

while True:
    data = ser.read(9999)
    if len(data) > 0:
        if(data == 'READY'):
            f.readline()
        else:
            sleep(0.5)

    sleep(1)

ser.close()

But it doesn’t work, however if i replace the if(data == ‘READY’ block by print data. I get the READY message.

Also i can read my file with f.readline()…

Thanks to give advice to a py newbie

—
edit :
Important info, the serial doesn’t receive only “READY” message, but a bunch of other, but i want just to react when the “READY” messsage is received.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:28:11+00:00Added an answer on June 12, 2026 at 9:28 pm

    I just replace

    data = ser.read(9999)

    by

    data = ser.readline(9999) which gives me the message line by line instead of second by second of input data and then replace

    if( data == 'READY' ):by

    if (data.startswith('READY')):

    and now it works 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call Python From PHP And Get Return Code probably a very stupid
I`m new to python and I have the stupid problem with passing an argument.
I have an HTML page which is completely generated from a Python file. I
I have a stupid WinCE application where I'm just trying to force an exception
I have a simple stupid question. Here's the problem, for years, my company has
I am learning python at college. I have got a very stupid question. How
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
I'm trying to install Feedparser 5.1 for Python 3.2, Windows 64 bit. I have
I have a problem with the Python logging module, I'm not sure if I'm
Sorry, I'm sure this is a stupid question. I have successfully installed python 2.6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.