I have some XML tagged string as follows.
<Processor>AMD Athlon(tm) 64 X2 Dual Core Processor 4400+ 2.31 GHz</Processor>
<ClockSpeed>2.31</ClockSpeed>
<NumberOfCores>2</NumberOfCores>
<InstalledMemory>2.00</InstalledMemory>
<OperatingSystem>Windows 7 Professional</OperatingSystem>
How can I detect the data type automatically using python?
For example, “AMD Athlon(tm) 64 X2 Dual Core Processor 4400+ 2.31 GHz” -> string, “2.31” -> float, and on.
I need this functionality as I need to make SQLite Table out of the XML data something like
CREATE table ABC (Processor string, ClockSpeed float ... )
One possibility is to try various types in precise sequence, defaulting to
strif none of those work. E.g.:This is particularly advisable, of course, when you to use want exactly the same syntax conventions as Python — e.g., accept
'0x7e'asintas well as'126', and so on. If you need different syntax conventions, then you should instead perform parsing on strings, whether via REs or by other means.