顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2016年9月11日 星期日

Python 3 Tutorial

Learn Python in the most social and fun way, with SoloLearn!
Learn Python, one of today's most in-demand programming languages on-the-go, while playing, for FREE! Compete and collaborate with your fellow SoloLearners, while surfing through short lessons and fun quizzes. Practice writing Python code within the app, collect points, and show off your skills. 
When you complete the course, you'll win a Certificate of Completion as a trophy!
So don’t wait; dive right in! Start coding with Python!

from : http://www.sololearn.com/Course/Python/

2015年5月11日 星期一

Installing pip on Mac OS X

All you need to do is
sudo easy_install pip

2013年7月10日 星期三

Python Logging - Sentry

Sentry helps with exception logging and viewing for your Django project. It can handle multiple Django installs where the logs can be managed from a single place, or it can be used on a per-project basis. The latter is how it’s preconfigured in DJ Skeletor.
Besides logging the exceptions, Sentry can also catch normal logs you create with Python’s logging system. This is also preconfigured in DJ Skeletor.

Example

Enough talk, let’s see some action. First, we’ll create a virtual environment (you do use virtualenv, right? if not, you should) and install prerequisite packages:
    virtualenv --no-site-packages myenv
    cd myenv
    source bin/activate
    pip install django django-debug-toolbar south django-sentry
Next, we’ll clone the boilerplate project:
    git clone https://github.com/senko/dj-skeletor.git myproject
    cd myproject
Let’s activate the development environment and prepare the database:
    cd settings
    ln -s dev.py local.py
    cd ..
    python manage.py syncdb
    python manage.py migrate sentry
All done, let’s run it!
    python manage.py runserver
See? Piece of cake. With boring initial set-up out of our way, we can focus on building an awesome web site or app.
DJ Skeletor is open source and is available on GitHub. Feel free to use it or base your own boilerplate on it – if you do, please share your thoughts in the comments.
en → zh
的

Python Web framework - Pyramid

Django用久了,难免会感觉到自由度不够。不可否认,这种自由度的牺牲能够带来一些好处。比如,一体化的框架(full-stack framework)能够提供全面的solution,你不需要再为cache,session,feed,orm,auth,template等问题困扰,完全按照Django的设计哲学来使用就可以了。使用Django能够快速开发应用,而且技术的统一对于团队开发来说无疑是一件好事,团队成员无需在技术选型上进行过多的争论——Django已经帮我们定好了,just DO it。

但是在提供全面的solution的同时,Django将自己打造成了一个封闭的框架。由于所有的组件都靠自己实现,可能在每一个方面都做得不够好(尽管够用)。同时为了方便使用,Django的各个组件之间耦合比较紧密,你很难将某个组件替换成你自己喜欢的库。比如Django最为人诟病的ORM和Template,如果你想替换成SQLAlchemy和Mako,几乎是不可能的事情。即使勉强使用,也会让你非常别扭。

话说天下大事,分久必合。在python web framework 的战国时代,Django几乎做到了一家独大。但如果其他的框架合纵联合,未必不能与Django一争高下。
现在这种融合的趋势已经显现,而Django如果依然固步自封,即使再强大,也会在历史的尘埃中销声匿迹。如果你不相信,我们可以追索一下事实真相,不难看出这种融合恰恰是从更加强大的Zope的分裂开始的。

在《戏说WSGI》一文中,曾经列举了几个python web框架。其中Zope是一个另类,因为Zope非常厚重,适合组织大规模的开发,构建复杂的应用。为了能够面对更高的复杂度,Zope提供了一个组件框架ZCA (Zope Component Architure),引入了接口的概念,使得复杂系统可以基于接口开发。ZCA提供了适配器组件,用于装配整个应用的各个组成部分,还进一步提供了可重用的工具组件,事件组件等。可以说,ZCA是Zope中最有价值的产品。

尽管ZCA能够将Zope提供的认证、对象发布、事务管理、授权等功能组装起来,但是这些功能在Zope之外还是很难使用。于是有了Repoze项目。Repoze的目标是将Zope的功能组件拆解出来,使得其他的python web应用能够使用。说到这里,不禁又要感慨一下WSGI的重要意义:WSGI定义了Web服务器和Web应用以及Web中间件之间的交互协议,只要支持WSGI,各种web服务器、web应用和中间件就能相互对接。而Repoze正是将Zope组件按照WSGI进行封装,从而遵循WSGI的python web 框架可以很容易使用这些组件。

最初,Repoze推出了自己的一个非常轻量级的web框架:repoze.bfg。在repoze.bfg中利用了ZCA的特性。于是python web framework世界中又多了一方势力。但恰恰是这个不起眼的小势力推动了历史的进程。repoze.bfg和Pylons类似, 几乎都是完全的策略自由(policy-free),你可以随意的指定数据持久层,模板系统等外围部分,而其核心就是约定了URL如何映射到 view 代码以及如何调用view,在这个过程中完全遵循WSGI规范。后来repoze.cfg的开发者决定将其合并到Pylons。于是拉开了Python web框架合并的序幕。这个合并的框架叫做Pyramid。无独有偶,原本基于Pylons的TurboGears也宣布开发基于Pyramid的分支。

至此,混乱的江湖看到了统一的希望,相信越来越多的python web框架会融合,或至少能够互通。或许,随着更加开放的框架的出现,Django会慢慢淡出大家的视野,让我们拭目以待。

官網:http://www.pylonsproject.org/
en → zh
和网络

2013年6月11日 星期二

Cannot install MySQL-Python

It seems you have installed MySQL 5.5.10 and Python 2.6. Current version of MySQL-python (version 1.2.3) is supported from MySQL-3.23 through 5.0. However you can try installing it via ActivePython.
If you install ActivePython to the default path, open terminal and run:
/opt/ActivePython-2.6/bin/pypm install mysql-python
I had the similar case with MySQL 5.5 and Python 2.7 on my Fedora 15 platform and it worked well for me.
reference : http://stackoverflow.com/questions/6216009/cannot-install-mysql-python

2011年3月11日 星期五

Mac OSX 10.6 安裝Python 2.6.5 備忘錄

Snow Leopard原本內建的Python 2.6.1在使用urllib的urlopen()時
Python會有crash的風險
官網說,Python2.6.3以後的版本就修正好了的樣子
現在去抓就是Python2.6.5,那就來裝Python2.6.5吧~
測試環境OS,Mac OSX 10.6(Snow Leopard)
抓了官網上的python-2.6.5-macosx10.3-2010-03-24.dmg
安裝完之後發現site-packages不相通
所以原本安裝的module都不能import,淦!
只好一個一個module重裝一遍,2.6.5的site-packages位置在:
/Library/Frameworks/Python.framework/Version/2.6/lib/python2.6/site-packages
進去看果然全是空的。
module重裝到pycurl時,一直報錯丫丫丫丫!
後來同事找出問題點,Mac OSX原本附的Python 2.6.1是x86_64版
但我Download下來的dmg包會安裝成32bit版本
所以改用tar ball包來自行編譯x86_64版本
這個版本:Python 2.6.5 bzipped source tarball(http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2)
$ tar -xvzpf Python-2.6.5.tar.bz2
$ cd Python-2.6.5
$ ./configure –with-universal-arch=x86_64 –enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk –enable-framework=/Library/Frameworks –with-framework-name=Python2.6.5
這裡configure的參數說明:
–with-universal-arch=x86_64 (指定編譯成x86_64,如果不給這個參數,預設是i386,也就是32-bit版)
README底下的說明是用–with-universal-archs,但在執行時又報錯,要我用–with-universal-arch
後來發現,如果要用–with-universal-archs,其後的參數要用intel(i368和x86_64混合)
不然就要用–with-universal-arch,並指定’x86_64′
–enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk (指定OSX的SDK版本,這裡採用OSX 10.6)
–enable-framework=/Library/Frameworks (指定安裝在/Library/Frameworks路徑底下)
–with-framework-name=Python2.6.5 (指定安裝在/Library/Frameworks路徑底下的目錄名稱)
因為Python 2.6.1和Python 2.6.5(i386或x86_64)都是Python2.6,所以用Python2.6.5來區隔一下
$ make
$ sudo make install
雖然make install這裡,README有建議不要用sudo(superuser)來執行,但是權限上會有寫入的問題
還是得sudo一下,嘖嘖。
安裝完之後再到使用者的家目錄底下($ cd ~/),修改一下.base_profile
將原本指向舊Python的路徑改成新的Python路徑
這是我的:
# Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
# PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" (<這舊的)
PATH="/Library/Frameworks/Python2.6.5.framework/Versions/2.6/bin:${PATH}" (<這新的)
export PATH
儲存之後,關掉Terminal再進Terminal執行python
就是新的python2.6.5環境啦~

reference: http://chibakuma.net/blog/?p=107

2010年8月17日 星期二

Python Framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Developed four years ago by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.

官方網站:http://www.djangoproject.com/

wibiya widget