Impressive obfuscated python code

This code snippet is again lay down on Mandelbrot Set, obfuscater favourite snip code

Okay, this is the python code with ASCII Mandelbrot art,

_                                      =   (
                               V       ,B,c
                             :c   and Y(V*V+B,B,  c
               (              2+c-4*abs(V)**-0.4)/i
                 )  ;v,      x=1500,1000;C=range(v*x
                  );import  struct;P=struct.pack;M,
            j  ='<QIIHHHH',open('M.bmp','wb').write
for X in j('BM'+P(M,v*x*3+26,26,12,v,x,1,24))or C:
            i  ,Y=_;j(P('BBB',*(lambda T:(T*80+T**9
                  *i-950*T  **99,T*70-880*T**18+701*
                 T  **9     ,T*i**(1-T**45*2)))(sum(
               [              Y(0,(A%3/3.+X%v+(X/v+
                             /x   -2.7,i)**2 for
                               A       in C
                                       )   )

try it if you dare :), it will full utilize your PC and will take about 15 minutes to render full anti-aliasing Mandelbrot image

You should get this image

What do you say? super cool isn’t it?

source :


Get Delta/Elapse time in Python with datetime

Do you remember when we were young, we used hours to time notions, “I’ll be there in an hour”, “It takes about half-hour”, “My mail will reach next week”. Oh my, week?! Well it did happen. Once upon a time.

we evolved to be impatient

We were talking about getting time with time python module which be fine for human. Now human need to keep up with machine, let’s keep up with them then, we are talking with milliseconds and microseconds now, we will use datetime.

import datetime

datetime.datetime(2012, 2, 17, 20, 29, 53, 567000)

uh, …, I will change it. Too much typing.

from datetime import datetime

startTime =

# do something fast! faster!

elapsedTime = – startTime
print elapsedTime.microseconds

Notice on microseconds, because Pyhton give in microseconds we can simply convert it to milliseconds with * 1000

What if things might takes in minutes, hours? for this we can utilize total_seconds(), divmod function, and print formating and come up with

[python smarttabs=”true”]
from datetime import datetime

startTime =

# do something fast! faster!

elapsedTime = – startTime

totSecs = elapsedTime.total_seconds()
theHours, reminder = divmod(totSecs, 3600)
theMins, reminder = divmod(reminder, 60)
theSecs, theMicroSec = divmod(reminder, 1)

print "action taken in %02d:%02d:%02d.%d" %
(theHours, theMins, theSecs, theMicroSec)

we can change microseconds to milliseconds depending on needs, but that’s the idea.

Get Delta/Elapse time in Python

How to get delta time in python? Python provide time module, as my favourite way to get delta / elapse time, of course, depends on what you need, to get simple hour-minute-seconds is what i usually do taking user normal actions, like time taken running scripts, batching, clicking buttons and navigate between tabs, or buttons.

import time

startTime = time.time()

# doing blah… blah…
# whatever actions we do in here

elapsedTime = time.gmtime(time.time() – startTime)
strTime = time.strftime("%H:%M:%S", elapsedTime)
print "action taken in %s" % strTime

Do you have a second?

Human usually only care about hour-minute-seconds, because it’s how we communicate right?
People use second to measure time, at least. “How long does it takes to backup?”, “Do you have a second?”, we talk in second, the smallest notion of time in daily human communication.

Pyhton time module works well for this purpose.

py2exe redistributable

In my works, I have been dealing with a lot of last minutes issue and request, it means that work will pop up, could be some calls, people approach me, email with urgent icon and marked as important because “the content inside telling you need to do something about it ASAP blah blah”, this just appear like hour before I wrapt my phone, bag, and lock my system.

Last week was different, none of that mentioned,
I come with self defence first
We had different mood, it was a holiday mood between the 25th and end of the year, two long weekend in row, time to clear leave, shutdown maybe, you can name it.

I was working on python application, and thou still far from complete, I need to get feedback on my application, as it right on track, match with the needs –it should be!-, the user interaction, and is this application should be dumb easy, so that I can make revision or whatever needed to make it back on tract in the way it’s intended to be.

I had the idea to make an executable with py2exe and installable packace so it’s easy to distribute, I will just sent the installer and anyone interested will.. obviously, double click, next, next, … they know the drill.

The mood, brought me back to procrastination habbit, or in a way it was a distraction I had in hand,
1. Somehow, i notice small thing -it always started with small thing- to improve and implement, and I though I can do that in, say 2 hours.
2. I’ve been doing the same packaging (executable and installer) in another small pyhton apps, it will be just 30 minutes job.
From here I go with the first point, and I did it, it was according to plan, I was taking my time actually.
Move to the next one, make executable, and … surprise, it just simply fail
error: MSVCP90.dll: No such file or directory
ck, typical

I fumbled on it for sometime and still couldn’t figure it out. Why! I’ve been doing it with other apps, and it was fine, was it because the fine working executable using Tk inter instead of my new WxPython gui library?
Too many disturbed questions in my head, anxious, and I know it will give me a hasty solution in return.
The clever solution, give up to figure it your own and just google it, and it’s end up in py2exe tutorial,
Providing the Microsoft Visual C runtime DLL
my my my …, It become I am the guy who didn’t Read The Fine Manual, I didn’t expect this way.
Hey, it didn’t give me problem with my other apps.

And I did according to the tutorial, prove it working, and celebrate a little about it. The next wiser action, pack my things and going home :), clear my mind and come with strategy, to find out more about the why, how and implement it carefully, neatly in the code.

I’m glad I did it right on the next day as it planned, just no unwanted surprise.