{"id":8122,"date":"2021-02-09T10:03:42","date_gmt":"2021-02-09T04:33:42","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=8122"},"modified":"2024-01-01T10:34:31","modified_gmt":"2024-01-01T05:04:31","slug":"python-shelve","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-shelve\/","title":{"rendered":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data"},"content":{"rendered":"\n<p>Hello coders!! In this article, we will be learning about Python Shelve and the various functions that we can perform in it.<strong> In Python, a shelve is a dictionary-like object. It is different from &#8220;<a href=\"https:\/\/docs.python.org\/3\/library\/dbm.html\" target=\"_blank\" rel=\"noreferrer noopener\">dbm<\/a>&#8221; databases as the value of shelve can be arbitrary Python objects. <\/strong>So, let us get straight into our topic now.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Different_functions_available_in_Python_Shelve\" >Different functions available in Python Shelve:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_1_Create_a_database_and_store_values_in_Python_shelve\" >Example 1: Create a database and store values in Python shelve:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_2_Access_the_value_corresponding_to_the_given_key\" >Example 2: Access the value corresponding to the given key:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_3_List_the_items\" >Example 3: List the items:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_4_List_the_keys\" >Example 4: List the keys:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_5_List_the_values\" >Example 5: List the values:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_6_Delete_an_item_in_Python_Shelve\" >Example 6: Delete an item in Python Shelve:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Example_7_Update_Python_Shelve\" >Example 7: Update Python Shelve:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Python_shelve_vs_pickle\" >Python shelve vs pickle:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Must_Read\" >Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Conclusion\" >Conclusion:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#Trending_Python_Articles\" >Trending Python Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-different-functions-available-in-python-shelve\"><span class=\"ez-toc-section\" id=\"Different_functions_available_in_Python_Shelve\"><\/span>Different functions available in Python Shelve:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-table alignwide\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Method<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>open()<\/strong><\/td><td>open persistent dictionary object<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>close()<\/strong><\/td><td>synchronize and close persistent dictionary objects.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>sync()<\/strong><\/td><td>Write back all entries in the cache since the shelf was opened with the writeback set to True.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>get()<\/strong><\/td><td>returns value associated with a key<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>items()<\/strong><\/td><td>tuples list<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>keys()<\/strong><\/td><td>list of shelf keys<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>pop()<\/strong><\/td><td>remove the specified key and return the corresponding value.<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>update()<\/strong><\/td><td>update shelf from another dictionary\/iterable<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>values()<\/strong><\/td><td>list of shelf values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Let us see certain examples to understand these functions in a better way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-1-create-a-database-and-store-values-in-python-shelve\"><span class=\"ez-toc-section\" id=\"Example_1_Create_a_database_and_store_values_in_Python_shelve\"><\/span>Example 1: Create a database and store values in Python shelve:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport shelve\nsh = shelve.open(&quot;student&quot;)\nsh&#x5B;'name'] = &quot;Prachee&quot;\nsh&#x5B;'age'] = 21\nsh&#x5B;'marks'] = 95\nsh.close()\n<\/pre><\/div>\n\n\n<p><strong>The above code will create a database sample.dir in the current working directory and store the key-value data in the form of the hashtable.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-2-access-the-value-corresponding-to-the-given-key\"><span class=\"ez-toc-section\" id=\"Example_2_Access_the_value_corresponding_to_the_given_key\"><\/span>Example 2: Access the value corresponding to the given key:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsh=shelve.open('student')\nsh&#x5B;'age']\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">21<\/pre>\n\n\n\n<p>This can also be written as:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsh.get('age')\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">21<\/pre>\n\n\n\n<p><strong>The get() method returns the value which is associated with the particular key.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-3-list-the-items\"><span class=\"ez-toc-section\" id=\"Example_3_List_the_items\"><\/span>Example 3: List the items:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist(sh.items())\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">[ ( ' name ' , ' Prachee ') , ( ' age ' , 21 ) , ( ' marks ' , 95 ) ]<\/pre>\n\n\n\n<p><strong>The items() method returns the key with the corresponding values as a list of tuples.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-4-list-the-keys\"><span class=\"ez-toc-section\" id=\"Example_4_List_the_keys\"><\/span>Example 4: List the keys:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist(sh.keys())\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">[ ' name ' , ' age ' , ' marks ' ]<\/pre>\n\n\n\n<p><strong>The keys() method returns the keys in the form of a list.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-5-list-the-values\"><span class=\"ez-toc-section\" id=\"Example_5_List_the_values\"><\/span>Example 5: List the values:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist(sh.values())\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">[ ' Prachee ', 21 , 95 ]<\/pre>\n\n\n\n<p><strong>The values() method returns shelf values in the form of a list.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-6-delete-an-item-in-python-shelve\"><span class=\"ez-toc-section\" id=\"Example_6_Delete_an_item_in_Python_Shelve\"><\/span>Example 6: Delete an item in Python Shelve:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsh.pop('marks')\nlist(sh.items())\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">95\n[ ( ' name ' , ' Prachee ' ) , ( ' age ', 21 ) ]<\/pre>\n\n\n\n<p><strong>The pop() function removes the item having the given key from the shelf and returns its corresponding value.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-7-update-python-shelve\"><span class=\"ez-toc-section\" id=\"Example_7_Update_Python_Shelve\"><\/span>Example 7: Update Python Shelve:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nup = {'roll':66 , 'dept':'IT'}\nsh.update(up)\nlist(sh.items())\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">[ ( ' name ' , ' Prachee ' ) , ( ' age ' , 21 ) , ( ' roll ', 66 ) ]<\/pre>\n\n\n\n<p><strong>Using the update() method we can update the shelve with some dictionary or iterable<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-shelve-vs-pickle\"><span class=\"ez-toc-section\" id=\"Python_shelve_vs_pickle\"><\/span>Python shelve vs pickle:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong><span style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">SHELVE<\/span><\/strong><\/th><th><strong><span style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">PICKLE<\/span><\/strong><\/th><\/tr><\/thead><tbody><tr><td>It is built on top of&nbsp;<code>pickle<\/code>. It is used to implement a serialization dictionary where the objects are pickled but associated with a key.&nbsp;<\/td><td>It is used to serialize some object as a single-byte stream in a file.<\/td><\/tr><tr><td><code>import shelve<\/code><br>vals = [1, 2, 3, 4, 5]<br><code>with shelve.open('shelfE', 'c') as shelf:<\/code><br>    <code>shelf['ints'] = vals<\/code><br><code>with shelve.open('shelfE', 'r') as shelf:<\/code><br><code>  for key in shelf.keys(): <\/code><br>         <code>print(repr(key), repr(shelf[key]))<\/code><\/td><td><code>import pickle<br>vals = [1, 2, 3, 4, 5]<br>with open('pickleE.p', 'wb') as pfile: pickle.dump(vals, pfile)<br>with open('pickleE.p', 'rb') as pfile: integers = pickle.load(pfile) <\/code><br>    <code>print(integers)<\/code><\/td><\/tr><tr><td><strong>OUTPUT:<\/strong><br>&#8216;ints&#8217;, [1, 2, 3, 4, 5]<\/td><td><strong>OUTPUT:<\/strong><br>[1, 2, 3, 4, 5]<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/www.pythonpool.com\/50-python-interview-questions\/\" rel=\"noreferrer noopener\" target=\"_blank\">50+ Frequently Asked Python Questions For Interview<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/python-ord\/\" rel=\"noreferrer noopener\" target=\"_blank\">What is Python ord Function<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/working-with-crud-in-python\/\" rel=\"noreferrer noopener\" target=\"_blank\">Working with CRUD in Python<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/python-check-if-variable-exists\/\" rel=\"noreferrer noopener\" target=\"_blank\">\u3010How to\u3011 Check if the Variable Exists in Python<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/cpickle\/\" rel=\"noreferrer noopener\" target=\"_blank\">cPickle in Python Explained With Examples<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With this, we come to an end with this article. I hope that the concept of Python shelves and the various functions that are available for shelf operations were cleared from this article.<\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-delta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-2\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Python_Articles\"><\/span>Trending Python Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 11, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined.webp 1200w \" alt=\"[Fixed] nameerror: name Unicode is not defined\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method.webp 1200w \" alt=\"[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>Hello coders!! In this article, we will be learning about Python Shelve and the various functions that we can perform in it. In Python, a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Python Shelve: Storing, Retrieving, Updating, and Deleting Data\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/#more-8122\" aria-label=\"More on Python Shelve: Storing, Retrieving, Updating, and Deleting Data\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":8760,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[3504,3505,3503,3502,3501],"class_list":["post-8122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-python-shelve-example","tag-python-shelve-module","tag-python-shelve-query","tag-python-shelve-tutorial","tag-shelve-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Shelve: Storing, Retrieving, Updating, and Deleting Data<\/title>\n<meta name=\"description\" content=\"Python shelve is a dictionary-like object. It is different from &quot;dbm&quot; databases as the value of shelve can be arbitrary Python objects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-shelve\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Shelve: Storing, Retrieving, Updating, and Deleting Data\" \/>\n<meta property=\"og:description\" content=\"Hello coders!! In this article, we will be learning about Python Shelve and the various functions that we can perform in it. In Python, a shelve is a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-shelve\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-09T04:33:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-01T05:04:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prachee Sao\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prachee Sao\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/\"},\"author\":{\"name\":\"Prachee Sao\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\"},\"headline\":\"Python Shelve: Storing, Retrieving, Updating, and Deleting Data\",\"datePublished\":\"2021-02-09T04:33:42+00:00\",\"dateModified\":\"2024-01-01T05:04:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/\"},\"wordCount\":426,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png\",\"keywords\":[\"python shelve example\",\"python shelve module\",\"python shelve query\",\"python shelve tutorial\",\"shelve python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-shelve\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-shelve\/\",\"name\":\"Python Shelve: Storing, Retrieving, Updating, and Deleting Data\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png\",\"datePublished\":\"2021-02-09T04:33:42+00:00\",\"dateModified\":\"2024-01-01T05:04:31+00:00\",\"description\":\"Python shelve is a dictionary-like object. It is different from \\\"dbm\\\" databases as the value of shelve can be arbitrary Python objects.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-shelve\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png\",\"width\":1350,\"height\":650,\"caption\":\"Python Shelve\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-shelve\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Shelve: Storing, Retrieving, Updating, and Deleting Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\",\"name\":\"Prachee Sao\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"caption\":\"Prachee Sao\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data","description":"Python shelve is a dictionary-like object. It is different from \"dbm\" databases as the value of shelve can be arbitrary Python objects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-shelve\/","og_locale":"en_US","og_type":"article","og_title":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data","og_description":"Hello coders!! In this article, we will be learning about Python Shelve and the various functions that we can perform in it. In Python, a shelve is a","og_url":"https:\/\/www.pythonpool.com\/python-shelve\/","og_site_name":"Python Pool","article_published_time":"2021-02-09T04:33:42+00:00","article_modified_time":"2024-01-01T05:04:31+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png","type":"image\/png"}],"author":"Prachee Sao","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Prachee Sao","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-shelve\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/"},"author":{"name":"Prachee Sao","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47"},"headline":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data","datePublished":"2021-02-09T04:33:42+00:00","dateModified":"2024-01-01T05:04:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/"},"wordCount":426,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png","keywords":["python shelve example","python shelve module","python shelve query","python shelve tutorial","shelve python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-shelve\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-shelve\/","url":"https:\/\/www.pythonpool.com\/python-shelve\/","name":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png","datePublished":"2021-02-09T04:33:42+00:00","dateModified":"2024-01-01T05:04:31+00:00","description":"Python shelve is a dictionary-like object. It is different from \"dbm\" databases as the value of shelve can be arbitrary Python objects.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-shelve\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-shelve\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-shelve\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/02\/Theatre-Actor-Portfolio-Website-2.png","width":1350,"height":650,"caption":"Python Shelve"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-shelve\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python Shelve: Storing, Retrieving, Updating, and Deleting Data"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47","name":"Prachee Sao","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","caption":"Prachee Sao"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=8122"}],"version-history":[{"count":10,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8122\/revisions"}],"predecessor-version":[{"id":31430,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/8122\/revisions\/31430"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/8760"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=8122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=8122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=8122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}