Tiger12506 keridee at jayco.net
Thu Feb 21 00:02:58 CET 2008

> As I understand it python is not a strongly typed language so no 
> declaration
> of variables is necessary.  My question is this:
> If I use a variable in a program that stores certain numbers and I'm 
> porting
> it to say ... java where I must first declare the variables before I use
> them how do I find out what type to give that variable, specifically is
> there a way to identify the type of a variable used in a python program 
> for
> reference?
> What I'm saying is if I have used a certain variable to hold literally
> dozens of different values and I BELIEVE them all to be integers but I'm 
> not
> entirely sure that I have not stumbled into the float realm is there a way
> to have python list all variables contained in a program and tell me what
> type it has internally stored them as?  I realize I could trudge through 
> the
> entire 1000 lines and check all the variables and see what values I have
> assigned them one at a time but I'm wondering if there is an easier way to
> get that data?
import copy

di = copy.copy(globals())
for y, z in di.iteritems():
  print y, "is of type: ",type(z)

More information about the Tutor mailing list