Skip to main content
Post Closed as "Duplicate" by tripleee python
added 24 characters in body
Source Link
user497457
  • 327
  • 2
  • 3
  • 9

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

def creatingShotInstance():

    import movieClass

    BrokenCristals = movieClass.shot()
    global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
    BrokenCristals.set_name('BrokenCristals')
    BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
    BrokenCristals.set_length(500)
    Fight._shots.append(BrokenCristals)

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals'

but if instead of doing that I declare a string variable like this:

def creatingShotInstance():

    import movieClass

    a = 'BrokenCristals'
    
    vars()[a] = movieClass.shot()
    global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
    eval(a+".set_name('"+a+"')")
    eval(a+".set_description('Main'Both charactercharacters winsgoes thethrough fight!'a big glass\nand break it')")
    eval(a+".set_length(325500)")
    Fight._shots.append(vars()[a])

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals is not defined'

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

def creatingShotInstance():

    import movieClass

    BrokenCristals = movieClass.shot()
    global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
    BrokenCristals.set_name('BrokenCristals')
    BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
    BrokenCristals.set_length(500)
    Fight._shots.append(BrokenCristals)

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals'

but if instead of doing that I declare a string variable like this:

def creatingShotInstance():

    import movieClass

    a = 'BrokenCristals'
    
    vars()[a] = movieClass.shot()
    global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
    eval(a+".set_name('"+a+"')")
    eval(a+".set_description('Main character wins the fight!')")
    eval(a+".set_length(325)")
    Fight._shots.append(vars()[a])

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals is not defined'

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

def creatingShotInstance():

    import movieClass

    BrokenCristals = movieClass.shot()
    global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
    BrokenCristals.set_name('BrokenCristals')
    BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
    BrokenCristals.set_length(500)
    Fight._shots.append(BrokenCristals)

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals'

but if instead of doing that I declare a string variable like this:

def creatingShotInstance():

    import movieClass

    a = 'BrokenCristals'
    
    vars()[a] = movieClass.shot()
    global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
    eval(a+".set_name('"+a+"')")
    eval(a+".set_description('Both characters goes through a big glass\nand break it')")
    eval(a+".set_length(500)")
    Fight._shots.append(vars()[a])

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals is not defined'

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

added 427 characters in body; added 2 characters in body
Source Link
user497457
  • 327
  • 2
  • 3
  • 9

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

def creatingShotInstance():

    import movieClass

    BrokenCristals = movieClass.shot()
    global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
    BrokenCristals.set_name('BrokenCristals')
    BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
    BrokenCristals.set_length(500)
    Fight._shots.append(BrokenCristals) 

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals'

but if instead of doing that I declare a string variable like this:

def creatingShotInstance():

    import movieClass

    a = 'BrokenCristals'
    
    vars()[a] = movieClass.shot()
    global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
    eval(a+".set_name('"+a+"')")
    eval(a+".set_description('Main character wins the fight!')")
    eval(a+".set_length(325)")
    Fight._shots.append(vars()[a])

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals is not defined'

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

import movieClass

BrokenCristals = movieClass.shot()
global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
BrokenCristals.set_name('BrokenCristals')
BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
BrokenCristals.set_length(500)
Fight._shots.append(BrokenCristals)

but if instead of doing that I declare a string variable like this:

import movieClass

a = 'BrokenCristals'
    
vars()[a] = movieClass.shot()
global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
eval(a+".set_name('"+a+"')")
eval(a+".set_description('Main character wins the fight!')")
eval(a+".set_length(325)")
Fight._shots.append(vars()[a])

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

def creatingShotInstance():

    import movieClass

    BrokenCristals = movieClass.shot()
    global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
    BrokenCristals.set_name('BrokenCristals')
    BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
    BrokenCristals.set_length(500)
    Fight._shots.append(BrokenCristals) 

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals'

but if instead of doing that I declare a string variable like this:

def creatingShotInstance():

    import movieClass

    a = 'BrokenCristals'
    
    vars()[a] = movieClass.shot()
    global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
    eval(a+".set_name('"+a+"')")
    eval(a+".set_description('Main character wins the fight!')")
    eval(a+".set_length(325)")
    Fight._shots.append(vars()[a])

def accesingShotInstance():
    import movieClass

    return BrokenCristals.get_name()#it returns me 'BrokenCristals is not defined'

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

Brevity
Source Link
unwind
  • 401.7k
  • 64
  • 491
  • 619

I'm a python/programming newbie and maybe my question has notno sense at all , but...

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

import movieClass

BrokenCristals = movieClass.shot()
global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
BrokenCristals.set_name('BrokenCristals')
BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
BrokenCristals.set_length(500)
Fight._shots.append(BrokenCristals)

but if instead of doing that I declare a string variable like this:

import movieClass

a = 'BrokenCristals'
    
vars()[a] = movieClass.shot()
global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
eval(a+".set_name('"+a+"')")
eval(a+".set_description('Main character wins the fight!')")
eval(a+".set_length(325)")
Fight._shots.append(vars()[a])

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error...what What should I do??

I hope the question is clear enough

Thanks in advance

David

I'm a python/programming newbie and maybe my question has not sense at all , but...

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

import movieClass

BrokenCristals = movieClass.shot()
global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
BrokenCristals.set_name('BrokenCristals')
BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
BrokenCristals.set_length(500)
Fight._shots.append(BrokenCristals)

but if instead of doing that I declare a string variable like this:

import movieClass

a = 'BrokenCristals'
    
vars()[a] = movieClass.shot()
global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
eval(a+".set_name('"+a+"')")
eval(a+".set_description('Main character wins the fight!')")
eval(a+".set_length(325)")
Fight._shots.append(vars()[a])

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error...what should I do??

I hope the question is clear enough

Thanks in advance

David

I'm a python/programming newbie and maybe my question has no sense at all.

My problem is that I can't get a variable to be global if it is dynamic, I mean I can do this:

import movieClass

BrokenCristals = movieClass.shot()
global BrokenCristals #here I declare BrokenCristals like a global variable and it works, I have access to this variable (that is a  shot class instance) from any part of my script.
BrokenCristals.set_name('BrokenCristals')
BrokenCristals.set_description('Both characters goes through a big glass\nand break it')
BrokenCristals.set_length(500)
Fight._shots.append(BrokenCristals)

but if instead of doing that I declare a string variable like this:

import movieClass

a = 'BrokenCristals'
    
vars()[a] = movieClass.shot()
global a #this line is the only line that is not working now, I do not have acces to BrokenCristals class instance from other method, but I do have in the same method.
eval(a+".set_name('"+a+"')")
eval(a+".set_description('Main character wins the fight!')")
eval(a+".set_length(325)")
Fight._shots.append(vars()[a])

I tried this :

global vars()[a]

and this:

global eval(a)

but It gives me an error. What should I do?

Source Link
user497457
  • 327
  • 2
  • 3
  • 9
Loading