{"id":295,"date":"2008-04-04T18:39:51","date_gmt":"2008-04-05T01:39:51","guid":{"rendered":"http:\/\/www.stevenbrown.ca\/blog\/?p=295"},"modified":"2008-04-04T18:39:51","modified_gmt":"2008-04-05T01:39:51","slug":"snakes-in-an-office","status":"publish","type":"post","link":"https:\/\/www.stevenbrown.ca\/blog\/archives\/295","title":{"rendered":"Snakes in an Office"},"content":{"rendered":"<p>I&#8217;ve <a href=\"https:\/\/www.stevenbrown.ca\/blog\/archives\/250\">mentioned before<\/a> that my job (whose contract is almost up) doesn&#8217;t require programming.  But that doesn&#8217;t mean that programming is not useful.  When I first got my laptop, I asked the tech guy about the process of installing new software.  It went something like this:<\/p>\n<ol>\n<li>Write a formal request for the software you would like installed and submit it to the tech support department.<\/li>\n<li>Wait for review and approval.<\/li>\n<li>Wait for them to install it.<\/li>\n<\/ol>\n<p>A pretty standard (and painful) process in large organizations, unfortunately.  I asked him, &#8220;So if I want to install Python I just submit one of these requests?&#8221;<\/p>\n<p>Insead of answering my question, he asked me one in return.  &#8220;What would you want to install <em>Python<\/em> for?!&#8221;  I think he actually spat and curled his lips at the thought.<\/p>\n<p>&#8220;I don&#8217;t know&#8230;  writing basic scripts.&#8221;  I really didn&#8217;t know what at the time, but I knew it would be useful.  And I wanted to use it.<\/p>\n<p>He proceeded to look at me as if I had suggested bathing in tomato sauce as a remedy for headaches.<\/p>\n<p>So I was under the impression that I couldn&#8217;t install new software and didn&#8217;t want to bother going through all that formal cock holding; I went without my Firefox, my Python.  I&#8217;ve since discovered that I <em>can<\/em> install things.  (Sorta.)<\/p>\n<p><em>Anyway<\/em>, I was using Python at work today, and I just love it.  Previously, I had been fumbling around with VBA in Excel and Word.  I had a button set up in Word that would run a macro\/VBA to export the form&#8217;s contents to a CSV file in a particular folder.  I could open a Word document anywhere, press the export button, and the CSV would be created\/overwritten in that folder.  Then I had a button set up in Excel to run a macro that would import all CSV files in that folder as rows in the spreadsheet.  (This was actually <em>really<\/em> useful, and if you have to deal with a lot of similar tasks in Office, use VBA and macros.)  There was an inconsistency in the number of rows I had in my spreadsheet and the number of docs I had&#8230; so I wanted to compare the exported CSVs with the available DOCs.<\/p>\n<p>Enter, the Python interpreter (great for little tasks and as a substitute shell on windows).<\/p>\n<p>The word documents were in a bunch of different folders (for various reasons) but once I had a variable, <code>originals<\/code>, containing a list of all the documents, and a variable, <code>exported<\/code>, containing a list of all the CSV, files, I was rolling.<\/p>\n<p><code class=\"codeblock\"><br \/>\n>>> len(originals), len(exported)<br \/>\n(198,200) # Hmmmm, looks like a job for sets!<br \/>\n>>> s1,s2 = (set(originals), set(exported))<br \/>\n>>> len(s1.difference(s2))<br \/>\n398<br \/>\n>>> # What the...<br \/>\n...<br \/>\n>>> originals<br \/>\n['doc1.doc', 'doc2.doc', ...., 'doc200.doc']<br \/>\n>>> exported<br \/>\n['doc1.txt', 'doc2.txt', ..., 'doc200.txt']<br \/>\n>>> # Oh yeah, different extensions.  Duh...<br \/>\n... # Bus leaves SOON!<br \/>\n... # Need to quickly strip the extensions and rebuild the sets....<br \/>\n...<br \/>\n>>> s1,s2 = ( set([s[:-4] for s in s1]), set([s[:-4] for s in s2]) )<br \/>\n>>> s1<br \/>\n['doc1', 'doc2', ... , 'doc200']<br \/>\n>>> # Cool<br \/>\n...<br \/>\n>>> s1.difference(s2)<br \/>\n(['doc38', 'doc72'])<br \/>\n<\/code><\/p>\n<p>AHA!!  Caught my bus.  Python is great.  \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve mentioned before that my job (whose contract is almost up) doesn&#8217;t require programming. But that doesn&#8217;t mean that programming is not useful. When I first got my laptop, I asked the tech guy about the process of installing new software. It went something like this: Write a formal request for the software you would&hellip; <a class=\"more-link\" href=\"https:\/\/www.stevenbrown.ca\/blog\/archives\/295\">Continue reading <span class=\"screen-reader-text\">Snakes in an Office<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[48,141,139,66,46,142,140,143],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-geek","tag-code","tag-excel","tag-office","tag-programming","tag-python","tag-vba","tag-word","tag-work","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4jEMb-4L","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":0,"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stevenbrown.ca\/blog\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}