Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 2nd, 2003, 01:24 PM
Cuboidz Cuboidz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 11 Cuboidz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Python Pointers ?

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:
def __init__(self, *args):


There is a * before args, and I dont' have a clue what that means

Reply With Quote
  #2  
Old September 2nd, 2003, 02:43 PM
Cuboidz Cuboidz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 11 Cuboidz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Variable amount of arguments

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)

Reply With Quote
  #3  
Old September 3rd, 2003, 12:36 PM
FiveGrainJa FiveGrainJa is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Alexandria, VA
Posts: 5 FiveGrainJa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old September 3rd, 2003, 07:47 PM
Cuboidz Cuboidz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 11 Cuboidz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking It's like you read my mind

After seeing the **kw form just a moment ago I came here and you conveniently already answered my question

Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python Pointers ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway