[Tutor] omnicomplete vim python

2006-08-25 Thread anil maran
do u guys know how to enable omnicomplete using vim
for python thanks

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


[Tutor] function arg

2006-08-25 Thread josip
I have here few function from game tic-tac-toe from book python for absoulute beginners     def first(): """ Determine who goes first. Computer or Player. """ gofirst = raw_input("Do You want to go first? (y/n): ")   if gofirst == 'y':  print "You start first"  player = X  computer = O else:  print "Computer is first."  player = O  computer = X return computer, player     def newTable(): """ Create new table. """ table = [] for num in range(9):  table.append('') return table     def playerMove(table):   ##  <== here """ Get player moves """ move = None while move not in legalMoves(table):  move = int(raw_input("Enter Your
 position? (0-9): "))  if move not in range(9):   print '\nOnly numbers 0 - 9'  elif move not in legalMoves(table):   print "\nThat position is allready occupied. Choose another: " print "OK..." return move     Why I have to put table in function playerMove and in some others functions?  If I dont put it's not working.     Thanks! 
		 All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python programming activities

2006-08-25 Thread Bob Gailer




Are you familiar with Kakuro (Cross Sums)? See
http://www.kakuropuzzle.com/ for an example. In every such puzzle the
top row and left column are all "black". I exclude these from the
following "rules":

A valid puzzle meets the following rules:
1 - black squares are symmetric around center. (thus ditto for white).
2 - every white square has at least one white square neighbor 
 vertically and horizontally.
3 - there is a path from any white square to any other white square.
4 - the upper left square is black
5 - there are at most 9 contiguous white squares.
6 - a black square followed horizontally by contiguous white squares 
 has a number in its upper right corner that is the sum of the
digits 
 to be placed in the contiguous white squares. 
7 - ditto for vertically, the number going in the lower left.
8 - there must be at least one combination of unique digits that totals
to the expected sum.
9 - there must be one and only one solution to the puzzle that meets
all expected sums.

This leads to an interesting series of programming assignments. You
would start with some # of rows and columns. Each time the program
would print the result. Aim for a simple character representation of
the board. Example:

       1 2 3 4
  +-+-+-+-+-+
  |X|X|11\XX|10\XX|X|
  +-+-+-+-+-|
1 |X| 3\4 |     |     | 7\X |
  +-+-+-+-+-|
2 |XX\12|     |     |     |     |
  +-+-+-+-+-|
3 |XX\10|     |     |     |     |
  +-+-+-+-+-|
4 |X|XX\5 |     |     |X|
  +-+-+-+-+-+

There are many ways to represent such a puzzle. I offer the following
list of lists where 
- 0 = black with no numbers
- 0.r = row sum
- c.0 = column sum
- c.r = row and column sums
- -1 = blank white square
- any integer between 1 and 9 = white square with number (potential
solution)
Given that the above puzzle would look like:
[[0,0,11.0,10.0,0],
 [0.3.4,-1,-1,7.0],
 [0.12.-1,-1,-1,-1],
 [0.10.-1,-1,-1,-1],
 [0,0.5,-1,-1,0]]


Assignment - Solve one or more of these puzzles, if you are not
familiar with them.
Assignment - Take the above list representation of the puzzle and print
the human-readable form as shown above. 
Assignment - Program for human to enter the layout of a puzzle.
Assignment - Look up the shelve module. This is an easy way to save and
restore Python objects. This will be very useful to save puzzles that
are in progress and restore them later. Write a simple program to save
and restores some trivial object.
Assignment - Apply the shelve technology to save & restore puzzles.
Assignment - Program for human to enter value(s) for a square, using
the row and column number to identify the square,
and to print the result on demand.
Assignment - Evaluate the solution to see if all the sums are correct.
Report errors.
Assignment - Design a structure that would be indexed by a potential
sum and # of contiguous white squares to contain the potential
solutions for that combination. Example for sum = 5 and # squares = 2 
((1,4),(2,3)).
Assignment - Fill that table with the potential solutions.
Assignment - Use that table to put values in rows and print a potential
solution to a puzzle.
Assignment - Think of ways to optimize automated solving of a puzzle
rather than just brute force trial-and-error.

I realize that this can go on and on. I hope this is in the ballpark of
sufficient interest and somewhat easy steps. Let me knw.

-- 
Bob Gailer
510-978-4454


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


[Tutor] Tkinter Icon Suse 10

2006-08-25 Thread Alberto Troiano
Hi everyoneIt's been a long time since I left Python for .NET 2003, but then again I need it to make an app under Linux Suse 10 and I have a questionI'm trying to put an icon to my window...Here is the code so far:
###Start Code###import Tkinterfrom Tkinter import *root = Tk()root.iconbitmap("Change.ico")root.mainloop()###End Code###It works great under Windows but on an Suse 10 Machine it complains about the file. Is this because the icon files are not the same as in Windows or should I be using another sentence to make it work?
I know it's a dumb question but I'm out of practice and I couldn't find docs on Google (maybe I didn't look where I supposed to)Ups..I forgot, I'm using Python 2.4.1Regards-- Alberto
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the invalid syntax?

2006-08-25 Thread Alan Gauld
Nathan,

> Sorry, but it only showed a text-box with the message "Invalid 
> syntax!", then highlighted the %.

OK, But if you try it from a command prompt you will get a proper
error message. But even if you tell us which line it is highlighting,
there are several % signs in your code.

Generally when pythonindicates a syntax error it will be within a
few lines of where the error occurs, so iut saves us a lot of reading!

Alan G.


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


[Tutor] A list of ints to a strings

2006-08-25 Thread Amadeo Bellotti
I need to convert a list of intgers to a string so for example

I have this
x = [1, 2, 3, 4, 5, 6]

I want this

x = "1 2 3 4 5 6"

I need this to write it to a .txt file does anyone know how to do this?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python programming activities

2006-08-25 Thread Bob Gailer
Bob Gailer wrote:

I amend the previous e-mail:

) this is in response to [EMAIL PROTECTED] desire for some programming 
assignments to work while commuting.
) "I exclude these from the following rules" refers just to rules 1 and 4.
) rule 3 - the path is vertical or horizontal, not diagonal.
) rule 5 "there are at most 9 contiguous white squares" should read "any 
contiguous set of white squares has at most 9 squares."

-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] A list of ints to a strings

2006-08-25 Thread Amadeo Bellotti
thank you and like wat if i wanna write one string on one line and another string on another line ect.On 8/25/06, David Heiser <
[EMAIL PROTECTED]> wrote:






This 
will work
 
x = [1, 2, 3, 4, 5, 
6]
 
x = str(x)[1:-1].replace(",", 
'')
 
open("filename.txt", 
"w").write(x)
 

  
  -Original Message-From: 
  [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED]] On Behalf Of 
  Amadeo BellottiSent: Friday, August 25, 2006 3:28 
  PMTo: TutorSubject: [Tutor] A list of ints to a 
  stringsI need to convert a list of intgers to a string so 
  for exampleI have thisx = [1, 2, 3, 4, 5, 6]I want 
  thisx = "1 2 3 4 5 6"I need this to write it to a .txt file 
  does anyone know how to do this?


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


Re: [Tutor] A list of ints to a strings

2006-08-25 Thread John Fouhy
On 26/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:
> I need to convert a list of intgers to a string so for example
>
>  I have this
>  x = [1, 2, 3, 4, 5, 6]
>
>  I want this
>
>  x = "1 2 3 4 5 6"

Actually, I disagree with David's solution somewhat --- I think that
the pythonic way to do this is as follows:

Firstly, you can use a list comprehension to convert each integer into
a separate string.  If you don't know about list comprehensions, you
can read about them in any python tutorial.

>>> x = [1, 2, 3, 4, 5]
>>> y = [str(i) for i in x]
>>> y
['1', '2', '3', '4', '5']

Then you can use the .join() method of strings to join them into a
single line.  In this case, the separator is a space, ' ':

>>> z = ' '.join(y)
>>> z
'1 2 3 4 5'

If you want to put one number on each row, you can use the newline
character '\n' as a separator instead:

>>> '\n'.join(y)
'1\n2\n3\n4\n5'
>>> print '\n'.join(y)
1
2
3
4
5

HTH!

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


Re: [Tutor] Tkinter Icon Suse 10

2006-08-25 Thread Michael Lange
On Fri, 25 Aug 2006 15:14:49 -0400
"Alberto Troiano" <[EMAIL PROTECTED]> wrote:

> Hi everyone
> 
> It's been a long time since I left Python for .NET 2003, but then again I
> need it to make an app under Linux Suse 10 and I have a question
> I'm trying to put an icon to my window...
> Here is the code so far:
> 
> ###Start Code###
> 
> import Tkinter
> from Tkinter import *
> 
> root = Tk()
> root.iconbitmap("Change.ico")
> root.mainloop()
> 
> ###End Code###
> 
> It works great under Windows but on an Suse 10 Machine it complains about
> the file. Is this because the icon files are not the same as in Windows or
> should I be using another sentence to make it work?
> I know it's a dumb question but I'm out of practice and I couldn't find docs
> on Google (maybe I didn't look where I supposed to)
> Ups..I forgot, I'm using Python 2.4.1
> 

Hi Alberto,

you will have to use an xbm bitmap file for the iconbitmap, like

root.iconbitmap("@Change.xbm")

HTH

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


Re: [Tutor] A list of ints to a strings

2006-08-25 Thread Amadeo Bellotti
HTH

wat i ment is like i have

x = [1, 2, 3, 4, 5]
y = [2, 3, 4, 5, 1]

and i want x and y as a string

and i want to write it to a file so its like

1 2 3 4 5
2 3 4 5 1

sorry about that misunderstandingOn 8/25/06, John Fouhy <[EMAIL PROTECTED]> wrote:
On 26/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:> I need to convert a list of intgers to a string so for example>>  I have this>  x = [1, 2, 3, 4, 5, 6]
>>  I want this>>  x = "1 2 3 4 5 6"Actually, I disagree with David's solution somewhat --- I think thatthe pythonic way to do this is as follows:Firstly, you can use a list comprehension to convert each integer into
a separate string.  If you don't know about list comprehensions, youcan read about them in any python tutorial.>>> x = [1, 2, 3, 4, 5]>>> y = [str(i) for i in x]>>> y
['1', '2', '3', '4', '5']Then you can use the .join() method of strings to join them into asingle line.  In this case, the separator is a space, ' ':>>> z = ' '.join(y)>>> z'1 2 3 4 5'
If you want to put one number on each row, you can use the newlinecharacter '\n' as a separator instead:>>> '\n'.join(y)'1\n2\n3\n4\n5'>>> print '\n'.join(y)123
45HTH!--John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I make Python read a string character bycharacter?

2006-08-25 Thread Alan Gauld

"Akash" <[EMAIL PROTECTED]> wrote 
>> How do I make Python read a string character by character?
> 
 str = 'string'
 for i in range(0, len(str)):
> ... print str[i]
> ...

Or without indexing:

for c in "string":
  print c

> s
> t
> r
> i
> n
> g

However I'm not sure if thats what Nathan meant.

If you mean how do you read a string of characters 
from a file use read() with a size of 1.

If you mean from stdin then it depends on the platform. 
Use curses for Linux/MacOS or use msvcrt. 
In both cases the function is getch()

Alan G.

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


Re: [Tutor] Query to the tutor mailing list

2006-08-25 Thread Alan Gauld
> i put a significant number of exercises in "Core Python," some which
> ...
> there are about 260 exercises in the 1st ed., and the upcoming 2nd 
> ed.
> will have well over 300.  i believe this is more than any other 
> Python
> book out there.

Certainly more than mine Wes!
I got a lot of flack on amazon reviews for not putting exercises
at the end of each chapter - although in fact there are over 50
"challenges" throughout the text, but you have to read the text
to find them! ( That's because I don't like text book style
exercises personally...)

However one badly missed Python resource that used to help
a lot was the Useless Python web site. Alas it seems to have
dissappeared fromthe web. The author tried to do a revamp and
for some reason version 2 never quite got the support the original
site did. But it was a great resource of little mini-projects and
challenges for beginners.

And of course the Python Challenge game is still on the web,
but the challenge there tends to be in figuring out what to do,
once yopu get past that you can write the code in about
5 minutes flat! The other problem is you usually need to paste
the result back into a webn browser to assess the result!

Alan G. 


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


Re: [Tutor] omnicomplete vim python

2006-08-25 Thread Alan Gauld

"anil maran" <[EMAIL PROTECTED]> wrote 
> do u guys know how to enable omnicomplete using vim
> for python thanks

Nope.
But what is omnicomplete and why would I want it?

Alan G,
A Python and vim user for 5 years but not (yet) an omnicompleteist

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


Re: [Tutor] Query to the tutor mailing list

2006-08-25 Thread Kent Johnson
Alan Gauld wrote:
> However one badly missed Python resource that used to help
> a lot was the Useless Python web site. Alas it seems to have
> dissappeared fromthe web. 

It's back!
http://www.uselesspython.com/

Kent

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


[Tutor] Sending an attatchment with SMTP lib

2006-08-25 Thread nimrodx
Hi All,

How do I go about sending an attachment with SMTP lib?

Thanks,

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


Re: [Tutor] tkinter events:

2006-08-25 Thread Zsiros Levente
The link is broken.

Mike Hansen wrote:

> 
>
>  
>
>>-Original Message-
>>From: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf Of Zsiros Levente
>>Sent: Thursday, August 24, 2006 2:21 PM
>>To: Danny Yoo
>>Cc: python tutor
>>Subject: Re: [Tutor] tkinter events: 
>>
>>If we're talking about data hiding, let me ask: why Python doesn't 
>>implement data hiding (I mean 'private' and 'protected')? I 
>>consider it 
>>a very important OOP feature, because that makes OOP different from 
>>structural programming.
>>
>>
>>
>
>This might explain...
>
>http://pyfaq.infogami.com/tutor-how-do-i-make-public-and-private-attribu
>tes-and-methods-in-my-classes
>
>Mike
>**
>IMPORTANT: The contents of this email and any attachments are confidential. 
>They are intended for the 
>named recipient(s) only.
>If you have received this email in error, please notify the system manager or 
>the sender immediately and do 
>not disclose the contents to anyone or make copies thereof.
>*** eSafe scanned this email for viruses, vandals, and malicious content. ***
>**
>
>___
>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] tkinter events:

2006-08-25 Thread Zsiros Levente




So, in the following line
self.can.bind("",lambda x:self.handler(x,'release'))
the event-handler will call handler(event, 'release') when the
mousebutton is released, but the 'self' reference is automatically
passed over, so the result will be the handler(self,event, 'release')
call.

Correct me, if I'm wrong.


  
#!/usr/bin/python

# This program implements .  it was originally written by
#Zsiros Levente.  all rights of this modified version go to him :)

from Tkinter import *

class ButtonHandler(object):
def __init__(self):
#our self.mousedown variable is what we'll use to check the state
#of the button, since we're going to be passing a copy of 'self'
#around, we don't have to deal with scoping of the variables.
#I.E. self.mousedown is global to functions in the class
#that accept a 'self' argument.
self.mousedown = 0

#we make the window normally. note all these are 'self' variables
#so we can change them easily elsewhere in the class.
self.root = Tk()
self.root.geometry('600x500+200+200')
self.label = Label(self.root, text=str(self.mousedown))
self.can = Canvas(self.root, width='500', height='400', bg='white')
#lambda is a way we can add extra arguments to a function.
#since the callback of bound events is only a single argument,
#we use 'lambda x' to get the 'event' instance, and pass it
#along with another string identifying which event it came from.
#this may or may not be necessary, but it's cool and it
#makes the handler function make more sense.
#also, we only need one handler function this way.
self.can.bind("",lambda x:self.handler(x,'motion'))
self.can.bind("",lambda x:self.handler(x,'press'))
self.can.bind("",lambda x:self.handler(x,'release'))
self.label.pack()
self.can.pack()
self.root.mainloop()

def handler(self,event,x):
#the first two clauses of the if-elif branch implement your
#'press' and 'release' functions.
if x == 'press':
self.mousedown = 1
elif x == 'release':
self.mousedown = 0
elif x == 'motion':
if self.mousedown:
#you could do something really cool here, like store the time
#that the button was last pressed, and increase the radius of the circle
#depending on how long it's been since then.
r = 5
self.can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, fill="orange")
	self.label.config(text=str(self.mousedown))


#we create an instance of the class which automatically
#calls the '__init__' method.
x = ButtonHandler()
  




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


Re: [Tutor] tkinter events:

2006-08-25 Thread Zsiros Levente




So, in the following line
self.can.bind("",lambda x:self.handler(x,'release'))
the event-handler will call handler(event, 'release') when the
mousebutton is released, but the 'self' reference is automatically
passed over, so the result will be the handler(self,event, 'release')
call.

Correct me, if I'm wrong.


  
#!/usr/bin/python

# This program implements .  it was originally written by
#Zsiros Levente.  all rights of this modified version go to him :)

from Tkinter import *

class ButtonHandler(object):
def __init__(self):
#our self.mousedown variable is what we'll use to check the state
#of the button, since we're going to be passing a copy of 'self'
#around, we don't have to deal with scoping of the variables.
#I.E. self.mousedown is global to functions in the class
#that accept a 'self' argument.
self.mousedown = 0

#we make the window normally. note all these are 'self' variables
#so we can change them easily elsewhere in the class.
self.root = Tk()
self.root.geometry('600x500+200+200')
self.label = Label(self.root, text=str(self.mousedown))
self.can = Canvas(self.root, width='500', height='400', bg='white')
#lambda is a way we can add extra arguments to a function.
#since the callback of bound events is only a single argument,
#we use 'lambda x' to get the 'event' instance, and pass it
#along with another string identifying which event it came from.
#this may or may not be necessary, but it's cool and it
#makes the handler function make more sense.
#also, we only need one handler function this way.
self.can.bind("",lambda x:self.handler(x,'motion'))
self.can.bind("",lambda x:self.handler(x,'press'))
self.can.bind("",lambda x:self.handler(x,'release'))
self.label.pack()
self.can.pack()
self.root.mainloop()

def handler(self,event,x):
#the first two clauses of the if-elif branch implement your
#'press' and 'release' functions.
if x == 'press':
self.mousedown = 1
elif x == 'release':
self.mousedown = 0
elif x == 'motion':
if self.mousedown:
#you could do something really cool here, like store the time
#that the button was last pressed, and increase the radius of the circle
#depending on how long it's been since then.
r = 5
self.can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, fill="orange")
	self.label.config(text=str(self.mousedown))


#we create an instance of the class which automatically
#calls the '__init__' method.
x = ButtonHandler()
  




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


Re: [Tutor] tkinter events:

2006-08-25 Thread Zsiros Levente
So, in the following line

self.can.bind("",lambda x:self.handler(x,'release'))

the event-handler will call handler(event, 'release') when the 
mousebutton is released, but the 'self' reference is automatically 
passed over, so the result will be the handler(self,event, 'release') call.

Correct me, if I'm wrong.

>
>
>#!/usr/bin/python
>
># This program implements .  it was originally written by
>#Zsiros Levente.  all rights of this modified version go to him :)
>
>from Tkinter import *
>
>class ButtonHandler(object):
>def __init__(self):
>#our self.mousedown variable is what we'll use to check the state
>#of the button, since we're going to be passing a copy of 'self'
>#around, we don't have to deal with scoping of the variables.
>#I.E. self.mousedown is global to functions in the class
>#that accept a 'self' argument.
>self.mousedown = 0
>
>#we make the window normally. note all these are 'self' variables
>#so we can change them easily elsewhere in the class.
>self.root = Tk()
>self.root.geometry('600x500+200+200')
>self.label = Label(self.root, text=str(self.mousedown))
>self.can = Canvas(self.root, width='500', height='400', bg='white')
>#lambda is a way we can add extra arguments to a function.
>#since the callback of bound events is only a single argument,
>#we use 'lambda x' to get the 'event' instance, and pass it
>#along with another string identifying which event it came from.
>#this may or may not be necessary, but it's cool and it
>#makes the handler function make more sense.
>#also, we only need one handler function this way.
>self.can.bind("",lambda x:self.handler(x,'motion'))
>self.can.bind("",lambda x:self.handler(x,'press'))
>self.can.bind("",lambda x:self.handler(x,'release'))
>self.label.pack()
>self.can.pack()
>self.root.mainloop()
>
>def handler(self,event,x):
>#the first two clauses of the if-elif branch implement your
>#'press' and 'release' functions.
>if x == 'press':
>self.mousedown = 1
>elif x == 'release':
>self.mousedown = 0
>elif x == 'motion':
>if self.mousedown:
>#you could do something really cool here, like store the time
>#that the button was last pressed, and increase the radius of 
> the circle
>#depending on how long it's been since then.
>r = 5
>self.can.create_oval(event.x-r, event.y-r, event.x+r, 
> event.y+r, fill="orange")
>   self.label.config(text=str(self.mousedown))
>
>
>#we create an instance of the class which automatically
>#calls the '__init__' method.
>x = ButtonHandler()
>  
>

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