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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:37:45+00:00 2026-05-11T05:37:45+00:00

there is a check I need to perform after each subsequent step in a

  • 0

there is a check I need to perform after each subsequent step in a function, so I wanted to define that step as a function within a function.

>>> def gs(a,b): ...   def ry(): ...     if a==b: ...       return a ... ...   ry() ... ...   a += 1 ...   ry() ... ...   b*=2 ...   ry() ...  >>> gs(1,2) # should return 2 >>> gs(1,1) # should return 1 >>> gs(5,3) # should return 6 >>> gs(2,3) # should return 3 

so how do I get gs to return ‘a’ from within ry? I thought of using super but think that’s only for classes.

Thanks

There’s been a little confusion… I only want to return a if a==b. if a!=b, then I don’t want gs to return anything yet.

edit: I now think decorators might be the best solution.

  • 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. 2026-05-11T05:37:46+00:00Added an answer on May 11, 2026 at 5:37 am

    This should allow you to keep checking the state and return from the outer function if a and b ever end up the same:

    def gs(a,b):     class SameEvent(Exception):         pass     def ry():         if a==b:             raise SameEvent(a)     try:         # Do stuff here, and call ry whenever you want to return if they are the same.         ry()          # It will now return 3.         a = b = 3         ry()      except SameEvent as e:         return e.args[0] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to perform a check is there an entry for each of the
Suppose we need to check three boolean conditions to perform a select query. Let
I basically need to check if there is an easier way to do this
I'm working with a vector and need to check if there exists an element
I need to check in some fast way if there is any text nodes
I need to check a directory to see if there are any files whose
I need to check if I Filesystem exists, and if it does exist there
I need to check the value of my birthdate input field. There should be
So there is record.new_record? To check if something is new I need to check
Is there a simple way to check the type of an object? I need

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.