Load file, encoding ISO-8859-1 , encoding utf-8 python code

Load text from file to list:

def load_txt_file(p):
    klist = []
    with open(p) as fword:
        klist = fword.read().splitlines()
    return klist

Load text from file to list -encoding ISO-8859-1:

def load_txt_file_ISO(p):
    all_data = []
    with open(p, encoding = "ISO-8859-1") as fword:
        all_data = fword.read().splitlines()
    return all_data

Load text from file to list -encoding utf8:

def load_txt_file_utf8(p):
    all_data = []
    with open(p, encoding="utf-8") as fword:
        all_data = fword.read().splitlines()
    return all_data

Save list to file:

def save_list_to_file(xlist, xxpath):
    file1 = open(xxpath,"w")
    for i in xlist:
        file1.writelines("{}\n".format(i))
    file1.close()
    
Proudly powered by WordPress | Theme: Rits Blog by Crimson Themes.