如何使用python和Google AppEngine编写或创建文件(如果不存在) [英] how to write or create (when no exist) a file using python and Google AppEngine
本文介绍了如何使用python和Google AppEngine编写或创建文件(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
f = open('text/a.log', 'wb')
f.write('hahaha')
f.close()
它不存在时不会创建新文件
and it is not create a new file when not exist
如何做到这一点,
谢谢
已更新
class MyThread(threading.Thread):
def run(self):
f = open('a.log', 'w')
f.write('hahaha')
f.close()
错误是:
Traceback (most recent call last):
File "D:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "D:\zjm_code\helloworld\views.py", line 15, in run
f = open('a.log', 'w')
File "d:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1188, in __init__
raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: w
推荐答案
由于Google Appengine不允许您写入文件
Its because of google appengine not allowed you to write files
它的定义是这样的
ALLOWED_MODES = frozenset(['r', 'rb', 'U', 'rU'])
和
if mode not in FakeFile.ALLOWED_MODES:
raise IOError('invalid mode: %s' % mode)
注意:"U"是通用换行模式, http://docs.python.org/library/io.html#io.open
Note: 'U' is universal newline mode, http://docs.python.org/library/io.html#io.open
修改:您可能会对Google AppEngine 登录感兴趣>他们文档中的会话
Edit: You might interest Google AppEngine Logging session in their documents
示例
import logging
....
logging.error('There was an error retrieving ...')
logging.debug('Finish something')
这篇关于如何使用python和Google AppEngine编写或创建文件(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文