Q:

Convert epoch timestamp to datetime.datetime object

I'd like to convert an epoch time stamp (eg, et =1351036517.179364) to a datetime.datetime object.  So far, I've used time.ctime(et) which gives me a string of something like "Fri Oct  5 22:20:33 2012 ". 
Eventually, I need the datetime object to compute time difference between two datapoints, the other datapoint is a datetime object as well.
Thanks! 

A:

It's worthwhile to remember that a timestamp has no associated timezone information.
Unix time is unambiguously UTC, but it's not unusual to store local time in Unix-style timestamps. You must check against a known reference to be sure.

If your timestamps are already in UTC (Unix time), you can use Marc B's suggestion of subtract two unix timestamps directly to give you the number of seconds of difference between them.
You may then want to create a timedelta, which will allow you to easily manipulate datetimes with it (you can sum or subtract a timedelta to/from a datetime, for example).
datetime.timedelta( seconds= n_seconds )

If your timestamps are in local time, don't subtract them directly, as you'll get potentially incorrect results. 
Instead, you should use datetime.fromtimestamp first, attach a timezone to each datetime, and only then subtract them to get the timedelta.
To convert back from a timedelta to the number of seconds, there's timedelta.total_seconds, assuming you're using python 2.7 . If you have an earlier version, you'll have to do the calculation by hand, or pip install datetime

