(1)
PYTHON文件开始的第一行“#!”,表示执行一些特殊命令,通常“use Python on a Unix, Linux, or Unix-like system”时会用到。
例如《Learning Python(3rd Edition)》的“Unix Executable Scripts (#!)”中给出的例子:
brian.py文件如下:
#!/usr/local/bin/python
print 'The Bright Side of Life...' # Another comment here
% brian
The Bright Side of Life...
(2)
PYTHON文件开始的第一行标明编码格式,主要用来显示中文等。
英文显示如:
# -*- coding: utf-8 -*-
或
#coding=utf-8
或
#!/usr/bin/python
# -*- coding: utf-8 -*-
中文显示如:
# -*- coding: gb2312 -*-
PYTHON文件开始的第一行“#!”,表示执行一些特殊命令,通常“use Python on a Unix, Linux, or Unix-like system”时会用到。
例如《Learning Python(3rd Edition)》的“Unix Executable Scripts (#!)”中给出的例子:
brian.py文件如下:
#!/usr/local/bin/python
print 'The Bright Side of Life...' # Another comment here
% brian
The Bright Side of Life...
(2)
PYTHON文件开始的第一行标明编码格式,主要用来显示中文等。
英文显示如:
# -*- coding: utf-8 -*-
或
#coding=utf-8
或
#!/usr/bin/python
# -*- coding: utf-8 -*-
中文显示如:
# -*- coding: gb2312 -*-