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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:20:15+00:00 2026-05-13T00:20:15+00:00

I guess this is kinda abusing the feature, but I’m still curious whether it

  • 0

I guess this is kinda abusing the feature, but I’m still curious whether it could be done –
I want to do something like:

with conditional(a):
    print 1

so that the print 1 part is executed only if a==True.
Is this possible?

EDIT:
Like people state below, this is horrible style. It’s just a riddle\question. Don’t try this at home, not for the faint of heart 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-05-13T00:20:15+00:00Added an answer on May 13, 2026 at 12:20 am

    There’s no real reason to do that, since conditionals are already supplied using the if statement:

    if a == True:
        print 1
    

    But, if you’re just asking for fun, the answer is you can’t really. To stop the with content from executing, conditional will need to somehow stop execution, in its __enter__ method. But the only way it can do that is raising an exception, which means no other code will run, unless you wrap the with with a try statement for handling cases a != True

    Edit: seeing I was prosecuted in the comments and votes for using the OP’s condition (a == True) I considered changing it to if a, which is of course the idiom in Python for testing conditionals. But, we do not know what the OP had in mind, and whether he really does want a to be a boolean, and doesn’t want block to execute if a = [1] (which will pass if a) I decided to leave it as is.

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

Sidebar

Related Questions

Okay, I guess this is entirely subjective and whatnot, but I was thinking about
I am busy writing my thesis (so, I guess this could count as a
I'm learning about POSIX threads right now, but I guess this is just a
I guess the topic says it. I have tried googling this, but havent gotten
i know this is kinda retarded but I just can't figure it out. I'm
I guess this is an odd one, and the answer is most likely it
I have a HashMap (although I guess this question applies to other collections) of
Well, I guess this day had to come. My client's website has been compromised
Ok another WPF question, well I guess this is just general .NET. I have
I guess I'll illustrate with an example: In this game you are able to

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.