Re: [Tutor] Cataloging Web Page Information

2005-03-04 Thread Kent Johnson
Anderson wrote:
Hello,
I currently have access to a webpage that has information that I'd
like to put into a CSV (comma seperated value) spreadsheet. Its
frontend is a form; you fill the form out by entering some text and
selecting the appropriate option from a drop down menu, and then you
press the submit form button.
You may be able just to send the same data as the form without having to actually read the form from 
the web site. If the form uses GET, you can see the data it sends in the URL bar of the browser 
after you submit the form. If the form uses POST, you will have to look at the actual form to see 
how the data is formatted.

Alternatively you can use ClientForm to fill out the actual form and submit it.
http://wwwsearch.sourceforge.net/ClientForm/
The webpage subsequently displays links to every entry it can find and
when you click on the link you get the full info of that entry.
BeautifulSoup can help you pull the links out of the reply.
http://www.crummy.com/software/BeautifulSoup/
urllib2 (in the standard library) can retrieve the final web page, if you need to parse it use 
BeautifulSoup again.

Kent
I want to automate the whole process with a python script. I figured
out that the csv module(s) would be best for storing the received
information but what module should I use to access the website, fill
out the form, enter each resulting link and retrieve the information?
Thanks for your time,
Anderson
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cataloging Web Page Information

2005-03-04 Thread Anderson
Hello,

I currently have access to a webpage that has information that I'd
like to put into a CSV (comma seperated value) spreadsheet. Its
frontend is a form; you fill the form out by entering some text and
selecting the appropriate option from a drop down menu, and then you
press the submit form button.

The webpage subsequently displays links to every entry it can find and
when you click on the link you get the full info of that entry.

I want to automate the whole process with a python script. I figured
out that the csv module(s) would be best for storing the received
information but what module should I use to access the website, fill
out the form, enter each resulting link and retrieve the information?

Thanks for your time,
Anderson
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] returning table elements with Beautiful Soup

2005-03-04 Thread Kent Johnson
Bill Kranec wrote:
Hi,
I'm trying to use Beautiful Soup to scrape some data out of an HTML 
table.  I can do this using

table = soup("td", {'class' : 'yfnc_tabledata1' })
table[0].string.strip()
OK, table is a list of Tags, the first one has a 'string' attribute.
However, if I try
for entry in table:
   entry.string.strip()
I get: AttributeError: Tag instance has no attribute 'string'
Because not every Tag in table has a 'string' attribute, only the ones that have a single string 
child somewhere.

Try this and you will see better what is going on:
import urllib2
from BeautifulSoup import BeautifulSoup
data = urllib2.urlopen('http://finance.yahoo.com/q?s=IBM').read()
soup = BeautifulSoup(data)
table = soup("td", {'class' : 'yfnc_tabledata1' })
for entry in table:
print entry
try:
print entry.string
except AttributeError:
print 'No string'
## prints
92.37
92.37
Mar 4
Mar 4
http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif"; alt="Down" /> 0.04 (0.04%)
No string
...etc

Notice the third element has two string children - ' ' and '0.04 (0.04%)'. You will have to do 
a little more work if you want the text from that one.

Is there an easy way to have Beautiful Soup return each data element in 
the table, preferably into a list?
allStrings = [entry.string for entry in table if hasattr(entry, 'string')]
print allStrings
## prints
['92.37', 'Mar 4', '92.41', '92.94', 'N/A', 'N/A', '107.33', '92.36 - 93.18', '81.90 - 99.10', 
'4,754,000', '4,619,454', '150.81B', '18.65', '4.95', '0.72 (0.78%)', '15.02', '1.57', '10-Mar-05', 
' 8-Feb-05', '5.62', '1.04', '2.1', '1.64']

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with IntVar() (SOLVED!)

2005-03-04 Thread Ronnie Betzen
Thanks, Kent!

Moving self.top=Tk() up solved the IntVar() problem.
*sigh* Man, learning curves can be a royal pain ;-)

Also, thanks for the advice about starting off with little bits at a time. 
Kinda seems like an obvious way to do things when you think about it. :-/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with IntVar() - Oops! Here's the code.

2005-03-04 Thread Kent Johnson
There seem to be quite a few problems with this code...
Ronnie Betzen wrote:
#! /usr/bin/env python
import Tkinter
should be
  from Tkinter import *
class timer:
  def __init__(self):
  
The next line needs to be after the line 'self.top = Tk()' so Tkinter is initialized when the 
variable is created.
  # initialize global variables
  self.ckbuttonstatus = IntVar()
  
  # set up main window
  self.top = Tk()
  self.top.geometry('355x125')
appname is not defined...
  self.top.title(appname)
etc...
I think you have bitten off too much here. Try starting with a very small, working program that has 
a little of what you want in it. Then add another little piece and get that working. Repeat until 
you get to where you want to be. Ask questions when you don't understand the next step.

Here is a very simple program that links a checkbox and a label through a variable. Maybe this is a 
step in the right direction for you:

from Tkinter import *
root = Tk()
var = IntVar()
Label(textvariable=var).pack()
c = Checkbutton(text="Click Me", variable=var)
c.pack()
root.mainloop()
Kent
  self.top.resizable(width='no', height='no')
  
  # set up menubar
  self.menubar = menu(self.top)
  self.top.config(menu = self.menubar)
  
  # set up file menu
  self.filemenu = Menu(self.menubar, tearoff = 0)
  self.filemenu.add_cascade(label="File", menu=self.filemenu)
  self.filemenu.add_checkbutton(label = "Click Me!", command = 
self.labelUpdate)
  self.filemenu.add_command(label = "Quit", command=self.top.quit)
  
  # set up main display area
  self.frame = Frame(self.top)
  self.frame.pack(fill=x)
  self.displaylabel=Label(self.frame, text=" ", font="Times 36 bold", 
relief="sunken")
  self.displaylabel.pack(side=BOTTOM, fill=X)
  
  def labelUpdate(self):
  self.status = self.ckbuttonstatus.get()
  self.labeltext = "Chekbutton status is: " + self.status
  self.displaylabel.config(text=labeltext)
  self.top.update()
  
if __name__ == '__main__':
 mainApp = timer()
 mainloop()
 

On Friday 04 March 2005 08:39 pm, Ronnie Betzen wrote:
I've been trying to use IntVar() to update checkboxes using the Tkinter
toolkit.  To date I haven't been successful getting it to work.  Evidently
I'm missing some concept with regards to setting up my interface.  I've
successfully run scripts by other people using IntVar() so I know my
personal system is ok.
Here is some code that causes me problems with IntVar().  Can someone
enlighten this total newbie (python and programming both.) as to what I'm
missing here?
Thanks,
Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] returning table elements with Beautiful Soup

2005-03-04 Thread Bill Kranec
Hi,
I'm trying to use Beautiful Soup to scrape some data out of an HTML 
table.  I can do this using

table = soup("td", {'class' : 'yfnc_tabledata1' })
table[0].string.strip()
However, if I try
for entry in table:
   entry.string.strip()
I get: AttributeError: Tag instance has no attribute 'string'
Clearly Python is now treating the cell as a list element, not as a 
Beautiful Soup class, so it cannot find the method that I want to use.  
But I can't seem to find a way to do what I meant to do.

Is there an easy way to have Beautiful Soup return each data element in 
the table, preferably into a list?

Any help is greatly appreciated.
Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with IntVar() - Oops! Here's the code.

2005-03-04 Thread Ronnie Betzen
#! /usr/bin/env python
import Tkinter

class timer:
  def __init__(self):
  
  # initialize global variables
  self.ckbuttonstatus = IntVar()
  
  # set up main window
  self.top = Tk()
  self.top.geometry('355x125')
  self.top.title(appname)
  self.top.resizable(width='no', height='no')
  
  # set up menubar
  self.menubar = menu(self.top)
  self.top.config(menu = self.menubar)
  
  # set up file menu
  self.filemenu = Menu(self.menubar, tearoff = 0)
  self.filemenu.add_cascade(label="File", menu=self.filemenu)
  self.filemenu.add_checkbutton(label = "Click Me!", command = 
self.labelUpdate)
  self.filemenu.add_command(label = "Quit", command=self.top.quit)
  
  # set up main display area
  self.frame = Frame(self.top)
  self.frame.pack(fill=x)
  self.displaylabel=Label(self.frame, text=" ", font="Times 36 bold", 
relief="sunken")
  self.displaylabel.pack(side=BOTTOM, fill=X)
  
  def labelUpdate(self):
  self.status = self.ckbuttonstatus.get()
  self.labeltext = "Chekbutton status is: " + self.status
  self.displaylabel.config(text=labeltext)
  self.top.update()
  
