Thursday, January 18, 2018

flask alembic sqlalchemy make base model using cls.__name__ to table name

from collections import OrderedDict
from flask import json, jsonify

from sqlalchemy import func, text
from sqlalchemy import Boolean, Column, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declared_attr

from app import db


class CoreModel(db.Model):
__abstract__ = True

# __tablename__ = name_model as name
@declared_attr
def __tablename__(cls):
cn = cls.__name__.lower()
_i = cn.rfind('_')
if _i > 0:
return cn[:_i]
else:
return cn

# model as dict
def as_dict(self):
result = OrderedDict()
for key in self.__mapper__.c.keys():
result[key] = getattr(self, key)
return result

def addme(self):
db.session.add(self)

@classmethod
def commit(self):
db.session.commit()

def save(self):
db.session.add(self)
db.session.commit()
return self

def delete(self):
db.session.delete(self)
db.session.commit()


class BaseModel(CoreModel):
__abstract__ = True

id = db.Column(db.Integer, primary_key=True)
created_at = db.Column(db.TIMESTAMP)
modified_at = db.Column(db.TIMESTAMP)
deleted = db.Column(db.Boolean, nullable=False, default=False)

@classmethod
def get_first(self):
return self.query.order_by(self.id.asc()).first()

@classmethod
def get_last(self):
return self.query.order_by(self.id.desc()).first()

@classmethod
def get_list_all(self):
lst = []
for item in self.query.order_by(self.id.asc()).all():
lst.append(item.as_dict())
return lst


class FullBaseModel(BaseModel):
__abstract__ = True

created_ip = db.Column(db.String(length=50))
created_by = db.Column(db.Integer, db.ForeignKey('user.id'))
modified_ip = db.Column(db.String(length=50))
modified_by = db.Column(db.Integer, db.ForeignKey('user.id'))
ordering = db.Column(db.Integer, nullable=False, default=0)

python flask json jsonify convert json string object

from flask import jsonify, json
try:
# Initialize a employee list
employeeList = []

# create a instances for filling up employee list
for i in range(0, 2):
empDict = {
'firstName': 'Roy',
'lastName': 'Augustine'
}
employeeList.append('adsf')

# convert to json data
jsonStr = json.dumps(employeeList)
jsonObj = json.loads(jsonStr)
print(jsonObj)
# print(jsonify(Employees=jsonStr))
except Exception as e:
print(str(e))

Wednesday, January 17, 2018

python __repr__ vs __str__ and cast variable, isinstance tuple vs list, dict for repr(), str(), int(), eval(code or string)

