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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:19:51+00:00 2026-05-26T10:19:51+00:00

Basically, what I’d like to do is: >>> from functools import partial >>> partial(str.startswith,

  • 0

Basically, what I’d like to do is:

>>> from functools import partial
>>> partial(str.startswith, prefix='a')('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: startswith() takes no keyword arguments

But more generally the question is, how to fill specific positional arguments with partial.

P.S. I do realize that I can use a lambda instead.

  • 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-26T10:19:51+00:00Added an answer on May 26, 2026 at 10:19 am

    It cannot be done. You have to make a wrapper function.

    Ostensibly, you would use keyword arguments, as you tried to do – that’s what they’re for, right? Unfortunately, as you’ve discovered, python’s standard library functions do not take named parameters. Thus, it is not possible given the current implementation of partial without making another function to run interference.

    According to the acceptance of PEP 309, what was accepted for inclusion was "a partial() type constructor binding leftmost positional arguments and any keywords." Furthermore, it states:

    Note that when the object is called as though it were a function, positional arguments are appended to those provided to the constructor, and keyword arguments override and augment those provided to the constructor.

    Positional arguments, keyword arguments or both can be supplied at when creating the object and when calling it.

    Because additional positional arguments are appended, there would be no way to supply some preceding positional argument (by this implementation).

    However, it goes on:

    Partially applying arguments from the right, or inserting arguments at arbitrary positions creates its own problems, but pending discovery of a good implementation and non-confusing semantics, I don’t think it should be ruled out.

    So, it apparently could be on the table, but as it stands, it is not implemented that way.

    For the sake of disclosure, emphasis in quotes above was my own.

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

Sidebar

Related Questions

Basically, what I want is like this creating variable names from an array list
Basically I want to be able to call jQuery from FireBug, place code that
Basically, I would like a brief explanation of how I can access a SQL
Basically I am trying to restart a service from a php web page. Here
Basically, I have a matrix class like this (with a lot of operator overloads
Basically, I'd like to know if this code is okay, <body id=some_id <!--[if lt
Basically I need some text like: I have an ice cream cone. You are
Basically I just need the effect of copying that HTML from browser window and
Basically what i'd like to do is injecting what's in HttpContext.Current.User everytime I ask
Basically if I want to transform a name from stephen smith to Stephen Smith

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.