[Tutor] Questions about the new turtle module in Python 2.6b2

2008-08-09 Thread Dick Moores

Gregor,


1. I want the window to open with the right edge 0 pixels from the 
right edge of my screen.
However, setup(width=.75, height=.915, startx=-0, starty=0) doesn't 
work. I have to do the nearest thing,
setup(width=.75, height=.915, startx=-1, starty=0). A small thing, 
but what's wrong with perfection.


2. There's a lot I don't understand in
turtle.setup(width=_CFG[, "width"], height=_CFG[, "height"], 
startx=_CFG[, "leftright"], starty=_CFG[, "topbottom"])


What is '_CFG'? And how should anyone know what it is?
What is "leftright"? And how to use it?
What is "topbottom"? And how to use it?

3. http://docs.python.org/dev/library/turtle.html#turtle.stamp

"turtle.stamp()
Stamp a copy of the turtle shape onto the canvas at the current 
turtle position. Return a stamp_id for that stamp, which can be used 
to delete it by calling clearstamp(stamp_id)."


But in your version 1 
(), the 
turtle is hidden by hideturtle()! What are you stamping? It seems the 
shape, or rectangle. If so, why does the doc say 'turtle'?


4. For my random_rectangles.py program I've started to try out the 
new turtle. (See the current state of random_rectanglesV16_web.py at 
.)  The only downside I've 
found is that the new turtle is much faster that the old. I want to 
set the speed so that the outlines of rectangles are drawn slowly 
enough that the user (me at present) can both appreciate the colors 
and have time to check the names of the colors being printed in the 
console window. Using the old turtle, I found that a default delay of 
1 ((delay(1)) was just right; with the new turtle, setting a delay of 
even 50 affects only the first cycle of rectangles. So I don't use 
delay at all. Setting the slowest speed of 1 (speed(1)) is still too 
fast. How can I slow down the drawing of the rectangles?


5. I've been unable to figure out how to use onclick() 
(). 
I'd like to find a way to pause my script by clicking on the screen 
-- so I could snag an image of what's showing, and then click again 
to restart the drawing of the rectangles. And in addition, being able 
to stop the program with a double click on the screen would be very 
handy. Could you explain how to do these, if in fact they are possible?


That's all for now.

Thanks,

Dick

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


Re: [Tutor] issue with the Backslash on IDLE 1.2.2

2008-08-09 Thread bob gailer
Please always reply to tutor@python.org as well as me. All of us can 
help and learn.


Marc Rambert wrote:




Marc Rambert wrote:

hi,

I would like to make some regular expression, unfortunately I can't 
because the backslash doesn't work


Please explain "doesn't work".

I interpret that as "I press the \ key and nothing shows up in the 
active window."





hi yes you are right and this is when I am in french keyboard.


I can't help here but perhaps someone else can.

--
Bob Gailer
Chapel Hill NC 
919-636-4239


When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.


Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

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


Re: [Tutor] Questions about the new turtle module in Python 2.6b2

2008-08-09 Thread Dick Moores


At 03:12 AM 8/9/2008, Dick Moores wrote:
4. For my random_rectangles.py
program I've started to try out the new turtle. (See the current state of
random_rectanglesV16_web.py at
<
http://py77.python.pastebin.com/d3e842821>.)  The only downside
I've found is that the new turtle is much faster that the old. I want to
set the speed so that the outlines of rectangles are drawn slowly enough
that the user (me at present) can both appreciate the colors and have
time to check the names of the colors being printed in the console
window. Using the old turtle, I found that a default delay of 1
((delay(1)) was just right; with the new turtle, setting a delay of even
50 affects only the first cycle of rectangles. So I don't use delay at
all. Setting the slowest speed of 1 (speed(1)) is still too fast. How can
I slow down the drawing of the rectangles?
I seem to have solved #4. 
I had been using tracer() as tracer(True) in my function draw_rect(). In
rereading the doc, I noticed that
<
http://docs.python.org/dev/library/turtle.html#turtle.tracer>
has 
"turtle.tracer(flag=None,
delay=None)"
so in draw_rect() I tried changing tracer(True) to tracer(True, dly).
(See the new version, random_rectanglesV17_web.py, at
<
http://py77.python.pastebin.com/f54c9211f>, lines 220, 230, 240,
etc.)
Then I enabled the user to enter both speed and delay, with a default
speed of 1 and a default delay of 15 (see the new function
get_speed_and_delay_from_user(), lines 153-179). On my computer, these
defaults seemed to be ideal. 
But now I have another puzzle: As long as delay is kept constant, it
doesn't seem to matter what speed is chosen -- from the slowest of 1 to
the fastest of 0. Why is speed irrelevant? 
Dick
BTW at
<
http://py77.python.pastebin.com/f54c9211f>, if you click on the
'view diff' link just above the code, you'll get a diff with the
immediately previous version.





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


[Tutor] something is fundamentally wrong...

2008-08-09 Thread Joshua Nikkel
I've pasted the following from my python shell.  Please note that the first
two lines of code are taken directly from the standard tutorial files under
section 3.1.2.  Will someone please tell me why something as basic and
straightforward as this will not work?  Everything else seems to work just
fine, but not this.  All I need is someway to get the length of a string...

please help,

nosh


Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
on win32
Type "copyright", "credits" or "license()" for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.2.2   No Subprocess 
>>> s = 'supercalifragilisticexpialidocious'
>>> len(s)
Traceback (most recent call last):
  File "", line 1, in 
len(s)
TypeError: 'str' object is not callable
>>> s
'supercalifragilisticexpialidocious'
>>> len(s)
Traceback (most recent call last):
  File "", line 1, in 
len(s)
TypeError: 'str' object is not callable
>>>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unable to catch exception

2008-08-09 Thread James
All,

I'm having a rather strange problem that I'm hoping someone can shed
some light on. I'm trying to catch a BadStatusLine exception raised by
the httplib library. Below is the traceback that Python gives me when
something goes wrong with one of my programs:

-

Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
self.run()
  File "cherryTree.py", line 237, in run
qDump = browser.open( url ).read() # get the new c3 queue
  File "/usr/lib/python2.5/site-packages/mechanize/_mechanize.py",
line 203, in open
return self._mech_open(url, data)
  File "/usr/lib/python2.5/site-packages/mechanize/_mechanize.py",
line 229, in _mech_open
response = UserAgentBase.open(self, request, data)
  File "/usr/lib/python2.5/site-packages/mechanize/_opener.py",
line 181, in open
response = urlopen(self, req, data)
  File "/usr/lib/python2.5/urllib2.py", line 399, in _open
'_open', req)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/usr/lib/python2.5/site-packages/mechanize/_http.py", line
700, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.5/site-packages/mechanize/_http.py", line
675, in do_open
r = h.getresponse()
  File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
response.begin()
  File "/usr/lib/python2.5/httplib.py", line 385, in begin
version, status, reason = self._read_status()
  File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
raise BadStatusLine(line)
BadStatusLine

-

This error happens when I try to open a page using mechanize. From
what I gather this error only happens when the web server returns an
unknown error.

The error only happens once every blue moon, but to avoid a crash I
setup a try/catch.

try:
   
catch BadStatusLine:
   print "yuck!"

However, somehow the thread that this code is in still raised a
BadStatusLine exception and the thread stopped cold.

Thoughts on how to possibly fix this?

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


Re: [Tutor] something is fundamentally wrong...

2008-08-09 Thread Martin Walsh
Joshua Nikkel wrote:
> IDLE 1.2.2   No Subprocess 
 s = 'supercalifragilisticexpialidocious'
 len(s)
> Traceback (most recent call last):
>   File "", line 1, in 
> len(s)
> TypeError: 'str' object is not callable

My guess would be that you've reassigned the name 'len' to some other
object, in this case a string. Does the error persist after you restart
IDLE (or Restart Shell from the Shell menu)?

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


[Tutor] importing path question

2008-08-09 Thread dave selby
Hi all,

I have a main directory 'kmotion2' where python scripts live. They
access a library of scripts in 'kmotion2/core'  as 'kmotion2/core' has
a __init__.py file. However I now need to create a new directory
'utilities' inside 'kmotion2' that also needs to access scripts in
'core'

kmotion2 directory
|   |
core utilities

So I need to import up the tree then back down. Is this possible ?

Dave






-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems with Gauge Bar.

2008-08-09 Thread Olrik Lenstra
Hello mail list ;)

I've been developing a program for a while now (I am still a beginner
though) and I want to add a progress bar (gauge bar) to my program.
I am having quite some trouble actually implementing it though. I attached
the file TSO.pyw which is my current project.
I want to keep it within 1 python file if it's possible. Because I want to
turn it into a single executable file.

I am using wxPython for my GUI and a Win32API module.

I hope to hear from you.
Regards,
Olrik
##--
## TroubleShooting Olrik.
## The Tool that makes a Tech's life easier!
##
## All information can be found at:
## http://artellos.geekstogo.com/
##
## TroubleShooting Olrik, Copyright 2008 Olrik Lenstra
## All Rights Reserved.
##
##--
## Importing the Modules required for TSO.
##--
import wx
import os, sys
import string
import win32api
import re

##--
## Calling for the install directory.
##--
instDir = sys.argv[0]
instDir = instDir.rsplit(r"\TSO.exe")
instDir = str(instDir[0])

##--
## Change the directory to the installed directory.
##--
os.chdir(instDir)

##--
## Setting the text for the version displaying the version, e-mail and site.
##--
versionText = """Troubleshooting Olrik
Version 0.10.2.0
E-Mail:  [EMAIL PROTECTED]
Website: http://artellos.geekstogo.com/

Troubleshooting Olrik, Copyright 2008 Olrik Lenstra
All Rights Reserved."""

##--
## This is the text that is shown in the main screen of the program.
##--
introRaw = """Welcome to Troubleshooting Olrik.
Press 'Scan' to start the scan.
Please be patient while the program
creates a log. The File can be viewed
through the 'Logs' button."""

##--
## The following will create the frame with buttons and text for the program.
## The frame is not resizable and the Maximize button is disabled.
##--
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
wx.Size(300, 280),
  style = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER 
| wx.MAXIMIZE_BOX))

panel = wx.Panel(self, -1)

introFont = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)
introText = wx.StaticText(panel, -1, introRaw,(50, 10), 
style=wx.ALIGN_CENTRE)
introText.SetFont(introFont)

wx.Button(panel, 1, 'Scan!', (115, 90))
wx.Button(panel, 2, 'Logs', (115, 120))
wx.Button(panel, 3, 'Version', (115, 150))
wx.Button(panel, 4, 'Credits', (115, 180))

self.Bind(wx.EVT_BUTTON, self.OnScan, id=1)
self.Bind(wx.EVT_BUTTON, self.OnLogs, id=2)
self.Bind(wx.EVT_BUTTON, self.OnVersion, id=3)
self.Bind(wx.EVT_BUTTON, self.OnCredits, id=4)

##--
## Define the 'Scan!' Button's event.
## This is the main part of the program.
## 'scan()' has been defined later on in the program.
##--
def OnScan(self, event):

##--
## The following displays a messagebox at the beginning of the log saying it 
can take a while.
##--
startScan = '''TSO will now start creating a log.
Please be patient as this can take from 5 up to 10 minutes.
Please press OK to start TSO.'''
dlg2 = wx.MessageDialog(self, startScan, 'Starting TSO.', 
wx.OK|wx.ICON_INFORMATION)
dlg2.ShowModal()
dlg2.Destroy()

##--
## This part simply calls the features in TSO.
##--
  
scan()

##--
## The following displays a messagebox at the end of the log saying the log is 
created.
##-

[Tutor] IP address parse

2008-08-09 Thread Que Prime
I'm trying to parse a log file for all ip addresses but can't get my RE to
work.  Thanks in advance for pointing me in the right direction


#IP address parse

##
import re

infile = open("host0_declare.txt","r")
outfile = open("out.txt","w")

patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})

for line in infile:
  m = patt.match(line)
  if m:
outfile.write("%s.%s.%s.%s\n"%m.groups())

infile.close()
outfile.close()
#
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IP address parse

2008-08-09 Thread Timothy Grant
On Sat, Aug 9, 2008 at 9:57 PM, Que Prime <[EMAIL PROTECTED]> wrote:
> I'm trying to parse a log file for all ip addresses but can't get my RE to
> work.  Thanks in advance for pointing me in the right direction
>
>
> #IP address parse
>
> ##
> import re
>
> infile = open("host0_declare.txt","r")
> outfile = open("out.txt","w")
>
> patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})
>
> for line in infile:
>   m = patt.match(line)
>   if m:
> outfile.write("%s.%s.%s.%s\n"%m.groups())
>
> infile.close()
> outfile.close()
> #
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Well there's one glaring problem, but I'll put that down to a
re-keying error. there are no quote marks around your pattern string.

However, the likely problem is that you are using re.match() instead
of re.search().

Your re will ONLY match if the only thing on the line matches your pattern.

-- 
Stand Fast,
tjg.  [Timothy Grant]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using generators to mock raw_input for doctest

2008-08-09 Thread broek


Hi all,

I'm building a tool that will be run in a shell and depends heavily on
raw_input. I'm also using doctest (mostly via doctest.testfile) to
create unit tests for it.

After thinking a while about how to use doctest for invocations of
raw_input, I came up with the general sort of idea shown in the toy
code below.

I have two questions:

1) As I've never really made generators `mine,' I'm not sure if this is
the best (read `best' as `easiest and simplest') way to use a generator
for this task. Should I be doing it differently?

2) Is there some better way to enable doctesting of code that uses
raw_input? All I found when googling was the suggestion that in place of:

def myfunc():
   # code employing raw_input here

one could write:

def myfunc(input_meth=raw_input):
   # code with raw_input calls replaced with input_meth calls

but that seems like complicating my code for the non-doctest case.
Perhaps that worries me too much, though---I've yet to become test
infected ;-)

Thanks for any input,

Brian vdB



import  sys

class myraw(object):
def __init__(self, values):
self.values = values
self.stream = self.mygen()
def mygen(self):
for i in self.values:
yield i
def readline(self):
return str(self.stream.next())

def double_user_input():
"""A silly example to illustrate my method for testing.

>>> sys.stdin = myraw([1,21,12.5,3.1415])
>>> double_user_input()
2
>>> double_user_input()
42
>>> double_user_input()
25
>>> double_user_input()  # doctest: +ELLIPSIS
6.28300...
>>> sys.stdin = sys.__stdin__
"""
val = float(raw_input()) * 2
val = [val, int(val)][val == int(val)]
return val

def __test():
import doctest
doctest.testmod()

if __name__ == "__main__":
__test()

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


Re: [Tutor] IP address parse

2008-08-09 Thread Josh Rosen


On Aug 9, 2008, at 10:46 PM, Josh Rosen wrote:

There are a few different problems in your code.  First off, regular  
expressions must be passed to re.compile() as strings.


	patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\. 
(\[0-9]{1,3})


should read

	patt = re.compile(r"(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\. 
(\[0-9]{1,3})").


I've used a raw string literal here to prevent Python from  
interpreting the backslashes as character escapes.  However, this  
regular expression still won't work.  If you're going to use a  
character class, there's no need to put a backslash in front of it.   
Correcting this, the line becomes:


	patt = re.compile(r"([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9] 
{1,3})")


This works, but it can be made simpler by using the shorthand  
notation \d in place of [0-9]:


patt = re.compile(r"(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})")

Since it doesn't look like you're doing anything with the parts of  
the ip besides writing the whole ip to a file, you can eliminate the  
capturing parentheses in your regular expression and replace them  
with a single pair:


patt = re.compile(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})")

The string formatting expression becomes:

outfile.write("%s\n" % m.groups())

Hope this helps,
Josh


On Aug 9, 2008, at 9:57 PM, Que Prime wrote:

I'm trying to parse a log file for all ip addresses but can't get  
my RE to work.  Thanks in advance for pointing me in the right  
direction



#IP address parse

##
import re

infile = open("host0_declare.txt","r")
outfile = open("out.txt","w")

patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\. 
(\[0-9]{1,3})


for line in infile:
 m = patt.match(line)
 if m:
   outfile.write("%s.%s.%s.%s\n"%m.groups())

infile.close()
outfile.close()
#
___
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] Questions about the new turtle module in Python 2.6b2

2008-08-09 Thread Gregor Lingl

Dick Moores schrieb:

At 03:12 AM 8/9/2008, Dick Moores wrote:
4. For my random_rectangles.py program I've started to try out the 
new turtle. (See the current state of random_rectanglesV16_web.py at 
< http://py77.python.pastebin.com/d3e842821>.) 
 The only 
downside I've found is that the new turtle is much faster that the 
old. I want to set the speed so that the outlines of rectangles are 
drawn slowly enough that the user (me at present) can both appreciate 
the colors and have time to check the names of the colors being 
printed in the console window. Using the old turtle, I found that a 
default delay of 1 ((delay(1)) was just right; with the new turtle, 
setting a delay of even 50 affects only the first cycle of 
rectangles. So I don't use delay at all. Setting the slowest speed of 
1 (speed(1)) is still too fast. How can I slow down the drawing of 
the rectangles?


I seem to have solved #4.

I had been using tracer() as tracer(True) in my function draw_rect(). 
In rereading the doc, I noticed that < 
http://docs.python.org/dev/library/turtle.html#turtle.tracer>

has
"turtle.tracer(/flag=None/, /delay=None/)"

so in draw_rect() I tried changing tracer(True) to tracer(True, dly). 
(See the new version, random_rectanglesV17_web.py, at < 
http://py77.python.pastebin.com/f54c9211f>, lines 220, 230, 240, etc.)


Then I enabled the user to enter both speed and delay, with a default 
speed of 1 and a default delay of 15 (see the new function 
get_speed_and_delay_from_user(), lines 153-179). On my computer, these 
defaults seemed to be ideal.



That's fine!
But now I have another puzzle: As long as delay is kept constant, it 
doesn't seem to matter what speed is chosen -- from the slowest of 1 
to the fastest of 0. Why is speed irrelevant?

Did you observe that faster speeds need arguments in the range from 2 to 10?
That means speed(10) is fastest speed.

Gregor


Dick

BTW at < http://py77.python.pastebin.com/f54c9211f>, if you click on 
the 'view diff' link just above the code, you'll get a diff with the 
immediately previous version.








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


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