Python for MS-DOS (was: Re: RS232 support for DOS on 486?)

Oleg Broytmann phd at phd.fep.ru
Wed Jun 13 03:57:10 EDT 2001


On 12 Jun 2001, Cyril Slobin wrote:
> >    Do you know you can put this into init.py (I hope your Python executes
> > init.py upon interactive startup) and have history load/save automatically?
>
> > import rlcompleter, readline
>
> Unsafe. I have three different python executables floating around, one
> of them haven't readline at all and one have old-styled readline. So my
> startup.py have a lot of try/except's to catch all the possible cases.
>
> > histfile="%s/.python-history" % os.environ["HOME"]
>
> Unportable. Use os.path.join instead;

   Sure, thanks. BTW, here is my entire init.py. May be you find something
useful:

from pydoc import help

# From Bruce Edge, http://groups.yahoo.com/group/python-list/message/128961

import rlcompleter, readline
#readline.parse_and_bind("tab: complete")
readline.parse_and_bind("tab: menu-complete")

import os
histfile="%s/.python-history" % os.environ["HOME"]
readline.read_history_file(histfile)

def savehist():
   global histfile
   readline.write_history_file(histfile)

import atexit
atexit.register(savehist)


# From Randall Hopper, http://groups.yahoo.com/group/python-list/message/130175

import sys
if os.environ.get("TERM") in ["xterm", "rxvt", "vt100"]:
   sys.ps1 = "\001\033[0:1;32m\002>>> \001\033[0m\002"
   sys.ps2 = "\001\033[0:31m\002... \001\033[0m\002"


# From: Paul Magwene, http://groups.yahoo.com/group/python-list/message/129882

class DirLister:

    def __getitem__(self, key):
        s =  os.listdir(os.getcwd())
        return s[key]

    def __getslice__(self,i,j):
        s =  os.listdir(os.getcwd())
        return s[i:j]

    def __call__(self, path=os.getcwd()):
        path = os.path.expanduser(os.path.expandvars(path))
        return os.listdir(path)

    def __repr__(self):
        return str(os.listdir(os.getcwd()))


class DirChanger:
    def __init__(self, path=os.getcwd()):
        self.__call__(path)

    def __call__(self, path=os.getcwd()):
        path = os.path.expanduser(os.path.expandvars(path))
        os.chdir(path)

    def __repr__(self):
        return os.getcwd()


ls = DirLister()
cd = DirChanger()


# From Thomas Heller, http://groups.yahoo.com/group/python-list/message/133035

import sys
def info(*args):
   import pdb
   pdb.pm()
sys.excepthook = info

Oleg.
----
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list