0

I have .py file which contains list. I want to read this file and append elements to the list and save the file. I tried Access Python parse trees I am feeling lost with this module.Is there any easy way of doing it? or Any example of using Access Python parse trees that can help me out

Amar
  • 666
  • 5
  • 13
  • So having a file `a.py` containing `some_list = ['A', 'B', 'C']` you want to open it from inside some other python file, append some elements to it and have `a.py` contain ``some_list = ['A', 'B', 'C', 'new Element']`` after this operation? – Simon Fromme May 22 '16 at 02:21
  • @siwica yes correct. Thats it I wanna do. – Amar May 22 '16 at 02:25
  • 1
    Since this will be far from trivial: Why do you want to do this? – Simon Fromme May 22 '16 at 02:26
  • I am using this for django. I have list containing installed apps which is django way of configuring an app in project and I have an function that creates another app, so the app name need to be appended to this list for configuring. – Amar May 22 '16 at 02:29
  • do you have any failed coding attemps that provide some error messages that you can share with us? – glls May 22 '16 at 02:32
  • 1
    @Amar: See the following question: http://stackoverflow.com/questions/24027901/dynamically-loading-django-apps-at-runtime – Simon Fromme May 22 '16 at 02:34
  • @siwica this is great thank you so much! But I want this app to be added permanently to the app list not just during run time. I suppose app would be uninstalled if the server restarts. – Amar May 22 '16 at 02:50
  • 2
    Since I am not using Django myself I am not sure how this works. But there will definitely be a better solution then playing around with the parse tree. You should probably open a new question with this exact problem. When you find yourself in the situation of attempting to do something very unusual you should at first ask yourself if there is another solution to the more general problem before further pursuing the unusual one. – Simon Fromme May 22 '16 at 02:55
  • @siwica Thanks man! – Amar May 22 '16 at 02:56

0 Answers0