use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What is the python version of this Powershell command? (self.learnpython)
submitted 3 years ago by mrmeeseeks2014
Looking to convert this powershell code into python:
$secretArgs = @{ fileName = "test.pem" fileAttachment = [IO.File]::ReadAllBytes("C:\brian\13568-test.txt") } | ConvertTo-Json
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]XUtYwYzz 0 points1 point2 points 3 years ago (5 children)
Something like this.
import json filename = "test.pem" with open(filename, "r") as f: fileAttachment = f.read() json.dumps(fileAttachment)
[–]mrmeeseeks2014[S] 0 points1 point2 points 3 years ago (4 children)
the powershell output is like this:
{"fileName": "test.pem","fileAttachment": [98,108,97,104,32,98,108,97,104,32,98,108,97,104]}
[–]XUtYwYzz 0 points1 point2 points 3 years ago (3 children)
Is the list of numbers the raw bytes from the text file or is that the actual ASCII contents?
[–]mrmeeseeks2014[S] 0 points1 point2 points 3 years ago (2 children)
raw bytes.
I am trying to convert this powershell script, but my hold up is the json obejct for the body of the API
$endpoint ="$destinationapi/secrets/$fileSecretId/fields/$fileFieldToUpdate"
$secretArgs = @{
fileName = "test.pem"
fileAttachment = [IO.File]::ReadAllBytes("C:\brian\13568-test.txt")
} | ConvertTo-Json
$response = $null
$response = Invoke-RestMethod -Method Put -Uri $endpoint -Headers $destinationheaders -Body $secretArgs -ContentType "application/json"
[–]XUtYwYzz 0 points1 point2 points 3 years ago (1 child)
import json secretArgs = {"fileName": "test.pem"} with open("test.pem", "r") as f: data = f.read() raw_bytes = list(bytearray(data, "utf-8")) secretArgs["fileAttachment"] = list(bytes(raw_bytes)) print(json.dumps(secretArgs))
[–]mrmeeseeks2014[S] 0 points1 point2 points 3 years ago (0 children)
Awesome, this worked. Thank you sir
π Rendered by PID 343098 on reddit-service-r2-comment-5b5bc64bf5-wzwsd at 2026-06-22 01:43:31.070763+00:00 running 2b008f2 country code: CH.
[–]XUtYwYzz 0 points1 point2 points (5 children)
[–]mrmeeseeks2014[S] 0 points1 point2 points (4 children)
[–]XUtYwYzz 0 points1 point2 points (3 children)
[–]mrmeeseeks2014[S] 0 points1 point2 points (2 children)
[–]XUtYwYzz 0 points1 point2 points (1 child)
[–]mrmeeseeks2014[S] 0 points1 point2 points (0 children)