In my humble opinion, a test specialist needs to be able to script/code or – preferably – create his own tools. I know, I know, there are plenty of ‘ready for use’ tools out there. Many of them usually work fine and quite some of them are free. But that isn’t always the case. Existing tools sometimes lack functionality. Or they are too expensive.
Therefore, one my new year’s resolutions is to learn a programming language. I’ve chosen to explore Python. It’s a quite accessible language and it’s not restricted to a certain platform. I plan to start from scratch, even though I did learn some things about Java, OO, and MVC in the past. But that’s almost ten years ago, so I won’t rely on that archaic knowledge. I’ve past the “Hello World” test, so now it’s time for the real stuff!
An example of my own:
#Decimal to hexadecimal #David Baak, January 7, 2013 #Using a function and a list #definition stack= hexalist=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F") #function: add to stack def addto( y ): stack.append(hexalist[y]) return #input check while True: try: x = int(input("Please enter an integer: ")) break except ValueError: print ("Oops! That was no valid integer. Try again...") #the main decision tree if x>=16: while x >= 16: y=x%16 addto(y) x=x//16 y=x addto(y) while stack: print(stack.pop(), end="") else: y=x print(hexalist[y])
Yes, this a detour for the already available
print(hex(x)) but I thought it was nice to show some of my thinking and give you a taste of the syntax.
- Extra sauce please
- My first Python tool