Skip to content

Instantly share code, notes, and snippets.

View JackInTaiwan's full-sized avatar

Jack Cheng JackInTaiwan

View GitHub Profile
# -*- encoding: utf-8 -*-
import urllib2 as url2
from bs4 import BeautifulSoup
import re
import requests
#from vpython import * # !!! MUST import this,otherwise you're NOT allowed to use curve or others!!!
from visual import *
from visual.graph import *
res = list()
@JackInTaiwan
JackInTaiwan / py_convert.py
Created September 11, 2017 13:33
Python_convert science notation
def convert(num) :
num = str(num)
if ('e' in num):
index = num.index('e')
power = num[index+1::]
power = int(power)
num_num = num[:index]
output = '0.' + '0'*(abs(power)-1) + num_num
return (output)
else :
@JackInTaiwan
JackInTaiwan / python_advanced_private_1.py
Last active October 1, 2018 16:02
python_advanced_private_1
class Animal:
blood = True
__alive = True
print(Animal.blood)
# True
print(Animal.alive)
# Error: AttributeError: type object 'Animal' has no attribute 'alive'
print(Animal.__alive)
@JackInTaiwan
JackInTaiwan / python_advanced_private_3.py
Created October 1, 2018 16:57
python_advanced_private_3
class Animal:
def __init__(self):
self.__alive = True
self.__age = 0
def get_age(self):
return self.__age
def add_age(self):
self.__age += 1
@JackInTaiwan
JackInTaiwan / python_advanced_private_4.py
Created October 1, 2018 17:10
python_advanced_private_4
class Animal:
def __init__(self):
self.__alive = True
def __print_something(self):
print("shxt!!!")
dog = Animal()
@JackInTaiwan
JackInTaiwan / python_advanced_private_2.py
Last active October 2, 2018 14:27
python_advanced_private_2
class Animal:
def __init__(self, food):
self.blood = True
self.__alive = True
self.__food = food
def __say_something(self):
print("this tutorial is so long...")
def set_food(self, new_food):
class Shiba:
def __init__(self, height, weight):
self.height = height
self.weight = weight
@staticmethod
def pee(length):
print("pee" + "." * length)
class Shiba:
pee_length = 10
def __init__(self, height, weight):
self.height = height
self.weight = weight
@classmethod
def pee(cls):
print("pee" + "." * cls.pee_length)
class Shiba:
pee_length = 10
def __init__(self, height, weight):
self.height = height
self.weight = weight
@staticmethod
def pee():
print("pee" + "." * pee_length)
import abc
class Dog(metaclass=abc.ABCMeta):
@abc.abstractmethod
def eat_shit(self):
return NotImplemented
class Shiba(Dog):