Programming

Pythoneer

Wednesday, September 21. 2005

phpSqliteAdmin Installation

I wanted a simple web based "download and run"-SQLite browser. So my choice was of course a PHP tool, first thing to look for is something like phpMyAdmin just for SQLite.

There are two of them, with the same name "phpSQLiteAdmin":

  1. One by Yves Glodt
  2. Another one by Richard Heyes

and none of them works out of the box! So here is what I did to get number 2 (phpSQLiteAdmin by Richard Heyes) running.


Continue reading "phpSqliteAdmin Installation"

Posted by Wolfram in Programming at 12:44
Comments (0)
Trackbacks (0)

Saturday, September 10. 2005

What I want from a (unit)test module

or Deficits of pyUnit

I don't even know for sure if unittests is the perfect testing method in my case, but until now the methodology of it works fine for me, it's just those little things that sometimes bother me.

Here is what I am missing

  • run tests X times, we have timing issues and unless the tests didn't succeed a hundred times i don't trust them to always pass, I need e.g. a simple command line parameter "--repeat=100"
  • if i call assert*() inside a method multiple times it shall also be counted as that number of tests. E.g. i write the function test_x() and inside i have three times assert() calls, because i am too lazy to write 3 seperate functions, this shall also count three tests!

Yeah I realize now, that those are not big things, but I just started yesterday writing down what I miss, so this list might grow. I am sure there is someone out there who can help ... thanks

Posted by Wolfram in Programming at 12:03
Comments (3)
Trackbacks (0)

Friday, September 2. 2005

Configuration management

Gotta read some stuff about configuration management and the software development process besides hacking. It seems there is a lack of tools in the open source world. Even though I am always again surprised how much better it works than in some companies. Actually it's the other way around, I know that it works in the open source world, I am surprised that it doesn't work in some companies.

Posted by Wolfram in Programming at 18:13
Comments (0)
Trackbacks (0)

Tuesday, August 2. 2005

My first AppleScript

I read the book two months ago, but I never wrote a line of AppleScript. But now I did!

-- Open the terminal application and two windows
-- the right window shall be a python shell and shall
-- have the full height and be at the right edge of the screen
-- the first window stays at the left side of the screen
-- in normal size
tell application "Terminal"
  activate

-- this is cruel, there is no "make new window" I have
-- to step through the menu
-- yucky ... but it works .... jippi
-- thanks to to Fork on #ignmac and to
-- http://bbs.applescript.net/viewtopic.php?pid=32691
tell application "System Events"
   click menu item "Neues Shell-Fenster" of menu "Ablage"\
   of menu bar item "Ablage" of menu bar 1 of process "Terminal"
end tell

tell window 1
set position to {0, 0}
end tell

-- get the width+height of the screen
-- http://www.macosxhints.com/article.php?story=20050428173653581
try
  set window_info to do shell script\
  "defaults read com.apple.loginwindow\
  | grep -w 'NSWindow Frame About This Mac'"
  set screen_width to (word 13 of window_info as number)
  set screen_height to (word 14 of window_info as number)
on error -- use defaults on failure
  set screen_width to 1024
  set screen_height to 768
end try

-- set window 2 dims
tell window 2
  set position to {screen_width - 1000, 0}
  set size to {1000, screen_height}
end tell

-- open the python shell in window 2
do script "clear; python" in window 2

end tell

Posted by Wolfram in Programming at 11:27
Comments (4)
Trackbacks (0)

Tuesday, July 26. 2005

Import strangness?

I have a module tree containing the following modules module.util and module.x.util. The latest, module.x.util imports some module that again imports module.util (it doesn't import it directly!).

Why does import module.x.util as util work, but from module.x import util not?
In the last case util is <module 'module.util' from ...>! Why that?

Posted by Wolfram in Programming at 17:22
Comments (0)
Trackbacks (0)

Thursday, July 14. 2005

The least about Unicode

I have to admit I was a little bit ignorant until today. But not anymore :-)
A must read: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

And more

  • A nice Python specific UTF article
  • Another Unicode in Python
  • Introduction to Unicode
  • A list of all the characters and more info
  • The wikipedia article about Unicode and about ISO 8859
Posted by Wolfram in Programming at 12:56
Comment (1)
Trackbacks (0)

Thursday, June 23. 2005

Is there a real editor for HTML, JavaScript, CSS?

Before you say yes, of course, listen to what I want.
Lately I am doing a lot of Python programming, using WingIDE (I guess people who read this blog are already bored by me mentioning Python). And now that I am trying to write a little dashboard widget which is nothing more than HTML, JS and CSS (btw Apple also brought up the cool <canvas> element for their dashboard clock) I realize what I am missing.

The WingIDE has a feature that I call dive into. It let's you dive into the function/variable/class/etc. that your cursor is on. Actually it's exactly like the "step into" in your debugger. It simply goes to the place where this item (your cursor is on) is defined, also if it is located in another file than the current one or any of the opened files. It just opens the file and jumps to the proper line.

Another item the WingIDE has is the auto-bookmarking. That is simply like a click and "dive" history. When you dive into a piece of code and want to jump back to where you came from (as I mostly do), you simply jump back in history. Just like in a browser. In this IDE you can define the shortcuts for it, which are the same as in my browser, of course. This allows very well to "just look how the function does it" and keep on working. You simply dive into and go back in the history.

What does all that have to do with HTML, CSS and JavaScript editing?
A hell lot I think. I guess you got my point by now. First thing where I realized I miss it was a simple define in a JavaScript file. I could not find the variable definition in the current JS file. But where did it come from? Well, just go back to the HTML file where all the JS files get included and look at all the files (or use a search over all files). That can really cost some time. All I wanted was a dive into from the current file to get to the defintion.
The same thing about CSS. There is a tag <div class="popup">. Now I would like to know what the CSS define for popup looks like. I open the CSS file do a search for the class popup. Ok, quite feasible for simple setups, but it could be easier. Simply press the shortcut for dive into the CSS class and you get there at an instance, like a finger snap.

The drawbacks of providing this are of course the effort that it would cost to implement it. The pages might be very dynamic also the includes etc. And the web environment might had to be simulated (or used) in some cases to detect the actual connection between the different items and/or files. But hey we got enough power in our computers and the applications we develop become more high level every day. So tools like those should be basic development tools. Or not?
Just a thought ...

Posted by Wolfram in Programming at 23:11
Comments (3)
Trackbacks (0)

Friday, June 17. 2005

Storing trees in a DB

Again I am searching for the best way of storing a tree structure in the DB. Quite a while ago I had written the PEAR package Tree (for PHP). I have given up maintenance a while ago because of the lack of time. There I implemented a couple methods to store trees (in XML file, file system, array, etc.) of course also two different ways to store trees in the DB. The one is the famous and much discussed nested structure the other is the simple (brain dead - someone called it) way, which only stores the parent ID for each node.

So why am I searching again? I simply want a method, which is easy to implement (or even better already implemented) and fast enough on small trees. But on the other hand I always try to get the best and that means cleanest too (nested!?).

Implementing the nested tree structure I had made my hands already really dirty. First it was just that some SQL statements were (let me say) challenging. But then when it came down to copying and moving parts of the tree in a manner, that the structure never gets corrupted at any time, I had given up I think (I know I shouldn't say that in case a potential employer might read this, but hey it was my spare time!).
Another problem that made me realize it will become harder to implement was that I realized that I need a parent-ID for each element, in order to find the parent easily. That meant all other statements needed to be updated. Actually the entire code, ok. (That was a good time to start writing tests, since the entire thing got quite big already.) I don't want to go more into detail. I can tell it takes quite some time, patience and learning (at least for me it did) to get the nested sets done in a DB. And sometimes I think my head was exploding from the headaches it gave me. But we programmers are that way I think.

So now I will start looking for the ideal Python solution for that. I am definitely not going to make my hands dirty on nested trees again! It has to support mySQL of course.
Any suggestions?

Posted by Wolfram in Programming at 00:19
Comments (12)
Trackbacks (0)

Wednesday, June 8. 2005

Python: Tkinter vs. wxPython

Now I am going to dive into the stuff I am really looking forward to and I was not doing for years - GUI development. Therefore I first asked on #python and I really got the impression really quickly that Tkinter is out, wxPython rules. Ok the result of this article came early. My decision was taken quickly too.
Anyway I wanted more proof here it is, a nice short summary of Tkinter vs. wxPython. About Tkinter there is said "Probably a dead-end technology, as toolkits such as wxPython gain mindshare." ok that's enough, I am convinced.

Next of course I was looking for tools to build the GUI. I always want to see results first, I learn best on the job.
On #python someone suggested boa constructor (cool name!). It is not as straight forward as I expected it, but I might learn.
Within the examples of wxPython comes XRCed a simple but not WYSIWYG editor but somehow easy to catch up with. And for being a beginner with wxPython I was right away impressed of what it can do and how good it looks, this app is written with wxPython of course.
In the article mentioned above I read about wxDesigner. I don't know it yet, but it looks good. You have to buy a license, until you didn't you can not save. Let's see.
There are some more wxGlade, PythonCard and Spe.

Posted by Wolfram in Programming at 21:46
Comment (1)
Trackbacks (0)

Wednesday, June 1. 2005

Python: Discovering, Part I

Just some easy stuff today.

Dynamic import

It didn't take me long to find out. Now I know that the dynamic counter part for the import-statement you mostly use at the beginning of files to import other modules/classes/etc. is a built-in function __import__() which is only logical for Python.

     __import__(my_module)
loads my_module, which better exist if you don't catch the ImportError, like here:
     try:
__import__(my_module)
except ImportError, reason:
...solve the problem now...
You can also do the beloved from-import thing (btw I am always tempted to write import-from):
The statement ‘from spam.ham import eggs’ results in ‘import (’spam.ham’, globals(), locals(), [’eggs’])’.
[Taken from the Python Library Reference]

Python simplifies code, sometimes!

One of Python's design goals definitely is to be as simple as possible. In regards of writing functional code it definitely reached it. I am sure I am much faster writing Python code than ever before, also simply because you can leave out a lot of braces and parentheses, etc. I catch myself quite sometimes still putting the ";" at the end of a line, which fortunately also works in Python. The curly braces I don't touch anymore but for dictionaries. But, I was just looking at some of the code I am currently working on, and there you can see that the syntax-simplicity stops when it comes to defining list, dictionaries, and so on especially when they are nested, as in my case. You can easily mistype things and as opposed to the "official" Python style guide you can only read the structure properly by formatting it using spaces so it stays readable. Even when the IDE's syntax checker warned me, I didn't see the error and thought I was smarter. But I wasn't. It just took me too long to see the syntax error. So there is not much win in there. This is what the structure, to be optimized, looks like now:

    data = {
"init": {"states":("step1",), "screen":"init", "data":[2,4,6,8]}
,"step1": {"states":("one:init",), "screen":"step 1"}
,"one:done": {"states":("done","init"), "data":[1,2,3,4,5,6]}
,"done": {"states":(), "screen":"done, yeah"}
}
May be a better support by the IDE would solve the whole thing. It would just need to do two things. First offer an easy mode to edit complex structures this has to be intergated in the editor and useable via keyboard of course. And second the code that results out of it has to be well readable by other editors, that don't have this editing feature. Also, may be the structuring by indenting could be used here too. I have ne real plan on how

Missing doc tags support

Pyhton lacks doc tags support. First I was really amazed that Pyhton makes the doc string available in the code, but now that seems half-hearted. I might want to inspect more than the doc-string. I am missing at least a standardized way to write the header-comments like java-doc (or php-doc). inspect.getargsepc() helps a lot, but doesn't and can't provide all the information one could get if doc-tags like @param, @return, etc. would be filled in by the developer. Additionally the IDE could provide much more detailed information in the auto-complete feature. What I miss most about it is the @see feature because documentation lives from cross-references. And it happens very often that you write comments like "for further info see the attribute/function". Optional automatic type-checking would be a next use case. Drawbacks are surely a possible performance decrease, but this might be handled by optionally turning this feature off. And the following looks pretty good in my eyes.

def draw_rectangle(x, y, height, width):
"""Draw a rectangle with the given coordinates.

@see draw()
@param int the top position where to start the rectangle
@param int the left position where to start the rectangle
@param int the height of the rectangle
@param int the width of the rectangle
@return bool True on success
"""

Posted by Wolfram in Programming at 21:35
Comments (0)
Trackbacks (0)

Saturday, May 21. 2005

Python: some neat things and PHP bashing

During the last weeks of my entry into the Python world I have very quickly realized that I have to change my way of thinking and programming. A very good example is this thread where I tried to act smart and learned something!

Just now I read on the python-list an ancient mail about why print is a statement and not a function, there I also found out how to avoid the new line at the end of a print which never really bothered me, but I always asked myself how to avoid it, just in case I would ever need it.

print "no new line after me",

See the comma at the end! Huhu, cool thing. Some things are just easier than I thought. And it makes perfectly sense. I am using the print statement (without parentheses) quite a lot also with comma seperated arguments, instead of concatenated strings, so that should have been something, not obvious, but one of the first options to try.

PHP bashing

Another example of why I like Python better (over PHP). In PHP I would do the following:

if (in_array("x",$array) && $value)

In Python you do the same like this

if "x" in array and value

Which one is better to read?

Another interesting Python thing was finding the common words in two strings. I would not have come up with something that simple:

>>> import sets
>>> set1 = sets.Set("Bernd das Brot".split())
>>> set2 = sets.Set("Bäcker Bernd backt Brot".split())
>>> set1 & set2
set(['Brot', 'Bernd'])

Isn't that awesome? For those new to Python the ">>>" at the beginning of the line come from the Python shell, which btw is really great, I think I mentioned that. Sets seem to be in Python since 2.3.3.
OK, in PHP you would do it using the array_intersect function. But then you go into the hell of PHP's array-functions you first need to get the order of the parameters right :-). I think PHP's array functions are the best chaos you can find, especially the different orders of parameters for functions that do alike things. I don't even want to start about the naming. Many others have done that before.

Posted by Wolfram in Programming at 01:38
Comment (1)
Trackbacks (0)

Friday, May 6. 2005

Python: goto was implemented!

From the Python page in wikipedia:

goto was implemented as a joke for April 1st 2004, in an add-on module

There are other programming languages seriously considering it, hehe.


Posted by Wolfram in Programming at 21:15
Comments (0)
Trackbacks (0)

Wednesday, May 4. 2005

Python: Builtin Introspection is a great thing

I come from the PHP side. I skipped PHP5 until now, I only know it from the theory, but what I have experienced until PHP4 was always again mixed with a little bit of frustration. Now after switching to Python about two weeks ago (and I am already quite productive!) I can't say how much time the builtin introspection methods have saved. Such as dir() or even the simple __dict__ attribute of an object/class. The Python command line is always opened, simply to try things. Having that would have helped a lot when starting with PHP. But PHP was just made for the web, initially. Python feels really good on the desktop, it's not as castrated on the command line as PHP.

In the Python shell I am always trying the constructs that I am thinking about using where I am not sure about how and if they work, I am inspecting objects there and searching the sys.path lot of times. It is simply the little testing env that makes you feel one with the language. I just don't know why on my Mac the UP and DOWN keys don't work, for selecting the last commands. On the Windows  (Virtual PC of course, not real!) Python shell it does work, it does even auto-complete, very nice!

Posted by Wolfram in Programming at 07:27
Comments (0)
Trackbacks (0)

Sunday, April 24. 2005

Article to be read: Scripting ...

This article "Scripting: Higher Level Programming for the 21st Century" sounds interesting.
Posted by Wolfram in Programming at 12:47
Comments (0)
Trackbacks (0)

Wednesday, April 20. 2005

Jump into Python, Part 1

Beforehand a huge thanks to Mark Pilgrim, his "Dive into Python" is a great starting point for programmers who want to learn Python. As an experienced programmer you can skip some stuff. But I read every single word, simply because I was scared to miss anything important. And sometimes the little side notes are most astonishing and worth being read.

Because I know that there is simply too much stuff in such a tutorial and that I forget exectly those that I wanted to remember, I've copy+pasted some stuff that I found interesting and that I felt would be good to have close at hand.

All the following are just quotes from http://diveintopython.org that simply feel good to read :-)

Good stuff

everything in Python is an object. Strings are objects. Lists are objects. Functions are objects. Even modules are objects.

indentation is a language requirement and not a matter of style

Python gives you an added incentive: the doc string is available at runtime as an attribute of the function

Python does not support in-line assignment, so there's no chance of accidentally assigning the value you thought you were comparing

A negative index accesses elements from the end of the list counting backwards. The last element of any non-empty list is always li[-1].

You can get a subset of a list, called a “slice”, by specifying two indices. li[0:3]

In Python, and and or perform boolean logic as you would expect, but they do not return boolean values; instead, they return one of the actual values they are comparing. This can really reduce the code size and the potential errors and and and ...

In Python 2.2 and later, you can inherit classes directly from built-in datatypes like dict

Good to know and to remember, because I am sure I will need to look that up

In a boolean context the following applies

  • 0 is false; all other numbers are true.
  • An empty string ("") is false, all other strings are true.
  • An empty list ([]) is false; all other lists are true.
  • An empty tuple (()) is false; all other tuples are true.
  • An empty dictionary ({}) is false; all other dictionaries are true.
  • The and-or trick, bool and a or b, will not work like the C expression bool ? a : b when a is false in a boolean context. Solution: (1 and [a] or [b])[0]
Lists
  • Lists can also be concatenated with the + operator. list = list + otherlist has the same result as list.extend(otherlist). But the + operator returns a new (concatenated) list as a value, whereas extend only alters an existing list. This means that extend is faster, especially for large lists.
  • li += ['two'] is equivalent to li.extend(['two']).
  • li = [1, 2] * 3 is equivalent to li = [1, 2] + [1, 2] + [1, 2]
Tuples
  • A tuple can not be changed in any way once it is created.
  • Tuples Have No Methods
  • You can't find elements in a tuple. Tuples have no index method.
  • Tuples are faster than lists.
  • Tuples can be used as keys in a dictionary (because they are immutable), so a tuple of lists can not be used!
  • (user,) - the comma is required when defining a tuple with one element

Strings

  • String formatting in Python uses the same syntax as the sprintf function in C.
  • join works only on lists of strings; it does not do any type coercion. Joining a list that has one or more non-string elements will raise an exception.
  • " ".join(s.split()) remove multiple white spaces and new lines, tabs etc. and replace by a single whitespace

Functions

  • in Python, arguments can be specified by name, in any order (i.e. info(a="x", b="y") or the same info(b="y", a="x"))
  • processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s) processFunc is now a function that collapses s if collapse is True

