Python Forum

Full Version: Python instantly closes (Twitch Plays, Python 2)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I was using someone's code and I am not very experienced in python.
The installation must be right - I got the needed version of python (Python 2) and PyWin32.
But right after I launch it, it disappears. It launches and disappears in half a moment, in speed I cannot compare to any.
I tried many ways to stop it and read what it says but things don't help. Anything that comes to code screws over in my situation.

main.py (the .py I launched):

import twitch
import keypresser
import keyholder
t = twitch.Twitch();
k = keypresser.Keypresser();
 

username = "sumatras";
key = "my_oauth_key_it_was_written_right";
t.twitch_connect(username, key);
while True:

    new_messages = t.twitch_recieve_messages();
            if not new_messages:

        continue
    else:
        for message in new_messages:

            msg = message['message'].lower()
            username = message['username'].lower()
            print(username + ": " + msg.encode('utf-8'));
			
			if msg == "right": keyholder.holdForSeconds(msg, 0.8);
			if msg == "left": keyholder.holdForSeconds(msg, 0.8);
			if msg == "up": keyholder.holdForSeconds(msg, 0.8);
			if msg == "down": keyholder.holdForSeconds(msg, 0.8);
			if msg == "c": keyholder.holdForSeconds(msg, 0.3);
			if msg == "z": keyholder.holdForSeconds(msg, 0.3);
			if msg == "x": keyholder.holdForSeconds(msg, 0.3);
			if msg == "enter": keyholder.holdForSeconds(msg, 0.3);
If any of you can help me I will really appreciated, otherwise I will be just mourning the mental and physical pain I went through because it did not work. Smash
From your description it sounds like you're trying to run your code by double-clicking the file.
If so, take a look at https://python-forum.io/Thread-How-to-Ex...ython-code