Any python programmers out there that could give me a hand?

So this script is supposed to basically send someone a text message, wait for a response, and when they answer, display their response to the console before exiting. No matter what I do it either doesn’t wait for a response or displays like 30 old responses and exits. I’m kind of at my wits end with this, so I was wondering if a fresh pair of eyes could take a look? Thanks in advance.

I’m not pythoner, can’t write program in Pyrhon myself. I write code in bash (shell script), Pascal, and sometimes php
Looking at your code I see
last_processed_sid = message.sid
is executed only, if the condition is true in the “if” statenent above.
Is it sure, you want to update “last processed” only in that execution path?
Just asking of course I don’t know much about Python, and am highly prone to overlook somethin obvious here.

Edit:
I was thinking about a bit more, and I feel kind of sure, that updating “last processed” does not make sense there, as there’s a sys.exit right in the next line.

Originally:

for message in messages:
        if message.sid != initial_message_sid and message.sid != last_processed_sid:
            print("Response received: Thank you for your response.")
            last_processed_sid = message.sid
            sys.exit(0)

Updating last_processed in the for loop, but outside of the if would make more sense, I think:

for message in messages:
        if message.sid != initial_message_sid and message.sid != last_processed_sid:
            print("Response received: Thank you for your response.")
            sys.exit(0)
        last_processed_sid = message.sid

I’m not saying for sure, that change will make it work as intended, I’m also unsure that my change is really correct in Python syntax - so take this please just as a shoot in the dark :slight_smile:

2 Likes

Thanks, I’m going to have to mess about with this today and see if I can’t get it working right. Coding always drives me up a wall, I’m trying to get more comfortable with it though. lol

2 Likes