0
que = queue.Queue()
get_videos(que)


def get_videos(self, theQue):
        links = input('Enter links comma seperated: ')
        list = links.split(',')
        for i in list:
                theQue.put(i)
        return

My current code says "NameError get_videos is not defined" I guess I tried with and without self and neither help maybe I'm confused how this works.

Nathan Takemori
  • 139
  • 1
  • 10
  • 3
    self is only used in classes. Since this is not in a class, self is just another variable to pass to your function. You definitely should remove it. – Rashid 'Lee' Ibrahim Mar 22 '20 at 01:50

2 Answers2

1

You are calling the function before its definition, the interpreter has no clue what get_videos you are talking about or trying to call here, so you need to call it after it's defined

que = queue.Queue()


def get_videos(theQue):
        links = input('Enter links comma seperated: ')
        list = links.split(',')
        for i in list:
                theQue.put(i)
        return
get_videos(que)

Also self param is only for class methods, you could name your parameters anything you want, but you are passing only one value, the self gets passed automatically when you call this function on a class instance -it should be defined within the class-

kareem_emad
  • 1,123
  • 1
  • 7
  • 12
  • 1
    I was hoping to link in a good explanation of _why_ python is like this; [here's the best I found on short notice](https://stackoverflow.com/a/3756598/10135377). – ShapeOfMatter Mar 22 '20 at 01:56
0

You should write like that:

   def get_videos(self, theQue):
    links = input('Enter links comma seperated: ')
    list = links.split(',')
    for i in list:
            theQue.put(i)
    return
   que = queue.Queue()
   get_videos(que)
Marc Steven
  • 477
  • 4
  • 16