No such file or directory?
<p>For some reason despite having the file in the main and in the same directory, I keep getting the no such file error. Any help is appreciated. </p>

<pre><code>    import time
    def firstQues():

            print('"TT(Announcing): HONING IN FROM SU CASA CUIDAD, (Their hometown)"')
            time.sleep(3)
            print('"VEN EL UN.....(Comes the one.....)"')
            time.sleep(2)
            print('"EL SOLO......(The ONLY.....)"')
            time.sleep(3)
            print('"CampeÃ³n NOVATO (NEWBIE CHAMP)"')
            print()


            text_file = open("Questions1.txt", "r")
            wholefile = text_file.readline()
            for wholefile in open("Questions1.txt"):
                    print(wholefile)
                    return wholefile
                    return text_file

    def main():
            firstQues()
            text_file = open("Questions1.txt", "r")
    main()
</code></pre>

<p>The simplest solution comes down to a paradigm choice, <em>ask for permission</em> or <em>ask for forgiveness</em>.</p>

<p>Ask for permission: check if the file exists before using</p>

<pre><code>import os.path

if os.path.isfile("Questions1.txt"):
  #read file here
</code></pre>

<p>Ask for forgiveness: try-except block, report if issues</p>

<pre><code>try:
  #read file and work on it
except:
  print 'Error reading file'
</code></pre>

<p>If you use read-write flag, it will create a file when it doesn't exist, but it doesn't seem like you want to write</p>

<pre><code>with open("Questions1.txt", "rw") as f:
  #work on file
</code></pre>

<p>Pick your poison. Hope this helps :)</p>

python python-3.x