Re: [Tutor] help with arrays

2007-05-18 Thread Alan Gauld
"Stephen Adler" <[EMAIL PROTECTED]> wrote

> I'm quite new to python and come from a c++/old school
> math/computing/physics background.

Thats OK, many of us came from there too.
Its not permanently damaging! :-)

> is that I can't for the life of me figure out how to allocate a 1meg
> buffer. (or any arbitrary sized buffer) without using something like 
> the
> range function.

First I have to ask why you need to? Thats an fairly
unusual requirement in Python where storage is nearly
always dynamically allocated.

> It would be nice to do something like
>
> a=string(10)
>
> or something like that which would create a string 100 
> characters
> long. And then use that as input into the array module so that I can
> build up an array. What's the standard convention to do this?

And again why do you need to use an array, thats also fairly
uncommon. Can you not just allocate a dynamically created
string to a normal Python list?

Thee are valid cases in Python where you do need to
preallocate a block of storage and where the array module
is the best choice but before going there lets be sure we
need to!

> Also, how about pointers?

Most things in Python are effectively pointers in that all variables
in Python are effectively references in C++ terms. There are no
static variables. Everything is passed by reference.

> I'm using a c++ wrapped in python package
> called vtk and there are some function or class "attributes" which
> return pointers. How do I create a pointer reference?

Its just a name in Python

myName = returnMyPointer()

HTH,

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


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


[Tutor] (no subject)

2007-05-18 Thread Teresa Stanton
Hi all:

Remember when I was having problems moving my .gif around my Tkinter maze?
Well, I was going about it all wrong (as some pointed out).  What REALLY
works is a graph.  I used a dictionary, the keys are main coordinates that
are a path that the .gif follows using a greedy algorithm that finds all the
paths to a determined location.  The definition of the keys are all the
possible directions the .gif can go.  Not all paths are covered on purpose.
In any case, here is the updated code, for those who asked me to post it.
I'm hoping to have it completed next week, without the gif of my dog (lol)
and a bad guy or two to follow the gif that will be used in the maze. 

The next thing I have to do is bind an event to the arrow keys that will
update the current x and y position.. I haven't quite worked that out yet.
Right now the gif moves through the maze based on the path.  Now the event
(an keyboard arrow) should tell it to go to that direction at the next turn.
The function that defines the move is called move_gif().  I could use some
ideas because I keep getting stuck on the details. How does the event effect
the current course through the maze? Does it somehow update the current call
to find_all_paths?  
Or some sort of Helper function that interrupts the current path at a vertex
giving it a new path?  That one seems most likely, but I'm still stuck on
how to stop at the vertex and move to the new location.  Any help would be
appreciated.

TYIA

T
<>"""
Build the maze and pathway
"""
from Tkinter import *
import time

root = Tk()
root.title("Background")
canvasOne = Canvas(width = 800, height = 700, bg = 'black')
canvasOne.pack()

def createWall((x0, y0), (x1, y1), colour = 'blue', width = 3):
""" create a double wall outlining the maze. """
canvasOne.create_line(x0, y0, x1, y1, width = width, fill = colour)
canvasOne.create_line(350, 630, 450, 630, width = 3, fill = 'gold', tag = 
'gate')

def buildPathHorizontal((val1, val2, number), increment = 20, delta = 5):
""" build the  horizontal path through the maze, small white squares"""
for i in range(number):
val1 += increment
x, y = val1, val2
deltax = x + delta
deltay = y + delta
canvasOne.create_rectangle(x, y, deltax, deltay, fill = 'white')

def buildPathVertical((val1, val2, number), increment = 20, delta = 5):
""" build the vertical path through the maze, small white squares"""
for i in range(number):
val2 += increment
x, y = val1, val2
deltax = x + delta
deltay = y + delta
canvasOne.create_rectangle(x, y, deltax, deltay, fill = 'white')

outerWall = [(450, 640), (475, 640), (475, 640), (475, 690), (475, 690), (790, 
690), (790, 690),
 (790, 530), (790, 530), (660, 530), (660, 530), (660, 360), 
(790, 360), (790, 10), (790, 10),
 (10, 10), (10, 10), (10, 360), (10, 360), (150, 360), (150, 
360), (150, 530), (150, 530),
 (10, 530), (10, 530), (10, 690), (10, 690), (325, 690), (325, 
690), (325, 640), (325, 640),
 (350, 640), (350, 630), (350, 630), (315, 630), (315, 680), 
(20, 680), (20, 680), (20, 560),
 (20, 540), (160, 540), (160, 540), (160, 350), (20, 350), (20, 
350), (20, 20), (20, 20),
 (380, 20), (380, 20), (380, 130), (380, 130), (420, 130), (420, 
130), (420, 20), (420, 20),
 (780, 20), (780, 350), (780, 350), (650, 350), (650, 350), (650, 
540), (650, 540), (780, 540),
 (780, 540), (780, 680), (780, 680), (485, 680), (485, 630), (485, 
630), (450, 630), (450, 630),
 (450, 640)]
topLeftBox = [(130, 105), (130, 125), (130, 125), (250, 125), (250, 125), (250, 
105),
(130, 105), (250, 105)]
secondTopLeftBox = [(160, 215), (160, 225), (160, 215), (230, 215), (230, 215),
(230, 225), (160, 225), (230, 225)]
topRightBox = [(545, 105), (545, 125), (545, 125), (665, 125), (665, 125), 
(665, 105), 
   (545, 105), (665, 105)]
secondTopRightBox = [(560, 215), (560, 225), (560, 215), (625, 215), (625, 
215), (625, 225),
 (625, 225), (560, 225)]
middleT = [(345, 240), (455, 240), (345, 240), (345, 240), (345, 250), (395, 
250), (395, 250), (395, 335),
   (395, 335), (405, 335), (405, 335), (405, 250), (405, 250), (455, 
250), (455, 250), (455, 240)]
leftSidewaysT = [(275, 340), (275, 500), (275, 340), (285, 340), (285, 340), 
(285, 415), (285, 415), (345, 415),
 (345, 415), (345, 425), (285, 425), (345, 425), (285, 425), 
(285, 500), (275, 500), (285, 500)]
rightSidewaysT = [(525, 340), (525, 500), (525, 340), (515, 340), (515, 340), 
(515, 415), (515, 415), (455, 415),
  (455, 415), (455, 425), (515, 425), (455, 425), (515, 425), 
(515, 500), (515, 500), (525, 500)]

walls = [outerWall] 

for wall in walls: 
for i in range(len(wall) - 1):
createWall(outerWall[i], outerWall[i+1])

boxes = [top

[Tutor] (no subject)

2007-05-18 Thread Richard Henderson
Hello, 
I am a rank beginner, as I'm sure my question will show. After I enter and save 
 a script using Notepad, it is not recognized by DOS and will not run. What 
might I be doing wrong. I am using PythonWin  and Windows XP.
Thanks,
Richard




  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2007-05-18 Thread Tim Golden
Richard Henderson wrote:
> Hello,
> I am a rank beginner, as I'm sure my question will show. After I enter 
> and save  a script using Notepad, it is not recognized by DOS and will 
> not run. What might I be doing wrong. I am using PythonWin  and Windows XP.

Often the case that Notepad will (silently) add a ".txt" to
whatever filename you offer, unless you quote the whole
thing. This confusion can be compounded if you have set the
(default) setting: Hide extensions for known file types.

TJG

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


Re: [Tutor] (no subject)

2007-05-18 Thread Paulo Nuin
Hi Richard

Have you try running it with Python in front of the script name? Such as:

python my_script.py

Usually on Windows command prompt, if Python is not on your path you 
have to enter the whole path to it, something like C:\Python25\python.

HTH

Paulo

Richard Henderson wrote:
> Hello,
> I am a rank beginner, as I'm sure my question will show. After I enter 
> and save  a script using Notepad, it is not recognized by DOS and will 
> not run. What might I be doing wrong. I am using PythonWin  and 
> Windows XP.
> Thanks,
> Richard
>
> 
> Moody friends. Drama queens. Your life? Nope! - their life, your story.
> Play Sims Stories at Yahoo! Games. 
> 
> 
>
> ___
> 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] urllib.urlencode and unicode strings

2007-05-18 Thread Jon Crump
Kent,

Thanks so much. It's easy when you know how. Now that I know, I only need 
the encode('utf-8') step since geopy does the urlencode step.

On Thu, 17 May 2007, Kent Johnson wrote:

> It's two steps. First convert to utf-8, then urlencode:
 c = u'\xe2'
 c
> u'\xe2'
 c.encode('utf-8')
> '\xc3\xa2'
 import urllib
 urllib.quote(c.encode('utf-8'))
> '%C3%A2'
>
> Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2007-05-18 Thread Luke Paireepinart
Richard Henderson wrote:
> Hello,
> I am a rank beginner, as I'm sure my question will show. After I enter 
> and save  a script using Notepad, it is not recognized by DOS and will 
> not run. What might I be doing wrong. I am using PythonWin  and 
> Windows XP.
> Thanks,
> Richard
Please never again write a message to this mailing list without a subject.
For those of us who have threads turned on, it becomes quite cumbersome.
(for me, you essentially revived a thread from 7/6/2005 because my 
thunderbird can't tell that
this message isn't part of the thread because it has the same subject line.)
Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2007-05-18 Thread Rikard Bosnjakovic
On 5/18/07, Teresa Stanton <[EMAIL PROTECTED]> wrote:

> Remember when I was having problems moving my .gif around my Tkinter maze?

No, but we will all hereby remember you forever for posting a new
thread without a proper subject on this list. Perhaps at the same time
as our eyes will start peering.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
Hi,

I am trying to write a simple program to display Conway's Game Of Life.
I have the bones of the program together but I'm struggling with the
function that tests for and applies the rules of the game (the important
bit). I have the current state of the game stored in a 2d matrix with
each cell represented by a 1 or 0 (alive or dead) i.e: [[0, 1, 0], [1,
0, 0], [0, 0, 0]]. I'm using a 15 * 15 matrix for testing purposes. I
have come up with the following function to update the matrix so far:

def update_matrix(matrix):
matrix_updated = [matrix]
# Perform check for each value in the matrix
for x in range(len(matrix[0])):
for y in range(len(matrix)):
neighbour_count = 0
if matrix[x-1][y+1]: neighbour_count = neighbour_count + 1 
if matrix[x][y+1]: neighbour_count = neighbour_count + 1
if matrix[x+1][y+1]: neighbour_count = neighbour_count + 1
if matrix[x+1][y]: neighbour_count = neighbour_count + 1
if matrix[x+1][y-1]: neighbour_count = neighbour_count + 1
if matrix[x][y-1]: neighbour_count = neighbour_count + 1
if matrix[x-1][y-1]: neighbour_count = neighbour_count + 1
if matrix[x-1][y]: neighbour_count = neighbour_count + 1
# Apply game of life rules to each item in the matrix
if 2 < neighbour_count > 3:
matrix_updated[x][y] = 0
elif neighbour_count == 3:
matrix_updated[x][y] = 1
# No need to change values if neighbour count == 2
return matrix_updated

I have two problems with this code: Firstly, when testing cells on the
edges of the matrix, I get an IndexError because I am testing an item in
the list that does not exist. I want the program to assume that cells
outside the bounds of the board are automatically dead. I am not sure
how to suppress or avoid this error so that neighbour_count is not
incremented for indexes outside the matrix.

My second problem is that this function seems to be very clunky to me
(even if it did work...). I cannot think of a way of checking each of
the 8 cells surrounding the one being tested without doing it this way.
Is there a better way of doing this?

Thanks in advance, Matt.


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


Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Rikard Bosnjakovic
On 5/18/07, Matt Smith <[EMAIL PROTECTED]> wrote:

> I am not sure
> how to suppress or avoid this error so that neighbour_count is not
> incremented for indexes outside the matrix.

Something like this:

try:
   the_index_outside_matrix_test()
except IndexError:
  suppress_the_error()

> Is there a better way of doing this?

Perhaps something like this:

for n in (x, x+1, x-1):
  for m in (y, y+1, y-1):
if matrix[n, m]:
  neighbour_count = neighbour_count + 1



-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
On Fri, 2007-05-18 at 23:49 +0200, Rikard Bosnjakovic wrote:
> Something like this:
> 
> try:
>the_index_outside_matrix_test()
> except IndexError:
>   suppress_the_error()

Thanks Rikard,

I'm not sure how I would go about actually suppressing the error - what
would suppress_the_error() actually call?

Cheers,

Matt


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


Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
> > Is there a better way of doing this?
> 
> Perhaps something like this:
> 
> for n in (x, x+1, x-1):
>   for m in (y, y+1, y-1):
> if matrix[n, m]:
>   neighbour_count = neighbour_count + 1
> 

I need to not text matrix[x][y] is there a simple way to exclude this from the 
possible combinations of values from the two tuples?


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


Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Luke Paireepinart
Matt Smith wrote:
> On Fri, 2007-05-18 at 23:49 +0200, Rikard Bosnjakovic wrote:
>   
>> Something like this:
>>
>> try:
>>the_index_outside_matrix_test()
>> except IndexError:
>>   suppress_the_error()
>> 
>
> Thanks Rikard,
>
> I'm not sure how I would go about actually suppressing the error - what
> would suppress_the_error() actually call?
>   
In this case, you don't need to do anything to the error.
You're expecting an IndexError, and if one occurs, you're assuming that 
that neighbor doesn't count.
So just put the code Rikard sent you in the try block
and in the except block, put 'pass' (i.e. "Do Nothing").

Another note:  I think (x-1, x, x+1) is more clear than (x, x+1, x-1),
and also: note that Rikard's code will always check x,y  which will 
always be 1 (assuming you don't do checks on
whether they should stay alive for already dead squares!)
You can add an if statement to remove this case, or,  easier (and 
probably more efficient) just subtract 1 from your result.

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


Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Luke Paireepinart
Matt Smith wrote:
>>> Is there a better way of doing this?
>>>   
>> Perhaps something like this:
>>
>> for n in (x, x+1, x-1):
>>   for m in (y, y+1, y-1):
>> if matrix[n, m]:
>>   neighbour_count = neighbour_count + 1
>>
>> 
>
> I need to not text matrix[x][y] is there a simple way to exclude this from 
> the possible combinations of values from the two tuples?
see my other reply, Matt.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] GRUMPY?

