赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  103 随笔 :: 0 文章 :: 41 评论 :: 96617 阅读

03 2013 档案

摘要:1. python中的继承class Parent(object): def override(self): print "PARENT override()" def implicit(self): print "PARENT implicit()" def altered(self): print "PARENT altered()"class Child(Parent): def override(self): print "CHILD override()" def altered(self): ... 阅读全文
posted @ 2013-03-23 21:50 赵乐ACM 阅读(162) 评论(0) 推荐(0) 编辑

摘要:1. 今天学了一些概念。(书的第41~43章)用这个方法可以分清楚class、object、instance## Animal is-a object (yes, sort of confusing) look at the extra creditclass Animal(object): pass## Dog is-a animal, it has-a nameclass Dog(Animal): def __init__(self, name): ## ?? self.name = name## Cat is-a animal, it has-a ... 阅读全文
posted @ 2013-03-22 22:42 赵乐ACM 阅读(180) 评论(0) 推荐(0) 编辑

摘要:1. list相关的有一个比较有趣的问题,就是mystuff.append('hello'),python是怎么解释的。这里有段话讲的比较清楚,就不翻译了,直接贴过来。Python sees you mentionedmystuffand looks up that variable. It might have to look backwards to see if you created with=, look and see if it is a function argument, or maybe it's a global variable. Either 阅读全文
posted @ 2013-03-21 21:27 赵乐ACM 阅读(903) 评论(0) 推荐(0) 编辑

摘要:1. 整理python的关键字# _*_ coding:utf-8 _*_anddel #删除list中的某个元素或者这个list,同样适用于字典fromnotwhileaselifglobalorwith #http://www.cnblogs.com/Brogrammer/archive/2012/07/23/2605570.htmlassert #assert语句用来声明某个条件是真的。例如,如果你非常确信某个你使用的列表中至少有一个元素,而你想要检验这一点,并且在它非真的时候引发一个错误,那么assert语句是应用在这种情形下的理想语句。当assert语句失败的时候,会引发一个Asse 阅读全文
posted @ 2013-03-20 22:43 赵乐ACM 阅读(154) 评论(0) 推荐(0) 编辑

摘要:1. list比较熟悉了,但是list的函数们还不清楚,参考http://docs.python.org/2/tutorial/datastructures.html2. for和while经验是尽量少用while,因为while出错的机会大。3. 综合起来写的一个小程序from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" next = raw_input("> ") if "0" in next 阅读全文
posted @ 2013-03-19 18:27 赵乐ACM 阅读(297) 评论(0) 推荐(0) 编辑

摘要:1. Django如何新建一个网站python django-admin.py startproject mysite在mysite文件夹下会生成如下文件:mysite/ manage.py mysite/ settings.py urls.py __init__.py wsgi.py启动网站python manage.py runserverpython manage.py runserver 8080 #修改端口号,默认的是8000python manage.py runserver 0.0.0.0:8000 #告诉服务器... 阅读全文
posted @ 2013-03-18 21:13 赵乐ACM 阅读(1485) 评论(0) 推荐(0) 编辑

摘要:整理的一些符号(前三个在java和c中是不这样表达的,用&&、||、!表达)andornot!=(not equal)==(equal)>=(greater-than-equal)<=(less-than-equal)TrueFalseView Code # _*_ coding:utf-8 _*_print (True and False), Falseprint (False and True), Falseprint (1 == 1 and 2 == 1), Falseprint ("test" == "test"), 阅读全文
posted @ 2013-03-18 11:32 赵乐ACM 阅读(241) 评论(0) 推荐(0) 编辑

摘要:这个系列的博客是学习《Learn Python the Hard Way》中做的笔记。1. 由于今天需要看的five chapters是复习性质的内容,把前边的内容综合了一下,所以没有新内容只把代码贴在这View Code print "Let's practice everything."print "You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs."poem = """\t The lovely 阅读全文
posted @ 2013-03-18 00:14 赵乐ACM 阅读(755) 评论(0) 推荐(0) 编辑

摘要:1. 文件写操作文件写操作,需要在打开文件的时候添加参数,如open("filename", "w")以下是对文件操作的函数小结close -- Closes the file. Like File->Save.. in your editor.read -- Reads the contents of the file, you can assign the result to a variable.readline -- Reads just one line of a text file.truncate -- Empties the fil 阅读全文
posted @ 2013-03-16 12:10 赵乐ACM 阅读(251) 评论(0) 推荐(0) 编辑

摘要:1. python输入raw_input()函数。a = raw_input() #得到的是字符串a = int(raw_input()) #如果想得到int,只能这样如果输入特殊字符,比如\t \n等,会和输入一样输出,%r会输出\\t、\\n,%s会输出\t、\nView Code print "How old are you?"age = raw_input()print "How tall are you?"height = raw_input()print "How much do you weight?"weight = 阅读全文
posted @ 2013-03-15 22:33 赵乐ACM 阅读(867) 评论(0) 推荐(0) 编辑

摘要:1. String类型输出,看示例x = "There are %d types of people" % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s" % (binary, do_not)z = "Those who know %r and those who %r" % (binary, do_not)print xprint yprint zprint "I said 阅读全文
posted @ 2013-03-14 16:24 赵乐ACM 阅读(265) 评论(0) 推荐(0) 编辑

摘要:1. 脚本中写中文出现乱码,用以下可以解决。参考http://www.python.org/dev/peps/pep-0263/ # coding=<encoding name> #!/usr/bin/python # -*- coding: <encoding name> -*- #!/usr/bin/python # vim: set fileencoding=<encoding name> :2. 输出格式,先看代码my_name = 'Zed A. Shaw'print "Let's talk a... 阅读全文
posted @ 2013-03-13 23:28 赵乐ACM 阅读(393) 评论(0) 推荐(0) 编辑

摘要:1. 在页面上显示PHP的worning、notice等的代码error_reporting(E_ALL);ini_set("display_errors", TRUE); 2. 写php代码的时候,应该尽量避免调用函数,比如<?php if (...) { print "<b>hello</b>"; }?>应该写成<?php if (...) : ?> <b>hello</b><?php endif ?>这样就减少了函数调用,可以提高效率3. 如果遇到可能会出错的地方, 阅读全文
posted @ 2013-03-12 23:26 赵乐ACM 阅读(174) 评论(0) 推荐(0) 编辑

摘要:httpclient登录新浪微博(非SDK方式)分享此文章苦逼的折腾了快一星期,总算把新浪微博rsa加密登录折腾ok了,这里需要注意的是httpclient最好用4.0的,否则cookie管理很是问题。进入正题,最近新浪微博更新了sso登录方式,加密算法变成了rsa,获取nonce和servertime,pubkey,这里涉及到rsa加密,通常用java进行rsa加密一般都是从文件读取公钥信息或者是base64编码的公钥信息转换成key,然后进行加密,但是新浪给的不是base64加密,而是给的一个N(参见RSA加密算法,RSA加密算法),而我先入为主,把新浪给的pubkey当作base64编码 阅读全文
posted @ 2013-03-11 23:13 赵乐ACM 阅读(7638) 评论(0) 推荐(0) 编辑

摘要:1. 为什么给一个URL发送的http请求里会有host这一项Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3Accept-Encoding:gzip,deflate,sdchAccept-Language:zh-CN,zh;q=0.8Connection:keep-aliveCookie:************************Host:www.google.com.hkUser-Agent:Mozilla/5.0 ( 阅读全文
posted @ 2013-03-09 20:36 赵乐ACM 阅读(178) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示