Pycharm Encoding Conflict

Whenever I run my code I am getting the notification saying

File was loaded in the wrong encoding: 'UTF-8'.

I have tried changing encoding several times, but apparently It does not happen to work. My 2 external txt. files work just fine, but the pickle one is the real struggle. I am hoping for finding some solution.. Thank you in advance. Below I am sharing all my code.

def arraynew():
        num1 = int(input("Select size of an array : "))
        value = []
        for i in range(num1):
            value.append(random.randint(1, 99))
        print("Sorting Array...")
        print("Average value is: ")
        print("Minumum value is: ")
        print("Maximum value is: ")

def saveData():
    file = open("newyear.txt", "wb")
    pickle.dump(arraynew(), file)
def loadData():
    file = open("newyear.txt",'rb')
    object_file = pickle.load(file)

1 answer

  • answered 2020-01-14 02:18 Shashwath Thiyagarajan

    If you have tried changing the encoding, it is probable that something is wrong on the IDE's side. I have used PyCharm's community edition before, and sometimes it just doesn't work great. For example, if I installed ANSIColors through pip AND/OR through the JetBrains server, it still displayed syntax errors. Usually, there is a simple fix that I tend to use. I create a new project and copy and paste the code from the old file to the new one. It can be a little gruesome if you have a lot of files. Also, one more thing to keep in mind is that you should set the encoding while creating a new project. I don't use PyCharm anymore, so I am not really the best person to ask, but if you have absolutely no other solution, you can go for it.