X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=functions.py;h=3472b77d411a60567df32abdc2f4df7f1aba0854;hb=refs%2Fheads%2F3.0;hp=da8fbae8348fc0763bc8cd69706af96794b45670;hpb=14ef9adbd80ca7e8ed9ee3f108858fa7d7c24d5b;p=iramuteq diff --git a/functions.py b/functions.py index da8fbae..4a9b857 100755 --- a/functions.py +++ b/functions.py @@ -50,7 +50,7 @@ def open_folder(folder): else: opener ="open" if sys.platform == "darwin" else "xdg-open" #call([opener, folder]) - call(["%s %s &" % (opener, folder)], shell=True) + call(["%s '%s' &" % (opener, folder)], shell=True) def normpath_win32(path) : if not sys.platform == 'win32' : @@ -83,13 +83,13 @@ class TGen : def write(self, path = None): if path is None : path = self.path - with open(path, 'w') as f : + with open(path, 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join([val] + self.tgen[val]) for val in self.tgen])) def writetable(self, pathout, tgens, totocc): etoiles = list(totocc.keys()) etoiles.sort() - with open(pathout, 'w') as f : + with open(pathout, 'w', encoding='utf8') as f : line = '\t'.join(['tgens'] + etoiles) + '\n' f.write(line) for t in tgens : @@ -369,7 +369,7 @@ class DoConf : if outfile is None : outfile = self.configfile outfile = normpath_win32(outfile) - with open(outfile, 'w') as f : + with open(outfile, 'w', encoding="utf-8") as f : f.write(txt) #self.conf.write(f) @@ -389,7 +389,7 @@ class DoConf : def write_tab(tab, fileout) : - csvWriter = csv.writer(open(fileout, 'w'), delimiter=';', quoting = csv.QUOTE_NONNUMERIC) + csvWriter = csv.writer(open(fileout, 'w', newline='', encoding='utf8'), delimiter=';', quoting = csv.QUOTE_NONNUMERIC) csvWriter.writerows(tab) class BugDialog(wx.Dialog): @@ -433,7 +433,7 @@ def CreateIraFile(DictPathOut, clusternb, corpname='corpus_name', section = 'ana AnalyseConf.set(section, 'clusternb', clusternb) AnalyseConf.set(section, 'corpus_name', corpname) - fileout = open(DictPathOut['ira'], 'w') + fileout = open(DictPathOut['ira'], 'w', encoding='utf8') AnalyseConf.write(fileout) fileout.close() @@ -516,10 +516,10 @@ def treat_line_alceste(i, line) : line[5] = str(float(line[5].replace(',', '.')))[0:7] return [i, int(line[0]), int(line[1]), float(line[2]), float(line[3]), line[6], line[4], line[5]] -def ReadProfileAsDico(File, Alceste=False, encoding = sys.getdefaultencoding()): +def ReadProfileAsDico(File, Alceste=False, encoding = 'utf8'): dictlem = {} print('lecture des profiles') - FileReader = codecs.open(File, 'r', encoding) + FileReader = open(File, 'r', encoding='utf8') Filecontent = FileReader.readlines() FileReader.close() DictProfile = {} @@ -679,7 +679,7 @@ def PlaySound(parent): print('pas de son') def ReadDicoAsDico(dicopath): - with codecs.open(dicopath, 'r', 'UTF8') as f: + with open(dicopath, 'r', encoding='UTF8') as f: content = f.readlines() lines = [line.rstrip('\n\r').replace('\n', '').replace('"', '').split('\t') for line in content if line != ''] return dict([[line[0], line[1:]] for line in lines]) @@ -696,9 +696,9 @@ def ReadLexique(parent, lang = 'french', filein = None): else : parent.lexique = ReadDicoAsDico(filein) -def ReadList(filein, encoding = sys.getdefaultencoding(), sep = ';'): +def ReadList(filein, encoding = 'utf8', sep = ';'): #file = open(filein) - with codecs.open(filein, 'r', encoding) as f : + with open(filein, 'r', encoding='utf8') as f : content = f.read() content = [line.replace('\n', '').replace('\r','').replace('\"', '').replace(',', '.').split(sep) for line in content.splitlines()] #file = codecs.open(filein, 'r', encoding) @@ -810,11 +810,12 @@ def launchcommand(mycommand): Popen(mycommand) def print_liste(filename,liste): - with open(filename,'w') as f : + with open(filename,'w', encoding='utf8') as f : for graph in liste : f.write(';'.join(graph) +'\n') -def read_list_file(filename, encoding = sys.getdefaultencoding()): - with codecs.open(filename,'r', encoding) as f: + +def read_list_file(filename, encoding = 'utf8'): + with open(filename,'r', encoding='utf8') as f: content=f.readlines() ncontent=[line.replace('\n','').split(';') for line in content if line.strip() != ''] return ncontent @@ -885,7 +886,7 @@ def doconcorde(corpus, uces, mots, uci = False) : def getallstcarac(corpus, analyse) : pathout = PathOut(analyse['ira']) - profils = ReadProfileAsDico(pathout['PROFILE_OUT'], Alceste, self.encoding) + profils = ReadProfileAsDico(pathout['PROFILE_OUT'], Alceste, 'utf8') print(profils) def read_chd(filein, fileout): @@ -1021,7 +1022,7 @@ def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 50) : def write_translation_profile(prof, lems, language, dictpathout) : if os.path.exists(dictpathout['translations.txt']) : - with codecs.open(dictpathout['translations.txt'], 'r', 'utf8') as f : + with open(dictpathout['translations.txt'], 'r', encoding='utf8') as f : translist = f.read() translist = [line.split('\t') for line in translist.splitlines()] else : @@ -1039,13 +1040,13 @@ def write_translation_profile(prof, lems, language, dictpathout) : elif line[0] == '*****' : rest[i] = ['*****','*','*', '*', '*', '*'] toprint += rest - with open(dictpathout['translation_profile_%s.csv' % language], 'w') as f : + with open(dictpathout['translation_profile_%s.csv' % language], 'w', encoding='utf8') as f : f.write('\n'.join([';'.join(line) for line in toprint])) - with open(dictpathout['translation_words_%s.csv' % language], 'w') as f : + with open(dictpathout['translation_words_%s.csv' % language], 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join([val, lems[val]]) for val in lems])) if 'translation_profile_%s.csv' % language not in [val[0] for val in translist] : translist.append(['translation_profile_%s.csv' % language, 'translation_words_%s.csv' % language]) - with open(dictpathout['translations.txt'], 'w') as f : + with open(dictpathout['translations.txt'], 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join(line) for line in translist])) def makesentidict(infile, language) :