ealeon
ealeon

Reputation: 12452

Python visibility to pass in function

In A.py

class A
  blah = some_fun(d)      <----- needs d
  def __init__
  def a
  def b

def c
  def d                 <---- d is inside c

is it possible to pass in d because currently blah cannot see d for obvious reasons?

Upvotes: 0

Views: 105

Answers (3)

superdud
superdud

Reputation: 91

How about:

class A
  blah = some_fun(d)
  def __init__
  def a
  def b

def c
  global d
  def d                 <---- d is now global

Upvotes: 0

Adrian Ratnapala
Adrian Ratnapala

Reputation: 5673

You can define class A inside the function c, in which case it will be able to see d (assuming d is defined first). Then you might need to pass out A from the function so that outsiders can use it.

Something about this smells like you are solving the wrong problem for the real task at hand. Perhaps you could clarify your question and/or give a more concrete example.

Upvotes: 0

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 250911

Something like this:

def c():
    def d():
        pass
    return d

blah = some_fun(c())

Upvotes: 2

Related Questions