csv to txt in python [duplicate]
This question already has an answer here:
How do I copy a file in Python?
14 answers
I have multiple .csv files in the fodler and I need to convert them to .txt files. Currently I am able just to rename them, but I want to leave the original files in place
import os,sys
folder = 'C:....'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.csv', '.txt')
output = os.rename(infilename, newname)
python csv
marked as duplicate by Josh J, Ankit Jaiswal, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 15:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I copy a file in Python?
14 answers
I have multiple .csv files in the fodler and I need to convert them to .txt files. Currently I am able just to rename them, but I want to leave the original files in place
import os,sys
folder = 'C:....'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.csv', '.txt')
output = os.rename(infilename, newname)
python csv
marked as duplicate by Josh J, Ankit Jaiswal, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 15:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09
add a comment |
This question already has an answer here:
How do I copy a file in Python?
14 answers
I have multiple .csv files in the fodler and I need to convert them to .txt files. Currently I am able just to rename them, but I want to leave the original files in place
import os,sys
folder = 'C:....'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.csv', '.txt')
output = os.rename(infilename, newname)
python csv
This question already has an answer here:
How do I copy a file in Python?
14 answers
I have multiple .csv files in the fodler and I need to convert them to .txt files. Currently I am able just to rename them, but I want to leave the original files in place
import os,sys
folder = 'C:....'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.csv', '.txt')
output = os.rename(infilename, newname)
This question already has an answer here:
How do I copy a file in Python?
14 answers
python csv
python csv
asked Nov 15 '18 at 10:53
Kamran AbbasovKamran Abbasov
246
246
marked as duplicate by Josh J, Ankit Jaiswal, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 15:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Josh J, Ankit Jaiswal, jpp
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 15:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09
add a comment |
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09
add a comment |
1 Answer
1
active
oldest
votes
You can use the copyfile of shutil.
import shutil
....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the copyfile of shutil.
import shutil
....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
add a comment |
You can use the copyfile of shutil.
import shutil
....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
add a comment |
You can use the copyfile of shutil.
import shutil
....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
You can use the copyfile of shutil.
import shutil
....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
answered Nov 15 '18 at 11:02
Niels HenkensNiels Henkens
724517
724517
add a comment |
add a comment |
Do you just want to change the file-extension, or do you also want to change the content of the csv?
– Niels Henkens
Nov 15 '18 at 10:55
Copy file then rename the copy. stackoverflow.com/questions/123198/…
– Josh J
Nov 15 '18 at 10:57
What do you want to achieve? You are just making another copy with '.txt' extension.
– Ankit Jaiswal
Nov 15 '18 at 11:09