0001 """Hook to allow user-specified customization code to run. 0002 0003 As a policy, Python doesn't run user-specified code on startup of 0004 Python programs (interactive sessions execute the script specified in 0005 the PYTHONSTARTUP environment variable if it exists). 0006 0007 However, some programs or sites may find it convenient to allow users 0008 to have a standard customization file, which gets run when a program 0009 requests it. This module implements such a mechanism. A program 0010 that wishes to use the mechanism must execute the statement 0011 0012 import user 0013 0014 The user module looks for a file .pythonrc.py in the user's home 0015 directory and if it can be opened, execfile()s it in its own global 0016 namespace. Errors during this phase are not caught; that's up to the 0017 program that imports the user module, if it wishes. 0018 0019 The user's .pythonrc.py could conceivably test for sys.version if it 0020 wishes to do different things depending on the Python version. 0021 0022 """ 0023 0024 import os 0025 0026 home = os.curdir # Default 0027 if 'HOME' in os.environ: 0028 home = os.environ['HOME'] 0029 elif os.name == 'posix': 0030 home = os.path.expanduser("~/") 0031 elif os.name == 'nt': # Contributed by Jeff Bauer 0032 if 'HOMEPATH' in os.environ: 0033 if 'HOMEDRIVE' in os.environ: 0034 home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH'] 0035 else: 0036 home = os.environ['HOMEPATH'] 0037 0038 pythonrc = os.path.join(home, ".pythonrc.py") 0039 try: 0040 f = open(pythonrc) 0041 except IOError: 0042 pass 0043 else: 0044 f.close() 0045 execfile(pythonrc) 0046
Generated by PyXR 0.9.4