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 7917979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:20:53+00:00 2026-06-03T15:20:53+00:00

I use an array for storage of functions which needs to be called in

  • 0

I use an array for storage of functions which needs to be called in a row:

def do_xslt(xsl, xml):
    newxml = dosomethingwithit(xsl,xml)
    return newxml

TRANSFORM_PIPELINE = [
    do_xslt('pass1.xsl'),
    do_xslt('pass2.xsl'),
    do_xslt('pass3.xsl'),
]

what I now want to do is to call the TRANSFORM_PIPELINE with its given argument and a dynamic one.

I have something like this in my mind which should call in a loop do_xslt('passX.xsl', xml)

for transform in TRANSFORM_PIPELINE:
    xml = transform(xml) 

This approach is of course wrong. But how to make the right way in Python?

  • 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-06-03T15:20:56+00:00Added an answer on June 3, 2026 at 3:20 pm

    Use functools.partial() to partially apply the function:

    from functools import partial
    TRANSFORM_PIPELINE = [
        partial(do_xslt, 'pass1.xsl'),
        partial(do_xslt, 'pass2.xsl'),
        partial(do_xslt, 'pass3.xsl')
    ]
    

    Calling the functions returned by partial() will call do_xslt('pass1.xsl', *args, **kwargs) with *args and **kwargs being the arguments passed to the new function.

    Demo:

    >>> def do_xslt(xsl, xml):
    ...     print 'do_xslt(%r, %r)' % (xsl, xml)
    ...     return xml + '*' + xsl
    ...
    >>> from functools import partial
    >>> TRANSFORM_PIPELINE = [
    ...     partial(do_xslt, 'pass1.xsl'),
    ...     partial(do_xslt, 'pass2.xsl'),
    ...     partial(do_xslt, 'pass3.xsl')
    ... ]
    >>> x = 'xml is lame'
    >>> for transform in TRANSFORM_PIPELINE:
    ...     x = transform(x)
    ...     print x
    ...
    do_xslt('pass1.xsl', 'xml is lame')
    xml is lame*pass1.xsl
    do_xslt('pass2.xsl', 'xml is lame*pass1.xsl')
    xml is lame*pass1.xsl*pass2.xsl
    do_xslt('pass3.xsl', 'xml is lame*pass1.xsl*pass2.xsl')
    xml is lame*pass1.xsl*pass2.xsl*pass3.xsl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it okay to use array without single or double quotion like $array[key]? I
I'm making a top-bottom queue. Do I use array or arraylist?
I use an array to store fieldvalues. To easily add and access elements I
If I use an array of linked list to implement a hash table, the
I want to take an array and use that array's values to populate an
I'm trying to use an array to set the where parameters for a Zend
I try use a integer array in java with the code below: public static
I'm trying to use empty() in array mapping in php. I'm getting errors that
Many people and authors suggested to us to use list than array. List <Integer>
ı have a query_string and ı want to use it in array. ı have

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.