Author Topic: [Python] Constantly get input/output  (Read 1360 times)

0 Members and 2 Guests are viewing this topic.

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
[Python] Constantly get input/output
« on: June 11, 2012, 12:08:13 am »
I am working on a minecraft server wrapper and I just need something so I can constantly input commands and constantly get the output for commands/other things. Any help would be awesome.
Blog: rexmckinnon.tumblr.com

Offline NeX

  • Peasant
  • *
  • Posts: 74
  • Cookies: 5
    • View Profile
Re: [Python] Constantly get input/output
« Reply #1 on: June 11, 2012, 12:45:29 am »
Code: [Select]
while(1):
var = raw_input("User input: ")
print "User input is: ", var

Does that help?

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] Constantly get input/output
« Reply #2 on: June 11, 2012, 12:51:48 am »
No, because it might need to output something before it gets input or vice versa
Blog: rexmckinnon.tumblr.com

Offline NeX

  • Peasant
  • *
  • Posts: 74
  • Cookies: 5
    • View Profile
Re: [Python] Constantly get input/output
« Reply #3 on: June 11, 2012, 12:54:47 am »
I seem to not understand the phenomenon of writing something to output which relies on the input, BEFORE getting the input. Either that, or you need something like threads? One for writing the output based on previous calculations that include the last input and another for getting the input whenever you need it.

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: [Python] Constantly get input/output
« Reply #4 on: June 11, 2012, 01:20:19 am »
Code: (python) [Select]
while(1):
        if need_to_output:
            print output
var = raw_input("User input: ")
print "User input is: ", var
?
Easter egg in all *nix systems: E(){ E|E& };E

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: [Python] Constantly get input/output
« Reply #5 on: June 11, 2012, 03:05:35 am »
Code: (python) [Select]
while(1):
        if need_to_output:
            print output
   var = raw_input("User input: ")
   print "User input is: ", var
?


Kinda. But I need it to not get hung on getting the input. I think I need to use threads maybe?
Blog: rexmckinnon.tumblr.com

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: [Python] Constantly get input/output
« Reply #6 on: June 11, 2012, 03:40:40 am »

Kinda. But I need it to not get hung on getting the input. I think I need to use threads maybe?

Yeah you need to use threads. One thread changes the map the other one listens for user input.
Easter egg in all *nix systems: E(){ E|E& };E

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] Constantly get input/output
« Reply #7 on: June 11, 2012, 04:51:22 am »
Kinda. But I need it to not get hung on getting the input. I think I need to use threads maybe?

That hung up is called blocking. You will need threads. Internet protocols can also block, so without knowing more information of what your wanting to do, I will suggest threading.
>>>import this
-----------------------------