title: is it possible to access variable (local or global) main.py when running imported module function?
body: <p>e.g. I have 2 py script, namely <code>main.py</code> and <code>stringhelper.py</code>.</p>
  <p>Since <code>print(f'{student_{i}_{j}}')</code> cannot be read in IDE if variable <code>student_1_2</code> exist and if <code>i=1</code>,<code>j=2</code>,
  I want to make a function that can print  <code>'x{a{h}b{i}c{j}z}y'</code> by changing the string to</p>
  <pre><code>exec('''temp_s = 'a{}b{}c{}z'.format(h,i,j)''') # where I suppose e.g. h can refer to main.h but cannot
  exec('''print('x{}y'.format(f'{temp_s}')'''
  </code></pre>
  <p>In
  <code>stringhelper.py</code></p>
  <pre><code>import re
  def execprintf(s):
      
      
      if s.find('{')&lt;0:
          print(s)
          exec('''print(s)''')
      else:
          # use re to do sth to recongize {...{...{ case
          if conditionA: # {...{...{ case
              print('warning for input s')
          elif conditionB: # ... {...{ case 
              # not finished
              # not writing as I meet some problem for simple '{h}' case below
              pass
          else:
              ss = re.split('{|}',s)
              ss_even = ss[0::2]
              ss_odd = ss[1::2]
              s_wo_args = '{}'.join(ss_even)
              s_args = ', '.join(ss_odd)
              exec('''print(s_wo_args.format('''+s_args+'''))''')
  </code></pre>
  <p>In
  <code>main.py</code></p>
  <pre><code>from stringhelper.py import execprintf
  h = 1
  execprintf('{h}') # NameError: name 'h' is not defined
  </code></pre>
  <p>If I copy the <code>execprintf</code> function into <code>main.py</code> and does not <code>import</code> from <code>stringhelper.py</code>, it can read h and display 1.
  Is it possible to read the h in stringhelper.py?
  I need at least <code>exceprintf('a{h}b{i}c{j}d')</code> can run correctly first.</p>