Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:52:41+00:00 2026-05-15T16:52:41+00:00

I have some XML tagged string as follows. <Processor>AMD Athlon(tm) 64 X2 Dual Core

  • 0

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 ... )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:52:42+00:00Added an answer on May 15, 2026 at 4:52 pm

    One possibility is to try various types in precise sequence, defaulting to str if none of those work. E.g.:

    def what_type(s, possible_types=((int, [0]), (float, ()))):
        for t, xargs in possible_types:
            try: t(s, *xargs)
            except ValueError: pass
            else: return t
        return str
    

    This is particularly advisable, of course, when you to use want exactly the same syntax conventions as Python — e.g., accept '0x7e' as int as well as '126', and so on. If you need different syntax conventions, then you should instead perform parsing on string s, whether via REs or by other means.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some XML in an XmlDocument, and I want to display it on
i have some xml with math ml inside, and i would like to find
So I have some XML in the following format: <somenode> <html xmlns=http://www.w3.org/1999/xhtml> <head> <title/>
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I'm not even sure if it's possible but say I have some XML: <source>
How do I escape '<' and '>' character in sed. I have some xml
I have xml where some of the element values are unicode characters. Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.