摘要:
获取一个字符串所有连续子串组成集合(set)的长度,居然是Facebook的interview题目,我也做出来了,哈哈:def get_all_substrings(string): length = len(string) alist = [] for i in xrange(length): for j in xrange(i,length): alist.append(string[i:j + 1]) return alistprint get_all_substring('abcde')不过感觉写的有点simple,问问stackoverflow:还是这样写比... 阅读全文
摘要:
问题症状和这里的类似,直接在SQL语句用%拼接string会出现OperationalError: (1054, "Unknown column 'XX' in 'where clause'")错误,使用2.6+版本的Python最好使用format方法,如下:SQL语句:run_sql.sql:create database name;create table just_id_and_name ( id integer primary key auto_increment, name varchar(200) not null);use n 阅读全文
摘要:
iframe页面和原本的页面传值方法实例,可以用于获取父页面和子页面的dom对象的值。parent.html: Home Page For Iframe This is for iframe To Get it. iframe.html: Iframe Home Page close iframe Add Element To Parent Page Get Parent Page Ele 在本地的Chrome浏览器无法使用,会出现安全错误。放在服务器上就行了。 阅读全文
摘要:
with语句一般用于文件打开,避免使用如下繁琐的格式:fd = Nonetry: fd = open("./hello.txt") for line in fd: print lineexcept Exception as e: print efinally: fd.close()使用with语句如下:with open("./hello.txt") as f: for line in f: print line其他更cool的用法,留到以后慢慢收集。 阅读全文