开发者

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

开发者 https://www.devze.com 2023-04-12 15:31 出处:网络
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 f

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

精彩评论

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

关注公众号