0

How would I compare an element of a tuple return from a function in an if statement? For example, I would like to do something like the following...

if platform.machine() == "AMD64" :

This function only has one string varaible return. I would like to do the same except with platform.architecture() which has a return that looks like ('32bit', 'WindowsPE'). What I currently do is ...

architecture = platform.architecture()
if architecture[0] == "64bit":

I was wondering if there was something more pythonic that could be achieved in one line.

2
  • 4
    There is nothing wrong with just if platform.machine()[0] == '64bit':. Commented Jan 10, 2014 at 11:34
  • @RemcoGerlich: please post this as answer as it's the pythonic one. Commented Jan 10, 2014 at 11:47

1 Answer 1

2

Since, platform.architecture is unreliable, the best way to get the processor architecture would be

if platform.machine()[:-2] == "64":
    # 64 bit machine
else:
    # 32 bit machine

If you are really looking for the best way to use the value which you retrieved from a function, you can simply ignore other values and get only the values which you need using the index

def temp():
    return 1, "Welcome"
if temp()[1] == "Welcome":
    print 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.