If One Line

Rick Johnson rantingrickjohnson at gmail.com
Thu Dec 25 11:46:05 EST 2014


On Thursday, December 25, 2014 9:19:25 AM UTC-6, JC wrote:
> Hello,
> 
> Is it possible in python:
> 
> if ((x = a(b,c)) == 'TRUE'):
> 	print x
> 
> Thanks.

Could you not simply rephrase:

    result = foo()
    if result == 'TRUE':
        do_something()

Of course, another oddity is fact that you're "seemingly" using a string to represent what should be a Boolean value. 

You may want to check out the contextlib, which allows you to create custom context managers utilizing the "with" statement.

    path = 'C:\d\e\f\g.txt
    with open(path) as f:
        do_something()



More information about the Python-list mailing list