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

  • SEARCH
  • Home
  • 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 6680627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:29:50+00:00 2026-05-26T04:29:50+00:00

I want to sort some kind of functions by Python and XML, but I’m

  • 0

I want to sort some kind of functions by Python and XML, but I’m really confused about it.

I’ll give you an example,

There are 3 input options that contains in a config.xml file.

<inputs>
    <input1 value='1- Sending Email' />
    <input2 value='2- Extracting a Tar File' />
    <input3 value='3- Rebooting Server' />
</inputs>

—

So, I have already pythoned each function in a folder named “funcs” and I have no problems with them.

All I want is;

1- Listing the inputs and ask for which one to choose.

2- And I need to do it by array. Because I only want to update the XML file in the future, so I’ll never touch the main file that lets python to do every functions.

Any help will make me grateful, thank you.

  • 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-26T04:29:51+00:00Added an answer on May 26, 2026 at 4:29 am

    This involves a bit of mindreading, but I think I know what you’re looking for… I built a file called inputs.xml that contains the xml you referenced above, then I read it and stored the inputs in a python dictionary called inputs

    from xml.etree import ElementTree
    
    inputs = dict()
    tree = ElementTree.parse( 'inputs.xml' )
    for row in tree.getiterator('inputs'):
        for elem in row.getchildren():
            inputs[elem.tag] = elem.get('value')
    

    The results…

    $ python
    Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01) 
    [GCC 4.3.4 20090804 (release) 1] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from xml.etree import ElementTree
    >>> 
    >>> inputs = dict()
    >>> tree = ElementTree.parse( 'inputs.xml' )
    >>> for row in tree.getiterator('inputs'):
    ...     for elem in row.getchildren():
    ...         inputs[elem.tag] = elem.get('value')
    ... 
    >>> print inputs
    {'input2': '2- Extracting a Tar File', 'input3': '3- Rebooting Server', 'input1': '1- Sending Email'}
    >>>
    

    Now suppose you take input from a user and store it as a string in a python variable called input… if you want to access what choice the user selected, use inputs["input"+input]…

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

Sidebar

Related Questions

I really want to put in some sort of section handler into App.config that
I want to know how to add some sort of emblem or badge to
I'm just learning how to do things, and want to start using some sort
i want to sort dictionary based upon value of each dictioanry item.but if i
Is there some sort of Learning C for developers of other languages book or
I'm kind of interested in getting some feedback about this technique I picked up
I'd like some kind of string comparison function that preserves natural sort order 1
I want to sort items where the comparison is performed by humans: Pictures Priority
I want to sort on a certain column only for rows containing a certain
I want to sort a flat, associative array by its values alphabetically and preserve

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.