Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

user.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Hook to allow user-specified customization code to run.
  2. As a policy, Python doesn't run user-specified code on startup of
  3. Python programs (interactive sessions execute the script specified in
  4. the PYTHONSTARTUP environment variable if it exists).
  5. However, some programs or sites may find it convenient to allow users
  6. to have a standard customization file, which gets run when a program
  7. requests it. This module implements such a mechanism. A program
  8. that wishes to use the mechanism must execute the statement
  9. import user
  10. The user module looks for a file .pythonrc.py in the user's home
  11. directory and if it can be opened, execfile()s it in its own global
  12. namespace. Errors during this phase are not caught; that's up to the
  13. program that imports the user module, if it wishes.
  14. The user's .pythonrc.py could conceivably test for sys.version if it
  15. wishes to do different things depending on the Python version.
  16. """
  17. import os
  18. home = os.curdir # Default
  19. if os.environ.has_key('HOME'):
  20. home = os.environ['HOME']
  21. elif os.name == 'nt': # Contributed by Jeff Bauer
  22. if os.environ.has_key('HOMEPATH'):
  23. if os.environ.has_key('HOMEDRIVE'):
  24. home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH']
  25. else:
  26. home = os.environ['HOMEPATH']
  27. pythonrc = os.path.join(home, ".pythonrc.py")
  28. try:
  29. f = open(pythonrc)
  30. except IOError:
  31. pass
  32. else:
  33. f.close()
  34. execfile(pythonrc)