Opening / attempting to read a file

I tried to just read and save the contents of the text file into an array, but:

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

This gives me an error for "open":

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

This check discovers the names that should be resolved, but not. Due to dynamic sending and duck printing, this is possible in a limited but useful number of cases. Top-level and class-level elements are better supported than instance elements.

Can someone explain what I'm doing wrong? Thanks

+4
source share
3 answers

This is a known issue in PyCharm when it does not update its interpreter cache. This happens most often if you install a new interpreter, service packs, etc.

pycharm

. PyCharm, ( ). , .

, ALT + ENTER " "

+4

, , python? .. , python pyCharm ? :

Ctl + Shift + a (cmd + shift + a Mac) " ", python 2.x 3.x , ( , ).

.

+1
array = []

with open('/path/to/file', 'r') as fp:
    for line in fp.readlines():
        array.append(line)
-2
source

All Articles