[Tutor] deck dealing program

2005-08-07 Thread luke
from random import randint   def identify_card(n):    cardname = ""    royals = ["Jack","Queen","King","Ace"]    temp = n % 13    if temp > 8:    cardname += royals[temp-9]    else:    cardname += str(temp+2)    cardname += " of "       suits = ["Spades","Hearts","Diamonds","Club

Re: [Tutor] use of webbrowser.open_new()

2005-08-07 Thread Danny Yoo
On Sun, 7 Aug 2005, Tom Cloyd wrote: > Having just discovered the webbrowser module, I've confirmed that I can > indeed open a URL in my default browser using something like > > webbrowser.get_new("{URL}") > > What I want to do is open a web page stored on my local machine. I'm not > getting it

Re: [Tutor] use of webbrowser.open_new()

2005-08-07 Thread jfouhy
Quoting Tom Cloyd <[EMAIL PROTECTED]>: Compare the filename here: > webbrowser.open_new("C:\__Library\folders\05238 Design for Confusion\05238 > Design for Confusion -05krugman.html") With here: > WindowsError: [Errno 2] The system cannot find the file specified: > 'C:\\__Library\x0colders*38

[Tutor] use of webbrowser.open_new()

2005-08-07 Thread Tom Cloyd
Having just discovered the webbrowser module, I've confirmed that I can indeed open a URL in my default browser using something like webbrowser.get_new("{URL}") What I want to do is open a web page stored on my local machine. I'm not getting it to work - webbrowser.open_new("C:\__Library\fol

Re: [Tutor] Use functions re avoid Re: Can the following algorithm be improved?

2005-08-07 Thread Brian van den Broek
Nathan Pinno said unto the world upon 2005-08-07 22:10: > My message is in the attachment. Nathan, Just one fellow's voice, but I vote for "please don't do that" [the attachment]. It makes it more work to read your message. > Here is the improved algorithm: > import random > a = random.choi

[Tutor] Use functions re avoid Re: Can the following algorithm be improved?

2005-08-07 Thread Danny Yoo
Answer: yes, very much so. *grin* Ok, let's take a look at some snippets. ## cd = int(raw_input("How many cards to deal (1-6) or 9 to exit:")) if cd == 1: a = random.choice(range(52)) if a == 0: a = "Ace of Hearts" elif a == 1: a = "T

Re: [Tutor] a dictionary method good for this process

2005-08-07 Thread Kent Johnson
Srinivas Iyyer wrote: > Hi Kent: > Thank you for your tip on making a sub-dictionary. > However, I see some new prbs. that I am unable to > solve are persisting. could you enlighten me, please. > > >>d={} >>for m in listB: >> cols = m.split('\t') >> term = cols[1] >> d.setdefault(term, []).a

Re: [Tutor] IP Address from Python module?

2005-08-07 Thread Danny Yoo
> >I think you're looking for socket.gethostbyname(). > > > >http://www.python.org/doc/lib/module-socket.html#l2h-2594 > > > >Here's an example using the socket.gethostbyname() function: > > > >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/335890 > > > > > Oh.. btw I don't think

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Kent Johnson
Jan Eden wrote: > Now I'll see if I understand the practical difference between items() > and iteritems() - the Python tutorial uses iteritems() in such a > context. iteritems() is actually better usage but a little harder to explain. dict.items() creates a new list with the (key, value) pairs:

Re: [Tutor] IP Address from Python module?

2005-08-07 Thread Joseph Quigley
Danny Yoo wrote: >On Fri, 5 Aug 2005, Joseph Quigley wrote: > > > >>Is it possible to get my internet and/or network IP address from Python? >>Is there any other way to get it? >> >> > >Hi Joe, > >I think you're looking for socket.gethostbyname(). > >http://www.python.org/doc/lib/module-

Re: [Tutor] What's the invalid syntax? Code supplied

2005-08-07 Thread Nathan Pinno
After reading what Steve Reighard and Danny wrote, I've decided that I was wrong. I'm sorry. I'm almost done my new algorithm, and will share it with the group.   Nathan ---I wanted help, and you criticized me,I wanted aid, and you r

Re: [Tutor] What's the invalid syntax? Code supplied

2005-08-07 Thread steve reighard
I've been on this mailing list for some time, I even remember Tim Peters, and have been very impressed with the patience and expertise of the "tutors" who answer questions, e.g. Allen, Danny, Bob, etc.  I want to urge those tutors to continue to help us neophytes and to thank them for the help they

Re: [Tutor] What's the invalid syntax? Code supplied

2005-08-07 Thread Nathan Pinno
All, I do understand that concept. I was trying to implement it, and got stuck, so I asked for help. Nathan --- I wanted help, and you criticized me, I wanted aid, and you refused, So I will do it myself! --Author unknown --

Re: [Tutor] What's the invalid syntax? Code supplied

2005-08-07 Thread Nathan Pinno
Alan and all, I'm no longer going to use this method. I thought up a more easier idea for dealing cards. I was going to share it, but with all this time and effort pointing out things that I should know, instead of helping me, I don't think I will, because it will probably be ripped to shreds b

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Jan Eden
Hi Kent, hi Alan, Alan G wrote on 07.08.2005: >> page = Show(type=type, id=id) >> >> class Show: >> def __init__(self, type, id): >> self.id = id >> ... >>return self > >First a couple of comments. >You don't need to return self from __init__. >You can only instantiate Show *a

Re: [Tutor] Assistance!

2005-08-07 Thread Luis N
On 8/7/05, gordnjen <[EMAIL PROTECTED]> wrote: > > I am now stuck again. I am at my wit's end. The course I am taking is a > supposed "beginners" course. It is a distance education class, and our > textbook does NOT contain the information required to do all of the > assignments (perhaps it was de

Re: [Tutor] Guess my number?

2005-08-07 Thread Joseph Quigley
Hi. > I want the program to say "You're stupid!" When a player fails to guess in > 10 tries. > But, it's not working.. Very simple fix for bug: > elif (guess < number): > print "Higher...\n" > elif (tires > 10): > print "You're stupid!" > else: > print "Error!

Re: [Tutor] Tutor Digest, Vol 18, Issue 37

2005-08-07 Thread Joseph Quigley
Hi. > I want the program to say "You're stupid!" When a player fails to guess in > 10 tries. > But, it's not working.. Very simple fix for bug: > elif (guess < number): > print "Higher...\n" > elif (tires > 10): > print "You're stupid!" > else: > print "Error!

Re: [Tutor] What's the invalid syntax? Code supplied

2005-08-07 Thread Alan G
> What's the invalid syntax? Here is the code: > import random > hand = { >'0' : ["Ace"] >'1' : ["Two"] Nathan, You really need to take some time out to read about data structures in Python. You are trying to use a dictionary, with a string as a key and a list as a value. The list has a

[Tutor] Assistance!

2005-08-07 Thread gordnjen
I am now stuck again. I am at my wit's end. The course I am taking is a supposed "beginners" course. It is a distance education class, and our textbook does NOT contain the information required to do all of the assignments (perhaps it was designed for people with more experience and/or knowledge?)

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Alan G
> page = Show(type=type, id=id) > > class Show: > def __init__(self, type, id): > self.id = id > ... >return self First a couple of comments. You don't need to return self from __init__. You can only instantiate Show *after* you've defined it. > For two parameters, this is rel

Re: [Tutor] Lots of variables

2005-08-07 Thread Alan G
> I am trying to write a gui that has a lot of checkboxes. It is over > 200 > different ones. I use a for statement to generate: > >ver = 200 >for i in ['Car','House','Boat','Plane']: >self.fra26_che01p = Checkbutton (self.fra26) >self.fra26_che01p.place(in_

Re: [Tutor] a dictionary method good for this process

2005-08-07 Thread Srinivas Iyyer
Hi Kent: Thank you for your tip on making a sub-dictionary. However, I see some new prbs. that I am unable to solve are persisting. could you enlighten me, please. > d={} > for m in listB: > cols = m.split('\t') > term = cols[1] > d.setdefault(term, []).append(m) > > for i in listA: >

Re: [Tutor] XMMS song search

2005-08-07 Thread R. Alan Monroe
> songsearch = raw_input(Enter song name: ") > f = file(/home/joe/.xmms/xmms.pls) Don't forget your quotation marks around the filename. > f.find(songsearch) You _find_ stuff in strings, not in the file itself. Read each line of the file one at a time, because each line will be a string. for

Re: [Tutor] Guess my number?

2005-08-07 Thread Rob Andrews
Let's take a look I pasted your code into a new window and gave it a go. You used tabs for indentation (or they got in there somewhere in the email/copy/paste process), which confused my tiny mind, so I replaced 'em with spaces. I noticed a few things. Here's my code:

[Tutor] XMMS song search

2005-08-07 Thread Joseph Quigley
Hi. I have 7.8 GB of music (1808 songs) and I use XMMS to play them. However I can't find some songs. Apparently there is no song search feature in XMMS (something I plan to add whenever I learn C or can incorporate Python into C.. unless someone else has already done this) so I have a hard tim

[Tutor] Guess my number?

2005-08-07 Thread . ,
I want the program to say "You're stupid!" When a player fails to guess in 10 tries. But, it's not working.. import random number = random.randrange(100) + 1 guess = int(raw_input("Take a guess: ")) tries = 1 while (guess != number): if (guess > number): print "Lower...\n" elif

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Kent Johnson
Jan Eden wrote: > My idea was to transfer the same technique to Python like this: > > class NewClass: > def __init__(self, **parameters): > for i in parameters.keys(): self.i = parameters[i] > > But the assignment in the for loop obviously does not work with > instance attributes. I w

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Jan Eden
Jan Eden wrote on 07.08.2005: >But the assignment in the for loop obviously does not work with >instance attributes. I will have to read up some more about instance >attributes. Ok... so this works: class NewClass: def __init__(self, **parameters): self.data = {} for i in par

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Jan Eden
Hi Kent, Kent Johnson wrote on 07.08.2005: >>So how can I add the values of all the paramaters to my class >>instance in one step? > >There was recently a long discussion of this on comp.lang.python. >http://groups.google.com/group/comp.lang.python/browse_frm/thread/ >7346ad00a14e821a/9dc993d2954

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Kent Johnson
Jan Eden wrote: > In Python, I would do: > > page = Show(type=type, id=id) > > class Show: def __init__(self, type, id): self.id = id self.type = > type ... return self > > For two parameters, this is relatively simple. But if I have for > example 10 parameters on instantiation, assigning each v

[Tutor] references and popping, caveats?

2005-08-07 Thread mailing list
Hi all, I have the following code - >>> j = """a = { b = { c = { d = 5 e = 10 } } }""" >>> ref = [] >>> data = {} >>> ref.append(data) >>> for line in j.split('\n'): ... if "=" in line: ... (LHS, RHS) = line.split(" = ") ... if RHS == "{": ... #op

Re: [Tutor] Class instantiation parameters

2005-08-07 Thread Jan Eden
Hi, Jan Eden wrote on 07.08.2005: >So how can I add the values of all the paramaters to my class >instance in one step? > apologies for replying to my own post: I just discovered the **args formal parameter. Thanks, Jan -- I was gratified to be able to answer promptly, and I did. I said I did

[Tutor] Class instantiation parameters

2005-08-07 Thread Jan Eden
Hi, after using Perl for some years for simple scripting tasks, one of my programs reached a size where an OO design is appropriate. So I rewrote the program using OO techniques in Perl. Because I am not entirely satisfied with the implementation, I decided port the program to Python. The firs