Skip to content

Howto - Python yield statement #1081

Open
@RickDW

Description

@RickDW

Hi folks, not sure if this is the best place to get some advice, feel free to let me know if it's not.
I'm trying to implement a Python class which has one method that uses two yield statements. My current PyCall implementation is this, but it gives me a "SyntaxError: 'yield' outside function":

using PyCall

textual = pyimport("textual")
pyimport("textual.app")
pyimport("textual.widgets")


@pydef mutable struct StopwatchApp <: textual.app.App
    function compose(self)
        py"""
        yield textual.widgets.Header()
        yield textual.widgets.Footer()
        """
    end
end

The full error is this:

Traceback (most recent call last)
in <lambda>:1

/home/name/.julia/packages/PyCall/1gn3u/src/pyeval.jl:1
const Py_single_input = 256 # from Python.h

SyntaxError: 'yield' outside function

yield doesn't seem to be discussed in PyCall's docs so I'm wondering if there's an implementation for this. Please give me a shout if you can help me out :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions