Generally frowned upon, but you can technically change the assigned value of a global variable from inside a function, if you explicitly declare the variable global
, on more recent versions of Python. Global variables are generally considered a bad thing, so use sparingly and carefully - but you might as well know about it as a feature of the language.
single_item_arrays = []
component_text_ids = []
def getText_identifiers(component_id) :
global single_item_arrays # Notice the explicit declaration as a global variable
if component_id is 'powersupply':
for i in ['Formfactor','PSU',]:
component_text_ids.append(i)
single_item_arrays = formaten,PSU = [],[]
getText_identifiers('powersupply')
print(single_item_arrays)
print(component_text_ids)
See also Use of "global" keyword in Python
Personally I would use the following, replacing global variables with explicit return variables:
def getText_identifiers(component_id) :
single_item_arrays, component_text_ids = [], []
if component_id is 'powersupply':
for i in ['Formfactor','PSU',]:
component_text_ids.append(i)
single_item_arrays = formaten,PSU = [],[]
return single_item_arrays, component_text_ids
single_item_arrays, component_text_ids = getText_identifiers('powersupply')
print(single_item_arrays)
print(component_text_ids)