大约有 46,000 项符合查询结果(耗时:0.0323秒) [XML]
What is __main__.py?
What is the __main__.py file for, what sort of code should I put into it, and when should I have one?
5 Answers
...
What __init__ and self do on Python?
...
In this code:
class A(object):
def __init__(self):
self.x = 'Hello'
def method_a(self, foo):
print self.x + ' ' + foo
... the self variable represents the instance of the object itself. Most object-oriented languages pass this as a hidden p...
What are some (concrete) use-cases for metaclasses?
... Matplotlib. However, on occasion one wants to do interactive plotting. With only a couple functions I found that I was able to increment the figure count, call draw manually, etc, but I needed to do these before and after every plotting call. So to create both an interactive plotting wrapper and...
What is a “callable”?
Now that it's clear what a metaclass is , there is an associated concept that I use all the time without knowing what it really means.
...
Immutability of Strings in Java
...
str is not an object, it's a reference to an object. "Hello" and "Help!" are two distinct String objects. Thus, str points to a string. You can change what it points to, but not that which it points at.
Take this code, for example:
String s1 = "He...
Ignore python multiple return value
... -1: this "convention" sucks when you add gettext functionality to someone else's code (that defines a function called '_') so it should be banned
– nosklo
Jan 11 '09 at 13:32
...
How do I check OS with a preprocessor directive?
...need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this:
...
Is there a built-in function to print all the current properties and values of an object?
...
Print that dictionary however fancy you like:
>>> print l
['ArithmeticError', 'AssertionError', 'AttributeError',...
or
>>> from pprint import pprint
>>> pprint(l)
['ArithmeticError',
'AssertionError',
'AttributeError',
'BaseException',
'DeprecationWarning',
......
Purpose of Python's __repr__
...for end users.
A simple example:
>>> class Point:
... def __init__(self, x, y):
... self.x, self.y = x, y
... def __repr__(self):
... return 'Point(x=%s, y=%s)' % (self.x, self.y)
>>> p = Point(1, 2)
>>> p
Point(x=1, y=2)
...
How to return a value from __init__ in Python?
I have a class with an __init__ function.
10 Answers
10
...
