{"id":1209,"date":"2023-04-01T20:28:28","date_gmt":"2023-04-01T19:28:28","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=1209"},"modified":"2023-04-01T20:28:28","modified_gmt":"2023-04-01T19:28:28","slug":"python-cycle-and-setattr","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2023\/04\/01\/python-cycle-and-setattr\/","title":{"rendered":"Python: cycle and setattr"},"content":{"rendered":"\n<p>This week a colleague refactor a script that I wrote and the end was pretty different from what I did. The logic was the same but the code was very differnt. I learnt two things about python<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><a href=\"https:\/\/www.toppr.com\/guides\/python-guide\/references\/methods-and-functions\/python-setattr\/#Setattr_python\">setattr<\/a>: This method provides an alternate means to assign values to class variables, in addition to constructors and object functions. It comes in handy when we want to add a new attribute to an object and assigning it a value<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><a href=\"https:\/\/realpython.com\/python-itertools\/#:~:text=cycle()%20function.,end%20of%20inputs%20is%20reached.\">cycle<\/a>: . This function takes an iterable\u00a0<code>inputs<\/code>\u00a0as an argument and returns an infinite iterator over the values in\u00a0<code>inputs<\/code>\u00a0that returns to the beginning once the end of\u00a0<code>inputs<\/code>\u00a0is reached.\u00a0<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This week a colleague refactor a script that I wrote and the end was pretty different from what I did. The logic was the same but the code was very differnt. I learnt two things about python setattr: This method provides an alternate means to assign values to class variables, in addition to constructors and &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2023\/04\/01\/python-cycle-and-setattr\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Python: cycle and setattr&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1209","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":1,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"predecessor-version":[{"id":1210,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1209\/revisions\/1210"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}