0

I am new to VS Code and I am moving code over from jupyter notebook. I have two files, one with all the functions and one calling the functions. In the functions file I have this code:

def streamPosts(connection, cursor, subreddit, blacklist = None, ticker_list = None):
    Do Something


if __name__ == '__main__':
    streamComments(connection, cursor, subreddit, blacklist, ticker_list)

In jupyter notebook this code runs fine and the code in VS Code that calls this file also work fine but I am wondering why this code is causing errors by saying they are not defined. I understand that I have not created the variables since I do that in the other file but should VS Code recognize this?

Thanks.

  • 1
    Show how you're trying to call the functions from the other file. – Barmar Jul 13 '21 at 20:47
  • 3
    If you're importing this file, the `if __name__ == '__main':` code doesn't run. That line is for running a function if you run the functions script directly instead of loading it as a module. – Barmar Jul 13 '21 at 20:48
  • 1
    See https://stackoverflow.com/questions/419163/what-does-if-name-main-do/419185#419185 – Barmar Jul 13 '21 at 20:49
  • In Jupyter all variables are in ONE (1) namespace, the variables on the main program are not visible to the functions file, you can't import variables from main in the functions file, cyclic import, if you need these variables pass them along as arguments – rioV8 Jul 14 '21 at 06:13

0 Answers0