Gregor Lingl | 1 Aug 2002 06:40
Picon

Re: Use? Abuse? Amusement? Amendments?


Chris Kassopulo schrieb:

>Running Python 2.0.1
>
>$ python /home/ckasso/python/turtles.py
>  File "/home/ckasso/python/turtles.py", line 7
>    yield 1
>          ^
>SyntaxError: invalid syntax
>
>  
>
Of course, I forgot to mention: trees.py needs Python 2.2 or higher

This is because it's intention was (among others) to have some visual
representation of how generators work - an those were introduced
in Python only with V2.2

Gregor

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Aris Santillan | 1 Aug 2002 07:38
Picon
Favicon

SCP / SFTP

Hello guys!

im a newbie

does anyone had a script for wrapping a SCP / SFTP command
in python, coz i want to embed it on a DTML?

Aris Santillan

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Dan Shafer | 1 Aug 2002 07:49

Re: Tkinter Editor

Check out PythonCard (http://www.pythoncard.org), a GUI-creation tool being 
patterned after the mold of HyperCard and Visual Basic and built on top of 
wxWindows. While the current release (0.6.8.1) is not commercial software 
and you need to understand Python coding a bit to get the most out of it, 
it's quite usable as it is. It comes with a ton of great samples (caveat..I 
wrote some of them!) and good (though incomplete) docs (another caveat...I 
wrote most of them).

It has its own mailing list, too.

Dan Shafer, Chief Scribe and Tablet Keeper
PythonCard Open Source Project
http://pythoncard.sourceforge.net

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Scot W. Stevenson | 1 Aug 2002 11:15
Picon

Skipping elements from inside generator loops

Hello there, 

So here I am playing around with generators, and just for the heck of it I 
see if I can get a for-loop to skip one element from inside the loop. To 
my surprise, this works (in Python 2.2):

==================================================
from __future__ import generators

procession= ['black cat',
             'white cat',
             'grey cat',
             'ALARM!',
             'the evil dog',
             'fat cat',
             'slow cat']

def animal_walk(animal_list):
    for one_animal in animal_list:
        yield one_animal

cat_parade = animal_walk(procession)

for animal in cat_parade:
    if animal == 'ALARM!':
        # Skip one animal on list
        cat_parade.next()
    else:
        print animal
=============================================
(Continue reading)

ibraheem umaru-mohammed | 1 Aug 2002 12:06
Picon

Re: Skipping elements from inside generator loops

[Scot W. Stevenson wrote...]
<snip>...</snip>
-| 
-| Somehow, it doesn't seem right to be able to change what amounts to a loop 
-| counter from the inside, even though it is useful here. Fooling around 
-| some more, I find that you can not do this with "normal" for loops:
-| 
-| ===============================
-| for a in range(len(procession)):
-|     if procession[a] == 'ALARM!':
-|         a = a+1
-|     else:
-|         print procession[a]
-| ===============================
-| 

Hmmnn...This works for me:

	ibraheem <at> ignoramus:$ python2.2
	Python 2.2.1 (#1, Apr 25 2002, 14:21:58)
	[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
	Type "help", "copyright", "credits" or "license" for more information.
	rlcompleter2 0.9.6 activated
	>>> procession=['black cat',
	>>> ... 'white cat',
	>>> ... 'grey cat',
	>>> ... 'ALARM!',
	>>> ... 'evil dog',
	>>> ... 'fat cat',
	>>> ... 'slow cat']
(Continue reading)

Doug.Shawhan | 1 Aug 2002 16:40
Picon

Meeester bell.

I have been looking through the modules for a text-mode bell that will work
in windows (i.e. not in curses or Tkinter).

I am postitive I have seen this beastie somewhere... Any clues?

d

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Jerry Brady | 1 Aug 2002 18:40
Picon
Favicon

on mailing list

Hi:

Is there anyone thats from Kentucky on your mailing list.. Like to find someone closes to me in

kentucky

Thanks

Jerry

>From: tutor-request <at> python.org
>Reply-To: tutor <at> python.org
>To: tutor <at> python.org
>Subject: Tutor digest, Vol 1 #1807 - 10 msgs
>Date: Thu, 01 Aug 2002 12:00:05 -0400
>
>Send Tutor mailing list submissions to
> tutor <at> 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
> tutor-request <at> python.org
>
>You can reach the person managing the list at
> tutor-admin <at> python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
> 1. Re: listdir, ispath and unicode (followup question) (Danny Yoo)
> 2. Re: Use? Abuse? Amusement? Amendments? (Kalle Svensson)
> 3. Problem - how to solve it ? (A)
> 4. Re: Problem - how to solve it ? (Matthew Sherborne)
> 5. Re: Use? Abuse? Amusement? Amendments? (Gregor Lingl)
> 6. SCP / SFTP (Aris Santillan)
> 7. Re: Tkinter Editor (Dan Shafer)
> 8. Skipping elements from inside generator loops (Scot W. Stevenson)
> 9. Re: Skipping elements from inside generator loops (ibraheem umaru-mohammed)
> 10. Meeester bell. (Doug.Shawhan <at> gecits.ge.com)
>
>--__--__--
>
>Message: 1
>Date: Wed, 31 Jul 2002 15:04:44 -0700 (PDT)
>From: Danny Yoo
>To: Poor Yorick
>cc: tutor <at> python.org
>Subject: Re: [Tutor] listdir, ispath and unicode (followup question)
>
>
>
>On Wed, 31 Jul 2002, Poor Yorick wrote:
>
> > I am running Windows 2000 English edition. The filename contains
> > cyrillic characters typed with a standard Windows 2000 IME when I
> > created the file. Here is the result of your suggestion:
> >
> > filename = os.path.join(os.getcwd(), os.listdir(os.getcwd())[0])
> >
> > >>> filename
> > 'd:\\tmp2\\???????'
> > >>> os.stat(filename)
> > Traceback (most recent call last):
> > File "", line 1, in ?
> > os.stat(filename)
> > OSError: [Errno 2] No such file or directory: 'd:\\tmp2\\???????'
>
>
>Hmmm... now I'm suspecting that the cyrillic characters might be making a
>difference. I did a scan through the Python Enhancement Proposal 277:
>
> http://www.python.org/peps/pep-0277.html
>
>which implies that Unicode filenames might not work out-of-the-box. If
>your locale at that point where you're running the Python script isn't
>Cyrillic, that can potentially cause problems.
>
>
>The PEP above provides an implementation that's supposed to handle Unicode
>filenames properly, without the intermediate LOCALE translation stuff; can
>you see if this works for you? Sorry about the roundabout way of
>answering your question.
>
>
>
>--__--__--
>
>Message: 2
>Date: Thu, 1 Aug 2002 00:26:41 +0200
>From: Kalle Svensson
>To: tutor <at> python.org
>Subject: Re: [Tutor] Use? Abuse? Amusement? Amendments?
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>[Sean 'Shaleh' Perry]
> > where does one get turtle?
>
>It seems to be a part of the standard library.
>http://www.python.org/doc/current/lib/module-turtle.html
>
>Peace,
> Kalle
>- --
>Kalle Svensson, http://www.juckapan.org/~kalle/
>Student, root and saint in the Church of Emacs.
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.7 (GNU/Linux)
>Comment: Processed by Mailcrypt 3.5.6
>
>iD8DBQE9SGQadNeA1787sd0RAngkAKCdbxhdNJd6J4zawWLAYVhbh9vWDwCgtIA4
>acTGCIaZTaeik061IPDr6BM=
>=GtY4
>-----END PGP SIGNATURE-----
>
>
>--__--__--
>
>Message: 3
>From: "A"
>To: python-list <at> python.org, tutor <at> python.org,
> activepython <at> listserv.activestate.com, python-help <at> python.org
>Reply-to: printers <at> sendme.cz
>Date: Wed, 31 Jul 2002 20:54:41 +0200
>Subject: [Tutor] Problem - how to solve it ?
>
>Hi,
>I have a program that I compiled( with Installer) into exe for using
>on Win32 systems. It works well on Windows Me, Windows 9x but
>on some computers with Windows 2000 it causes General
>Protection Error and the programs is finished. It would be nice if the
>program wrote a line number or something similar that could help a
>user find out which command caused that General Protection
>Error. Is there any solution for that?
>Thank you for help
>Ladislav
>
>
>_______________________________________________
>ActivePython mailing list
>ActivePython <at> listserv.ActiveState.com
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
>
>
>
>--__--__--
>
>Message: 4
>Date: Thu, 01 Aug 2002 10:08:16 +1200
>From: Matthew Sherborne
>To: printers <at> sendme.cz
>Cc: python-list <at> python.org, tutor <at> python.org,
> activepython <at> listserv.activestate.com, python-help <at> python.org
>Subject: [Tutor] Re: Problem - how to solve it ?
>
>GPFs are fired when some C code crashes not python code. In the error it
>should give the name of a DLL or say python.exe.
>
>To find what part of your code is causing the error, do print messages,
>or write to a log file in the area around where the program crashes.
>
>Start in the highest level of the code, print a line before and after
>each sub routine is called, where the print outs stop, go to the sub
>routine after the last print out and put a bunch of print lines between
>all the sections in that and re-run. Keep narrowing it down like this. :)
>
>It may a bug in some windows DLL, so you could either fix it, or release
>a "Known Issues.txt" file with the program, letting them know that they
>must update their windows release if this happens. :)
>
>GBU
>Matthew Sherborne
>
>A wrote:
>
> >Hi,
> >I have a program that I compiled( with Installer) into exe for using
> >on Win32 systems. It works well on Windows Me, Windows 9x but
> >on some computers with Windows 2000 it causes General
> >Protection Error and the programs is finished. It would be nice if the
> >program wrote a line number or something similar that could help a
> >user find out which command caused that General Protection
> >Error. Is there any solution for that?
> >Thank you for help
> >Ladislav
> >
> >
> >_______________________________________________
> >ActivePython mailing list
> >ActivePython <at> listserv.ActiveState.com
> >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
> >
> >
> >
> >
> >
>
>
>
>
>
>
>--__--__--
>
>Message: 5
>Date: Thu, 01 Aug 2002 06:40:01 +0200
>From: Gregor Lingl
>To: Chris Kassopulo , tutor <at> python.org
>Subject: Re: [Tutor] Use? Abuse? Amusement? Amendments?
>
>
>Chris Kassopulo schrieb:
>
> >Running Python 2.0.1
> >
> >$ python /home/ckasso/python/turtles.py
> > File "/home/ckasso/python/turtles.py", line 7
> > yield 1
> > ^
> >SyntaxError: invalid syntax
> >
> >
> >
>Of course, I forgot to mention: trees.py needs Python 2.2 or higher
>
>This is because it's intention was (among others) to have some visual
>representation of how generators work - an those were introduced
>in Python only with V2.2
>
>Gregor
>
>
>
>
>
>--__--__--
>
>Message: 6
>From: "Aris Santillan"
>To:
>Date: Thu, 1 Aug 2002 13:38:05 +0800
>Subject: [Tutor] SCP / SFTP
>
>Hello guys!
>
>im a newbie
>
>does anyone had a script for wrapping a SCP / SFTP command
>in python, coz i want to embed it on a DTML?
>
>Aris Santillan
>
>
>--__--__--
>
>Message: 7
>Date: Wed, 31 Jul 2002 22:49:06 -0700
>From: Dan Shafer
>Subject: Re: [Tutor] Tkinter Editor
>To: tutor <at> python.org
>
>Check out PythonCard (http://www.pythoncard.org), a GUI-creation tool being
>patterned after the mold of HyperCard and Visual Basic and built on top of
>wxWindows. While the current release (0.6.8.1) is not commercial software
>and you need to understand Python coding a bit to get the most out of it,
>it's quite usable as it is. It comes with a ton of great samples (caveat..I
>wrote some of them!) and good (though incomplete) docs (another caveat...I
>wrote most of them).
>
>It has its own mailing list, too.
>
>Dan Shafer, Chief Scribe and Tablet Keeper
>PythonCard Open Source Project
>http://pythoncard.sourceforge.net
>
>
>
>--__--__--
>
>Message: 8
>From: "Scot W. Stevenson"
>Organization: Hexenhaus Zepernick
>To: Tutor
>Date: Thu, 1 Aug 2002 11:15:15 +0200
>Subject: [Tutor] Skipping elements from inside generator loops
>
>Hello there,
>
>So here I am playing around with generators, and just for the heck of it I
>see if I can get a for-loop to skip one element from inside the loop. To
>my surprise, this works (in Python 2.2):
>
>==================================================
>from __future__ import generators
>
>procession= ['black cat',
> 'white cat',
> 'grey cat',
> 'ALARM!',
> 'the evil dog',
> 'fat cat',
> 'slow cat']
>
>def animal_walk(animal_list):
> for one_animal in animal_list:
> yield one_animal
>
>cat_parade = animal_walk(procession)
>
>for animal in cat_parade:
> if animal == 'ALARM!':
> # Skip one animal on list
> cat_parade.next()
> else:
> print animal
>=============================================
>
>This produces:
>
>===================
>black cat
>white cat
>grey cat
>fat cat
>slow cat
>===================
>
>Somehow, it doesn't seem right to be able to change what amounts to a loop
>counter from the inside, even though it is useful here. Fooling around
>some more, I find that you can not do this with "normal" for loops:
>
>===============================
>for a in range(len(procession)):
> if procession[a] == 'ALARM!':
> a = a+1
> else:
> print procession[a]
>===============================
>
>lets fido into the fun (in other words, ignores the 'a=a+1'. It only works
>with a while-loop and a counter:
>
>===============================
>counter = 0
>while counter < len(procession):
> if procession[counter] == 'ALARM!':
> counter = counter+2
> else:
> print procession[counter]
> counter = counter+1
>===============================
>
>Now I'm curious: Is this ability to manipulate generator loops from the
>inside considered a bug or a feature? It certainly makes the "normal" for
>loop behave differently than the generator for loop, and that alone seems
>like a good way to shoot yourself in the foot...
>
>[While we're at it: I assume that there is a way to solve the problem with
>list comprehensions, but I can't figure it out. Note that looking for the
>dog directly is considered cheating: All you get to do is skip one list
>entry when somebody sounds the alarm.]
>
>Thanks again for the help,
>Y, Scot
>
>Who is off to feed his own cat
>
>--
> Scot W. Stevenson -- scot <at> possum.in-berlin.de -- Zepernick, Germany
>
>
>
>--__--__--
>
>Message: 9
>Date: Thu, 1 Aug 2002 11:06:33 +0100
>From: ibraheem umaru-mohammed
>To: tutor <at> python.org
>Subject: Re: [Tutor] Skipping elements from inside generator loops
>
>[Scot W. Stevenson wrote...]
>...
>-|
>-| Somehow, it doesn't seem right to be able to change what amounts to a loop
>-| counter from the inside, even though it is useful here. Fooling around
>-| some more, I find that you can not do this with "normal" for loops:
>-|
>-| ===============================
>-| for a in range(len(procession)):
>-| if procession[a] == 'ALARM!':
>-| a = a+1
>-| else:
>-| print procession[a]
>-| ===============================
>-|
>
>Hmmnn...This works for me:
>
> ibraheem <at> ignoramus:$ python2.2
> Python 2.2.1 (#1, Apr 25 2002, 14:21:58)
> [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> rlcompleter2 0.9.6 activated
> >>> procession=['black cat',
> >>> ... 'white cat',
> >>> ... 'grey cat',
> >>> ... 'ALARM!',
> >>> ... 'evil dog',
> >>> ... 'fat cat',
> >>> ... 'slow cat']
> >>> for a in range(len(procession)):
> >>> ... if procession[a] == 'ALARM!':
> >>> ... a = a + 1
> >>> ... else:
> >>> ... print procession[a]
> >>> ...
> >>> black cat
> >>> white cat
> >>> grey cat
> >>> evil dog
> >>> fat cat
> >>> slow cat
> >>>
>
>But I guess most people would use a 'continue' instead:
>
> >>>for a in range(len(procession)):
> >>>... if procession[a] == 'ALARM!':
> >>>... continue
> >>>... else:
> >>>... print procession[a]
> >>>...
> >>>black cat
> >>>white cat
> >>>grey cat
> >>>evil dog
> >>>fat cat
> >>>slow cat
> >>>
> >>>procession
> >>>['black cat', 'white cat', 'grey cat', 'ALARM!', 'evil dog', 'fat cat', 'slow cat']
> >>>
>
>...
>
>Kindest regards,
>
> --ibs.
>--
> ibraheem umaru-mohammed
> www.micromuse.com
> --0--
>
>
>--
> ibraheem umaru-mohammed
> www.micromuse.com
> --0--
>
>
>--__--__--
>
>Message: 10
>From: Doug.Shawhan <at> gecits.ge.com
>To: tutor <at> python.org
>Date: Thu, 1 Aug 2002 10:40:57 -0400
>Subject: [Tutor] Meeester bell.
>
>I have been looking through the modules for a text-mode bell that will work
>in windows (i.e. not in curses or Tkinter).
>
>I am postitive I have seen this beastie somewhere... Any clues?
>
>d
>
>
>
>--__--__--
>
>_______________________________________________
>Tutor maillist - Tutor <at> python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest

MSN Photos is the easiest way to share and print your photos: Click Here

_______________________________________________ Tutor maillist - Tutor <at> python.org http://mail.python.org/mailman/listinfo/tutor

Jeff Shannon | 1 Aug 2002 18:45

Re: Skipping elements from inside generator loops


ibraheem umaru-mohammed wrote:

> [Scot W. Stevenson wrote...]
> <snip>...</snip>
> -|
> -| Somehow, it doesn't seem right to be able to change what amounts to a loop
> -| counter from the inside, even though it is useful here. [...]
>
> Hmmnn...This works for me:  [...]
>
>         >>> ...
>         >>> black cat
>         >>> white cat
>         >>> grey cat
>         >>> evil dog
>         >>> fat cat
>         >>> slow cat
>         >>>

The point here was that the generator version (and the while-loop version) skipped the
"evil dog" entry.  Thus, sounding the "alarm" allowed the felines to frolick unmolested.

To my mind, this greater control of the iteration is a very positive feature of
generators.

By the way, the effect *can* be created with a for-loop:

procession= ['black cat',
             'white cat',
             'grey cat',
             'ALARM!',
             'the evil dog',
             'fat cat',
             'slow cat']
cat_parade = procession[:]

for n in range(len(cat_parade)):
    if cat_parade[n] == 'ALARM!':
        clear = cat_parade.pop(n+1)
    else:
        print cat_parade[n]

-------- output is -----------
black cat
white cat
grey cat
fat cat
slow cat
------------------------------

Note that I am iterating over a copy of the list -- popping an item from the list
permanently modifies it, so I'm using a copy that I can throw away just in case the
original procession list is needed later.  Also, pop() returns the item that was removed
from the list -- I'm assigning it to 'clear', an otherwise unused variable, because
otherwise the returned item is printed in the interactive shell.  It would *not* be
printed in a direct execution, though -- this is strictly a feature of the interactive
shell that it will display unassigned results, the same feature that lets you do this sort
of thing:

>>> procession
['black cat', 'white cat', 'grey cat', 'ALARM!', 'the evil dog', 'fat cat', 'slow cat']
>>>

BTW, the reason that the original for-loop solution (adding 1 to the loop counter) didn't
work has to do with the *way* that for-loops work in Python.  In C/C++ (and many other
languages), a for loop has a counter that starts at some number, and is incremented until
it reaches (or exceeds) some other number, but that's *not* what for-loops do in Python.
Instead, they take a list, and sequentially assign each element of the list to the "loop
counter" variable.  This is pretty apparent when you're iterating over a list of strings,
but it's easy to forget when you're using an integer counter.  The trick here is that
range(len(cat_parade)) actually creates a list of integers.  When you added 1 to the
counter, you didn't modify that (unnamed) list of integers, and that list is all that the
for-loop looks at.

Hope that helps...

Jeff Shannon
Technician/Programmer
Credit International

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Timothy M. Brauch | 1 Aug 2002 19:14

Re: on mailing list

From: "Jerry Brady" <hiddenworlds <at> hotmail.com>
To: <tutor <at> python.org>
> Hi:
>
> Is there anyone thats from Kentucky on your mailing list.. Like to find
someone closes to me in
>
> kentucky
>
> Thanks
>
> Jerry

I'm from Kentucky, actually Northern Kentucky which almost a completely
seperate state.  But, I am moving to North Carolina at the end of the week
for a job with Wake Forest.  Go Demon Deacons!

I do know that Centre College in Danville, KY (just outside Lexington)
teaches Python in the introductory computer science class.

 - Tim

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Abel Daniel | 1 Aug 2002 19:56
Picon
Favicon

Re: Meeester bell.

Doug.Shawhan <at> gecits.ge.com wrote:
> I have been looking through the modules for a text-mode bell that will work
> in windows (i.e. not in curses or Tkinter).
> 
> I am postitive I have seen this beastie somewhere... Any clues?
> 
> d
I you run the python program in a shell window, you might try
>>> print"\007"
which beeps (at least for me). This works by echoing a ASCII code 7
which is represented by a beep.

Or you can use the winsound module on M$ platforms. 

abli
abli <at> freemail.hu

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane