from xlrd import open_workbook import json import os os.chdir("d:/2018/mayank") book = open_workbook('demo.xlsx') sheet = book.sheet_by_index(0) # read header values into the list keys = [sheet.cell(0, col_index).value for col_index in range(sheet.ncols)] print ("keys are", keys) dict_list = [] for row_index in range(1, sheet.nrows): d = {keys[col_index]: sheet.cell(row_index, col_index).value for col_index in range(sheet.ncols)} dict_list.append(d) j = json.dumps(dict_list) with open('data.json', 'w') as f: f.write(j)
Install the module pip install cx_Oracle Import the module import cx_Oracle Establish the connection cn = cx_Oracle.connect('userid/password@servername') #rest commands are same as MySQL
The time module provides the current date and time using time() function The time.time() returns the number of second elapsed from 1/1/1970 12:00 am till current date and time called as ticks >>> import time >>> time.time() 1522211915.914467 We can also convert these ticks into actual date and time using function time.localtime() >>> time.localtime(time.time()) time.struct_time(tm_year=2018, tm_mon=3, tm_mday=28, tm_hour=10, tm_min=10, tm_sec=0, tm_wday=2, tm_yday=87, tm_isdst=0) It returns a structure having different fields for date and time which we can convert into date or time format >>> t=time.localtime(time.time()) >>> currentdate='%02d-%02d-%d' % (t.tm_mday,t.tm_mon,t.tm_year) >>> currentdate '28-03-2018' >>> currenttime='%02d-%02d-%02d' % (t.tm_hour,t.tm_min,t.tm_sec) >>> currenttime '10-12-05' We can also use this structure inside the functions and ...
Comments
Post a Comment