Lookin' for a book...


I am going to be introducing myself to python for upcoming projects at work and am curious if anyone has any suggestions on a good book for reference.
I'm not looking for a 'learners guide' or any other such material, rather, a manual of sorts.
For instance, For C++: I used Bjarne's book, For C: I used several, K&R most recently, and Stevens' books for any application.
If anyone has a suggestion, I would appreciate it.
Thank you.
Posted On: Friday 28th of December 2012 05:26:43 AM Total Views:  208
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




Combinatorial of elements in Python?

I have 2 (or more) groups of elements, and I want to get all possible unique combinations from all of them. Is there a build-in method to do it ADictionary={"one":["A","B","C","D"],"two":["H","I"]} I want to have all possible combinations from "one" and "two", that is: AH BI CH DI AI BH CI DH Sounds easy, but is not -- Sebastián Bassi (\t\t\t\t\t\t\t\t\t\t) Diplomado en Ciencia y Tecnología. GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
VIEWS ON THIS POST

79

Posted on:

Monday 5th November 2012
View Replies!

[ANNOUNCE] gmpy 1.0 alpha released

See http://gmpy.sourceforge.net/ for details. What is it: a wrapper for the GMP library, to provide multi-precision arithmetic for Python. Multi-precision floats, and unbounded-precision rationals, are not present in stock Python; multi-precision integers ('long') are, but gmpy's version of multi-precision integers is faster for some operations (NOT all -- used to be, but Python 2.3 did serious enhancements to some operations on longs) and provides lots of nifty pre-packaged additional functions. Minor changes and bug-fixes since the latest 0.9 pre-alpha; support for Python 2.3. The Windows binary release is now for Python 2.3 _only_ (if you're stuck with Python 2.2 on Windows, you can keep using gmpy 0.9 pre-alpha and not really suffer from that). Known bug on Windows: the scan0 and scan1 functions appear broken (perhaps related to the lack of a GMP 4.0 library for Windows -- haven't found one around yet). Alex
VIEWS ON THIS POST

78

Posted on:

Monday 5th November 2012
View Replies!

indices question

Lanny wrote: > Please don't tell me that "list indices must be integers" because I know > that, Why can't I put a varible thats an integer instead raw_input() always returns a string. You have to convert the string into an integer using int(). Christian
VIEWS ON THIS POST

59

Posted on:

Wednesday 7th November 2012
View Replies!

python mechanize/libxml2dom question

hi... i've got the following situation, with the following test url: "http://schedule.psu.edu/soc/fall/oz/a-c/acctg.html#". i can generate a list of the tables i want for the courses on the page. however, when i try to create the xpath query, and plug it into the xpath within python, i'm missing something. if i have a parent xpath query, that generates a list of results/nodes... how can i then use the individual parent node, and trigger off of it, to get further information. i tried using the following chunk of code with no luck. #s is the html from the course file d = libxml2dom.parseString(s, html=1) #at this point, we should have a vaild "d" representation print "sdddd=",s aa=libxml2dom.toString(d) print "hereeeeee \n\n\n" print "aa",aa #sys.exit() # **** course names cpath='//table[position()>0]/descendant::td[position()=2][@width="85%"]/../t d[1]/font/a[2]/text()' cpath_=[] cpath_=d.xpath(cpath) print "len=",len(cpath_) if len(cpath_)>0: for cpath in cpath_: #get the coursename info cname=cpath.toString() print "cpath=",cpath print "cname=",cname rr="./../../../../../../following-sibling::table//tr[position()>1]" rr=cpath.xpath() print "rrlen=",len(rr) print rr[0].toString() sys.exit() i'm assuming that there's a libxml2node method that will do what i need that i'm missing... pointers/comments would be helpful here...
VIEWS ON THIS POST

79

Posted on:

Wednesday 7th November 2012
View Replies!

Re: sum up numbers in a list

>>> L=['10','15','20'] >>> sum(int(x) for x in L) 45 or >>> sum(map(int,L)) 45 sharon kim wrote: > , > > i have a list, for example; > > >>> L=[] > >>> L.append('10') > >>> L.append('15') > >>> L.append('20') > >>> len(L) > 3 > >>> print L > ['10', '15', '20'] > > is there a way to sum up all the numbers in a list the number of > objects in the list is vary, around 50 to 60. all objects are 1 to 3 > digit positive numbers. > > all i can think of is check the length of the list (in the above > example, 3), then L[0]+L[1]+L[2] ...... > > is there a better way to do the job
VIEWS ON THIS POST

76

Posted on:

Wednesday 7th November 2012
View Replies!

RE: threading

