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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:35:06+00:00 2026-06-15T20:35:06+00:00

Are Python’s built-in functions not available for use as keyword defaults, or should I

  • 0

Are Python’s built-in functions not available for use as keyword defaults, or should I be using some other way of referring to a function?

I wanted to write a function like this:

def isPNGBlock(bytes, blockLen, pngOffset=0, pngErrorLogger=print):
    ...
    try:
        r.validate_signature()
        width, height, pixels, metadata = r.read(lenient=True)
    except png.Error as e:
        pngErrorLogger(e)

Instead I’ve had to settle for doing this with a default argument of None as a flag value.

def isPNGBlock(bytes, blockLen, pngOffset=0, pngErrorLogger=None):
    ...
    try:
        r.validate_signature()
        width, height, pixels, metadata = r.read(lenient=True)
    except png.Error as e:
        if pngErrorLogger is None:
            print(e)
        else:
            pngErrorLogger(e)

or using a wrapper function:

def defaultLogger(str):
    print(str)

def isPNGBlock(bytes, blockLen, pngOffset=0, pngErrorLogger=defaultLogger ):
    ...
    try:
        r.validate_signature()
        width, height, pixels, metadata = r.read(lenient=True)
    except png.Error as e:
        pngErrorLogger(e)
  • 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-15T20:35:07+00:00Added an answer on June 15, 2026 at 8:35 pm

    Are Python’s built-in functions not available for use as keyword defaults

    They are available to use just like any other function.

    However, in Python 2 print is a statement, not a function. It became a function in Python 3, so your code will work there. It will also work in recent versions of Python 2 if you use from __future__ import print_function. For example, using Python 2.7.3:

    In [2]: from __future__ import print_function
    
    In [3]: def isPNGBlock(bytes, blockLen, pngOffset=0, pngErrorLogger=print):
       ...:     pngErrorLogger('test')
       ...:     
    
    In [4]: isPNGBlock(0, 0)
    test
    

    If you can’t use print as a function, you could either write a wrapper, or use sys.stdout.write:

    In [7]: isPNGBlock(0, 0, 0, sys.stdout.write)
    test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python's len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat '\t'
Python does not provide built-in support for multi-dimensional arrays. I need to develop an
Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s
Python does not print traceback messages from exceptions raised in daemon threads. For example,
Python is so dynamic that it's not always clear what's going on in a
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()
Python newb...beware! I am trying to recursively ftp some files. In the script below,
Python allows to call a static method not only from a class, but also
Python's arbitrary precision decimals are lovely, but I can't seem to find a way
Python decorators are fun to use, but I appear to have hit a wall

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.