id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
python_descriptors_attribute/lookups_121_0.txt | Close | |
python_descriptors_attribute/howtousepythondictio_113_0.txt | Copyright © 2022 IDG Communications, Inc. | |
python_descriptors_attribute/462180_46_0.txt | [ Online Python Compiler - online editor (onlinegdb.com)
](https://www.onlinegdb.com/online_python_compiler) | |
python_descriptors_attribute/howtousepythondictio_106_0.txt | **Next read this:** | |
python_descriptors_attribute/462180_4_0.txt | 
[ Can the get() method for a dictionary be used without assigning the result
to a variable? ](https://discuss.codecademy.com/t/can-the-get-method-for-a-
dictionary-be-used-without-assigning-the-result-to-a... | |
python_descriptors_attribute/howtousepythondictio_71_0.txt | ## Calling function objects in dictionaries | |
python_descriptors_attribute/lookups_82_0.txt | ### Unverified details | |
python_descriptors_attribute/Peter_Lamut_blog_26_2.txt | om_svg "Create
a website or blog at WordPress.com")
* [ Subscribe ]() [ Subscribed ]()
* [  Peter Lamut's blog ](https://blog.peterlamut.com)
Sign me up
* Already have a WordPress.com account? [ Log in now. ](https://wordpre... | |
python_descriptors_attribute/supportingindexandke_73_0.txt | * [ FAQ / Help ](https://pythonmorsels.helpscoutdocs.com)
* [ Privacy Policy ](/privacy/)
* [ Feature History ](/history/)
* [ About Us ](/about/) | |
python_descriptors_attribute/howtousepythondictio_28_0.txt | movie_years = {
"2001: a space odyssey": 1968,
"Blade Runner": 1982
} | |
python_descriptors_attribute/howtousepythondictio_111_0.txt | Follow | |
python_descriptors_attribute/462180_65_0.txt | user_ids = {"teraCoder": 100019, "pythonGuy": 182921, "samTheJavaMaam":
123112, "lyleLoop": 102931, "keysmithKeith": 129384} if 182921 in
user_ids.values(): print("ha") else: print("doh") | |
python_descriptors_attribute/howtousepythondictio_4_0.txt | [ ]() | |
python_descriptors_attribute/Peter_Lamut_blog_0_1.txt | s to swallow any redundant positional arguments, preventing them
from filling the keyword arguments:
def demo(x, y, *args, separator='___'):
print(x, y, args, sep=separator)
>>> demo(10, 20, 30, 40)
10___20___(30, 40)
>>> demo(10, 20, 30, 40, separator='---')
10---2... | |
python_descriptors_attribute/real_python_0_2.txt | to/descriptor.html#descriptor-protocol) to implement **read-only** descriptors.
Now, run the example above and you’ll see the descriptor log the access to the
console before returning the constant value:
Shell
$ python descriptors.py
accessing the attribute to get the value
42
Copied!
H... | |
python_descriptors_attribute/supportingindexandke_12_0.txt | 01:25 | |
python_descriptors_attribute/supportingindexandke_17_0.txt | [ Sign in ](/accounts/login/?next=&action=change_setting) to your Python
Morsels account to save your screencast settings. | |
python_descriptors_attribute/Peter_Lamut_blog_26_0.txt | Skip to content
[ ](https://blog.peterlamut.com/)
[ Peter Lamut's blog ](https://blog.peterlamut.com/)
Mostly writings about Python and programming in general
Menu
* [ Home ](/)
* [ Twitter ](https://twitter.com/plamut "Twitter: @plamut")
* [ GitHub ](https://github.com/plamut "GitHub: plamut")
* [ Stac... | |
python_descriptors_attribute/Peter_Lamut_blog_10_2.txt | le code.
I use Linux, like to crack jokes, and enjoy attending developer meetups and
conferences like EuroPython.
I do not own any pets or hair care products.
Search for: Search
## Tags
* [ Attribute lookup ](https://blog.peterlamut.com/tag/attribute-lookup/)
* [ ChainMap ](https://blog.peterlamut.com/tag/ch... | |
python_descriptors_attribute/lookups_112_0.txt | ### Source Distribution | |
python_descriptors_attribute/supportingindexandke_68_0.txt | New User | |
python_descriptors_attribute/Peter_Lamut_blog_18_0.txt | Skip to content
[ ](https://blog.peterlamut.com/)
[ Peter Lamut's blog ](https://blog.peterlamut.com/)
Mostly writings about Python and programming in general
Menu
* [ Home ](/)
* [ Twitter ](https://twitter.com/plamut "Twitter: @plamut")
* [ GitHub ](https://github.com/plamut "GitHub: plamut")
* [ Stac... | |
python_descriptors_attribute/lookups_11_0.txt | Released: Jul 3, 2021 | |
python_descriptors_attribute/supportingindexandke_60_0.txt | 01:25 | |
python_descriptors_attribute/462180_59_0.txt | user_ids = {"teraCoder": 100019, "pythonGuy": 182921, "samTheJavaMaam": 123112,\
"lyleLoop": 102931, "keysmithKeith": 129384} | |
python_descriptors_attribute/Peter_Lamut_blog_29_3.txt | thon
interpreter. In CPython, its reference implementation, this is a program
written in C that loops through the bytecode given to it, and interprets the
instructions in it one by one.
The heart of this machinery is implemented in [ Python/ceval.c
](https://github.com/python/cpython/blob/v3.7.0b1/Python/ceval.c) file... | |
python_descriptors_attribute/supportingindexandke_19_0.txt | In Python, you can **customize how square brackets (` [] ` ) work ** on your
objects. | |
python_descriptors_attribute/lookups_99_0.txt | 0.3.0 | |
python_descriptors_attribute/howtousepythondictio_89_0.txt | for key, value in movie_years.items(): | |
python_descriptors_attribute/lookups_114_0.txt | Uploaded Jul 3, 2021 ` Source ` | |
python_descriptors_attribute/462180_49_0.txt | [ sebastienbaillargeon
](https://discuss.codecademy.com/u/sebastienbaillargeon) July 27, 2021,
12:10am 10 | |
python_descriptors_attribute/Peter_Lamut_blog_17_1.txt | attribute ` x ` into a descriptor:
>>> Foo.x = DescriptorX()
>>> Foo.__dict__['x']
<__main__.DescriptorX at 0x7fa0b2ff3790>
Accessing a descriptor does not simply return it as it is the case with non-
descriptor attributes, but instead invokes its ` __get__() ` method and return
the result.... | |
python_descriptors_attribute/supportingindexandke_63_0.txt | Next Up __ 01:54 | |
python_descriptors_attribute/supportingindexandke_36_0.txt | >>> colors = ForgivingIndexer(["purple", "blue", "green", "pink"])
>>> colors[1]
'blue' | |
python_descriptors_attribute/supportingindexandke_8_0.txt | Series: [ Dunder Methods __ ](/screencasts/dunder-methods/) | |
python_descriptors_attribute/howtousepythondictio_38_0.txt | example_values = {
"integer": 32,
"float": 5.5,
"string": "hello world",
"variable": some_var,
"object": some_obj,
"function_output": some_func(),
"some_list": [1,2,3],
"another_dict": {
"Blade Runner": 1982
}
} | |
python_descriptors_attribute/lookups_83_0.txt | _These details have **not** been verified by PyPI _ | |
python_descriptors_attribute/462180_34_0.txt | [ omarghoche ](https://discuss.codecademy.com/u/omarghoche) June 4, 2020,
4:10pm 6 | |
python_descriptors_attribute/lookups_143_0.txt | [ 
AWS Cloud computing and Security Sponsor ](https://aws.amazon.... | |
python_descriptors_attribute/supportingindexandke_58_0.txt |  | |
python_descriptors_attribute/supportingindexandke_21_0.txt | Lists in Python support **indexing** using square brackets: | |
python_descriptors_attribute/lookups_101_0.txt | ](/project/lookups/0.3.0/) | |
python_descriptors_attribute/lookups_134_0.txt | * [ Code of conduct ](https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md "External link")
* [ Report security issue ](/security/)
* [ Privacy policy ](https://www.python.org/privacy/ "External link")
* [ Terms of use ](/policy/terms-of-use/)
* [ Acceptable Use Policy ](/policy/acceptable-use-policy/) | |
python_descriptors_attribute/462180_60_0.txt | def value_lookup(value, dictionary):
if value in dictionary.values():
print(f"\"{value}\" is a value within the dictionary.")
else:
print(f"\"{value}\" is not a value within the dictionary.") | |
python_descriptors_attribute/lookups_13_0.txt | ### Navigation | |
python_descriptors_attribute/462180_53_0.txt | There’s probably a shorter way to write it, but solving your challenge was
fun! | |
python_descriptors_attribute/462180_71_0.txt | [ abo-22 ](https://discuss.codecademy.com/u/abo-22) January 29, 2023, 11:49am
14 | |
python_descriptors_attribute/Peter_Lamut_blog_28_3.txt | kOverflow profile")
* [ LinkedIn ](https://si.linkedin.com/in/peterlamut "LinkedIn profile")
[ Peter Lamut's blog ](https://blog.peterlamut.com/) [ Create a website or
blog at WordPress.com ](https://wordpress.com/?ref=footer_custom_svg "Create
a website or blog at WordPress.com")
* [ Comment ](https://blog.pe... | |
python_descriptors_attribute/Peter_Lamut_blog_14_4.txt | /blog.peterlamut.com/2019/02/22/enums-to-
replace-hardcoded-string-constants/#comments)
## [ Python attribute lookup explained in detail
](https://blog.peterlamut.com/2018/11/04/python-attribute-lookup-explained-in-
detail/)
A few months ago I gave a talk at the local [ Python meetup
](https://www.meetup.com/Ljublja... | |
python_descriptors_attribute/howtousepythondictio_19_0.txt |  Maria
Vonotna/Shutterstock | |
python_descriptors_attribute/howtousepythondictio_104_0.txt | movie_titles = {
"2001: a space odyssey",
"Blade Runner",
"Blade Runner 2049"
} | |
python_descriptors_attribute/Peter_Lamut_blog_24_1.txt | tw) {
x = slotw(v, w);
if (x != Py_NotImplemented)
return x;
Py_DECREF(x); /* can't do it */
}
Py_RETURN_NOTIMPLEMENTED;
}
##### Delegating the work to the right function
The ` binary_op1() ` function expects references to two Python object... | |
python_descriptors_attribute/Peter_Lamut_blog_23_1.txt | contained in
it: 1
>>> b = Bank() ... | |
python_descriptors_attribute/462180_73_0.txt | > dict.values() | |
python_descriptors_attribute/lookups_128_0.txt | * [ Installing packages ](https://packaging.python.org/tutorials/installing-packages/ "External link")
* [ Uploading packages ](https://packaging.python.org/tutorials/packaging-projects/ "External link")
* [ User guide ](https://packaging.python.org/ "External link")
* [ Project name retention ](https://www.python.org/... | |
python_descriptors_attribute/real_python_0_4.txt | py
class Vehicle(object):
can_fly = False
number_of_weels = 0
class Car(Vehicle):
number_of_weels = 4
def __init__(self, color):
self.color = color
my_car = Car("red")
print(my_car.color)
print(my_car.number_of_weels)
print(my_car.c... | |
python_descriptors_attribute/462180_33_0.txt | Perfect! Thank you a lot! I understand where the confusion I was making was.

 | |
python_descriptors_attribute/lookups_132_0.txt | * [ Bugs and feedback ](/help/#feedback)
* [ Contribute on GitHub ](https://github.com/pypi/warehouse "External link")
* [ Translate PyPI ](https://hosted.weblate.org/projects/pypa/warehouse/ "External link")
* [ Sponsor PyPI ](/sponsors/)
* [ Development credits ](https://github.com/pypi/warehouse/graphs/contributors ... | |
python_descriptors_attribute/Peter_Lamut_blog_12_2.txt | owing example, but it is instead retrieved
from ` A ` :
>>> A.x = 'x from A'
>>> e_inst.x
'x from A'
The actual lookup order can be seen by inspecting the **method resolution
order** (MRO) of a class:
>>> E.__mro__
(__main__.E, __main__.C, __main__.A, __main__.D, __main__... | |
python_descriptors_attribute/462180_14_0.txt | [ Can the get() method for a dictionary be used without assigning the result
to a variable? ](https://discuss.codecademy.com/t/can-the-get-method-for-a-
dictionary-be-used-without-assigning-the-result-to-a-variable/354256/4) | |
python_descriptors_attribute/howtousepythondictio_65_0.txt | There are a few idiosyncrasies worth noting about how values work in
dictionaries. | |
python_descriptors_attribute/howtousepythondictio_42_0.txt | new_dict = {} | |
python_descriptors_attribute/lookups_27_0.txt | **License:** Mozilla Public License 2.0 (MPL 2.0) (MPLv2) | |
python_descriptors_attribute/supportingindexandke_55_0.txt | ](/static/images/logo-vertical-no-text.fcd6a9b434c2.svg) | |
python_descriptors_attribute/supportingindexandke_4_0.txt | # Supporting index and key lookups | |
python_descriptors_attribute/462180_37_0.txt | 1 Like | |
python_descriptors_attribute/lookups_12_0.txt | DCI lookups in Python (inspired by Netbeans Platform Lookups API) | |
python_descriptors_attribute/lookups_127_0.txt | ## Help | |
python_descriptors_attribute/lookups_53_0.txt | ... | |
python_descriptors_attribute/Peter_Lamut_blog_30_0.txt | Skip to content
[ ](https://blog.peterlamut.com/)
[ Peter Lamut's blog ](https://blog.peterlamut.com/)
Mostly writings about Python and programming in general
Menu
* [ Home ](/)
* [ Twitter ](https://twitter.com/plamut "Twitter: @plamut")
* [ GitHub ](https://github.com/plamut "GitHub: plamut")
* [ Stac... | |
python_descriptors_attribute/Peter_Lamut_blog_22_2.txt | onary ](https://blog.peterlamut.com/tag/dictionary/)
* [ Enum ](https://blog.peterlamut.com/tag/enum/)
* [ Function arguments ](https://blog.peterlamut.com/tag/function-arguments/)
* [ General ](https://blog.peterlamut.com/tag/general/)
* [ Metaclasses ](https://blog.peterlamut.com/tag/metaclasses/)
* [ Pytho... | |
python_descriptors_attribute/462180_2_0.txt | [ Frequently Asked Questions ](/c/faqs/python-faq/1793) [ Python FAQ
](/c/faqs/python-faq/1793) | |
python_descriptors_attribute/Peter_Lamut_blog_1_1.txt | witter ](https://blog.peterlamut.com/2020/04/01/distinguishing-between-none-and-missing-values-in-dictionaries-with-a-sentinel/?share=twitter "Click to share on Twitter")
* [ Facebook ](https://blog.peterlamut.com/2020/04/01/distinguishing-between-none-and-missing-values-in-dictionaries-with-a-sentinel/?share=faceb... | |
python_descriptors_attribute/lookups_142_0.txt | Supported by | |
python_descriptors_attribute/462180_56_0.txt | I found a way but it uses the .values() dictionary method. | |
python_descriptors_attribute/howtousepythondictio_85_0.txt |
we'd get ` 1968 ` and ` 1982 ` . In this case, we're using the keys to obtain
the values. | |
python_descriptors_attribute/lookups_64_0.txt | A list of people who have contributed to Lookups in order of their first
contribution. | |
python_descriptors_attribute/Peter_Lamut_blog_9_3.txt | amut.com/2019/06/24/dropping-into-a-debugger-with-the-built-in-debugger-function/#comments)
* [ Reblog ]()
* [ Subscribe ]() [ Subscribed ]()
* [  Peter Lamut's blog ](https://blog.peterlamut.com)
Sign me up
* Already have... | |
python_descriptors_attribute/howtousepythondictio_70_0.txt | If we want to re-run ` some_func() ` every time we access that key, we need to
take a different approach—one that also has other uses. | |
python_descriptors_attribute/supportingindexandke_2_0.txt | ` / ` | |
python_descriptors_attribute/Peter_Lamut_blog_13_1.txt | g values:
>>> state = fetch_object_state(obj) # assume "Open"
>>> State.NEW == state
False # !!!
In order to work as expected, an enum member’s _value_ must be compared:
>>> State.NEW.value == state
True
This is unfortunate, because the extra ` .value ` part makes... | |
python_descriptors_attribute/howtousepythondictio_7_0.txt |  | |
python_descriptors_attribute/Peter_Lamut_blog_25_0.txt | Skip to content
[ ](https://blog.peterlamut.com/)
[ Peter Lamut's blog ](https://blog.peterlamut.com/)
Mostly writings about Python and programming in general
Menu
* [ Home ](/)
* [ Twitter ](https://twitter.com/plamut "Twitter: @plamut")
* [ GitHub ](https://github.com/plamut "GitHub: plamut")
* [ Stac... | |
python_descriptors_attribute/Peter_Lamut_blog_2_6.txt | 18%252F11%252F04%252Fpython-attribute-lookup-explained-in-detail%252F)
* * [  Peter Lamut's blog ](https://blog.peterlamut.com)
* [ Customize ](https://peterlamut.wordpress.com/wp-admin/customize.php?url=https%3A%2F%2Fpeterlamut... | |
python_descriptors_attribute/lookups_17_0.txt | ###### Maintainers | |
python_descriptors_attribute/lookups_40_0.txt | A lookup is like a dict where you can store object instances as values. And
the search keys are their type classes. | |
python_descriptors_attribute/supportingindexandke_51_0.txt | To track your progress on this Python Morsels topic trail, [ sign in
](/accounts/login/?next=/supporting-index-and-key-lookups/) or [ sign up
](/accounts/signup/?action=mark_read&bid=toggle-read-toggle) . | |
python_descriptors_attribute/supportingindexandke_9_0.txt |  Trey Hunner 2
min. read • 1 min. video • Python 3.8—3.12 • Jan. 31, 2022 | |
python_descriptors_attribute/Peter_Lamut_blog_4_3.txt | ter Lamut's blog ](https://blog.peterlamut.com)
* [ Customize ](https://peterlamut.wordpress.com/wp-admin/customize.php?url=https%3A%2F%2Fpeterlamut.wordpress.com%2F2017%2F09%2F)
* [ Subscribe ]() [ Subscribed ]()
* [ Sign up ](https://wordpress.com/start/)
* [ Log in ](https://wordpress.com/log-in?r... | |
python_descriptors_attribute/real_python_2_0.txt | ## Passing Multiple Arguments to a Function
**` *args ` ** and **` **kwargs ` ** allow you to pass multiple arguments or
keyword arguments to a function. Consider the following example. This is a
simple function that takes two arguments and returns their sum:
Python
def my_sum(a, b):
return a ... | |
python_descriptors_attribute/Peter_Lamut_blog_2_3.txt | probably the ` __getattr__() ` method that
you want to override.
## Summary
Accessing an attribute on a (new-style) class instance invokes the `
__getattribute__() ` method that performs the following:
* Check the class hierarchy using MRO (but do not examine metaclasses):
* If a data (overriding) descripto... | |
python_descriptors_attribute/lookups_65_0.txt | Format: ` Name-or-Well-known-alias <email@domain.tld> (url) ` | |
python_descriptors_attribute/lookups_43_0.txt | * You can also lookup by parent class and not just the most subclasses of an instance.
* You can get hold of a ` lookups.Result ` , which allows you to register a listener for a given class search. You will be notified when an instance of that class is added/removed from the lookup.
* Deferred instanciation with ` look... | |
python_descriptors_attribute/Peter_Lamut_blog_23_2.txt | s/)
* [ Dictionary ](https://blog.peterlamut.com/tag/dictionary/)
* [ Enum ](https://blog.peterlamut.com/tag/enum/)
* [ Function arguments ](https://blog.peterlamut.com/tag/function-arguments/)
* [ General ](https://blog.peterlamut.com/tag/general/)
* [ Metaclasses ](https://blog.peterlamut.com/tag/metaclasse... | |
python_descriptors_attribute/howtousepythondictio_22_0.txt | Show More __ | |
python_descriptors_attribute/lookups_8_0.txt | # lookups 0.3.0 | |
python_descriptors_attribute/Peter_Lamut_blog_31_1.txt | >> Foo.get_name
<bound method Foo.get_name of <class '__main__.Foo'>>
>>> Foo.__dict__['get_name'].__get__(None, Foo)
<bound method Foo.get_name of <class '__main__.Foo'>>
` __get__() ` gets called with two parameters – the object instance the
attribute belongs to ( ` None ` here, because accessing th... | |
python_descriptors_attribute/real_python_0_3.txt | ke a look at this pure Python example from
the [ official docs
](https://docs.python.org/3/howto/descriptor.html#functions-and-methods) :
Python
import types
class Function(object):
...
def __get__(self, obj, objtype=None):
"Simulate func_descr_get() in Objects/funco... | |
python_descriptors_attribute/Peter_Lamut_blog_32_1.txt | > Foo.get_name
<bound method Foo.get_name of <class '__main__.Foo'>>
>>> Foo.__dict__['get_name'].__get__(None, Foo)
<bound method Foo.get_name of <class '__main__.Foo'>>
` __get__() ` gets called with two parameters – the object instance the
attribute belongs to ( ` None ` here, because accessing the... | |
python_descriptors_attribute/462180_18_0.txt | 10 Likes |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.