Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with my code
#1
Hello Guys,
i am working on a school project and could need some help.

command = [getuser(),getpw(),getnewuser(),getnewpw(),getreppw()]
variable = [user,pw,newU,newpw,reppw]
surce = [e1,e2,f1,f2,f3]


for i in range(5) :
    def command[i]:
        global variable[i]
        variable[i] = surce[i].get()
        return variable[i]
As you see i have to create lots of defs and like to shorten this,
because i have to add even more variables and it would be way more efficent if i
could just add it to the list, instead of creating a new def.

def getuser():
    global user
    user = e1.get()
    return user

def getpw():
    global pw
    pw = e2.get()
    return pw

def getnewuser():
    global newU
    newU = f1.get()
    return newU

def getnewpw():
    global newpw
    newpw = f2.get()
    return newpw

def getreppw():
    global reppw
    reppw = f3.get()
    return reppw


Thanks for your help.

Greedings
Godx
Reply
#2
If I write your code in my python interpreter, it won't run. Can you post a whole working script, because I find it difficult to understand what you're trying to do.
Reply
#3
Thats my problem, the upper code dosent run. It should basicly just shorten the lowere code.
Reply
#4
(Aug-21-2018, 05:00 PM)Godx Wrote:
for i in range(5) :
    def command[i]:
        global variable[i]
        variable[i] = surce[i].get()
        return variable[i]

that makes no sense to me.
Reply
#5
I'd like to create 5 defs with this.
In the first round it should get the first value of every string.

command = [getuser(),getpw(),getnewuser(),getnewpw(),getreppw()]
variable = [user,pw,newU,newpw,reppw]
surce = [e1,e2,f1,f2,f3]

so if 1 = 1:

def getuser():
    global user
    user = e1.get()
    return user
Reply
#6
is there a file from which you read the data?
Reply
#7
If I understand your intentions you want call function from string. This is how it's should be done: How do I use strings to call functions/methods?.

Defining function is not the same as calling function.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Forum Jump:

User Panel Messages

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