class Point3D(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

def __repr__(self):
return str(self.z)

def __str__(self):
return "(%s, %s, %s)" % (self.x, self.y, self.z)


my_point = Point3D(1, 2, 3)
print(my_point)
v = str(repr(my_point))
b = isinstance(v, str)
if b:
v1 = int(v) + 1
s = str(v1) + ';'
print(s)
else:
print(b, ";")

print(isinstance(('a', 'b'), tuple))
print(isinstance(['a', 'b'], list))

dic = {'abc': 'abc', 'def': {'a1': 'a1v', 'a2': 'a2v'}}
for elem in dic.values():
if isinstance(elem, dict):
for ndx, item in elem.items():
print(ndx, ' => ', item, 'is ')
for i in item:
print(i)

Monday, January 15, 2018

existing source folder force set-upstream from local repository to bitbucket repository

existing source folder force set-upstream from local repository to bitbucket repository

git remote add origin https://user@bitbucket.org/maths-team/maths-repo.git

git remote -v

git fetch origin

#force remove all commits and init first commit
touch initial

#stagin the changes
git add .gitignore or .vscode

git commit -m "chagnes"

git push -u origin master

git push --force --set-upstream origin master

python flask alembic engine sqlalchemy db instance with models example

from sqlalchemy import func, text
from sqlalchemy import Boolean, Column, Integer, \
    String, ForeignKey

from app import db


# Set up user_loader
# @login_manager.user_loader
# def load_user(user_id):
#    return User.query.get(int(user_id))


class Node(db.Model):
    __tablename__ = 'node'
    id = Column(Integer(), primary_key=True)
    name = Column(String(200))
    parent_id = Column('parent_id', Integer())
    lft = Column('lft', Integer())
    rgt = Column('rgt', Integer())
    deleted = Column('deleted', Boolean, default=False)

    def __init__(self, name, parent_id, lft, rgt):
        self.name = name
        self.parent_id = parent_id
        self.lft = lft
        self.rgt = rgt

    @classmethod
    def saveAsRoot(self, name):
        cut = self.getLowerBound() + 1
        node = self(name, 0, cut, cut + 1)
        db.session.add(node)
        db.session.commit()
        self.preOrder(self, 0, 0)
        return node

    def addNodeChild(self, parent_id, node_name):
        node = self(node_name, parent_id, None, None)
        db.session.add(node)
        db.session.commit()
        self.preOrder(self, 0, 0)
        return node

    def preOrder(self, parent, left):
        right = left + 1
        result = Node.query.filter_by(parent_id=parent)

        for r in result:
            right = self.preOrder(self, r.id, right)

        n = Node.query.get(parent)
        if n:
            n.lft = left
            n.rgt = right
            db.session.commit()

        return right + 1

    def getLowerBound():
        data = db.session.query(func.max(Node.rgt)).scalar()
        if data:
            return data
        return 1

    def path(id):
        sql = text(
            'SELECT parent.name FROM node AS n, node AS parent WHERE n.lft BETWEEN parent.lft AND parent.rgt AND n.id = :id ORDER BY parent.lft;')
        result = db.engine.execute(sql, {'id': id})
        names = []
        for row in result:
            names.append(row[0])
        return ">".join(names)


class Goods(db.Model):
    __tablename__ = 'goods'
    id = Column(Integer(), primary_key=True)
    sku = Column(String(200))
    name = Column(String(200))
    unit = Column(String(20))
    photo_path = Column(String(255))
    node_id = Column('node_id', Integer(), ForeignKey('node.id'))
    deleted = Column('deleted', Boolean, default=False)


class Company(db.Model):
    __tablename__ = 'company'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), index=True, unique=True)
    phone = db.Column(db.String(60), index=True)
    email = db.Column(db.String(60), index=True)
    address = db.Column(db.Text)
    deleted = db.Column(db.Boolean, default=0)
    company_type = Column(String(20))


class Zone(db.Model):
    __tablename__ = 'zone'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), index=True, unique=True)
    deleted = db.Column(db.Boolean, default=0)

    @classmethod
    def allArray(self):
        zones = []
        for n in Zone.query.all():
            zones.append({'id': n.id, 'name': n.name})
        return zones


class Settings(db.Model):
    __tablename__ = 'settings'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), index=True, unique=True)
    settings_key = db.Column(db.String(60), index=True, unique=True)
    value = db.Column(db.Text, index=True, unique=True)
    deleted = db.Column(db.Boolean, default=0)


class Location(db.Model):
    __tablename__ = 'location'
    id = Column(Integer(), primary_key=True)
    name = Column(String(200))
    parent_id = Column('parent_id', Integer())
    lft = Column('lft', Integer())
    rgt = Column('rgt', Integer())
    zone_id = db.Column(db.Integer, db.ForeignKey('zone.id'))
    deleted = Column('deleted', Boolean, default=False)

    def __init__(self, name, parent_id, lft, rgt, zone_id):
        self.name = name
        self.parent_id = parent_id
        self.lft = lft
        self.rgt = rgt
        self.zone_id = zone_id

    @classmethod
    def saveAsRoot(self, name):
        cut = self.getLowerBound() + 1
        node = self(name, 0, cut, cut + 1, None)
        db.session.add(node)
        db.session.commit()
        self.preOrder(self, 0, 0)
        return node

    def addNodeChild(self, parent_id, node_name):
        node = self(node_name, parent_id, None, None, None)
        db.session.add(node)
        db.session.commit()
        self.preOrder(self, 0, 0)
        return node

    def preOrder(self, parent, left):
        right = left + 1
        result = Location.query.filter_by(parent_id=parent)

        for r in result:
            right = self.preOrder(self, r.id, right)

        n = Location.query.get(parent)
        if n:
            n.lft = left
            n.rgt = right
            db.session.commit()

        return right + 1

    def getLowerBound():
        data = db.session.query(func.max(Location.rgt)).scalar()
        if data:
            return data
        return 1

    def path(id):
        sql = text(
            'SELECT parent.name FROM location AS n, location AS parent WHERE n.lft BETWEEN parent.lft AND parent.rgt AND n.id = :id ORDER BY parent.lft;')
        result = db.engine.execute(sql, {'id': id})
        names = []
        for row in result:
            names.append(row[0])
        return ">".join(names)

    def map(cls):
        sql = text(
            'SELECT parent.name FROM location AS n, location AS parent WHERE n.lft BETWEEN parent.lft AND parent.rgt AND n.id = :id ORDER BY parent.lft;')
        result = db.engine.execute(sql, {'id': cls.id})
        names = []
        for row in result:
            names.append(row[0])
        return ">".join(names)

    def toTree(self):
        nodes = Location.query.filter_by(parent_id=0)
        tree = []
        for n in nodes:
            tree.append({'id': n.id, 'name': n.name, 'parent_id': n.parent_id, 'zone_id': n.zone_id,
                         'children': self.TReverse(self, n)})
        return tree

    def TReverse(self, node):
        nodes = Location.query.filter_by(parent_id=node.id)
        if nodes == None:
            return []
        tree = []
        for n in nodes:
            tree.append({'id': n.id, 'name': n.name, 'parent_id': n.parent_id, 'zone_id': n.zone_id,
                         'children': self.TReverse(self, n)})
        return tree


class Seller(db.Model):
    __tablename__ = 'seller'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120))
    email = db.Column(db.String(120))
    phone = db.Column(db.String(120))
    address = db.Column(db.Text)
    company_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    company = db.relationship('Company')
    location = db.relationship('Location')
    users = db.relationship('User', secondary='seller_user')
    deleted = db.Column(db.Boolean, default=0)

    @classmethod
    def covarage_area(cls, id):
        return SellerLocationCoverage.query.filter_by(seller_id=id, is_active=1)


class Buyer(db.Model):
    __tablename__ = 'buyer'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120))
    email = db.Column(db.String(120))
    phone = db.Column(db.String(120))
    fax = db.Column(db.String(120))
    address = db.Column(db.Text)
    company_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    deleted = db.Column(db.Boolean, default=0)
    users = db.relationship('User', secondary='buyer_users', backref=db.backref('buyers', lazy='dynamic'))

    @classmethod
    def company(self, buyer):
        if buyer.company_id:
            return Company.query.get(buyer.company_id).name
        return "---"


class BuyerUser(db.Model):
    __tablename__ = 'buyer_users'
    id = db.Column(db.Integer, primary_key=True)
    buyer_id = db.Column(db.Integer, db.ForeignKey('buyer.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))


class SellerLocationCoverage(db.Model):
    __tablename__ = 'seller_coverage_area'
    id = db.Column(db.Integer, primary_key=True)
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    start_at = db.Column(db.DateTime)
    ends_at = db.Column(db.DateTime)
    is_active = db.Column(db.Boolean, default=1)
    location = db.relationship('Location')


class CompanyBranch(db.Model):
    __tablename__ = "company_branch"
    id = db.Column(db.Integer, primary_key=True)
    company_id = db.Column(db.Integer, db.ForeignKey('company.id'))
    location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    company = db.relationship('Company')
    location = db.relationship('Location')

    branch_name = db.Column(db.String(120))
    phone = db.Column(db.String(120))
    address = db.Column(db.String(200))
    contact = db.Column(db.String(200))
    deleted = db.Column(db.Boolean, default=0)


class SellerUser(db.Model):
    __tablename__ = "seller_user"
    id = db.Column(db.Integer, primary_key=True)
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    seller = db.relationship('Seller')
    user = db.relationship('User')

    def __init__(self, seller_id, user_id):
        self.seller_id = seller_id
        self.user_id = user_id

    def __repr__(self):
        return '<SellerUser {} {}>'.format(self.seller_id, self.user_id)

    def __str__(self):
        return self.id


class SellerGoods(db.Model):
    __tablename__ = "seller_goods"
    id = db.Column(db.Integer, primary_key=True)
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    seller = db.relationship('Seller')
    goods = db.relationship('Goods')
    price = db.Column(db.Integer)

    @classmethod
    def seller_goods_discount(cls, goods, seller):
        result = db.session.execute(text('SELECT sd.* FROM seller_discount sd '
                                         'INNER JOIN seller_goods_discount sgd ON sgd.seller_discount_id = sd.id '
                                         'WHERE sd.seller_id=:seller and sgd.goods_id=:goods and now() BETWEEN  start_at and ends_at'),
                                    {'seller': seller,
                                     'goods': goods})
        return result


class SellerDiscount(db.Model):
    __tablename__ = "seller_discount"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    discount_type = db.Column(db.String(200))
    discount_amount = db.Column(db.Float)
    start_at = db.Column(db.DateTime)
    end_at = db.Column(db.DateTime)
    is_active = db.Column(db.Boolean)
    seller_id = db.Column(db.Integer, db.ForeignKey('Seller.id'))


class SellerGoodsDiscount(db.Model):
    __tablename__ = "seller_goods_discount"
    id = db.Column(db.Integer, primary_key=True)
    seller_discount_id = db.Column(db.Integer, db.ForeignKey('seller_discount.id'))
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    for_buyer_id = db.Column(db.Integer, db.ForeignKey('buyer.id'))
    discount = db.relationship('SellerDiscount')


class GoodsPrice(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    seller = db.relationship('Seller')
    goods = db.relationship('Goods')
    price = db.Column(db.Integer)
    start_data = db.Column(db.DateTime)
    end_data = db.Column(db.DateTime)


class Order(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order_number = db.Column(db.String(20))
    total_price = db.Column(db.Float)
    total_discount = db.Column(db.Float)
    status = db.Column(db.String(20))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))


class OrderItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Integer)
    unit_price = db.Column(db.Float)
    total_price = db.Column(db.Float)
    total_discount = db.Column(db.Float)
    total = db.Column(db.Float)
    status = db.Column(db.String(20))
    order_id = db.Column(db.Integer, db.ForeignKey('order.id'))
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    seller_goods_id = db.Column(db.Integer, db.ForeignKey('seller_goods.id'))


class OrderItemDiscount(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    seller_goods_discount_id = db.Column(db.Integer)
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    seller_id = db.Column(db.Integer, db.ForeignKey('seller.id'))
    disconut_type = db.Column(db.String(200))
    disconut_amount = db.Column(db.Float)

Wednesday, January 10, 2018

python class inherit from parent class that super(SelfClassType, self) __init__ or __class__

#The first is used to initialise newly created object, and receives arguments used to do that:
class Input(object):
def __init__(self, x, y):
self.x = x
self.y = y
print("Input inited x=%d, y=%d" % (self.x, self.y))

def __call__(self, a):
self.x = self.x + a
print(self.x, self.y)


class AInput(Input):
input_type = 'password'

def __init__(self, hide_value=True):
self.hide_value = hide_value
super(AInput, self).__init__(5, 10)
print("AInput inited")

def __call__(self, field):
return super(AInput, self).__call__(field)


a = AInput()# __init__

#The second implements function call operator.
a(2)# __call__

Tuesday, January 9, 2018

create, push, view bitbucket branches

Before creating a new branch, pull the changes from upstream. Your master needs to be up to date.
Create the branch on your local machine and switch in this branch :
$ git checkout -b [name_of_your_new_branch]
Change working branch :
$ git checkout [name_of_your_new_branch]
Push the branch on github :
$ git push origin [name_of_your_new_branch]
When you want to commit something in your branch, be sure to be in your branch. Add -u parameter to set upstream.
You can see all branches created by using :
$ git branch
boroo@homework MINGW64 /d/Projects/Python.Projects/maths (branch1)
$ git commit -m "change by branch1"
[branch1 f493b16] change by branch1
 1 file changed, 1 insertion(+), 3 deletions(-)

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (branch1)
$ git push
fatal: The current branch branch1 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin branch1


boroo@homework MINGW64 /d/Projects/Python.Projects/maths (branch1)
$ git push --set-upstream origin branch1
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote:
remote: Create pull request for branch1:
remote:   https://bitbucket.org/maths-team/maths-repo/pull-requests/new?source=branch1&t=1
remote:
To https://bitbucket.org/maths-team/maths-repo.git
   221deea..f493b16  branch1 -> branch1
Branch 'branch1' set up to track remote branch 'branch1' from 'origin'.

added or changed files push to bitbucket repository

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git add init_bitbucket_repo_example.txt

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git commit -m 'add one txt file'
[master d739c57] add one txt file
 1 file changed, 27 insertions(+)
 create mode 100644 init_bitbucket_repo_example.txt

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git push --set-upstream origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 737 bytes | 737.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://bitbucket.org/maths-team/maths-repo.git
   2b33be7..d739c57  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git commit -m 'change main'
[master 221deea] change main
 2 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 .vscode/launch.json

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.27 KiB | 1.27 MiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To https://bitbucket.org/maths-team/maths-repo.git
   d739c57..221deea  master -> master

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$

first time push my vscode project into empty bitbucket repository using bash command

boroo@homework MINGW64 /d/Projects/Python.Projects/maths
$ git init
Initialized empty Git repository in D:/Projects/Python.Projects/maths/.git/

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git add *

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git commit -m "Initial Commit"
[master (root-commit) 2b33be7] Initial Commit
 1 file changed, 9 insertions(+)
 create mode 100644 main.py

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$ git remote add origin https://boroobaldka@bitbucket.org/m
aths-team/maths-repo.git

boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)To https://bitbucket.org/maths-team/maths-repo.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
boroo@homework MINGW64 /d/Projects/Python.Projects/maths (master)
$

Monday, January 8, 2018

python dictionary datatypes features

x = {1:2, 'hello': 'boroo'}
print x

y = 'world'
x.update({'x':y})
x['y'] = 'yeald'
print x['x']
print x

python list append, pop, unshift, shift, deque object insert appendleft clear copy extendleft

from collections import deque
a = [1,2,3,4,5]
a.append(6)
print a
print a.pop()
#['a'] = 'b'
a = ([10] + a + [11]) # Unshift / Push
print a
a = a[:6] # Shift / UnPush
print a, ';;;;;;;;;'
print a.pop(5)
del a[:3]
print a
print deque(a).popleft()



result::::::::::::::::::::::::::
PS D:\Projects\Python.Projects\maths> python main.py
[1, 2, 3, 4, 5, 6]
6 [10, 1, 2, 3, 4, 5, 11] [10, 1, 2, 3, 4, 5] ;;;;;;;;;
5
[3, 4] 3 PS D:\Projects\Python.Projects\maths>

python decimal,float,rmax,min,ound,sorted,sum,int

from decimal import *
getcontext().prec = 4
print Decimal(1) / Decimal(7)
formatted = Decimal('0.142857')
print formatted
#getcontext().prec = 28
print Decimal('0.1428571428571428571428571429')
print Decimal('NaN')
print (Decimal('-Infinity') == '-Infinity')

data = map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())
print max(data)
print min(data)
print sorted(data)
print sum(data)
#Decimal('19.29')
a,b,c,d = data[:4]
print str(a), str(b), str(c), str(d)
#'1.34 1.87 3.45 2.35'
print float(a)
#1.34
print round(a, 1) # round() first converts to binary floating point
#1.3
print int(a)
#1
print (a * 5)
#Decimal('6.70')
print (a * b)
#Decimal('2.5058')
print (c % a)
#Decimal('0.77')
print Decimal(9).sqrt()
#3
print Decimal(3).exp()
#20.09
print Decimal('10').log10()
#1

