我正在摆弄输出一个json文件,其中包含目录中文件的一些属性.我的问题是,当附加到文件时,每个对象之间没有分隔符.我可以在每个'f'之后添加一个逗号并删除最后一个,但这对我来说似乎是一个草率的工作.
import os
import os.path
import json
#Create and open file_data.txt and append
with open('file_data.txt', 'a') as outfile:
files = os.listdir(os.curdir)
for f in files:
extension = os.path.splitext(f)[1][1:]
base = os.path.splitext(f)[0]
name = f
data = {
"file_name" : name,
"extension" : extension,
"base_name" : base
}
json.dump(data, outfile)
Run Code Online (Sandbox Code Playgroud)
这输出:
{"file_name": "contributors.txt", "base_name": "contributors", "extension": "txt"}{"file_name": "read_files.py", "base_name": "read_files", "extension": "py"}{"file_name": "file_data.txt", "base_name": "file_data", "extension": "txt"}{"file_name": ".git", "base_name": ".git", "extension": ""}
我想要的是实际的JSON:
{"file_name": "contributors.txt", "base_name": "contributors", "extension": "txt"},{"file_name": "read_files.py", "base_name": …
我有一个 Django 应用程序,我试图在带有 Gunicorn 的 Ubunutu VPS 上设置,但在运行时遇到错误gunicorn project:application -b myip:8000。这是结果的输出:
Traceback (most recent call last):
File "/home/user/project/env/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
super(Application, self).run()
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
self.manage_workers()
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
time.sleep(0.1 * random.random())
File "/home/user/project/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
self.reap_workers()
File …Run Code Online (Sandbox Code Playgroud)