Re: [Tutor] Complete programming newbie requires tutorial. (Chris Andrew)

2006-01-16 Thread Liam Clarke
I also highly recommand Alan Gauld's tutorial -
http://www.freenetpages.co.uk/hp/alan.gauld/


On 1/16/06, Ron Sheely <[EMAIL PROTECTED]> wrote:
> Two things.
>
> First, I've been watching this list for several weeks now. I wanted to
> respond to Chris Andrew's question regarding Python tutorials (Complete
> programming newbie requires tutorial. (Message-ID:
> <[EMAIL PROTECTED]>Chris Andrew). Did I reply
> correctly?
>
> Second, I've found four Python tutorials helpful to new programmers. I
> list them in suggested order. BTW, I believe Danny's tutorial is where I
> heard about this list.
>
> 1) One Day of IDLE Toying, by Danny Yoo
> (http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/)
>
> 2) Python Org's IDLE Tutorial (http://www.python.org/idle/doc/idlemain.html)
>
> 3) A Byte of Python by Swaroop C H
> (http://www.ibiblio.org/g2swap/byteofpython/read/)
>
> 4) Mark Pilgrim's Python tutorial for experienced programmers
> (http://www.diveintopython.org/)
>
>
>
> ___
> 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] setuptools question

2006-01-16 Thread Liam Clarke
How were you calling easy_install?

On 1/16/06, Shuying <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm not sure where's the best place to ask so I thought I'd try it
> here.  I've got python2.3 and python2.4 installed on my machine and
> I'm trying to upgrade setuptools for both versions of python. So I've
> got no problems upgrading setuptools for python2.3 but when I try to
> do the same for python2.4, I get :
> Traceback (most recent call last):
>   File "easy_install", line 7, in ?
> sys.exit(
>   File 
> "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> line 236, in load_entry_point
> return get_distribution(dist).load_entry_point(group, name)
>   File 
> "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> line 229, in get_distribution
> if isinstance(dist,Requirement): dist = get_provider(dist)
>   File 
> "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> line 115, in get_provider
> return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
>   File 
> "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> line 382, in find
> raise VersionConflict(dist,req) # XXX add more info
> pkg_resources.VersionConflict: (setuptools 0.6a5
> (/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg),
> Requirement.parse('setuptools==0.6a9'))
>
> and I'm not sure what's the best way to fix it. Suggestions please!
>
> Thanks,
> Shuying
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] timeout

2006-01-16 Thread frank h.
Hello
how can I break a loop after a certain amount of time has passed?

pseudocode:

with timeout of 60sec:
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeout

2006-01-16 Thread frank h.
Hello
how can I break a loop after a certain amount of time has passed?

pseudocode:

with timeout of 60sec:
while True:
pass

is there a simple way? without resorting to queues etc. (this is a bit
over my head)
thanks for any insight you might have
-frank


On 1/16/06, frank h. <[EMAIL PROTECTED]> wrote:
> Hello
> how can I break a loop after a certain amount of time has passed?
>
> pseudocode:
>
> with timeout of 60sec:
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeout

2006-01-16 Thread Rinzwind
Hello,With the time module and sleep(60)?http://www.python.org/doc/2.3.5/lib/module-datetime.html
sleep(
  secs)
Suspend execution for the given number of seconds.  The argument may
be a floating point number to indicate a more precise sleep time.
The actual suspension time may be less than that requested because any
caught signal will terminate the sleep() following
execution of that signal's catching routine.  Also, the suspension
time may be longer than requested by an arbitrary amount because of
the scheduling of other activity in the system.WimOn 1/16/06, frank h. <[EMAIL PROTECTED]
> wrote:Hellohow can I break a loop after a certain amount of time has passed?
pseudocode:with timeout of 60sec:while True:passis there a simple way? without resorting to queues etc. (this is a bitover my head)thanks for any insight you might have
-frankOn 1/16/06, frank h. <[EMAIL PROTECTED]> wrote:> Hello> how can I break a loop after a certain amount of time has passed?
>> pseudocode:>> with timeout of 60sec:>___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] timeout

2006-01-16 Thread Kent Johnson
If you just want a delay, as your empty loop pseudocode seems to do, use 
time.sleep() as Wim suggested.

If you are processing in a loop and you want to stop processing after a 
certain amount of time, you could check time.time() each time through 
the loop and end when the allotted time has elapsed.

If you want to abort the loop from outside the loop, it's a harder 
problem...

Kent

frank h. wrote:
> Hello
> how can I break a loop after a certain amount of time has passed?
> 
> pseudocode:
> 
> with timeout of 60sec:
> while True:
> pass
> 
> is there a simple way? without resorting to queues etc. (this is a bit
> over my head)
> thanks for any insight you might have
> -frank
> 
> 
> On 1/16/06, frank h. <[EMAIL PROTECTED]> wrote:
> 
>>Hello
>>how can I break a loop after a certain amount of time has passed?
>>
>>pseudocode:
>>
>>with timeout of 60sec:
>>
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


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


[Tutor] tutorials

2006-01-16 Thread catherine curley
Hi
 
Has anyone got an easy way of printing the Python documentation in PDF format.  Its all in HTML and is time consuming to print.
 
Catherine
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PIL, fonts and making images

2006-01-16 Thread Rinzwind
I've been using python wih PIL to create some buttons (automatically inside my program). The following code works and creates a PNG 70x70 with the letter 'p' inside.#!/usr/bin/pythonimport os, sysimport Image, ImageFont, ImageDraw
image = Image.new('RGBA',(70,70),(0,0,0))ifo = ImageFont.truetype("arial.ttf",24)#ifo = ImageFont.truetype("MARRFONT.TTF",24)draw = ImageDraw.Draw(image)draw.text((0, 0), 'p', font=ifo)
image.save('image.png','PNG')I save this program inside a temp dir and copied arial.ttf inside this directory. It works :-)Want I want though is to do this with MARRFONT.TTF. That is a (free) font that has chesspieces inside. (can be downloaded here:
http://antraxja-fonts.iweb.pl/pobierz.php?font=3903 )The font works: inside the download there's a DOC that I can open with OO.org and that let's me show the chesspieces (after I copied the font to my fontsdir). If I type a 'p' in arial and then change the font it shows a Pawn. Cool isn't it? :)
But when I un-comment the line with this font and save it I get a black square. Can anyone tell me why it doesn't work?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tutorials

2006-01-16 Thread Brian van den Broek
catherine curley said unto the world upon 16/01/06 08:26 AM:
> Hi
> 
> Has anyone got an easy way of printing the Python documentation in PDF
> format.  Its all in HTML and is time consuming to print.
> 
> Catherine

pdf format is available here: .

Best,

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


Re: [Tutor] timeout

2006-01-16 Thread Hugo González Monteverde
Hi Frank,

 > how can I break a loop after a certain amount of time has passed?
 >


If the loop actually does something, I've used time.time() in the past:

start_time = time.time()
timeout = 60 #seconds


while True:
 do_something()
 if time.time() - start_time >= timeout:
 break

time.time() just keeps increasing as it reports the system's clock (in 
UNIX epoch time, just increasing seconds)

Hope that helps,

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


Re: [Tutor] tutorials

2006-01-16 Thread Alan Gauld
> Has anyone got an easy way of printing the Python documentation in PDF
> format.  Its all in HTML and is time consuming to print.

You can buy it in paper book form. 
It's a lot cheaper than trying to print the online stuff page by page!

Of course someone else may be paying for the paper in which case 
you may not care about printing costs... But you do realise just how 
much there is to print - many hundreds of pages, probably well over 
a thousand! Thats a lot of big ring binders.

Alan G

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


Re: [Tutor] timeout

2006-01-16 Thread Alan Gauld
> how can I break a loop after a certain amount of time has passed?

> with timeout of 60sec:

I assume you want the loop to do somerthing until the timeout?
If so then the logic is:

timeout = now() + 60
while now() < timeout:
do something.

Using the time module you can easily calculate timeout and now.

It gets trickier with small values - if you wanted 60ms say, but at 
the seconds level it works ok.

HTH,

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


[Tutor] Python debugger bummer

2006-01-16 Thread Victor Bouffier
Hi to all,

I tried to look for a reference to this issue in the ASPN archive, but I
can't seem to find an answer.

I currently work under Linux and have never been able to properly use
the Python debugger. Coming from a Perl background, I fail to find a
similar simple way to step through my code the way I am able to do it
through the -d flag using Perl on the command line. It is so painless.

I have used Python on Windows, usually writing my programs using Vim,
and entering the PythonWin environment to debug my programs. It is a
good environment to do that, although I prefer my independent editor for
writing my programs.

I once paid for ActiveState's Komodo for Linux to use as an IDE, but I find it
bloated and slow, not to mention the need to constantly upgrade if you
want to keep up with versions (have not done it yet).

Does anyone have any suggestions as to an alternative to PythonWin, or
even better still, a reference to a good tutorial on how to use my
current tools: how to use the python debugger as the way Perl debugger
works? I am certain the Python interpreter (being better that Perl in
that sense) must have a way to use the debugger.

I work under Linux using vi/gvim and ipython (I have never really tried
IDLE).

Thanks in advance for any help.
Victor


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


Re: [Tutor] Python debugger bummer

2006-01-16 Thread Victor Bouffier
Hi again,

I was going through the Python library documentation and I found
something I never saw before.

$ python -m pdb myscript.py

This is what I was looking for! Great help.

Any further reference could of course help a lot. I never was able to
get the hang of it until now.

Victor


On Mon, 2006-01-16 at 13:12 -0600, Victor Bouffier wrote:
> Hi to all,
> 
> I tried to look for a reference to this issue in the ASPN archive, but I
> can't seem to find an answer.
> 
> I currently work under Linux and have never been able to properly use
> the Python debugger. Coming from a Perl background, I fail to find a
> similar simple way to step through my code the way I am able to do it
> through the -d flag using Perl on the command line. It is so painless.
> 
> I have used Python on Windows, usually writing my programs using Vim,
> and entering the PythonWin environment to debug my programs. It is a
> good environment to do that, although I prefer my independent editor for
> writing my programs.
> 
> I once paid for ActiveState's Komodo for Linux to use as an IDE, but I find it
> bloated and slow, not to mention the need to constantly upgrade if you
> want to keep up with versions (have not done it yet).
> 
> Does anyone have any suggestions as to an alternative to PythonWin, or
> even better still, a reference to a good tutorial on how to use my
> current tools: how to use the python debugger as the way Perl debugger
> works? I am certain the Python interpreter (being better that Perl in
> that sense) must have a way to use the debugger.
> 
> I work under Linux using vi/gvim and ipython (I have never really tried
> IDLE).
> 
> Thanks in advance for any help.
> Victor
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] __getitem__

2006-01-16 Thread Christopher Spears
I understand that you can use __getitem__ as a hook to
modify indexing behavoir in a class.  That's why
__getitem__ not only affects [] but also for loops,
map calls, list comprehension, etc.  For loops, etc.
work by indexing a  sequences from zero to a higher
index until out-of-bounds is reached.  But why does
this work?

>>> class stepper:
... def __getitem__(self, i):
... return self.data[i]
...
>>> 'p' in X
True

What does 'in' have to do with indexing?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__

2006-01-16 Thread bob
At 12:12 PM 1/16/2006, Christopher Spears wrote:
>I understand that you can use __getitem__ as a hook to
>modify indexing behavoir in a class.  That's why
>__getitem__ not only affects [] but also for loops,
>map calls, list comprehension, etc.  For loops, etc.
>work by indexing a  sequences from zero to a higher
>index until out-of-bounds is reached.  But why does
>this work?
>
> >>> class stepper:
>... def __getitem__(self, i):
>... return self.data[i]
>...
> >>> 'p' in X
>True
>
>What does 'in' have to do with indexing?

What does X have to do with stepper? 

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


Re: [Tutor] __getitem__

2006-01-16 Thread Christopher Spears
Sorry!

X = stepper()
X.data = "Spam"

--- bob <[EMAIL PROTECTED]> wrote:

> At 12:12 PM 1/16/2006, Christopher Spears wrote:
> >I understand that you can use __getitem__ as a hook
> to
> >modify indexing behavoir in a class.  That's why
> >__getitem__ not only affects [] but also for loops,
> >map calls, list comprehension, etc.  For loops,
> etc.
> >work by indexing a  sequences from zero to a higher
> >index until out-of-bounds is reached.  But why does
> >this work?
> >
> > >>> class stepper:
> >... def __getitem__(self, i):
> >... return self.data[i]
> >...
> > >>> 'p' in X
> >True
> >
> >What does 'in' have to do with indexing?
> 
> What does X have to do with stepper? 
> 
> 


"I'm the last person to pretend that I'm a radio.  I'd rather go out and be a 
color television set."
-David Bowie

"Who dares wins"
-British military motto

"I generally know what I'm doing."
-Buster Keaton
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] __iter__

2006-01-16 Thread Christopher Spears
I'm not sure if I understand __iter__.  You use it to
create an object that iterates through itself using a
next menthod ?

class Squares:
def __init__(self, start, stop):
self.value = start - 1
self.stop = stop
def __iter__(self):
return self
def next(self):
if self.value == self.stop:
raise StopIteration
self.value += 1
return self.value ** 2

>>> from iters import Squares
>>> for i in Squares(1, 5):
... print i,
...
1 4 9 16 25


"I'm the last person to pretend that I'm a radio.  I'd rather go out and be a 
color television set."
-David Bowie

"Who dares wins"
-British military motto

"I generally know what I'm doing."
-Buster Keaton
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setuptools question

2006-01-16 Thread Shuying
I think I tried python2.4 /usr/bin/easy_install -U setuptools and
directly the #! line in easy_install to use python2.4.

On 1/16/06, Liam Clarke <[EMAIL PROTECTED]> wrote:
> How were you calling easy_install?
>
> On 1/16/06, Shuying <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I'm not sure where's the best place to ask so I thought I'd try it
> > here.  I've got python2.3 and python2.4 installed on my machine and
> > I'm trying to upgrade setuptools for both versions of python. So I've
> > got no problems upgrading setuptools for python2.3 but when I try to
> > do the same for python2.4, I get :
> > Traceback (most recent call last):
> >   File "easy_install", line 7, in ?
> > sys.exit(
> >   File 
> > "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> > line 236, in load_entry_point
> > return get_distribution(dist).load_entry_point(group, name)
> >   File 
> > "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> > line 229, in get_distribution
> > if isinstance(dist,Requirement): dist = get_provider(dist)
> >   File 
> > "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> > line 115, in get_provider
> > return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
> >   File 
> > "/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py",
> > line 382, in find
> > raise VersionConflict(dist,req) # XXX add more info
> > pkg_resources.VersionConflict: (setuptools 0.6a5
> > (/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg),
> > Requirement.parse('setuptools==0.6a9'))
> >
> > and I'm not sure what's the best way to fix it. Suggestions please!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __getitem__

2006-01-16 Thread Kent Johnson
Christopher Spears wrote:
> I understand that you can use __getitem__ as a hook to
> modify indexing behavoir in a class.  That's why
> __getitem__ not only affects [] but also for loops,
> map calls, list comprehension, etc.  For loops, etc.
> work by indexing a  sequences from zero to a higher
> index until out-of-bounds is reached.  But why does
> this work?
> 
> 
class stepper:
> 
> ... def __getitem__(self, i):
> ... return self.data[i]
> ...
> 
'p' in X
> 
> True
> 
> What does 'in' have to do with indexing?

How do you suppose 'in' works? To see if something is in a list, for 
example, you have to iterate over each element of the list and check if 
it is the item you expect.

Under the hood, Python will use the __contains__() or __getitem__() 
special method of a class to evaluate 'x in y'.

Loosely speaking, if y is an instance of a class that implements 
__getitem__() but not __contains__(), 'x in y' is more or less the same 
as this:

def in(x, y):
   for i in y:
 if i == x:
   return True
   return False

 From the language reference:
"For user-defined classes which do not define __contains__() and do 
define __getitem__(), x in y is true if and only if there is a 
non-negative integer index i such that x == y[i], and all lower integer 
indices do not raise IndexError exception. (If any other exception is 
raised, it is as if in raised that exception)."

http://docs.python.org/ref/comparisons.html#l2h-432

Kent

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


Re: [Tutor] __iter__

2006-01-16 Thread Kent Johnson
Christopher Spears wrote:
> I'm not sure if I understand __iter__.  You use it to
> create an object that iterates through itself using a
> next menthod ?

Yes, you seem to have it right. Your code is fine IMO.

In many cases it's easier to use a generator than an iterator class. If 
you are using this in real code (as opposed to just trying to understand 
__iter__) you should learn about them. Here is your example with a 
generator:

  >>> def squares(start, stop):
  ...   for i in range(start, stop+1):
  ... yield i*i
  ...
  >>> for i in squares(1, 5):
  ...   print i,
  ...
1 4 9 16 25

Learn about generators here:
http://www.python.org/doc/2.3.5/whatsnew/section-generators.html

Kent

> 
> class Squares:
> def __init__(self, start, stop):
> self.value = start - 1
> self.stop = stop
> def __iter__(self):
> return self
> def next(self):
> if self.value == self.stop:
> raise StopIteration
> self.value += 1
> return self.value ** 2
> 
> 
from iters import Squares
for i in Squares(1, 5):
> 
> ... print i,
> ...
> 1 4 9 16 25
> 
> 
> "I'm the last person to pretend that I'm a radio.  I'd rather go out and be a 
> color television set."
> -David Bowie
> 
> "Who dares wins"
> -British military motto
> 
> "I generally know what I'm doing."
> -Buster Keaton
> ___
> 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] Python debugger bummer

2006-01-16 Thread Alan Gauld
> I was going through the Python library documentation and I found
> something I never saw before.
> 
> $ python -m pdb myscript.py

I was just about to suggest loading pdb...

And of course there is also a graphical debugger in IDLE as 
well as PythonWin.

The paper version of my book contains a chapter 
(not on the web site) on how to use pdb to debug a script.
pdb has its limitations but if you are used to gdb then its 
not too bad.

(pdb) help

is your friend.

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

2006-01-16 Thread Alan Gauld
> map calls, list comprehension, etc.  For loops, etc.
> work by indexing a  sequences from zero to a higher
> index until out-of-bounds is reached.  

What makes you think that?
So far as I know for loops work by calling next on 
an iterator until nothing gets returned, no indexes 
involved.(At least not in the for loop) But they could 
just as well work by calling the len() function and 
iterating that number of times. And len() could be 
stored as part of the data structure ala Pascal arrays.

The point being that it is dangerous to assume how 
a language feature works internally, it can change from 
version to version.

In this case the iterator solution means that the for 
loop can work on any iterable entity - like files for 
instance.

> But why does this work?
> 
 class stepper:
> ... def __getitem__(self, i):
> ... return self.data[i]
> ...
 'p' in X
> True
> 
> What does 'in' have to do with indexing?

Nothing unless its implementation uses a while loop
and index, but thats unlikely.

But your code doesn't show what X is, I assume its 
an instance of stepper? (The convention is for uppercase 
class names and lower case object names so I'm slightly 
unsure about that assumption!) But we don't even have 
the whole of stepper since there is no self.data definition.
Its kind of hard to say.

I'm slightly confused by the question, sorry.

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

2006-01-16 Thread Alan Gauld

> Sorry!
> 
> X = stepper()
> X.data = "Spam"

Aha! The fog in my brain clears.

>> > >>> class stepper:
>> >... def __getitem__(self, i):
>> >... return self.data[i]
>> >...
>> > >>> 'p' in X
>> >True
>> >
>> >What does 'in' have to do with indexing?

To find out if 'p' is in X Python has to step through the data in X.
I'm not sure that your getitem is being called, it may just be a string 
search operation. But I suspect it may assume the data is an iterator
and repeatedly call next() till it gets a match or runs out of data. 
In that case getitem may well get called. a simple print statement 
in getitem will find out...

Alan G.

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


Re: [Tutor] Design suggestion - is a cookie the answer?

2006-01-16 Thread Python
On Mon, 2006-01-16 at 01:12 +, Alan Gauld wrote:
> > I'm sure this is implied in Alan's post, but I'm going to point it
> out
> ...
> > To avoid further cheating you might want to sure there is no way to
> > submit the form without javascript turned on. E.g. Don't have a
> submit
> > button and a form with an 'onSubmit' validation. Which some examples
> > do use. Otherwise, they can just turn off Javascript support in
> their
> > browser and bypass your validation.
> 

Javascript might be the appropriate level of paranoia for your
situation, however, remember that people do not have to use your form to
submit data to your web script.  An enterprising student could save the
form and edit it him(her)self to bypass any javascript checks or even
synthesize their own submit data (e.g. use urllib to supply answers).  

There is no check to make sure that the answers fed back to the script
fit the problems that were written out in the form.  Of course any kid
who could figure out how to maximize points cheating your script can
probably handle simple multiplication.

I liked the variable name insertpupilsnick.  If Dr Seuss had written a
book on programming, I'm sure it would have had variable names like
that.

-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] Design suggestion - is a cookie the answer?

2006-01-16 Thread John Fouhy
On 16/01/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
> No. JavaScript is an event driven paradigm and it only
> picks up the explicit events you register with it(*). One of
> the problems of using CGI is the ese of frigging it. I assume
> you are using GET instead of POST? GET is the default
> submission method but POST is nearly always better and
> should avoid the problem here. (I think, I haven't tried it!)

I believe the python CGI module is submission-method agnostic --- your
code doesn't need to know or care whether the data was submitted using
POST or GET.  So, even if you are using POST, clever kids could, I
think, construct a GET url to do the same thing.

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


Re: [Tutor] Design suggestion - is a cookie the answer?

2006-01-16 Thread Danny Yoo
> On 16/01/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
> > No. JavaScript is an event driven paradigm and it only picks up the
> > explicit events you register with it(*). One of the problems of using
> > CGI is the ese of frigging it. I assume you are using GET instead of
> > POST? GET is the default submission method but POST is nearly always
> > better and should avoid the problem here. (I think, I haven't tried
> > it!)
>
> I believe the python CGI module is submission-method agnostic --- your
> code doesn't need to know or care whether the data was submitted using
> POST or GET.  So, even if you are using POST, clever kids could, I
> think, construct a GET url to do the same thing.

Sorry I missed most of this thread!  I wanted to interject that there are
some experimental web frameworks that might allow us to get around the
issues with browser reload.  Most of these fall under "continuation-based"
web frameworks.  For example, CherryFlow:

http://subway.python-hosting.com/wiki/CherryFlow

There are links on that page that talk about this in more detail.
However, I have to admit that the only continuation web frameworks I've
been playing with have been in PLT Scheme, so I'm not so sure how mature
the Python implementations are.

Best of wishes!

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


Re: [Tutor] PIL, fonts and making images

2006-01-16 Thread Danny Yoo
> Want I want though is to do this with MARRFONT.TTF. That is a (free) font
> that has chesspieces inside. (can be downloaded here:
> http://antraxja-fonts.iweb.pl/pobierz.php?font=3903 )

Hi Rinzwind,

You might want to contact the folks who make that font: according to the
Fontbook on my Mac OS X box, that particular font has serious problems.
My system says that it's defective because it's missing a "Font Name
Table", whatever that is.

Best of wishes to you!

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


Re: [Tutor] __iter__

2006-01-16 Thread Danny Yoo


On Mon, 16 Jan 2006, Christopher Spears wrote:

> I'm not sure if I understand __iter__.  You use it to create an object
> that iterates through itself using a next menthod ?

Hi Chris,

Yes, that's one application.


But __iter__() doesn't necessarily have to return 'self'.  For example,
here's a useless toy class that might help explain what can happen if we
do so without thinking:


class MyListOfNumbers:
def __init__(self, data):
self.data = data
def __iter__(self):
return Pointer(self)


class Pointer:
def __init__(self, numbers):
self.numbers = numbers
self.offset = 0
def next(self):
if self.offset == len(self.numbers.data):
raise StopIteration
element = self.numbers.data[self.offset]
self.offset = self.offset + 1
return element


Let's see how this might work:

###
>>> nums = MyListOfNumbers([0, 1])
>>> for x in nums:
... for y in nums:
... print x, y
...
0 0
0 1
1 0
1 1
###



Now imagine what might happen if we didn't return a separate Pointer
iterator:


class MyListOfNumbers2:
def __init__(self, data):
self.data = data
self.offset = 0

def __iter__(self):
return self

def next(self):
if self.offset == len(self.data):
raise StopIteration
element = self.data[self.offset]
self.offset = self.offset + 1
return element


On a glance, this also looks reasonable:

##
>>> nums = MyListOfNumbers2([3, 1, 4, 1, 5])
>>> for n in nums:
... print n
...
3
1
4
1
5
##


But, of course, you know that there has to be SOMETHING wrong here.
*grin*

And here's one example that shows a problem:

##
>>> nums = MyListOfNumbers2([0, 1])
>>> for x in nums:
... for y in nums:
... print x, y
...
0 1
>>>
##

We expected to see all pairs of 0-1 combinations, but came up way short.
Do you know why?


Best of wishes!

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


Re: [Tutor] Python debugger bummer

2006-01-16 Thread Victor Bouffier
Thanks Alan.
As always, you are very helpful.

Victor

On Mon, 2006-01-16 at 23:35 +, Alan Gauld wrote:
> > I was going through the Python library documentation and I found
> > something I never saw before.
> > 
> > $ python -m pdb myscript.py
> 
> I was just about to suggest loading pdb...
> 
> And of course there is also a graphical debugger in IDLE as 
> well as PythonWin.
> 
> The paper version of my book contains a chapter 
> (not on the web site) on how to use pdb to debug a script.
> pdb has its limitations but if you are used to gdb then its 
> not too bad.
> 
> (pdb) help
> 
> is your friend.
> 
> 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


[Tutor] help

2006-01-16 Thread james middendorff
I am trying to do some AGI scripting with python and
asterisk, I read the book, Asterisk the Future of
Telephony, which has an example of AGI + python. I
have found that none of the example seems to work. My
question is I have figured out how to play a recorded
message sys.stdout.write('EXEC PLAYBACK name "*#"')
then you do sys.stdout.flush() and you will get your
message played. In the book it shows if you want to
capture something the user inputs you do result =
sys.stdin.readline().strip() but when I add that to my
line I cannot get my message to be played? Am I
totally off on this. All I want it to make a message
play, then capture their input, and put it to use in
the rest of my python script?
Thanks for any help. I hope someone else is playing
with asterisk and python
James

"I would kill everyone in this room
for a drop of sweet beer."
 Homer Simpson

__
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