A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-May/064728.html below:

[Python-Dev] unittest argv

[Python-Dev] unittest argv [Python-Dev] unittest argvGuido van Rossum guido at python.org
Mon May 1 20:31:00 CEST 2006
On 5/1/06, John Keyes <john at integralsource.com> wrote:
> > No. Late binding of sys.argv is very important. There are plenty of
> > uses where sys.argv is dynamically modified.
>
> Can you explain this some more?  If it all happens in the same
> function call so how can it be late binding?

You seem to be unaware of the fact that defaults are computed once,
when the 'def' is executed (typically when the module is imported).

Consider module A containing this code:

  import sys
  def foo(argv=sys.argv):
      print argv

and module B doing

  import sys
  import A
  sys.argv = ["a", "b", "c"]
  A.foo()

This will print the initial value for sys.argv, not ["a", "b", "c"].
With the late binding version it will print ["a", "b", "c"]:

  def foo(argv=None):
    if argv is None:
      argv = sys.argv
    print argv

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4