Advertisement
1400_SpaceCat

write variables name and parameters

Aug 8th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def writeVars(*args)
  2.     File = open("heroSave.py","w")
  3.  
  4.         var_name = lambda x:[ n for n in globals() if id(globals()[n]) == id(x) ][0]
  5.  
  6.         for stats in args:
  7.                
  8.                 if ( type(stats) == int or type(stats) == float ):
  9.  
  10.                         File.write(var_name(stats)+" = ")
  11.                         File.write(str(stats)+"\n")
  12.  
  13.                 elif ( type(stats) == str ):
  14.                         File.write(var_name(stats)+" = ")
  15.                         File.write("\""+stats+"\""+"\n")
  16.  
  17.         File.close()
  18.  
  19. x,y,z = 1,2,3
  20. writeVars(x,y,z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement