1python2.4不支持下面这种异常处理语法

  1. try:
  2. except:
  3. finally:

只有2.5以上才行,为此只能改成下述写法,damn fuck python 2.4...

  1. try:
  2. try:
  3. except:
  4. finally:

2,python实现单例模式的一种方法:

  1. class MyClass:
  2. _instance = None
  3. def __init__(self):
  4. pass
  5. @staticmethod
  6. def getInstance():
  7. if not MyClass._instance:
  8. MyClassMyClass._instance = MyClass()
  9. return MyClass._instance

3,python读取文本文件

  1. f = open(filePath) #打开文本文件,默认模式是只读
  2. try:  #damn python 2.4...
  3. try:
  4. for line in f:
  5. name,age = line.split() #每一行是name,age
  6. process(name,age) #进行处理
  7. except EOFError:
  8. pass
  9. finally:
  10. f.close()

4,python实现以POST方式提交数据

  1. params = urllib.urlencode({'name':self.name})
  2. try:
  3. try: #damn python 2.4...
  4. conn = urllib2.urlopen(self.crossBattleServiceURL, params) #提交请求
  5. result = conn.read()
  6. print result
  7. except HTTPError,e:
  8. print 'http error:',e.reason
  9. except URLError,e:
  10. print 'url error:',e.reason
  11. finally:
  12. conn.close()

5,Android中调试服务

      参考文章:http://www.helloandroid.com/tutorials/how-debug-service

      Androidservice的调试和普通的Application不同,如果仅仅设置断点的话,调试器是不会在你的断点处停下来的,解决方法就是

      在代码中声明,以便让调试器能到你声明的地方。你只需加入下面这一句代码即可:

  1. android.os.Debug.waitForDebugger();

  你的断点可以设置在这句调用后面任何地方。

      举例如下:

  1. public class SoftKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener
  2. {
  3. @Override
  4. public void onConfigurationChanged(Configuration newConfig)
  5. {
  6. Log.d("SoftKeyboard", "onConfigurationChanged()");
  7. /* now let's wait until the debugger attaches */
  8. android.os.Debug.waitForDebugger();
  9. super.onConfigurationChanged(newConfig);
  10. /* do something useful... */
  11. }

6HTML5的前景确实是越来越明朗化了,不断有新的游戏作品出来,但flash短时间内肯定还是可以维持目前的王者之位,不过Adobe真的要努力了。看看Google这个Quake II的移植项目,感兴趣的话可以一试:

http://www.cnbeta.com/articles/107768.htm

http://code.google.com/p/quake2-gwt-port/