if __name__ == '__main__':
 mainApp = timer()
 mainloop()
 

On Friday 04 March 2005 08:39 pm, Ronnie Betzen wrote:
> I've been trying to use IntVar() to update checkboxes using the Tkinter
> toolkit.  To date I haven't been successful getting it to work.  Evidently
> I'm missing some concept with regards to setting up my interface.  I've
> successfully run scripts by other people using IntVar() so I know my
> personal system is ok.
>
> Here is some code that causes me problems with IntVar().  Can someone
> enlighten this total newbie (python and programming both.) as to what I'm
> missing here?
>
> Thanks,
>
> Ron
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with IntVar()

2005-03-04 Thread Ronnie Betzen
I've been trying to use IntVar() to update checkboxes using the Tkinter 
toolkit.  To date I haven't been successful getting it to work.  Evidently 
I'm missing some concept with regards to setting up my interface.  I've 
successfully run scripts by other people using IntVar() so I know my personal
system is ok.

Here is some code that causes me problems with IntVar().  Can someone 
enlighten this total newbie (python and programming both.) as to what I'm 
missing here?

Thanks,

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Linked List

2005-03-04 Thread Jacob S.
I'm taking a shot in the dark and answering here.
Have you tried making a copy of the list, iterating over the copy, and 
changing the original based on the copy?

Jacob
Hi,
Any body has any idea on how to implement a linked
list in python?
Ordinary python lists are not quite the same. what i
need  is a list i can traverse through sequentially
without bothering about the indices, as another
process is continuously editing this list, by
inserting and deleting elements even as the list is
being traversed.
Shitiz

__
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-03-04 Thread Kent Johnson
Kevin wrote:
Hello all. I have just completed my very first python program just a
simple number guessing. I would like for someone to try it out if they
could and let me know how I did with it and where I could have
improved apon it. There are t files main.py and defs.py
I second Brian's comments about comments and white space. The comments make it very hard to pick out 
the actual code. Better if you can let the code speak for itself.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: Re: Q & A

2005-03-04 Thread Andrei
Chelan Farsight wrote on Fri, 4 Mar 2005 12:37:58 -0600:

> actions of Mr. Chui.  I simply wanted to make sure that I have joined
> the right list.  Are we allowed to ask total n00b questions on this
> list?  If not what level of understanding is presumed before someone
> should post a question?

The Tutor list is for beginners, which includes people who haven't
programmed before. I'd say it even includes homework where the student in
question has actually tried doing something and ran into a snag, but not in
the case where the student just posts a "solve this homework for me".

-- 
Yours,

Andrei

=
Real contact info (decode with rot13):
[EMAIL PROTECTED] Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Berkeley db incompatibility

2005-03-04 Thread Bill Campbell
I don't know that this is a tutor topic, but since I'm a python newbie,
I'll try.

Building python-2.4 with db-4.3.27 fails on an undefined enum, DB_LSTAT_ERR
resulting in no bsddb module.  It looks like the sleepycat folks decided to
break backwards compatibility by dropping this out of the enum.

I've tried google to find a fix, but haven't found anything yet.

Is there a recommended fix for this?

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
UUCP:   camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

The Constitution is a written instrument.  As such, its meaning
does not alter.  That which it meant when it was adopted, it
means now.
-- SOUTH CAROLINA v. US, 199 U.S. 437, 448 (1905)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Q & A

