Python Forum

Full Version: Python None Type
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can someone kindly help with this code.

I am trying to achieve a string that looks like: instrument.write("FREQ:CENT 2442 MHz")

Unfortunately when I run this code I find out I am getting None as FRE result. So I end up having something like : FREQ:CENT None MHz

I have tried to solve this problem but can not find any solution.

Below is my Program.

----------------------------------------------
def switch_channel_2_4G_20M(Channel_No):
    switcher = {
        1: "2412",
        2: "2417",
        3: "2422",
        4: "2427",
        5: "2432",
        6: "2437",
        7: "2442",
        8: "2447",
        9: "2452",
        10: "2457",
        11: "2462",
        12: "2467",
        13: "2472"
    }

    #print switcher.get(Channel_No,"Invalid Frequency")


BW = 2
Band = 20
Channel = 1
if BW == 2 and Band == 20:
	FRE = switch_channel_2_4G_20M(Channel)
	 


Frequency = "FREQ:"  + "CENT " + str(FRE) + " MHz"


instrument.write(Frequency)
(Dec-14-2018, 05:45 PM)sigo4u2002 Wrote: [ -> ]def switch_channel_2_4G_20M(Channel_No):
The function doesn't return anything. And when you don't explicitly return anything, it returns None. So you're assigning the result of the function to FRE, but the function never has a result.

It looks like you almost had it working. After defining the dict, add something like return switcher.get(Channel_No, "Invalid Frequency").