0
def time_stats(df):
    start_time = time.time()

When I run this code in VS Code it does run fine, however "time" is underlined: underlined word

and if I hover with the mouse there, I see an error message from PyLance that states:

"time" is not defined: UndefinedVariable

I did import time at the start of my file though and couldn't find clues in https://docs.python.org/3/library/time.html#time.time.

I guess this is not a big issue but since I'm learning I would love to have some advice so that I can avoid bad habits from the start.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
maud
  • 13
  • 1
  • 4
  • 3
    Sounds like a VS Code or PyLance problem, not so much Python. You may want to add the `VS Code` and/or [pylance] tags to your question, so people selecting on those tagsmay find your question more easily. – 9769953 Jun 22 '21 at 15:07
  • 1
    Apparently PyLance has a lot of problems with this, google autocompleted *"pylance no"* to *"pylance not detecting imports"* – Nick is tired Jun 22 '21 at 15:09
  • 1
    Does this answer your question? [VSCode settings for Pylance](https://stackoverflow.com/questions/65200732/vscode-settings-for-pylance) (and try to add your python libs directory to the list perhaps?) – Nick is tired Jun 22 '21 at 15:11
  • Thank you all! I'm glad to hear that it's probably not something to do with my code. – maud Jun 22 '21 at 15:45
  • @maud Could you run your code correctly? And can you enable flake8 linter? You can add this in your settings.json file: "python.linting.flake8Enabled": true, – Steven-MSFT Jun 23 '21 at 03:23
  • @maud And could you reload your VScode to have a try? Thanks a lot. – Steven-MSFT Jun 23 '21 at 03:24

1 Answers1

0

your code looks fine. few things you can check

  • Try disabling pylance.

  • if you are using python linters(pylint) then you might need to disable that too. check this Github issue for more details.

    python.linting.pylintEnabled": false use this code to disable pylint in your setting.json file.

Let me know if this helps.