Re: [Tutor] Learning books

2005-12-23 Thread w chun
On 12/20/05, Richard <[EMAIL PROTECTED]> wrote:
> Afternoon all, My son asked me what books I would like for Christmas
> this year. So what would you recommend?
>
> I am a beginner here.


hi richard,

welcome to the list.  are you a beginner to Python (but have
programming experience), a beginner to programming *and* Python, or
other?

if you are new to programming period, then congratulations for finding
Python and this mailing list... you've done your homework.  good books
to start here include:
1) michael dawson's python programming for the absolute beginner
2) alan (gauld)'s learn to program
and as a good beginner's reference:
3) chris fehily's quick start guide

if you're new to programming from a computer science student's
perspective, there's:
1) john zelle's python programming: intro to computer science

if you're new to programming from a graphic artist/designer or
multimedia point-of-view, try:
1) mark guzdial's introduction to computing and programming in python

if you're already a programmer and want to pick up Python as quickly
as possible:
1) Core Python Programming by yours truly, however 2nd ed
won't come out until Summer 2006, and i myself am having a hard time
getting new copies of the 1st ed
2) mark pilgrim's dive into python
3) magnus hetland's beginning python
4) ascher and lutz learning python if you have a background in C programming

good luck, and feel free to ask more specific questions about what
you're looking for.

cheers,
- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] assert

2005-12-23 Thread shivayogi kumbar
sir,
   I would like to know about 'asser't keyword how it works in the
fallowing program
   class myClass:
count = 0
 def __init__(self):
  myClass.count = myClass.count + 1
  def __del__(self):
   myClass.count =myClass.count -1
assert myClass.count>0
  def howmany(self):
   return myClass.count

 >>>a=myClass()
>>>b=myClass()
>>>a.howmany()
>>>del b
>>>del a
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assert

2005-12-23 Thread python-tutor
Try this:

>>>a=myClass()
>>>b=myClass()
>>>a.howmany()
>>>a.count=0
>>>del a

Does this help clear things up?


Todd Maynard

On Friday 23 December 2005 06:18, shivayogi kumbar wrote:
> class myClass:
>                         count = 0
>                          def __init__(self):
>                                   myClass.count = myClass.count + 1
>                           def __del__(self):
>                                    myClass.count =myClass.count -1
>                                     assert myClass.count>0
>                           def howmany(self):
>                                    return myClass.count
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assert

2005-12-23 Thread Kent Johnson
shivayogi kumbar wrote:
> sir,
>I would like to know about 'asser't keyword how it works in the
> fallowing program

I'm not sure what the question is. Do you not understand assert at all 
or is there something about how this program works that you don't 
understand?

assert is documented here:
http://docs.python.org/ref/assert.html#l2h-461

Simplified a little,
   assert myClass.count>0
is essentially the same as
   if not myClass.count>0: raise AssertionError

assert is usually used to verify an assumption about the state of a 
program at some point. The usage here doesn't really make sense, as 
myClass.count can legitimately be 0. A better assertion would be
   assert myClass.count>=0
since you would expect this to always be true.

Kent

>class myClass:
> count = 0
>  def __init__(self):
>   myClass.count = myClass.count + 1
>   def __del__(self):
>myClass.count =myClass.count -1
> assert myClass.count>0
>   def howmany(self):
>return myClass.count
> 
>  >>>a=myClass()
> 
b=myClass()
a.howmany()
del b
del a
> 
> ___
> 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] Input checking [letters or numbers]

2005-12-23 Thread Panagiotis Atmatzidis
Hello,

Can someone provide me with an error checking example about an x
variable that needs to be number only? I used something like:

 def useridf():
 print ""
 print "WARNING: If you don't understand why this must be unique,
exit and read the manual."
 print ""
 userid = input("x : ")

I know that "input" accepts only numbers, but I don't want the program
to break if someone puts other chars in it. I want to, print "Only
numbers are accepted." which is easy. But still I can't understand how
to do the check using if/elif/else statements.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread bob
At 10:15 AM 12/23/2005, Panagiotis Atmatzidis wrote:
>Hello,
>
>Can someone provide me with an error checking example about an x
>variable that needs to be number only? I used something like:
>
>  def useridf():
>  print ""
>  print "WARNING: If you don't understand why this must be unique,
>exit and read the manual."

You ask the user to exit but you don't tell him how to do that!

>  print ""
>  userid = input("x : ")
>
>I know that "input" accepts only numbers

How did you "know" that? Try this:
print input("x ; ")
and enter "Hello world"

Truth is input() "accepts" anything and attempts to evaluate it as a 
Python expression. If that fails it raises an exception.

You should use raw_input() instead. This takes any input and returns 
it as a character string.
x = raw_input("x : ")
if x.isdigit(): # ensure input is a number
   y = int(x) # convert to integer
else:
   print 'Boo"

>, but I don't want the program
>to break if someone puts other chars in it. I want to, print "Only
>numbers are accepted." which is easy. But still I can't understand how
>to do the check using if/elif/else statements.

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


Re: [Tutor] assert

2005-12-23 Thread python-tutor

Shivayogi,

Sorry my last e-mail wasn't very helpful.  

Better would have been:

>>> a=myClass()
>>> b=myClass()
>>> a.howmany()
>>> myClass.count=0
>>> del a
which will (hopefully)  give you something like: 

Exception exceptions.AssertionError:  in > ignored

Assert is commonly used as a sanity check for things that you always expect to 
be true.

Hope this helps,

Todd Maynard


On Friday 23 December 2005 06:55, [EMAIL PROTECTED] wrote:
> Try this:
> >>>a=myClass()
> >>>b=myClass()
> >>>a.howmany()
> >>>a.count=0
> >>>del a
>
> Does this help clear things up?
>
>
> Todd Maynard
>
> On Friday 23 December 2005 06:18, shivayogi kumbar wrote:
> > class myClass:
> >                         count = 0
> >                          def __init__(self):
> >                                   myClass.count = myClass.count + 1
> >                           def __del__(self):
> >                                    myClass.count =myClass.count -1
> >                                     assert myClass.count>0
> >                           def howmany(self):
> >                                    return myClass.count
>
> ___
> 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] Input checking [letters or numbers]

2005-12-23 Thread Panagiotis Atmatzidis
Hello there,

Thank you for the prompt response.

On 12/23/05, bob <[EMAIL PROTECTED]> wrote:
> At 10:15 AM 12/23/2005, Panagiotis Atmatzidis wrote:
> >Hello,
> >
> >Can someone provide me with an error checking example about an x
> >variable that needs to be number only? I used something like:
> >
> >  def useridf():
> >  print ""
> >  print "WARNING: If you don't understand why this must be unique,
> >exit and read the manual."
>
> You ask the user to exit but you don't tell him how to do that!
>
> >  print ""
> >  userid = input("x : ")
> >
> >I know that "input" accepts only numbers
>
> How did you "know" that? Try this:
> print input("x ; ")
> and enter "Hello world"

OSX atma ~ $ python
Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("x: ")
x: hello world
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1
hello world
 ^
SyntaxError: unexpected EOF while parsing

Just did.. and as you can see I get an error. I know because I read so
in the tutorial I mentioned before.. I mean that it says so.. now I am
taking the first steps into programming, hence I don't really know if
there's another reason for input to break upon chars.

>>> x = input("x: ")
x: 12
>>>

>
> Truth is input() "accepts" anything and attempts to evaluate it as a
> Python expression. If that fails it raises an exception.

Okay.

>
> You should use raw_input() instead. This takes any input and returns
> it as a character string.

I already use raw_input for alphanumeric characters.

> x = raw_input("x : ")
> if x.isdigit(): # ensure input is a number
>y = int(x) # convert to integer
> else:
>print 'Boo"

Thank you for the sample code.

>
> >, but I don't want the program
> >to break if someone puts other chars in it. I want to, print "Only
> >numbers are accepted." which is easy. But still I can't understand how
> >to do the check using if/elif/else statements.
>
>

Best Regards,

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


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread Danny Yoo
> x = raw_input("x : ")
> if x.isdigit(): # ensure input is a number
>y = int(x) # convert to integer
> else:
>print 'Boo"


Hello Bob and Panagiotis,

It might be good to make this number-reading thing a function, just to
make it easier to reuse (and test!) it.  Let's call this input_number()
for the moment.

###
def input_number(prompt):
"""Reads an integer from the next line of input."""
while 1:
x = raw_input(prompt)
if x.isdigit():
return int(x)
else:
print 'Boo'
###


Does this work?  Let's try it informally:

##
>>> input_number('number please: ')
number please: 1
1
>>> input_number('number please: ')
number please: 1234
1234
>>> input_number('number please: ')
number please: 1st
Boo
number please: 74
74
>>>
##

I added one more behavior so that input_number continues to ask until it's
satisified by a number.  Hope this helps!

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


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread Panagiotis Atmatzidis
Hello Dany :-)

On 12/23/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
> > x = raw_input("x : ")
> > if x.isdigit(): # ensure input is a number
> >y = int(x) # convert to integer
> > else:
> >print 'Boo"
>
>
> Hello Bob and Panagiotis,
>
> It might be good to make this number-reading thing a function, just to
> make it easier to reuse (and test!) it.  Let's call this input_number()
> for the moment.
>
> ###
> def input_number(prompt):
> """Reads an integer from the next line of input."""
> while 1:
> x = raw_input(prompt)
> if x.isdigit():
> return int(x)
> else:
> print 'Boo'
> ###
>
>
> Does this work?  Let's try it informally:
>
> ##
> >>> input_number('number please: ')
> number please: 1
> 1
> >>> input_number('number please: ')
> number please: 1234
> 1234
> >>> input_number('number please: ')
> number please: 1st
> Boo
> number please: 74
> 74
> >>>
> ##
>
> I added one more behavior so that input_number continues to ask until it's
> satisified by a number.  Hope this helps!

Yes, it really helps a lot. Now I can proceed with my script!!

Thank you for the reply,

Best Regards,

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


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread Panagiotis Atmatzidis
Yeah works you're right. :-)

On 12/23/05, bob <[EMAIL PROTECTED]> wrote:
> At 11:16 AM 12/23/2005, Panagiotis Atmatzidis wrote:
> >Hello there,
> >
> >Thank you for the prompt response.
> >
> >On 12/23/05, bob <[EMAIL PROTECTED]> wrote:
> >[snip]
> > > print input("x ; ")
> > > and enter "Hello world"
> >
> > >>> x = input("x: ")
> >x: hello world
> >Traceback (most recent call last):
> >   File "", line 1, in ?
> >   File "", line 1
> > hello world
> >  ^
> >SyntaxError: unexpected EOF while parsing
> >
> >Just did.. and as you can see I get an error. I know because I read so
> >in the tutorial I mentioned before.. I mean that it says so.. now I am
> >taking the first steps into programming, hence I don't really know if
> >there's another reason for input to break upon chars.
>
> Enter "hello world" including the quotes.
> input expects a Python expression.
> hello world is not a Python expression
> "hello world" is
> [snip]
>
>


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


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread bob
At 11:16 AM 12/23/2005, Panagiotis Atmatzidis wrote:
>Hello there,
>
>Thank you for the prompt response.
>
>On 12/23/05, bob <[EMAIL PROTECTED]> wrote:
>[snip]
> > print input("x ; ")
> > and enter "Hello world"
>
> >>> x = input("x: ")
>x: hello world
>Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 1
> hello world
>  ^
>SyntaxError: unexpected EOF while parsing
>
>Just did.. and as you can see I get an error. I know because I read so
>in the tutorial I mentioned before.. I mean that it says so.. now I am
>taking the first steps into programming, hence I don't really know if
>there's another reason for input to break upon chars.

Enter "hello world" including the quotes.
input expects a Python expression.
hello world is not a Python expression
"hello world" is
[snip] 

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


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread Panagiotis Atmatzidis
On 12/23/05, Panagiotis Atmatzidis <[EMAIL PROTECTED]> wrote:
> Hello Dany :-)
>
> On 12/23/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
[...]
> >
> >
> > Hello Bob and Panagiotis,
> >
> > It might be good to make this number-reading thing a function, just to
> > make it easier to reuse (and test!) it.  Let's call this input_number()
> > for the moment.
> >
> > ###
> > def input_number(prompt):
> > """Reads an integer from the next line of input."""
> > while 1:
> > x = raw_input(prompt)
> > if x.isdigit():
> > return int(x)
> > else:
> > print 'Boo'
> > ###
[...]
> > I added one more behavior so that input_number continues to ask until it's
> > satisified by a number.  Hope this helps!
>
> Yes, it really helps a lot. Now I can proceed with my script!!
[...]

Another newbe question! I use "while True: " to evaluate an
expression, I see that you used while 1: .. what's the diffrence if
any?!
--
Panagiotis
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input checking [letters or numbers]

2005-12-23 Thread Kent Johnson
Panagiotis Atmatzidis wrote:
> Hello,
> 
> Can someone provide me with an error checking example about an x
> variable that needs to be number only? I used something like:
> 
>  def useridf():
>  print ""
>  print "WARNING: If you don't understand why this must be unique,
> exit and read the manual."
>  print ""
>  userid = input("x : ")
> 
> I know that "input" accepts only numbers, but I don't want the program
> to break if someone puts other chars in it. I want to, print "Only
> numbers are accepted." which is easy. But still I can't understand how
> to do the check using if/elif/else statements.

Another way to do this is to use raw_input() to get the input as a 
string, then just try to convert it to an int and catch any exception. 
This also works well encapsulated into a function:

def getInt(prompt):
   while 1:
 s = raw_input(prompt)
 try:
   return int(s)
 except ValueError:
   print 'Only numbers are accepted'

This approach will accept negative numbers as well as positive:

  >>> def getInt(prompt):
  ...   while 1:
  ... s = raw_input(prompt)
  ... try:
  ...   return int(s)
  ... except ValueError:
  ...   print 'Only numbers are accepted'
  ...
  >>> getInt('x: ')
x: ae
Only numbers are accepted
x: -4
-4

Kent

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


Re: [Tutor] Learning books

2005-12-23 Thread Richard
First of thanks for all the great input from everyone!!!

Okay, so I have been reading some of the tutorials around the net on 
Python. great stuff I might add but I am getting all confused with the 
TCL, xwwidgets etc. I want to be able to program and I am just using the 
standard IDE that comes with Python. Am I on the right track? Or I am 
better off using a different one or ??? I see that some are someting 
with  C++ but heck, I just want to learn Python for now. I do want the 
widgets to look nice sure. HELP!

Thanks in advance and Happy Holidays!!

Richard

P.S. I think I am getting one or two of the recomended books for 
Christmas! (cant wait!)

nephish wrote:

>Learning Python by O'Reilly,
>got me started after realizing that Programming Python by O'Reilly was a
>tad over me head.
>
>i am new here too.
>
>On Tue, 2005-12-20 at 14:46 -0600, Richard wrote:
>  
>
>>Afternoon all, My son asked me what books I would like for Christmas 
>>this year. So what would you recommend?
>>
>>I am a beginner here.
>>
>>
>>Thanks
>>
>>
>>Richard
>>___
>>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] Input checking [letters or numbers]

2005-12-23 Thread bob
At 11:28 AM 12/23/2005, Panagiotis Atmatzidis wrote:
>On 12/23/05, Panagiotis Atmatzidis <[EMAIL PROTECTED]> wrote:
> > Hello Dany :-)
> >
> > On 12/23/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
>[...]
> > >
> > >
> > > Hello Bob and Panagiotis,
> > >
> > > It might be good to make this number-reading thing a function, just to
> > > make it easier to reuse (and test!) it.  Let's call this input_number()
> > > for the moment.
> > >
> > > ###
> > > def input_number(prompt):
> > > """Reads an integer from the next line of input."""
> > > while 1:
> > > x = raw_input(prompt)
> > > if x.isdigit():
> > > return int(x)
> > > else:
> > > print 'Boo'
> > > ###
>[...]
> > > I added one more behavior so that input_number continues to ask 
> until it's
> > > satisified by a number.  Hope this helps!
> >
> > Yes, it really helps a lot. Now I can proceed with my script!!
>[...]
>
>Another newbe question! I use "while True: " to evaluate an 
>expression, I see that you used while 1: .. what's the diffrence if any?!

In this case, no difference. True and False are Python boolean 
constants, and also a subset of integer. So one may print True + 1 and see 2.

Conditional statements (while, if, elif) and the if clause of list 
comprehensions and generator expressions expect an expression that 
will be treated as True if not empty and False if empty. From the 
L:angRef: "In the context of Boolean operations, and also when 
expressions are used by control flow statements, the following values 
are interpreted as false: None, numeric zero of all types, empty 
sequences (strings, tuples and lists), and empty mappings 
(dictionaries). All other values are interpreted as true."

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


Re: [Tutor] Learning books

2005-12-23 Thread Nick Lunt
Hi Richard,

I myself just about know enough python to help me in my job occasionally and
to do some cool little hobby projects.
When it comes to creating GUI's for my programs I always use pythoncard, see
here www.pythoncard.org .

It's very simple to use, and the tutorials on their site will have you up
and running in no time.
It's based on wxpython but you don't need to know wxpython to use it at all,
unless pythoncard itself does not implement some functionality that you
desire.

The pythoncard mailing list is also very low volume and very helpful.

As a side note, I am the senior unix admin for a uk financial corp and I
know very well that learning perl would be the best 'prospective' language
for me to get to grips with, but no matter what issue I come up with at work
(or home) python is always, and I truly mean always, the better option.

I wish you good luck with your python learning experience, and I'm sure that
you will find it's also a very cool language to use. I can't help but feel
that it is inevitable that it will eventually overtake perl as the scripting
language of choice.

I hope none of that went too far off topic :)

Nick .


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Richard
> Sent: 23 December 2005 20:05
> Cc: tutor
> Subject: Re: [Tutor] Learning books
>
>
> First of thanks for all the great input from everyone!!!
>
> Okay, so I have been reading some of the tutorials around the net on
> Python. great stuff I might add but I am getting all confused with the
> TCL, xwwidgets etc. I want to be able to program and I am just using the
> standard IDE that comes with Python. Am I on the right track? Or I am
> better off using a different one or ??? I see that some are someting
> with  C++ but heck, I just want to learn Python for now. I do want the
> widgets to look nice sure. HELP!
>
> Thanks in advance and Happy Holidays!!
>
> Richard
>
> P.S. I think I am getting one or two of the recomended books for
> Christmas! (cant wait!)
>
> nephish wrote:
>
> >Learning Python by O'Reilly,
> >got me started after realizing that Programming Python by O'Reilly was a
> >tad over me head.
> >
> >i am new here too.
> >
> >On Tue, 2005-12-20 at 14:46 -0600, Richard wrote:
> >
> >
> >>Afternoon all, My son asked me what books I would like for Christmas
> >>this year. So what would you recommend?
> >>
> >>I am a beginner here.
> >>
> >>
> >>Thanks
> >>
> >>
> >>Richard
> >>___
> >>Tutor maillist  -  Tutor@python.org
> >>http://mail.python.org/mailman/listinfo/tutor
> >>
> >>
> >
> >
> >
> >
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.14.5/212 - Release Date: 23/12/2005
>
>

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