How to determine a variable's datatype?
Alessandro Bottoni
Alessandro.Bottoni at think3.com
Thu Mar 16 08:11:28 EST 2000
Peter,
I just asked the some question (and for the same reason: SQL).
See the "Types" module in the standard distribution documentation.
I hope this help.
--------------------------------
Alessandro Bottoni
(Alessandro.Bottoni at Think3.com)
(alessandro.bottoni at libero.it)
Web Programmer
Think3 inc.
(www.think3.com)
> -----Original Message-----
> From: Peter Bittner [SMTP:bittneph at aston.ac.uk]
> Sent: Wednesday, March 15, 2000 8:26 PM
> To: python-list at python.org
> Subject: How to determine a variable's datatype?
> Importance: High
>
> 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
> +--------------------------
> --
> http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list