def nl2br(string, is_xhtml= True ):
if is_xhtml is True :
return string.replace('\n','
\n')
else :
return string.replace('\n','
\n')
實現explode
>>> str = 'a|b|c|d|e'
>>> str.split("|")
['a', 'b', 'c', 'd', 'e']
實現implode
>>> list = ['a', 'b', 'c', 'd', 'e']
>>> "|".join(list)
'a|b|c|d|e'
2011年6月25日 星期六
GAE is not multi-line
在GAE中如果有多行文字儲存,有\n換行符號
GAE會報錯(
請對model 加上參數 db.StringProperty(multiline=True)
GAE會報錯(
is not multi-line)請對model 加上參數 db.StringProperty(multiline=True)
2011年4月12日 星期二
2011年1月19日 星期三
2011年1月13日 星期四
使用remote_api直接調用遠端的db model
#!/usr/bin/env python
#
import os
import sys
# Hardwire in appengine modules to PYTHONPATH
# or use wrapper to do it more elegantly
appengine_dirs = ['/Applications/blah/blah/google_appengine'...]
sys.path.extend(appengine_dirs)
# Add your models to path
my_root_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, my_root_dir)
from google.appengine.ext import db
from google.appengine.ext.remote_api import remote_api_stub
import getpass
from models.mystuff import Foo
APP_NAME = 'my-app'
os.environ['AUTH_DOMAIN'] = 'gmail.com'
os.environ['USER_EMAIL'] = 'me@gmail.com'
def auth_func():
return (raw_input('Username:'), getpass.getpass('Password:'))
# Use local dev server by passing in as parameter:
# servername='localhost:8080'
# Otherwise, remote_api assumes you are targeting APP_NAME.appspot.com
remote_api_stub.ConfigureRemoteDatastore(APP_NAME,
'/remote_api', auth_func)
# Do stuff like your code was running on App Engine
foos = Foo.all().fetch(100)
for foo in foos:
foo.note = 'Hello World!'
db.puts(foos)由ConfigureRemoteDatastore換掉所操作的model,由ConfigureRemoteDatastore
對model定義,code中沒看到定義 Foo
2010年7月22日 星期四
Python的UUID產出辦法
python的uuid模組有四種方式可以產生uuid
以上分別對應的方式為:
#-*- encoding: utf-8 -*-
import uuid

print uuid.uuid1()
print uuid.uuid3(uuid.NAMESPACE_DNS, 'testname')
print uuid.uuid4()
print uuid.uuid5(uuid.NAMESPACE_DNS, 'testme')
- 使用硬體及時間
- 以MD5對字串取值
- 隨機產生
- 使用SHA-1
以上分別對應的方式為:
訂閱:
意見 (Atom)