clear screen / locate cursor

Peter peter.mosley at talk21.com
Mon Nov 22 04:38:40 EST 2004


I am just trying to learn python, to use for some fairly basic command
line utilities which will run in either Windows/DOS or Linux. I cannot
find a platform neutral way of manipulating the screen. I don't want
to do anything complex, but just:-

1. Clear the screen
2. Print a string at an arbitrary x,y position
3. Receive a single key stroke

It seems that under Linux the curses module will do all this and more
(though I haven't tried it), but despite Python documentation curses
does not seem to be available under DOS. I have solved the 'clear
screen' problem with the code below, but made no progress on the other
two:-

def cls():
   a=os.name
   if a=='posix':                  #linux
      os.system('clear')
   elif a=='nt':                   #windows
      os.system('cls')
   else:                           #unknown
      print 
      print ('='*(78-len(a)))+a
      print

Is this the best solution? Can anyone help with the others?  I have
tried searching python documentation and this newsgroup, but found no
pointers.  It can't be difficult (for the experts!) - other cross
platform languages such as Yabasic and Euphoria seem to have such a
facility, so what am I missing?

The email address above was genuine once but has long been abandoned
to spam.  Pleae reply via newsgroup or to

   peter dot mosley at spamguardnorth dot org after removing spamguard

Thanks in advance for any help.



More information about the Python-list mailing list