{"id":500,"date":"2020-11-21T17:38:31","date_gmt":"2020-11-21T17:38:31","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=500"},"modified":"2020-11-21T17:38:31","modified_gmt":"2020-11-21T17:38:31","slug":"python-golang-p1","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2020\/11\/21\/python-golang-p1\/","title":{"rendered":"python-golang-p1"},"content":{"rendered":"\n<p>This week I had to update several spreadsheets&#8230;. again donkey job, again try to work smarter. So there was a pattern, and I knew I could copy\/paste to the spreadsheet all changes (192 changes per file&#8230;). So decided to create a python script to generate the output I needed. It was just new hostnames for devices. So it wasnt really difficult. Although I had to search for basic stuff like how to make a for loop in python. That&#8217;s what happens when yo dont use thing often.<\/p>\n\n\n\n<p>Anyway, I managed to get my basic python script. And I could copy paste the output to the spreadsheet just fine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat rename.py \nfor x in range(137,141):\n    print(\"router-p1-r\" + str(x) + \"01\")\n    print(\"router-p1-r\" + str(x) + \"02\")\n    print(\"router-p1-r\" + str(x) + \"03\")\n    print()\n$ \n$ python rename.py \nrouter-p1-r13701\nrouter-p1-r13702\nrouter-p1-r13703\n\nrouter-p1-r13801\nrouter-p1-r13802\nrouter-p1-r13803\n\nrouter-p1-r13901\nrouter-p1-r13902\nrouter-p1-r13903\n\nrouter-p1-r14001\nrouter-p1-r14002\nrouter-p1-r14003\n<\/code><\/pre>\n\n\n\n<p>But now, I have been trying to learn golang (even though I dont master python neither bash&#8230;.) and I thought this was a basic stuff to try in golang too. So again, I had to search for basic stuff. How to create a range: <a href=\"https:\/\/stackoverflow.com\/questions\/21950244\/is-there-a-way-to-iterate-over-a-range-of-integers\">link<\/a>. How to concatenate a string and a integer: <a href=\"https:\/\/maxchadwick.xyz\/blog\/concatenate-a-string-and-an-int-in-go\">link<\/a>.<\/p>\n\n\n\n<p>So managed to get this and looks like it does the same job:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat rename.go \npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfor i := 137; i &lt;= 141; i++ {\n\t\tfmt.Println(fmt.Sprint(\"router-p1-r\", i, \"01\"))\n\t\tfmt.Println(fmt.Sprint(\"router-p1-r\", i, \"02\"))\n\t\tfmt.Println(fmt.Sprint(\"router-p1-r\", i, \"03\"))\n\t\tfmt.Println()\n\t}\n}\n$ \n$ go run rename.go \nrouter-p1-r13701\nrouter-p1-r13702\nrouter-p1-r13703\n\nrouter-p1-r13801\nrouter-p1-r13802\nrouter-p1-r13803\n\nrouter-p1-r13901\nrouter-p1-r13902\nrouter-p1-r13903\n\nrouter-p1-r14001\nrouter-p1-r14002\nrouter-p1-r14003\n\nrouter-p1-r14101\nrouter-p1-r14102\nrouter-p1-r14103\n<\/code><\/pre>\n\n\n\n<p>So got the same result in both languages. Keep going!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I had to update several spreadsheets&#8230;. again donkey job, again try to work smarter. So there was a pattern, and I knew I could copy\/paste to the spreadsheet all changes (192 changes per file&#8230;). So decided to create a python script to generate the output I needed. It was just new hostnames for &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2020\/11\/21\/python-golang-p1\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;python-golang-p1&#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":[24,25],"tags":[],"class_list":["post-500","post","type-post","status-publish","format-standard","hentry","category-golang","category-python"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/500","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=500"}],"version-history":[{"count":1,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/500\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}