Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > do you master list comprehensions?

Reply
Thread Tools

do you master list comprehensions?

 
 
Keith Dart
Guest
Posts: n/a
 
      12-17-2004
Fernando Perez wrote:

> <blatant plug>
>
> You might want to look at ipython:
>
> http://ipython.scipy.org,
>
>
> </blatant plug>
>


I did just recently install that. It looks very nice. Would make a great
interactive prompt for an IDE, as well.



--
\/ \/
(O O)
-- --------------------oOOo~(_)~oOOo----------------------------------------
Keith Dart <(E-Mail Removed)>
vcard: <http://www.kdart.com/~kdart/kdart.vcf>
public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key>
================================================== ==========================
 
Reply With Quote
 
 
 
 
aleks90210@hotmail.com
Guest
Posts: n/a
 
      12-17-2004
Thought you might enjoy my super-small flatten function: (though google
groups seems to be munging my whitespace today)

def flatten(d):
"flatten([[[1,[2,3],[4,5]],6],[7]])==[1,2,3,4,5,6,7]"
return reduce(lambda a,b:a+b,[(type(x) in (list, tuple) \
and flatten(x) or [x]) for x in d])

 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      12-17-2004
Steven Bethard wrote:
> Very cool. I didn't know about this. Does anyone know how to make it
> work with Pythonwin[1]? (Obviously, I can type the above in manually
> every time, but I'd much rather have Pythonwin do this automatically for
> me.)
>
> Steve
>
> [1] I'd do my example code at the command prompt, but I can't live
> without copy-paste.


You can copy and paste from a Windows command prompt. It's a bit bizarre, but
- In the system menu for a command window, pick Properties
- On the Options tab, turn on Quick Edit mode
- Now you can copy and paste with right-click (!). If you have text selected, right-click will copy,
otherwise paste. It's a bit strange but it works.

I think it's wonderfully ironic that in Windows - which takes such pains to make everything keyboard
accessible - in a *command line* window, which is using keyboard input by its nature - you have to
use the mouse for copy and paste!!

Kent
 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      12-17-2004
Kent Johnson wrote:
> You can copy and paste from a Windows command prompt. It's a bit
> bizarre, but
> - In the system menu for a command window, pick Properties
> - On the Options tab, turn on Quick Edit mode
> - Now you can copy and paste with right-click (!). If you have text
> selected, right-click will copy, otherwise paste. It's a bit strange but
> it works.


Yeah, I'm familiar with this -- all my command windows are enabled with
Quick Edit. =) The problem is that I can't then edit what I've
copy-pasted. I can, of course, copy a few lines, type in an edited
line, copy a few more lines, type in another edited line, etc., but this
gets tedious...

Sorry about not being clear about my problem!

STeve
 
Reply With Quote
 
Fernando Perez
Guest
Posts: n/a
 
      12-17-2004
Keith Dart wrote:

> Fernando Perez wrote:
>
>> <blatant plug>
>>
>> You might want to look at ipython:
>>
>> http://ipython.scipy.org,
>>
>>
>> </blatant plug>
>>

>
> I did just recently install that. It looks very nice. Would make a great
> interactive prompt for an IDE, as well.


Glad you like it And yes, there are plans to clean it up so it can be
easily embedded into a full-blown IDE (as well as remaining available for
regular command-line use). This keeps on getting delayed by inevitable bug
fixes and my very limited time, but it will happen...

Best,

f

 
Reply With Quote
 
Bengt Richter
Guest
Posts: n/a
 
      12-18-2004
On Fri, 17 Dec 2004 08:03:12 -0500, Kent Johnson <(E-Mail Removed)> wrote:

>Steven Bethard wrote:
>> Very cool. I didn't know about this. Does anyone know how to make it
>> work with Pythonwin[1]? (Obviously, I can type the above in manually
>> every time, but I'd much rather have Pythonwin do this automatically for
>> me.)
>>
>> Steve
>>
>> [1] I'd do my example code at the command prompt, but I can't live
>> without copy-paste.

>
>You can copy and paste from a Windows command prompt. It's a bit bizarre, but
>- In the system menu for a command window, pick Properties
>- On the Options tab, turn on Quick Edit mode
>- Now you can copy and paste with right-click (!). If you have text selected, right-click will copy,
>otherwise paste. It's a bit strange but it works.
>
>I think it's wonderfully ironic that in Windows - which takes such pains to make everything keyboard
>accessible - in a *command line* window, which is using keyboard input by its nature - you have to
>use the mouse for copy and paste!!
>

Not true on NT4 at least:

Alt-Spacebar gets you the system menu
Follow with e then k which gets you in select mode

use arrow keys to move to top left of a box, or whole screen
(if there's more buffer than screen, arrows should cause scrolling
to access more)

hold shift key down and use arrow keys while continuing to hold
the shift key down to select a box of text (need not be at edges)
this can also scroll through buffer as necessary to select more than can
be visible at one time. Just keep holding down shift.

press enter to capture box of text to clipboard

paste as usual with ctrl-v ins some apps, shift-insert in vim (depending),
or paste back into the dos window with Alt-spacebar e p

Regards,
Bengt Richter
 
Reply With Quote
 
Scott David Daniels
Guest
Posts: n/a
 
      12-20-2004
Bengt Richter wrote:
> Not true on NT4 at least:
> Alt-Spacebar gets you the system menu ....
> paste into the dos window with Alt-spacebar e p

Thanks immensely for this -- I love it.

--Scott David Daniels
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Steven Bethard
Guest
Posts: n/a
 
      12-27-2004
I wrote:
> Kent Johnson wrote:
>
>> You can do the same thing using a PYTHONSTARTUP file - see
>> http://docs.python.org/tut/node4.htm...00000000000000
>>
>> You can change the prompts with
>> import sys
>> sys.ps1 = ' >>> '
>> sys.ps2 = ' ... '

>
>
> Very cool. I didn't know about this. Does anyone know how to make it
> work with Pythonwin[1]?


Solved my own problem here. For anyone else out there using PythonWin,
the solution that worked for me is to put the following (or whatever
customizations you want) in a sitecustomize.py somewhere on my PYTHONPATH:

import sys
sys.ps1 = 'py> '
sys.ps2 = '... '

PythonWin (as well as my Command Prompt python) now has the above prompts.

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2nd Post: VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue... Sam ASP .Net 1 07-20-2006 06:17 PM
VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue... Sam ASP .Net 0 07-20-2006 02:31 AM
Cross Page Post Back When Using Mixture of Master Pages and Non-Master Pages Jason@webbit.com ASP .Net 1 05-16-2006 02:00 PM
Master Pages Great! But what about Master User Controls? Electrified Research ASP .Net 5 10-11-2005 02:32 PM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments