How to determine a variable's datatype?
Peter Bittner
bittneph at aston.ac.uk
Wed Mar 15 14:26:26 EST 2000
Hi there!
Is it possible in Python to determine the datatype of an object?
E.g. (kind of like this)
var1 = 3
var2 = 'Hello'
var1.datatype ==> yields "int"
var2.datatype ==> yields "string" or list of characters
This would be crucial for this function that I want to write in a module
called 'sql':
def insert(table_name, dict_of_tags_and_values):
" returns a SQL-string that inserts a new dataset in a table"
prefix = 'INSERT INTO ' + str(table_name)
entities = ''
values = ''
for dictpair in dict_of_tags_and_values
# - split this pair
# - if value != '' (-> strings!!!) or...
# ... value != 0 (-> numbers/integers!!!):
# add strings to entities and values with or without 's
#
return prefix + ' (' + entities + ') VALUES (' + values + ')'
For a number the value added must be plain, for a string the 'value'
must be enclosed in '-characters.
Hence this is crucial to this application!
Does someone know if it's possible to determine it?
Please mail me any suggestion!! (-> mailto: bittneph at aston.ac.uk)
Peter
| Peter H. Bittner
| International Student at Aston University
| e-mail: bittneph at aston.ac.uk
| web: http://beam.to/bimbo
+--------------------------
More information about the Python-list
mailing list