Re: [Tutor] Strange list behaviour in classes
-Original Message- From: Walter Prins Sent: Feb 25, 2010 7:09 AM To: Dave Angel Cc: Alan Gauld , tutor@python.org Subject: Re: [Tutor] Strange list behaviour in classes On 25 February 2010 11:22, Dave Angelwrote: The indentation in your code is lost when I look for it -- everything's butted up against the left margin except for a single space before def variance. This makes it very hard to follow, so I've ignored the thread till now. This may be caused by the mail digest logic, or it may because you're posting online, and don't tell it to leave the code portion unformatted. This is probably something your end, I read and post from within Google mail (as well as from Thunderbird occassionally) and I have no trouble seeing the indentation. (I don't use the mail digest, I receive single emails/posts.)=== I am also seeing the same unindented code. . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting pixels
-Original Message- From: Bill Allen Sent: Sep 18, 2010 11:45 AM To: Alan Gauld Cc: tutor@python.org Subject: Re: [Tutor] plotting pixels On Sat, Sep 18, 2010 at 10:44 AM, Bill Allenwrote: On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld wrote: For plotting pixels I would not use turtle graphics.That would be a fairly complicated option I'd have thought.A simple canvas would be easier.Alan G. Oh, I see! I did not realize that Tk had a canvas widget. That is nice. I will have to play with that and see if I can get everything done in the code I am working with. What I am doing is just trying to do a simple Mandelbrot set plot. It is another bit of coding that I do when learning a new language to get a handle on some of the graphics capabilities, and I am to that point. -Bill It appears that the Tk canvas widget does not support simply plotting a pixel. However, I can plot a line only one pixel long. I wonder why they do not simply provide the pixel plot primitive? I have seen very many graphics packages that do this and I have always wondered why. The primitive obviously exists in the underlying code, because that is what everything else is built upon. Does Tk actually have a something like a create_pixel method in the canvas widget that I have missed?-Bill Is it naive of me to ask, "Couldn't one write his own plotpixel( ) function using the line() function?" . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] new print statement + time module
-Original Message- >From: spir >Sent: Feb 28, 2009 2:16 AM >To: tutor@python.org >Subject: Re: [Tutor] new print statement + time module > >Le Sat, 28 Feb 2009 06:34:07 +0200, >George Wahid s'exprima ainsi: > >> I downloaded python 3.0.1 today and started experimenting with the new >> print statement. >> >> >>>import time >> >>>for l in 'the answer': >> ...print(l,end='') >> ...time.sleep(0.1) >> >> the code is supposed to print "the answer" with a 0.1 second long >> pause between the letters. instead, it waits for 1 second ( >> 0.1*len("the answer") seconds ) and then prints "the answer". what am >> I doing wrong ? > >Indeed, it does the same for me with python 2.5: > >from time import sleep >for c in "1234567890": > sleep(0.25) > print c, > >I guess python underlying outputs are managed like a queue that is flushed at >certain points, eg whan a newline comes. >Already noticed weird outputs messing up ordinary prints (~ sys.stdout) and >exceptions messages (sys.stderr). I'd like to know more about that. > >> both replacing print(l,end='') with print(l) or using the msvcrt >> module instead of the print function work fine. > >The same with py2.5. Without the ',', all is fine. Maybe there is a trick to >force python printing ot in due time, but I have no idea, sorry. > >Denis >-- >la vita e estrany >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor The above code for the 2.5 version appears to work as expected in the command line versions of 2.5. . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is Dani Web?
Title: Signature.html Try this:http://www.ask.com/bar?q=what+is+daniweb&page=1&qsrc=121&ab=0&u=http%3A%2F%2Fwww.daniweb.com%2Fforums%2Ffaq.php%3Ffaq%3Ddaniweb_faqor shorterhttp://tinyurl.com/cfsvpa-Original Message- From: Wayne Watson Sent: Apr 9, 2009 11:52 PM To: "tutor@python.org" Subject: [Tutor] What is Dani Web? See . It seems to a set of forum for a lot of software, including Python. I don't see any explanation of Dani and how it formed. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best Python Editor
-Original Message- >From: pyt...@bdurham.com >Sent: Jun 13, 2009 10:16 AM >To: Alan Gauld , tutor@python.org >Subject: Re: [Tutor] Best Python Editor > >Alan, > >> I spoke a wee bit too soon. The editor is nice but the debugger and some of >> the other tools windows (eg variables) are broken. Pity, lots of potential >> here. > >The current release of Pyscripter is not stable. > >Drop back one release and you'll find a very solid product. > >Malcolm Sounds interesting. What is the stable version and where can it be found? . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using insert method on a list matrix
try M[0].insert(0, 'pod')-Original Message- From: Raj Medhekar Sent: Jul 19, 2009 7:12 PM To: Python Tutor Subject: [Tutor] Using insert method on a list matrix I would like to know how I could use the insert method in a List matrix eg. for the matrix belowM=[[1,2,3], [3,2,1], [4,3,2]]if wanted to insert the string 'pod' in list [0] before [1] in list [0] in M using the built in method insert How would I go about doing this? I've tried may List Comprehension possibilities but none of then worked. Below are some of the things I tried. >>> M=[[1,2,3], [3,2,1], [4,3,2]]>>> M.insert([1][1], 'pod')Traceback (most recent call last): File "", line 1, in M.insert([1][1], 'pod')IndexError: list index out of range>>> [row[0] for row in M.insert(1, 'pod')]Traceback (most recent call last): File "", line 1, in [row[0] for row in M.insert(1, 'pod')]TypeError: 'NoneType' object is not iterable>>> M.insert(1,'pod')>>> M[[1, 2, 3], 'pod', 'pod', [3, 2, 1], [4, 3, 2]]>>> M.insert[0](1,'pod')Traceback (most recent call last): File "", line 1, in M.insert[0](1,'pod')TypeError: 'builtin_function_or_method' object is unsubscriptableAny help is greatly appreciated! Thanks!-Raj . ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] eazy python question involving functions and parameters
-Original Message- >From: wesley chun >Sent: Sep 21, 2009 4:49 AM >To: tutor@python.org >Subject: Re: [Tutor] eazy python question involving functions and parameters > >>> Just think: 4 players left means that this is the semi final. >> >> What a brilliant answer! It tells him how to do it if he just stops and >> thinks but gives nothing away. I love it. :-) > >i agree with alan on this. in fact, i can just picture the brackets in >my head already. :-) Couldn't this be a king of the hill type of competition with winner of first contest takes on a remaining challenger and the winner of that takes on the last challenger? . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What language should I learn after Python?
-Original Message- >From: Dave Angel >Sent: Oct 7, 2009 12:47 AM >To: Mark Young >Cc: tutor@python.org >Subject: Re: [Tutor] What language should I learn after Python? > >> maybe I should try again, or maybe I'll try C. > >On the other hand, perhaps you should learn something that has >practically nothing in common with Python. Forth is at a different >extreme. The entire interpreter/compiler can be defined in maybe 50 >lines of (Forth) code. On dangerous ground here. I always felt Forth was more a religion than a computer language, hehe. . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PyGTK: is there a library for both Linux and Windows
-Original Message- >From: Chris Fuller >Sent: Oct 21, 2009 10:43 AM >To: tutor@python.org >Subject: Re: [Tutor] PyGTK: is there a library for both Linux and Windows > > >on differences: > >The downloads include binaries, so there have to be distinct files for Linux >and Windoze. If you download the same versions, there shouldn't be any >noticeable differences, with one big exception: multithreading and PyGTK >don't mix well on Windows. Your application might run perfectly (and look >correct) on Linux, but in Windoze it's a mess. You can find workarounds, but >I haven't come across one that looked reliable. If you have Python 2.6 or >higher, you can use the multiprocessing module (also available separately for >earlier versions) to emulate threads with processes, which will relieve the >problem, but make it a little harder for your threads (processes) to >communicate with each other. > >Cheers In a forum like this why do some presumably intelligent people insist on using insulting and derogatory terminology as above? Flame wars are ugly. . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Still having trouble with my game of life algorithm
-Original Message- >From: Matt Smith <[EMAIL PROTECTED]> >Sent: May 25, 2007 4:31 PM >To: Python Tutor >Subject: [Tutor] Still having trouble with my game of life algorithm > >Hi, > >First of all, thanks to everyone who helped with my last post >(http://mail.python.org/pipermail/tutor/2007-May/054360.html). I have >re-written the function that applies the rules but it still doesn't >return the expected result. I have been through it and corrected a >couple of bugs bet as far as I can tell it should return a matrix that >has had the rules of Conway's game of life >(http://en.wikipedia.org/wiki/Conway%27s_game_of_life) applied. Here is >my function: > >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 >for n in (x-1, x, x+1): >for m in (y-1, y, y+1): >try: >if matrix[m][n]: >if (n,m) != (x,y): >neighbour_count = neighbour_count + 1 >except IndexError: >pass ># Apply game of life rules to each item in the matrix >if neighbour_count < 2: >matrix_updated[y][x] = 0 >elif neighbour_count > 3: >matrix_updated[y][x] = 0 >elif neighbour_count == 3: >matrix_updated[y][x] = 1 ># No need to change value if neighbour count == 2 >return matrix_updated > >I have also attached the full program and the input file that I am using >for testing in case anyone is interested. The program does use curses to >display the board so I guess it won't be any good for Windows users. > >I hope someone can see where I am going wrong here. > >Thanks, > >Matt I am NOT an expert, and I have not studied your code very carefully, but I had a thought. If I understand Conway's rules, if an empty cell has exactly two neighbors, a new "live" cell is spawned. I don't see that you have done this, but it may be something subtle that I missed. ken oliver ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Ingenious script (IMO)
-Original Message- >From: Kent Johnson <[EMAIL PROTECTED]> >Sent: Aug 6, 2007 3:46 PM >To: Dick Moores <[EMAIL PROTECTED]> >Cc: Python Tutor List >Subject: Re: [Tutor] Ingenious script (IMO) > >Dick Moores wrote: >> At 10:16 AM 8/6/2007, Eric Brunson wrote: >> >> Your point about efficiency is well-taken. >> >>> def makechange( amount, denominations ): >>> >>> coins = {} >>> for d in denominations: >>> coins[d] = int( amount/d ) >>> amount = amount%d >>> >>> return coins >> >> OK, I used this this way: >> >> >> def makechange( amount, denominations ): >> >> coins = {} >> for d in denominations: >> coins[d] = int( amount/d ) >> amount = amount%d >> >> return coins >> >> denominations = (2000, 1000, 500, 100, 50, 25, 10, 5, 1) >> amount = 2218 >> print makechange(2218, denominations) >> == >> >> And get: >> {1: 3, 100: 2, 5: 1, 1000: 0, 10: 1, 2000: 1, 50: 0, 500: 0, 25: 0} >> >> That's the correct change: 3 pennies, 2 $1 bills, 1 nickel, no $10 >> bills, 1 dime, 1 $20 bill, no half-dollars, no $5 bills, no quarters. >> >> For amount = 3288: >> {1: 3, 100: 2, 5: 0, 1000: 1, 10: 1, 2000: 1, 50: 1, 500: 0, 25: 1} >> >> Why those weird orders? > >Dictionaries are not ordered. If you want to see it in order you could >sort the list of key, value pairs: >print sorted(makechange(2218, denominations).items(), reverse=True) > >Kent Do you have a clever, pythonic way to suppress the denominations with "zero" counts? Ken ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A fun puzzle
-Original Message- >From: Dick Moores <[EMAIL PROTECTED]> >Sent: Aug 24, 2007 4:30 PM >To: Python Tutor List >Subject: Re: [Tutor] A fun puzzle > >Dick Moores wrote: >>At 10:22 AM 8/24/2007, Kent Johnson wrote: >>>So you actually pasted that code into timeit.py? >>Yeah. :-( I think I learned on the Tutor list to do it that way, but >>I'm not sure. Thanks for showing me a correct way. > >I hope not! > >>>Using timeit more conventionally I get unsurprising results. This >>>program has output: >>>0.497083902359 >>>0.359513998032 >>> >>>which is more in line with what I would expect. >>Using your exact code, I just got >>0.737564690484 >>1.17399585702 >>Which is the reverse of your result, but on a slower computer. >>What's up with that?? > > >Kent, > >That result was gotten using Ulipad. Thought I'd try it at my command >line (several times, of course--I've reported what seemed to be >representative data). > >Using command line: >0.673447044247 >0.511676204657 > >Using IDLE: >0.845213567646 >0.685519807685 > >Using Wing Pro (executing with Alt+F5) >0.940486290855 >0.998467123615 > >Is it possible that the timeit module should be used only at the command line? > >Dick The IDLE numbers match those on my machine to within 0.001. For what it is worth. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sales tax
-Original Message- From: Ian Witham <[EMAIL PROTECTED]> Sent: Sep 18, 2007 11:39 PM To: Christopher Spears <[EMAIL PROTECTED]> Cc: tutor@python.org Subject: Re: [Tutor] sales tax As Michael points out, you need to explicitly use the round function, as the float formatting merely truncates anything after the second decimal place.I ran across a similar problem with the int() fuction early on. Anything after the decimal point is truncated, not rounded, leading to behavior I was not expecting. For example:int(-1.5) == -1int(-.5) == 0int(.5) == 0int(1.5) == 1Ian***Ian, You may well be aware of this already, but just in case...The behavior of the int function is not what I expected either. I was expecting something like the greatest integer function from mathematics.The floor() function of the math module has the behavior I expected.Ken ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sqrt on a variable
From: samir amassine <[EMAIL PROTECTED]> Subject: [Tutor] Sqrt on a variable hello, i can't seem to use the sqrt function on a variable, do you know how i can???i want to make the ABC formulaSamir**I am guessing a bit as to your needs, but you may try this:from math import sqrtIf by ABC formula you mean Pythagorean theorem tryc = sqrt(a**2 + b**2)Ken ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] wanting to learn
>Don't be like most and put off the super timple tutorials. I had a lot >of fun (after reading the Core python books out there) with the kids >tutorial because it was just fun to play around and learn some python >/ work with some python in the process. Honestly I didn't learn >anything because the core books taught me everything but if your brain >is on information overload then start here: > >http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/ This sounds interesting to me, but I have not been successful at downloading the text at the link above. The dreaded 404. Does anyone have the Windows version of the book or a suggestion as to where to download it? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] school physics/math courses
For a starting place, you may want to look at "Mathematics for the Digital Age and Programming in Python" by Maria and Gary Litvin. ISBN 978-0-9727055-8-5 Both authors are very helpful and often contribute to math and CS electronic discussion groups. Communications possible through information below: Skylight Publishing 9 Bartlet Street, Suite 70 Andover, MA 01810 web: http://www.skylit.com e-mail: [EMAIL PROTECTED] [EMAIL PROTECTED] -Original Message- >From: roberto <[EMAIL PROTECTED]> >Sent: Oct 16, 2008 7:15 AM >To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> >Cc: tutor@python.org >Subject: [Tutor] school physics/math courses > >hello >(i am rather new in python ...) > >i am about to start a course of physics and math for students aged >14-17 (high school) >and i am deeply interested in the possibilty of teaching fundamental >concepts of these subjects via teaching programming; >i chose python (i won't change my mind ...) > >so i am looking for resources on how to deal with these topics via >this great programming language; > >i need some help from you and moreover if you are aware of books >already covering these need > >thank you in advance >-- >roberto >OS: GNU/Linux, Debian >___ >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] cube root
-Original Message- >From: Andre Engels >Sent: Jan 19, 2009 7:22 AM >To: spir >Cc: tutor@python.org >Subject: Re: [Tutor] cube root > >On Mon, Jan 19, 2009 at 1:13 PM, spir wrote: >> Do you know any common algorithm to convert decimal (in the sense of >> fractional) decimals (in the sense of base 10 numbers) into binaries? >> >> 123.456 --> 011.bbb... >> and/or >> 123456 * 10**(-3) --> bbb... * 2**(-bbb...) >> >> How do python/C achieve that? > >There's probably more efficient methods, but a simple method to >convert a decimal fraction to a binary would be the following >(untested): > >def tobinary(n,precision=12) ># n is a number between 0 and 1 that should be converted, >precision is the number of binary digits to use. >assert 0.0 <= n < 1.0 >outcome = "0." >compare = 0.5 >for i in xrange(precision): >if n > compare: >outcome += "1" >n -= compare >if n == 0.0: break >else: >outcome += "0" >compare /= 2 >return outcome > >-- >André Engels, andreeng...@gmail.com I hope my memory serves. To convert decimal fraction into binary fraction, do the following repeatedly to the decimal until desired accuracy is achieved. Multiply by 2, if result is less than 1, next digit is 0 else next digit is 1 and you drop the whole number part of the result. Continue... .456 * 2 = .912(first digit is 0) .912 * 2 = 1.824 (next digit is 1) .824 * 2 = 1.648 (next digit is 1) .648 * 2 = 1.296 (next digit is 1) .296 * 2 = .592(next digit is 0) 0.456 ~ 0.01110 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] transforming an integer to a list of integers
Not an expert here, but I think I would first change it to a big string of 1000 chars and then pick off the chars one at a time and do int().-Original Message- From: "H.G. le Roy" Sent: Feb 3, 2009 10:17 AM To: tutor@python.org Subject: [Tutor] transforming an integer to a list of integers Hi,recently I learned about Project Euler (http://projecteuler.net/) and now I'm trying to work me through. At the moment I'm thinking about http://projecteuler.net/index.php?section=problems&id=8 One step for my solution should be transforming this big integer to a list of integers. I did:import mathbignr = 12345bignrs =[]for i in xrange(math.ceil(math.log10(bignr)): rem = bignr % 10 bignrs.append(rem) bignr /= 10However this "feels" a bit complicated, Do you know a better (more simple, nice etc.) way to do this?Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor