I've seen alot of people asking what language they should learn next, and I often question how well they know the languages they claim to. Since I know it is hard to just go and program, I have decided to ask some more advanced Python questions, and see who the first to answer correctly is....
(code follows questions)
1) What does the code do?
2) What flaw(s) do(es) it have? (and recode it fixing the problems)
3) What is a rough Windows alternative?
4) What advantages/disadvantages does the Windows version have? (The Win version I came up with had 1 minor advantage, 2 major disadvantages)
5) How could you implement it so both the Linux and Windows versions co-exist in the same file, with the proper version used depending on the platform (needs to be transparent to the programmer using it)?
Code:
(btw Kerm/admins, why aren't there boxes around code and quote anymore?)
(code follows questions)
1) What does the code do?
2) What flaw(s) do(es) it have? (and recode it fixing the problems)
3) What is a rough Windows alternative?
4) What advantages/disadvantages does the Windows version have? (The Win version I came up with had 1 minor advantage, 2 major disadvantages)
5) How could you implement it so both the Linux and Windows versions co-exist in the same file, with the proper version used depending on the platform (needs to be transparent to the programmer using it)?
Code:
import os, pty, threading
class MPlayer(threading.Thread):
def __init__(self, args):
threading.Thread.__init__(self)
if (type(args) == str):
args = (args,)
self.mplayer_args = args
def run(self):
pid, fd = pty.fork()
if (pid):
self.mplayer_pid = pid
else:
os.execvp("mplayer", ("mplayer",) + self.mplayer_args)
(btw Kerm/admins, why aren't there boxes around code and quote anymore?)