Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python None Type
#1
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)
Reply
#2
(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").
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Type hinting - return type based on parameter micseydel 2 2,519 Jan-14-2020, 01:20 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020