I want add some powershell code in python,but meet '%{0}'in powershell when I use format function,then can't compile python.So I want to know the mean to change my code
Asked
Active
Viewed 675 times
1 Answers
0
The double dot ..
is a range constructor. 0..65535
will return an array of integers from 0 to 65535. The percent sign after a pipe |%
is shorthand for foreach-object
after the pipe.
In this case, your powershell function
[byte[]]$bytes = 0..65535|%{0}
Creates an array called bytes
of type byte
that has 65536 zeros for its values.
If you are trying to call this from Python using the string format
function, then your will need to escape the curly brackets by doubling them. For instance, if you wanted to use Python to adjust the variable name, you would use:
# in Python:
powershell_cmd = '[byte[]]${} = 0..65535|%{{0}}'.format('bytes')

James
- 32,991
- 4
- 47
- 70
-
Thanks for your answer,I change my powershellcode as [byte[]]$bt=0..65535|%{{0}},but powershellcode seem don't have the same mean as before and get the wrong result – user8910954 Nov 09 '17 at 03:51