Tagged Questions
8
votes
5answers
1k views
__init__ as a constructor?
Dive into Python -
It would be tempting but incorrect to
call this the constructor of the
class. It's tempting, because it looks
like a constructor (by convention,
__init__ is the first ...
3
votes
1answer
74 views
What is this use of __init__ for?
I'm fairly new to python and I'm reading a book about creating games with pygame. I came across this piece of code in the book. I don't understand why Sprite.__init__(self) is necessary. I have run ...
0
votes
2answers
48 views
Initialise several variables at once to the same object but different instances
What is the cleanest way of initialising several objects the same way, without making them all point to the same object? I want to do this:
a, b, c = create_object(), create_object(), create_object()
...
3
votes
2answers
94 views
How to initialize nested dictionaries in Python
I'm using Python v2.7 dictionaries, nested one inside another like this:
def example(format_str, year, value):
format_to_year_to_value_dict = {}
# In the actual code there are many format_str and ...
1
vote
2answers
60 views
Initializing superclasses in Python
I'm learning Python. At the moment, I can do what I want to do by composition, but when I try to do the same thing using inheritance, I get an error. Here's my code. I'm basically trying to make a ...
-1
votes
1answer
35 views
python : instantiation of object
class Team :
def __init__(self):
print "object instantiated"
To create an object of Team class,
>>> obj = Team()
object instantiated
From obj I can access member of Team ...
6
votes
1answer
76 views
What is a wrapper_descriptor, and why is Foo.__init__() one in this case?
import inspect
class Foo(object):
pass
if __name__ == '__main__':
print type(Foo.__init__)
print inspect.getsourcelines(Foo.__init__)
Output:
<type 'wrapper_descriptor'>
...
4
votes
2answers
3k views
Python - TypeError: unbound method
So this Python problem has been giving me problems since I've tried refactoring the code into different files. I have a file called object.py and in it, the related code is:
class Object:
#this is a ...
5
votes
3answers
534 views
What is the difference between a constructer and initializer in python? [duplicate]
Possible Duplicate:
Python (and Python C API): new versus init
I'm at college just now and the lecturer was using the terms constructors and initializers interchangeably. I'm pretty sure ...
2
votes
2answers
64 views
Python: new instance of variable is not created in new instance of class [duplicate]
I have found strange Python's behavior (or probably I don't understand how inheritance and/or default values of attributes works).
For given code
class A(object):
def __init__(self, s):
...
0
votes
1answer
84 views
Pydev+Kivy - Empty __init__ files
I am using Eclipse and PyDev to develop for the Python library called Kivy.
I ran through the proper setup instructions, and developing and running from Eclipse works perfect.
However, when I, or ...
0
votes
1answer
44 views
initializing queue with condition
You have to implement the methods for the class m_sorted_list, which when initialized takes a parameter sorted which is true or false. When the parameter is true the list is sorted in ascending order. ...
1
vote
2answers
112 views
Referencing a list inside it's inline for loop initialization?
I would like to be able to write something like this:
x = [0]
x = [x[i-1] for i in range(1,10)]
I know this example doesn't make any sense. But I would like to know if it's possible to use ...
1
vote
1answer
39 views
python inheritance function override during init
Somehow the Father class can see the methods of the Child class. I presumed that only internal methods are available to Father during init
But apparently I am wrong. Here is the code:
class ...
0
votes
2answers
33 views
How to skip initializing the 1st returned value from a function? - Python
Often i only need the 2nd thing that was returned from a function; for example the code below where i want get a list of .txt files and get the filenames without the extension:
import os, glob
indir ...