What s the right way to concatenate files and appending the New Line character in Python Text or binary mode

0 votes

Trying to concatenate multiple files in a root to a single file. These are the problems I face:

  • When I've opened each textfile in text file mode the output file shows strange characters (gibberish)
  • When I've opened each textfile in binary mode the output file was corrected.

I'm using Python3 here, so what am I missing?

Nov 13, 2018 in Python by Nymeria
• 3,560 points

edited Dec 14, 2018 by Nymeria 1,665 views

1 answer to this question.

0 votes

It seems like you're using the wrong encoding for the file in this case. 

If you write a file in one encoding and read it in a different encoding, you will end up getting nonsensical characters made up of the same bytes being interpreted in the wrong way IMHO.

Hope this helps!

answered Nov 13, 2018 by Anirudh
• 2,090 points

edited Dec 14, 2018 by Anirudh

Related Questions In Python

–1 vote
2 answers
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 58,020 points
943 views
0 votes
1 answer

How to handle AssertionError in Python and find out which line or statement it occurred on?

Use the traceback module: import sys import traceback try: ...READ MORE

answered Dec 18, 2018 in Python by charlie_brown
• 7,720 points
5,693 views
0 votes
1 answer

What is the preferred way to concatenate strings in python??

If the strings you are concatenating are ...READ MORE

answered Dec 21, 2018 in Python by charlie_brown
• 7,720 points
819 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
11,027 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
2,534 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
108,828 views
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,350 points
4,611 views
0 votes
1 answer

How do I generate some random numbers with a distribution using Python?

scipy.stats.rv_discrete is what you ned IMHO. You can supply ...READ MORE

answered Oct 31, 2018 in Python by Anirudh
• 2,090 points

edited Dec 14, 2018 by Anirudh 1,462 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP