Python - Function with incorrect return

Asked

Viewed 68 times

0

The code below is a simplistic example, but it represents exactly the error that is giving in my official code.

    def MontarURL(self):
    URL = "C:\\Users\\tttt\\Desktop\\Imagens\\2.png"
    return (URL)

    A = MontarURL
    print (A)

The return should be a URL and returns something like this: Main Function.Montarurl at 0x038EB390. Which is not just a display problem, because I’m going to need this URL in its normal way for another function.

How do I return exactly what it should and not just the memory address where the object is?

1 answer

0


You are not calling the function correctly, try this way:

def MontarURL():
    URL = "C:\\Users\\tttt\\Desktop\\Imagens\\2.png"
    return (URL)
# Você precisa chamar a função dessa forma, senão vai 
#retornar o endereço de memória bem como você já descobriu
A = MontarURL()
print (A)
  • The interesting thing is that it worked, but still, Pycharm points out as wrong for being lacking function self.

  • if this function is within a class, it really takes the self.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.