0

I'm working on fixing some code in a git project, and have an issue. The program uses key-value pairs, where the value is numeric (as a String). I know how to code it in Visual Basic (or think I do), but I'm not sure how to do it in Python. If I have to convert it and compare that, I can, but I'm trying to minimize the code required.

The VB equivalent of what I want to do is either:

select case (CDec(data['Frequency']) >= 144.000 AND CDec(data['Frequency'] <= 174.000)

or

if (CDec(data['Frequency']) >= 144.000 or CDec(data['Frequency'] <= 174.000) then

How would I do this in Python? As I said, I can convert the value to a decimal and compare it, but I'd like to avoid that if possible.

Thanks, and have a great night. :) Patrick.

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235

2 Answers2

0

144.0 <= int(data['Frequency']) <= 174.0

I guess ... its called chained comparison

and int to cast something to int ... (I assume thats what CDec does)

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
0

CDec() would be the conversion to compare to 144.0 and in Python it is float().

You certainly could use:

if 144.0 <= float(data['Frequency']) <= 178.0 : ...

Stuart Deal
  • 75
  • 1
  • 4