2005-03-04 Thread Chelan Farsight
Kent and Danny,
Thanks so much for the quick and warmhearted reply.
/whew
Just wanted to make sure.  I know there are lists specifically aimed
at advanced users and wanted to watch my p's and q's.
Well as I work my way through I am certain I will have questions and I
am glad I have found a place to help out.
Oh and rant away it can be kinda fun at times =)
Thanks again,
Chelan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Q & A

2005-03-04 Thread Danny Yoo


On Fri, 4 Mar 2005, Chelan Farsight wrote:

> Okay this is a real question I have and I am not trying to defend the
> actions of Mr. Chui.  I simply wanted to make sure that I have joined
> the right list.  Are we allowed to ask total n00b questions on this
> list?

Hi Chelan,


Yikes!  Newcomer questions are perfectly fine.

I'm sorry for the exasperated tone I used in my last message, and will try
to explain myself.

Let me clarify: if it's obvious that the questioner doesn't even care
about the question they are asking --- if someone is just trying to get us
to do homework so they can copy and paste it into some word processor ---
then I get annoyed.  (But I should have posted my rant off-list, so that
it didn't disrupt anyone else.)

If it looks like the questioner cares about the answer, and is doing other
things to learn more about the subject, then that's ok.


> If not what level of understanding is presumed before someone should
> post a question?

Any level of understanding is actually fine.  Personally, it's the human
intent of the questions that matters to me.  Neither of Chui's questions
had anything to do with Python.  If there's any real requirement about
questions, it's that it should at least have something to do with learning
how to program in Python.


> I just want to make sure that total newbies are welcome here.  If not
> then a reccomendation for another list would be greatly appreciated.

This list is for beginners and newcomers to Python and programming.  If
you have any questions, please feel free to ask them.  And, again, I
apologize about the earlier rant; I get emotional very easily.  *grin*

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Q & A

2005-03-04 Thread Kent Johnson
Chelan Farsight wrote:
Okay this is a real question I have and I am not trying to defend the
actions of Mr. Chui.  I simply wanted to make sure that I have joined
the right list.  Are we allowed to ask total n00b questions on this
list?  
Yes, this list is specifically for total n00bs and other beginners (and people who like to answer 
beginners' questions :-)

If not what level of understanding is presumed before someone
should post a question?
None. A reasonable level of *effort* is appreciated. You will get better results if you try 
something and ask for help when you get stuck, and if you take the time to write a clear question.

Again, please do not misunderstand, I have no qualms with *refusing*
to do someone's homework for them.  I just want to make sure that
total newbies are welcome here.  
Yes, definitely.
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Linked List

2005-03-04 Thread Danny Yoo


On Fri, 4 Mar 2005, Andrei wrote:

> Shitiz Bansal wrote on Fri, 4 Mar 2005 09:19:41 -0800 (PST):
>
> > Any body has any idea on how to implement a linked list in python?

There's a chapter on Linked Lists in "How to Think Like a Computer
Scientist":

http://www.ibiblio.org/obp/thinkCSpy/chap17.htm


You might also enjoy this post from a few years back:

http://mail.python.org/pipermail/tutor/2002-April/014073.html

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Programming challenge (C++ and Python)

2005-03-04 Thread Danny Yoo


On Fri, 4 Mar 2005, Liam Clarke wrote:

> ??? Why am I getting this one as new again?

Hi Liam,

This one is my fault.  As a mailing list administrator, I have to go
through stuff that's sitting in a moderation queue.  I'd been a little
derelict in my responsibility lately, and hadn't looked at the queue since
January.

I looked at it yesterday and started allowing some messages to come in ,
but I was careless enough not to notice some the questions that were
already posted to this list from back in January.

I apologize for this; I'll try to do a less careless job next time.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Re: Q & A

2005-03-04 Thread Chelan Farsight
Okay this is a real question I have and I am not trying to defend the
actions of Mr. Chui.  I simply wanted to make sure that I have joined
the right list.  Are we allowed to ask total n00b questions on this
list?  If not what level of understanding is presumed before someone
should post a question?
Again, please do not misunderstand, I have no qualms with *refusing*
to do someone's homework for them.  I just want to make sure that
total newbies are welcome here.  If not then a reccomendation for
another list would be greatly appreciated.
Thanks for your patience and help,
chelan


On Thu, 3 Mar 2005 22:58:31 -0800 (PST), Danny Yoo
<[EMAIL PROTECTED]> wrote:
> 
> [Meta note to other folks on the list: I'm sorry for letting this post
> through; I was rushing, and I should have been more careful when going
> through my moderation queue.]
> 
> 
> On Fri, 25 Feb 2005, liew choon chui wrote:
> 
> > Here are two question to need some solution.
> 
> Hi Lieu Choon Chui,
> 
> I do not want to be rude, but, bluntly speaking, you have to do your own
> work.  Asking us to do it for you is a bit insulting, and I hope you
> understand you've just made a terrible netiquette blunder.  Your homework
> is yours to solve.
> 
> Please read:
> 
> http://www.catb.org/~esr/faqs/smart-questions.html
> 
> If you have questions about Python, we will be happy to help you.  But
> don't dump homework questions on us and expect a useful response.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: Linked List

2005-03-04 Thread Andrei
Shitiz Bansal wrote on Fri, 4 Mar 2005 09:19:41 -0800 (PST):

> Any body has any idea on how to implement a linked
> list in python?

Perhaps like this:

>>> class node(object):
... def __init__(self, item, next=None):
... self.item = item
... self.next = next
>>> a = node('item a')
>>> b = node(3)
>>> c = node((3,4))
>>> d = node('last item')
>>> a.next = b
>>> b.next = c
>>> c.next = d
>>> mynode = a
>>> while mynode:
... print mynode.item
... mynode = mynode.next
item a
3
(3, 4)
last item

-- 
Yours,

Andrei

=
Real contact info (decode with rot13):
[EMAIL PROTECTED] Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Linked List

2005-03-04 Thread Shitiz Bansal
Hi,
Any body has any idea on how to implement a linked
list in python?
Ordinary python lists are not quite the same. what i
need  is a list i can traverse through sequentially
without bothering about the indices, as another
process is continuously editing this list, by
inserting and deleting elements even as the list is
being traversed.

Shitiz




__ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-03-04 Thread Brian van den Broek
Kevin said unto the world upon 2005-03-04 10:43:
Hello all. I have just completed my very first python program just a
simple number guessing. I would like for someone to try it out if they
could and let me know how I did with it and where I could have
improved apon it. There are t files main.py and defs.py
Thanks
Hi Kevin,
Though I am a learner, too, I have a few comments. They are more about 
style than substance.

1) A lot of your code comments get in the way of my reading and easily 
understanding the code. Consider:

.# leading `.'s to foil google groups and other whitespace stripping 
readers
.if play == '3': #If user picks 3
.print "\nHave a nice day!\n" #Tell them to have a nice day
.sys.exit() #Then exit the entire thing

I think this would be much easier to read if it were like:
.if play == '3':# If user picks 3
.print "\nHave a nice day!\n"   # Tell them to have a nice day
.sys.exit() # Then exit the entire thing
(Note that some people hate the comments along the side and would 
prefer them the precede the line(s) they comment on. I like the 2 
column approach, but that's just one duffer's view.)

But, even better would be:
.if play == '3':
.print "\nHave a nice day!\n"
.sys.exit()
Your comments are close to the canonical example of 'bad comments':
count += 1  # increment count by 1
Comments like this add nothing except squiggles to read on the screen 
or page. They just repeat the code; so, instead of helping, they are 
just noise. Comments are good for tricky bits, to explain just why 
some non-obvious chunk of code is there, or to remind the reader (who 
could well be you) why some particular approach was taken.

(Neatness counts ;-)
2) Whitespace is a good thing. Python needs it horizontally, but you 
can (and, IMHO, should) employ vertical whitespace to chunk up the 
code. Your code had this chunk:

