Problem with variables and objects. Supestamente local variable behaves as global

0

I'm doing a code and this happens to me:

First I made this class with the intention of using it as if it were a structure of those of C and C ++

class Data:
  titulo = []
  id = []
  fecha=[]

Then I did a function where I gave values to the members

def funcion1():    

 vd = Data()

 #aquí va algo de código pero no es relevante

 vd.id.append(id)
 vd.titulo.append(title)      
 vd.fecha.append(date)

Then I did another function that has nothing to do with the first and that I wanted to use again an object of the type Data () (different object).

def funcion2():

 vdn = Data()

 #aquí va algo de código pero no es relevante

 for k in range( len(vdn.id) ):
  print("%s" % vdn.titulo[k])

The issue is that something is happening that I did not expect and that does not interest me. In function2 (), vdn is taking the values I gave to vd in function1 (). That is, it is behaving like a global variable, even giving it a different name.

Is there any way to prevent this from happening? I'm interested in using only local variables.

    
asked by Iván Rodríguez 18.06.2018 в 17:28
source

0 answers