Re: finding monitor or screen resolution in Linux with standard python module
On Mar 7, 11:25 am, "akbar" <[EMAIL PROTECTED]> wrote: > I googled and searched in archive. All I can find is finding > resolution with Tkinter and pygame. Any idea to find monitor > resolution with standard python module? > I can check from output of: xprop -root > _NET_DESKTOP_GEOMETRY(CARDINAL) . The problem is when you use Beryl or > Xgl, it is not correct anymore because Beryl or Xgl set this value > from amount of workspaces multiplied by monitor or screen resolution. A method 'screen' from Python X Library looks promising: http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html#SEC15 More, or less if I understand right you just need to request from server dimensions of the screen, over x protocol of course. So it will be something associated with Xlib. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading character from keyboard
Tommy Grav napisal(a): > A very simple question. I would like to read a single character from the > keyboard (y or n). I have tried to look in my Python books and a google > search, but have come up empty. I am sure the info s out there, but I > guess I am unable to find the right question or search keyword :o/ > > Any hints or help appreciated > Cheers >Tommy Actually, if you want to read only one character from keyboard, you will need to use terminal operations rather than plain input stream. Unfortunately this is rather not portable solution. For Windows you have to import msvcrt, on Unices curses module. The latter code is quite similar. Example: import msvcrt def prompt(msg='Your choice: ', options={'y': True, 'n': False}): while True: print msg key = msvcrt.getch() choice = str(key).lower() if options.has_key(choice): break print 'You entered wrong key! Enter again.' return options[choice] print prompt() and 'Good for you.' or 'Bad Luck.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob Question: Force input to be int?
On 23 Sty, 10:59, [EMAIL PROTECTED] wrote: > Hello everyone! > I have a piece of code that looks like this: > > if len(BuildList) > 0: > print "The script found %d game directories:" % len(BuildList) > print > num = 0 > for i in BuildList: > print str(num) +" " + i > num = num + 1 > print > print "Select a build number from 0 to " + str(len(BuildList) - 1) > buildNum = int(raw_input('Select build #> ')) > > while buildNum > (len(BuildList) -1) or buildNum <= -1: > print > print "Error: Invalid build number!" > print "Select a build number from 0 to " + str(len(BuildList) - > 1) > print > buildNum = int(raw_input('Select build: ')) > > The problem is with the while buildNum-loop. If the user enters a > non-numeric value in the buildNum input, the scripts throws an > exception. I need to constrict the user to ONLY use integers in the > input box. How can I solve this issue? Also if you would like to try mentioned approach 'Look before you leap', this code should be quite clear: buildNumber = ('foo', 'bar') n = len(buildNumber) loop = True while loop: input = raw_input('select a build number from 0 to %d: ' % (n-1)) if input.isdigit(): ch = int(input) loop = not ch in range(n) # if ch is NOT in range of [0, n), then it is ok to loop if loop: print 'Error! Invalid build number' print 'Choice: %d' % ch In fact I don't know if it applies to python, but in conventional languages it is a bad habit to use exceptions for every simple test as it takes time to jump around code. So, correct me please. -- http://mail.python.org/mailman/listinfo/python-list