Problem writing JSON to file using PythonHow do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?Can comments be used in JSON?How can I pretty-print JSON in a shell script?Does Python have a ternary conditional operator?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How do I list all files of a directory?Does Python have a string 'contains' substring method?
Is the apartment I want to rent a scam?
How important is a good quality camera for good photography?
Why are angular mometum and angular velocity not necessarily parallel, but linear momentum and linear velocity are always parallel?
Can GPL and BSD licensed applications be used for government work?
How can I make sure my players' decisions have consequences?
Is there a published campaign where a missing artifact or a relic is creating trouble by its absence?
Very basic singly linked list
Is a normal-sized rug with the Animate Objects spell cast on it able to carry a person and fly?
Who has jurisdiction for a crime committed in an embassy?
Monty Hall Problem with a Fallible Monty
"I you already know": is this proper English?
What exactly makes a General Products hull nearly indestructible?
How can I create a shape in Illustrator which follows a path in descending order size?
Impact of throwing away fruit waste on a peak > 3200 m above a glacier
What is the purpose of the fuel shutoff valve?
What is "ass door"?
Why keep the bed heated after initial layer(s) with PLA (or PETG)?
Why did computer video outputs go from digital to analog, then back to digital?
What should I say when a company asks you why someone (a friend) who was fired left?
Where is this photo of a group of hikers taken? Is it really in the Ural?
How did C64 games handle music during gameplay?
Other than a swing wing, what types of variable geometry have flown?
kids pooling money for Lego League and taxes
What is a reasonable time for modern human society to adapt to dungeons?
Problem writing JSON to file using Python
How do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?Can comments be used in JSON?How can I pretty-print JSON in a shell script?Does Python have a ternary conditional operator?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?How do I list all files of a directory?Does Python have a string 'contains' substring method?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to write a JSON file to the file system using Python. When I go to read the file there's nothing there. I think I'm doing something else wrong.
This is my code:
today = datetime.today()
output_dir = "../../../json/iam"
output_file = output_dir + 'pol-aws-secrets-manager-' + user_name + today +'.json'
policy_doc = "blah":"blah"
with open(output_file, 'w+') as writer:
json.dump(policy_doc,writer)
What am I doing wrong?
python json
add a comment |
I am trying to write a JSON file to the file system using Python. When I go to read the file there's nothing there. I think I'm doing something else wrong.
This is my code:
today = datetime.today()
output_dir = "../../../json/iam"
output_file = output_dir + 'pol-aws-secrets-manager-' + user_name + today +'.json'
policy_doc = "blah":"blah"
with open(output_file, 'w+') as writer:
json.dump(policy_doc,writer)
What am I doing wrong?
python json
add a comment |
I am trying to write a JSON file to the file system using Python. When I go to read the file there's nothing there. I think I'm doing something else wrong.
This is my code:
today = datetime.today()
output_dir = "../../../json/iam"
output_file = output_dir + 'pol-aws-secrets-manager-' + user_name + today +'.json'
policy_doc = "blah":"blah"
with open(output_file, 'w+') as writer:
json.dump(policy_doc,writer)
What am I doing wrong?
python json
I am trying to write a JSON file to the file system using Python. When I go to read the file there's nothing there. I think I'm doing something else wrong.
This is my code:
today = datetime.today()
output_dir = "../../../json/iam"
output_file = output_dir + 'pol-aws-secrets-manager-' + user_name + today +'.json'
policy_doc = "blah":"blah"
with open(output_file, 'w+') as writer:
json.dump(policy_doc,writer)
What am I doing wrong?
python json
python json
edited Mar 26 at 15:59
Chris
64.1k18 gold badges132 silver badges125 bronze badges
64.1k18 gold badges132 silver badges125 bronze badges
asked Mar 26 at 15:49
bluethundrbluethundr
6625 gold badges19 silver badges44 bronze badges
6625 gold badges19 silver badges44 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Take a look in ../../../json/
for your files.
You're building your filenames by sticking strings together, which is very error prone. In this case you've forgotten a /
, so instead of getting files like
../../../json/iam/foo.json
you're getting files like
../../../json/iamfoo.json
A much safer strategy would be to use something like os.path
or pathlib
.
add a comment |
In addition to the response above. I tried your code and it created a file with "blah":"blah"
without any issues.
The problem could be in the path you specified.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361258%2fproblem-writing-json-to-file-using-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Take a look in ../../../json/
for your files.
You're building your filenames by sticking strings together, which is very error prone. In this case you've forgotten a /
, so instead of getting files like
../../../json/iam/foo.json
you're getting files like
../../../json/iamfoo.json
A much safer strategy would be to use something like os.path
or pathlib
.
add a comment |
Take a look in ../../../json/
for your files.
You're building your filenames by sticking strings together, which is very error prone. In this case you've forgotten a /
, so instead of getting files like
../../../json/iam/foo.json
you're getting files like
../../../json/iamfoo.json
A much safer strategy would be to use something like os.path
or pathlib
.
add a comment |
Take a look in ../../../json/
for your files.
You're building your filenames by sticking strings together, which is very error prone. In this case you've forgotten a /
, so instead of getting files like
../../../json/iam/foo.json
you're getting files like
../../../json/iamfoo.json
A much safer strategy would be to use something like os.path
or pathlib
.
Take a look in ../../../json/
for your files.
You're building your filenames by sticking strings together, which is very error prone. In this case you've forgotten a /
, so instead of getting files like
../../../json/iam/foo.json
you're getting files like
../../../json/iamfoo.json
A much safer strategy would be to use something like os.path
or pathlib
.
answered Mar 26 at 15:56
ChrisChris
64.1k18 gold badges132 silver badges125 bronze badges
64.1k18 gold badges132 silver badges125 bronze badges
add a comment |
add a comment |
In addition to the response above. I tried your code and it created a file with "blah":"blah"
without any issues.
The problem could be in the path you specified.
add a comment |
In addition to the response above. I tried your code and it created a file with "blah":"blah"
without any issues.
The problem could be in the path you specified.
add a comment |
In addition to the response above. I tried your code and it created a file with "blah":"blah"
without any issues.
The problem could be in the path you specified.
In addition to the response above. I tried your code and it created a file with "blah":"blah"
without any issues.
The problem could be in the path you specified.
answered Mar 26 at 15:58
IrekIrek
1129 bronze badges
1129 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361258%2fproblem-writing-json-to-file-using-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown