env_user = "toto" def function(use_sudo=False): run('mycommand', use_sudo) def function2(use_sudo=False): run('mycommand', use_sudo) if env_user != "root": use_sudo = True function(use_sudo) function2(use_sudo) # INSTEAD OF: def function(): if env_user == "root": run('mycommand') else: sudo('mycommand') def function2(): if env_user == "root": run('mycommand') else: sudo('mycommand') function() function2()