1,python2.4不支持下面这种异常处理语法
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
try
:
except :
finally :
except :
finally :
只有2.5以上才行,为此只能改成下述写法,damn fuck python 2.4...
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
try
:
try :
except :
finally :
try :
except :
finally :
2,python实现单例模式的一种方法:
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
class
MyClass:
_instance = None
def __init__ (self):
pass
@staticmethod
def getInstance():
if not MyClass._instance:
MyClass._instance = MyClass()
return MyClass._instance
_instance = None
def __init__ (self):
pass
@staticmethod
def getInstance():
if not MyClass._instance:
MyClass._instance = MyClass()
return MyClass._instance
3,python读取文本文件
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
f
=
open(filePath)
#
打开文本文件,默认模式是只读
try : # damnpython2.4...
try :
for line in f:
name,age = line.split() # 每一行是name,age
process(name,age) # 进行处理
except EOFError:
pass
finally :
f.close()
try : # damnpython2.4...
try :
for line in f:
name,age = line.split() # 每一行是name,age
process(name,age) # 进行处理
except EOFError:
pass
finally :
f.close()
4,python实现以POST方式提交数据
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
params
=
urllib.urlencode({
'
name
'
:self.name})
try :
try : # damnpython2.4...
conn = urllib2.urlopen(self.crossBattleServiceURL,params) # 提交请求
result = conn.read()
print result
except HTTPError,e:
print ' httperror: ' ,e.reason
except URLError,e:
print ' urlerror: ' ,e.reason
finally :
conn.close()
try :
try : # damnpython2.4...
conn = urllib2.urlopen(self.crossBattleServiceURL,params) # 提交请求
result = conn.read()
print result
except HTTPError,e:
print ' httperror: ' ,e.reason
except URLError,e:
print ' urlerror: ' ,e.reason
finally :
conn.close()
5,Android中调试服务
参考文章:http://www.helloandroid.com/tutorials/how-debug-service
在Android中service的调试和普通的Application不同,如果仅仅设置断点的话,调试器是不会在你的断点处停下来的,解决方法就是
在代码中声明,以便让调试器能到你声明的地方。你只需加入下面这一句代码即可:
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
android.os.Debug.waitForDebugger();
你的断点可以设置在这句调用后面任何地方。
举例如下:
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br/ /> <br/ /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ /> http://www.CodeHighlighter.com/<br/ /> <br/ /> -->
public
class
SoftKeyboard
extends
InputMethodService
implements
KeyboardView.OnKeyboardActionListener
{
@Override
public void onConfigurationChanged(ConfigurationnewConfig)
{
Log.d( " SoftKeyboard " , " onConfigurationChanged() " );
/* nowlet'swaituntilthedebuggerattaches */
android.os.Debug.waitForDebugger();
super .onConfigurationChanged(newConfig);
/* dosomethinguseful... */
}
{
@Override
public void onConfigurationChanged(ConfigurationnewConfig)
{
Log.d( " SoftKeyboard " , " onConfigurationChanged() " );
/* nowlet'swaituntilthedebuggerattaches */
android.os.Debug.waitForDebugger();
super .onConfigurationChanged(newConfig);
/* dosomethinguseful... */
}
6,HTML5的前景确实是越来越明朗化了,不断有新的游戏作品出来,但flash短时间内肯定还是可以维持目前的王者之位,不过Adobe真的要努力了。看看Google这个Quake II的移植项目,感兴趣的话可以一试: