In [1]:
import time
In [2]:
time.time()
Out[2]:
In [3]:
time.time()
Out[3]:
In [4]:
for i in range(3):
print('Tick')
time.sleep(1)
print('Tock')
time.sleep(1)
In [5]:
time.sleep(5)
In [6]:
now = time.time()
In [7]:
now
Out[7]:
In [8]:
round(now, 2)
Out[8]:
In [9]:
round(now, 4)
Out[9]:
In [10]:
round(now)
Out[10]:
In [2]:
import datetime
In [12]:
datetime.datetime.now()
Out[12]:
In [13]:
dt = datetime.datetime.now()
In [14]:
dt.year, dt.month, dt.day
Out[14]:
In [15]:
dt.hour, dt.minute, dt.second
Out[15]:
In [16]:
datetime.datetime.fromtimestamp(1000000)
Out[16]:
In [17]:
datetime.datetime.fromtimestamp(time.time())
Out[17]:
In [18]:
halloween2015 = datetime.datetime(2015, 10, 31, 0 , 0, 0)
In [19]:
newyears2016 = datetime.datetime(2016, 1, 1, 0, 0, 0)
In [20]:
oct31_2015 = datetime.datetime(2015, 10, 31, 0, 0, 0)
In [21]:
halloween2015 == oct31_2015
Out[21]:
In [22]:
halloween2015 > newyears2016
Out[22]:
In [23]:
newyears2016 > halloween2015
Out[23]:
In [24]:
newyears2016 != oct31_2015
Out[24]:
In [25]:
delta = datetime.timedelta(days=11, hours=10, minutes=9, seconds=8)
In [26]:
delta.days, delta.seconds, delta.microseconds
Out[26]:
In [27]:
delta.total_seconds()
Out[27]:
In [28]:
11*24*3600 + 10*3600 + 9*60 + 8
Out[28]:
In [29]:
str(delta)
Out[29]:
In [30]:
dt = datetime.datetime.now()
In [31]:
dt
Out[31]:
In [33]:
thousandDays = datetime.timedelta(days=1000)
In [34]:
dt + thousandDays
Out[34]:
In [35]:
oct21st = datetime.datetime(2015, 10, 21, 16, 29, 0)
In [36]:
aboutThirtyYears = datetime.timedelta(days=365*30)
In [37]:
oct21st
Out[37]:
In [38]:
oct21st - aboutThirtyYears
Out[38]:
In [39]:
oct21st - (2 * aboutThirtyYears)
Out[39]:
In [45]:
halloween2016 = datetime.datetime(2016, 10, 31, 0, 0, 0)
In [46]:
while datetime.datetime.now() < halloween2016:
time.sleep(1)
In [40]:
oct21st = datetime.datetime(2015, 10, 21, 16, 29, 0)
In [42]:
oct21st.strftime('%Y/%m/%d %H:%M:%S')
Out[42]:
In [43]:
oct21st.strftime('%I:%M %p')
Out[43]:
In [44]:
oct21st.strftime('%B of %y')
Out[44]:
In [47]:
datetime.datetime.strptime('October 21, 2015', '%B %d, %Y')
Out[47]:
In [48]:
datetime.datetime.strptime('2015/10/21 16:29:00', '%Y/%m/%d %H:%M:%S')
Out[48]:
In [49]:
datetime.datetime.strptime("October of '15", "%B of '%y")
Out[49]:
In [50]:
datetime.datetime.strptime("November of '63", "%B of '%y")
Out[50]:
In [51]:
print("Cats", "Dogs", "Frogs", sep=" & ")
In [3]:
import threading
In [55]:
threadObj = threading.Thread(
target=print, args=["Cats", "Dogs", "Frogs"], kwargs={"sep":" & "})
In [56]:
threadObj.start()
In [4]:
import requests
In [5]:
import subprocess
In [6]:
subprocess.Popen("/usr/bin/gnome-calculator")
Out[6]:
In [7]:
calcProc = subprocess.Popen("/usr/bin/gnome-calculator")
In [9]:
calcProc.poll() == None
Out[9]:
In [10]:
calcProc.wait()
Out[10]:
In [11]:
calcProc.poll()
Out[11]:
In [14]:
subprocess.Popen(["/usr/bin/gedit", "/home/dario/temp.txt"])
Out[14]:
In [16]:
subprocess.Popen(["/usr/bin/python3", "hello.py"])
Out[16]:
In [17]:
fileObj = open("hello.txt", "w")
In [18]:
fileObj.write("Hello world!!!")
Out[18]:
In [19]:
fileObj.close()
In [23]:
subprocess.Popen(["gedit", "hello.txt"], shell=True)
Out[23]:
In [ ]: