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.

Marmstrong
  • 1,686
  • 7
  • 30
  • 54

1 Answers1

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
Community
  • 1
  • 1
thefourtheye
  • 233,700
  • 52
  • 457
  • 497