我看到人们一直在做的事情是:
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
super(ExcitingMan, self).say_hi() # Calling the parent version once done with custom stuff.
Run Code Online (Sandbox Code Playgroud)
我从未见过的人做的事情是:
class Man(object):
def say_hi(self):
print('Hello, World.')
class ExcitingMan(Man):
def say_hi(self):
print('Wow!')
return super(ExcitingMan, self).say_hi() # Returning the value of the call, so as to fulfill the parent class's contract.
Run Code Online (Sandbox Code Playgroud)
这是因为我和所有错误的程序员挂在一起,还是有充分的理由呢?
>> url = 'https://test.authorize.net/gateway/transact.dll'
>> data = {'x_login': 'abc123', 'x_type': 'AUTH_CAPTURE', 'x_card_num': '4444333322221103', 'x_amount': '50.75', 'x_tran_key
': 'abc123', 'x_version': '3.1', 'x_delim_char': '|', 'x_exp_date': '022012', 'x_delim_data': 'TRUE'}
>>
>> urllib2.urlopen(url, data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gateways\base.py", line 81, in dispatch
return gw_method(self, *args, **kwargs)
File "gateways\decorators.py", line 17, in wrapper
method(*args, **kwargs)
File "gateways\authorize_net.py", line 39, in auth_capture
return self.post_data(data)
File "gateways\authorize_net.py", line 43, in post_data
raw_response = urllib2.urlopen(self.get_endpoint(), data)
File "C:\Python26\lib\urllib2.py", line …
Run Code Online (Sandbox Code Playgroud) 模型上的字段foo = models.ForeignKey(Foo)
将自动为列添加数据库索引,以便更快地查找.这很好,但Django的文档没有说明模型元中的字段是否unique_together
接受相同的处理.我碰巧有一个模型,其中列出的一个char字段unique_together
需要一个快速查找索引.我知道db_index=True
在字段定义中添加副本不会有任何损害,但我很好奇.
让我先说,我也得到了同样的错误乳清定义启动__init__
和运行super()
的__init__
.我只将它简化为这个自定义方法,以查看错误是否仍然发生.
import HTMLParser
class Spider(HTMLParser):
"""
Just a subclass.
"""
Run Code Online (Sandbox Code Playgroud)
单独在模块中会引发以下错误:
Traceback (most recent call last):
File "D:\my\path\to\my\file
class Spider(HTMLParser):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
Run Code Online (Sandbox Code Playgroud) 我刚刚安装了GitStats,我就在那时我必须说,"现在,什么?".我在网站上看到了用户代码行等的示例,但没有关于如何获得这样简单统计数据的示例.我不需要图表或任何东西.我只是希望能够在一个用户列表中控制输出结果 - >代码行或其他东西.任何帮助深表感谢.
我不明白JSON RPC中的ID是什么.另外,在开发工具包时,考虑不使用JSON-RPC.org的标准有多糟糕?在JSON-RPC世界中似乎存在一些歧义.
PS我所指的ID是这里的ID:
{"params":["Hello","World"],"method":"hello_world","id":1}
Run Code Online (Sandbox Code Playgroud) 我浪费了一整天努力使用minimax算法来制作无与伦比的tictactoe AI.我一路上都错过了一些东西(大脑炒).
我不是在这里寻找代码,只是更好地解释我出错的地方.
from copy import deepcopy
class Square(object):
def __init__(self, player=None):
self.player = player
@property
def empty(self):
return self.player is None
class Board(object):
winning_combos = (
[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6],
)
def __init__(self, squares={}):
self.squares = squares
for i in range(9):
if self.squares.get(i) is None:
self.squares[i] = Square()
@property
def available_moves(self):
return [k for k, v in self.squares.iteritems() …
Run Code Online (Sandbox Code Playgroud) 如何更改jQuery对话框标题栏的背景颜色?
我看过themeroller但它似乎对我不起作用.
谢谢
我想知道,因为据我所知,CherryPy纯粹是用Python构建的,这显然比C等慢.这是否意味着它只适用于开发/测试环境,或者我可以在NGINX后面使用它,就像我目前使用Apache和Fast CGI一样?
在与同行讨论N + 1以及糟糕的数据库查询的严重性能影响后,我访问了http://guides.rubyonrails.org/active_record_querying.html.
ActiveRecord(Rails):
clients = Client.includes(:address).limit(10)
Run Code Online (Sandbox Code Playgroud)
在客户端具有地址的情况下,我打算在循环访问客户端时访问它们,Rails提供includes
让它知道继续并将它们添加到查询中,这样可以立即消除9个查询.
Django的:
https://github.com/lilspikey/django-batch-select提供批量查询支持.你知道其他库或技巧来实现上面提供的Rails,但是在一个不那么冗长的庄园中(如在rails示例中只有19个字符修复N + 1并且非常清楚)?另外,批量选择是以同样的方式解决问题,还是这两个不同的事情?
顺便说一句,我不是在问select_related
,虽然乍一看似乎是答案.我说的是address
有一个forign键的情况client
.