You are right, And ill tell you WHY this is. The script editor is global, so whatever you do in python or mel inside the script editor it gets to be global. Your module is not global. And the mel you evaluate is not global it is as if you were typing:
global dirpath
dirpath = "C:\Documents and Settings\3d\My Documents\maya\projects\default\scenes"
maya.mel.eval (' global $dirpath; $dirpath= python ("dirpath") ')
maya.mel.eval (' setProject $dirpath; ')
Which i must say is a EXTREMELY bad idea!
now then about calling this wouldn't it just be easier to do the following:
dirpath = "C:\Documents and Settings\3d\My Documents\maya\projects\default\scenes"
maya.mel.eval (' setProject '+dirpath )
It would save you a lot of code and 2 times polluting the global namespace.
FYI:
Actually it seems you dont know this. As its not a command its a procedure, you can actually do exactly the same thing in python, see if you lookat what the mel command does is is jut basically calls the:
workspace -o $path;
with a lot of safeguards, and gui updates. But you can do this all without the hooks in in python too with:
dirpath = "C:\Documents and Settings\3d\My Documents\maya\projects\default\scenes"
cmds.workspace( dirpath , o=True )