I want to programmatically add 'someapp'
into django settings.py file, which looks like this:
before:
...
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
]
...
after:
...
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'someapp',
]
...
What comes to my mind is the following step:
- locate
^INSTALLED_APPS = [
string in the file - locate
]
string to indicate the end of string parsed. - fetch all the items within
[]
to avoid conflict - append
someapp
to the end of[]
This looks like a simple question, but I still want to know how to do it with best practice.
Although this is about python scripting, Bash script with GNU tools, like sed,awk,grep, are also welcomed.