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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:43:25+00:00 2026-06-05T23:43:25+00:00

From my ipython shell, I see a method setdefault in os.environ but it is

  • 0

From my ipython shell, I see a method setdefault in os.environ but it is not documented. http://docs.python.org/library/os.html#os.environ. Is it documented somewhere else?

def setdefault(self, key, failobj=None):
    if key not in self:
        self[key] = failobj
    return self[key]

Can I use this function or write a wrapper for those lines?

  • 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-05T23:43:28+00:00Added an answer on June 5, 2026 at 11:43 pm

    The os.environ documentation does state it’s a mapping:

    A mapping object representing the string environment.

    As such it behaves according to the python mapping documentation of which dict is the standard implementation.

    os.environ therefor behaves just like the standard dict, it has all the same methods:

    >>> import os
    >>> len(os.environ)
    36
    >>> 'USER' in os.environ
    True
    >>> os.environ.fromkeys
    <bound method classobj.fromkeys of <class os._Environ at 0x107096ce8>>
    

    The .setdefault method is documented on the same page as the rest of the mapping methods, and you can use it just fine as is.

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

Sidebar

Related Questions

Is it possible to use the IPython shell from an existing Python shell, as
From the Microsoft website (see msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx ) it clearly says Services cannot directly interact
I cannot access the context attribute of an HttpResponse object from ipython. But the
When I open a python or ipython from command-line, I don't have commands history
When I am in an interactive python session (usually IPython), the following commands: from
Using IPython .10-2, I can do the following from a python command line program:
I'm working from inside an ipython shell and often need to reload the script
From what I've found in C#, the Control.Invoke method requires that you use a
I want to utilize introspection capability of python for debugging/development, but cannot find appropriate
I'm afraid I don't understand something basic. I use python interactively with IPython and

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.