0

I have seen a few questions on this topic but I wanted to check here for some clarification.

The basic problem is I have a script I am running it on a server and this line fails to run:

with open("Copy of normalized.log2.counts.csv") as bedR:

    line = bedR.readline()
    print(line.split(sep))

> UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range (128)

In this case sep = ",". When I run the following (essentially same) commands locally I get a valid result:

with open("Copy of normalized.log2.counts.csv") as bedR:

    line = bedR.readline()

    #get start col
    print(line.split(sep))

Since my PC is running Windows and the server is UNIX I suspect that there is some issue with translation.

*note I used dos2unix on both files before running the script and this appears to work so far, but I would love a solution that involves global settings that I can str within my python script if possible, or methods to encode the whole file from python.

Connorr.0
  • 97
  • 9
  • Does this answer your question? [Encoding gives "'ascii' codec can't encode character … ordinal not in range(128)"](https://stackoverflow.com/questions/2513027/encoding-gives-ascii-codec-cant-encode-character-ordinal-not-in-range128) – Makoto Dec 02 '19 at 21:30
  • This could work, I was hoping to avoid encode since I would prefer a solution that could be used all at once for the whole file, but it may be the way to go. – Connorr.0 Dec 02 '19 at 22:13
  • Might be worth taking a look at [this](https://stackoverflow.com/q/728891/4041795) – Montmons Dec 02 '19 at 22:27

0 Answers0