{"id":385,"date":"2015-12-31T18:23:32","date_gmt":"2015-12-31T22:23:32","guid":{"rendered":"http:\/\/www.tayloraliss.com\/blog\/?p=385"},"modified":"2016-01-05T13:53:29","modified_gmt":"2016-01-05T17:53:29","slug":"happy-new-year","status":"publish","type":"post","link":"https:\/\/www.tayloraliss.com\/blog\/?p=385","title":{"rendered":"Happy New Year!"},"content":{"rendered":"<p>Wow. It&#8217;s the end of 2015. What a ride it has been. I can&#8217;t believe that I started programming a year ago. It feels&#8230; not so long ago haha. Looking back, I see that I have really grown as a developer. And I guess as a person too. I can&#8217;t continue this post without first mentioning the biggest thing to happen in my life. Last week, December 21st, I got married to the most wonderful girl in the world. I really couldn&#8217;t have come so far without her never-ending support. I really am blessed. Because she was on a fiance visa, we only did the civil wedding at city hall. A really low-key thing. It was great though &#8211; my whole immediate family got to be there. We plan on doing a much grandeur wedding this April\/May when her mother comes to visit. How many people get to say they had two wedding celebrations, huh?<\/p>\n<p>Last month I finished my first computer science\u00a0class &#8211; Introduction to Computer Science I. It&#8217;s only the first step of my academic journey, but I can&#8217;t help comparing this semester to the semester I had ten\u00a0years ago. Ten years ago I was a freshman in college also enrolled\u00a0\u00a0in my first\u00a0CS class at the UMass: Dartmouth. I was taking Object Oriented Programming I and I had never felt more in-over-my-head than those few weeks I was in the class. I was\u00a0thrown right into a Linux environment and expected to do&#8230; well pretty much the same stuff I did this semester at OSU. I realize now that at that point in my life, I wasn&#8217;t ready for the rigors of pursuing a CS degree. I was naive and immature. In a panic, I switched out of the program &#8211; eventually winding up in the history department after a semester of non-major pre-requisite classes. Looking back, I see that switching out was the right thing to do. Had I stayed in that class, I probably would have flunked it. Maybe I would have even flunked out of college. It was a scary time.<\/p>\n<p>But now all that is behind me. I have a bright future ahead of me and I&#8217;m feeling exceedingly optimistic. I love the OSU program so far and feel like my knowledge is growing exponentially each day. Second semester starts next Monday. In the meantime, I&#8217;m back to learning Python and Flask. I really want to deploy my program onto the web. I&#8217;m very excited about it. However, I&#8217;ve been away from Python so long that I&#8217;ve forgotten a lot of its conventions. While doing some simple programming, I had a devil of a time getting a program to run correctly until I remembered that you can&#8217;t use the ++ operator in Python. As Steve says, I was &#8220;corrupted by C++&#8221;, heh.<\/p>\n<p>Well let&#8217;s talk about some new stuff. What have I learned recently?<\/p>\n<ul>\n<li>If\u00a0you\u00a0put a <code>main.py<\/code> file and a module\u00a0file <span style=\"text-decoration: underline;\">in the same directory<\/span> and run the\u00a0<code>main.py <\/code>file, it&#8217;s able to <code>import<\/code> from the modules\u00a0without an\u00a0<code>__init__.py<\/code> file.\u00a0However, if the module was in <span style=\"text-decoration: underline;\">another directory<\/span>, you would need to add an empty\u00a0\u00a0<code>__init__.py<\/code> file.\u00a0This is because the\u00a0<code>__init__.py<\/code> file is\u00a0how Python identifies directories from which you&#8217;re allowed to import. The directory of the script you&#8217;re running is an exception &#8211; you&#8217;re always allowed to import from it. (<a href=\"http:\/\/stackoverflow.com\/questions\/4142151\/python-how-to-import-the-class-within-the-same-directory-or-sub-directory#comment27915014_4142178\">source<\/a>)<\/li>\n<li>When the Python interpreter reads a source file, it executes all of the code found in it. Before executing the code, it will define a few special variables. For example, if the python interpreter is running that module (the source file) as the main program, it sets the special <code>__name__<\/code> variable to have a value <code>\"__main__\"<\/code>. If this file is being imported from another module, <code>__name__<\/code> will be set to the module&#8217;s name. (<a href=\"http:\/\/stackoverflow.com\/a\/419185\">source<\/a>)<\/li>\n<\/ul>\n<p>Here is a (relatively) simple example of how to import a class, create an object and use a method in that object:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#main.py\r\nfrom myModule import MyClass\r\n\r\ndef main():\r\n    instance = MyClass()\r\n    instance.myMethod()\r\n\r\nif __name__ == \"__main__\":\r\n    main()<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#myModule.py\r\nclass MyClass(object):\r\n\r\n    def __init__(self):\r\n        print(\"Object created!\")\r\n\r\n    def myMethod(self):\r\n        print(\"Hello from myClass.myMethod()\")<\/pre>\n<p>When run, this will be the result:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-theme=\"droide\" data-enlighter-linenumbers=\"false\" data-enlighter-language=\"shell\">Object created!\r\nHello from myClass.myMethod()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Wow. It&#8217;s the end of 2015. What a ride it has been. I can&#8217;t believe that I started programming a year ago. It feels&#8230; not so long ago haha. Looking back, I see that I have really grown as a developer. And I guess as a person too. I can&#8217;t continue this post without first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385"}],"version-history":[{"count":6,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}