------=_NextPart_000_0005_01BFBED5.6BBFB2E0-- From johnc@greatentertaining.com Tue May 16 08:45:40 2000 From: johnc@greatentertaining.com (John Choi) Date: Tue, 16 May 2000 00:45:40 -0700 Subject: [Tutor] does anyone know the time module Message-ID: This is a multi-part message in MIME format. ------=_NextPart_000_0002_01BFBED0.0F10FDB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi everyone: I've been working my way through Ivan's book and find the examples to be the biggest help in learning Python. Most excellent learning guide Ivan! I'd like to start doing stuff with time... Using two dates as user-input strings in this format DD-MM-YY, find the number of days between them. I'd also like to put to use the leap.py program to determine Gregorian leap years, i.e 365 versus 366 days in a year. Any and all help would be great. Cheers, J.C. ------=_NextPart_000_0002_01BFBED0.0F10FDB0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi everyone:

I've been working my way through = Ivan's book=20 and find the examples to be the biggest help in learning Python.  = Most=20 excellent learning guide Ivan!

I'd like to start doing stuff with = time...

Using two dates as user-input = strings in=20 this format DD-MM-YY, find the number of days between them.  =

I'd also like to put to use the = leap.py=20 program to determine Gregorian leap years, i.e 365 versus 366 days in a=20 year.

Any and all help would be=20 great.

Cheers,

J.C.
Hallo=20 !

I hope it = is possible=20 to solve my problems with programming python.
*1: What can I do to send arguments with=20 "command"  to another method, without calling the method=20 immediately. But after activating the button.
*2: IWhy can I = not do this ?=20 (Error with the Index) How is it possible ?
Thanks=20 Fabian
(fabwing@uni-muenster.de= ) =20
import = Tkinter

class XXX=20 (Tkinter.Frame):

rows =3D 8
columns =3D=20 8

def __init__(self, root):
= Tkinter.Frame.__init__=20 (self, root)
self.butt =3D []
self.butt =3D=20 [self.butt]*self.rows
for row in range = (self.rows):
=20 self.butt [row] =3D [self.butt] * self.columns
for = column in range=20 (self.columns):
=  =20 self.butt [row][column] =3D Tkinter.Button(text =3D 'xxx', background = =3D 'white',=20 command =3D = self.surrounding(row,=20 column)) *1
self.butt=20 [row][column].grid(row=3Drow, column=3Dcolumn)
=

def=20 surrounding (self, row, column):    ## I know this is not = a good=20 algorithem

if row =3D=3D 0:
if = column =3D=3D=20 0:
self.change (0, 1)
= self.change=20 (1, 0)
self.change (1, 1)
elif = column =3D=3D=20 self.columns:
self.change (0, = 2)
=20 self.change (1, 2)
self.change (1, = 3)
=20 else:
self.change (0, = column-1)
=20 self.change (0, column+1)
self.change (1,=20 column-1)
self.change (1, = column)
=20 self.change (1, column+1)
elif row =3D=3D = self.rows:
if=20 column =3D=3D 0:
self.change (row-1, = 0)
=20 self.change (row-1, 1)
self.change (row,=20 1)
elif column =3D=3D = self.columns:
=20 self.change (row, column-1)
self.change (row-1,=20 column-1)
self.change (row-1, = column)
=20 else:
self.change (row, = column-1)
=20 self.change (row-1, column-1)
self.change (row-1,=20 column)
self.change (row-1,=20 column+1)
self.change (row, column+1)
=20 else:
if column =3D=3D 0:
= self.change (row-1,=20 column)
self.change (row-1,=20 column+1)
self.change (row,=20 column+1)
self.change (row+1,=20 column+1)
self.change (row+1, = column)
elif=20 column =3D=3D self.columns:
self.change (row+1,=20 column)
self.change (row+1,=20 column-1)
self.change (row,=20 column-1)
self.change (row-1,=20 column-1)
self.change (row-1, = column)
=20 else:
self.change (row+1, = column)
=20 self.change (row+1, column-1)
self.change (row,=20 column-1)
self.change (row-1,=20 column-1)
self.change (row-1,=20 column)
self.change (row-1,=20 column+1)
self.change (row,=20 column+1)
self.change (row+1,=20 column+1)

def change (self, row, column):
##if self.butt = [row] [column]=20 ["background" =3D=3D "white"]: *2
## = self.butt [row]=20 [column] ["background"] =3D "black"
=20 ##else:
## self.butt [row] [column] ["background"] = =3D=20 "white"
print row, column ##only=20 example
def main ():
app =3D XXX=20 (Tkinter.Tk())
app.pack()
app.mainloop()
if = __name__ =3D=3D=20 '__main__':
main()
------=_NextPart_000_0004_01BFC509.2FDC2F80-- From uncle_wiggly@bigfoot.com Tue May 23 22:00:07 2000 From: uncle_wiggly@bigfoot.com (K P) Date: Tue, 23 May 2000 16:00:07 -0500 Subject: [Tutor] Embedding Question Message-ID: <200005232102.QAA05219@solaris1.mysolution.com> After much effort I finally have a small grasp on embedding Python in my own program (and by extension, extending Python). Not small task I think for a self-taught programmer (embedding in C++ program under DOS using DJGPP, fun). My goal is to use Python as my program's scripting language (similar to VBA for MS Office on Windows platforms). Here's where I need some clues, to ensure I understand the process: 1) Decide what methods/functions/etc I want to 'expose' to Python 2) Write an extension that allows Python to access these methods/etc 3) Embed both extension and Python in my program Is that (in simplified terms) the 'correct' way to approach it? Is there a more efficient way? I guess that means I would also need call- back methods for my program to use Python objects...... Ken From arcege@shore.net Wed May 24 15:55:56 2000 From: arcege@shore.net (Michael P. Reilly) Date: Wed, 24 May 2000 10:55:56 -0400 (EDT) Subject: [Tutor] Little questions ! In-Reply-To: <000701bfc4f8\$6d56c5c0\$4ac8c8c8@309> from "Fabian Wissing" at May 23, 2000 10:49:43 PM Message-ID: <200005241455.KAA27302@northshore.shore.net> > > This is a multi-part message in MIME format. > > ------=_NextPart_000_0004_01BFC509.2FDC2F80 > Content-Type: text/plain; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > Hallo ! > > I hope it is possible to solve my problems with programming python. > *1: What can I do to send arguments with "command" to another method, = > without calling the method immediately. But after activating the button. > *2: IWhy can I not do this ? (Error with the Index) How is it possible ? > Thanks Fabian > (fabwing@uni-muenster.de) =20 Hi, The reason is that you are setting the callback to the _result_ of the "self.surrounding()" method call, not to the a callable itself. How about: ... = Tkinter.Button(text='xxx', ..., command = lambda r=row, c=column, s=self: s.surrounding(r, c) ) This creates an "anonymous function" that saves the values you want (as default parameters) and sets that function as the callback, which will call the surrounding method when it, itself, is called. Also, you replicate the _same_ list object when you use [self.butt]* self.rows. (Not to mention that you are creating a HUGE number of self references with the "self.butt[row] = [self.butt]*self.columns" statement.) You will want to put that in the loop (since you go thru the bother anyway): self.butt = [] for row in range(self.rows): # create a new list and put it in its place self.append([None] * self.columns) for column in range(self.columns): ... -Arcege > import Tkinter > > class XXX (Tkinter.Frame): > =20 > rows =3D 8 > columns =3D 8 > =20 > def __init__(self, root):=20 > Tkinter.Frame.__init__ (self, root) > self.butt =3D [] > self.butt =3D [self.butt]*self.rows > for row in range (self.rows): > self.butt [row] =3D [self.butt] * self.columns > for column in range (self.columns): > self.butt [row][column] =3D Tkinter.Button(text =3D 'xxx', = > background =3D 'white', command =3D self.surrounding(row, column)) *1 > self.butt [row][column].grid(row=3Drow, column=3Dcolumn) > =20 > =20 > def surrounding (self, row, column): ## I know this is not a good = > algorithem > =20 > if row =3D=3D 0: > if column =3D=3D 0: > self.change (0, 1) > self.change (1, 0) > self.change (1, 1) > elif column =3D=3D self.columns: > self.change (0, 2) > self.change (1, 2) > self.change (1, 3) > else: > self.change (0, column-1) > self.change (0, column+1) > self.change (1, column-1) > self.change (1, column) > self.change (1, column+1) > elif row =3D=3D self.rows: > if column =3D=3D 0: > self.change (row-1, 0) > self.change (row-1, 1) > self.change (row, 1) > elif column =3D=3D self.columns: > self.change (row, column-1) > self.change (row-1, column-1) > self.change (row-1, column) > else: > self.change (row, column-1) > self.change (row-1, column-1) > self.change (row-1, column) > self.change (row-1, column+1) > self.change (row, column+1) > else: > if column =3D=3D 0: > self.change (row-1, column) > self.change (row-1, column+1) > self.change (row, column+1) > self.change (row+1, column+1) > self.change (row+1, column) > elif column =3D=3D self.columns: > self.change (row+1, column) > self.change (row+1, column-1) > self.change (row, column-1) > self.change (row-1, column-1) > self.change (row-1, column) > else: > self.change (row+1, column) > self.change (row+1, column-1) > self.change (row, column-1) > self.change (row-1, column-1) > self.change (row-1, column) > self.change (row-1, column+1) > self.change (row, column+1) > self.change (row+1, column+1) > =20 > def change (self, row, column): > ##if self.butt [row] [column] ["background" =3D=3D "white"]: *2=20 > ## self.butt [row] [column] ["background"] =3D "black" > ##else: > ## self.butt [row] [column] ["background"] =3D "white" > print row, column ##only example > def main (): > app =3D XXX (Tkinter.Tk()) > app.pack() > app.mainloop() > if __name__ =3D=3D '__main__': > main() > > ------=_NextPart_000_0004_01BFC509.2FDC2F80 > Content-Type: text/html; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printable > > > > > > http-equiv=3DContent-Type> > > > >
color=3D#000000>Hallo=20 > !
>
color=3D#000000> color=3D#000000>
>
I hope it = > is possible=20 > to solve my problems with programming python. color=3D#000000>
>
face=3DArial=20 > size=3D2>*1: What can I do to send arguments with=20 > "command"  to another method, without calling the method=20 > immediately. But after activating the button.
>
*2: IWhy can I = > not do this ?=20 > (Error with the Index) How is it possible ?
>
Thanks=20 > Fabian
>
href=3D"mailto:(fabwing@uni-muenster.de">(fabwing@uni-muenster.de= > ) =20 >
>
import = > Tkinter
>

>
class XXX=20 > (Tkinter.Frame):

rows =3D 8
columns =3D=20 > 8

def __init__(self, root):
= > Tkinter.Frame.__init__=20 > (self, root)
self.butt =3D []
self.butt =3D=20 > [self.butt]*self.rows
for row in range = > (self.rows):
=20 > self.butt [row] =3D [self.butt] * self.columns
for = > column in range=20 > (self.columns):
= >  =20 > self.butt [row][column] =3D Tkinter.Button(text =3D 'xxx', background = > =3D 'white',=20 > command =3D = > self.surrounding(row,=20 > column)) *1
self.butt=20 > [row][column].grid(row=3Drow, column=3Dcolumn)
= >

def=20 > surrounding (self, row, column):    ## I know this is not = > a good=20 > algorithem

if row =3D=3D 0:
if = > column =3D=3D=20 > 0:
self.change (0, 1)
= > self.change=20 > (1, 0)
self.change (1, 1)
elif = > column =3D=3D=20 > self.columns:
self.change (0, = > 2)
=20 > self.change (1, 2)
self.change (1, = > 3)
=20 > else:
self.change (0, = > column-1)
=20 > self.change (0, column+1)
self.change (1,=20 > column-1)
self.change (1, = > column)
=20 > self.change (1, column+1)
elif row =3D=3D = > self.rows:
if=20 > column =3D=3D 0:
self.change (row-1, = > 0)
=20 > self.change (row-1, 1)
self.change (row,=20 > 1)
elif column =3D=3D = > self.columns:
=20 > self.change (row, column-1)
self.change (row-1,=20 > column-1)
self.change (row-1, = > column)
=20 > else:
self.change (row, = > column-1)
=20 > self.change (row-1, column-1)
self.change (row-1,=20 > column)
self.change (row-1,=20 > column+1)
self.change (row, column+1)
=20 > else:
if column =3D=3D 0:
= > self.change (row-1,=20 > column)
self.change (row-1,=20 > column+1)
self.change (row,=20 > column+1)
self.change (row+1,=20 > column+1)
self.change (row+1, = > column)
elif=20 > column =3D=3D self.columns:
self.change (row+1,=20 > column)
self.change (row+1,=20 > column-1)
self.change (row,=20 > column-1)
self.change (row-1,=20 > column-1)
self.change (row-1, = > column)
=20 > else:
self.change (row+1, = > column)
=20 > self.change (row+1, column-1)
self.change (row,=20 > column-1)
self.change (row-1,=20 > column-1)
self.change (row-1,=20 > column)
self.change (row-1,=20 > column+1)
self.change (row,=20 > column+1)
self.change (row+1,=20 > column+1)

def change (self, row, column):
color=3D#000000 face=3DArial size=3D4>  ##if self.butt = > [row] [column]=20 > ["background" =3D=3D "white"]: *2
## = > self.butt [row]=20 > [column] ["background"] =3D "black"
=20 > ##else:
## self.butt [row] [column] ["background"] = > =3D=20 > "white"
print row, column ##only=20 > example
def main ():
app =3D XXX=20 > (Tkinter.Tk())
app.pack()
app.mainloop()
if = > __name__ =3D=3D=20 > '__main__':
main()