我无法找到明确的答案.AFAIK,你不能__init__在Python类中拥有多个函数.那么我该如何解决这个问题呢?
假设我有一个Cheese使用该number_of_holes属性调用的类.我怎样才能有两种创建奶酪对象的方法......
parmesan = Cheese(num_holes = 15)number_of_holes属性:gouda = Cheese()我只想到一种方法来做到这一点,但这似乎有点笨重:
class Cheese():
def __init__(self, num_holes = 0):
if (num_holes == 0):
# randomize number_of_holes
else:
number_of_holes = num_holes
Run Code Online (Sandbox Code Playgroud)
你说什么?还有另外一种方法吗?
你如何在Python中获得两个变量的逻辑xor?
例如,我有两个我期望成为字符串的变量.我想测试只有其中一个包含True值(不是None或空字符串):
str1 = raw_input("Enter string one:")
str2 = raw_input("Enter string two:")
if logical_xor(str1, str2):
print "ok"
else:
print "bad"
Run Code Online (Sandbox Code Playgroud)
该^运营商似乎是按位,并在所有对象没有定义:
>>> 1 ^ 1
0
>>> 2 ^ 1
3
>>> "abc" ^ ""
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud) 我有一个Kronos入口点http://kronos../wfc/XmlService我应该能够访问但是当我在浏览器中打开它时,响应是:
<Kronos_WFC>
<Response Status="Failure" ErrorCode="1332" Message="WFP-01110 The MIME type of the request is invalid. Type Found: . Valid types: text/xml, application/xml."></Response>
</Kronos_WFC>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能使用网络服务?
顺便说一句,我正在使用C#与服务器通信.