Any

  • In Python, you can use either == None or is None, but is None is faster.
  • In Java, you determine whether two string variables reference the same physical memory location by using str1 == str2. This is called object identity, and it is written in Python as str1 is str2. To compare string values in Java, you would use str1.equals(str2); in Python, you would use str1 == str2.
  • There are no constants in Python. Everything can be changed if you try hard enough.

Why?

Of course I have some questions. I guess all of them have been discussed already a hundered times in forums, anyway.

  • Why does an if, else and a def need a colon (:) at the end?
  • Why is deleting an element from a dictionary done by using a function del d[42] and why not d[42].del()? I thought everything was an object! d.clear() is also a method for clearing the dictionary ...
  • Slicing has nice shortcuts inside the brackets, why not allow li[] = 'new element' for appending a new element, instead of the append() method?
  • The mentioned tutorial says: "extend concatenates lists". Ok, so call it concat() instead of extend()! Geee.
  • Why does the first argument in every method have to be self? If Python would provide it by default one could save overhead and falling in the trap.
  • I read a couple of times: "... None, which is the Python null value." Why the hell is it not called Null?

I have not gotten through all the tutorial yet, but I will. And I will keep you informed about further complaints :-)

Posted by Wolfram in Programming at 13:13
Comment (1)
Trackbacks (0)
(Page 1 of 2, totaling 18 entries) » next page

Calendar

Back August '08
Mon Tue Wed Thu Fri Sat Sun
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Quicksearch

Categories

  • XML JavaScript
  • XML Mac stuff
  • XML Miscellaneous
  • XML Missing or not found
  • XML Music
  • XML Private
  • XML Programming


All categories

Archives

August 2008
July 2008
June 2008
Recent...
Older...

supersized.org

Owner login

supersized s9y blog hosting
Free s9y blog!

Disclaimer

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Top Referrers

www.google.com (8)
aenzioat.741.com (3)
bekaqkja.kogaryu.com (3)
machinegun.00freehost.com (3)
rettzemk.servetown.com (3)
www.google.ca (3)
www.google.co.uk (2)
www.google.com.pk (1)
www.google.de (1)
www.google.nl (1)

Top Exits

The owner of supersized.org is not responsible for any content on this page!