Mike takes to heart the adage that ideas are f***ing worthless without action.

Tuesday, July 28, 2009

getting back into it... day 4

I installed PyScripter (written in Delphi) and my productivity went way up now that I have a good debugger. I've now passed my unit tests for the first time. I feel I'm now on my way to becomming a python programmer, slowly but surely.

Installed same tools on my work machine, and did my first sync. I expected the contents on the C:\wave folder of obsolete to be updated... but that's not how a distributed system works... you then tell it to sync the changes on that machine to the tip... which prevents a ton of headaches... a much saner way to go.

I edited the ignore options on Tiny, now we don't care about the .pyc files.

I've deliberately made a bad edit and commit and reverted it... works well!

I'm feeling pretty good about this.

Monday, July 27, 2009

getting back into it... day 3

Today I decided I needed a debugger... since I'm not really up on the syntax of python (lists look like tuples look like arrays to me)... I was really lost... it took about an hour to digging around to decide on PyScripter to be my IDE. I don't want to get tied into a product I can't afford, so I took a pass on Komodo from ActiveState.

I've managed to finally deduce what I was doing wrong, and pass one of my trivial unit tests... the code now looks like this:



--Translate01.py
"""Translates internal representation to and from xhtml"""

#define Exceptions

class HtmlError(Exception): pass
class invalidHtmlError(HtmlError): pass

#Define escape mapping
htmlCharMap = [('>', ">"),
('<', "<")]


def toHtml(x):
"""convert x to html string"""
return x

def fromHtml(s):
"""convert html string to internal representation"""

result = ''
index = 0
while index < len(s):
foundat = -1
i = 0
for ascii,html in htmlCharMap:
if (foundat < 0) & (s[index:index+len(html)] == html):
foundat = i
i += 1
if foundat >= 0:
ascii, html = htmlCharMap[foundat]
result += ascii
index += len(html)
else:
result += s[index]
index += 1
return result

Translate01_test.py:
"""Unit test for translate01.py"""

import translate01
import unittest

class KnownValues(unittest.TestCase):
knownValues = ( ( '', ''),
( 'x','x'),
( '>','>'),
( '<','<'),
( 'this is a test','this is a test') )

def testToHtmlKnownValues(self):
"""ToHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.toHtml(s1)
self.assertEqual(s2,result)

def testFromHtmlKnownValues(self):
"""FromHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.fromHtml(s2)
self.assertEqual(s1,result)


if __name__ == "__main__":
unittest.main()

Saturday, July 25, 2009

getting back into it... day 2

I've downloaded and installed TortiseHg for Windows (I'm running XP on my netbook) and I've done my first few tests with it... it's pretty nice. I've used TortiseSVN in the past, so I kind of knew what to expect. I chose TortiseHg and Mercurial because it's the version control system that Python is going to use in the future, so that's good enough for me. I don't have the experience or time to get it, so I'm going with the crowd on this one for now.

I added some test cases, now my code doesn't pass. Here's the current version of the testing unit:


"""Unit test for translate01.py"""

import translate01
import unittest

class KnownValues(unittest.TestCase):
knownValues = ( ( '', ''),
( 'x','x'),
( '>','>'),
( '<','<') )
def testToHtmlKnownValues(self):
"""ToHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.toHtml(s1)
self.assertEqual(s2,result)
def testFromHtmlKnownValues(self):
"""FromHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.fromHtml(s2)
self.assertEqual(s1,result)


if __name__ == "__main__":
unittest.main()

Friday, July 24, 2009

Shaking off the cobwebs, getting back into it

I've got some programming ideas, inspired by previous efforts and the most recent lessons learned from Google Wave, I'm going to start a python project to handle translating source code (specifically pascal code) bidirectionally to object code and symbol tables.

My main programming exerience is in Borland's Delphi 5, which suceeded a number of years using Turbo Pascal 7.0 under DOS. So, these new languages like Python, etc al. are a bit odd to me, but I really like the power of the built in dictionaries, tuples, etc.

I'm using an old build of Active State python (2.5.1) which I'll be updating. I managed to write a few modules with very trivial amounts of code, cribbing heavily from "Dive into Python" by Mark Pilgrim.

Here it is... ALL of it...


Translate01.py:

"""Translates internal representation to and from xhtml"""

#define Exceptions

class HtmlError(Exception): pass
class invalidHtmlError(HtmlError): pass

def toHtml(x):
"""convert x to html string"""
return x

def fromHtml(x):
"""convert html string to internal representation"""
return x



Translate01_test.py:

"""Unit test for translate01.py"""

import translate01
import unittest

class KnownValues(unittest.TestCase):
knownValues = ( ( '', ''),
( 'x','x'))
def testToHtmlKnownValues(self):
"""ToHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.toHtml(s1)
self.assertEqual(s2,result)
def testFromHtmlKnownValues(self):
"""FromHtml should give known results with known input"""
for s1,s2 in self.knownValues:
result = translate01.fromHtml(s2)
self.assertEqual(s1,result)

if __name__ == "__main__":
unittest.main()



It actually runs.... and tests ok... (because it's trivial right now)

PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.
Portions Copyright 1994-2006 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> ..
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK


So.... I'm on a journey... and I just took the very first step... a thousand miles to go. ;-)

About Me

My photo
Munster, Indiana, United States
I fix things, I take pictures, I write, and marvel at the joy of life. I'm trying to leave the world in better condition than when I found it.