Opening/Attempting to Read a file

13,457

Solution 1

This is a known issue in PyCharm, when it fails to update its cache of the interpreter. It happens most often if you install a new interpreter, update packages, etc.

You can search for this and related issues at the pycharm bug tracker

Its a temporary problem and will resolve itself. Keep an eye on the bottom right of the PyCharm window where it displays notifications (next to the icon of the guy in the hat). Click on this and the Event Log will have some messages for you.

If its really bothering you, you can hit ALT+ENTER and click "Ignore unresolved reference open"

Solution 2

Have you checked your preferences to make sure that you are using the correct python interpreter? ie define which version of python pyCharm should be using? This is set in your preferences:

Ctl+Shift+a (cmd+shift+a on Mac) and type "project interpreter", then set this to be python 2.x or 3.x depending on what you have installed(or whatever virtualEnv you have defined).

Then you can invalidate the cache and restart.

Share:
13,457
Évariste Galois
Author by

Évariste Galois

.

Updated on June 09, 2022

Comments

  • Évariste Galois
    Évariste Galois almost 2 years

    I tried to simply read and store the contents of a text file into an array, but:

    ins = open( "file.txt", "r" )
    array = []
    for line in ins:
        array.append( line )
    ins.close()
    

    It gives me an error for "open":

    Unresolved reference 'open' less... (Ctrl+F1) 
    

    This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.

    Can anyone explain what I'm doing wrong? Thanks

  • Kevin
    Kevin over 9 years
    Ok, but how does this fix the "Unresolved reference 'open'" error?
  • Évariste Galois
    Évariste Galois over 9 years
    That's not the problem.. Once again the term "open" yields the same error: Unresolved reference 'open'