speed_of_light = 299792458 billionth = 1.0 /1000000000 nanostick = speed_of_light * billion print nanostick
variable changes with faster processer, even in the same expression, divede by cycles_per_second.
speed_of_light = 299792458 cycles_per_second = 2700000000. # 2.7GHz cycle_distance = speed_of_light / cycles_per_second cycles_per_second = 2800000000. # 2.8GHz print(cycle_distance) cycle_distance = speed_of_light / cycles_per_second print(cycle_distance)
Finding Strings in strings
pythagoras = 'There is geometry in the humming of the string, there is music in the spacing of the spheres'
print(pythagoras.find('string'))
print(pythagoras[40:])
print(pythagoras.find('algebra'))
danton = "De l'audance, encore de l'audace, toujours de l'audace"
print(danton.find('audace'))
print(danton.find('audace', 0))
print(danton.find('audace', 5))
print(danton.find('audace', 6))
print(danton[6:])
link procedure
def get_next_target(page):
start_link = page.find('<a href=')
start_quote = page.find('"', start_link)
end_quote = page.find('"', start_quote + 1)
url = page[start_quote + 1:end_quote]
return url, end_quote
print(get_next_target('this is a <a href="www.yahoo.co.jp">link</a>'))
How to crawler get a link from webpages.
def print_all_links(page):
while True:
url, endpos = get_next_target(page)
if url:
print(url)
page = page[endpos:]
else:
break
print_all_links(get_page('http://yahoo.co.jp'))
find last position
def find_last(s, t):
last_pos = -1
while True:
pos = s.find(t, last_pos)
if pos == -1:
return last_pos
last_pos = pos