#!/usr/bin/python  import sys from PyQt4 import QtGui  class Example(QtGui.QWidget):      def __init__(self):         super(Example, self).__init__() # what the meaning of this line          self.initUI()      def initUI(self):          lbl1 = QtGui.QLabel('ZetCode', self)         lbl1.move(15, 10)          lbl2 = QtGui.QLabel('tutorials', self)         lbl2.move(35, 40)          lbl3 = QtGui.QLabel('for programmers', self)         lbl3.move(55, 70)                  self.setGeometry(300, 300, 250, 150)         self.setWindowTitle('Absolute')             self.show()  def main():      app = QtGui.QApplication(sys.argv)     ex = Example()     sys.exit(app.exec_())   if __name__ == '__main__':     main()
6639
What's the difference between:  class Child(SomeBaseClass):     def __init__(self):         super(Child, self).__init__()   and:  class Child(SomeBaseClass):     def __init__(self):         SomeBaseClass.__init__(self)   I've seen super being used quite a lot in classes with only single inheritance. I can see why you'd use it in multiple inheritance but am unclear as to what the advantages are of using it in this kind of situation.
124165
I understood the very basic concept of how to use /etc/network/interfaces, but all I find online are examples, example after example, which I can copy-paste from. What I miss is an explanation of the syntax, an explanation of the meaning of the commands and which order the commands require. I want to understand, because most of the time copy-paste is not enough, because I'm not working on a fresh machine, so I can't just overwrite existing configurations because it would break a lot of stuff. man interfaces was not very helpful since it is written very complicated.  Example questions I have: what does inet in an iface line mean exactly (I could not even find it in the manpage), what does manual in an iface line mean exactly (many examples use it, but according to manpage it needs an extra config file then, which the examples don't present), when do I use or need them? When not? When I create a bridge, what exactly happens to the interfaces?
3866
Is it possible to have static class variables or methods in Python? What syntax is required to do this?
37170
My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, but the birds need to move every moment.  Tkinter, however, hogs the time for its own event loop, and so his code won't run. Doing root.mainloop() runs, runs, and keeps running, and the only thing it runs is the event handlers.  Is there a way to have his code run alongside the mainloop (without multithreading, it's confusing and this should be kept simple), and if so, what is it?  Right now, he came up with an ugly hack, tying his move() function to &lt;b1-motion&gt;, so that as long as he holds the button down and wiggles the mouse, it works. But there's got to be a better way.
7012
In Python 2.5, the following code raises a TypeError:  &gt;&gt;&gt; class X:       def a(self):         print "a"  &gt;&gt;&gt; class Y(X):       def a(self):         super(Y,self).a()         print "b"  &gt;&gt;&gt; c = Y() &gt;&gt;&gt; c.a() Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt;   File "&lt;stdin&gt;", line 3, in a TypeError: super() argument 1 must be type, not classobj   If I replace the class X with class X(object), it will work. What's the explanation for this?
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
32816
I have seen many files which have this line as the first line in them. What exactly is this?  #!/usr/bin/env python   What does it mean? Why is it necessary?
14375
starts with      I know that this isn't the first post with this problem, but I am   stuck with this for a day (total, not 1 day in a row). Somehow I can't   get this to work, maybe it is just 1 little adjustment that I need to   make, but I can't seem to find it :(   I'm sure the question , both for immediate answering and for people later having the same kind of problem.  But I'm afraid removing it might be considered rude by the asker as he might see the question with the introduction both more humble and more accorded to his personal writing style (especially in a case where the code follows immediately after this introduction).  Should I proceed and remove this lengthy useless introduction or just not bother ?
53471
Now that it's clear , there is an associated concept that I use all the time without knowing what it really means.   I suppose everybody made once a mistake with parenthesis, resulting  in an "object is not callable" exception. What's more, using __init__ and __new__ lead to wonder what this bloody __call__ can be used for.  Could you give me some explanations, including examples with the magic method ?
1615
What is __init__.py for in a Python source directory?
77525
After a few hours I am about to give up on finding a kind of documentation for the QGIS Python API that actually works/gives the correct information. It is obvious that there is no actual code documentation besides the one for the C++ API which differs from what works in Python. Ok, there is the help()-function, too, to get information about classes which is more than ust tedious to use. As an entry point, I thought I could use the tutorials/cookbook: . Even simple things like adding features does not work the described way in the current QGIS Version 2.4.0-Chugiak (there is no addFeature-function for example).  I wonder how working with the Python console and writing plugins makes sense under such unfavorably conditions.  What sources can actually be used to lookup and learn the Python API for QGIS for current versions?
22006
When defining a method on a class in Python, it looks something like this:  class MyClass(object):     def __init__(self, x, y):         self.x = x         self.y = y   But in some other languages, such as C#, you have a reference to the object that the method is bound to with the "this" keyword without declaring it as an argument in the method prototype.    Was this an intentional language design decision in Python or are there some implementation details that require the passing of "self" as an argument?
35741
How do I create a GUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?
56356
Pretty simple question: In Linux, why does Python require the line   #!/usr/bin/python   at the start of a python file, since Windows doesn't?  What does it do? 'cause the description "Links to Python" is a bit vague...
79650
I have a series of Python classes in a file. Some classes reference others.  My code is something like this:  class A():     pass  class B():     c = C()  class C():     pass   Trying to run that, I get NameError: name 'C' is not defined. Fair enough, but is there any way to make it work, or do I have to manually re-order my classes to accommodate? In C++, I can create a class prototype. Does Python have an equivalent?  (I'm actually playing with Django models, but I tried not complicate matters).
91640
I have a model class:  class Person(db.Model):   first_name = db.StringProperty(required=True)   last_name = db.StringProperty(required=True)   I have an instance of this class in p, and string s contains the value 'first_name'. I would like to do something like:  print p[s]   and   p[s] = new_value   Both of which result in a TypeError.  Does anybody know how I can achieve what I would like?
104558
I'm using a builder pattern to seperate a bunch of different configuration possibilities. Basically, I have a bunch of classes that are named an ID (something like ID12345). These all inherit from the base builder class. In my script, I need to instantiate an instance for each class (about 50) every time this app runs. So, I'm trying to see if instead of doing something like this:  ProcessDirector = ProcessDirector() ID12345 = ID12345() ID01234 = ID01234()  ProcessDirector.construct(ID12345) ProcessDirector.construct(ID01234)  ID12345.run() ID01234.run()   Can I do something like this (I know this doesn't work):  IDS = ["ID12345", "ID01234"]  ProcessDirector = ProcessDirector() for id in IDS:   builder = id() #some how instantiate class from string   ProcessDirector.construct(builder)   builder.run()   That way, when I need to add a new one in the future, all I have to do is add the id to the IDS list, rather than peppering the new ID throughout the code.   EDIT  Looks like there are some different opinions based on where the data is coming from. These IDs are entered in a file that no one else has access to. I'm not reading the strings from the command line, and I'd like to be able to do as little alteration when adding a new ID in the future.