如何在django中使用shell命令在目录中创建文件
答
Django,只是一个Python框架。所以,你可以在Django中做什么,你可以在Python中做什么。
在Python中,打开(和创建)文件的方式是open(filename, mode)
。
>>> f = open('testing', 'w')
之后,你有一个文件对象,你可以写在上面,并做你需要做的一切后,关闭它。
>>> f.write('Hello world!')
>>> f.close()
>>> f = open('testing', 'r')
>>> f.read()
'Hello world!'
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files –