python - 如何使用 python 和 Google AppEngine 编写或创建(当不存在时)文件

标签 python google-app-engine file

这是我的代码:

f = open('text/a.log', 'wb')
f.write('hahaha')
f.close()

不存在时不创建新文件

怎么做,

谢谢

已更新

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 App Engine。

来自Google App Engine documentation :

The Sandbox

Applications run in a secure environment that provides limited access to the underlying operating system. These limitations allow App Engine to distribute web requests for the application across multiple servers, and start and stop servers to meet traffic demands. The sandbox isolates your application in its own secure, reliable environment that is independent of the hardware, operating system and physical location of the web server. Examples of the limitations of the secure sandbox environment include:

  • An application cannot write to the file system. An app can read files, but only files uploaded with the application code. The app must use the App Engine datastore, memcache or other services for all data that persists between requests.

关于python - 如何使用 python 和 Google AppEngine 编写或创建(当不存在时)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2680215/

相关文章:

python - 如何将行字符串值转换为特征

python - 如何使用 json google translate api?

python - 无法从 VS Code 调试 Django 进程

python - Google AppEngine 使用哪个 simplejson 模块?

java - 对静态文件的请求是否会导致应用程序在 GAE 中启动?

python - 如何在 Google App Engine 中包含第三方 Python 库?

python - 从方法中获取字典?

php - $ _FILES中的 “type”来自哪里?

android - 在 flutter 中打开文件的正确方法?

C# 访问锁定的文件