.if play == '3': #If user picks 3
.print "\nHave a nice day!\n" #Tell them to have a nice day
.sys.exit() #Then exit the entire thing
.elif play == '2': #If user picks 2
.instruct() #Then lets call the instructions function
.elif play == '1': #If user picks 1
.game() #Then lets call the game function for the user to play
.elif play == '': #This is used is the menu leaves the screen 
so the user can get it back
.choice() #Bring back the menu
.else:
.print "\nYou need to pick 1, 2 or 3 or hit enter to see 
choices\n"

Try reading that and then this:
.if play == '3':
.print "\nHave a nice day!\n"
.sys.exit()
.
.elif play == '2':
.instruct()
.
.elif play == '1':
.game()
.
.elif play == '':  # I might have put a comment here but
.choice()  # the else clause below explains it.
.
.else:
.print "\nYou need to pick 1, 2 or 3 or hit enter to see 
choices\n"

Which one is easier to read? :-)
The separation between blocks doesn't matter too much when the blocks 
are short, but I still like it. Different strokes, though. But, if 
each block had, say 4 or 5 lines, it would be much easier for me to 
parse with the separation.

3) I've come to like informative dosctrings a lot. When you start 
using tools like pydoc on your own code, you will be glad you used 
them. (Plus, they cut down on the need for inline comments.)

and,
4) I'd make the yesno() function do a bit more work. So, combining 
these two points, where you have:

.def yesno(question):
."""Asks the use a yes or no question"""
.answer = None
.while answer not in ('y','ye','yes','n','no'):
.answer = raw_input(question).lower()
.if answer not in ('y','ye','yes','n','no'):
.print "Please enter Y or N"
.return answer
I have a utility function:
def yes_or_no(question):
.'''Asks the user the question; returns True for yes, False for no.
.
.question is used to prompt the user for raw_input. That input is
.put in lower case and compared to the values ['y', 'yes', 'n',
.'no']. If it matches a `yes' value, True is returned; if it
.matches a `no' value False is returned. If it matches none of
.these values, a report of what was entered and of valid inputs
.is printed and the user is reprompted until an acceptable value
.is entered.
.'''
.response = raw_input(question)
.while True:
.
.lresp = response.lower()
.
.if lresp == 'y' or lresp == 'yes':
.# adjust matching values to your tastes
.return True
.if lresp == 'n' or lresp == 'no':
.return False
.
.response = raw_input('''
.You entered: %s
.Valid inputs are `n', 'no', `y', and `yes' (any case).
.Please try again.
.%s
.''' %(response, question))
My code is a lot longer, but 1) it does 

[Tutor] (no subject)

2005-03-04 Thread Kevin
Hello all. I have just completed my very first python program just a
simple number guessing. I would like for someone to try it out if they
could and let me know how I did with it and where I could have
improved apon it. There are t files main.py and defs.py

Thanks

##

#!/usr/bin/python
#main.py
###
from defs import *
import sys
###

choice() #Lets call the main menu up for the user
#This is used to ask if you would like to keep playing#
while 1:
play = raw_input("What is your choice? ") #Aks use to enter a choice
from the menu
if play == '3': #If user picks 3
print "\nHave a nice day!\n" #Tell them to have a nice day
sys.exit() #Then exit the entire thing
elif play == '2': #If user picks 2
instruct() #Then lets call the instructions function
elif play == '1': #If user picks 1
game() #Then lets call the game function for the user to play
elif play == '': #This is used is the menu leaves the screen so the
user can get it back
choice() #Bring back the menu
else:
print "\nYou need to pick 1, 2 or 3 or hit enter to see 
choices\n"
#Let the user know that they can only pick 1, 2, 3 or just hit enter
and nothing else.

###
#defs.py
#
import random
import sys
###
#This is not used in the game yet
def yesno(question):
"""Asks the use a yes or no question"""
answer = None
while answer not in ('y','ye','yes','n','no'):
answer = raw_input(question).lower()
if answer not in ('y','ye','yes','n','no'):
print "Please enter Y or N"
return answer

#This is the guessing game#
def game():
"""This is the main part of the guessing game"""
tries = 5 #Set the number of tries to 5
guess = random.randrange(2)+1 #Computer picks a number from 1 to 20
while 1:
try:
answer = int(raw_input("What is your guess? ")) #Ask 
the user to
guess the number
if answer != guess: #Check to see if answer is not 
equal to guessed number 
tries -= 1 #if answer is wrong reduce the 
number of tries by 1
print "Thats not it, you only have %d tries 
left" %tries #Tell
user not right  answer
if tries == 0: #Check to see if user has run 
out of tries
print "\nYou lost this round!" #If no 
tries left let the user know
raw_input("\n[Hit Enter to 
Continue]\n") #Wait for user to go
back to main menu
choice() #Show main menu for user
break #Then break out of the loop
if answer == guess: #If the answer is equal to the 
guessed number
print "\nCongrats you just Won this round!!" 
#Tell the user he
just one in so many tries
raw_input("[Hit Enter to Continue]") #Wait for 
user to go back to main menu
choice() #Show main menu for user
break #Break out of the loop
except ValueError: #Lets make sure that the user is only 
typeing in
numbers and nothing else
print "\nYou can only use numbers\n" #Let user 
know they can only
use numbers

#This is the main menu for the game
def choice():
"""The main menu of the game"""
print """

#  #
#  NUMBER GUESSING GAME# 
#  #
# - Created by Kevin J #
# - [EMAIL PROTECTED]   #
#  #
# 1 - Play #
# 2 - instructions #
# 3 - Quit #
\n"""

#This is the instuctions on how to play the game that can be called
from the main menu
def instruct():
"""Instructions on how to play the
guessing game"""
print"""\n
HOW TO PLAY THE NUMBER GUESSING GAME

# To play this game all you need to do is guess a number from 1 to 20. #
# You will only have 5 tries to beat the game. Once you have beat the  #
# game or you have used up all of your 5 tries you will be sent back   #
# to the main screen were you can quit or start over again.#
##

[Tutor] Re: Newbie question.

2005-03-04 Thread Mike Hansen

Subject:
Re: [Tutor] Newbie question.
From:
Gwyn Evans <[EMAIL PROTECTED]>
Date:
Fri, 4 Mar 2005 09:37:21 +
To:
tutor@python.org
To:
tutor@python.org
On Fri, 28 Jan 2005 09:42:07 +0200, Adriaan Louw
<[EMAIL PROTECTED]> wrote:
 

I want to learn python as quick as possible, for web programming at first,
and applications later on. Any leads? 
   

Hi,
 I'd start with the basic python tutorials, then have a look at
something like CherryPy (http://www.cherrypy.org/) or Quixote
(http://www.quixote.ca/) for the initial web stuff - there are others,
too. Try & read around each a bit, e.g. web site/mailing lists, then
download & give ones you fancy a try.
 

I would politely disagree here. You need to walk before you can run. If 
you haven't done _any_ web programming before, it's probably best to do 
a small web app using just python's cgi module. I would think that 
CherryPy and Quixote are complex web tools/frameworks that I wouldn't 
recommend to someone new to web programming until they got their feet 
wet doing some basic web programming. After that, then explore more 
advanced web programming with CherryPy or Quixote.

If you have done some basic web programming in other languages, then 
ignore this message.

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] make an .exe

2005-03-04 Thread David Holland


Noel 
Thanks for that info, I did do a search for that but I could not find anything useful
Message: 3Date: Fri, 4 Mar 2005 10:11:51 +From: Max Noel <[EMAIL PROTECTED]>Subject: Re: [Tutor] Make a .exeTo: David Holland <[EMAIL PROTECTED]>Cc: tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=US-ASCII; format=flowedOn Mar 4, 2005, at 09:26, David Holland wrote:> It Completed with these errors :-> The following modules appear to be missing {'AppKit',> 'Foundation', 'objc']Now that's really weird. AppKit and Foundation are Mac OS X frameworks, and objc stands for Objective-C, the language in which they're written and which you're supposed to use to develop applications that use them.However, since you're on a Windows box, I have no idea why Python is trying to involve them.-- Maxmaxnoel_fr at yahoo dot fr -- ICQ #85274019"Look at you hacker... A pathetic creature of meat and bone, pantin!
 g and
 sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"--___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutorEnd of Tutor Digest, Vol 13, Issue 13*Send instant messages to your online friends http://uk.messenger.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question.

2005-03-04 Thread Kent Johnson
Adriaan Louw wrote:
I want to learn python as quick as possible, for web programming at 
first, and applications later on. Any leads?
There are many tutorials available, see 
http://www.python.org/doc/Intros.html for one list.
 
I have an xp windows and ms office machine. (I'm considering linux, but 
it's a bit daunting?)
 
How do I run python scripts? Nothing happens when I double-click the 
filename, in IDLE I only get the code, and not what it does.
You can run the program in IDLE using Run / Run Module (F5).
I know that cgi-scripts must be called from html. I want to to use a 
python server for testing. Which is thebest, and how?
There are many options for web programming, one list is here:
http://www.python.org/moin/WebProgramming
In addition to CherryPy and Quixote, Snakelets is a complete web solution that is intended to be 
easy to learn.
Twisted and Zope are perhaps the most comprehensive solutions.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Make a .exe

2005-03-04 Thread Max Noel
On Mar 4, 2005, at 09:26, David Holland wrote:
It Completed with these errors :-
The following modules appear to be missing {'AppKit',
'Foundation', 'objc']
	Now that's really weird. AppKit and Foundation are Mac OS X 
frameworks, and objc stands for Objective-C, the language in which 
they're written and which you're supposed to use to develop 
applications that use them.
	However, since you're on a Windows box, I have no idea why Python is 
trying to involve them.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Proxy

2005-03-04 Thread Gwyn Evans
On Sat, 29 Jan 2005 16:23:29 -0800 (PST), Ali Polatel
<[EMAIL PROTECTED]> wrote:
> is it possible to connect to somewhere through a proxy while using sockets
> module of Python to connect? If yes can you show me some basic examples? 

Yes, but not auto-magically.  If you want to stay at the sockets
level, you'll have to handle all the proxy interaction yourself.  I'd
suggest instead looking at the urllib2 module, as I believe that you
can use that (via a Request object?) to handle the proxy for you.

/Gwyn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question.

2005-03-04 Thread Gwyn Evans
On Fri, 28 Jan 2005 09:42:07 +0200, Adriaan Louw
<[EMAIL PROTECTED]> wrote:
> I want to learn python as quick as possible, for web programming at first,
> and applications later on. Any leads? 

Hi,
  I'd start with the basic python tutorials, then have a look at
something like CherryPy (http://www.cherrypy.org/) or Quixote
(http://www.quixote.ca/) for the initial web stuff - there are others,
too. Try & read around each a bit, e.g. web site/mailing lists, then
download & give ones you fancy a try.

> I have an xp windows and ms office machine. (I'm considering linux, but it's
> a bit daunting?) 

  No need to in most cases.

> How do I run python scripts? Nothing happens when I double-click the
> filename, in IDLE I only get the code, and not what it does. 

  Command line is one way.  Make sure your PATH (My
Computer/Propeties/Advanced/Environment, or similar) has the Python
folder in it then try "python "

  You can also try Explorer/Tools/Folder Options/File Types/.PY to
associate .py files with the python.exe file.

Gwyn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Make a .exe

2005-03-04 Thread David Holland
I have a game I wrote using python and pygame that I am trying to change into a .exeI created the script setup.py which has this code :- setup.pyfrom distutils.core import setupimport py2exesetup(console=["Gamename.py"])
In a dos prompt with all the files there I ran :-python setup.py py2exe
It Completed with these errors :-The following modules appear to be missing {'AppKit','Foundation', 'objc'] but  the  game.exe was createdHowever when I try to run it I get
 !
  &nb
 sp; File "livewires3\games.pyc", line 585 in init_textFile "livewires3\games.pyc", line 585 in init_textFatal Python error:  SegmentationFault.Livewires3 is a modified version of a pygamewrapper. http://www.livewires.org.uk/python/ is where theoriginal is.The book I used to learn python "python programmingfor the absolute beginner" has a modified version ofthis with some functionality added and !
 taken
 away.I modified the wrapper so that has the functionalityof both wrappers.  Any ideas about how to fix it ?
Thanks in advance
DavidSend instant messages to your online friends http://uk.messenger.yahoo.com ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor