[Tutor] [Fwd: Re: Which Designer]
Thank you both for your help and insight. It has given me room for thought. Much appeciated, Sharon Original Message Subject:Re: [Tutor] Which Designer Date: Mon, 26 Apr 2010 09:09:59 +0100 From: Alan Gauld alan.ga...@btinternet.com To: tutor@python.org References: 4bd44500.9060...@gmail.com hr2jpv$30...@dough.gmane.org4bd4e2d8.70...@gmail.com 20100426013130.ga80...@dragon.alchemy.com Steve Willoughby st...@alchemy.com wrote However, there are some real disadvantages to Tk(inter) as well, chiefly that it is a least-common denominator which does a passable job of running GUIs but they don't look consistent with the native look of Windows or OS/X The new themed widgets in Tk have changed that, they are built on the native widgets and look just like any other GUI. Available in Tkinter from Python 2.7 and 3.1 or whatever. And there is a lot of missing functionality. This is still true although Tix addresses the biggest gaps - but is sadly lacking documentation - you have to use the Tcl/Tk docs :-( (I keep intending to do a write up on Tix but other things get in the way!) And there are other bolt-ons too such as PMW. I'm getting into wxPython at the moment, and I have to say it's at least worth a look. It's also available for every platform (but doesn't come with Python), and is far more complete, and just about as easy to use as Tk, but looks a lot more polished. wxPython is definielt more powerful and in particular has support for things like printing and drag n drop which are missing fromTk. There are other toolkits with their advocates as well, of course, but if someone were just starting out with Python GUI programming, I'd recommend looking around at your options before starting with Tk. I'd still advocate Tk because a) It comes with Python so is standard b) It is also the standard GUI in Ruby, Perl and Tcl so once learned is oportable c) It is best documented with many books etc featuring it d) It is easy to learn the basic GUI principles that are valid in any Framework (a bit like learning Python is good becauise it helps you learn other languages) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Any
Hi all, I was just wondering if anyone here can recommend any freeware program that has been written in python and for which the source code is available. Basically I just want to see a program that does something relatively simple and straightforward, but something that is real world, I mean something that people actually use, hopefully something that comes with it's own installer and GUI. I'd like to try out using the program as an ordinary user and then I want to look at the source code to see how it's been achieved. Any ideas or suggestions? Kevin Kirton Australia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
Kevin Kirton kpkir...@gmail.com wrote I was just wondering if anyone here can recommend any freeware program that has been written in python and for which the source code is available. IDLE? The IDE that comes with Python ias wtten in Python and the source comes as part of the standard library. But if thats not enough try both sourceforge and the PyGame web sites. On sourceforge search for projects using python... DIA is one that springs to mind(a Visio type drawing program) PyGame has lots of Python games you can download, several with source. Basically I just want to see a program that does something relatively simple and straightforward, but something that is real world, I mean something that people actually use, hopefully something that comes with it's own installer and GUI. You can use the python install tools or drive them with something higher level like Wize(?) or Installshield (or the free InstallMaker for Windows that I used to use... I don't know if its still extant however!) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
Christian Witts wrote: Maybe look through projects at Freshmeat [1]. [1] http://freshmeat.net/tags/python That's exactly what I was looking for. I've already selected a few small programs and now I plan on installing them, seeing how they operate from a user's perspective, then I'll take a look at the source code and see what I can work out. Thanks very much. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
On Thu, 29 Apr 2010 13:04:20 +0100 Alan Gauld alan.ga...@btinternet.com wrote: IDLE? The IDE that comes with Python ias wtten in Python and the source comes as part of the standard library. There's also a free software programming editor --editra, I guess-- written in and mainly for python. (But I would not recommend it for first tweaks, because it is great code but highly abstract.) Denis vit esse estrany ☣ spir.wikidot.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
Alan Gauld wrote: But if thats not enough try both sourceforge and the PyGame web sites. On sourceforge search for projects using python... DIA is one that springs to mind(a Visio type drawing program) PyGame has lots of Python games you can download, several with source. PyGame looks promising (very distracting too). DIA in itself looks quite useful and interesting, so I might learn that as a user then see if I can look through its code. Thanks for your help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
On Thu, 29 Apr 2010 08:06:30 pm Kevin Kirton wrote: Hi all, I was just wondering if anyone here can recommend any freeware program that has been written in python and for which the source code is available. The Red Hat Package Manager (rpm) is written in Python. The original BitTorrent application was written in Python. The Roundup and Trac bug-trackers are both written in Python, as are the version-control systems Bazaar and Mercurial. So are Mailman and Plone. Most of these are fairly big applications though. Not huge, but big. The Reddit website is written in Python, as is the EVE Online massive multiplayer game, although I doubt the source code for them are available. Basically I just want to see a program that does something relatively simple and straightforward, but something that is real world, I mean something that people actually use, hopefully something that comes with it's own installer and GUI. Unfortunately, these days all the cool kids are programming web apps rather than desktop applications. So it's a bit hard to find interesting, useful desktop applications. However, you can check out Pygame, PythonCard and Dabo: http://www.pygame.org/news.html http://pythoncard.sourceforge.net/ http://dabodev.com/ Pygame is a framework for, well, programming games in Python. Pythoncard is a desktop application based on Apple's much-loved and never forgotten Hypercard (may it rest in peace!). And Dabo is based on Visual FoxPro. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to get ipRouteTable from Cisco router?
Hello! I want to get route tables from Cisco routers in the network. What i have: import re from pysnmp.entity.rfc3413.oneliner import cmdgen s = r'(%s)' % ('(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)\ {3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)') pattern = re.compile(s) file = 'routers.txt' s = open(file).read() i = 0 router_list = [] while True: match = pattern.search(s, i) if match: router_list.append(match.group(1)) i = match.end() + 1 else: break class router: def __init__(self, who): self.name = who routetable = {} router1 = router(router_list[0]) cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( cmdgen.CommunityData('test-agent', public, 0), cmdgen.UdpTransportTarget((router1.name, 161)), (1,3,6,1,2,1,4,21,1,1)) if errorIndication: print errorIndication else: if errorStatus: print '%s at %s\n' % (errorStatus.prettyPrint(),varBindTable[-1][int(errorIndex)-1]) else: for varBindTableRow in varBindTable: for oid, val in varBindTableRow: print varBindTableRow Result: Code: Select all [(ObjectName('1.3.6.1.2.1.4.21.1.1.0.0.0.0'), IpAddress('0.0.0.0'))] [(ObjectName('1.3.6.1.2.1.4.21.1.1.10.9.0.0'), IpAddress('10.9.0.0'))] [(ObjectName('1.3.6.1.2.1.4.21.1.1.192.168.1.0'), IpAddress('192.168.1.0'))] How can i get IpAddress values from this list and put they in the dictionary? Or may be there is much better solution? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
The Reddit website is written in Python, as is the EVE Online massive multiplayer game, although I doubt the source code for them are available. Actually, Reddit has made it's source available and has included a HOWTO install Reddit on your webserver. There is a Google Group reddit-dev for this purpose, as well. See http://code.reddit.com for more...they actually use Trac for that site. ;). -- Brie ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to get ipRouteTable from Cisco router?
Hello! I want to get route tables from Cisco routers in the network. What i have: snip else: for varBindTableRow in varBindTable: for oid, val in varBindTableRow: print varBindTableRow snip Result: Code: Select all [(ObjectName('1.3.6.1.2.1.4.21.1.1.0.0.0.0'), IpAddress('0.0.0.0'))] [(ObjectName('1.3.6.1.2.1.4.21.1.1.10.9.0.0'), IpAddress('10.9.0.0'))] [(ObjectName('1.3.6.1.2.1.4.21.1.1.192.168.1.0'), IpAddress('192.168.1.0'))] How can i get IpAddress values from this list and put they in the dictionary? Or may be there is much better solution? My guess, from looking at what you have there, str(varBindTableRow[1]) should get your IP address in a string format. In any case the varBindTableRow[1] will contain the IpAddress object(?) that is displayed in the lists. HTH, Wayne Results are: 1. print str(varBindTableRow[1]) IndexError: list index out of range 2. print str(varBindTableRow[0][1]) АЁ 3. but for ipRouteIfIndex, i have print str(varBindTableRow[0][1]) 0 0 1 So, it works for IfIndex, RouteType, but not for Dest, Mask and NextHop as they return ip. Thanks indeed. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] blackjack game
# Blackjack # From 1 to 7 players compete against a dealer import cards, games class BJ_Card(cards.Card): A Blackjack Card. ACE_VALUE = 1 def get_value(self): if self.is_face_up: value = BJ_Card.RANKS.index(self.rank) + 1 if value 10: value = 10 else: value = None return value value = property(get_value) class BJ_Deck(cards.Deck): A Blackjack Deck. def populate(self): for suit in BJ_Card.SUITS: for rank in BJ_Card.RANKS: self.cards.append(BJ_Card(rank, suit)) class BJ_Hand(cards.Hand): A Blackjack Hand. def __init__(self, name): super(BJ_Hand, self).__init__() self.name = name def __str__(self): rep = self.name + :\t + super(BJ_Hand, self).__str__() if self.total: rep += ( + str(self.total) + ) return rep def get_total(self): # if a card in the hand has value of None, then total is None for card in self.cards: if not card.value: return None # add up card values, treat each Ace as 1 total = 0 for card in self.cards: total += card.value # determine if hand contains an Ace contains_ace = False for card in self.cards: if card.value == BJ_Card.ACE_VALUE: contains_ace = True # if hand contains Ace and total is low enough, treat Ace as 11 if contains_ace and total = 11: # add only 10 since we've already added 1 for the Ace total += 10 return total total = property(get_total) def is_busted(self): return self.total 21 class BJ_Player(BJ_Hand): A Blackjack Player. def is_hitting(self): response = games.ask_yes_no(\n + self.name + , do you want a hit? (Y/N): ) return response == y def bust(self): print self.name, busts. self.lose() def lose(self): print self.name, loses. def win(self): print self.name, wins. def push(self): print self.name, pushes. class BJ_Dealer(BJ_Hand): A Blackjack Dealer. def is_hitting(self): return self.total 17 def bust(self): print self.name, busts. def flip_first_card(self): first_card = self.cards[0] first_card.flip() class BJ_Game(object): A Blackjack Game. def __init__(self, names): self.players = [] for name in names: player = BJ_Player(name) self.players.append(player) self.dealer = BJ_Dealer(Dealer) self.deck = BJ_Deck() self.deck.populate() self.deck.shuffle() def get_still_playing(self): remaining = [] for player in self.players: if not player.is_busted(): remaining.append(player) return remaining # list of players still playing (not busted) this round still_playing = property(get_still_playing) def __additional_cards(self, player): while not player.is_busted() and player.is_hitting(): self.deck.deal([player]) print player if player.is_busted(): player.bust() def play(self): # deal initial 2 cards to everyone self.deck.deal(self.players + [self.dealer], per_hand = 2) self.dealer.flip_first_card()# hide dealer's first card for player in self.players: print player print self.dealer # deal additional cards to players for player in self.players: self.__additional_cards(player) self.dealer.flip_first_card()# reveal dealer's first if not self.still_playing: # since all players have busted, just show the dealer's hand print self.dealer else: # deal additional cards to dealer print self.dealer self.__additional_cards(self.dealer) if self.dealer.is_busted(): # everyone still playing wins for player in self.still_playing: player.win() else: # compare each player still playing to dealer for player in self.still_playing: if player.total self.dealer.total: player.win() elif player.total self.dealer.total: player.lose() else: player.push() # remove everyone's cards for player in self.players: player.clear() self.dealer.clear() def main(): print \t\tWelcome to Blackjack!\n names = [] number = games.ask_number(How many players? (1 - 7): , low = 1, high = 8) for i in range(number): name = raw_input(Enter player name: ) names.append(name)
Re: [Tutor] blackjack game
On 04/30/10 06:23, Shurui Liu (Aaron Liu) wrote: # Blackjack # From 1 to 7 players compete against a dealer snip code Here is the code of this game. I want to change some part of them. 1. Since I don't know what part of code is responsible for the number of cards, so I don't know how to add a card number check attribute, I mean, to check the number of card is more enough for next time play no matter how many players there are, if cards are not more enough, print out a notice and stop the program; The BJ_Game is responsible in querying the Deck if it has enough cards for the round. BJ_Game will calculate the number of players and asks if ask BJ_Deck if it can support that much player. Be careful when calculating number of cards since in blackjack using one deck it is possible to split one's hand into four (btw, why is BJ_Player inheriting BJ_Deck? that would make splitting impossible; a player has a hand but it is not a hand :-) 2. I am not sure if I can let the winner get all of the cards and print out what cards the winner has when the game finished. that depends on the house rule, I think, some games requires all player can see everyone else's card while other games keeps everyone's hand closed. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Any
Steven D'Aprano st...@pearwood.info wrote Pythoncard is a desktop application based on Apple's much-loved and never forgotten Hypercard (may it rest in peace!). And Dabo is based on Visual FoxPro. Just a caveat: Both of these are really development tools rather than applications in the normal sense - although they are applications for developers of course! But they are much closer to Visual Studio than to MS Word... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] blackjack game
Shurui Liu (Aaron Liu) shuru...@gmail.com wrote Your sig says you are studying Comp Sci and engineering. You have posted the code for what is really a very, very, small program. In the real world you will be expected to read and understand much bigger programs than this - think about 1000+ files and half a million lines of code (That was my first post uni' project - in C) You apparently want us to read this code and interpret it for you? Please try reading it and figuring out how it works first, then if you have sections you want help with, come back and ask specific questions. Don't expect us to do something you are not willing to at least make a start on... -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ # Blackjack # From 1 to 7 players compete against a dealer import cards, games class BJ_Card(cards.Card): A Blackjack Card. ACE_VALUE = 1 def get_value(self): if self.is_face_up: value = BJ_Card.RANKS.index(self.rank) + 1 if value 10: value = 10 else: value = None return value value = property(get_value) class BJ_Deck(cards.Deck): A Blackjack Deck. def populate(self): for suit in BJ_Card.SUITS: for rank in BJ_Card.RANKS: self.cards.append(BJ_Card(rank, suit)) class BJ_Hand(cards.Hand): A Blackjack Hand. def __init__(self, name): super(BJ_Hand, self).__init__() self.name = name def __str__(self): rep = self.name + :\t + super(BJ_Hand, self).__str__() if self.total: rep += ( + str(self.total) + ) return rep def get_total(self): # if a card in the hand has value of None, then total is None for card in self.cards: if not card.value: return None # add up card values, treat each Ace as 1 total = 0 for card in self.cards: total += card.value # determine if hand contains an Ace contains_ace = False for card in self.cards: if card.value == BJ_Card.ACE_VALUE: contains_ace = True # if hand contains Ace and total is low enough, treat Ace as 11 if contains_ace and total = 11: # add only 10 since we've already added 1 for the Ace total += 10 return total total = property(get_total) def is_busted(self): return self.total 21 class BJ_Player(BJ_Hand): A Blackjack Player. def is_hitting(self): response = games.ask_yes_no(\n + self.name + , do you want a hit? (Y/N): ) return response == y def bust(self): print self.name, busts. self.lose() def lose(self): print self.name, loses. def win(self): print self.name, wins. def push(self): print self.name, pushes. class BJ_Dealer(BJ_Hand): A Blackjack Dealer. def is_hitting(self): return self.total 17 def bust(self): print self.name, busts. def flip_first_card(self): first_card = self.cards[0] first_card.flip() class BJ_Game(object): A Blackjack Game. def __init__(self, names): self.players = [] for name in names: player = BJ_Player(name) self.players.append(player) self.dealer = BJ_Dealer(Dealer) self.deck = BJ_Deck() self.deck.populate() self.deck.shuffle() def get_still_playing(self): remaining = [] for player in self.players: if not player.is_busted(): remaining.append(player) return remaining # list of players still playing (not busted) this round still_playing = property(get_still_playing) def __additional_cards(self, player): while not player.is_busted() and player.is_hitting(): self.deck.deal([player]) print player if player.is_busted(): player.bust() def play(self): # deal initial 2 cards to everyone self.deck.deal(self.players + [self.dealer], per_hand = 2) self.dealer.flip_first_card()# hide dealer's first card for player in self.players: print player print self.dealer # deal additional cards to players for player in self.players: self.__additional_cards(player) self.dealer.flip_first_card()# reveal dealer's first if not self.still_playing: # since all players have busted, just show the dealer's hand print self.dealer else: # deal additional cards to dealer print self.dealer self.__additional_cards(self.dealer) if self.dealer.is_busted(): # everyone still playing wins for player in self.still_playing: player.win() else: # compare each player still playing to dealer for player in
Re: [Tutor] blackjack game
On Fri, 30 Apr 2010 06:23:44 am Shurui Liu (Aaron Liu) wrote: Here is the code of this game. I want to change some part of them. 1. Since I don't know what part of code is responsible for the number of cards, so I don't know how to add a card number check attribute, I mean, to check the number of card is more enough for next time play no matter how many players there are, if cards are not more enough, print out a notice and stop the program; In real life, cards are dealt from a deck, and if the deck does not have enough cards, something will happen -- usually the dealer will start a new, shuffled, deck. Does your code have a deck? 2. I am not sure if I can let the winner get all of the cards and print out what cards the winner has when the game finished. That's a question about blackjack, not Python. Since I don't play blackjack, I don't know. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Boa Constructor list control
Hello, I am just learning how to use Boa Constructor to make GUI apps, and am having some problem with understanding the list control. The list control has a property called columns, but I cannot figure out how to add columns, and specify names for them. When I click the column property a small window opens up with it's title set to col1 something with the word Name in a label on it. Subsequent clicks on the column properry of the list control just brings this little window up again. I cannot change the text in the label of that small window to the name I want for a column, and I cannot figure out how to add more columns to the list control. When the small column window is selected no properties show for it in the Inspector window. Can anyone tell me how to use this control? I tried using the Boa Constructor help menu, and it led me to a very brief description of the list control, with no details on what it's properties were even. Thanks, Ray Parrish -- Linux dpkg Software Report script set.. http://www.rayslinks.com/LinuxdpkgSoftwareReport.html Ray's Links, a variety of links to usefull things, and articles by Ray. http://www.rayslinks.com Writings of The Schizophrenic, what it's like to be a schizo, and other things, including my poetry. http://www.writingsoftheschizophrenic.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor