Re: [Tutor] Newbie question: programs not printing

2016-03-10 Thread Alan Gauld
On 10/03/16 13:33, Patrick Craine wrote:

> I downloaded Python 2.7.11 but for some reason it seems that it's not
> responding the way it¹s supposed to. I haven¹t been able to figure out the
> problem. I¹m on Mac OSX 10.11.3.

You probably didn't need to download Python because it is
installed by default on a Mac. Not to worry.

> Here¹s an example of what¹s happening:
> 
 x = int(raw_input('Enter an integer: '))
> if x%2 == 0:
> print 'Even'
> else:
> print 'Odd'
> if x%3 != 0:
> print 'And not divisible by 3'
> Enter an integer: 3


Now that looks very strange to me. It starts off with
the Python  >>> prompt but you should have got the
prompt immediately after the first line not at the end.
How are you entering the text, are you using the command
line tool in a Terminal? Or are you using an IDE like IDLE?

Marc has also commented on the lack of indentation(spacing).
Python is quite fussy about indenting code you need to
follow the visual layout from your tutor.

> When I put the integer in, I understand it¹s supposed to return ³odd² or
> ³even,² but it¹s not giving me anything.

That's because somehow the prompt is happening after
you have already executed all the logic code. If I
enter it on my (Linux) PC I get:

>>> x = int(raw_input('Enter an integer: '))
Enter an integer: 3
>>> if x%2 == 0:
...print 'Even'
... else:
...print 'Odd'
...
Odd
>>> if x%3 != 0:
...print 'And not divisible by 3'
...
>>>

Can you see the differences?
The input prompt appears right at the top.

> Also, at the top of the shell I¹m getting this message:
> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
> Visit http://www.python.org/download/mac/tcltk/ for current information.

Just ignore that for now, it only affects you once you
get to writing GUIs, which is a long way down the road yet ;-)

The other possible way to run your code is to type it all
into a file using Textedit (or some other text editor,
not a word processor) and save it as plain text in a
folder of your choice (but a new one for your programs
might be a good idea!) as a file called something
like testnum.py

You can then run the file by starting the Terminal application.
Then drag the folder you used to save the file into the Terminal
(If I recall correctly that should change the active Terminal
folder to that one! If not, type cd followed by the folder path)
Then type, at the prompt:

python testnum.py

Hopefully that works.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question: programs not printing

2016-03-10 Thread Marc Tompkins
On Thu, Mar 10, 2016 at 5:33 AM, Patrick Craine 
wrote:

> >>> x = int(raw_input('Enter an integer: '))
> if x%2 == 0:
> print 'Even'
> else:
> print 'Odd'
> if x%3 != 0:
> print 'And not divisible by 3'
> Enter an integer: 3
> >>>
>
> It could be your email program that's messing with your indentation, but
to me it looks like you're not indenting at all.  And that would be a
problem - Python is whitespace-aware, and indentation levels are crucial.
Try this (if, that is, MY indentation doesn't get trashed!):

if x%2 == 0:
print 'Even'
else:
print 'Odd'
if x%3 != 0:
print 'And not divisible by 3'




0
viruses found. www.avast.com

<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question

2015-11-11 Thread Mark Lawrence

On 11/11/2015 19:38, George Henry wrote:

How do I find a site to download Python for Windows that includes a Toolbar?

I'm using Windows 8.1  Have tried installing Python 3.4.2 but notice that
the Python shell does not include a tool bar (i.e. File, Edit, Shell, Debug,
etc.).

Help please.

Thanks!



So IDLE is not good enough for you?  I'll let you find it as it's part 
of the standard library, i.e. you've all ready downloaded it.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question

2015-11-11 Thread Albert-Jan Roskam
Hi,

(Sorry for top-postin - I am using my phone).

You can try Spyder IDE, it is part of Anaconda and Python(x, y): 
https://pythonhosted.org/spyder/installation.html#installing-on-windows-vista-7-8-10

Regards,
Albert-Jan

> From: gfhenry1...@gmail.com
> To: tutor@python.org
> Date: Wed, 11 Nov 2015 11:38:47 -0800
> Subject: [Tutor] Newbie Question
> 
> How do I find a site to download Python for Windows that includes a Toolbar?
> 
> I'm using Windows 8.1  Have tried installing Python 3.4.2 but notice that
> the Python shell does not include a tool bar (i.e. File, Edit, Shell, Debug,
> etc.).
> 
>  
> 
> Help please.
> 
>  
> 
> Thanks!
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question. Is it possible to run/call a python2.7 program and reference results from/in python3.3?

2013-09-13 Thread Alan Gauld

On 13/09/13 15:59, Paul Smith wrote:


So there are many tools out there but mechanize and scrapy 3rd party
modules seem to produce the best results; however nothing like these
exist for Python3. I get close but cannot produce the clean simple url
results in python3


Yes that's the biggest barrier to python 3 adoption. There are
just too many tools that have not been ported yet.



But now go do the same in python3? I am stumped...


You can do it but it's a rewrite with other modules.


So can one call the python27 program and use results in python33?


Yes via the subprocess module. You can execute any program that 
reads/writes to stdin/out and access the output. Its not exactly

pretty but it works.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-30 Thread Tommy Kaas
Thanks for the explanation. It's clearer now.
Tommy

Tommy Kaas tommy.k...@kaasogmulvad.dk wrote

   for row in soup('table', {'class' : 'spad'})[0].tbody('tr'):
 
 Do you understand the syntax from a Python point of view?

 No. That's the problem.


OK, I'll assume you understand the basic for loop structure
and focus on the function call:

soup('table', {'class' : 'spad'})[0].tbody('tr')

Ignore the bit at the end for now:

soup('table', {'class' : 'spad'})

Thats a call to a function taking a string and a dictionary as 
arguments.
The string says we want to look for table tags. And the dictionary 
says
we want tables that have an attribute class with a value spad.
Is that bit clear?

Then we add an index [0] to get the first table.

Finally we call tbody(tr) to extract the tr tags from the table.
The for loop thus iterates over the rows of the first table with 
class=spad.

There might be slightly more to it than that, its a long time since I
played with BS...

 Which help file?
Well, maybe not a file, but the text produced by typing: 
help(BeautifulSoup)

Ah, in that case you should definitely read the tutorial.

http://www.crummy.com/software/BeautifulSoup/documentation.html

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 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


Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Alan Gauld


Tommy Kaas tommy.k...@kaasogmulvad.dk wrote


for row in soup('table', {'class' : 'spad'})[0].tbody('tr'):

The example works fine, and I can change it a bit and it still 
works. But I
simply don't understand how I am supposed to the fourth line - after 
for
row in soup. I can clearly see it defines the area I want to 
scrape, but

how is the syntax build?


Do you understand the syntax from a Python point of view?


that information myself? I have tried to read the help-file of
BeautifulSoup, but found nothing there.


Which help file?
There is a fairly good tutorial for Beautiful Soup here:

http://www.crummy.com/software/BeautifulSoup/documentation.html

Is that the one you meant?

Did you find the section Searching By CSS class?

If so we need more specific questionws about what you don't 
understand.

If not, try reading it and then come back for more... :-)

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] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Tommy Kaas
-Oprindelig meddelelse-
Fra: tutor-bounces+tommy.kaas=kaasogmulvad...@python.org
[mailto:tutor-bounces+tommy.kaas=kaasogmulvad...@python.org] På vegne af
Alan Gauld
Sendt: 28. juli 2010 20:00
Til: tutor@python.org
Emne: Re: [Tutor] Newbie question - syntax - BeautifulSoup


Tommy Kaas tommy.k...@kaasogmulvad.dk wrote

 for row in soup('table', {'class' : 'spad'})[0].tbody('tr'):

 The example works fine, and I can change it a bit and it still 
 works. But I
 simply don't understand how I am supposed to the fourth line - after 
 for
 row in soup. I can clearly see it defines the area I want to 
 scrape, but
 how is the syntax build?

Do you understand the syntax from a Python point of view?

No. That's the problem.


 that information myself? I have tried to read the help-file of
 BeautifulSoup, but found nothing there.

Which help file?

Well, maybe not a file, but the text produced by typing: help(BeautifulSoup)



There is a fairly good tutorial for Beautiful Soup here:

http://www.crummy.com/software/BeautifulSoup/documentation.html

Is that the one you meant?

Did you find the section Searching By CSS class?

If so we need more specific questionws about what you don't 
understand.
If not, try reading it and then come back for more... :-)

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


Re: [Tutor] Newbie question - syntax - BeautifulSoup

2010-07-28 Thread Alan Gauld

Tommy Kaas tommy.k...@kaasogmulvad.dk wrote


  for row in soup('table', {'class' : 'spad'})[0].tbody('tr'):

Do you understand the syntax from a Python point of view?

No. That's the problem.



OK, I'll assume you understand the basic for loop structure
and focus on the function call:

soup('table', {'class' : 'spad'})[0].tbody('tr')

Ignore the bit at the end for now:

soup('table', {'class' : 'spad'})

Thats a call to a function taking a string and a dictionary as 
arguments.
The string says we want to look for table tags. And the dictionary 
says

we want tables that have an attribute class with a value spad.
Is that bit clear?

Then we add an index [0] to get the first table.

Finally we call tbody(tr) to extract the tr tags from the table.
The for loop thus iterates over the rows of the first table with 
class=spad.


There might be slightly more to it than that, its a long time since I
played with BS...


Which help file?
Well, maybe not a file, but the text produced by typing: 
help(BeautifulSoup)


Ah, in that case you should definitely read the tutorial.

http://www.crummy.com/software/BeautifulSoup/documentation.html

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 maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Kent Johnson
2008/10/16 Emad Nawfal (عماد نوفل) [EMAIL PROTECTED]:

 It works fine. It seems that in the file you have there are lines whose
 length is less than you should expect

Yes, my guess is there is a blank line in the file.

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


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Emad Nawfal (عماد نوفل)
On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. [EMAIL PROTECTED]wrote:

 Hi,

 I feel very stupid, but I am stuck. I could try some workaround, but I want
 to understand what I am doing wrong.

 The line:

 for line in open(parameterfile).readlines( ):
print line.split()# trouble line


 The trouble line works fine in this example. It prints
 what I want, something which looks like lists of words:

 ['CT', 'CT', '268.0', '1.529']...  etc.

 However, if I want to manipulate the individual list elements, I run into
 trouble. While

 print line.split()[0]

 still works, (it yields CT  - first element),

 however,

 print line.split()[1]

 gives error:

 File readatoms.py, line 103, in module
print line.split()[1]
 IndexError: list index out of range

 Could you please tell me what's wrong. (I come from Perl background so
 Python seems out-of-the-body experience to me).

 Sincerely,

 Vis


Here is a solution:
 for line in open('DBAN1001.txt').readlines():
... line = line.split()
... if len(line)  1: # This is what makes it work for me.
... print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.















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




-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Emad Nawfal (عماد نوفل)
Here is a solution:
 for line in open('DBAN1001.txt').readlines():
... line = line.split()
... if len(line)  1: # This is what makes it work for me.
... print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.


On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. [EMAIL PROTECTED]wrote:

 Hi,

 I feel very stupid, but I am stuck. I could try some workaround, but I want
 to understand what I am doing wrong.

 The line:

 for line in open(parameterfile).readlines( ):
print line.split()# trouble line


 The trouble line works fine in this example. It prints
 what I want, something which looks like lists of words:

 ['CT', 'CT', '268.0', '1.529']...  etc.

 However, if I want to manipulate the individual list elements, I run into
 trouble. While

 print line.split()[0]

 still works, (it yields CT  - first element),

 however,

 print line.split()[1]

 gives error:

 File readatoms.py, line 103, in module
print line.split()[1]
 IndexError: list index out of range

 Could you please tell me what's wrong. (I come from Perl background so
 Python seems out-of-the-body experience to me).

 Sincerely,

 Vis













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




-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] Newbie question

2008-07-01 Thread asdg asdg
You need to add the folder containing this module to your PYTHONPATH.

To do this, go to you interpreter and type:
 import sys
 sys.path.append(C:\Python25\ExampleFolder) 
That path was just an example, insert your own path leading to the desired 
folder there.

Python imports it's modules from specific folders on your hard-drive.
These folders where Python looks in are contained in a list. sys.path is 
actually a the list containing those path names. Appending new path names to 
sys.path makes python look in those locations too when importing modules.

Hope this helped you understand.

-Mishu

--- On Tue, 7/1/08, Nkem Onyemachi [EMAIL PROTECTED] wrote:
From: Nkem Onyemachi [EMAIL PROTECTED]
Subject: [Tutor] Newbie question
To: tutor@python.org
Date: Tuesday, July 1, 2008, 1:19 PM

Hi,
I am studying thinking like a computer scientist using Python.
chapter 4 importing turtleworld is kind of a hitch 4 me .I downloaded the
swampy module and when importing, the interpreter gives am error saying this
module does not exist what do i do? i saved the swampy folder in the Python
folder in drive C . Thanks
_
Sent from my phone using flurry - Get free mobile email and news at:
http://www.flurry.com



  
___
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] Newbie question

2008-07-01 Thread Alan Gauld


asdg asdg [EMAIL PROTECTED] wrote

You need to add the folder containing this module to your 
PYTHONPATH.


Being picky you want to add it to your sys.path value

Python loads sys.path from the values in PYTHONPATH which is
an OS environment variable. Modifying PYTHONPATH after you
start Python will have no effect on the current session. PYTHONPATH
changes will only affect the next session you start.


To do this, go to you interpreter and type:

import sys
sys.path.append(C:\Python25\ExampleFolder)


The snag with this is you need to do it every time you want to use
swampy. To make it apply in every session then you need to add it to
PYTHONPATH.

Python imports it's modules from specific folders on your 
hard-drive.

These folders where Python looks in are contained in a list.
sys.path is actually the list containing those path names.
Appending new path names to sys.path makes python look
in those locations too when importing modules.


And Python automatically appends any folders it finds in
PYTHONPATH when it starts up.

HTH,

Alan G 



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


Re: [Tutor] newbie question

2007-10-18 Thread jon vspython
From http://diveintopython.org/getting_to_know_python/index.html, we can get
this solution which works no matter the size of the dictionaries:

print ' '.join([%s % (v,) for k,v in menu_specials.items()])

It generates a formatted string for value in the dictionary and then joins
them using white spaces.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question

2007-10-15 Thread Evert Rol
   Hi Ram,

 Either of the following should do it:

 print string.join([menu_specials[val] for val in  
 menu_specials], ', ')
 or
 print string.join([menu_specials[val] for val in  
 menu_specials.keys()],
 ', ')
 or
 print string.join([menu_specials[val] for val in [breakfast,  
 lunch,
 dinner]  ], ', ')

In addition, you'll need a tuple as the print argument list below:

  print %s %s %s % (menu_specials[breakfast], menu_specials 
[lunch], menu_specials[dinner])

Your one-argument print statement can actually be written as a one- 
element tuple:
  print %s % (menu_specials[breakfast], )

With this, and if you want to use your formatted print statements  
instead of the join, you could use something like
   print Specials: %s %s %s % tuple(menu_specials.values())
which turns the output of menu_specials.values() (a list) into a  
tuple. Disadvantage is that you'll need to know the number of values  
in advance, for the number of '%s' in your format string  
(alternatively, you could build up the format string in a loop  
first). Note that values() bypasses the above list comprehensions  
entirely.

hth,

   Evert


 Hi all,

 I have just started learning to program and am working through the  
 Beginning
 Python from Wrox.

 I am working through one of the examples in the books on  
 dictionaries. Here
 is the example.

 menu_specials = {breakfast : sausage and eggs,
 ... lunch : split pea soup and garlic bread,
 ... dinner: 2 hot dogs and onion rings}
 print %s % menu_specials[breakfast]
 sausage and eggs
 print %s % menu_specials[lunch]
 split pea soup and garlic bread
 print %s % menu_specials[dinner]
 2 hot dogs and onion rings

 I am trying to print out the entire dictionary but am getting an  
 error.
 print %s %s %s % menu_specials[breakfast, lunch, dinner]
 Traceback (most recent call last):
   File input, line 1, in module
 KeyError: ('breakfast', 'lunch', 'dinner')

 I also tried
 print %s %s %s % menu_specials[breakfast], menu_specials[lunch],
 menu_specials[dinner]
 Traceback (most recent call last):
   File input, line 1, in module
 TypeError: not enough arguments for format string

 What is the correct syntax to output breakfast, lunch and dinner  
 with one
 command?

 thanks,

 Ram






 ___
 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] newbie question

2007-10-15 Thread Trilok Khairnar
Thinking more about the solutions I posted, I have a couple of questions :-)

1]print string.join([menu_specials[val] for val in menu_specials], ', ')

 Will this use iterkeys() under the hood?
2]print string.join([menu_specials[val] for val in
menu_specials.keys()], ', ')
 Given that a.keys() returns a copy of a's list of keys, will it be
memory intensive for large lists and it's better to use an iterator?

Thanks,
Trilok.

-Original Message-
From: Trilok Khairnar [mailto:[EMAIL PROTECTED]
Sent: Monday, October 15, 2007 9:05 PM
To: 'Ramkumar Kashyap'
Cc: 'tutor@python.org'
Subject: RE: [Tutor] newbie question

Either of the following should do it:

print string.join([menu_specials[val] for val in menu_specials], ', ')
or
print string.join([menu_specials[val] for val in menu_specials.keys()],
', ') or
print string.join([menu_specials[val] for val in [breakfast, lunch,
dinner]  ], ', ')

Thanks,
Trilok.



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Ramkumar Kashyap
Sent: Monday, October 15, 2007 8:32 PM
To: tutor@python.org
Subject: [Tutor] newbie question


Hi all,

I have just started learning to program and am working through the Beginning
Python from Wrox.

I am working through one of the examples in the books on dictionaries. Here
is the example.

 menu_specials = {breakfast : sausage and eggs,
... lunch : split pea soup and garlic bread, ... dinner: 2 hot dogs
and onion rings}
 print %s % menu_specials[breakfast]
sausage and eggs
 print %s % menu_specials[lunch]
split pea soup and garlic bread
 print %s % menu_specials[dinner]
2 hot dogs and onion rings

I am trying to print out the entire dictionary but am getting an error.
print %s %s %s % menu_specials[breakfast, lunch, dinner] Traceback
(most recent call last):
  File input, line 1, in module
KeyError: ('breakfast', 'lunch', 'dinner')

I also tried
print %s %s %s % menu_specials[breakfast], menu_specials[lunch],
menu_specials[dinner] Traceback (most recent call last):
  File input, line 1, in module
TypeError: not enough arguments for format string

What is the correct syntax to output breakfast, lunch and dinner with one
command?

thanks,

Ram






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


Re: [Tutor] newbie question

2007-10-15 Thread Trilok Khairnar

 With this, and if you want to use your formatted print statements instead
of the join, you could use something like
 print Specials: %s %s %s % tuple(menu_specials.values()) which turns the
output of menu_specials.values() (a list) into a tuple.
 Disadvantage is that you'll need to know the number of values in advance,
for the number of '%s' in your format string (alternatively,
 you could build up the format string in a loop first). Note that values()
bypasses the above list comprehensions entirely.

With the following, you can do fine without knowing the length in advance.

tpl = tuple(menu_specials.values())
Print Specials:  + ' '.join([%s*len(tpl)]) % tpl

Thanks,
Trilok.


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


Re: [Tutor] newbie question (teaching you to fish?)

2007-10-15 Thread bob gailer
Ramkumar Kashyap wrote:
 Hi all,

 I have just started learning to program and am working through the 
 Beginning Python from Wrox.

 I am working through one of the examples in the books on dictionaries. 
 Here is the example.

  menu_specials = {breakfast : sausage and eggs,
 ... lunch : split pea soup and garlic bread,
 ... dinner: 2 hot dogs and onion rings}
  print %s % menu_specials[breakfast]
 sausage and eggs
  print %s % menu_specials[lunch]
 split pea soup and garlic bread
  print %s % menu_specials[dinner]
 2 hot dogs and onion rings

 I am trying to print out the entire dictionary but am getting an error.
 print %s %s %s % menu_specials[breakfast, lunch, dinner]
 Traceback (most recent call last):
   File input, line 1, in module
 KeyError: ('breakfast', 'lunch', 'dinner')
Do you understand why you got that error?

 I also tried
 print %s %s %s % menu_specials[breakfast], menu_specials[lunch], 
 menu_specials[dinner]
 Traceback (most recent call last):
   File input, line 1, in module
 TypeError: not enough arguments for format string
Do you understand why you got that error?

The first step to getting things right is to understand the error and 
relate it to what Python expects.

What are the acceptable right arguments to %? In what way did your 2nd 
attempt fail to meet these requirements?

Once you answer that then the fix should be obvious. So give it a try, 
then come back for more help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question

2007-10-15 Thread Trilok Khairnar
I agree, was just trying to take home the point that if at all a format
string must be used (for whatever obscure reason), then it is not necesssary
to know beforehand the number of values in the dictionary (or the length of
list of its values) in order to to build the format string.
Hope that was parseably short, though not quite exactly pithy. :-)

Regards,
Trilok


-Original Message-
From: Luke Paireepinart [mailto:[EMAIL PROTECTED]
Sent: Monday, October 15, 2007 10:03 PM
To: Trilok Khairnar
Cc: tutor@python.org
Subject: Re: [Tutor] newbie question

Trilok Khairnar wrote:
 With this, and if you want to use your formatted print statements
 instead

 of the join, you could use something like

 print Specials: %s %s %s % tuple(menu_specials.values()) which
 turns the

 output of menu_specials.values() (a list) into a tuple.

 Disadvantage is that you'll need to know the number of values in
 advance,

 for the number of '%s' in your format string (alternatively,

 you could build up the format string in a loop first). Note that
 values()

 bypasses the above list comprehensions entirely.

 With the following, you can do fine without knowing the length in advance.

 tpl = tuple(menu_specials.values())
 Print Specials:  + ' '.join([%s*len(tpl)]) % tpl

I don't see the point of building a format string and then substituting for
it.
Why not just do:
print Specials:  + ' '.join(menu_specials.values())

-Luke


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


Re: [Tutor] newbie question

2007-10-15 Thread Luke Paireepinart
Trilok Khairnar wrote:
 With this, and if you want to use your formatted print statements instead
 
 of the join, you could use something like
   
 print Specials: %s %s %s % tuple(menu_specials.values()) which turns the
 
 output of menu_specials.values() (a list) into a tuple.
   
 Disadvantage is that you'll need to know the number of values in advance,
 
 for the number of '%s' in your format string (alternatively,
   
 you could build up the format string in a loop first). Note that values()
 
 bypasses the above list comprehensions entirely.

 With the following, you can do fine without knowing the length in advance.

 tpl = tuple(menu_specials.values())
 Print Specials:  + ' '.join([%s*len(tpl)]) % tpl
   
I don't see the point of building a format string and then substituting 
for it.
Why not just do:
print Specials:  + ' '.join(menu_specials.values())

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


Re: [Tutor] newbie question

2007-10-15 Thread Alan Gauld
Ramkumar Kashyap [EMAIL PROTECTED] wrote

 print %s %s %s % menu_specials[breakfast], 
 menu_specials[lunch],
 menu_specials[dinner]

Whoops, I also should have added parentheses around the values.
Otherwise Python sees a tuple consisting of the string and first
value followed by the two succeeding values. And the single value
doesn't match the 3 %s tokens.

So it should be:

 print %s %s %s % (menu_specials[breakfast], 
 menu_specials[lunch],
menu_specials[dinner])

Because of the parens you don't need the \ character so you can ignore 
that bit.

Note to self: Test before posting!

Blush,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] newbie question

2007-10-15 Thread Alan Gauld
Ramkumar Kashyap [EMAIL PROTECTED] wrote

 menu_specials = {breakfast : sausage and eggs,
 ... lunch : split pea soup and garlic bread,
 ... dinner: 2 hot dogs and onion rings}

 print %s % menu_specials[breakfast]

You don't really need the %s bit it could just be

 print menu_specials[breakfast]

 I am trying to print out the entire dictionary but am getting an 
 error.

 print %s %s %s % menu_specials[breakfast, lunch, dinner]

The bit between [] is the key to the dictionary(notice key is 
singular!)
You have passed a tuple of 3 strings (a tuple because they are
separated by commas) as a key. But the dictionary keys are all
single strings not tuples. In other words you need to access the
dictionary 3 times like so:

 print %s %s %s % menu_specials[breakfast], 
 menu_specials[lunch], menu_specials[dinner]

 print %s %s %s % menu_specials[breakfast], 
 menu_specials[lunch],
 menu_specials[dinner]

That should have worked. are you sure you had it all on one line?
If you need to break the line use a \ character.
My previous example could be done like this:

 print %s %s %s % menu_specials[breakfast], \
  menu_specials[lunch], \
  menu_specials[dinner]

Or missing the formatting string as:

 print menu_specials[breakfast], \
  menu_specials[lunch], \
  menu_specials[dinner]

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] newbie question

2007-10-15 Thread jon vspython
There's also a specially tailored solution for dictionaries:

print %(breakfast)s %(lunch)s %(dinner)s % menu_specials
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question

2007-10-15 Thread Alan Gauld

jon vspython [EMAIL PROTECTED] wrote 

 There's also a specially tailored solution for dictionaries:
 
 print %(breakfast)s %(lunch)s %(dinner)s % menu_specials

Good catch! I keep forgetting about that.
I really must get into the habit of using it more often 
when working with dictionaries.

Thanks,

Alan G.


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


Re: [Tutor] newbie question

2007-06-17 Thread Kent Johnson
bellzii wrote:
 hey everyone , can any1 tell me what does the module optparse do ?

It helps parse command line arguments. See the docs at
http://docs.python.org/lib/module-optparse.html

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


Re: [Tutor] newbie question

2007-06-17 Thread Alan Gauld

bellzii [EMAIL PROTECTED] wrote
 hey everyone , can any1 tell me what does the module optparse do ?


It parses options.
That is it takes a command string and works out what
the various bits mean, in particular the command line
options or switches.

For example you can call python like this:

$ python -i foo.py

And the -i is an option that tells python not to exity the 
intrerpreter
after running foo.py.

optparse can be usd to validate and select options in your programs.

The documentation includes background info and an extensive
tutorial (this must be one of the best documented modules in
the library) , did you read through it before posting? If so what
did you not understand?

HTH,

Alan G. 


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


Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Bob Gailer
[EMAIL PROTECTED] wrote:
 I'm working my way through the book beginning python and I came across an 
 exercise that suggests using Exception trapping to see if a value is in a 
 dictionary:

 fridge={apple:A shiny red apple,pear:a nice ripe 
 pear,grapes:seadless grapes}
 food_sought=apple
 fridge_list=fridge.keys();
 try:
 print The fridge contains %s %fridge[food_sought]
 except (KeyError):
 print The fridge does not contain %s%food_sought

 I'm fairly certain the book is in error in calling this a short-cut since 
 the has_key method is much less verbose to use
Perhaps the version of Python, when the book was written, did not have 
has_key?
Less verbose? Let's see - if I do a straightforward translation I get:

if fridge.has_key(food_sought):
print The fridge contains %s %fridge[food_sought]
else:
print The fridge does not contain %s%food_sought

That's 2 less words!

But consider (same word count but even easier to read):

if food_sought in fridge:

 question about exceptions in general:

 In Java using exceptions in the way shown above is a classic anti-pattern 
 since Exceptions should only be used for..well exceptional conditions.  
   
Ah the dreaded should. Who says? But then in Java exception handling 
is more complex, and avoiding it seems a good idea.
 Is the same true of Python? Or is ok to use Exception handling like the book 
 suggests?
   
Since there is no one on the Python side saying should (AFAIK) I can 
only opine: use whatever gets the job done, is readable and maintainable.

Many things can be tested for with ease. But consider when you use 
raw_input to get a string, and you want to accept it only if it will 
convert to float. The only easy way I know is to use the float() 
function inside a try:. If you wanted to test it without try: you'd have 
to write a regular expression for floating point syntax and use re. Not 
as easy or readable.

-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Andre Engels
2007/5/8, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 I'm working my way through the book beginning python and I came across an 
 exercise that suggests using Exception trapping to see if a value is in a 
 dictionary:

 fridge={apple:A shiny red apple,pear:a nice ripe 
 pear,grapes:seadless grapes}
 food_sought=apple
 fridge_list=fridge.keys();
 try:
 print The fridge contains %s %fridge[food_sought]
 except (KeyError):
 print The fridge does not contain %s%food_sought

 I'm fairly certain the book is in error in calling this a short-cut since 
 the has_key method is much less verbose to use,

Is it?

if fridge.has_key(food_sought):
foo
else:
bar

doesn't look much less verbose than:

try:
foo
except (KeyError):
bar

 but it brings up a question about exceptions in general:

 In Java using exceptions in the way shown above is a classic anti-pattern 
 since Exceptions should only be used for..well exceptional conditions.

 Is the same true of Python? Or is ok to use Exception handling like the book 
 suggests?

Exceptions are in general much more freely used in Python than in most
other languages, it's called the EAFP (It's easier to ask
forgiveness than to get permission) style, instead of the LBYL (look
before you leap) style most other languages use.


-- 
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread Alan Gauld
[EMAIL PROTECTED] wrote

 fridge={apple:A shiny red apple,pear:a nice ripe 
 pear,grapes:seadless grapes}
 food_sought=apple
 fridge_list=fridge.keys();

Not sure what this line is for...

 try:
print The fridge contains %s %fridge[food_sought]
 except (KeyError):
print The fridge does not contain %s%food_sought

This is a fairly common Python idiom.

 I'm fairly certain the book is in error in calling this a 
 short-cut

I agree, its not much of a shortcut. but oit is a common Python idiom.

 In Java using exceptions in the way shown above is
 a classic anti-pattern since Exceptions should only
 be used for..well exceptional conditions.

There are a few reasons for this in Jave, not least that
Exceptions are quite expensive in Java whereas they
are relatively cheap in Python.

 Or is ok to use Exception handling like the book suggests?

Its generally OK but at the same time don't overdo it.
Exceptions have a lot in common with gotos. They can
obfuscate the flow of code unless the try block is short
and simple. Personally I prefer to use exception for real
exceptions when possible, but sometimes they do offer
a neat way of expressing things. And of course accessing
a non existent key is an exception!

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Newbie Question on Exceptions...

2007-05-08 Thread John Fouhy
On 09/05/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 try:
 print The fridge contains %s %fridge[food_sought]
 except (KeyError):
 print The fridge does not contain %s%food_sought
[...]
 Is the same true of Python? Or is ok to use Exception handling like the book 
 suggests?

This general debate is called look before you leap vs easier to ask
forgiveness than permission.  If you google for python eafp lbyl
you will get a zillion pages of people debating it.  Here's a quote
from a post by Alex Martelli
(http://en.wikipedia.org/wiki/Alex_Martelli):

# from http://mail.python.org/pipermail/python-list/2003-May/205182.html

There are umpteen good reasons why EAFP is vastly superior to LBYL.  For
example, we can just focus on the fact that these days we work mostly on
multiprogrammed machines.  While script A is running, some other programs
B, C, D, ... are typically also running -- and they might be mucking
with the same directories and/or files that A is working with.

So, if A's structure is:

if iswhatiwant(thefile):
useappropriately(thefile)
else:
dealwithwrongness()

then A is buggy.  That is because, between the moment in which the test
'iswhatiwant' runs (and returns a true value), and the later moment in
which procedure 'useappropriately' runs, *just about anything may have
happened* -- in particular, some other program Z might have removed or
modified 'thefile' so that it's NOT what A wants any more.  I.e., A may
lose control of the CPU between the moment it tests and the later time
in which it uses the result of that test.

This is known as a race condition and it's among the hardest problems
you may run into.  A may seem to be running just fine 99 times and then
the 100th time BOOM -- because of accidents of timing between A and
other stuff that may be running at the same time... a race, so to
speak, whence the name whereby this horrid condition is known.

Fortunately, in a language with good support for exceptions such as
Python, you are NOT doomed to enter the hell of race conditions -- just
use EAFP instead of LBYL:

try:
useappropriately(thefile)
except ItWasWrong, howwasitwrong:
dealwithwrongness()

See how deeply simpler this is?  'useappropriately' just ASSUMES the
file is 'what A wants' and raises an ItWasWrong exception if the
assumption proves to be unfounded.  You don't have to code a
separate 'iswhatiwant' test -- what you DO want is determined inherently
by what 'useappropriately' tries to do.  No race conditions, no code
that must duplicate the set of conditions to be checked for, no
duplicate work at runtime in terms of system calls to determine
if a condition holds followed by system calls to take advantaqe
of that condition.

This risks leaving the impression that EAFP is a panacea - it isn't,
and it has its own issues to watch for -- it's simply heads and
shoulders above LBYL in most practical cases.  Please see my more
detailed discussions of this in the Cookbook and the Nutshell for
something more about error-checking strategies.


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


Re: [Tutor] Newbie question concerning text covering multiple lines

2007-04-05 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote

 Several good beginners tutorials are listed here:
 http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

But very few of them will have been updated to reflect 
changes in 2.5. My own tutor is accurate for 2.3.
This is precisely because, as Kent said, the changes 
in Python are nearly always backwards compatible, so 
you can use old code in a new version.

If you came across something broken between 2.2 
and 2.5 you are very unlucky. What was it?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] Newbie question concerning text covering multiple lines

2007-04-04 Thread Kent Johnson
Guba Castro wrote:
 Hello,
 
 I recently started teaching myself Python with Michael Dawson's 'Python
 Programming for the Absolute Beginner'.
 
 My problem is that I am running Python 2.5 under Linux while the book is
 based on Python 2.2.3. Apparently this means that I cannot just follow
 the programming examples the author gives.

You should be able to use the book with Python 2.5. Python releases 
rarely break old code, rather they add new capabilities. What kinds of 
trouble are you having? If you tell us the specific problems you are 
running into we can help.

 While I like the book and intent to continue using it, I was wondering
 which online resources I should consult in order to bridge the gap. So
 far I am stuck with the Python Tutorial at http://docs.python.org/tut/
 which, however, doesn't care too precisely to my needs.
 
 Would you happen to have any suggestions for me?

Each Python release includes a What's New document that describes the 
changes in that release. You can find them by clicking on each version 
number here:
http://www.python.org/doc/versions/

Several good beginners tutorials are listed here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Kent

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


Re: [Tutor] Newbie question: random.sample illusion?

2006-12-07 Thread Luke Paireepinart
Moedeloos Overste wrote:
 Hi everybody,

 I'm in the process of learning Python and working my way through O'Reilly's 
 Learning Python. As an excercise I wrote (some copy/paste as well) a small 
 lottery program just to learn how to work with lists and dictionarys etc.

 The user has to enter 6 numbers from a range(1-45). The numbers are stored 
 in a list(num_list). Then the program asks the user how many times(vDraws) 
 he wants to play the lottery with his numbers. After entering the program 
 draws the lottery the desired number of times and compares the winning 
 numbers with the users numbers.

 Now, by accident I stumbled upon the following; if the user enters the 
 numbers 1 to 6 as his lottery numbers he always wins! So somewhere I must 
 have made a mistake. Could somebody have a look at the code please and tell 
 me where I took a wrong turn?



 winnings=0
 right2=1
 right3=4
 right4=15
 right5=450
 right6=100
   
it might be clearer to do
prizes = [0,0,1,4,15,450,100]
 user_nums=[] # empty List for numbers
 print Kies je nummers tussen 0 en 46
 print
 whereat=1
 listindex=0
   
What is the point of having two variables here?
You never use listindex.
You should start whereat at 0.
 # when 7th number is inputted loop breaks
 while whereat = 6:
   
And loop until whereat is less than 6.
That's the general consensus on looping in Computer Science.  Starting at 0.
 num=raw_input(Voer +str(whereat)+. Lotto nummer in: )
   
And just change this line to str(whereat+1) instead.
 # check that user inputted value is not smaller than 1 or bigger than 45
 # and that it is not already in user_nums
 if num !=  and len(num) != 0:
   
If they enter 'a' your program will crash.
A better solution would be to use a try except block.
eg. 
try:
  tmp = int(num)
  if tmp = 1 and tmp = 45 and tmp not in user_nums:
 user_nums.append(tmp)
  whereat += 1
except ValueError:
pass  
 if int(num) = 1 and int(num) = 45 and num not in user_nums:
  user_nums.append(num)
   
Also note here that you're using the integer representation of num to 
compare it to 1 and 45,
but then you're storing the string representation of it in user_nums.
This may be part of why you're having a problem.
  whereat+=1
  listindex+=1
 # if above statement if false just pass and ask for the number 
 again!
 else:
 pass
 print '1 trekking kost U 1 euro inzet'
 print
 vDraws = input(Hoe vaak wil je in de lotto spelen met deze nummers? :)

 # Create dictionary for statiscal purposes later on :-)
 d={1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 
 14:0, 15:0,
 16:0, 17:0, 18:0, 19:0, 20:0, 21:0, 22:0, 23:0, 24:0, 25:0, 26:0, 27:0, 
 28:0,
 29:0, 30:0, 31:0, 32:0, 33:0, 34:0, 35:0, 36:0, 37:0, 38:0, 39:0, 40:0, 
 41:0, 42:0,
 43:0, 44:0, 45:0}
   
This could be:
d = {}
for x in range(1,46):
d[x] = 0
Or several varations of this, using lambda  map, and such.
 match=0
 count=0
   
You don't use count in your program anywhere.
 inzet=vDraws * 1
   
There's absolutely no reason to multiply something by 1.
 while vDraws  0:
 x=random.sample(range(1,46), 6)# draws lottery from given range
 for i in x:
 y=int(i)
   
This line is unnecessary, 'i' is already an integer.
 d[y] = int(d[y])+ 1 #stores values in lottonumbers dictionary
   
Can be shortened to d[y] += 1
 for p in user_nums:
count+=1
   
no reason to do this because the for loop will end when it runs out of 
variables.
y=str(y)
   
Again, if you leave the original items as integers you don't have to do 
all this conversion.
if p in y:
   
I would change this to 'if p == y', because I'm not sure what 'in' is 
doing here.
 match+=1 # increase matching variable by one if its right 
 number

 # caculating winnings
 if match ==2:
 winnings+=right2
 match=0
 elif match ==3:
 winnings+=right3
 match=0
 elif match == 4:
 winnings+=right4
 match=0
 elif match == 5:
 winnings+=right5
 match=0
 elif match == 6:
 winnings+=right6
 match=0
   
Using that prizes list, this can be shortened to
winnings += prizes[match]
match = 0
 vDraws = vDraws - 1
   
Or vDraws -= 1
 # sorting dictionary by its values
 items=d.items()
 backitems=[ [v[1],v[0]] for v in items]
 backitems.sort()
 sortedlist=[ backitems[i][1] for i in range(0,len(backitems))]

 print
 print
 print
 saldo=winnings-inzet
 print
 print
 print '-' * 80
 if saldo  0:
 print 'U heeft', saldo, 'euro winst gemaakt!'
 else:
 print 'U heeft', saldo, ' euro verlies geleden!'


 print 'U heeft in totaal gewonnen', winnings, 'euro.'
 print 'Uw inzet was', inzet, 'euro'
 print 'De 6 meest gevallen getallen waren:',
 for x in 

Re: [Tutor] Newbie question: random.sample illusion?

2006-12-07 Thread Luke Paireepinart
Moedeloos Overste wrote:
 Hi everybody,

 I'm in the process of learning Python and working my way through O'Reilly's 
 Learning Python. As an excercise I wrote (some copy/paste as well) a small 
 lottery program just to learn how to work with lists and dictionarys etc.

 The user has to enter 6 numbers from a range(1-45). The numbers are stored 
 in a list(num_list). Then the program asks the user how many times(vDraws) 
 he wants to play the lottery with his numbers. After entering the program 
 draws the lottery the desired number of times and compares the winning 
 numbers with the users numbers.

 Now, by accident I stumbled upon the following; if the user enters the 
 numbers 1 to 6 as his lottery numbers he always wins! So somewhere I must 
 have made a mistake. Could somebody have a look at the code please and tell 
 me where I took a wrong turn?

   
Ooops, I accidentally hit 'send' on that other e-mail before I was done 
with it.

I was just going to say that you forgot to include 'random'.
Also, here is the code with the changes I suggested.
I ran it on 1,2,3,4,5,6 for 80 tries and didn't win every time.

#code begins here.
import random
winnings=0
prizes = [0,0,1,4,15,450,100]

user_nums=[] # empty List for numbers
print Kies je nummers tussen 0 en 46
print
whereat=0
# when 6th number is inputted loop breaks
while whereat  6:
num=raw_input(Voer +str(whereat+1)+. Lotto nummer in: )
# check that user inputted value is not smaller than 1 or bigger than 45
# and that it is not already in user_nums
try:
tmp = int(num)
if tmp = 1 and tmp = 45 and tmp not in user_nums:
user_nums.append(tmp)
whereat += 1
except ValueError:
pass 
print '1 trekking kost U 1 euro inzet'
print
vDraws = input(Hoe vaak wil je in de lotto spelen met deze nummers? :)
# Create dictionary for statiscal purposes later on :-)
d = {}
for x in range(1,46):
d[x] = 0
match=0
count=0
inzet=vDraws
while vDraws  0:
x=random.sample(range(1,46), 6)# draws lottery from given range
for i in x:
d[i] += 1 #stores values in lottonumbers dictionary
   
for p in user_nums:
if p == i:
 match+=1 # increase matching variable by one if its 
right number
winnings += prizes[match]
match = 0
vDraws -= 1

# sorting dictionary by its values
items=d.items()
backitems=[ [v[1],v[0]] for v in items]
backitems.sort()
sortedlist=[ backitems[i][1] for i in range(0,len(backitems))]
print '\n\n'
saldo=winnings-inzet
print '\n'
print '-' * 80
if saldo  0:
print 'U heeft', saldo, 'euro winst gemaakt!'
else:
print 'U heeft', saldo, ' euro verlies geleden!'
print 'U heeft in totaal gewonnen', winnings, 'euro.'
print 'Uw inzet was', inzet, 'euro'
print 'De 6 meest gevallen getallen waren:',
for x in sortedlist[0:6]: print x, #prints the 6 most drawn numbers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question: random.sample illusion?

2006-12-07 Thread Moedeloos Overste
Dear Luke,

Wow, thank you for all the input.You really made an effort .It's always nice 
when someone is willing to share his knowledge with you. You really opened 
my eyes on some things. I guess it's gonna be a long night for me. But I'm 
really enjoying myself though :-)

Regards,

Robert

From: Luke Paireepinart [EMAIL PROTECTED]
To: Moedeloos Overste [EMAIL PROTECTED]
CC: tutor@python.org
Subject: Re: [Tutor] Newbie question: random.sample illusion?
Date: Thu, 07 Dec 2006 12:17:23 -0600

Moedeloos Overste wrote:
Hi everybody,

I'm in the process of learning Python and working my way through 
O'Reilly's Learning Python. As an excercise I wrote (some copy/paste as 
well) a small lottery program just to learn how to work with lists and 
dictionarys etc.

The user has to enter 6 numbers from a range(1-45). The numbers are stored 
in a list(num_list). Then the program asks the user how many times(vDraws) 
he wants to play the lottery with his numbers. After entering the program 
draws the lottery the desired number of times and compares the winning 
numbers with the users numbers.

Now, by accident I stumbled upon the following; if the user enters the 
numbers 1 to 6 as his lottery numbers he always wins! So somewhere I must 
have made a mistake. Could somebody have a look at the code please and 
tell me where I took a wrong turn?



winnings=0
right2=1
right3=4
right4=15
right5=450
right6=100

it might be clearer to do
prizes = [0,0,1,4,15,450,100]
user_nums=[] # empty List for numbers
print Kies je nummers tussen 0 en 46
print
whereat=1
listindex=0

What is the point of having two variables here?
You never use listindex.
You should start whereat at 0.
# when 7th number is inputted loop breaks
while whereat = 6:

And loop until whereat is less than 6.
That's the general consensus on looping in Computer Science.  Starting at 
0.
 num=raw_input(Voer +str(whereat)+. Lotto nummer in: )

And just change this line to str(whereat+1) instead.
 # check that user inputted value is not smaller than 1 or bigger than 
45
 # and that it is not already in user_nums
 if num !=  and len(num) != 0:

If they enter 'a' your program will crash.
A better solution would be to use a try except block.
eg. try:
  tmp = int(num)
  if tmp = 1 and tmp = 45 and tmp not in user_nums:
 user_nums.append(tmp)
  whereat += 1
except ValueError:
pass
 if int(num) = 1 and int(num) = 45 and num not in user_nums:
  user_nums.append(num)

Also note here that you're using the integer representation of num to 
compare it to 1 and 45,
but then you're storing the string representation of it in user_nums.
This may be part of why you're having a problem.
  whereat+=1
  listindex+=1
 # if above statement if false just pass and ask for the 
number again!
 else:
 pass
print '1 trekking kost U 1 euro inzet'
print
vDraws = input(Hoe vaak wil je in de lotto spelen met deze nummers? :)

# Create dictionary for statiscal purposes later on :-)
d={1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 
14:0, 15:0,
 16:0, 17:0, 18:0, 19:0, 20:0, 21:0, 22:0, 23:0, 24:0, 25:0, 26:0, 
27:0, 28:0,
 29:0, 30:0, 31:0, 32:0, 33:0, 34:0, 35:0, 36:0, 37:0, 38:0, 39:0, 
40:0, 41:0, 42:0,
 43:0, 44:0, 45:0}

This could be:
d = {}
for x in range(1,46):
d[x] = 0
Or several varations of this, using lambda  map, and such.
match=0
count=0

You don't use count in your program anywhere.
inzet=vDraws * 1

There's absolutely no reason to multiply something by 1.
while vDraws  0:
 x=random.sample(range(1,46), 6)# draws lottery from given range
 for i in x:
 y=int(i)

This line is unnecessary, 'i' is already an integer.
 d[y] = int(d[y])+ 1 #stores values in lottonumbers dictionary

Can be shortened to d[y] += 1
 for p in user_nums:
count+=1

no reason to do this because the for loop will end when it runs out of 
variables.
y=str(y)

Again, if you leave the original items as integers you don't have to do all 
this conversion.
if p in y:

I would change this to 'if p == y', because I'm not sure what 'in' is doing 
here.
 match+=1 # increase matching variable by one if its right 
number

 # caculating winnings
 if match ==2:
 winnings+=right2
 match=0
 elif match ==3:
 winnings+=right3
 match=0
 elif match == 4:
 winnings+=right4
 match=0
 elif match == 5:
 winnings+=right5
 match=0
 elif match == 6:
 winnings+=right6
 match=0

Using that prizes list, this can be shortened to
winnings += prizes[match]
match = 0
 vDraws = vDraws - 1

Or vDraws -= 1
# sorting dictionary by its values
items=d.items()
backitems=[ [v[1],v[0]] for v in items]
backitems.sort()
sortedlist

Re: [Tutor] Newbie question: join() string method

2006-11-27 Thread Andreas Kostyrka
,.join(str(x) for x in intList)

Andreas

_ Ursprüngliche Mitteilung _
Betreff:[Tutor] Newbie question: join() string method
Autor:  Moedeloos Overste [EMAIL PROTECTED]
Datum:  27. November 2006 13:20:41

Hi,

I'm trying to use the join() method on a list to be able to store the 
contents of that list in a file. Basically I want the contents of the list 
stored without the []. I've tried numerous ways of using the join() method, 
but they all return errors. I've tried using the tutorial and documentation 
on this one but still can't work it out.

errors: TypeError: sequence item 0: expected string, int found



code:
LotNumbers = random.sample(range(1,45), 6) #random numbers from range into 
list)
','.join()  #?what's the 
correct syntax?
fout = open(draw__output.dat, a)
fout.write(LotNumbers) #writing string to 
file
fout.close()
vDraws = vDraws - 1

Can someone show me the correct way to use the join() method in this case?

Many thanks,

Robert

_
De makers van Hotmail hebben groot nieuws! Meer weten? Klik hier! 
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

___
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] Newbie question: join() string method

2006-11-27 Thread jhl

Hi,

I am not sure what 'random' does (what package is it from?), but

list=['1','2','3']
slist=','.join(list)

works, while

list=[1,2,3]
slist=','.join(list)

does not.  It appears 'join' only works on lists (and maybe tuples?) of
string objects and the list must be passed in as an argument.  Try
translating your list into a list of string representation of numbers and
then using join.

Hope this is a useful clue,
-Jason

On 11/27/06, Moedeloos Overste [EMAIL PROTECTED] wrote:


Hi,

I'm trying to use the join() method on a list to be able to store the
contents of that list in a file. Basically I want the contents of the list
stored without the []. I've tried numerous ways of using the join()
method,
but they all return errors. I've tried using the tutorial and
documentation
on this one but still can't work it out.

errors: TypeError: sequence item 0: expected string, int found



code:
LotNumbers = random.sample(range(1,45), 6) #random numbers from range into
list)
','.join()  #?what's
the
correct syntax?
fout = open(draw__output.dat, a)
fout.write(LotNumbers) #writing string to
file
fout.close()
vDraws = vDraws - 1

Can someone show me the correct way to use the join() method in this case?

Many thanks,

Robert

_
De makers van Hotmail hebben groot nieuws! Meer weten? Klik hier!
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

___
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] Newbie question: join() string method

2006-11-27 Thread Moedeloos Overste
Ha!

Thanx for all the input everybody. I finally got it to work. The contents of 
the list is now stored in the file without the []. The solution is in the 
code below. Next step in my learning process is reading the file contents 
and storing it in a dictionary.

One question: When I run the program from IDLE it writes the data to file 
but when I run it from the command prompt(win32)  it doesn't. why is this?



code:

vDraws = input(How many times do you want to draw the lottery? :)

# Draw lottery numbers  writing them to file

while vDraws  0:
LotNumbers = random.sample(range(1,45), 6) #random numbers from range 
into list)
strgOutput=,.join(str(i) for i in LotNumbers)   #??converting list 
to string to store it.
fout = open(draw__output.dat, a)
fout.write(strgOutput + \n)  #writing string to file
fout.close()
vDraws = vDraws - 1



From: Andreas Kostyrka [EMAIL PROTECTED]
Reply-To: Andreas Kostyrka [EMAIL PROTECTED]
To: Moedeloos Overste [EMAIL PROTECTED]
CC: tutor@python.org
Subject: Re: [Tutor] Newbie question: join() string method
Date: Mon, 27 Nov 2006 13:32:59 +0100

,.join(str(x) for x in intList)

Andreas

_ Ursprüngliche Mitteilung _
Betreff:   [Tutor] Newbie question: join() string method
Autor: Moedeloos Overste [EMAIL PROTECTED]
Datum: 27. November 2006 13:20:41

Hi,

I'm trying to use the join() method on a list to be able to store the
contents of that list in a file. Basically I want the contents of the list
stored without the []. I've tried numerous ways of using the join() method,
but they all return errors. I've tried using the tutorial and documentation
on this one but still can't work it out.

errors: TypeError: sequence item 0: expected string, int found



code:
LotNumbers = random.sample(range(1,45), 6) #random numbers from range into
list)
 ','.join()  #?what's 
the
correct syntax?
 fout = open(draw__output.dat, a)
 fout.write(LotNumbers) #writing string to
file
 fout.close()
 vDraws = vDraws - 1

Can someone show me the correct way to use the join() method in this case?

Many thanks,

Robert

_
De makers van Hotmail hebben groot nieuws! Meer weten? Klik hier!
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

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

_
Windows Live Mail: Slim, Persoonlijk, Betrouwbaar en het blijft natuurlijk 
gratis! http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

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


Re: [Tutor] Newbie question: join() string method

2006-11-27 Thread Alan Gauld
Moedeloos Overste [EMAIL PROTECTED] wrote

 One question: When I run the program from IDLE it writes the data to 
 file
 but when I run it from the command prompt(win32)  it doesn't. why is 
 this?

How do you know? Have you searched for the file?
Or are you looking in the same file that IDLE produced?
I would expect the code to create a new file in the current
directory - wherever you started the program. Did you look
there?

---
while vDraws  0:
LotNumbers = random.sample(range(1,45), 6) #random numbers from 
range
into list)
strgOutput=,.join(str(i) for i in LotNumbers) 
#??converting list
to string to store it.
fout = open(draw__output.dat, a)
fout.write(strgOutput + \n)  #writing string to file
fout.close()
--

It's probably better to put the open/close outside the loop

fout = open(...,'w')
while vDraws  0
...
fout.write(strgOutput + '\n')
vDraws -= 1
fout.close()

That way you can use 'w' to write the file(unless you really want the
previous runs to be in there too.) Also this will save the program
opening and closing the file for each line which is quite a slow 
process.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Newbie question: join() string method

2006-11-27 Thread wesley chun
 strgOutput=,.join(str(i) for i in LotNumbers)   #??converting list
 to string to store it.

note that here, you are *not* converting the list to a string to store
it.  you are converting each list member to a string and creating a
new list (actually generator [expression]) for the string.join()
method to takes its contents (now strings) and concatenate them
together into one large string delimited by ','s.

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

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


Re: [Tutor] newbie question about default arguments

2006-03-29 Thread Josh Adams
Thanks for your help.  That makes a lot more sense.  

Not to ask too many stupid questions, but why does the L2 assignment in the
if-block create a new L variable?  Shouldn't the scope from the function
definition dominate the inner scope of the if-block?

Thanks,
Josh

 Josh,
 
 If you print the id() of your L inside your f2(), you will notice something..
 In short, the default value stays the same; what you modified was another
 copy of []. Hope it helps.
 
 def f2(a, L=[]):
   print id(L) = , id(L)
   if L==[]:
 L=[]
 print id(L2) =, id(L)
   L.append(a)
   return L
 
  print f2(1)
 id(L)= 11788336
 id(L2)= 12047184
 [1]
 
 Kenny
 
 



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


Re: [Tutor] newbie question about default arguments

2006-03-29 Thread Kent Johnson
Josh Adams wrote:
 Thanks for your help.  That makes a lot more sense.  
 
 Not to ask too many stupid questions, but why does the L2 assignment in the
 if-block create a new L variable?  Shouldn't the scope from the function
 definition dominate the inner scope of the if-block?

It doesn't create a new variable, it binds a new value to the name L. if 
statements don't introduce a new scope so you are right about that.

Default values for functions are evaluated just once, when the function 
is defined. Rebinding L to a new list inside the function makes each 
execution get a fresh list.

This might help you understand Python name-binding semantics:
http://effbot.org/zone/python-objects.htm

Kent

 
 Thanks,
 Josh
 
 
Josh,

If you print the id() of your L inside your f2(), you will notice something..
In short, the default value stays the same; what you modified was another
copy of []. Hope it helps.

def f2(a, L=[]):
  print id(L) = , id(L)
  if L==[]:
L=[]
print id(L2) =, id(L)
  L.append(a)
  return L


print f2(1)

id(L)= 11788336
id(L2)= 12047184
[1]

Kenny


 
 
 
 
 ___
 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] Newbie question re. Functions

2006-02-01 Thread Ed Singleton
On 31/01/06, Jon Moore [EMAIL PROTECTED] wrote:
 Improve the function ask_number() so that the function can be called with a
 step value. Make the default value of step 1.

 The function looks like this:

 def ask_number(question, low, high):
 Ask for a number within the range
 response = None
 while response not in range(low, high):
 response =  int(raw_input(question))
 return response

To be honest, this made sense to me.  I assumed the author wants you
to be able to do the following:

ask_number(Give me an even number between 1 and 10, 1, 10, 2)

The solution would be:

def ask_number(question, low, high, step=1):
Ask for a number within the range
response = None
while response not in range(low, high, step):
response =  int(raw_input(question))
return response

But I definitely agree that he said it very, very badly.

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


Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Jon Moore
Thats fine, but what differance does it make?I can see no way that it improves the code.I assume later on when the function is called, it should look as follows:move = ask_number(Where will you move? (0-8): , 0, NUM_SQUARES, 1)
JonOn 01/02/06, Ed Singleton [EMAIL PROTECTED] wrote:
On 31/01/06, Jon Moore [EMAIL PROTECTED] wrote: Improve the function ask_number() so that the function can be called with a step value. Make the default value of step 1.
 The function looks like this: def ask_number(question, low, high): Ask for a number within the range response = None while response not in range(low, high):
 response =int(raw_input(question)) return responseTo be honest, this made sense to me.I assumed the author wants youto be able to do the following:ask_number(Give me an even number between 1 and 10, 1, 10, 2)
The solution would be:def ask_number(question, low, high, step=1):Ask for a number within the rangeresponse = Nonewhile response not in range(low, high, step):
response =int(raw_input(question))return responseBut I definitely agree that he said it very, very badly.Ed___Tutor maillist-
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- Best Regards
Jon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Kent Johnson
Jon Moore wrote:
 Hi,
 
 I am still working my way through my 'Python for absolute beginners 
 book' and have hit a brick wall with one of the end of chapter exercises.
 
 The challenge says:
 
 Improve the function ask_number() so that the function can be called 
 with a step value. Make the default value of step 1.
 
 The function looks like this:
 
 def ask_number(question, low, high):
 Ask for a number within the range
 response = None
 while response not in range(low, high):
 response =  int(raw_input(question))
 return response
 
 The author has not eluded to 'step values' in anyway that I can see in 
 the proceeding chapters!

I have the book and I don't understand what he is asking for in that 
question either.

To me a 'step value' would be something that alters a sequence, for 
example the third argument to range() is a step value:
   help(range)
Help on built-in function range in module __builtin__:

range(...)
 range([start,] stop[, step]) - list of integers

 Return a list containing an arithmetic progression of integers.
 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
 When step is given, it specifies the increment (or decrement).
 For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
 These are exactly the valid indices for a list of 4 elements.
   range(0, 6)
[0, 1, 2, 3, 4, 5]
   range(0, 6, 2)
[0, 2, 4]

Kent

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


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
Hi Jon,

 Improve the function ask_number() so that the function can be called with 
 a
 step value. Make the default value of step 1.

If its any consolation that doesn't really mean much to me either.
I understand the concept of step value - range() takes one for
example, check the docs.

But how a step value would be used in this kind of user-input scenario
I have no idea!

def ask_number(question, low, high):
Ask for a number within the range
response = None
while response not in range(low, high):
response =  int(raw_input(question))
return response

The only possibility I can think of is that the step value is used to
narrow the acceptable range each time round the loop. But given
we don't necessarily tell the user what the range is that would be
weird. We'd need to modify question as we go or something.

On the assumption you aren't being marked on this I'd just
make up your own mind what it should do and do it! :-)

...and treat it as a good example of a bad statement of
requirements!

Alan G 

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


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
I guess I am not going mad then!I will skip this exercise and move on.ThanksJonOn 31/01/06, Alan Gauld 
[EMAIL PROTECTED] wrote:Hi Jon, Improve the function ask_number() so that the function can be called with
 a step value. Make the default value of step 1.If its any consolation that doesn't really mean much to me either.I understand the concept of step value - range() takes one forexample, check the docs.
But how a step value would be used in this kind of user-input scenarioI have no idea!def ask_number(question, low, high):Ask for a number within the range
response = Nonewhile response not in range(low, high):response =int(raw_input(question))return responseThe only possibility I can think of is that the step value is used tonarrow the acceptable range each time round the loop. But given
we don't necessarily tell the user what the range is that would beweird. We'd need to modify question as we go or something.On the assumption you aren't being marked on this I'd justmake up your own mind what it should do and do it! :-)
...and treat it as a good example of a bad statement ofrequirements!Alan G-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Bob Gailer
Jon Moore wrote:
 Hi,

 I am still working my way through my 'Python for absolute beginners 
 book' and have hit a brick wall with one of the end of chapter exercises.

 The challenge says:

 Improve the function ask_number() so that the function can be called 
 with a step value. Make the default value of step 1.

 The function looks like this:

 def ask_number(question, low, high):
 Ask for a number within the range
 response = None
 while response not in range(low, high):
 response =  int(raw_input(question))
 return response

 The author has not eluded to 'step values' in anyway that I can see in 
 the proceeding chapters!
This lights my frustration fire. I wonder whether the author tested the 
book?

When I worked for a training company I was asked to test a new on-line 
course on JCL. I demurred by saying But I don't know JCL.. The reply 
was that's exactly what we want!

So a general recommendation to authors is to have a member of the target 
audience test the book. You Jon have done that but at some cost to you 
and those of us on this list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
I know. Its hard enough for someone like me as it is without things like this complicating it!I have another one for the group, but I will save it for another day ;)I have been looking for contact details for the author to ask him what he was eluding to with the exercise, but to no avail.
JonOn 31/01/06, Bob Gailer [EMAIL PROTECTED] wrote:
Jon Moore wrote: Hi, I am still working my way through my 'Python for absolute beginners book' and have hit a brick wall with one of the end of chapter exercises. The challenge says:
 Improve the function ask_number() so that the function can be called with a step value. Make the default value of step 1. The function looks like this: def ask_number(question, low, high):
 Ask for a number within the range response = None while response not in range(low, high): response =int(raw_input(question)) return response
 The author has not eluded to 'step values' in anyway that I can see in the proceeding chapters!This lights my frustration fire. I wonder whether the author tested thebook?When I worked for a training company I was asked to test a new on-line
course on JCL. I demurred by saying But I don't know JCL.. The replywas that's exactly what we want!So a general recommendation to authors is to have a member of the targetaudience test the book. You Jon have done that but at some cost to you
and those of us on this list.-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Danny Yoo


On Tue, 31 Jan 2006, Jon Moore wrote:

 I have been looking for contact details for the author to ask him what
 he was eluding to with the exercise, but to no avail.

Hi Jon,

I did find errata here:

http://www.muskalipman.com/ptr_detail.cfm?group=Programmingall=1isbn=1-59200-073-8

(bottom of the page)

but as far as contact information, I haven't been able to find anything.
I do agree the challenege exercise as you've put it seems somewhat
nonsensical.  *grin*

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


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
 So a general recommendation to authors is to have a member of the target 
 audience test the book. You Jon have done that but at some cost to you 
 and those of us on this list.

One advantage of doing my book as a web site first was that I had plenty
of testers before committing to print (over 100k visitors). Mind you the 
paper
version still had plenty of mistakes but mostly those were typos...


Alan G. 

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


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
DannyMany thanks for that, I notice a few erratas that I am yet to come up against. This will save my sanity (well some of it)1JonOn 31/01/06, 
Danny Yoo [EMAIL PROTECTED] wrote:
On Tue, 31 Jan 2006, Jon Moore wrote: I have been looking for contact details for the author to ask him what he was eluding to with the exercise, but to no avail.Hi Jon,I did find errata here:
http://www.muskalipman.com/ptr_detail.cfm?group=Programmingall=1isbn=1-59200-073-8(bottom of the page)
but as far as contact information, I haven't been able to find anything.I do agree the challenege exercise as you've put it seems somewhatnonsensical.*grin*
-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
AlanAre you the author of Learn to Program Using Python: A Tutorial for Hobbyists, Self-starters and All Who Want to Learn the Art of Computer Programming?
Is the book still available as a web site?JonOn 31/01/06, Alan Gauld [EMAIL PROTECTED]
 wrote: So a general recommendation to authors is to have a member of the target
 audience test the book. You Jon have done that but at some cost to you and those of us on this list.One advantage of doing my book as a web site first was that I had plentyof testers before committing to print (over 100k visitors). Mind you the
paperversion still had plenty of mistakes but mostly those were typos...Alan G.-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
 Are you the author of Learn to Program Using Python: A Tutorial for
 Hobbyists, Self-starters and All Who Want to Learn the Art of Computer
 Programming?

Yes.

 Is the book still available as a web site?

Yes. It has been substantially rewritten sionce the book was done to 
cover more recent features of Python. But the basic structure and 
content is still the same. The book has 3 chapters whose copyright 
belongs to Addison Wesley and thus are not on the web site but 
OTOH the web site has several topics which were written after 
the book was published

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Newbie question

2005-11-22 Thread Danny Yoo


On Tue, 22 Nov 2005, Douglass, Erik wrote:

 I am trying to follow some online first timer tutorials, and I am
 writing the practice scripts in notepad (only w32 at work :-()..  I save
 the script with a .py extension, and when I run it it opens for a brief
 moment in a command prompt then closes before I even have a chance to
 see what it says.  This may seem trivial, but Python also happens to be
 my first language so this is all new to me.  Using Python 2.4.2

Hi Erik,

No problem.

What's happening is that Windows is closing down any program that's
finished.  Usually, that's what you want, except while you're learning how
to program.  Most of the programs you will be writing will be short,
terminate quickly, and close down before you can see your program's
results!  *grin*


If you run your programs through IDLE, you should be able to see them run
to completion without closing down.  I wrote an introduction to IDLE here:

http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

It's a little outdated, but most of the information there is still
relevant.  (The menu option for running scripts now lives in the Module
menu, I think.)


One other way to get around the program-terminating-closes-window problem
is to keep your program from terminating.  Some people will add a last
statement to their program, like the infamous:

##
raw_input(Please press enter to continue...)
##

which should pause until the user presses the enter key.


Best of wishes to you!

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


Re: [Tutor] Newbie question

2005-11-22 Thread Liam Clarke-Hutchinson
Title: Message



Hi 
Eric, 

Either 
- 

add 
this line to the end of your scripts -
discard= raw_input("Press enter to finish.")

Or - 


Click 
on Start  Run... type cmd.exe and use DOS to move to the directory where 
your scripts are stored and run them via Python there.

It's 
not trivial when you're starting. :-)

Regards, 
Liam 
Clarke-Hutchinson
-Original Message-From: 
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of 
Douglass, ErikSent: Wednesday, 23 November 2005 3:03 
a.m.To: tutor@python.orgSubject: [Tutor] Newbie 
question

  
  I am trying to follow some online 
  first timer tutorials, and I am writing the practice scripts in notepad (only 
  w32 at work L).. I save the script 
  with a .py extension, and when I run it it opens for a brief moment in a 
  command prompt then closes before I even have a chance to see what it 
  says. This may seem trivial, but Python also happens to be my first 
  language so this is all new to me. Using Python 
  2.4.2
  
  Thanks for any help.
  
  Erik

A new monthly electronic newsletter covering all aspects of MED's work is 
now available. Subscribers can choose to receive news from any or all of 
seven categories, free of charge: Growth and Innovation, Strategic Directions, 
Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See 
http://news.business.govt.nz 
for more details.





govt.nz- connecting you to New 
Zealand central  local government services


Any opinions expressed in this message are not necessarily those of the Ministry 
of Economic Development. This message and any files transmitted with it are 
confidential and solely for the use of the intended recipient. If you are not 
the intended recipient or the person responsible for delivery to the intended 
recipient, be advised that you have received this message in error and that any 
use is strictly prohibited. Please contact the sender and delete the message and 
any attachment from your computer. 






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


Re: [Tutor] Newbie question

2005-11-22 Thread Carroll, Barry
Hello, Erik,

Welcome to the maillist.  

From your description, is sounds like you are attempting to run the
scripts by double clicking on them from Windows Explorer, or from the
Run dialog on the Start menu.  Both these methods open a command window
in a new process, run the script, then terminate the process as soon as
the script ends.  

Try opening a command window manually, changing to the directory where
the script resides, and running the program from there.  That way the
window will remain after the script has finished, and you can see the
results.  

One way to get to a command prompt window is to use the XP start menu:

 Start-All Programs-Accessories-Command Prompt

HTH

BGC

==
 Date: Tue, 22 Nov 2005 08:03:08 -0600
 From: Douglass, Erik [EMAIL PROTECTED]
 Subject: [Tutor] Newbie question
 To: tutor@python.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=us-ascii
 
 I am trying to follow some online first timer tutorials, and I am
 writing the practice scripts in notepad (only w32 at work :-()..   I
 save the script with a .py extension, and when I run it it opens for a
 brief moment in a command prompt then closes before I even have a
chance
 to see what it says.  This may seem trivial, but Python also happens
to
 be my first language so this is all new to me.Using Python 2.4.2
 
 
 
 Thanks for any help.
 
 
 
 Erik
 

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


Re: [Tutor] Newbie question

2005-11-22 Thread bob


At 12:20 PM 11/22/2005, Liam Clarke-Hutchinson wrote:
Hi
Eric, 

Either - 

add this line to the end of your scripts
-
discard = raw_input(Press enter to finish.)

Or - 

Click on Start  Run... type cmd.exe and
use DOS to move to the directory where your scripts are stored and run
them via Python there.
This is preferred, since any exception traceback will remain
visible.

It's not trivial when you're starting.
:-)

Regards, 

Liam
Clarke-Hutchinson

-Original Message-
From: [EMAIL PROTECTED]
[
mailto:[EMAIL PROTECTED]] On Behalf Of Douglass,
Erik
Sent: Wednesday, 23 November 2005 3:03 a.m.
To: tutor@python.org
Subject: [Tutor] Newbie question


I am trying to follow some online first timer tutorials, and I am
writing the practice scripts in notepad (only w32 at work
L).. I save the script
with a .py extension, and when I run it it opens for a brief moment in a
command prompt then closes before I even have a chance to see what it
says. This may seem trivial, but Python also happens to be my first
language so this is all new to me. Using Python
2.4.2





Thanks for any help.





Erik



A new monthly electronic newsletter covering all aspects of MED's work is
now available. Subscribers can choose to receive news from any or
all of seven categories, free of charge: Growth and Innovation, Strategic
Directions, Energy and Resources, Business News, ICT, Consumer Issues and
Tourism. See
http://news.business.govt.nz
for more details.





 
govt.nz - connecting you to New Zealand
central  local government services


Any opinions expressed in this message are
not necessarily those of the Ministry of Economic Development. This
message and any files transmitted with it are confidential and solely for
the use of the intended recipient. If you are not the intended recipient
or the person responsible for delivery to the intended recipient, be
advised that you have received this message in error and that any use is
strictly prohibited. Please contact the sender and delete the message and
any attachment from your computer. 

___
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] Newbie question

2005-11-22 Thread Hans Dushanthakumar



A short-cut if you dont want to use DOS to traverse to your 
directory or if you are feeling too lazy to type in the entire path  script 
name.

You can right-click on the script file in the Windows 
explorer and choose "Send to - Command prompt". This opens a command prompt 
with the path already set to the one that you want, and the name of the script 
already typed in. Now, just cursor to the left untill you reach the "" 
prompt and type in "python ". So now your command prompt reads "C:\whatever 
pathpython yourfile.py". Press enter to run the 
script.


From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of bobSent: 
Wednesday, 23 November 2005 10:44 a.m.To: Liam Clarke-Hutchinson; 
'Douglass, Erik'; 'tutor@python.org'Subject: Re: [Tutor] Newbie 
question
At 12:20 PM 11/22/2005, Liam Clarke-Hutchinson wrote:
Hi Eric, 
  Either - 
  add this line to the end of 
  your scripts -discard = raw_input("Press enter to 
  finish.")Or - 
  Click on Start  Run... 
  type cmd.exe and use DOS to move to the directory where your scripts are 
  stored and run them via Python there.This is preferred, 
since any exception traceback will remain visible.
It's not trivial when you're starting. :-)Regards, Liam Clarke-Hutchinson-Original Message-From: [EMAIL PROTECTED] [ 
  mailto:[EMAIL PROTECTED]] On Behalf Of Douglass, 
  ErikSent: Wednesday, 23 November 2005 3:03 a.m.To: 
  tutor@python.orgSubject: [Tutor] Newbie question
  
I am trying to follow some online first timer tutorials, and I am 
writing the practice scripts in notepad (only w32 at work L).. I save the script with a .py 
extension, and when I run it it opens for a brief moment in a command prompt 
then closes before I even have a chance to see what it says. This may 
seem trivial, but Python also happens to be my first language so this is all 
new to me. Using Python 2.4.2

Thanks for any help.

ErikA new 
  monthly electronic newsletter covering all aspects of MED's work is now 
  available. Subscribers can choose to receive news from any or all of 
  seven categories, free of charge: Growth and Innovation, Strategic Directions, 
  Energy and Resources, Business News, ICT, Consumer Issues and Tourism. 
  See http://news.business.govt.nz 
  for more details. govt.nz - 
  connecting you to New Zealand central  local government 
  services
  
  Any opinions expressed in this message are not 
  necessarily those of the Ministry of Economic Development. This message and 
  any files transmitted with it are confidential and solely for the use of the 
  intended recipient. If you are not the intended recipient or the person 
  responsible for delivery to the intended recipient, be advised that you have 
  received this message in error and that any use is strictly prohibited. Please 
  contact the sender and delete the message and any attachment from your 
  computer. 
  
  ___Tutor maillist 
  - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question

2005-11-22 Thread Liam Clarke-Hutchinson
Title: Message



Ooer,weirdkeystrokes... my apologies 
Bob.

This is preferred, since any 
exception traceback will remain visible.
That's a really good 
point... I believe associating a Python batch file using pause 
wouldallow tracebacks to remain also.

@echo 
off
c:\Python24\Python 
%1 %2 %3 %4 %5 %6 %7 %8 %9
pause

or 
similar...
Regards,
Liam 
Clarke-Hutchinsonwww.med.govt.nz 

  
  -Original Message-From: bob 
  [mailto:[EMAIL PROTECTED] Sent: Wednesday, 23 November 2005 
  10:44 a.m.To: Liam Clarke-Hutchinson; 'Douglass, Erik'; 
  'tutor@python.org'Subject: Re: [Tutor] Newbie 
  questionAt 12:20 PM 11/22/2005, Liam Clarke-Hutchinson 
  wrote:
  Hi 
Eric, Either - 
add this line to the end of 
your scripts -discard = raw_input("Press enter to 
finish.")Or - 
Click on Start  Run... 
type cmd.exe and use DOS to move to the directory where your scripts are 
stored and run them via Python there.
  It's not trivial when you're starting. :-)Regards, Liam Clarke-Hutchinson-Original Message-From: 
[EMAIL PROTECTED] [ mailto:[EMAIL PROTECTED]] On Behalf Of 
Douglass, ErikSent: Wednesday, 23 November 2005 3:03 
a.m.To: tutor@python.orgSubject: [Tutor] Newbie 
question

  I am trying to follow some online first timer tutorials, and I am 
  writing the practice scripts in notepad (only w32 at work L).. I save the script with a .py 
  extension, and when I run it it opens for a brief moment in a command 
  prompt then closes before I even have a chance to see what it says. 
  This may seem trivial, but Python also happens to be my first language so 
  this is all new to me. Using Python 2.4.2
   
  Thanks for any 
help.
   
  ErikA 
new monthly electronic newsletter covering all aspects of MED's work is now 
available. Subscribers can choose to receive news from any or all of 
seven categories, free of charge: Growth and Innovation, Strategic 
Directions, Energy and Resources, Business News, ICT, Consumer Issues and 
Tourism. See http://news.business.govt.nz for 
more details. govt.nz - 
connecting you to New Zealand central  local government 
services

Any opinions expressed in this message are not 
necessarily those of the Ministry of Economic Development. This message and 
any files transmitted with it are confidential and solely for the use of the 
intended recipient. If you are not the intended recipient or the person 
responsible for delivery to the intended recipient, be advised that you have 
received this message in error and that any use is strictly prohibited. 
Please contact the sender and delete the message and any attachment from 
your computer. 

___Tutor 
maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

A new monthly electronic newsletter covering all aspects of MED's work is 
now available. Subscribers can choose to receive news from any or all of 
seven categories, free of charge: Growth and Innovation, Strategic Directions, 
Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See 
http://news.business.govt.nz 
for more details.





govt.nz- connecting you to New 
Zealand central  local government services


Any opinions expressed in this message are not necessarily those of the Ministry 
of Economic Development. This message and any files transmitted with it are 
confidential and solely for the use of the intended recipient. If you are not 
the intended recipient or the person responsible for delivery to the intended 
recipient, be advised that you have received this message in error and that any 
use is strictly prohibited. Please contact the sender and delete the message and 
any attachment from your computer. 






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


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Alan Gauld
 friend told me I should learn Perl over Python as it's more
 prevalent.  I'm going to be using it on a Mac.

In that case you should switch to a PC because they are more prevalent.
Also you should learn to program in COBOL since its the most prevalent
of all computer languages.

And yet most folks in the industry prefer Macs to PCs when they have
a choice and most unbiased observers think COBOL sucks!
Python is a lot easier to learn and work with than Perl...
go figure. :-)


-- 
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




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


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Jan Eden
Hi Scott,

Scott Clausen wrote on 30.10.2005:

As a newbie to Python I'd like to know if someone can tell me some
strengths and weaknesses of this language. The reason I'm asking is
a friend told me I should learn Perl over Python as it's more
prevalent.  I'm going to be using it on a Mac.

I'd appreciate hearing any views on this topic. My own view is that
it's always good to learn new things as you then have more tools to
use in your daily programming.

I started learning Python approx. 4 months ago. I had been using Perl for about 
4 years at that time. (BTW, I work on a Mac, too)

The motivation for trying Python came when a certain project needed an OOP 
overhaul. While I was able to code an OOP version of the program, the result 
was rather slow and ugly. This was only partly because of my own deficiencies - 
Perl does not really invite you to produce clean code on larger projects (IMHO).

When I re-coded the very same project in Python, I achieved a much better 
(faster, more readable) result within weeks.

Most comparisons of Perl and Python also highlight Python's cleaner syntax, I 
can second that (although I got used to Perl's @$% syntax after a while).

Cheers,

Jan
-- 
Common sense is what tells you that the world is flat.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Liam Clarke
On 10/31/05, Scott Clausen [EMAIL PROTECTED] wrote:
 As a newbie to Python I'd like to know if someone can tell me some
 strengths and weaknesses of this language. The reason I'm asking is a
 friend told me I should learn Perl over Python as it's more
 prevalent.  I'm going to be using it on a Mac.

 I'd appreciate hearing any views on this topic. My own view is that
 it's always good to learn new things as you then have more tools to
 use in your daily programming.

 Thanks in advance.


Hi Scott,

I would say, it really depends on where you're coming from and where
you're going, coding wise. If your background is primarily Linux
scripting with sh, awk, grep, sed, (sed?) etc, then Perl will be a
nice and natural fit.

If you're starting from a clean slate, then I would recommend Python,
speaking as a relative beginner who had to make that choice myself not
too long ago.

Python has a nice clean syntax, which means that your errors are
usually errors of logic and not errors of using an @ instead of a $,
or missing a }, etc.

Perl has an incredibly huge library, and for a beginner, that's
challenging. Python's standard  library encompasses about 98% of
everything I need to do, and in a year of coding in Python, I'm still
not familiar with all of it, but I have a fair idea of where to find
particular functionality. I tried Perl and got incredibly confused by
CPAN.

Python is OO from the get go. Want to subclass integers? Sure, go right ahead.
Whereas, Perl tends to show it's roots in aforementioned shell
scripts, and the OO side feels awkward.

Also, I'll just mention a pet peeve of mine regarding Perl. It
flattens lists using the simple syntax. To nest a list requires
special syntax that most tutorials don't mention...

The classic reasons to prefer one over the other are a) scalability,
and b) maintainability.
Python scales well, and is quite straightforward to maintain, although
I live by the mantra that one can write Perl in any language.

The catch-cry of Perl is there's more than one way to do it. As a
learner, you'll spend a lot of time asking But which is the best
way? In Python, there's generally a straight-forward and obvious way,
and it's usually the best and simplest.

i.e. you can stick the items of a one list in another two ways, a for
loop, and a list method.
x=[1,2,3]
y = [4,5,6]
#either
for item in y:
x.append(item)

#or
x.extend(y)

The extend() method is simpler, and faster.

With regards to where you're going in the future, I don't know what
the future holds for Perl, but watching the .NET framework arise, I
think that Microsoft has the LAMP combination in it's sights. There's
already a Python implementation for the .NET framework, it's called
IronPython, (it's in alpha at the mo).

To be honest, if you still wanted to go with Perl, I'd recommend you
learn Ruby instead.
It originated in Perl, but it's just flat out better. It's the
language that experienced Perl users migrate to, as it has minimal
culture shock. And, Ruby on Rails is a great framework.

Ruby's standard library is quite minimal on the docs at the moment,
and the 3rd party modules aren't there, yet, whereas Python has a
mature community.

Good luck,

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


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Andrew P
If you are interested in learning another tool, please, start with
Python.  If you are interested in scripting UNIX, Perl is a fine
choice.  There prevalence matters, and quite a bit.  But sys admins
are usually very Perl-centric, and in my experience monolingual, and a
bit of an insular community :)

Python is more than the equal of Perl by any measure.  Including
system administration.  But moving beyond that is also a lovely
language for building applications, and everything from lightweight
CGI scripts to using hefty web frameworks, of which there are plenty
to choose from.

Perl is a language of exceptions to the rules.  Python tries very hard
to be consistent, which makes it much easier to learn, and much easier
to use, and much, much easier to apply the concepts you have learned
to other languages.  Including Perl, as a second or third language.

Perl can be coerced into big jobs, but it's not very pleasant.   The
best you can hope to keep in your head at once is your own set of
idioms, which will -not- match anybody elses, and will likely change
from week to week on you anyway.   And really when people tell you
they can't read what they wrote the day before when they come back to
it, they aren't lying!

Having said that, I love Perl, because it -is- quirky and sprawling
and lovable.  It's pretty much the worst case scenario of
everything-and-the-kitchen-sink, and really not so bad for all that,
and definitely more fun for it.  So if that appeals, then you'll have
fun too.

But Python tends to be compared to general purpose languages like Java
and C++ more often.  OOP heavyweights of the world.  Actually, let me
find that quote by Bruce Eckel, who wrote the (very) popular Thinking
in Java and Thinking in C++ books.  Here it is:

I believe it was definitely worth moving from C to C++, and from C++
to Java. So there was progress there. For something as advanced as
Python is over those languages -- and as different -- there will be
some hesitation.

And:

When you have the experience of really being able to be as productive
as possible, then you start to get pissed off at other languages. You
think, 'Gee, I've been wasting my time with these other languages.'

That second quote applies to many language vs language comparisons,
obviously.  But it's food for thought.

Oh, and never underestimate the power of the interactive interpreter! 
Don't do it!  Ever!

Take care,

Andrew

On 10/30/05, Scott Clausen [EMAIL PROTECTED] wrote:
 As a newbie to Python I'd like to know if someone can tell me some
 strengths and weaknesses of this language. The reason I'm asking is a
 friend told me I should learn Perl over Python as it's more
 prevalent.  I'm going to be using it on a Mac.

 I'd appreciate hearing any views on this topic. My own view is that
 it's always good to learn new things as you then have more tools to
 use in your daily programming.

 Thanks in advance.

 Scott
 ___
 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] Newbie Question - Python vs Perl

2005-10-31 Thread Tim Johnson
* Scott Clausen [EMAIL PROTECTED] [051030 16:30]:
 As a newbie to Python I'd like to know if someone can tell me some  
 strengths and weaknesses of this language. The reason I'm asking is a  
 friend told me I should learn Perl over Python as it's more  
 prevalent.  I'm going to be using it on a Mac.
 
  Prevalent? So what? Forget Perl entirely. Learn python and rebol 
  (www.rebol.com). At the same time.
  That's how we trained programmers here.
  Rebol arguably exceeds both python and perl in terms of sheer
  productivity on a line for line basis, but has a very small 
  user base and fewer modules.

  But the bottom line is to be multi-lingual. 
  Here's a pretty standard coding day for me.
  1)Write rebol code which parses html and generates python, perl
   and javascript code for deployment.
  2)Write python code for the deployment (front end), database
   interaction, server-side data validation etc.
  3)Write Javascript for client-side data validation, dynamic
html etc.
  4)Write elisp code to enhance productivity of my Emacs and Xemacs
Editors.
  5)Use vim/gvim for system wide analysis and editing.

  I believe the rebol is pretty straight-forward and easy to
  install for the mac.

  I use Python for most of the services used directly by customers
  on larger projects 'cuz it scales better (for me). and python teaches
  me good coding practices. IOWS, coding in python makes me a better
  rebol programmer too.

  The bottom line is don't get stuck on one programming language.
  I've seen new programmers go thru a fast learning curve, pick up
  something faster than an ol' fart like me would, but get so
  settled in one programming niche or another that they can't or
  won't change. Not good!

  I think python is the best way to learn *good* programming.
  MTCW
  tim

 I'd appreciate hearing any views on this topic. My own view is that  
 it's always good to learn new things as you then have more tools to  
 use in your daily programming.
 
 Thanks in advance.
 
 Scott
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson [EMAIL PROTECTED]
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-30 Thread Kent Johnson


Scott Clausen wrote:
 As a newbie to Python I'd like to know if someone can tell me some  
 strengths and weaknesses of this language. The reason I'm asking is a  
 friend told me I should learn Perl over Python as it's more  
 prevalent.  I'm going to be using it on a Mac.

http://wiki.python.org/moin/BeginnersGuide/Overview
http://www.linuxjournal.com/article/3882

You might be interested in this site that lets you compare Python and Perl code
http://pleac.sourceforge.net/

-- 
http://www.kentsjohnson.com

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


Re: [Tutor] Newbie question

2005-04-19 Thread Alan Gauld
 def square(y):
return y * y
 
 for x in range(1, 11):
print square(x),
 
 print
 
 Well, I understood the code above. My question is: Is
 it really necessary I have the last print statment

No, it just creates a blank line which makes it easier to separate 
the output of the program from the other stuff on the screen. 
Its a convenience feature which although not essential helps 
the user see the results.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question

2005-04-18 Thread Lee Cullens
That just gives you a spacer line after your output. To see such as a 
separator change it to   print '*'*10

On Apr 18, 2005, at 8:55 PM, Hoffmann wrote:
Hi All:
I am a newbie, and I am enjoying to study Python a
lot. I have a question about an example I got from one
of my books.
The program is:
def square(y):
   return y * y
for x in range(1, 11):
   print square(x),
print
Well, I understood the code above. My question is: Is
it really necessary I have the last print statment
(last line) in the code?
Thanks a lot in advance.
Hoffmann
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question

2005-04-18 Thread Brian van den Broek
Lee Cullens said unto the world upon 2005-04-18 21:07:
That just gives you a spacer line after your output. To see such as a 
separator change it to   print '*'*10

On Apr 18, 2005, at 8:55 PM, Hoffmann wrote:
Hi All:
I am a newbie, and I am enjoying to study Python a
lot. I have a question about an example I got from one
of my books.
The program is:
def square(y):
   return y * y
for x in range(1, 11):
   print square(x),
print
Well, I understood the code above. My question is: Is
it really necessary I have the last print statment
(last line) in the code?
Thanks a lot in advance.
Hoffmann

Hi all,
in the particular case, it is more than just a spacer, I think. It 
serves to break the print on the same line feature of the
print some_thing,
statement in the loop. Without it, the next thing printed will be on 
the same line:

 for i in range(1): # contrived to keep it all in block construct
... for i in range(5):
... print 'in',
... print 'out'
...
in in in in in out
(Unless, of course, that is what Lee meant. In which case--nevermind :-)
Best,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question

2005-04-18 Thread Lee Cullens
Thank you Brian for making the point that I did such a poor job of 
conveying.  My post did indeed fail to clearly and concisely answer the 
question.

Lee C
On Apr 18, 2005, at 11:34 PM, Brian van den Broek wrote:
Lee Cullens said unto the world upon 2005-04-18 21:07:
That just gives you a spacer line after your output. To see such as a 
separator change it to   print '*'*10
On Apr 18, 2005, at 8:55 PM, Hoffmann wrote:
Hi All:
I am a newbie, and I am enjoying to study Python a
lot. I have a question about an example I got from one
of my books.
The program is:
def square(y):
   return y * y
for x in range(1, 11):
   print square(x),
print
Well, I understood the code above. My question is: Is
it really necessary I have the last print statment
(last line) in the code?
Thanks a lot in advance.
Hoffmann

Hi all,
in the particular case, it is more than just a spacer, I think. It 
serves to break the print on the same line feature of the
print some_thing,
statement in the loop. Without it, the next thing printed will be on 
the same line:

 for i in range(1): # contrived to keep it all in block construct
... for i in range(5):
... print 'in',
... print 'out'
...
in in in in in out
(Unless, of course, that is what Lee meant. In which case--nevermind 
:-)

Best,
Brian vdB
___
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] 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 script.py

  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


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] NewBie Question... Variables

2005-02-15 Thread Liam Clarke
a = foo
b = bar
c = duck

print I will say only this -  %s to your %s and no %s % (a, b, c)

I will say only this - foo to your bar and no duck

And so forth. 

On Tue, 15 Feb 2005 19:07:56 +0900,   [EMAIL PROTECTED] wrote:
 How can I do it with several variables?
 
 I = John
 print %s used to love pizza % I
 
 About 10 or more...
 
 HELP plz :)
 
 _
 .   MSN  
 .
 http://www.msn.co.kr/news/
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor