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 8934481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:47:51+00:00 2026-06-15T09:47:51+00:00

I am trying to figure out how to put a define function inside a

  • 0

I am trying to figure out how to put a define function inside a define function inside of a class. Python code of what I want to do:

class Guy():
    def move(self):
        def left(self):
            //compute
        def right(self):
            //compute
        def up(self):
            //compute
        def down(self):
            //compute

And then be able to call Guy.move.right() later on in the program. The interpreter gives me an error saying ‘Function has no attribute right’ or something like that. Is there any way to do this without having to bring my functions out of the move function and calling them Guy.right, Guy.left, 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-15T09:47:52+00:00Added an answer on June 15, 2026 at 9:47 am

    this is a bad way to code…

    there is no way to call left function under Guy class since it is in the scope of move function, and unlike class, adding a function inside another function does not make it its attribute.

    Until the inside function is a attribute of the outside function there is no way to call it using the name of the enclosing function

    In case

    def move():
        def left():
    

    i.e. If there is only one function inside a function it is feasible to return left() from move function.

    However in this case there are multiple functions inside move function scope.

    You should look for something like a nested class and make move as a class rather than a function

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

Sidebar

Related Questions

I am trying to figure out where should I put database operation for each
I am trying to figure out how to get a json output in python
I can't figure out what is wrong with my code here. I am trying
I'm having a hard time trying to figure out why this piece of code
I have been trying to to figure out how to define a nested URL
I'm trying to figure out how to mirror encryption/decryption from an existing C function
I trying to figure out how to output my php to echo for my
I'm trying to access the http://s3.amazonaws.com/commoncrawl/parse-output/segment/ bucket with boto. I can't figure out how
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text

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.