You shouldn't upload simplejson module to GAE. As some people have already mentioned, you should write below.
from django.utils from simplejson
GAE uses Django framework. Django includes simplejson module.
seealso
NO BLOG, NO LIFE
You shouldn't upload simplejson module to GAE. As some people have already mentioned, you should write below.
from django.utils from simplejson
GAE uses Django framework. Django includes simplejson module.
seealso
Posted at 02:54 AM in Python | Permalink | Comments (0) | TrackBack (0)
Python
Easily add social capabilities to your website or web application using the Python SDK.
Source code, complete documentation and examples are provided on the GitHub project page.
As you may know, Yahoo! provides OAuth. Above quoted paragraph mentioned Python SDK. The SDK has some examples, especially appengine example. The example is hosted by GAE. You can try it soon. The URL is http://yapdemo.appspot.com/.
If you have any plans your application uses Yahoo! API - delicious, Yahoo! Mail, etc -, you'd see the SDK. Also you'd read the document: OAuth / OpenID Guides.
Posted at 02:53 AM in Python | Permalink | Comments (0) | TrackBack (0)
I'm a beginner of Python. I tried to split extension. I don't know the best way. use os.path.splitext? or regexp?
In case of regexp
>>> import pre
>>> p = re.compile('^.*\.(.*)')
>>> m = p.match('http://www.example.com/index.html')
>>> m.group(1)
'html'
Or in case of os.path.splitext
>>> import os.path
>>> os.path.splitext('http://www. example.com/index.html')
('http://www. example.com/index', '.html')
I like using os.path.splitext rather than regexp in this case. Any thought?
Posted at 01:26 AM in Python | Permalink | Comments (0) | TrackBack (0)
I tried to run jaikuengine on my Mac OS X (Tiger). I got following error.
LookupError: unknown encoding: X-MAC-JAPANESE
jaikuengine has django.
$ cd <YOUR_JAIKUENGINE_ROOT> $ svn pg svn:externals vendor django http://code.djangoproject.com/svn/django/tags/releases/1.0/django
Then I needed to patch to tzinfo.py on this version.
$ svn diff vendor/django/utils/tzinfo.py Index: vendor/django/utils/tzinfo.py =================================================================== --- vendor/django/utils/tzinfo.py (revision 11784) +++ vendor/django/utils/tzinfo.py (working copy) @@ -7,6 +7,8 @@ try: DEFAULT_ENCODING = locale.getdefaultlocale()[1] or 'ascii' + if DEFAULT_ENCODING == 'X-MAC-JAPANESE': + DEFAULT_ENCODING = 'ascii' except: # Any problems at all determining the locale and we fallback. See #5846. DEFAULT_ENCODING = 'ascii'
Reference from Mac OSXにDjango最新版を | tsuyuki.makoto. This article was written in Sep 2007. But this was good information to me in this case. Thanks!
Posted at 01:49 AM in Python | Permalink | Comments (0) | TrackBack (0)
Python では simplejson がデファクトっぽい感じだったので、simplejson をインストールしようと思ったら、以下のようなエラーメッセージが。。。
# wget http://pypi.python.org/packages/source/s/simplejson/simplejson-1.3.tar.gz#md5=fbe039b9b863572651a0f665acea34c9
# tar zxvf simplejson-1.3.tar.gz
# cd simplejson-1.3
# python setup.py install
---------------------------------------------------------------------------
This script requires setuptools version 0.6a11 to run (even to display
help). I will attempt to download it for you (from
http://cheeseshop.python.org/packages/2.5/s/setuptools/), but
you may need to enable firewall access for this script first.
I will start the download in 15 seconds.
(Note: if this machine does not have network access, please obtain the file
http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0.6a11-py2.5.egg
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------
Downloading http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0.6a11-py2.5.egg
Traceback (most recent call last):
File "setup.py", line 4, inez_setup.use_setuptools()
File "/private/var/root/tmp/simplejson-1.3/ez_setup/__init__.py", line 88, in use_setuptools
egg = download_setuptools(version, download_base, to_dir, download_delay)
File "/private/var/root/tmp/simplejson-1.3/ez_setup/__init__.py", line 142, in download_setuptools
src = urllib2.urlopen(url)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 419, in error
result = self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 582, in http_error_302
return self.parent.open(new)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
そもそも setuptools というのが必要みたい。(ごめんなさい。私は Python はよくわからないです。。。)
で、setuptools のサイト http://pypi.python.org/pypi/setuptools にアクセスして、Mac OS X の項を見つつ、次のように実施しました。
# wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg#md5=fe67c3e5a17b12c0e7c541b7ea43a8e6
# sh setuptools-0.6c9-py2.5.egg
なんと setuptools のインストールはとても簡単。
そして引き続き、simplejson のインストール
# python setup.py install
(中略)
Installed /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/simplejson-1.3-py2.5.egg
Processing dependencies for simplejson==1.3
Finished processing dependencies for simplejson==1.3
すばらしい。あっさり入りましたぞ。
ってことで simplejson は setuptools があればあっさりインストールできますよ、というお話でした。
年末のテレビを見ながらダラダラと simplejson と setuptools を調べていた私でした。本年もどうぞよろしく。(なんのこっちゃ)
seealso:
Posted at 01:43 AM in Python, typepad.jp | Permalink | Comments (0) | TrackBack (0)
最初に知ったときからだいぶ時間があいてしまったのですが、やっと試す時間が作れました。今日は Google App Engine についてメモです。
Google App Engine は Python 2.5 以上が必要なのですね。Google App Engine のインストール時に Python 2.5 以上がないと警告が出ましてインストールは途中で終了します。。。
Python はこちらからダウンロードできるようです。
さて、ここからやっと Google App Engine を使う準備が整ったことになりますね。
私の環境は Mac OS X (10.4.11、つまり Tiger) を使っています。
Google App Engine は /usr/local/google_appengine/ にインストールされました。
# find /usr/local/google_appengine/ -type f
としてみると Django が。へー。
さてインストールが完了したら早速触ってみます。まずは日本語版のスタートガイドを最初から順番においかけてみます。こういうときは写経です。
* 概要
* 開発環境
* Hello, World!
* webapp フレームワークの使用
* ユーザー サービスの使用
* webapp を使ったフォームの操作
* データストアの使用
* テンプレートの使用
* 静的ファイルの使用
* アプリケーションのアップロード
このスタートガイドでは最初は文字列 helloworld だけを表示するアプリをゲストブックアプリに成長させていくストーリーになっています。早速、「webapp フレームワークの使用」から「コンテンツを次のように置き換えます。」とどんどん上書きしていく形をとっています。(もし自分の心が写経モードだったときには章単位で新しいファイルを用意して、コピペではなくてちゃんとタイプしていくというのがいいですね。今回私はそのやり方にしました。)
とても簡単にアプリの開発ができる感じですね。Rails や Catalyst のように開発用のミニサーバで小さく作っていくスタイルはモチベーションが高まっていきますね。
Google App Engine はなかなか良さげです。早速自作アプリを作成しようと今コードを書いています。まだ Python をはじめて間もない、というか Google App Engine に触れるまでは Python のコードを書いたことがなかったので、これから一般的に使われるモジュールなどを知りたいな。おそらく Google App Engine で使えるモジュールと使えないモジュールがあると想像しているので、その辺りの違いなんかもこれから勉強したいです。
Python も結構面白いよ。
最後にいくつか特記しておきます。
データストアの使用
ここで以下のエラーで詰まりました。
Traceback (most recent call last):
File "/usr/local/google_appengine/google/appengine/ext/webapp/__init__.py", line 484, in __call__
handler.get(*groups)
File "/Users/takatsugu/GAE/helloworld/helloworld5.py", line 17, in get
greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
File "/usr/local/google_appengine/google/appengine/ext/db/__init__.py", line 1496, in __init__
from google.appengine.ext import gql
SystemError: Parent module 'google.appengine.ext.db' not loaded
よく調べてみると、/usr/local/google_appengine/demos/guestbook にこの章と似たようなサンプルがありました。コードを見比べても特に大きな違いは見られなかったので、試しにその demos/guestbook を起動しましたら、期待された動作が出来ました。「やっぱり何か違うのかなー」と思って、dev_appserver.py helloworld/ としたら、今度は上記のエラーを出力せずに起動しました。もしかして db,Model はサーバ起動時に生成されるのかな?これまで、 Hello, World!、 webapp フレームワークの使用、 ユーザー サービスの使用、 webapp を使ったフォームの操作、とずっと dev_appserver.py を Ctrl + C で終了させずにきたのでした。。。
とりあえずこのエラーが出たときには dev_appserver.py が起動していたら Ctrl + C で一旦停止した後、再び dev_appserver.py 起動するというのが対処法っぽいですね。(将来的にはgoogle_appengine か dev_appserver.py などのフレームワーク関係のコードを見てみてることにします。とりあえずは「開発用 Web サーバ」の章が参考になります。)
テンプレートの使用
ここでは以下のようなエラーが出ました。
Traceback (most recent call last):
File "/usr/local/google_appengine/google/appengine/ext/webapp/__init__.py", line 484, in __call__
handler.get(*groups)
File "/Users/takatsugu/GAE/helloworld/helloworld6.py", line 34, in get
self.response.out.write(template.render(path, template_values))
File "/usr/local/google_appengine/google/appengine/ext/webapp/template.py", line 80, in render
t = load(template_path, debug)
File "/usr/local/google_appengine/google/appengine/ext/webapp/template.py", line 125, in load
template = django.template.loader.get_template(file_name)
File "/usr/local/google_appengine/lib/django/django/template/loader.py", line 79, in get_template
source, origin = find_template_source(template_name)
File "/usr/local/google_appengine/lib/django/django/template/loader.py", line 54, in find_template_source
mod = __import__(module, globals(), locals(), [attr])
SystemError: Parent module 'django.template' not loaded
ここでもデータストアの使用のときと同様に dev_appserver.pl を再起動したところエラーが解消されました。テンプレートエンジンには Django テンプレート エンジン を使っているんですねぇ。本家サイトでは記法が詳しく書かれています。
Posted at 08:42 PM in Programming, Python, typepad.jp, Web/Tech | Permalink | Comments (0) | TrackBack (0)