I would like to know how I can write not only the 128 characters of ascci but also the characters of unicode in a txt file, I want to create the file and start writing, and then I want to reopen that file and continue writing below it.
Take into account that I need to copy the content of the file, that is, I should not see any, for example a
\n
but a line break,
and so on for each unicode character that you can enter Emphasis is not for a program to read it, it is to have the txt file and read it quietly from a notepad
def write_file(text, name_table):
file = open("llenado_tabla_" + name_table + ".txt","a")
file.write(text)
file.close()
def create_file(name_table, atributos):
file = open("llenado_tabla_" + name_tabla + ".txt","w")
file.write("-- Llenando tabla " + name_tabla + '\n')
file.write("INSERT INTO\n")
file.write(nombre_tabla + '(')
for i in range(len(atributos)):
if i == len(atributos) - 1:
file.write(atributos[i] + ') \n VALUES \n')
else:
file.write(atributos[i] + ',')
file.close()
When I try I get this error:
Traceback (most recent call last):
File "D:\Projects2.0\4to semestre\Bases de datos\creador_tablas.py", line 96, in <module>
main()
File "D:\Projects2.0\4to semestre\Bases de datos\creador_tablas.py", line 95, in main
introducir_registros(atributos, tipo_dato, cantidad_id, id_generado, nombre_tabla)
File "D:\Projects2.0\4to semestre\Bases de datos\creador_tablas.py", line 62, in introducir_registros
insertar_datos_txt(datos_tabla, False, nombre_tabla)
File "D:\Projects2.0\4to semestre\Bases de datos\creador_tablas.py", line 29, in insertar_datos_txt
escribe_fichero(texto, nombre_tabla)
File "D:\Projects2.0\4to semestre\Bases de datos\creador_tablas.py", line 3, in escribe_fichero
archivo.write(texto)
File "C:\Python39\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2212' in position 25: character maps to <undefined>