python
Python连接MySQLdb的mach-o, but wrong architecture错误解决
错误提示
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-x86_64.egg/_mysql.so: mach-o, but wrong architecture
这个问题是32bit和64bit的问题.
解决方法:
1 使用正确的环境编译MySQL-python-1.2.3.tar.gz,并安装
设置.bash_profile
PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ export VERSIONER_PYTHON_PREFER_64_BIT=yes export VERSIONER_PYTHON_PREFER_32_BIT=no
2 编译安装MySQL-python-1.2.3.tar.gz
ARCHFLAGS="-arch x86_64" python setup.py build#64bit使用这个 ARCHFLAGS="-arch i386" python setup.py build#32bit使用这个 sudo python setup.py install
3 开发环境IDE里设置DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
4 检查
#python >>import _mysql
python爬虫和数据挖掘
考虑用python做爬虫,需要研究学习的python模块
1内置的 urllib, urllib2 库用来爬取数据
2 使用BeautifulSoup做数据清洗
http://www.crummy.com/software/BeautifulSoup/
编码规则
Beautiful Soup tries the following encodings, in order of priority, to turn your document into Unicode:
1 An encoding you pass in as the fromEncoding argument to the soup constructor.
2 An encoding discovered in the document itself: for instance, in an XML declaration or (for HTML documents) an http-equiv META tag. If Beautiful Soup finds this kind of encoding within the document, it parses the document again from the beginning and gives the new encoding a try. The only exception is if you explicitly specified an encoding, and that encoding actually worked: then it will ignore any encoding it finds in the document.
3 An encoding sniffed by looking at the first few bytes of the file. If an encoding is detected at this stage, it will be one of the UTF-* encodings, EBCDIC, or ASCII.
4 An encoding sniffed by the chardet library, if you have it installed.
5 UTF-8
6 Windows-1252
可以用fromEncoding参数来构造BeautifulSoup
soup = BeautifulSoup(euc_jp, fromEncoding="gbk")
3 使用python chardet 字符编码判断
http://chardet.feedparser.org/download/
4 更加强大的 selenium
初学python的Web框架Django-模板
修改django的url规则和模板的基本操作
We’ll just have to take a few steps to make the conversion. We will:
1. Convert the URLconf.
2. Rename a few templates.
3. Delete some of the old, unneeded views.
4. Fix up URL handling for the new views.
初学python的Web框架Django之二-后台管理
一 激活管理界面 Activate the admin site
1 Add “django.contrib.admin” to your INSTALLED_APPS setting.
2 Run python manage.py syncdb. Since you have added a new application to INSTALLED_APPS, the database tables need to be updated.
3 Edit your mysite/urls.py file and uncomment the lines that reference the admin – there are three lines in total to uncomment. This file is a URLconf; we’ll dig into URLconfs in the next tutorial. For now, all you need to know is that it maps URL roots to applications. In the end, you should have a urls.py file that looks like this:
› Continue reading
初学python的Web框架Django
1下载
bear@njava:~$wget http://www.djangoproject.com/download/1.2/tarball/ bear@njava:~$tar -xzvf Django-1.2.tar.gz bear@njava:~$cd Django-1.2/ bear@njava:~$sudo python setup.py install
2 新建django项目
bear@njava:~$ django-admin.py startproject njava bear@njava:~$cd njava bear@njava:~$ls total 20K drwxr-xr-x 2 bear bear 4.0K 2010-05-19 23:27 . drwxr-xr-x 4 bear bear 4.0K 2010-05-19 23:27 .. -rw-r--r-- 1 bear bear 0 2010-05-19 23:27 __init__.py -rw-r--r-- 1 bear bear 546 2010-05-19 23:27 manage.py -rw-r--r-- 1 bear bear 3.3K 2010-05-19 23:27 settings.py -rw-r--r-- 1 bear bear 534 2010-05-19 23:27 urls.py bear@njava:~$python manage.py runserver 0.0.0.0:8000