2007-05-18 Thread Mike Hansen
> No, but we will all hereby remember you forever for posting a new
> thread without a proper subject on this list. Perhaps at the same time
> as our eyes will start peering.
> 

I would imagine that the original poster didn't have any remnants of the
previous thread. Yes, the poster should have put a subject. On the other
hand, we need to be nicer too. More like... "Glad you figured it out.
Hey, could you do us a favor next time and put a subject on your
message?"

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


[Tutor] question re: executing exe files with arguments

2007-05-18 Thread Janani Krishnaswamy
Hi!
I am having trouble executing an exe file with 3 arguments within a
python script.  Right now I have something like this:

os.system(r'"1/2/3/program 1/2/3/argument1 1/2/3/argument2"')

I was trying it with a raw string because of the /'s within it.  I'm not
sure of any other approaches.

Any advice would be greatly appreciated!

Thanks!

Janani 

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


Re: [Tutor] (no subject)

2007-05-18 Thread Kent Johnson
Rikard Bosnjakovic wrote:
> On 5/18/07, Teresa Stanton <[EMAIL PROTECTED]> wrote:
> 
>> Remember when I was having problems moving my .gif around my Tkinter maze?
> 
> No, but we will all hereby remember you forever for posting a new
> thread without a proper subject on this list. Perhaps at the same time
> as our eyes will start peering.

Let's remember that this is a list for beginners, with a well-earned 
reputation for friendliness. Please be gentle and forgiving of mistakes 
so beginners feel welcome as they learn.

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


Re: [Tutor] question re: executing exe files with arguments

2007-05-18 Thread Luke Paireepinart
Janani Krishnaswamy wrote:
> Hi!
> I am having trouble executing an exe file with 3 arguments within a
> python script.  Right now I have something like this:
>
> os.system(r'"1/2/3/program 1/2/3/argument1 1/2/3/argument2"')
>
> I was trying it with a raw string because of the /'s within it.  I'm not
> sure of any other approaches.
>   
'\' is the only reason you'd need to use a raw string, not '/'.
This is because backslash is used for special character sequences.
For example, a new line is '\n'.

Other than that, what is the problem you're having, exactly?
HTH,
-Luke

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


Re: [Tutor] (no subject)

2007-05-18 Thread Tom Tucker

Very cool! Where is Inky, Blinky, Pinky, and Clyde? ;-) Maybe dog catchers
would be better foes for Dusty.


On 5/18/07, Teresa Stanton <[EMAIL PROTECTED]> wrote:


Hi all:

Remember when I was having problems moving my .gif around my Tkinter maze?
Well, I was going about it all wrong (as some pointed out).  What REALLY
works is a graph.  I used a dictionary, the keys are main coordinates that
are a path that the .gif follows using a greedy algorithm that finds all
the
paths to a determined location.  The definition of the keys are all the
possible directions the .gif can go.  Not all paths are covered on
purpose.
In any case, here is the updated code, for those who asked me to post it.
I'm hoping to have it completed next week, without the gif of my dog (lol)
and a bad guy or two to follow the gif that will be used in the maze.

The next thing I have to do is bind an event to the arrow keys that will
update the current x and y position.. I haven't quite worked that out yet.
Right now the gif moves through the maze based on the path.  Now the event
(an keyboard arrow) should tell it to go to that direction at the next
turn.
The function that defines the move is called move_gif().  I could use some
ideas because I keep getting stuck on the details. How does the event
effect
the current course through the maze? Does it somehow update the current
call
to find_all_paths?
Or some sort of Helper function that interrupts the current path at a
vertex
giving it a new path?  That one seems most likely, but I'm still stuck on
how to stop at the vertex and move to the new location.  Any help would be
appreciated.

TYIA

T

___
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] subject changed to Tkinter arrow event

2007-05-18 Thread Teresa Stanton
Thanks.  Eventually, one will be able to take a picture of oneself and that
will be the gif that chases around the maze.  I'm trying to avoid any 'copy
write'  infringement. I have a little alien that I am trying to incorporate
into the maze that will try to find the gif.  But as it stands, it's not
very interactive which is why I'm hoping someone has the ability to guide me
in the direction I need to finish the interactive part with the keyboard
event. 

 

I am sorry for not putting a subject line the first time.  I suppose I was a
little hasty when sending the first post.

 

T

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Tom Tucker
Sent: Friday, May 18, 2007 3:27 PM
To: tutor@python.org
Subject: Re: [Tutor] (no subject)

 

Very cool! Where is Inky, Blinky, Pinky, and Clyde? ;-) Maybe dog catchers
would be better foes for Dusty. 



On 5/18/07, Teresa Stanton <[EMAIL PROTECTED]> wrote:

Hi all: 

Remember when I was having problems moving my .gif around my Tkinter maze?
Well, I was going about it all wrong (as some pointed out).  What REALLY
works is a graph.  I used a dictionary, the keys are main coordinates that 
are a path that the .gif follows using a greedy algorithm that finds all the
paths to a determined location.  The definition of the keys are all the
possible directions the .gif can go.  Not all paths are covered on purpose. 
In any case, here is the updated code, for those who asked me to post it.
I'm hoping to have it completed next week, without the gif of my dog (lol)
and a bad guy or two to follow the gif that will be used in the maze. 

The next thing I have to do is bind an event to the arrow keys that will
update the current x and y position.. I haven't quite worked that out yet.
Right now the gif moves through the maze based on the path.  Now the event 
(an keyboard arrow) should tell it to go to that direction at the next turn.
The function that defines the move is called move_gif().  I could use some
ideas because I keep getting stuck on the details. How does the event effect

the current course through the maze? Does it somehow update the current call
to find_all_paths?
Or some sort of Helper function that interrupts the current path at a vertex
giving it a new path?  That one seems most likely, but I'm still stuck on 
how to stop at the vertex and move to the new location.  Any help would be
appreciated.

TYIA

T

___
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] Help with excetion handing and making my codemore efficient needed please

