This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name v2NewReply | |
// @namespace http://bazqux.com?me=fdsfwf | |
// @include http://*.v2ex.com/my/topics* | |
// @include http://v2ex.com/my/topics* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function xpath(query){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import math | |
print "2/2=1 == " , 2/2 | |
print "3/2=1.5 == " , 3/2 | |
print "6/5=1.2 == " , 6/5 | |
print "1.2/10=0.12 == " , 1.2/10 | |
print "1.2/0.01=120 == " , 1.2/0.01 | |
print "1.0/1.0=1 == " , 1.0/1.0 | |
print "-------取小数-------" # 据说 P3 可以直接取小数 , P2 规则是整数相除得出整数 | |
print "float(3/2)=1.5 == " , float(3/2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script , user_name = argv | |
prompt = '>' | |
print "Hi %s , I'm the %s script." % (user_name , script) | |
print "I'd like to ask you a few questions." | |
print "Do you like me %s?" % user_name | |
likes raw_input(prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nose.tools import * | |
import sys | |
sys.path.append("../ex48") | |
from ex48.main import lexicon | |
def test_directions(): | |
assert_equal(lexicon.scan("north"), [('direction', 'north')]) | |
result = lexicon.scan("north south east") | |
assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east')]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class lexicon(object): | |
direction = ['north', 'south' , 'east' , 'west', 'down', 'up', 'left', 'right', 'back'] | |
verb = ['go' , 'stop' , 'kill' , 'eat'] | |
stop = ['the' , 'in' , 'of' , 'from', 'at' , 'it'] | |
noun = ['door' , 'bear' , 'princess', 'cabinet'] | |
finalList = [] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nose.tools import * | |
import nose | |
import sys | |
sys.path.append("../ex47") | |
from ex47.game import Room | |
def test_room(): | |
gold = Room("GoldRoom", | |
"""This room has gold in it you can grab. There's a | |
door to the north.""") | |
assert_equal(gold.name, "GoldRoom") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Room(object): | |
def __init__(self , name , description): | |
self.name = name | |
self.description = description | |
self.paths = {} | |
def go(self , direction): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:UTF-8 | |
from nose.tools import * | |
import nose | |
import sys | |
sys.path.append("../ex47") # 把 这个文件的上级目录的 ex47 加下 python 的模组 索引路径目录 | |
from ex47.game import Room # 把 ex47这个文件夹下的 game.py 里的 Room 类导入进来 | |
def test_room(): | |
gold = Room("GoldRoom", | |
"""This room has gold in it you can grab. There's a | |
door to the north.""") # 创建一个 Room 类的对象 gold , 参数1表示name 2表示description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$json = json_decode($_POST['data']); | |
for($i=0;$i<sizeof($json->items);$i++) | |
$json->items[$i]->description = strtoupper($json->items[$i]->description); | |
header('Content-Type: application/json'); | |
print json_encode($json); | |
?> |