result:::::::::::::::::::::::::::::::::::

PS D:\Projects\Python.Projects\maths> python main.py 0.1429 0.142857 0.1428571428571428571428571429NaNFalse9.25 0.03 [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'), Decimal('2.35'), Decimal('3.45'), Decimal('9.25')] 19.29 1.34 1.87 3.45 2.35 1.34 1.3 1 6.70 2.506 0.77320.09 1 PS D:\Projects\Python.Projects\maths>

python list Iterables, Generators, Yield

#
import time

start = time.clock()
mylist = [(x * x) for x in range(3000000)]
for i in mylist:
pass
stop = time.clock()
print stop-start


start = time.clock()
mygenerator = (x * x for x in range(3000000))
for i in mygenerator:
pass
stop = time.clock()
print stop-start


start = time.clock()
def createGenerator():
mylist = range(3000000)
for i in mylist:
yield i * i

mygenerator = createGenerator() # create a generator
#print(mygenerator) # mygenerator is an object!
for i in mygenerator:
pass
stop = time.clock()
print stop-start
#
#


value = raw_input()


def p_arr(str):
arr = str.split(',')
count = len(arr)
for item in arr:
print item
return count


print str(p_arr(value)) + ";;;"


result::::::::::::::
PS D:\Projects\Python.Projects\maths> python main.py 0.92048384 0.706350506667 0.705092266667 bor bor 1;;; PS D:\Projects\Python.Projects\maths>