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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:25:40+00:00 2026-06-10T12:25:40+00:00

I am a newbie to Python, i am having some doubts on working of

  • 0

I am a newbie to Python, i am having some doubts on working of below mentioned code snippet from shutil module.

def ignore_patterns(*patterns):
    """Function that can be used as copytree() ignore parameter.

    Patterns is a sequence of glob-style patterns
    that are used to exclude files"""
    def _ignore_patterns(path, names):
        ignored_names = []
        for pattern in patterns:
            ignored_names.extend(fnmatch.filter(names, pattern))
        return set(ignored_names)
    return _ignore_patterns

When a call to shutil.copytree is made with ignore option set to ignore_patterns, then it calls ignore_patterns function and returns a function. My doubts are:

1) ignore_patterns when called will return the _ignore_pattern function reference. Now when this function will be called, how is it still accessing the “patterns” list? Once called function “ignore_patterns” has returned, list patterns which was created at its call should be available for its called scope only.

2) What is the signicance of underscore in the returned function _ignore_patterns function name?

  • 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-10T12:25:42+00:00Added an answer on June 10, 2026 at 12:25 pm

    This is called a closure, and it’s a general feature of languages that allow nested functions. Inner functions can close over variables in an outer scope, and will retain a reference to that name when they are called from outside the outer function.

    The underscore is just to signify that _ignore_patterns is an inner function, while keeping the name of the returned function similar. It could be called anything you like.

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

Sidebar

Related Questions

I'm a python newbie, and I'm having some difficulty making a module out of
I have the following Python (3.2) code: from pygame import * class Application: def
I'm a programming newbie having difficulty with Python multiplication. I have code like this:
I'm a programming newbie and am having some trouble understanding an example from my
Newbie Python question. I have a class that inherits from several classes, and some
I'm python newbie and got a problem while doing some practices. Below is the
As a newbie to Python, and mainly having a background of writing scripts for
I'm newbie for python, I'm having task so I need to scan wifi and
I'm newbie in Python. I can't understand why this code does not work: reOptions
I'm newbie in Python. I have this simple code a = 0 b =

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.