Configure IPython to use powershell instead of cmd

后端 未结 3 837
青春惊慌失措
青春惊慌失措 2021-02-19 10:45

Searched for this, and couldn\'t seem to find anyone who\'d already asked, so here goes.

I\'m starting to switch over to IPython as my go-to shell on Windows 7, and I\'d

3条回答
  •  臣服心动
    2021-02-19 11:13

    The simplest way is to import os and update environment variable comspec in your Jupiter notebook or python shell

    import os
    os.environ['comspec']='powershell.exe'
    os.getenv('comspec')
    

    Then use following command.

    !gc log.txt | select -first 10 # head
    !gc -TotalCount 10 log.txt     # also head
    !gc log.txt | select -last 10  # tail
    !gc -Tail 10 log.txt           # also tail (since PSv3), also much faster than above option
    !gc log.txt | more             # or less if you have it installed
    !gc log.txt | %{ $_ -replace '\d+', '($0)' }         # sed
    

    and more at https://ss64.com/ps/

提交回复
热议问题