[Tutor] Iterating over sorted dictionary keys in one line
I know that one of the ways to iterate over sorted dictionary keys is: keylist = dictionary.keys() keylist.sort() for key in keylist: ... Is there a way to do this in a single line. Something like this would be ideal: for key in dictionary.keys().soft(): ... But this gives me following error: Traceback (most recent call last): File "", line 1, in ?TypeError: iteration over non-sequence I am guessing that this is because the sort method operates on a list in place and simply returns the 'None' value. Is there a way to do this in Python? Thanks, Marcin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Remaking Vim in Python (was Python Editors)
Ed, Before you dive into a full-fledged editor development project you might want to consider an existing extendible platform like Eclipse. It is much more than just an editor, i.e. it is an advanced IDE platform. The sweet thing is that it allows for developing plugins to add functionality. I have not tried it, but someone already developed a vi input mode plugin for it. Cheers, Marcin - Original Message - From: "Kent Johnson" <[EMAIL PROTECTED]> Cc: Sent: Friday, September 23, 2005 9:52 AM Subject: Re: [Tutor] Remaking Vim in Python (was Python Editors) > Ed Singleton wrote: >> I'd like a little advice on whether I'm being really stupid here. >> >> Having researched editors and stuff, I've not quite found what I'm >> looking for, though Vim comes close (except that it's extremely >> difficult to work out what to do with it). >> >> My instinct was to try and write a small program similar to vim, but >> in Python. The very basics should be quite easy. If I start a system >> that is very easily expandable then as and when I need further >> functionality I can add it in. >> >> I know it would be ambitious to try and do this, but is it stupidly >> ambitious? > > You might consider starting from one of the existing editors written in > Python, e.g. IDLE, eric3, spe, DrPython, scite and modifying it to suit. > Writing an editor is a big project. OTOH most of these editors probably > started out with some developer scratching an itch. So I'm not sure I > would call it stupidly ambitious... > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] 'print' without newline or space appended
Hello, This statement: for c in 'hello': print c will generate following output: h e l l o and by adding comma at the end of the print statement: for c in 'hello': print c, we get this output: h e l l o How do I output something using 'print' such that there is no new line or space appended at the end of the output. Hehe... just answered my own question: import sys for c in 'hello' : sys.stdout.write(c) Is this the way to do it or is there a more appropriate approach. Thanks, Marcin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'print' without newline or space appended
Thanks, This is the other 'work around'. I take there is no way to tell 'print' to do it, correct? Marcin - Original Message - From: "R. Alan Monroe" <[EMAIL PROTECTED]> To: "python-tutor" Sent: Sunday, September 25, 2005 10:29 AM Subject: Re: [Tutor] 'print' without newline or space appended >> Hello, > >> This statement: >> for c in 'hello': print c >> will generate following output: >> h >> e >> l >> l >> o >> and by adding comma at the end of the print statement: >> for c in 'hello': print c, >> we get this output: >> h e l l o >> How do I output something using 'print' such that there is no new line or >> space appended at the end of the output. > >> > >> Hehe... just answered my own question: >> import sys >> for c in 'hello' : sys.stdout.write(c) >> Is this the way to do it or is there a more appropriate approach. > > Also > > outstring = '' > for c in 'hello': >outstring += c > print outstring > > ___ > 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] Console output
- Original Message - From: "Roel Schroeven" <[EMAIL PROTECTED]> To: Sent: Wednesday, October 05, 2005 2:53 PM Subject: Re: [Tutor] Console output > Oliver Maunder wrote: >> Does anyone know how I can update a line of console output without >> creating a new line? I'm not explaning this too well, so here's an >> example. >> >> When you download a file with wget, the console display looks like this: >> >> 14% [===>] >> 344,192 16.28K/sETA 02:19 >> >> All the figures and the progress bar get continously updated. The only >> way I know of sending output to the console is to use print or >> sys.stdout.write(), but that would give me: >> 14% [===>] >> 344,192 16.28K/sETA 02:19 >> 18% [=> ] >> 344,192 16.28K/sETA 02:19 >> 20% [>] >> 344,192 16.28K/sETA 02:19 >> >> ...and that's really not what I'm after! >> >> Any help and ideas would be appreciated > > You need to: > - not write a newline > - backup to the beginning of the line > > Simple example: > > import sys > import time > > def progress(n): >for i in range(n+1): >sys.stdout.write('\r%3s%% [%s>%s]' % (i, '='*i, ' '*(n-i))) >sys.stdout.flush() >time.sleep(0.5) > > progress(60) > This works nicely, but do not forget that \r does not clear what you already have on the line, so you are safe if every time you re-write the line, you output the same number of characters, but if it is less, you will have residual from previous line. The way around it is to output a line of spaces that overwrites the previous line. > No newline is written, and the program backs up to the beginning of the > line using carriage return, '\r'. You can also put the carriage return > at the end of the line; the difference is that the cursor will be left > at the beginning of the line instead of at the end. > > It's also possible to back up using backspaces ('\b'), but then you need > to count how many characters you wrote and use the equal amount of > backslashes. > > -- > If I have been able to see further, it was only because I stood > on the shoulders of giants. -- Isaac Newton > > Roel Schroeven > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Raw image display in a GUI window
Hello, I want to use Python to do some experimentation with graphic processing/manipulation, and I am looking for a way to be able to manipulate individual pixels of the image, as well as display it in a GUI. Ideal image representation would be something of the form of a two-dimensional array of tuples, each tuple containing the Red, Green and Blue components. I have looked at Tk and Tkinter, and there is a PhotoImage class that can define an image which can than be displayed in a Canvas widget, but the PhotoImage class seams to be doing a lot of extra work on the image, including gamma correction, etc. I am interested in being able to display exactly the pixel values I set. Thank You all in advance, Marcin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Raw image display in a GUI window
Thanks Alex, Do you know if I can find somewhere sample code that would, lets say, create a 100x100 image and display it? Thanks, Marcin - Original Message - From: "Alex Hunsley" <[EMAIL PROTECTED]> To: "Marcin Komorowski" <[EMAIL PROTECTED]> Cc: "python-tutor" Sent: Tuesday, November 08, 2005 10:32 AM Subject: Re: [Tutor] Raw image display in a GUI window > Marcin Komorowski wrote: > >>Hello, >> >>I want to use Python to do some experimentation with graphic >>processing/manipulation, and I am looking for a way to be able to >>manipulate individual pixels of the image, as well as display it in a GUI. >>Ideal image representation would be something of the form of a >>two-dimensional array of tuples, each tuple containing the Red, Green and >>Blue components. >> >>I have looked at Tk and Tkinter, and there is a PhotoImage class that can >>define an image which can than be displayed in a Canvas widget, but the >>PhotoImage class seams to be doing a lot of extra work on the image, >>including gamma correction, etc. I am interested in being able to display >>exactly the pixel values I set. >> >>Thank You all in advance, >>Marcin > How about PyUI? > http://pyui.sourceforge.net/ > It may do what you're looking for... > alex > >> >>___ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> >> >> > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor