title: How to keep open a file in mutiple functions python
body: <p>Hey I would like to know how do I keep open :
  <code>open(namefile + ".py", 'w')</code> in multiple fonctions , like :</p>
  
  <pre><code>invalid_inputCHOICE = True
  invalid_inputCHOICE2 = True
  
  
  def start():
      invalid_inputCHOICE = False
      print('creating file')
      with open("Hello World.txt", 'w') as f:
          f.write('Hello\n')
          world()
  
  
  
  def world():
      invalid_inputCHOICE2 = False
      Answer = input('Should I write World ?')
      if Answer == 'yes':
          f.write('world')
      if Answer == 'no':
          print('Okay')
      else:
          print('please enter yes or no')
          world()
  
  while invalid_inputCHOICE:
      start()
  while invalid_inputCHOICE2:
      world()
  </code></pre>
  
  <p>and I got error : f is not defined but I defined it up .
  So how can I do to fix this but keep my functions ?
  error logs : </p>
  
  <pre><code>Traceback (most recent call last):
    File "H:/PYTHON-WORKSPACE/FileCreations.py", line 26, in &lt;module&gt;
      start()
    File "H:/PYTHON-WORKSPACE/FileCreations.py", line 10, in start
      world()
    File "H:/PYTHON-WORKSPACE/FileCreations.py", line 23, in world
      world()
    File "H:/PYTHON-WORKSPACE/FileCreations.py", line 18, in world
      f.write('world')
  NameError: name 'f' is not defined
  </code></pre>