2007-05-18 Thread Alan Gauld

"Matt Smith" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> > Is there a better way of doing this?
>>
>> Perhaps something like this:
>>
>> for n in (x, x+1, x-1):
>>   for m in (y, y+1, y-1):
>> if matrix[n, m]:
>>   neighbour_count = neighbour_count + 1
>>
>
> I need to not text matrix[x][y] is there a simple way to
> exclude this from the possible combinations of values
> from the two tuples?

As Luke said you don;t need to exclude it because you
know that it is always True so you can adjust the final
count to take that into consideration. The cost of testing
one extra cell is much less than testing for an exception
for each of the other 8!

The lesson?
Sometimes algorithms can be adjusted slightly to make
life a lot simpler.

Alan G. 


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


Re: [Tutor] (no subject)

2007-05-18 Thread Alan Gauld

"Luke Paireepinart" <[EMAIL PROTECTED]> wrote

> Please never again write a message to this mailing list without a 
> subject.
> For those of us who have threads turned on, it becomes quite 
> cumbersome.

FWIW I have the same problem reading via gmane. It was
telling me there were unread messages but I couldn't see
them till I scrolled way back in the history to find
the old thread.

Its not a killer but it is inconvenient in a threaded reader.

Alan G.



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


Re: [Tutor] two input acceptions

2007-05-18 Thread Rolando Pereira
adam urbas escreveu:
> Thanks for the help.  I've made quite some progress since I first posted this 
> email.  I have a question though, what did you mean when you were talking 
> about the raw_input( )?  How can the regular input( ) be used evilly?  If you 
> could explain in depth, I would be very grateful.  I have a new question 
> related to my program area.py., I guess it's the same one as before.  When I 
> run the program and input the rectangle option, it asks me for a radius, 
> unless I input 1, instead of rectangle.  How do I program it to accept both 1 
> and rectangle?> Date: Sat, 12 May 2007 18:55:20 +0100> From: [EMAIL 
> PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] 
> (no subject)> > adam urbas escreveu:> > Hi,I just started python today and I 
> would like a few pointers, if you don't mind.  I tried using a tutorial, but 
> was only able to get the correct results for the most basic problems.  # Area 
> calculation programprint “Welcome to the Area calculation program”print “––
–––”print# Print out the menu:print “Please select a shape:”print “1  
Rectangle”print “2  Circle”# Get the user’s choice:shape = input(“> “)# 
Calculate the area:if shape == 1:height = input(“Please enter the height: 
“)width = input(“Please enter the width: “)area = height*widthprint 
“The area is”, areaelse:radius = input(“Please enter the radius: “)area 
= 3.14*(radius**2)print “The area is”, areaI've been trying to get this to 
work.  I was on a forum on Google and they said to put:input("press ENTER to 
continue")at the end.  I did, but it didn't work.  It runs the program but just 
shuts itself off when its done and i don't even get to select any of the option 
things that i'm s> upposed to be able to select.  It just turns on then back 
off and I don't even get to see anything.  Could someone help me 
out.ThanksAdam> > 
_> > Create the 
ultimate e-mail address book. Import your cont
acts to Windows Live Hotmail.> > 
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507>
 > > > > > 
> > > > 
___> > Tutor maillist  -  
Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > First, 
welcome to the world of Python. :D> Second. please give a title when you start 
a new thread on a mailing list.> Third, format your posts and code. Since 
Python uses indented code, it's > kinda hard to read it when it's all in one 
line (Don't worry, I'll paste > it indented in a file attached to this email :D 
)> > Now for the code.> > After arranging the code, the first thing I noticed 
were this characters “ ”> > I tried running the code, and if gave me a error 
there, so I just > replace then with " ", and voilá, the code worked :D . So 
the lesson > here is always use either " " or ' ' in the code.> > Oh, a
lso another thing. Don't use input() to get the user input, because > that 
command can run code and it may be evilly used. Always use > raw_input() 
instead :D .> > Anyway, I hope I helped you,> > > -- > 
_> ASCII ribbon campaign ( )>   - against HTML email  X>   & vCards 
/ \
> _
> Create the ultimate e-mail address book. Import your contacts to Windows Live 
> Hotmail.
> www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507

First of all, what email client are you using?
Because the text is getting all weird and difficult to read (it's all in 
one line, with no paragraphs and things like that).

Now, the thing about input() and why it's not a good policy to use is 
that, unlike raw_input(), what type in a input() is executed by Python 
(in raw_input() is stored as a string).

Example:

var = raw_input()
 >> list("LOL")

Now we have a variable called var which contains the string that says 
'list("LOL")'
You can confirm that by typing:
print var
 >> 'list("LOL")

There, no harm done. Now let's try the same thing using the input() command:

var = input()
 >> list("LOL")

Now let's type "print var" again as we did before.

print var
 >> ['L', 'O'. 'L']

Now what happened? Because you used the input() command, what you type 
was interpreted by Python, instead of being stored in a string and since 
the list() command is used to create a list, Python did just that. He 
created a list. Now, in this example, no harm was done. But image 
someone typing the command os.system("command to delete some file or run 
some file"). That would send a delete command to the terminal, or 
install some file (it could even be a virus).

Ok, it's a little harder to explain, but the thing you should is that 
usually raw_input() = GOOD, input() = BAD.




Now, I couldn't quite understand

[Tutor] Continue Matching after First Match

2007-05-18 Thread Tom Tucker

Please forgive the colors, just trying to help illustrate my question.

The below code snipet works as designed, however the regex matches once and
exits.  I want it to continue matching and printing until EOF.  Any
suggestions?

Why the cStringIO stuff?  The input data shown below is collected from
os.popen.  I was trying to find an easy way of matching my regex.  Matching
with a string seemed easier than looping through the ouput collected.  Hmm.
Come to think of it, I guess I could match on the first "^dn" catpure that
output and then keep looping until "^cn:" is seen. Then repeat.

Anyways, any suggestions to fix the below code?

Thanks for the help,



Code Snipet
###
multi_regex = re.compile(r'dn: uid=(\w+)..*cn: ((\w+ \w+)|(\w+ \w+\.
\w+))..*(?=dn:)', re.MULTILINE| re.DOTALL)
output = os.popen(command).readlines()
voutput = cStringIO.StringIO()
for line in output:
 voutput.write(line)
 contents = voutput.getvalue()  #<-- contents is 
match = re.search(multi_regex, contents)
if match:
   print match.group(1)
   print match.group(2)



Blue = is what the regex matches
Red = regex groups # match.group(#)
Green = next regex groups not being captured

INPUT Data
###
version: 1
dn: uid=jtucker,ou=people,dc=companyA,dc=com
host: hostA
host: hostB
host: hostC
description: other
gecos: John Tucker
gidNumber: 1
uidNumber: 1157
sn: Tucker
cn: John Tucker
uid: jtucker
objectClass: top
objectClass: account
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
objectClass: inetorgperson
objectClass: organizationalPerson
loginShell: /usr/bin/ksh
homeDirectory: /home/jtucker
dn: uid=ttucker,ou=people,dc=companyA,dc=com
loginShell: /usr/bin/zsh
host: hostZ
host: hostC
uid: ttucker
cn: Tom Tucker
sn: Tucker
objectClass: top
objectClass: account
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
objectClass: inetorgperson
objectClass: organizationalPerson
uidNumber: 108
gidNumber: 102
gecos: Tom Tucker
homeDirectory: /home/ttucker
description: system


Current OUTPUT
#
jtucker
John Tucker


Desired OUTPUT

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


Re: [Tutor] Continue Matching after First Match

2007-05-18 Thread Tom Tucker

Disregard! Looks like part of my problem is the regex string.

On 5/18/07, Tom Tucker <[EMAIL PROTECTED]> wrote:


Please forgive the colors, just trying to help illustrate my question.

The below code snipet works as designed, however the regex matches once
and exits.  I want it to continue matching and printing until EOF.  Any
suggestions?

Why the cStringIO stuff?  The input data shown below is collected from
os.popen.  I was trying to find an easy way of matching my regex.
Matching with a string seemed easier than looping through the ouput
collected.  Hmm.  Come to think of it, I guess I could match on the first
"^dn" catpure that output and then keep looping until "^cn:" is seen. Then
repeat.

Anyways, any suggestions to fix the below code?

Thanks for the help,



Code Snipet
###
multi_regex = re.compile(r'dn: uid=(\w+)..*cn: ((\w+ \w+)|(\w+ \w+\.
\w+))..*(?=dn:)', re.MULTILINE| re.DOTALL)
output = os.popen(command).readlines()
voutput = cStringIO.StringIO()
for line in output:
  voutput.write(line)
  contents = voutput.getvalue()  #<-- contents is 
match = re.search(multi_regex, contents)
if match:
print match.group(1)
print match.group(2)



Blue = is what the regex matches
Red = regex groups # match.group(#)
Green = next regex groups not being captured

INPUT Data
###
version: 1
dn: uid= jtucker,ou=people,dc=companyA,dc=com
host: hostA
host: hostB
host: hostC
description: other
gecos: John Tucker
gidNumber: 1
uidNumber: 1157
sn: Tucker
cn: John Tucker
uid: jtucker
objectClass: top
objectClass: account
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
objectClass: inetorgperson
objectClass: organizationalPerson
loginShell: /usr/bin/ksh
homeDirectory: /home/jtucker
dn: uid=ttucker ,ou=people,dc=companyA,dc=com
loginShell: /usr/bin/zsh
host: hostZ
host: hostC
uid: ttucker
cn: Tom Tucker
sn: Tucker
objectClass: top
objectClass: account
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
objectClass: inetorgperson
objectClass: organizationalPerson
uidNumber: 108
gidNumber: 102
gecos: Tom Tucker
homeDirectory: /home/ttucker
description: system


Current OUTPUT
#
jtucker
John Tucker


Desired OUTPUT

jtucker
John Tucker
ttucker
Tom Tucker



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


Re: [Tutor] two input acceptions

2007-05-18 Thread Luke Paireepinart

> [snip]
>
> PS: Now I know why I see all posts messed up. It's because you're 
> sending your emails as a HTML, and I deactivated that on my email 
> client. I don't know if Hotmail (I believe you send you emails from 
> there) as an option to turn off HTML. If it was please use it :D
> (Besides being nice, you can get more responses if you do that. Not 
> everyone has an HTML capable email client.)
>
> PS2 (no, not the console): I just noticed you didn't send the email back 
>   to the mailing list. You should select reply to all (or a similar 
> option) when replying to mailing list, so that other people can learn too.
>   
Yeah, you should probably turn off HTML.
I don't know what the problem is, but I can't read your e-mails at all.
You'll get _much_ more help if people don't have to copy-paste your 
emails into another program and reformat them
just so they can read them.
Also, if your  code is more than a few lines, sending it as an 
attachment keeps it from getting all weird
from e-mail client formatting.
HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pywinauto for OS X and Linux?

2007-05-18 Thread John
I have been playing with pywinauto http://pywinauto.pbwiki.com/ for a 
few hours. Pywinauto allows you to use python to automate the GUI of 
Windows using Python in very intuitive ways.  What are the closest 
analogs for this under OS X and Linux?

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


[Tutor] encryption for files/passwords

2007-05-18 Thread Rohan Deshpande
Hey all,

I am writing a small python script to maintain some passwords and
identity info.  All the data is in an external file.  what is the best
way to encrypt/decrypt this file's data using a key? I am new to
encryption methods let alone how to do it in python.  I had a look at
python-crypto, ezPyCrypto and yawPyCrypto but they seemed overkill?

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


Re: [Tutor] encryption for files/passwords

2007-05-18 Thread Ben Sherman

On 5/18/07, Rohan Deshpande <[EMAIL PROTECTED]> wrote:


Hey all,

I am writing a small python script to maintain some passwords and
identity info.  All the data is in an external file.  what is the best
way to encrypt/decrypt this file's data using a key? I am new to
encryption methods let alone how to do it in python.  I had a look at
python-crypto, ezPyCrypto and yawPyCrypto but they seemed overkill?



If you only need to encrypt passwords, look at the crypt module - it does
one way password hashing.

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