Ich versuche, Funktion mit Wert aus einer anderen Datei als Variable auszuführen.Funktion mit Variable aus importierter Datei ausführen
eine Datei (sie text.py nehmen) mit:
VAR="abc"
In Hauptdatei:
variable1 -> that variable contain value "VAR"
import text
Funktion ausführen:
example_function(connect=text.variable1)
Warum kann ich es nicht auf diese Weise tun ?
EDIT:
echten Code:
variable = "VAR_23_23"
import text
from functionfile import number_function
from functionfile import find_number
number_to_substr=find_number(variable,"_",1)
source_var=variable[:number_to_substr]
number_function(connect=text.source_var)
bearbeiten 2.
text.py enthalten:
VAR="abc"
main.my enthalten:
import text
variable = "VAR_23_23"
from functionfile import number_function
from functionfile import find_number
number_to_substr=find_number(variable,"_",1) -> the result is "4"
source_var=variable[:number_to_substr] -> the result is "VAR"
number_function(connect=text.source_var) -> now trying to execute function with that variable name but as result I expect value from TEXT.py file.
Denn jetzt statt ‚abc‘ Wert I ‚VAR‘ bekam value.`
Das ist nicht wirklich klar. Funktioniert 'text.VAR' nicht, um den Wert von' VAR' aus 'text.py' zu erhalten (nach dem Import)? – Aurora0001
Bitte posten Sie echte Code-Schnipsel, die den Code zeigen. –
'variable1' ist innerhalb des aktuellen Moduls von' main' definiert, so dass 'text.variable1' insgesamt nicht korrekt ist –