title: Plain-text, Python-syntax file to save and restore some class variables?
body: <p>In my case, I'd like to save and restore some "plain" variables (i.e., ints, strings) in a file, which would end up as class properties. This example is the closest I got, by using <code>import</code>:</p>
  
  <p><strong><code>a.py</code></strong></p>
  
  <pre><code>b = 134
  a = "hello"
  </code></pre>
  
  <p><strong><code>mytest.py</code></strong></p>
  
  <pre><code>import inspect
  
  class Teost:
    from a import *
    def __init__(self):
      self.c = 12
      print(inspect.getmembers(self)) # has a and b
      print(self.__dict__)            # no a and b
      print(self.a)                   # prints "hello"
  
  xx = Teost()
  </code></pre>
  
  <p>So, here <code>a.py</code> acts as the file storing the variable values (<code>a</code> and <code>b</code>), and <code>from a import *</code> inside the class gets them as class properties (<code>self.a</code> and <code>self.b</code>), which is pretty much what I want.</p>
  
  <p>Unfortunately, turns out using starred <code>import</code> syntax in a class is frowned upon:</p>
  
  <pre><code>$ python mytest.py
  mytest.py:3: SyntaxWarning: import * only allowed at module level
    class Teost:
  [('__doc__', None), ('__init__', &lt;bound method Teost.__init__ of &lt;__main__.Teost instance at 0x7fdca368ab90&gt;&gt;), ('__module__', '__main__'), ('a', 'hello'), ('b', 134), ('c', 12)]
  {'c': 12}
  hello
  </code></pre>
  
  <p>... so I get an ugly "SyntaxWarning: import * only allowed at module level", which I cannot get rid of (unless I disable warnings, which I don't want to do)</p>
  
  <p>So, do I have any other options, to use a file written as <code>a.py</code> (i.e. in plain-text, Python syntax), and have the variables in it end up as some classes properties?</p>
  
  <p>(I've seen <a href="https://stackoverflow.com/questions/6568007/how-do-i-save-and-restore-multiple-variables-in-python">How do I save and restore multiple variables in python?</a>, but I'm not interested in <code>pickle</code> or <code>shelve</code> because neither of them writes in a Python-syntax, plain-text file)</p>