Python学习日记(一)------------Using the Python Interpreter

1. Invoking the Interpreter

type 'python' command in DOS box.

To add the installation directory to user path, by typing set path = %path%;C:\python27. But if you restart the cmd window, you need to do this again.

2.Quiting the Interpreter

quit() or Control-Z on Windows, Control-D on Unix

3.Argument Passing

import sys

sys.argv[0]

4.Source Code Encoding

# -*- coding: encoding -*-

With that declaration, all characters in the source file will be treated as having the encoding encoding, and it will be possible to directly write Unicode string literals in the selected encoding.

5. The Interactive Startup File

When you use Python interactively, it is frequently handy to have some standard commands executed every time the interpreter is started. You can do this by setting an environment variable named PYTHONSTARTUP to the name of a file containing your start-up commands.

and if you want to use the start up file in a script, you must do this explicitly in the script

import os

filename = os.environ.get('PYTHONSTARTUP')

if filename and os.path.isfile(filename):

      execfile(filename)

 

6. The Customization Modules

Python provides two hooks to let you customize it: sitecustomize and usercustomize.

import site

site.getusersitepackages()

than create or modify file usercustomize.py int the directory.

 

ps:tty: 设备终端 Unix-style line ending ('\n'); Window line ending('\r\n')

.pyw, in this case , the console window that normally appears is suppressed.

 

你可能感兴趣的:(Python,python)