How to append something to a new line in a excel file?
Hey I am using easygui and appending the user input to a excel (csv file). However the userinput will continuously append to the same line, and not the next line.
Here is my code :
#Adding a User
msg = 'Adding your information'
title = 'Uk Users'
box_names = ["Email" , "Password"]
box_values = (easygui.multpasswordbox(msg, title, box_names,))
while box_values[0] == '' or box_values[1] == '':
msg = 'Try again'
title = 'you missed a box, please try again!'
box_names_1 = ["Email" , "Password"]
box_values = str(easygui.multpasswordbox(msg, title, box_names_1))
#How to make it repeat?
else:
for i in range(len(box_values)):
box_values = str(box_values)
f = open('USERS.csv' , 'a') #'a' is for appending
f.write(box_values) #How to add something to a new line?
python file append
add a comment |
Hey I am using easygui and appending the user input to a excel (csv file). However the userinput will continuously append to the same line, and not the next line.
Here is my code :
#Adding a User
msg = 'Adding your information'
title = 'Uk Users'
box_names = ["Email" , "Password"]
box_values = (easygui.multpasswordbox(msg, title, box_names,))
while box_values[0] == '' or box_values[1] == '':
msg = 'Try again'
title = 'you missed a box, please try again!'
box_names_1 = ["Email" , "Password"]
box_values = str(easygui.multpasswordbox(msg, title, box_names_1))
#How to make it repeat?
else:
for i in range(len(box_values)):
box_values = str(box_values)
f = open('USERS.csv' , 'a') #'a' is for appending
f.write(box_values) #How to add something to a new line?
python file append
You could use thecsv
library from python and use thewriterow
method there.
– toti08
Nov 19 '18 at 14:42
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43
add a comment |
Hey I am using easygui and appending the user input to a excel (csv file). However the userinput will continuously append to the same line, and not the next line.
Here is my code :
#Adding a User
msg = 'Adding your information'
title = 'Uk Users'
box_names = ["Email" , "Password"]
box_values = (easygui.multpasswordbox(msg, title, box_names,))
while box_values[0] == '' or box_values[1] == '':
msg = 'Try again'
title = 'you missed a box, please try again!'
box_names_1 = ["Email" , "Password"]
box_values = str(easygui.multpasswordbox(msg, title, box_names_1))
#How to make it repeat?
else:
for i in range(len(box_values)):
box_values = str(box_values)
f = open('USERS.csv' , 'a') #'a' is for appending
f.write(box_values) #How to add something to a new line?
python file append
Hey I am using easygui and appending the user input to a excel (csv file). However the userinput will continuously append to the same line, and not the next line.
Here is my code :
#Adding a User
msg = 'Adding your information'
title = 'Uk Users'
box_names = ["Email" , "Password"]
box_values = (easygui.multpasswordbox(msg, title, box_names,))
while box_values[0] == '' or box_values[1] == '':
msg = 'Try again'
title = 'you missed a box, please try again!'
box_names_1 = ["Email" , "Password"]
box_values = str(easygui.multpasswordbox(msg, title, box_names_1))
#How to make it repeat?
else:
for i in range(len(box_values)):
box_values = str(box_values)
f = open('USERS.csv' , 'a') #'a' is for appending
f.write(box_values) #How to add something to a new line?
python file append
python file append
asked Nov 19 '18 at 14:35
Beni billhardtBeni billhardt
31
31
You could use thecsv
library from python and use thewriterow
method there.
– toti08
Nov 19 '18 at 14:42
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43
add a comment |
You could use thecsv
library from python and use thewriterow
method there.
– toti08
Nov 19 '18 at 14:42
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43
You could use the
csv
library from python and use the writerow
method there.– toti08
Nov 19 '18 at 14:42
You could use the
csv
library from python and use the writerow
method there.– toti08
Nov 19 '18 at 14:42
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43
add a comment |
1 Answer
1
active
oldest
votes
You could use the csv library, defining a Writer
object to write to your file. So you would need to replace the else statement with something like that:
else:
with open('USERS.csv', 'a', newline = '') as csvFile:
csvWriter = csv.writer(csvFile, delimiter = ',')
csvWriter.writerow(box_values)
The writerow
method will automatically put your new data into a new row. Also you don't need to explicitly convert your data to string.
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameternewline=''
. I'll update my answer.
– toti08
Nov 20 '18 at 7:19
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%2f53376874%2fhow-to-append-something-to-a-new-line-in-a-excel-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use the csv library, defining a Writer
object to write to your file. So you would need to replace the else statement with something like that:
else:
with open('USERS.csv', 'a', newline = '') as csvFile:
csvWriter = csv.writer(csvFile, delimiter = ',')
csvWriter.writerow(box_values)
The writerow
method will automatically put your new data into a new row. Also you don't need to explicitly convert your data to string.
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameternewline=''
. I'll update my answer.
– toti08
Nov 20 '18 at 7:19
add a comment |
You could use the csv library, defining a Writer
object to write to your file. So you would need to replace the else statement with something like that:
else:
with open('USERS.csv', 'a', newline = '') as csvFile:
csvWriter = csv.writer(csvFile, delimiter = ',')
csvWriter.writerow(box_values)
The writerow
method will automatically put your new data into a new row. Also you don't need to explicitly convert your data to string.
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameternewline=''
. I'll update my answer.
– toti08
Nov 20 '18 at 7:19
add a comment |
You could use the csv library, defining a Writer
object to write to your file. So you would need to replace the else statement with something like that:
else:
with open('USERS.csv', 'a', newline = '') as csvFile:
csvWriter = csv.writer(csvFile, delimiter = ',')
csvWriter.writerow(box_values)
The writerow
method will automatically put your new data into a new row. Also you don't need to explicitly convert your data to string.
You could use the csv library, defining a Writer
object to write to your file. So you would need to replace the else statement with something like that:
else:
with open('USERS.csv', 'a', newline = '') as csvFile:
csvWriter = csv.writer(csvFile, delimiter = ',')
csvWriter.writerow(box_values)
The writerow
method will automatically put your new data into a new row. Also you don't need to explicitly convert your data to string.
edited Nov 20 '18 at 7:20
answered Nov 19 '18 at 14:52
toti08toti08
1,77941623
1,77941623
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameternewline=''
. I'll update my answer.
– toti08
Nov 20 '18 at 7:19
add a comment |
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameternewline=''
. I'll update my answer.
– toti08
Nov 20 '18 at 7:19
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
Thanks, that does work although it does skip a line in the excel file, it is a lot better than what I had before.
– Beni billhardt
Nov 20 '18 at 2:16
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameter
newline=''
. I'll update my answer.– toti08
Nov 20 '18 at 7:19
@Benibillhardt right. Then in order to address that problem you should open the file specifying the parameter
newline=''
. I'll update my answer.– toti08
Nov 20 '18 at 7:19
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%2f53376874%2fhow-to-append-something-to-a-new-line-in-a-excel-file%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
You could use the
csv
library from python and use thewriterow
method there.– toti08
Nov 19 '18 at 14:42
Duplicate of How do you append to a file??
– bene
Nov 19 '18 at 14:43