Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:41:08+00:00 2026-06-13T07:41:08+00:00

def method(self, *args): def function(*args): #can this access all method’s variables, data, etc.

  • 0
def method(self, *args):
   def function(*args):
      #can this access all method's variables, data, etc.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:41:09+00:00Added an answer on June 13, 2026 at 7:41 am

    Yes you can,because python follows the following look-up rule while finding a variable:

    LEGB:

    L:local
    E:enclosing
    G:global
    B:built-in
    

    So, in your case it’s E:

    python 2.x:

    in python 2.x you can’t modify those variables in the func

    class A:
        def meth(self):
            foo=1
            bar=2
            def func():
                foo=2     # if you place this statement below the print statement then you'll get
                          # UnboundLocalError: local variable 'foo' referenced before assignment
                print foo,bar
            func()    
            print (foo) #meth's foo is unchanged
    a=A()
    a.meth()
    

    output:

    2 2 
    1
    

    python 3.x:
    use nonlocal to even modify the variables:

    class A:
        def meth(self):
            foo=1
            bar=2
            def func():
                nonlocal foo,bar             
                print (foo,bar)
                foo=2               #changes meth's foo to 2
            func()    
            print (foo)
    a=A()
    a.meth()
    

    output:

    1 2
    2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Best Guess: method - def(self, maybeSomeVariables); lines of code which achieve some purpose Function
I have a class that contains this class method: def self.get_event_record(row, participant) event =
How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
module Test def self.model_method puts this is a module method end end class A
I've defined this class: class RequiredFormSet(BaseFormSet): def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) And
I am overriding the save method on one of my models: def save(self, *args,
I have a private method def __pickSide(self): in a parent class that I would
I have a method which calls for a classmethod of another class def get_interface_params_by_mac(self,
I'm new to Python. I have a method that begins: def foo(self, list): length
I have this class: from threading import Thread import time class Timer(Thread): def __init__(self,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.