I keep getting 'invalid character in identifier' when opening a file in python

13,839

Two problems:

  1. Those tick characters are not valid. Use single ' or double " quotes.

  2. The correct syntax is with open(...) as f. You're missing the with statement.

The editor you're using should be highlighting your text in different colors to help you with this. If you don't have an editor that can do this, try downloading Sublime Text or Atom.

Share:
13,839
Vinci
Author by

Vinci

Updated on October 27, 2022

Comments

  • Vinci
    Vinci over 1 year

    So I'm trying to open a file with the following code:

    open(‘datapickle’, ‘rb’) as f: 
      names, F, approximate = pickle.load(f)
    

    However, I constantly get: enter image description here

    what can I do to fix this? Please help :(