wintermute1974




Entries
learn python (read all 10 entries…)
Typo Yields Weirdness

Dictionaries are one of the built in types that I really like in Python. (I think of them as the equivalent of dt and dd in HTML, if that helps anyone.)

But I made a typo, and that typo works. Now the typo is playing with my head. Take a look as this history from the Python Interpreter:

>>> d={} 
>>> d['key']=d
>>> d
{'key': {...}}

Yes, if this is correct, Python knows that dictionary ‘d’ has a key named ‘key’ that contains dictionary ‘d’.

What makes this example particularly cool is the {...}, which shows Python knows that there is no bottom at the end of this dictionary.

This is so cool.

These examples work too:

>>> d['key']['key']
{'key': {...}}
>>> d['key']['key']['key']['key']['key']['key']
{'key': {...}}



Read "The Pragmatic Programmer" (read all 3 entries…)
Book Delivered

The courier arrived with The Book while I was at work, but thankfully the Property Management company for my condominium signed for it.

And so here I sit, at home on a Tuesday evening, with my very own copy of The Pragmatic Programmer.

After reading some reviews on the web, I was worried that the typesetting would be poor, but all the grousing is unwarranted.

The copy I have is professionally printed and well laid out with a good mix of white space and text.

Since I am starting out on a new project, I think that I will read Chapter 7 on specifications first.



learn python (read all 10 entries…)
pydoc

It took the afternoon, but I found the useful Python module that creates a web server so that you can browse installed modules from your web browser:

It’s called pydoc.



learn python (read all 10 entries…)
It's import(ant)

This works, bringing function() into your namespace:
   from module import function

And this works, but you will have to call module.function():
   import module

But this one doesn’t work:
   import function from module

Of course, the third way is the one I have been typing all morning.

I got my first module to run in WingIDE this morning. The entire code is:
%{color:green}if name==’main’:
   print ‘Hello World’%

Very nice. In WingIDE, I:
  • created a project
  • created a new text file
  • associated the text file with the project
  • ran the project.

In the DebugI/O window, it showed “Hello World.”



Read "The Pragmatic Programmer" (read all 3 entries…)
Bought a Copy Online

The Toronto Public Library does not have a copy of The Pragmatic Programmer so I went ahead and bought a copy on Amazon. I chose free shipping, so it will probably be a week before it arrives.

I still can’t stop thinking of one of the free extracts on the book’s website. I usually am disappointed when I can get a program to run on my development PC, only to discover that it fails to load, much less run, on a regular user’s PC. I fear I may be guilty of Programming By Coincidence.



learn python (read all 10 entries…)
Mapped Out the Grand Plan

I spent about an hour or two tonight sitting at my kitchen table with pen and paper. Before hitting a single key of code in my pricing program, it helps to know what the goal is, so that I can get there.

Since Python treats everything like an object, the most natural way to create a pricing program is to map the real-world objects onto Python objects.

So far, I have a master object called the System. My program can have only one of them.

Each System will contain zero or more Components. Sample components include
  • rectifiers (that turn AC to DC),
  • inverters (that do the reverse)
  • batteries (that sit between rectifiers and inverters)
  • and sundry other components (such as diode droppers, blocking diodes, and best battery selectors).
Each Component will have a number of Attributes including:
  • input (voltage, current, etc)
  • output (the same)
  • settings
  • meters
  • alarms

The Attributes are the sticky part right now. Some attributes will be independent of one another, others will be mutually exclusive. Some will be dependent on one another.

This will probably take some time to thrash out, but I am glad I did it on paper first.



Read "The Pragmatic Programmer" (read all 3 entries…)
A Discovery on 43 Things

If it were not for this website, I would not know about this book.

Intrigued with the eighty or so people wishing to read this book, I checked for the website.

The main page did not convince me, but the extracts did. If my local library does not have a copy already, I will buy one.



learn python (read all 10 entries…)
Python Project

Well, I most definitely have a Python project to work on now: Yesterday, I pitched a Pricing Tool to the Vice President of the company I work for.

