def __init__(self, x):
     p("A.__init__ called")
     self.x = x
from ut import p
from fractions import *

F = Fraction
p("Fraction")
fr1 = F('0.2')
print fr1
print fr1.numerator
print fr1.denominator

p("num/den")
fr1 = F(2, 10)
print fr1
print fr1.numerator
print fr1.denominator

p('from float')
print Fraction.from_float(0.2)
#!/usr/bin/python

import copy

from ut import p


class A(object):
    
    def __init__(self, x):
        p("A.__init__ called")
        self.x = x


p("OBJECT DIRECT ASSIGNMENT")
ob1 = A(10)
ob2 = ob1

p("OB1 and OB2 ID's")
print id(ob1), id(ob2)
assert(id(ob1) == id(ob2))

p("INITIAL OB*.X")
print ob1.x, ob2.x

p("ALTERED OB*.X")
ob1.x = 33
print ob1.x, ob2.x

p("OB's SHALLOW COPY")
ob3 = copy.copy(ob1)
예제 #4
0
        while True:
            divisor = next(counter)

            if divisor >= current_dividend:
                no_more_divisors = True
                factors.append(divisor)
                break

            if current_dividend % divisor == 0:
                current_dividend //= divisor
                factors.append(divisor)
                break

        if no_more_divisors:
            break

    return set(factors)


def show_it(n: int) -> None:
    factors = sorted(prime_factors(n))
    print(f"{n} -> {factors} | {max(factors)}")


p("Prime factors")

show_it(8)
show_it(13195)
show_it(600851475143)
from ut import p
from functools import *

p("partial")

def myf(x, y):
	print x+y

myfp = partial(myf, y=3)
myfp(10)



def dec1(f):
	def wrapper():
		f()

	return wrapper

print "\n"
p("update_wrapper")

def dec2(f):

	def wrapper():
		f()

	wrapper = update_wrapper(wrapper, f)
	return wrapper

def somef2():
from ut import p

p("all")

print all([True, True, False])
print all([True, True, True])

p("any")

print any([0, 0])
print any([0, 1])
print any([1, 1])

p("any exclusive")

def anyex(itb):
	return any(itb) and not all(itb)

print anyex([0, 0])
print anyex([0, 1])
print anyex([1, 1])

p("bin")
print bin(5)

p("bytearray")
print bytearray(100)

p("callable")

print callable(p)
from ut import p
from random import *

p("randint")
print randint(10, 20)
print randint(10, 20)
print randint(10, 20)

p("random")
print random()
print random()
print random()

p("choice")
print choice([222,333,444,555])

p("shuffle")
lst = [1,2,3,4]
shuffle(lst)
print lst
from ut import p
from pickle import *

class A(object):

	def __init__(self):
		self.a = 20
		self.b = 30

	# def __str__(self):
	# 	return "zafuk"

p("DUMPS")
a = A()
pa = dumps(a)
a2 = loads(pa)

print a2.a
print a2.b