不得不说python有几个网站:
GNURADIO上说的网站:http://docs.python.org/tutorial/introduction.html
还有自己搜索到:http://diveintopython.org/
我自己的硬件环境:
CPU:I3 530
内存:4G
OS:Ubuntu 10.4
第一,安装,在命令行下打入python,发现没按照,输入
sudo apt-get install python
第二,按照完后,打开 Invoking the Interpreter
教程上写的:
The Python interpreter is usually installed as
to the shell. Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local Python guru or system administrator. (E.g., /usr/local/python is a popular alternative location.)
接下来可以进行编程。
可以直接启动python进去输入脚本,其实python说白了就是脚本语言类似,和MATLAB语言差不多,不用编译直接用那种。
下面继续学习,我看《dive into python》,按照里边输入了第一个例子,
源代码:
"""odbchelper.py sample script
This program is part of "Dive Into Python", a free Python book for
experienced programmers. Visit http://diveintopython.org/ for the
latest version.
All this stuff at the top of the script is just optional metadata;
the real code starts on the "def buildConnectionString" line
"""
__author__ = "Mark Pilgrim (mark@diveintopython.org)"
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2004/05/05 21:57:19 $"
__copyright__ = "Copyright (c) 2001 Mark Pilgrim"
__license__ = "Python"
def buildConnectionString(params):
"""Build a connection string from a dictionary
Returns string.
"""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"mpilgrim", \
"database":"master", \
"uid":"sa", \
"pwd":"secret"
}
print buildConnectionString(myParams)
结束后,chmod +x odbchelper.py
运行发现错误如下:
./odbchelper.py: line 11: __author__: command not found
./odbchelper.py: line 12: __version__: command not found
./odbchelper.py: line 13: __date__: command not found
./odbchelper.py: line 14: __copyright__: command not found
./odbchelper.py: line 15: __license__: command not found
./odbchelper.py: line 17: syntax error near unexpected token `('
./odbchelper.py: line 17: `def buildConnectionString(params):'
./odbchelper.py: line 12: __version__: command not found
./odbchelper.py: line 13: __date__: command not found
./odbchelper.py: line 14: __copyright__: command not found
./odbchelper.py: line 15: __license__: command not found
./odbchelper.py: line 17: syntax error near unexpected token `('
./odbchelper.py: line 17: `def buildConnectionString(params):'
然后我上网查了一下,发现是白痴问题,我没把Interpreter的路径写到文件中
在文件第一行加上:#! /usr/bin/python
问题解决,出现:server=mpilgrim;uid=sa;database=master;pwd=secret
和网上的教程一样