![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Array Slicing - Powershell compared to Python Hi, I guess this is a question for the Powershell team. When comparing array slicing with for example Python, I find that Powershell does not support doing what i most often use slicing for, ie "Get all but the first/last n items". In python you can write somelist[:-3] to get all but the last three (and the empty list if there are less than three elements in the list) In powershell you have to write: if ($somelist.Length -gt 3){ @() } else { $somelist[0..($somelist.Length -4)] } I would be quite hard pressed to call the Powershell way more elegant. Are there any plans for vNext to improve this area? Regards, /Staffan |
| | #2 (permalink) |
| Guest | Re: Array Slicing - Powershell compared to Python Howdy Staffan! I have 2 thoughts on this: 1) We have a really big list of amazing features we'd like to get implemented in Vnext and are in the process of deciding which ones we won't do (to ship is to choose). This doesn't "pop" as a compelling feature to me. 2) We are very customer driven. The fact that you've asked about it means a lot. Please submit this as a request via Connect and then other people can vote on it. We don't have the bandwidth to implement all feature requests but we do have bandwidth to implement some of the ones that the community asks for the most. Thanks for asking! -- Jeffrey Snover [MSFT] Windows Management Partner Architect Microsoft Corporation This posting is provided "AS IS" with no warranties, no confers rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx |
| | #3 (permalink) |
| Guest | Re: Array Slicing - Powershell compared to Python You could do this with type extensions (I posted about this example on my blog here: http://www.aaronlerch.com/blog/2007/...xtensions.html) In this case, something like this should work: <Types> <Type> <Name>System.Array</Name> <Members> <ScriptMethod> <Name>Slice</Name> <Script> if ($args[0] -eq $null) { $start = 0 } elseif ($args[0] -lt 0) { $start = $this.Length + [int]$args[0] } elseif ($args[0] -ge 0) { $start = [int]$args[0] } if ($args[1] -eq $null) { $end = $this.Length - 1 } elseif ($args[1] -lt 0) { $end = $this.Length + [int]$args[1] - 1 } elseif ($args[1] -ge 0) { $end = [int]$args[1] - 1 } if ($start -lt 0) { $start = 0 } elseif ($start -gt $this.Length) { return @() } if ($end -gt $this.Length) { $end = $this.Length } elseif ($end -lt 0) { return @() } if ($start -ge $end) { return @() } else { return $this[$start..$end] } </Script> </ScriptMethod> </Members> </Type> </Types> On May 5, 12:11 pm, "Jeffrey Snover [MSFT]" <jsno...@microsoft.com> wrote: > Howdy Staffan! > I have 2 thoughts on this: > 1) We have a really big list of amazing features we'd like to get > implemented in Vnext and are in the process of deciding which ones we won't > do (to ship is to choose). This doesn't "pop" as a compelling feature to > me. > > 2) We are very customer driven. The fact that you've asked about it means a > lot. Please submit this as a request via Connect and then other people can > vote on it. We don't have the bandwidth to implement all feature requests > but we do have bandwidth to implement some of the ones that the community > asks for the most. > > Thanks for asking! > -- > Jeffrey Snover [MSFT] > Windows Management Partner Architect > Microsoft Corporation > This posting is provided "AS IS" with no warranties, no confers rights. > Visit the Windows PowerShell Team blog at:http://blogs.msdn.com/PowerShell > Visit the Windows PowerShell ScriptCenter at:http://www.microsoft.com/technet/scr.../hubs/msh.mspx |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PowerShell param array | Daniel Jameson | PowerShell | 2 | 1 Week Ago 11:47 PM |
| Re: Running python scripts under PowerShell | Marco Shaw | PowerShell | 0 | 09-24-2007 11:11 AM |
| Re: Running python scripts under PowerShell | Brandon Shell | PowerShell | 0 | 09-24-2007 10:48 AM |
| how to assign values to array and how to create array via variable | Frank | PowerShell | 1 | 03-13-2007 05:18 PM |
| Using a WMI string array in Powershell | GordT. | PowerShell | 1 | 01-11-2007 12:33 PM |