1. check out the Caveats for thread module: http://docs.python.org/lib/module-thread.html Threads interact strangely with interrupts: the KeyboardInterrupt exceptionwill be received by an arbitrary thread. (When the signal module is available, interrupts always go to the main thread.) i.e., all threads (including main) to catch interrupt exceptions, and propagate that information to other threads. 2. since there is no way to interrupt a sleep (not aware of any), sleep is not the choice. use something else like napping. I mean, take shorter intervals of sleep, check every thing is fine and go back to napping. if something is fishy - go catch it. hope that helps. Edwin -----Original Message----- From: python-list-bounces+edwin.madari=verizonwireless.com@python.org [mailtoython-list-bounces+edwin.madari=verizonwireless.com@python.org] On Behalf Of Rhamphoryncus Sent: Thursday, August 14, 2008 2:52 PM To: python-list@python.org Subject: Re: threading On Aug 14, 3:30am, "Mathieu Prevot" wrote: > 2008/8/13 Parimala : > > > > > , > > > I am using python2.5.1 version to run my test scripts. Iwant to use > > 'threading' module in my tests. As a startup program, I had run the > > following one. > > > importthreading > > import sys > > import time > > > def hello(): > > i=0 > > try: > > while i > print "hi" > > time.sleep(1) > > i+=1 > > except KeyboardInterrupt: > > print 'KeyboardInterrupt' > > raise KeyboardInterrupt > > > try: > > thread=threading.Thread(target=hello,args=()) > > thread.start() > > except KeyboardInterrupt: > > print 'KeyboardInterrupt' > > raise KeyboardInterrupt > > > once program starts, problem is.. > > I am not able to abort the thread using (CTRL+C) KeyboardInterrupt. While > > running if I press CTRL+C, it won't generate any exception until the end of > > the execution. Once the execution gets over, it will give "Exception > > exceptions.KeyboardInterrupt in > 'C:\python25\lib\threading.py'> ignored" this message and exits. > > > I had gone through some documents, it says if a thread is joined with > > .join() method then we can't stop that process until it releases the lock > > what it acquired. But in the above program I didn't use .join() method but > > still I am not able to abort the thread. > > > Could you please suggest me how can I abort the thread at any point in time > > using CTRL+C. > > > > a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2 > > so you can terminate the thread by: > > (...) > t.start() > (...) > > while True: > try: > #some code > except KeyboardInterrupt: > t.terminate() > break > > Mathieu (For some reason the OP hasn't come through to groups.google.com.. odd) Note that it won't interrupt any blocked I/O, which is often what you need the most. If your threads are CPU-bound you can simply have them check a flag and exit if it becomes True. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you.
VIEWS ON THIS POST

157

Posted on:

Wednesday 7th November 2012
View Replies!

Re: People still using Tkinter?

I am, but "still" isn't the word, I just started. Good, *complete* docs seem to be hard to find, but using a combination of the free resources and going back and forth between them seems to work all right so far. -Chuckk On Sat, May 10, 2008 at 8:20 AM, Kenneth McDonald wrote: > Any guesses as to how many people are still using Tkinter And can anyone > direct me to good, current docs for Tkinter > >
VIEWS ON THIS POST

83

Posted on:

Wednesday 7th November 2012
View Replies!

Recommendation for Web Framework

Let me explain my situation a bit. I've been contracted to develop an ecommerce site. It's nothing too huge but requires a lot of custom development that's not typical for your run of the mill webstore. I've got about three weeks to get the project delivered and I've written quite a bit of code already. I'd like to find some sort of tool to generate some of the repetative bits like data management (think phpMyAdmin but for Python) so I don't have to write a stupid mangement script for every single module (users, customers, inventory, etc). I know there's tools out there that will do this for ASP code with a SQL server backend, but I haven't seen anything for Python outside of the web application frameworks. Ideally, I'd like something like Ruby on Rails that would provide scaffolding support so I can bootstrap the system, so to speak. I've looked at Django, but the client is only running Apache 1.x and Python 2.3. I've given Turbo Gears a try, but couldn't get SQLObject to run (threw an error that I didn't have time to struggle with). So basically I need something with low dependencies, easy to develop in, and releatively easy to deploy. Anyone have any recommendations I really need something on which I can ramp up quickly to get this project out of the door fast. I'm also a framework newbie, so I know there's a learning curve. Any input is appreciated,
VIEWS ON THIS POST

49

Posted on:

Wednesday 7th November 2012
View Replies!

what's the reasonale of loghelper() in mathmodule.c

Hi all, I downloaded Python-2.5.2.tar.bz2 and want to lean some math function implementation in it. I found that mathmodule.c implements 'math' module of python. In this file there's a function loghelper()(in Python-2.5.2/Modules/mathmodule.c), it seems with this function's help any base logarithm can be computed, its comments state as: /* A decent logarithm is easy to compute even for huge longs, but libm can't do that by itself -- loghelper can. func is log or log10, and name is "log" or "log10". Note that overflow isn't possible: a long can contain no more than INT_MAX * SHIFT bits, so has value certainly less than 2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is small enough to fit in an IEEE single. log and log10 are even smaller. */ static PyObject* loghelper(PyObject* args, double (*func)(double), char *format, PyObject *arg) { ....... } I cannot understand it well, can anyone explain me why and how loghelper() can compute any base logarithm Or could anyone give me some reference(such as, books or papers)
VIEWS ON THIS POST

126

Posted on:

Wednesday 7th November 2012
View Replies!

Re: Destructor?

Gabriel Rossetti wrote: > , > > we are writing an application that needs some cleanup to be done if the > application is quit, normally (normal termination) or by a signal like > SIGINT or SIGTERM. I know that the __del__ method exists, but unless I'm > mistaken there is no guarantee as of when it will be called, and some > objects may have already been released (at lease I've had trouble in the > past accessing certain objects from inside __del__, probably since the > parent class's __del__ has to be called first, then it's objects are > already released by the time I need to do something with them). Another > method would be to implement something using the signal module and have > a callback that does all the cleanup when the app. is > quit/terminated/interrupted and have all the child classes override that > with their cleanup code. > > What is the community's point of view on the subject > >
VIEWS ON THIS POST

45

Posted on:

Wednesday 7th November 2012
View Replies!

standard input, for s in f, and buffering

One thing that has annoyed me for quite some time. I apologize if it has been discussed recently. If I run this program on Unix (Python 2.4.4, on Debian Linux) import sys for s in sys.stdin: print '####', s , and type the input on the keyboard rather than piping a file into it, two annoying things happen: - I don't see any output until I have entered a lot of input (approximately 8k). I expect pure Unix filters like this to process a line immediately -- that is what cat, grep and other utilities do, and also what Perl's while() { ... } construct does. - I have to type the EOF character *twice* to stop the program. This is also highly unusual. If I saw this behavior in a program, as a long-time Unix user, I'd call it a bug. I realize this has to do with the extra read-ahead buffering documented for file.next() and that I can work around it by using file.readline() instead. The problem is, "for s in f" is the elegant way of reading files line by line. With readline(), I need a much uglier loop. I cannot find a better one than this: while 1: s = sys.stdin.readline() if not s: break print '####', s , And also, "for s in f" works on any iterator f -- so I have to choose between two evils: an ugly, non-idiomatic and limiting loop, or one which works well until it is used interactively. Is there a way around this Or are the savings in execution time or I/O so large that is willing to tolerate this bug BR, /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn!
VIEWS ON THIS POST

70

Posted on:

Wednesday 7th November 2012
View Replies!

Acting like button are being pressed (BUT THEY ARE NOT) Please Help

""" ----------------------------------------------------------------------------- Name: _tkUnderWaterDemolitionRemoval.py Purpose: The classic Under Water Demolition Removal game Author: mcsejung Created: 2008/02/15 RCS-ID: $Id: _tkUnderWaterDemolitionRemoval.py $ Copyright: (c) 2008 Licence: GPL This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Maintenance: 2008/02/15 The classic Under Water Demolition Removal game ----------------------------------------------------------------------------- """ from Tkinter import * class App: global matrix def __init__(self, master): #Define the matrix self.var2entry = range(8) for i in range(8): self.var2entry[i] = range(8) #Define the outer frame frame = Frame(master) frame.grid() #Define a square self.var2entry[0][0] = StringVar() self.entry00 = Button(frame, textvariable=self.var2entry[0] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry00.bind('', self.leftClick(self.entry00, 0, 0)) # bind left mouse click self.entry00.bind('', self.rightClick(self.entry00, 0, 0)) # bind right mouse click self.entry00.grid(row=0, column=0, sticky=W,) #Define a square self.var2entry[0][1] = StringVar() self.entry01 = Button(frame, textvariable=self.var2entry[0] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry01.bind('', self.leftClick(self.entry01, 0, 1)) # bind left mouse click self.entry01.bind('', self.rightClick(self.entry01, 0, 1)) # bind right mouse click self.entry01.grid(row=0, column=1, sticky=W,) #Define a square self.var2entry[0][2] = StringVar() self.entry02 = Button(frame, textvariable=self.var2entry[0] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry02.bind('', self.leftClick(self.entry02, 0, 2)) # bind left mouse click self.entry02.bind('', self.rightClick(self.entry02, 0, 2)) # bind right mouse click self.entry02.grid(row=0, column=2, sticky=W,) #Define a square self.var2entry[0][3] = StringVar() self.entry03 = Button(frame, textvariable=self.var2entry[0] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry03.bind('', self.leftClick(self.entry03, 0, 3)) # bind left mouse click self.entry03.bind('', self.rightClick(self.entry03, 0, 3)) # bind right mouse click self.entry03.grid(row=0, column=3, sticky=W,) #Define a square self.var2entry[0][4] = StringVar() self.entry04 = Button(frame, textvariable=self.var2entry[0] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry04.bind('', self.leftClick(self.entry04, 0, 4)) # bind left mouse click self.entry04.bind('', self.rightClick(self.entry04, 0, 4)) # bind right mouse click self.entry04.grid(row=0, column=4, sticky=W,) #Define a square self.var2entry[0][5] = StringVar() self.entry05 = Button(frame, textvariable=self.var2entry[0] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry05.bind('', self.leftClick(self.entry05, 0, 5)) # bind left mouse click self.entry05.bind('', self.rightClick(self.entry05, 0, 5)) # bind right mouse click self.entry05.grid(row=0, column=5, sticky=W,) #Define a square self.var2entry[0][6] = StringVar() self.entry06 = Button(frame, textvariable=self.var2entry[0] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry06.bind('', self.leftClick(self.entry06, 0, 6)) # bind left mouse click self.entry06.bind('', self.rightClick(self.entry06, 0, 6)) # bind right mouse click self.entry06.grid(row=0, column=6, sticky=W,) #Define a square self.var2entry[0][7] = StringVar() self.entry07 = Button(frame, textvariable=self.var2entry[0] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry07.bind('', self.leftClick(self.entry07, 0, 7)) # bind left mouse click self.entry07.bind('', self.rightClick(self.entry07, 0, 7)) # bind right mouse click self.entry07.grid(row=0, column=7, sticky=W,) #Define a square self.var2entry[1][0] = StringVar() self.entry10 = Button(frame, textvariable=self.var2entry[1] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry10.bind('', self.leftClick(self.entry10, 1, 0)) # bind left mouse click self.entry10.bind('', self.rightClick(self.entry10, 1, 0)) # bind right mouse click self.entry10.grid(row=1, column=0, sticky=W,) #Define a square self.var2entry[1][1] = StringVar() self.entry11 = Button(frame, textvariable=self.var2entry[1] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry11.bind('', self.leftClick(self.entry11, 1, 1)) # bind left mouse click self.entry11.bind('', self.rightClick(self.entry11, 1, 1)) # bind right mouse click self.entry11.grid(row=1, column=1, sticky=W,) #Define a square self.var2entry[1][2] = StringVar() self.entry12 = Button(frame, textvariable=self.var2entry[1] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry12.bind('', self.leftClick(self.entry12, 1, 2)) # bind left mouse click self.entry12.bind('', self.rightClick(self.entry12, 1, 2)) # bind right mouse click self.entry12.grid(row=1, column=2, sticky=W,) #Define a square self.var2entry[1][3] = StringVar() self.entry13 = Button(frame, textvariable=self.var2entry[1] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry13.bind('', self.leftClick(self.entry13, 1, 3)) # bind left mouse click self.entry13.bind('', self.rightClick(self.entry13, 1, 3)) # bind right mouse click self.entry13.grid(row=1, column=3, sticky=W,) #Define a square self.var2entry[1][4] = StringVar() self.entry14 = Button(frame, textvariable=self.var2entry[1] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry14.bind('', self.leftClick(self.entry14, 1, 4)) # bind left mouse click self.entry14.bind('', self.rightClick(self.entry14, 1, 4)) # bind right mouse click self.entry14.grid(row=1, column=4, sticky=W,) #Define a square self.var2entry[1][5] = StringVar() self.entry15 = Button(frame, textvariable=self.var2entry[1] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry15.bind('', self.leftClick(self.entry15, 1, 5)) # bind left mouse click self.entry15.bind('', self.rightClick(self.entry15, 1, 5)) # bind right mouse click self.entry15.grid(row=1, column=5, sticky=W,) #Define a square self.var2entry[1][6] = StringVar() self.entry16 = Button(frame, textvariable=self.var2entry[1] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry16.bind('', self.leftClick(self.entry16, 1, 6)) # bind left mouse click self.entry16.bind('', self.rightClick(self.entry16, 1, 6)) # bind right mouse click self.entry16.grid(row=1, column=6, sticky=W,) #Define a square self.var2entry[1][7] = StringVar() self.entry17 = Button(frame, textvariable=self.var2entry[1] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry17.bind('', self.leftClick(self.entry17, 1, 7)) # bind left mouse click self.entry17.bind('', self.rightClick(self.entry17, 1, 7)) # bind right mouse click self.entry17.grid(row=1, column=7, sticky=W,) #Define a square self.var2entry[2][0] = StringVar() self.entry20 = Button(frame, textvariable=self.var2entry[2] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry20.bind('', self.leftClick(self.entry20, 2, 0)) # bind left mouse click self.entry20.bind('', self.rightClick(self.entry20, 2, 0)) # bind right mouse click self.entry20.grid(row=2, column=0, sticky=W,) #Define a square self.var2entry[2][1] = StringVar() self.entry21 = Button(frame, textvariable=self.var2entry[2] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry21.bind('', self.leftClick(self.entry21, 2, 1)) # bind left mouse click self.entry21.bind('', self.rightClick(self.entry21, 2, 1)) # bind right mouse click self.entry21.grid(row=2, column=1, sticky=W,) #Define a square self.var2entry[2][2] = StringVar() self.entry22 = Button(frame, textvariable=self.var2entry[2] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry22.bind('', self.leftClick(self.entry22, 2, 2)) # bind left mouse click self.entry22.bind('', self.rightClick(self.entry22, 2, 2)) # bind right mouse click self.entry22.grid(row=2, column=2, sticky=W,) #Define a square self.var2entry[2][3] = StringVar() self.entry23 = Button(frame, textvariable=self.var2entry[2] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry23.bind('', self.leftClick(self.entry23, 2, 3)) # bind left mouse click self.entry23.bind('', self.rightClick(self.entry23, 2, 3)) # bind right mouse click self.entry23.grid(row=2, column=3, sticky=W,) #Define a square self.var2entry[2][4] = StringVar() self.entry24 = Button(frame, textvariable=self.var2entry[2] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry24.bind('', self.leftClick(self.entry24, 2, 4)) # bind left mouse click self.entry24.bind('', self.rightClick(self.entry24, 2, 4)) # bind right mouse click self.entry24.grid(row=2, column=4, sticky=W,) #Define a square self.var2entry[2][5] = StringVar() self.entry25 = Button(frame, textvariable=self.var2entry[2] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry25.bind('', self.leftClick(self.entry25, 2, 5)) # bind left mouse click self.entry25.bind('', self.rightClick(self.entry25, 2, 5)) # bind right mouse click self.entry25.grid(row=2, column=5, sticky=W,) #Define a square self.var2entry[2][6] = StringVar() self.entry26 = Button(frame, textvariable=self.var2entry[2] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry26.bind('', self.leftClick(self.entry26, 2, 6)) # bind left mouse click self.entry26.bind('', self.rightClick(self.entry26, 2, 6)) # bind right mouse click self.entry26.grid(row=2, column=6, sticky=W,) #Define a square self.var2entry[2][7] = StringVar() self.entry27 = Button(frame, textvariable=self.var2entry[2] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry27.bind('', self.leftClick(self.entry27, 2, 7)) # bind left mouse click self.entry27.bind('', self.rightClick(self.entry27, 2, 7)) # bind right mouse click self.entry27.grid(row=2, column=7, sticky=W,) #Define a square self.var2entry[3][0] = StringVar() self.entry30 = Button(frame, textvariable=self.var2entry[3] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry30.bind('', self.leftClick(self.entry30, 3, 0)) # bind left mouse click self.entry30.bind('', self.rightClick(self.entry30, 3, 0)) # bind right mouse click self.entry30.grid(row=3, column=0, sticky=W,) #Define a square self.var2entry[3][1] = StringVar() self.entry31 = Button(frame, textvariable=self.var2entry[3] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry31.bind('', self.leftClick(self.entry31, 3, 1)) # bind left mouse click self.entry31.bind('', self.rightClick(self.entry31, 3, 1)) # bind right mouse click self.entry31.grid(row=3, column=1, sticky=W,) #Define a square self.var2entry[3][2] = StringVar() self.entry32 = Button(frame, textvariable=self.var2entry[3] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry32.bind('', self.leftClick(self.entry32, 3, 2)) # bind left mouse click self.entry32.bind('', self.rightClick(self.entry32, 3, 2)) # bind right mouse click self.entry32.grid(row=3, column=2, sticky=W,) #Define a square self.var2entry[3][3] = StringVar() self.entry33 = Button(frame, textvariable=self.var2entry[3] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry33.bind('', self.leftClick(self.entry33, 3, 3)) # bind left mouse click self.entry33.bind('', self.rightClick(self.entry33, 3, 3)) # bind right mouse click self.entry33.grid(row=3, column=3, sticky=W,) #Define a square self.var2entry[3][4] = StringVar() self.entry34 = Button(frame, textvariable=self.var2entry[3] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry34.bind('', self.leftClick(self.entry34, 3, 4)) # bind left mouse click self.entry34.bind('', self.rightClick(self.entry34, 3, 4)) # bind right mouse click self.entry34.grid(row=3, column=4, sticky=W,) #Define a square self.var2entry[3][5] = StringVar() self.entry35 = Button(frame, textvariable=self.var2entry[3] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry35.bind('', self.leftClick(self.entry35, 3, 5)) # bind left mouse click self.entry35.bind('', self.rightClick(self.entry35, 3, 5)) # bind right mouse click self.entry35.grid(row=3, column=5, sticky=W,) #Define a square self.var2entry[3][6] = StringVar() self.entry36 = Button(frame, textvariable=self.var2entry[3] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry36.bind('', self.leftClick(self.entry36, 3, 6)) # bind left mouse click self.entry36.bind('', self.rightClick(self.entry36, 3, 6)) # bind right mouse click self.entry36.grid(row=3, column=6, sticky=W,) #Define a square self.var2entry[3][7] = StringVar() self.entry37 = Button(frame, textvariable=self.var2entry[3] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry37.bind('', self.leftClick(self.entry37, 3, 7)) # bind left mouse click self.entry37.bind('', self.rightClick(self.entry37, 3, 7)) # bind right mouse click self.entry37.grid(row=3, column=7, sticky=W,) #Define a square self.var2entry[4][0] = StringVar() self.entry40 = Button(frame, textvariable=self.var2entry[4] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry40.bind('', self.leftClick(self.entry40, 4, 0)) # bind left mouse click self.entry40.bind('', self.rightClick(self.entry40, 4, 0)) # bind right mouse click self.entry40.grid(row=4, column=0, sticky=W,) #Define a square self.var2entry[4][1] = StringVar() self.entry41 = Button(frame, textvariable=self.var2entry[4] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry41.bind('', self.leftClick(self.entry41, 4, 1)) # bind left mouse click self.entry41.bind('', self.rightClick(self.entry41, 4, 1)) # bind right mouse click self.entry41.grid(row=4, column=1, sticky=W,) #Define a square self.var2entry[4][2] = StringVar() self.entry42 = Button(frame, textvariable=self.var2entry[4] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry42.bind('', self.leftClick(self.entry42, 4, 2)) # bind left mouse click self.entry42.bind('', self.rightClick(self.entry42, 4, 2)) # bind right mouse click self.entry42.grid(row=4, column=2, sticky=W,) #Define a square self.var2entry[4][3] = StringVar() self.entry43 = Button(frame, textvariable=self.var2entry[4] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry43.bind('', self.leftClick(self.entry43, 4, 3)) # bind left mouse click self.entry43.bind('', self.rightClick(self.entry43, 4, 3)) # bind right mouse click self.entry43.grid(row=4, column=3, sticky=W,) #Define a square self.var2entry[4][4] = StringVar() self.entry44 = Button(frame, textvariable=self.var2entry[4] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry44.bind('', self.leftClick(self.entry44, 4, 4)) # bind left mouse click self.entry44.bind('', self.rightClick(self.entry44, 4, 4)) # bind right mouse click self.entry44.grid(row=4, column=4, sticky=W,) #Define a square self.var2entry[4][5] = StringVar() self.entry45 = Button(frame, textvariable=self.var2entry[4] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry45.bind('', self.leftClick(self.entry45, 4, 5)) # bind left mouse click self.entry45.bind('', self.rightClick(self.entry45, 4, 5)) # bind right mouse click self.entry45.grid(row=4, column=5, sticky=W,) #Define a square self.var2entry[4][6] = StringVar() self.entry46 = Button(frame, textvariable=self.var2entry[4] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry46.bind('', self.leftClick(self.entry46, 4, 6)) # bind left mouse click self.entry46.bind('', self.rightClick(self.entry46, 4, 6)) # bind right mouse click self.entry46.grid(row=4, column=6, sticky=W,) #Define a square self.var2entry[4][7] = StringVar() self.entry47 = Button(frame, textvariable=self.var2entry[4] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry47.bind('', self.leftClick(self.entry47, 4, 7)) # bind left mouse click self.entry47.bind('', self.rightClick(self.entry47, 4, 7)) # bind right mouse click self.entry47.grid(row=4, column=7, sticky=W,) #Define a square self.var2entry[5][0] = StringVar() self.entry50 = Button(frame, textvariable=self.var2entry[5] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry50.bind('', self.leftClick(self.entry50, 5, 0)) # bind left mouse click self.entry50.bind('', self.rightClick(self.entry50, 5, 0)) # bind right mouse click self.entry50.grid(row=5, column=0, sticky=W,) #Define a square self.var2entry[5][1] = StringVar() self.entry51 = Button(frame, textvariable=self.var2entry[5] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry51.bind('', self.leftClick(self.entry51, 5, 1)) # bind left mouse click self.entry51.bind('', self.rightClick(self.entry51, 5, 1)) # bind right mouse click self.entry51.grid(row=5, column=1, sticky=W,) #Define a square self.var2entry[5][2] = StringVar() self.entry52 = Button(frame, textvariable=self.var2entry[5] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry52.bind('', self.leftClick(self.entry52, 5, 2)) # bind left mouse click self.entry52.bind('', self.rightClick(self.entry52, 5, 2)) # bind right mouse click self.entry52.grid(row=5, column=2, sticky=W,) #Define a square self.var2entry[5][3] = StringVar() self.entry53 = Button(frame, textvariable=self.var2entry[5] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry53.bind('', self.leftClick(self.entry53, 5, 3)) # bind left mouse click self.entry53.bind('', self.rightClick(self.entry53, 5, 3)) # bind right mouse click self.entry53.grid(row=5, column=3, sticky=W,) #Define a square self.var2entry[5][4] = StringVar() self.entry54 = Button(frame, textvariable=self.var2entry[5] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry54.bind('', self.leftClick(self.entry54, 5, 4)) # bind left mouse click self.entry54.bind('', self.rightClick(self.entry54, 5, 4)) # bind right mouse click self.entry54.grid(row=5, column=4, sticky=W,) #Define a square self.var2entry[5][5] = StringVar() self.entry55 = Button(frame, textvariable=self.var2entry[5] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry55.bind('', self.leftClick(self.entry55, 5, 5)) # bind left mouse click self.entry55.bind('', self.rightClick(self.entry55, 5, 5)) # bind right mouse click self.entry55.grid(row=5, column=5, sticky=W,) #Define a square self.var2entry[5][6] = StringVar() self.entry56 = Button(frame, textvariable=self.var2entry[5] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry56.bind('', self.leftClick(self.entry56, 5, 6)) # bind left mouse click self.entry56.bind('', self.rightClick(self.entry56, 5, 6)) # bind right mouse click self.entry56.grid(row=5, column=6, sticky=W,) #Define a square self.var2entry[5][7] = StringVar() self.entry57 = Button(frame, textvariable=self.var2entry[5] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry57.bind('', self.leftClick(self.entry57, 5, 7)) # bind left mouse click self.entry57.bind('', self.rightClick(self.entry57, 5, 7)) # bind right mouse click self.entry57.grid(row=5, column=7, sticky=W,) #Define a square self.var2entry[6][0] = StringVar() self.entry60 = Button(frame, textvariable=self.var2entry[6] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry60.bind('', self.leftClick(self.entry60, 6, 0)) # bind left mouse click self.entry60.bind('', self.rightClick(self.entry60, 6, 0)) # bind right mouse click self.entry60.grid(row=6, column=0, sticky=W,) #Define a square self.var2entry[6][1] = StringVar() self.entry61 = Button(frame, textvariable=self.var2entry[6] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry61.bind('', self.leftClick(self.entry61, 6, 1)) # bind left mouse click self.entry61.bind('', self.rightClick(self.entry61, 6, 1)) # bind right mouse click self.entry61.grid(row=6, column=1, sticky=W,) #Define a square self.var2entry[6][2] = StringVar() self.entry62 = Button(frame, textvariable=self.var2entry[6] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry62.bind('', self.leftClick(self.entry62, 6, 2)) # bind left mouse click self.entry62.bind('', self.rightClick(self.entry62, 6, 2)) # bind right mouse click self.entry62.grid(row=6, column=2, sticky=W,) #Define a square self.var2entry[6][3] = StringVar() self.entry63 = Button(frame, textvariable=self.var2entry[6] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry63.bind('', self.leftClick(self.entry63, 6, 3)) # bind left mouse click self.entry63.bind('', self.rightClick(self.entry63, 6, 3)) # bind right mouse click self.entry63.grid(row=6, column=3, sticky=W,) #Define a square self.var2entry[6][4] = StringVar() self.entry64 = Button(frame, textvariable=self.var2entry[6] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry64.bind('', self.leftClick(self.entry64, 6, 4)) # bind left mouse click self.entry64.bind('', self.rightClick(self.entry64, 6, 4)) # bind right mouse click self.entry64.grid(row=6, column=4, sticky=W,) #Define a square self.var2entry[6][5] = StringVar() self.entry65 = Button(frame, textvariable=self.var2entry[6] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry65.bind('', self.leftClick(self.entry65, 6, 5)) # bind left mouse click self.entry65.bind('', self.rightClick(self.entry65, 6, 5)) # bind right mouse click self.entry65.grid(row=6, column=5, sticky=W,) #Define a square self.var2entry[6][6] = StringVar() self.entry66 = Button(frame, textvariable=self.var2entry[6] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry66.bind('', self.leftClick(self.entry66, 6, 6)) # bind left mouse click self.entry66.bind('', self.rightClick(self.entry66, 6, 6)) # bind right mouse click self.entry66.grid(row=6, column=6, sticky=W,) #Define a square self.var2entry[6][7] = StringVar() self.entry67 = Button(frame, textvariable=self.var2entry[6] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry67.bind('', self.leftClick(self.entry67, 6, 7)) # bind left mouse click self.entry67.bind('', self.rightClick(self.entry67, 6, 7)) # bind right mouse click self.entry67.grid(row=6, column=7, sticky=W,) #Define a square self.var2entry[7][0] = StringVar() self.entry70 = Button(frame, textvariable=self.var2entry[7] [0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry70.bind('', self.leftClick(self.entry70, 7, 0)) # bind left mouse click self.entry70.bind('', self.rightClick(self.entry70, 7, 0)) # bind right mouse click self.entry70.grid(row=7, column=0, sticky=W,) #Define a square self.var2entry[7][1] = StringVar() self.entry71 = Button(frame, textvariable=self.var2entry[7] [1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry71.bind('', self.leftClick(self.entry71, 7, 1)) # bind left mouse click self.entry71.bind('', self.rightClick(self.entry71, 7, 1)) # bind right mouse click self.entry71.grid(row=7, column=1, sticky=W,) #Define a square self.var2entry[7][2] = StringVar() self.entry72 = Button(frame, textvariable=self.var2entry[7] [2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry72.bind('', self.leftClick(self.entry72, 7, 2)) # bind left mouse click self.entry72.bind('', self.rightClick(self.entry72, 7, 2)) # bind right mouse click self.entry72.grid(row=7, column=2, sticky=W,) #Define a square self.var2entry[7][3] = StringVar() self.entry73 = Button(frame, textvariable=self.var2entry[7] [3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry73.bind('', self.leftClick(self.entry73, 7, 3)) # bind left mouse click self.entry73.bind('', self.rightClick(self.entry73, 7, 3)) # bind right mouse click self.entry73.grid(row=7, column=3, sticky=W,) #Define a square self.var2entry[7][4] = StringVar() self.entry74 = Button(frame, textvariable=self.var2entry[7] [4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry74.bind('', self.leftClick(self.entry74, 7, 4)) # bind left mouse click self.entry74.bind('', self.rightClick(self.entry74, 7, 4)) # bind right mouse click self.entry74.grid(row=7, column=4, sticky=W,) #Define a square self.var2entry[7][5] = StringVar() self.entry75 = Button(frame, textvariable=self.var2entry[7] [5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry75.bind('', self.leftClick(self.entry75, 7, 5)) # bind left mouse click self.entry75.bind('', self.rightClick(self.entry75, 7, 5)) # bind right mouse click self.entry75.grid(row=7, column=5, sticky=W,) #Define a square self.var2entry[7][6] = StringVar() self.entry76 = Button(frame, textvariable=self.var2entry[7] [6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry76.bind('', self.leftClick(self.entry76, 7, 6)) # bind left mouse click self.entry76.bind('', self.rightClick(self.entry76, 7, 6)) # bind right mouse click self.entry76.grid(row=7, column=6, sticky=W,) #Define a square self.var2entry[7][7] = StringVar() self.entry77 = Button(frame, textvariable=self.var2entry[7] [7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED, width=2, borderwidth=3) self.entry77.bind('', self.leftClick(self.entry77, 7, 7)) # bind left mouse click self.entry77.bind('', self.rightClick(self.entry77, 7, 7)) # bind right mouse click self.entry77.grid(row=7, column=7, sticky=W,) #Define a BOOM!!! self.var2entry80 = StringVar() self.var2entry80.set(' ') self.entry80 = Button(frame, textvariable=self.var2entry80, fg="red", bg="blue", font=("Verdana", 12), relief=FLAT, width=25, borderwidth=3) self.entry80.grid(row=8, column=0, sticky=W, columnspan=8) #Define a Quit self.var2entry90 = StringVar() self.var2entry90.set('QUIT') self.entry90 = Button(frame, command=self.quit, textvariable=self.var2entry90, fg="red", bg="blue", font=("Verdana", 12), relief=RAISED, width=25, borderwidth=3) self.entry90.grid(row=9, column=0, sticky=W, columnspan=8) def quit(self): #Chop down the tree and pull out the roots root.destroy() def boom(self): #Define a BOOM!!! global time2quit self.var2entry80.set('ssss BOOM!!!') time2quit = 1 def you_WIN(self): #Define a WIN!!! global time2quit, youWIN, youAreTheWinner youWIN += 1 if youWIN == youAreTheWinner: self.var2entry80.set('**** YOU WIN!!! ****') time2quit = 1 def leftClick(self, btn, R, C): #Do something when the LEFT button is clicked global time2quit, var2entry, matrix if time2quit == 1: self.quit() if matrix[R][C] == 'x': btn.config(fg='black') self.var2entry[R][C].set(' ') self.boom() self.var2entry[R][C].set(matrix[R][C]) self.you_WIN() def rightClick(self, btn, R, C): #Do something when the RIGHT button is clicked global var2entry btn.config(fg='red') self.var2entry[R][C].set(' ') def genSolution(): import random global matrix, time2quit, youWIN, youAreTheWinner time2quit = youWIN = youAreTheWinner = 0 nudr = [random.randint(1, 64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64)] matrix = range(8) for i in range(8): matrix[i] = range(8) for j in range(8): matrix[i][j] = random.randint(1, 64) if matrix[i][j] in nudr: matrix[i][j] = 'x' youAreTheWinner += 1 else: matrix[i][j] = int(0) youAreTheWinner = 64 - youAreTheWinner for i in range(8): for j in range(8): try: if (i-1 < 0) or (j-1 < 0): pass else: if matrix[i-1][j-1] == 'x': matrix[i][j] += 1 except: pass try: if (i-1 < 0): pass else: if matrix[i-1][j] == 'x': matrix[i][j] += 1 except: pass try: if (i-1 < 0) or (j+1 > 7): pass else: if matrix[i-1][j+1] == 'x': matrix[i][j] += 1 except: pass try: if (j-1 < 0): pass else: if matrix[i][j-1] == 'x': matrix[i][j] += 1 except: pass try: if matrix[i][j] == 'x': pass except: pass try: if (j+1 > 7): pass else: if matrix[i][j+1] == 'x': matrix[i][j] += 1 except: pass try: if (i+1 > 7) or (j-1 < 0): pass else: if matrix[i+1][j-1] == 'x': matrix[i][j] += 1 except: pass try: if (i+1 > 7): pass else: if matrix[i+1][j] == 'x': matrix[i][j] += 1 except: pass try: if (i+1 > 7) or (j+1 > 7): pass else: if matrix[i+1][j+1] == 'x': matrix[i][j] += 1 except: pass #Begin processing; request information root = Tk() root.tk_bisque() root.title('Under Water Mine Field') genSolution() for i in range(8): print for j in range(8): print matrix[i][j], print app = App(root) root.mainloop()
VIEWS ON THIS POST

81

Posted on:

Wednesday 7th November 2012
View Replies!

PIL and getpixel()

i am trying to get the pixel data using im.getpixel() i am getting a tuple like (152,118,106) for a pixel in a RGB jpeg image . what i really want is an integer value representing a pixel ,like waht i can get from java's BufferedImage.getRGB(x,y) .. i am wondering if someone can advise me on how i can do this thanx dn
VIEWS ON THIS POST

105

Posted on:

Wednesday 7th November 2012
View Replies!

ANN: PIL 1.1.6 final (december 3, 2006)

The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities, including display support for Windows and Tkinter. The new 1.1.6 release provides, among ...
VIEWS ON THIS POST

65

Posted on:

Saturday 10th November 2012
View Replies!

Removal of tkinter from python 3.0? [was: Fate of the repr module inPy3.0]

> Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ , > and saw that the repr module was slated for vaporization. I've only > used the module a few times ever. I'm curious if the community wants > it kept around or ...
VIEWS ON THIS POST

213

Posted on:

Sunday 11th November 2012
View Replies!

Re: Question about optimization

On Thu, 24 Jul 2008 17:19:41 -0400, Wei Hao wrote: >Hi: > >I'm pretty new to python and I have some optimization issues. I'll show you >the piece of code which is causing it, with pseudo-code before it and ...
VIEWS ON THIS POST

57

Posted on:

Sunday 25th November 2012
View Replies!

Google's tolerance of spam

On 13 Nov, 23:03, Ben Finney wrote: > > Their messages are an abuse of Google Groups's terms of service, and > Google will likely act on complaints that include a *full* copy of the > offending message. Unless ...
VIEWS ON THIS POST

67

Posted on:

Monday 26th November 2012
View Replies!