Learn practical skills, build real-world projects, and advance your career
Created 2 years ago
import happybase
#create connection
connection = happybase.Connection('localhost', port=9090, autoconnect=False)
#open connection
def open_connection():
connection.open()
#close opened connection
def close_connection():
connection.close()
#create the table
def create_table(name, cf):
print 'creating table ' + name
tables = list_tables()
if name not in tables:
open_connection()
connection.create_table(name, cf)
close_connection()
print 'table created'
else:
print 'table already present'
def list_tables():
print "fetching all table"
open_connection()
tables = connection.tables()
close_connection()
print "all tables fetched"
return tables