|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
After my crash course in Python syntax I started learning PyQt, where I encountered something that wasn't covered in my crash course tutorial:
Code:
#
# hello.py
#
import sys
from qt import *
class HelloButton(QPushButton):
def __init__(self, *args):
QPushButton.__init__(self, *args)
self.setText("Hello World")
class HelloWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.button = HelloButton(self)
self.setCentralWidget(self.button)
def main(args):
app = QApplication(args)
win = HelloWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
app.exec_loop()
if __name__ == "__main__":
main(sys.argv)
In the following line: Quote:
There is a * before args, and I dont' have a clue what that means ![]() |
|
#2
|
|||
|
|||
|
I figured it out
Apparently, * before a function argument list means you can have a variable amount of arguments, for example: Code:
def test(*args):
print "\n".join(args)
test("argument 1", "argument 2", "argument 3")
will print: Code:
argument 1 argument 2 argument 3 (The arguments are collected in a tuple) |
|
#3
|
|||
|
|||
|
There are two different ways of passing/receiving non-explicit arguments *args and **kw.
*args gives you a tuple of the extra arguments passed to the function **kw gives you a dictionary of the extra keyword arguments to the function. BTW, the use of the names 'args' and 'kw' is just a convention, you can use any name you like. It's the leading astrick or two that tells the interpreter what to use them as. Check out this link on python.org for more info: http://www.python.org/doc/current/t...000000000000000 |
|
#4
|
|||
|
|||
|
After seeing the **kw form just a moment ago I came here and you conveniently already answered my question
Thanks ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python Pointers ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|