Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
How to pass a function result to a tuple?

I am working on a Python/Django/Wagtail project, and at some point I have a class like this:

class SuperClass(BaseClass):

    body = StreamField([
        ('overview_speakers', OverviewSpeakers()),
    ])

    def some_function():
        return 'Hola'

OverviewSpeakers is a class that is expecting an argument and I want to try to pass in the results of some_function()

I tried both:

body = StreamField([
    ('overview_speakers', OverviewSpeakers(self.some_function())),
])

and

body = StreamField([
    ('overview_speakers', OverviewSpeakers(SuperClass.some_function())),
])

But respectively it yells that self or SuperClass are not defined.

What can I do to pass in the results of the function?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Check this out:

class SuperClass(BaseClass):

    def some_function():
        return 'Hola'

    body = StreamField([
        ('overview_speakers', OverviewSpeakers(some_function())),
    ])
over 4 years ago · Santiago Trujillo Relatório

0

You cannot refer to a class that is being defined, but you can add attibutes to it after it is defined. So this should work:

class SuperClass(BaseClass):
    def some_function():
        return 'Hola'

SuperClass.body = StreamField([
    ('overview_speakers', OverviewSpeakers(SuperClass.some_function())),
])
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda