Re: [Tutor] help

2005-03-13 Thread C Smith
On Sunday, Mar 13, 2005, at 05:01 America/Chicago, 
[EMAIL PROTECTED] wrote:

if this is not a program please teach me what is a
program and what i need to know to write them and if this is a program 
teach me
how to write better programs i can use outside of the python shell...
OK, how about this for starters:
http://www.ibiblio.org/obp/thinkCS/python/english/
This is an introductory html text that can act as a teacher for you. 
(There are some other resources at that address, too.)  It is the text 
that I used in an introductory programming class that I taught. As you 
go through this you sill start to learn the answers to your questions.

As to your desire to write programs you can use outside the 
shell...well that will come after you have an idea of what you would 
like to do and learn how to "say it" with a language.  But at this 
point I think your main task will be to learn how to "say things" in 
general.  Python is a nice language to work with in this regard.

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


[Tutor] re help

2005-03-13 Thread Ron Nixon
The following program takes text data like this:
Jimi Hendrix
2100 South Ave
Seattle, WA 55408

and changes it to this 

Jimi Hendrix, 2100 South Ave,Seattle,WA,55488

and writes it to a file. The problem I'm running into
is that it only writes this first address to a file
and there are several others in the file. I believe it
has something to do with using re.search instead of
re.findall. But re.findall returns a error when I try
using it. Suggestions? Thanks in advance.
Here is the script:

import re
f = open('reformat.txt').read()
pat = re.compile(r"([^\r\n]+)\n([^\r\n]*)\n([^\r\n]*)
([^\r\n]*) ([^\r\n]*)")
x=re.search(pat,f)
name = x.group(1)
address = x.group(2)
citystate = x.group(3)+x.group(4)
zipcd = x.group(5)
o= open('reformat1.txt','w')
o.write("%s,%s,%s,%s\n" % (name, address,
citystate,zipcd))
o.close()
print("%s,%s,%s,%s\n" % (name, address, citystate,zipcd))



__ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] command for clearing user screen input

2005-03-13 Thread Kent Johnson
Gopinath V, ASDC Chennai wrote:
HI all,
   I'm trying a series of inputs ...i need to get the screen cleared 
after every 5 inputs...can any 1 tell me how do I do it
Presuming you are using some kind of console window, you can do something 
like
print '\n' * 50
Anything fancier is platform dependent so you will have to tell us what platform you are on and if 
it is a console window or something else.

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


[Tutor] funny behaviour

2005-03-13 Thread Jacob Abraham
Dear Tutors,

   A class was created to extend timedelta to add and
subtract months. Simple doctests that simply create an
instance of the class failed. Could someone please
explain this really funny behaviour.

Regards,
Jacob Abraham

from datetime import datetime, timedelta

class WeirdTimeDelta(timedelta):
"""Allows addition and subtraction of months.

Variables are getting passed to the timedelta
constructor ??

>>> delta = WeirdTimeDelta(5)
>>> delta.days
0

Should'nt this work ???

>>> delta = WeirdTimeDelta(months=5)

"""

def __init__(self, months=0, *vals, **kwds):
"""Constructs a weird time delta."""
super(WeirdTimeDelta, self).__init__(*vals,
**kwds)
self.months = months

if __name__ == "__main__":
import doctest
doctest.testmod()

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] command for clearing user screen input

2005-03-13 Thread Gopinath V, ASDC Chennai
Title: command for clearing user screen input





HI all,
   I'm trying a series of inputs ...i need to get the screen cleared after every 5 inputs...can any 1 tell me how do I do it

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, March 13, 2005 4:31 PM
To: tutor@python.org
Subject: Tutor Digest, Vol 13, Issue 36


Send Tutor mailing list submissions to
    tutor@python.org


To subscribe or unsubscribe via the World Wide Web, visit
    http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
    [EMAIL PROTECTED]


You can reach the person managing the list at
    [EMAIL PROTECTED]


When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."



Today's Topics:


   1. Re: Code example (Alan Gauld)
   2. Re: Whats so good about OOP ? (Alan Gauld)
   3. Re: Whats so good about OOP ? (Sean Perry)
   4. Re: Whats so good about OOP ? (Sean Perry)
   5. help ([EMAIL PROTECTED])



--


Message: 1
Date: Sun, 13 Mar 2005 00:27:42 -
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Code example
To: "Mike Wagman" <[EMAIL PROTECTED]>, 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;   charset="Windows-1252"


> Can someone please show me an example of two programs - you run one
in
> console one - then when you run one in console two - it talks to the
> first program = sending a specific string instructing the first one
to
> close.


Look at the socket examples in the Python web pages.
The sender and receiver programs are exactly what you want.


If you don't understand them come back with more specific
questions


HTH,


Alan G.




--


Message: 2
Date: Sun, 13 Mar 2005 00:34:58 -
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Whats so good about OOP ?
To: "Mark Kels" <[EMAIL PROTECTED]>, 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;   charset="iso-8859-1"


> Can anyone give me an example for a task that could be done only
with
> OOP or will be much simpler to do with it ?


Anything that can be done in OOP can be done without it.
But OOP makes many things easier.


But OOP only really becomes useful in bigger programs. If your biggest
program is less than 100 lines of code then you probably haven't hit
the kinds of problems that OOP solves. Between 100 and 1000 lines you
increasingly hit problems of complexity, name collisions ( two things
with the same name), and writing nearly identical code lots of times.


By the time you get over 1000 lines all of those problems are
compounded
by the fact that you can't actually keep all the details in your head
anymore! Objects help bring some sanity to the procedings.


Finally, once you get your head around the concept of objects being
like little independant programms communicating via messages then they
start to fit certain types of problem very well. THe classic case is
the GUI with each window, doalog box, button, menu etc being
independant objects, but with a lot of common functions and a lot
of inter-communication. When you coule that to the event-driven
style of most GUI toolkits then events translate easily into
inter-object messages and OOP becomes a very natural way to program
GUIs.


HTH,


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




--


Message: 3
Date: Sat, 12 Mar 2005 23:49:28 -0800
From: Sean Perry <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Whats so good about OOP ?
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed


Brian van den Broek wrote:
> 
> 1) Namespace issues
> With procedural (or imperative -- don't know which is the right terms
> for non-OOP code which employs functions) code, you can have issues
> caused by namespaces. Just yesterday, someone on the main python
> list/newsgroup had code something like:
> 


procedural v. OO
imperative v. functional


In an imperative language you tell the computer what to do (imperative):
"put 5 in X, use X in function foo, store foo's result in blah". The 
base component is an imperative statement. If you have not had an 
English grammar class recently imperative sentences are things like 
"You, bring me my supper".


In a functional language, the base item is a function.


foo(X(blah())) or for the lispy people (foo (x (blah))).


You could do OO in a functional language. Haskell for instance has a 
concept of classes, user defined types, polymorphism, etc.


The point is, these are two axes on the programming language chart.


procedural, imperative -> C
OO, functional -> OCaml (close enough anyways)



--


Message: 4
Date: Sat, 12 Mar 2005 23:57:50 -0800
From: Sean Perry <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Whats so good ab

Re: [Tutor] help [Please use better subject lines than "help!"]

2005-03-13 Thread Danny Yoo


On Sun, 13 Mar 2005, R. Alan Monroe wrote:

> > ok i have learned that on the python shell or new window you can
> > type in..print "hello world"...and the output is ..'hello
> > world'.. or you can put in anything realy and it say it back to
> > you.is this a program or what
>
> Yep, that's a program. Just an ultra, ultra-simple one.
>
> > how to write better programs
>
> Have you learnt the "if" statement yet? If not, that's the next thing
> you want to learn. Tell us if you get stuck.

[meta: mailing list admin stuff]

Hi Jeff,

And when you tell us, please make the subject line a little bit more
descriptive.  Your last two messages had subject lines like "help!" or
"help me!".  We wouldn't be here if we didn't want to help.  *grin*

There's actually a very pratical reason why you should be more
descriptive: Your messages are actually not getting through directly to
the list because the mailing list software sees the naked word "help!" and
thinks that it's an administrative request!

Such messages get put on to a "moderation queue" that must be manually
curated by some poor, brain-dead mailing list administrator.  I would
laugh at that person, except that I am that brain-dead mailing list admin.
And I have to manually release messages that are caught in the moderation
queue from time to time, which sometime explains why it looks like it
takes a while for you messages to get to the list.

So if you can, please make my life easier: try to make your subject
headers more descriptive, like:

"Is this a program?"

A descriptive subject line should avoid manual moderation from the mailing
list software.


We're also trying to encourage good mailing list habits because all the
messages on the list are archived:

http://mail.python.org/pipermail/tutor/

and it is much easier for people to learn and find information from the
archives if messages have useful titles.


Best of wishes to you!

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


Re: [Tutor] python>data>sqlite>python>data>paper

2005-03-13 Thread Danny Yoo


On Sat, 12 Mar 2005, [iso-8859-1] Jan Ekström wrote:

> I have looked through a lot of tutor documentation. But I would ask
> someone to show me python code for putting som data in a sqlite database
> and code showing how I get data out of such a database

Hi Jan,


You may want to look at:

http://www.linuxjournal.com/articles/lj/0110/6650/6650l3.html

SQLite is, by its name, a light SQL database, so you may find the
documentation in:

http://www.python.org/topics/database/

and, in particular:

http://www.linuxjournal.com/article/2605

helpful in getting started with SQL databases.  You might also find the
Database Special Interest Group (DB-SIG) a valuable resource:

http://www.python.org/sigs/db-sig/


> and finaly code for printing data on a special part of a paper.

I think you might need to be more specific here.  Can you give us more
details about how you're trying to print, and what you mean by "special
part"?  Without any more details, I can only guess that you might be
interested in the Reportlab PDF generator:

http://www.reportlab.org/rl_toolkit.html

but again, I have no clue what you mean yet.  *grin*


Best of wishes to you!

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


RE: [Tutor] Newbie in Python (fwd)

2005-03-13 Thread Danny Yoo

On Sun, 13 Mar 2005, Danny Yoo wrote:

> Thanks for the reply..i wasn't sure how this works so I am glad there is
> someone that might be able to help me.  Because this is an university
> assignment I am not sure how much of help you can provide..but here it
> goes.

[text cut]

As you might understand, we won't do homework.  We'll try to point you
toward things that will help, but otherwise, our help will be very
restricted.


[homework problem statement cut]

I'll pretend that I did not read that problem statement, since most of it
is pretty much off-limits to us as Python-Tutors, and irrelevant to the
question that you have given us.


Let's get straight to your question.

> ---I am stuck in understanding how I can go about opening the
> folder(directory) that contains all the files that I need to process for
> this assignment.  As the folder contains sub folders ie and then the
> email files that need to be processed.

You may want to look at the 'os' module,

http://www.python.org/doc/lib/module-os.html

as it includes functions that deal with operating systems and directory
managment.  In particular, you may want to experiment with os.walk():

http://www.python.org/doc/lib/os-file-dir.html#l2h-1617

Other functions like os.chdir() or os.listdir() might also be useful to
you, as well as the utility functions in os.path:

http://www.python.org/doc/lib/module-os.path.html

I suspect, though, that os.walk() should do the trick.


If you have more questions, please feel free to ask.  But don't just
copy-and-paste problem statements from your homework: we will actively try
to ignore those.  We're much more interested in the questions that you
have.

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


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread Danny Yoo


On Sun, 13 Mar 2005, Brian van den Broek wrote:

> jrlen balane said unto the world upon 2005-03-13 19:37:
> > so for example, i am creating a text file with file.write()
> >
> > how am i going to make the file a tab-delimited file??? any
> > parameters needed???
> >
>
>  >>> record1 = ['Foo', 'Bar', 'Baz']
>  >>> record2 = ['Ham', 'Spam', 'Eggs']
>  >>> records = [record1, record2]
>  >>> lines = []
>  >>> for record in records:
> ...   lines.append('\t'.join(record) + '\n')
> ...


The 'csv' module might also be really handy here.  For example, we can
adapt the code from:

http://www.python.org/doc/lib/node617.html

Let me write Brian's example with 'csv', just to show how it works.

##
>>> record1 = ['Foo', 'Bar', 'Baz']
>>> record2 = ['Ham', 'Spam', 'Eggs']
>>> import sys
>>> writer = csv.writer(sys.stdout)
>>> for row in [record1, record2]:
... writer.writerow(row)
...
Foo,Bar,Baz
Ham,Spam,Eggs
##


By default, the 'csv' writer uses commas as separators, but we can set the
'dialect' of a csv writer to the 'excel-tab' dialect, which uses tabs as
delimiters:

##
>>> writer = csv.writer(sys.stdout, dialect='excel-tab')
>>> for row in [record1, record2]:
... writer.writerow(row)
...
Foo Bar Baz
Ham SpamEggs
##


I hope this helps!

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


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread Brian van den Broek
jrlen balane said unto the world upon 2005-03-13 19:37:
so for example, i am creating a text file with file.write()
how am i going to make the file a tab-delimited file??? any
parameters needed???
>>> record1 = ['Foo', 'Bar', 'Baz']
>>> record2 = ['Ham', 'Spam', 'Eggs']
>>> records = [record1, record2]
>>> lines = []
>>> for record in records:
... lines.append('\t'.join(record) + '\n')
...
>>> lines
['Foo\tBar\tBaz\n', 'Ham\tSpam\tEggs\n']
>>> output_file = file('c:/output.txt', 'w')
>>> output_file.writelines(lines)
>>> output_file.close()
>>>
HTH,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread jrlen balane
specifically, I want to write an array in to a text file, how am i
going to make the file a tab-delimited file???


On Mon, 14 Mar 2005 08:37:35 +0800, jrlen balane <[EMAIL PROTECTED]> wrote:
> so for example, i am creating a text file with
> file.write()
> 
> how am i going to make the file a tab-delimited file??? any parameters 
> needed???
> 
> 
> On Sun, 13 Mar 2005 15:59:46 -0800 (PST), Danny Yoo
> <[EMAIL PROTECTED]> wrote:
> >
> >
> > On Sun, 13 Mar 2005, jrlen balane wrote:
> >
> > > what does a tab delimited filename mean? how am i going to make this?
> > > also how does it differs from space delimited, csv, and others?
> >
> > Hello,
> >
> > As Kent mentioned, you probably mean "tab delimited file", which means a
> > file whose lines are split up into columns.  Each column is separated by a
> > tab, which, in theory, should make it easy to parse.
> >
> > The main difference between a tab-delimited file and the others you
> > mention is the "delimiter", the separator that's chosen to break columns
> > apart.
> >
> > By the way, you might be interested in:
> >
> > http://www.faqs.org/docs/artu/ch05s02.html#id2901882
> >
> > which talks a lot more about file formats in Unix and their relative
> > strengths and weaknesses.
> >
> > Best of wishes to you!
> >
> >
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread jrlen balane
so for example, i am creating a text file with 
file.write()

how am i going to make the file a tab-delimited file??? any parameters needed???


On Sun, 13 Mar 2005 15:59:46 -0800 (PST), Danny Yoo
<[EMAIL PROTECTED]> wrote:
> 
> 
> On Sun, 13 Mar 2005, jrlen balane wrote:
> 
> > what does a tab delimited filename mean? how am i going to make this?
> > also how does it differs from space delimited, csv, and others?
> 
> Hello,
> 
> As Kent mentioned, you probably mean "tab delimited file", which means a
> file whose lines are split up into columns.  Each column is separated by a
> tab, which, in theory, should make it easy to parse.
> 
> The main difference between a tab-delimited file and the others you
> mention is the "delimiter", the separator that's chosen to break columns
> apart.
> 
> By the way, you might be interested in:
> 
> http://www.faqs.org/docs/artu/ch05s02.html#id2901882
> 
> which talks a lot more about file formats in Unix and their relative
> strengths and weaknesses.
> 
> Best of wishes to you!
> 
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread Danny Yoo


On Sun, 13 Mar 2005, jrlen balane wrote:

> what does a tab delimited filename mean? how am i going to make this?
> also how does it differs from space delimited, csv, and others?

Hello,

As Kent mentioned, you probably mean "tab delimited file", which means a
file whose lines are split up into columns.  Each column is separated by a
tab, which, in theory, should make it easy to parse.

The main difference between a tab-delimited file and the others you
mention is the "delimiter", the separator that's chosen to break columns
apart.

By the way, you might be interested in:

http://www.faqs.org/docs/artu/ch05s02.html#id2901882

which talks a lot more about file formats in Unix and their relative
strengths and weaknesses.

Best of wishes to you!

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


Re: [Tutor] Terminology WAS Whats so good about OOP ?

2005-03-13 Thread Danny Yoo


> > 
> > Where I come from, the output of a function is determined by the input
> > to the function.
>
>   Well, actually, your being upset at that is the exact point of
> functional programming languages: in functional programming, the output
> of a function is determined by its input, and *only* its input.
> Therefore, there are no side-effects (variables being one) calling a
> function twice with the same arguments will *always* yield the same
> result.
>
>   The only time this paradigm is broken is (of course) when dealing
> with I/O.

Hi Max,


Just as an off-topic tangent: the "of course" part might need
qualification.  *grin*

Haskell, one of the main representatives of the functional programming
languages, uses the concept of "monads" to handle I/O.  Philip Wadler has
a whole page dedicated to monads:

http://homepages.inf.ed.ac.uk/wadler/topics/monads.html

where I/O fits in cleanly with the functional programming paradigm.
There appears to be a monad tutorial page here:

http://www.nomaware.com/monads/html/

Best of wishes!

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


RE: [Tutor] Newbie in Python (fwd)

2005-03-13 Thread Danny Yoo


-- Forwarded message --
Date: Sun, 13 Mar 2005 21:58:09 +1100
From: oscar ng <[EMAIL PROTECTED]>
To: 'Danny Yoo' <[EMAIL PROTECTED]>
Subject: RE: [Tutor] Newbie in Python

Hi Danny,

Thanks for the reply..i wasn't sure how this works so I am glad there is
someone that might be able to help me.  Because this is an university
assignment I am not sure how much of help you can provide..but here it
goes.

I need to build a mail filtering system that detects sorts mail messages
into appropriate categories, such as spam, job announcement and
conference announcement.

The assignment will be in two parts. In the first part you will try your
own approaches to solving the problem, using the Natural Language
Toolkit package for Python. In the second part, you will use the
techniques learned in the classes on text classification, and compare
the results of these and your own.


What Is Given
The target dataset consists of four types of documents, a list of spam
mail messages and a list of messages sent to various newsgroups. The
four types of documents are located in different directories. Each
document is formatted as an email message with the main text and two
email headers: From and Subject. All the HTML code has been removed.
Below is an example of a message from the corpus:

From: [EMAIL PROTECTED]
Subject: YOUR APPLICATION HAS BEEN APPROVED

 You Have Been APPROVED
for 3 UNSECURED VISA and MASTERCARDS!


Are you at least 18 Years of age?
Have a Valid Social Security No?
Income of at Least $99 p/week?
YOU'RE APPROVED!

Our Banks offer:
INSTANT FREE ONLINE APPROVAL!

Receive your cards in as little as
TWO Weeks from Today!

Just in Time for Summer Vacation!

For more information on how you can get your Visa or
Mastercards NOW, click on the link below:
MailTo:[EMAIL PROTECTED]



***
If you are no longer interested in receiving information
on Credit Cards or Financial Services, please click on
the link below and you will be removed from our optin list.
MailTo:[EMAIL PROTECTED]

The four categories are as follows:
spam
job announcements (now available)
conference announcements (now available)
other emails



What your code should do for Part I, then, is to tokenise the files,
classify the emails according to your own algorithm, and output the
results of the classification. Your algorithm might specify, for
example, that emails with greater than X% of capitalised words are spam.
Your algorithm for this part can be quite simple; the main aim is to get
the infrastructure built for Part II, and to get you thinking about what
is involved in these sorts of systems.

The output of your code might look as follows:

24 messages are SPAM (77% correct): msg-a-2 msg-a-3 ...
11 messages are JOB ANN (63% correct): ja-4 ja-6 ...
35 messages are CONF ANN (84% correct): ca-1 ca-3 msg-a-11 ...
9 messages are OTHER (22% correct): 1 10001 ...

---I am stuck in understanding how I can go about opening the
folder(directory) that contains all the files that I need to process for
this assignment.  As the folder contains sub folders ie and then the
email files that need to be processed.

Thanks for your time in reading this and hope to hear from you soon..
If you need more info there is a link
http://www.comp.mq.edu.au/units/comp348/assignments/ass1.html

-Original Message-
From: Danny Yoo [mailto:[EMAIL PROTECTED]
Sent: Friday, 11 March 2005 6:04 AM
To: oscar ng
Cc: tutor@python.org
Subject: Re: [Tutor] Newbie in Python

On Thu, 10 Mar 2005, oscar ng wrote:

> Needing help on a mail filtering system that explores the headers and
> text and determines which category the email falls into.

[text cut]

Hi Oscar,

Ok.  What help do you need?  You have not told us what problems you're
having, so we're stuck just twiddling our thumbs.  *grin*


Are you already aware of projects that do this, or are you doing this
for
fun?  The SpamBayes project has quite a bit of source code that may
interest you:

http://spambayes.sourceforge.net/

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


Re: [Tutor] Terminology WAS Whats so good about OOP ?

2005-03-13 Thread Max Noel
On Mar 13, 2005, at 18:38, Brian van den Broek wrote:
Thanks for the explanation, Sean.
The reference to grammatical theory here does seem to make sense. But, 
relying on correspondence between the technical terms in 
programming/comp. sci. and other fields with similar terminology can 
get in the way, too.

I've a background in formal logic; it took me some effort to stop 
being upset that in Pythonic programming parlance get_a_random_element 
is a "function":


Where I come from, the output of a function is determined by the input 
to the function.
	Well, actually, your being upset at that is the exact point of 
functional programming languages: in functional programming, the output 
of a function is determined by its input, and *only* its input. 
Therefore, there are no side-effects (variables being one) calling a 
function twice with the same arguments will *always* yield the same 
result.
	The only time this paradigm is broken is (of course) when dealing with 
I/O.

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

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


[Tutor] Terminology WAS Whats so good about OOP ?

2005-03-13 Thread Brian van den Broek
Sean Perry said unto the world upon 2005-03-13 02:49:
Brian van den Broek wrote:
1) Namespace issues
With procedural (or imperative -- don't know which is the right terms
for non-OOP code which employs functions) code, you can have issues
caused by namespaces. Just yesterday, someone on the main python
list/newsgroup had code something like:
procedural v. OO
imperative v. functional
In an imperative language you tell the computer what to do (imperative):
"put 5 in X, use X in function foo, store foo's result in blah". The 
base component is an imperative statement. If you have not had an 
English grammar class recently imperative sentences are things like 
"You, bring me my supper".

In a functional language, the base item is a function.
foo(X(blah())) or for the lispy people (foo (x (blah))).
You could do OO in a functional language. Haskell for instance has a 
concept of classes, user defined types, polymorphism, etc.

The point is, these are two axes on the programming language chart.
procedural, imperative -> C
OO, functional -> OCaml (close enough anyways)
Thanks for the explanation, Sean.
The reference to grammatical theory here does seem to make sense. But, 
relying on correspondence between the technical terms in 
programming/comp. sci. and other fields with similar terminology can 
get in the way, too.

I've a background in formal logic; it took me some effort to stop 
being upset that in Pythonic programming parlance get_a_random_element 
is a "function":

import random
def get_a_random_element(sequence):
return random.choice(sequence)
(Never mind that you wouldn't really write this; I needed it to 
genuinely be a function for the example.)

Where I come from, the output of a function is determined by the input 
to the function.

Anyway, thanks again. Best to all,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread Kent Johnson
jrlen balane wrote:
what does a tab delimited filename mean? how am i going to make this?
also how does it  differs from space delimited, csv, and others?
I think you probably mean "tab-delimited file", not "filename".
A tab-delimited file is similar to a space-delimited file. It is typically a record-oriented text 
file with one record per line, with fields of a record separated by tabs.

Like space-delimited files, this is a very easy format to read and write.
Kent
can't really find an article that could put me in the right direction
so i posted here. thanks in advance.
___
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] Clear the text in an entry widget

2005-03-13 Thread David Holland
Thanks John,

That works, the problem was that I had written 
self.answer_ent.grid.delete(0.0, END)

However when I replaced the 0.0 with a 0, it worked
fine.
At least I found a work around but your idea is much
more elegant.

David
--- John Fouhy <[EMAIL PROTECTED]> wrote:
> David Holland wrote:
> > I have written a simple test your maths program.
> > There is just one question, how do you clear the
> text
> > in a tkinter widget ?
> 
> If you have an entry widget e, then e.delete(0, END)
> will clear it.
> 
> Have a look at the docs here: 
>
http://www.pythonware.com/library/tkinter/introduction/
> 
> They aren't complete, but they are the best I have
> found...
> 
> -- 
> John.
> 

Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Clear the text in an entry widget

2005-03-13 Thread David Holland
I have written a simple test your maths program.
There is just one question, how do you clear the text
in a tkinter widget ?
The only way that I could do it was to create a
function to create the entry widget and then have it
re-created.  Is there a better way.
This is the way I did :-


def create_entry(self):
#self.label2_lbl.grid(row = 10, column = 0,
columnspan = 2, sticky = W)
self.answer_ent = Entry(self, width = 20)
self.answer_ent.grid(row = 10, column = 2,
columnspan = 4)
self.answer_txt = Text(self, width = 80,
height = 5)
self.answer_txt.grid(row = 14, column = 2,
columnspan = 4)

When the user asks for another a question and when the
program is initiated this is called.


Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] creating a tab delimited filename

2005-03-13 Thread jrlen balane
what does a tab delimited filename mean? how am i going to make this?
also how does it  differs from space delimited, csv, and others?

can't really find an article that could put me in the right direction
so i posted here. thanks in advance.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help

2005-03-13 Thread R. Alan Monroe

> ok i have learned that on the python shell or new window you can type 
in..print "hello world"...and the output is ..'hello world'.. or you 
can 
> put in anything realy and it say it back to you.is this a program or what

Yep, that's a program. Just an ultra, ultra-simple one.


> program and what i need to know to write them and if this is a program teach 
> me
> how to write better programs

Have you learnt the "if" statement yet? If not, that's the next thing
you want to learn. Tell us if you get stuck.


Alan

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


Re: [Tutor] help

2005-03-13 Thread Alan Gauld
> ok i have learned that on the python shell or new window you can
type
> in..>>>print "hello world"...and the output is ..'hello world'..
or you can
> put in anything realy and it say it back to you.is this a
program or what

Yes it is a program. And believe it or not the PC processor is
actually performing
literally hundreds of micro steps to do that one print statement.

> and what is the purpose of this can you realy use this for any thing
other then
> it just saying it back.

Yes, once you learn how to store data you can use print to print it
back out again.
A program that can't display any results is not much use!

> program and what i need to know to write them and if this is a
program teach me
> how to write better programs i can use outside of the python
shell...

Try one of the non programmers tutorials on the Python web site.

Mine is one example, try it, if you don't like the style try another
there are several to choose from. If you find a bit you don't
understand,
first try it again to see if you can figure it out (best way to
learn!)
then if still stuck send a queston to this list.
Include any error messages you get in the posting!

> have been reading and reading web pages and they talk about languges
and things
> but i have yet to see any languges or anything to teach me the
> langugesplease help meTHANK YOU ALL VERY MUCH !

Hopefully my tutorial and the other  non-programmers ones will do just
that.

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

2005-03-13 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
*
   ok i have learned that on the python shell or new window you can type 
in..>>>print "hello world"...and the output is ..'hello world'.. or 
you can put in anything realy and it say it back to you.is this a 
program or what and what is the purpose of this can you realy use this 
for any thing other then it just saying it back. 
print "hello world"
is a very simple program. It is traditionally used as the first program in any programming language. 
When you are able to run this program, you have learned a little bit about how to write a program in 
that language. For Python, you have learned how to install Python, how to start IDLE and how to run 
commands in the Python shell.

The print command in general can be very useful in a larger program. It is a simple way to give 
feedback to the user of the program.

if this is not a
program please teach me what is a program and what i need to know to 
write them and if this is a program teach me how to write better 
programs i can use outside of the python shell...
This mailing list is not a programming class, it is a place to get help when you have a specific 
problem. You have to do most of the work yourself. If you are looking for someone to take your hand 
and teach you all about programming you should find a class.

Imagine you are taking a math class. You will have a teacher, a textbook and homework. When you have 
problems with the homework you ask a tutor for help.

and i have been reading
and reading web pages and they talk about languges and things but i have 
yet to see any languges or anything to teach me the langugesplease 
help meTHANK YOU ALL VERY MUCH !*
Try the introductions for non-programmers linked on this page:
http://www.python.org/doc/Intros.html
When you have specific questions or problems ask questions here.
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] help

2005-03-13 Thread Jeff420harris00

    ok i have learned that on the python shell or new window you can type in..>>>print "hello world"...and the output is ..'hello world'.. or you can put in anything realy and it say it back to you.is this a program or what and what is the purpose of this can you realy use this for any thing other then it just saying it back. if this is not a program please teach me what is a program and what i need to know to write them and if this is a program teach me how to write better programs i can use outside of the python shell...and i have been reading and reading web pages and they talk about languges and things but i have yet to see any languges or anything to teach me the langugesplease help meTHANK YOU ALL VERY MUCH !
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor