开发者

How to create file in a directory using shell commands in django

Iam doing a project in django where i ha开发者_如何转开发ve to concatenate some log files and place it in the new file. How to create a file using shell commands in django???


Django, is just a Python framework. So, what you can do in Django is pretty much what you can do in Python.

In Python, the way to open (and create) files is with open(filename, mode).

>>> f = open('testing', 'w')

After you have a file object, you can write on it, and after doing everything you needed to do, close it.

>>> f.write('Hello world!')
>>> f.close()
>>> f = open('testing', 'r')
>>> f.read()
'Hello world!'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