It is the primary time standard by which the world regulates clocks and time. To get current UTC time in Python, we can use
In : import datetime In : datetime.datetime.now(datetime.timezone.utc) Out: datetime.datetime(2014, 11, 22, 14, 42, 21, 34435, tzinfo=datetime.timezone.utc)
It is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds. To get Unix timestamp, we can use
In : import time In : time.time() Out: 1416667432.5664258 In : int(time.time()) Out: 1416667766
With Pyhon 3.4, we can directly get timestamp from UTC.
In : datetime.datetime.utcnow().timestamp() Out: 1416649608.58369
To convert Unix timestamp to UTC we can use
In : datetime.datetime.utcfromtimestamp(1416668401) Out: datetime.datetime(2014, 11, 22, 15, 0, 1)
To convert UTC time object to Unix time, we can use
In : dt = datetime.datetime.now() In : dt.strftime("%s") Out: '1416668938'
Alternatively, we can use
In : import calendar In : dt = datetime.datetime.utcnow() In : calendar.timegm(dt.utctimetuple()) Out: 1416669150
When using iPython, users can import required modules to test them. After importing them, if they get modified either by user or some other process, users have to reload it for futher usage.
Depending on the Python version, appropriate
reload function can reload modules.
# Python 2.x In : imp.reload(module) # Python 3.0–3.3 In : imp.reload(module) # Python 3.4+ In : importlib.reload(module)
Instead of manually reloading, ipython has
autoreload extention which can auto reload modules. For that, load the extention and activate it.
In : %load_ext autoreload In : %autoreload 2
This can be added to ipython config file so that autoreload gets activated, whenver it starts.
$ ipython profile create
This creates a default config file. Open config file which is present at
~/.ipython/profile_default/ipython_config.py and add these two lines to it.
c.InteractiveShellApp.extensions = ['autoreload'] c.InteractiveShellApp.exec_lines = ['%autoreload 2']
Note that it won't reloads c extensions automatically.
Synapse is a graphical launcher enabling you to start applications and also to quickly find and access relevant documents and files (by making use of the Zeitgeist engine).While I was searching for some good file managers, I came across Synapse. It has redefined how I interact with my system. Some reasons why I liked this.