Get value not none - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Get value not none (/thread-24573.html) |
Get value not none - Clives - Feb-20-2020 Greetings, When I run the code I get none, not the drop-down value ie: DEV, TEMP or PROD. I am trying to exclude the none and get the value of source_. Any assistance appreciated. Regards, Clive import urllib import urllib.parse from urllib.parse import urlparse import urllib.request from urllib.request import urlopen def get_method_dropdown(): methods = ['DEV', 'TEMP', 'PROD'] method_widget = widgets.Dropdown( options=methods, value=methods[0], description='Env:' ) display(method_widget) # methods_widget.on_trait_change(filter_istd_qc_by_method,'value') return method_widget d = widgets.Dropdown( options=['DEV', 'TEMP', 'PROD'], value='TEMP' ) display(d) #print(d.value) output2 = widgets.Output() #display(d, output2) def get_value(change): print(change['new']) #print(select_variable.value) #clear_output() source_ = d.observe(get_value, names='value') ### get_value, names='value' #print(source_) if source_ == 'DEV': print("DEV = Output") elif source_ == 'TEMP': print("TEMP = Output") RE: Get value not none - buran - Feb-20-2020 what is widgets and where it comes from?
RE: Get value not none - Clives - Feb-20-2020 Apologies I forgot to add the ipywidgets from ipywidgets import interact, widgets from IPython.display import display import urllib import urllib.parse from urllib.parse import urlparse import urllib.request from urllib.request import urlopen def get_method_dropdown(): methods = ['DEV', 'TEMP', 'PROD'] method_widget = widgets.Dropdown( options=methods, value=methods[0], description='Env:' ) display(method_widget) # methods_widget.on_trait_change(filter_istd_qc_by_method,'value') return method_widget d = widgets.Dropdown( options=['DEV', 'TEMP', 'PROD'], value='TEMP' ) display(d) #print(d.value) output2 = widgets.Output() #display(d, output2) def get_value(change): print(change['new']) #print(select_variable.value) #clear_output() source_ = d.observe(get_value, names='value') ### get_value, names='value' #print(source_) if source_ == 'DEV': print("DEV = Output") elif source_ == 'TEMP': print("TEMP = Output") RE: Get value not none - Clives - Feb-21-2020 When I run the code I get None. I am trying to find an on_click or on_change event to get the "new" value ie if the user chooses Dev, Test or Prod. I would appreciate any assistance. Thanks, Clive RE: Get value not none - Clives - Feb-21-2020 I had tried if and while loops, nothing worked. Eventually I tried if !=, this worked. Thanks for the help if source_ != None: print(source_)This worked!! |