Programming isn’t my job - at least it isn’t right now - but I offered to create a tool that salesmen and end-customers can use in the field.

Now all I have to do is create it. I told him that I would have a prototype ready in two months. It looks like my evenings and weekends just got a whole lot busier! October 24, here I come!



learn python (read all 10 entries…)
Trying WingIDE for Development

Up until now, my favorite programming language has been Visual Basic 5, and one of the main reasons is that it has a nice IDE.

Those people coming from a Unix background prefer the command line, and so the default installation of Python is probably just fine for them.

But for me, I want syntax highlighting and the ability to visually stop and step through a program that has spit up and died.

A cursory Google search shows that there are dozens. At first, I tried some of the free ones: IDLE (which came with my installation of Python), DrPython, and PyCrust and PyAlaMode.

I was hoping to find a free editor that would meet my needs, but so far, no luck.

So, after surfing the web for Python development environment reviews, I learned about Wingware’s WingIDE. Sadly, it is a commerical program, with licenses and costs. Thankfully, there’s a stripped down “Personal” version that does not cost too much.

Wingware is generous enough to give you a trial version that you can run for three 10-day periods, of which I am on my first. As my screenshot shows, I have not actually coded in this IDE yet, but have been going through the tutorial slowly and systematically.

So far, so good. If paying a few dollars for a good IDE will save me hours (or days) of frustration later, it will be money well spent.



learn python (read all 10 entries…)
Two Program Ideas

Now that I have experimented a little with Python, my mind is already considering which fun, sample programs I could write to learn the language. So far, I can think of two.

Idea #1: Create A Text Adventure
This would be a “fun with objects” learning experience. I could define a room object and an object object and populate a world with them.

I could create a stub of a def parser(): function, which would interpret text typed by the user.

In its own, tiny way, this would be my tribute to the Infocom games that I used to play.

If I am lucky, the game will be more exciting than my life at work:
  • Look

You are seated at an office desk. Behind you is a window. To your right is a photocopier. Exits are to the south and west.

  • Examine desk

You are sitting behind dual 17” displays at work. In the right display, the Microsoft Outlook Inbox is maximized, like it is every day. A message from your brother Carl is highlighted there. To the left of your keyboard is a small cup of coffee with cream and sugar. The cup is half empty.

  • Hit the reply button

You hit the monitor with your fist. Your knuckles hurt.

  • Press the reply button with the mouse.

A window appears in the left display. You can see happy little desktop icons in the background.

  • Drink coffee

You don’t see any coffee here!

  • Drink cup

You take a sip of coffee. It is lukewarm. Your stomach turns.

  • Type a reply using the keyboard

You place your fingers on the home row of the keyboard. The keys are slightly discoloured, possibly from the dirt from the factory floor beyond this room, possibly from one too many snacks eaten at this desk.

Idea #2: Create a Game of Life

Now, this game is notConway’s Game of Life, simply because I never enjoyed the stupid repeating patterns.

Instead, I would create a bug object. Each bug would have an x% and %{color:red}y position on a two-dimensional world.

Each bug would also have a energy level that would count down with every move. When the bug discovers food, its energy increases. When the bug moves, it expends energy. If it doesn’t eat frequently enough, it dies.

To make the game interesting, each bug could have its own genotype in a 3×3 matrix for each of the cardinal directions plus the middle element for no movement at all.

Two assumptions I have already made for now are that multiple bugs can inhabit the same x,y position on the screen peacefully, and that bugs are blind and move without sensing the world outside.



learn python (read all 10 entries…)
Session 1: Introductory Bits

I finally sat down and started reading the How to think like a computer scientist book, which I’ll just call my primer from now on.

So, what did I learn?

Well, for one thing, both functions and classes are ridiculously easy to create.

%{color:blue}# These next two lines will create a function.
def name(parameters):
   pass%

%{color:blue}# These next two lines will create a class.
class powerful:
   pass%

