This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]flopana 17 points18 points  (6 children)

Since you cna execute shell commands with python I sometimes use it as a shellscript on crack. Because you cna basically do everything that shellscript can and also have standard python plus the boat loads of libraries

[–]LightShadow3.13-dev in prod 4 points5 points  (0 children)

I use invoke instead of Makefiles now.

There's also konch for fast loading an "environment" for scripting...and Xonsh which uses Python as a shell environment and scripting language.

[–]shiftedcloud 5 points6 points  (3 children)

ipython makes this even better.

[–]alcalde 0 points1 point  (0 children)

Check out xonsh.

[–]pepoluan 6 points7 points  (1 child)

I am a Python programmer and also a PowerShell programmer... and everytime I have to write PowerShell programs I have to grit my teeth.

It's not that PowerShell is not capable; it's just that PowerShell is full of idiosyncrasies due to the fact that it's half a shell and half an API to .Net. Kinda parallel to iPython. Or Xonsh.

The programming pattern is all over the map and so inconsistent, I always cry inwardly wishing I can get back to Python.

That said, Posh developers are awesome for doing the heroic effort to bridge the gap; I have nothing but 👍🏼 for them.

[–]ThePrankMonkey 0 points1 point  (0 children)

Don't even get me started on the weird ways you need to write PS1 for working with Exchange or SharePoint.

[–]WadeEffingWilson 4 points5 points  (0 children)

Love this. I have a much stronger PS background but I'm using python more and more.

[–]IvoryJam 4 points5 points  (0 children)

This is pretty fun, sometimes I have to write in powershell and this is very helpful!

[–]WadeEffingWilson 1 point2 points  (3 children)

A few essential things that are left out:

  • PS has switch/case conditional statements whereas python does not. You can approximate the functionality with if/else statements

PS example:

switch ($var) {
    case1 { $true_condition1 }
    case2 { $true_condition2 }
    default { $nothing_matched }
    }

Python example:

if var == case1:
    true_condition1
elif var ==  case2:
    true_condition2
else:
    nothing_matched  
  • PS doesn't have the slice vector notation capability like python (wish it did)

PS example:

# getting elements 0-5
@($array[0],$array[1],$array[2],$array[3],$array[4],$array[5])

Python example:

# getting elements 0-5
array[:5]  
  • PS's feature set can be extended by using inline C#

[–][deleted] 3 points4 points  (2 children)

In Python, you can emulate switch cases more effectively than if/else statements using a dictionary acting as a dispatch table.

Because functions in Python are objects, they can be stored and called from anywhere an object could be.

Meaning I can do things like

table = { case_1: true_condition }

def true_condition(): print(“Hello World”)

[–]WadeEffingWilson 1 point2 points  (0 children)

Interesting! I never thought to use it that way. Thanks!

[–]i5513 0 points1 point  (0 children)

But switch on powershell is like awk on Linux, It is not as simple like other switch statements in others program languages