在Windows上安装Python+MySQL 的常见问题及解决方法
验证是否已经安装了MySQLdb:
==========================================================
d:\usr\local\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] onwin32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
==========================================================
如果有类似于上面的"No module named MySQLdb",表明MySQLdb尚未安装或安装的不成功!
MySQL 版本:5.0.67
下载地址:http://dev.mysql.com/downloads/mysql/5.0.html#downloads
下载exe文件并安装
==========================================================
Python 版本:2.5
下载地址:http://www.python.org/download/releases/2.5.4/
下载msi文件并安装
MySQLdb版本: MySQLdb Windows binary for Python 2.5
下载地址:http://biohackers.net/wikiattach/Python2(2e)5/attachments/MySQL-python.exe-1.2.1_p2.win32-py2.5.exe
参见:http://forums.mysql.com/read.php?50,129618,140611#msg-140611
常见问题:
1.无法定位程序输入点 mysql_server_init 于动态链接库 LIBMYSQL.dll 上。
----------------------------------------------------------------------------------------------------
D:\usr\local\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\usr\local\Python25\Lib\site-packages\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: DLL load failed: 找不到指定的程序。
----------------------------------------------------------------------------------------------------
解决方法:把mysql安
相关文档:
# 017
def lifeIsAMirror():
string = raw_input()
if string == 'I love you!':
return 'I love you, too!'
elif string == 'Fuck you!':
return ''
else:
return
# end of def
string = lifeIsAMirror()
if len(string) == 0:
print 'You have nothing.'
else: ......
模块这东西好像没什么好讲的,无非是保存一份文件,然后在另一份文件中用import 和from ** import **(*)就行了。
这一章主要讲到了细节,导入模块Python里面是什么处理的,import 和 from ** import **有什么不一样。还有就是增加了reload()这个函数的使用说明。
以前看到哪里说尽量使用import而不要使用from ** import * ......
源代码下载:下载地址在这里
# 026
aList = ['1','2','3','4']
aListCopy = aList # 其实,这里仅仅复制了一个引用
del aList[0]
print aList
print aListCopy # 两个引用指向了了同一个对象,所以打印结果一样
aListCopy = aList[:] # 这是复制整个对象的有效方法
del aList[0]
print aList
print aListCopy
......
源代码下载:下载地址在这里
# 037
fileName = ''
while 1:
fileName = raw_input("Input a file name:")
if fileName == 'q':
break
try:
f = file(fileName, 'r')
print 'Opened a file.'
except:
print 'There is no file named', fileName
......
# 040
import time
try:
f = file('040_Finally.py')
while True:
line = f.readline()
if len(line) == 0:
break
time.sleep(0.33)
print line,
# end of while
finally:
f.close()
print 'Closed the file.'
# end of try
output:
> ......