I also discovered two very handy built-in functions.
  • id(variable) will give you the unique ID number for any variable currently available. This is handy if you want to tell if two variables are pointing to the same location or to two different locations.
  • type(variable) will tell you what type the variable presently is, with useful names such as ‘classobj’ or ‘int’.

I found both of these functions so handy, that I created my own “info” function, that goes like this:
%{color:blue}def info(var):
   print ‘Value:’,var
   print ‘ID:’,id(var)
   print ‘Type:’,type(var)%
And that is that.

Incidentally, pass is a place holder for when you do not have any statements. You’ll need it because of the indented structure of the language.



stop watching television
Television is Life Delayed

Television is a great time waster. You can sit down for the evening news and before you know it, it’s time to go to bed. If you are not careful, this can happen day after day, year after year.

Two years ago this September, I decided to stop watching television. I was worried I might die without it, so I did not throw it out—well, not at first, anyway. Instead, I unplugged my television and put it in the bottom of my closet, under old coats and a sleeping bag.

The first few weeks were strange. Suddenly, I had all this free time. I remember spending more time at work, or taking longer to come home in the evenings.

After a few months though, the stupid was out of my head. I found I had time to read books, go on walks around my neighborhood, and develop talents I did not know I possessed.

Although I did not know it at the time, I learned something valuable about it: Television is life delayed.

Once you regain the hours once spent idly staring blankly at the box, you will realize how interesting your own life can be.

I recommend you do it. Don’t “try to” do it. Don’t moan that you “have to” do it. Tell yourself that you want to do it, and then put the box away.



learn python (read all 10 entries…)
Found My Python Primer

Finally, I have found my Python Primer.

It is called How to think like a computer scientist by Allen B. Downey and Jeffrey Elkner. Best of all, I can share it with all of you because it is a free document. I chose to download the free PDF version as I find PDFs display quite nicely on my monitor.

I have programmed before, so I do not need much hand holding there. But an introductory guide will give a good survey of the entire language, and sometimes it is nice to be lead by the nose.

If I happen to learn a few good coding practices in doing so, so much the better.



stay up all night and day one time
You May Be Surprised

I did this out of necessity rather then by choice, but I still recommend you try it, if it comes naturally to you.

Do not force a sleepless night. If you find you are working late on a project that engrosses you, or that you are at a party with friends and you do not want to leave, then give it a try. Staying up just for the sake of staying up does not sound like much fun to me.

The only time I ever did this was in university, when I woke up one day, performed a chemistry or physics experiment in the lab, and then spent the whole night writing up my results to submit the next morning.

Personally, I was always surprised by my behavior the next day. I normally am a quiet, reserved guy. But deprived of sleep, I felt great, elated, like I was one with the universe and everything in it.

Each time I did it, I felt tired and horrible that night, but watching the sun rise was magical.

Mind you, my memory was shot that second day. Do not ask me what I did after a sleepless night. I do not really remember.



learn python (read all 10 entries…)
Why Python?

As a child in the 1980s, I was exposed to BASIC on 8-bit microcomputers. Over the years, I have had some success with C and assembly, but never really got serious about programming.

At my first real paying job, I discovered Visual Basic for Applications and later on the full-blown Visual Basic. I enjoyed using those tools, and truth be told, they’re still the ones I know best.

But Microsoft and I parted company when they started unrolling VB.net. By that time, I realized that Microsoft reinvents its tools every few years, and this did not appeal to me at all.

If there is a convincing reason to change development environments, fine, but just because some company wants to sell me their newest and greatest? No thanks.

So I surfed the web, looking for a free, open-source language which would not be held at the mercy of arbitrary upgrades to meet some company’s product cycle. There are many of them. I invite you to look at them for yourself.

Last year, I decided it was Python. I read the papers of Python’s creator, and in them, I learned that former VBers like myself were his target audience.

Since then, I have collected a few Python books. My first one was a bit of a disappointment, and it sort of put me off further studies. But no longer.

Now it is time to actually sit down and learn it.



Entries

 

43 Things Login