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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:27:46+00:00 2026-06-04T11:27:46+00:00

I was looking through some of the Django source code and came across this

  • 0

I was looking through some of the Django source code and came across this. What exactly does: encoding = property(lambda self: self.file.encoding) do?

  • 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-04T11:27:50+00:00Added an answer on June 4, 2026 at 11:27 am

    There’s nothing wrong with the other two answers, but they might be a little high-level. So here’s the 101 version:

    lambda

    Although it’s in their documentation for C#, I think Microsoft actually has the best explanation of the concept of lambda:

    A lambda expression is an anonymous function that can contain
    expressions and statements

    Most people without an official CS degree trip over lambda, but when you think of it as simply an “anonymous function”, I think it becomes much easier to understand. The format for lambda in Python is:

    lambda [argument]: [expression]
    

    Where [argument] can be nothing, a single argument or a comma-delimited list of arguments and [expression] is essentially the method body. That’s why @Jordan said the code you mentioned is roughly the equivalent of:

    def encoding(self):
        return self.file.encoding
    

    self is the argument passed into the method and the return value of the method (self.file.encoding) is the expression.

    property

    The property method allows you to create “getters” and “setters”, basically, for an attribute on a class. In traditional OOP, “members”, or the attributes of a class, are usually set as protected or private — you never actually access the attribute directly. Instead, you access methods that in turn retrieve or manipulate the attribute. Chief among those would get the getter and the setter. As their names pretty much describe, they are methods that get and set the value of an attribute, respectively.

    Now, Python OOP doesn’t really have a concept of protected or private attributes in the truest sense. You are free to follow the rules, but there’s nothing stopping you from accessing anything you want on a class. So, getters and setters are most normally, in Python, used in conjunction with property to “fake” an attribute, for lack of a better word. For example:

    def get_foo(self):
        return self.bar
    
    def set_foo(self, value):
        self.bar = value
    
    foo = property(get_foo, set_foo)
    

    With that I can now do things like instance.foo (no parenthesis) and instance.foo = 'something'. And it works just as if foo was a regular attribute on the class.

    In the code you mention, they’re only setting a getter, but it works the same. encoding will act like an attribute on the class and returns the value of file.encoding.

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

Sidebar

Related Questions

I was looking through some code for work, and came across this line: eval(\$element
While looking through some example C code, I came across this: y -= m
While looking through some old code I came across this gem: MyObject o =
Looking through some java code and this just does not seem right. To me,
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
Looking through some old company code, I came across a for loop that looks
I'm looking through some code for learning purposes. I'm working through this portion of
So I'm looking through some code, and I see this: class whatever { public:
I have been looking through some code on an open source project recently and
I was looking through some code and i saw this: <xsl:variable name=newlist select=concat(normalize-space($list), '

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.