2
I am having a problem regarding python b (Backspace), instead of deleting the previous character, it generates a "•" as the image below:
Follow the line of the code that generates this return:
#-*- coding: utf-8 -*-
import pyodbc
import platform
import json
#------------------------------------------------------#
local_arq = open("C:\Zabbix\prm2.txt", 'r') #Caminho do arquivo cujo encontra-se aa instancias
leitura = local_arq.readlines() #leitura das linhas do arquivo
varhost = platform.node()
x = 0 #var usada para separar os dados recebidos do TXT && Alterar o valor do hostname
y = 0
with open("test3.txt","w") as arq:
print('{"data": [')
for li in leitura:
count = li.split('--') #count = contador ele recebe os dados do TXT e separa eles onde tem o -
count[x].replace(" ", "") #Remove todos os espaços
for li2 in count:
hostname = varhost + '\\' + count[x]
con = pyodbc.connect("DRIVER={SQL Server};server="+hostname+";uid=sa;pwd=Ww1234567.")
query = con.cursor()
query.execute("SELECT name FROM SYSDATABASES")
for row in query:
#print(row)
print('{"{#INSTANCENAME}": "%s","{#DBNAME}": "%s"},' %(count[x], row[y]))
lol = ('{"{#INSTANCENAME}": "%s","{#DBNAME}": "%s"},' %(count[x], row[y]))
x = x + 1
print(lol + '\b]}')
y = y + 1
In case, I’m using b to erase that comma.
Thanks in advance!
NOTE: Python version 3.7
Actually this is the graphic character equivalent to ASCII 8, see here: https://upload.wikimedia.org/wikipedia/commons/f/f8/Codepage-437.png. It seems that you are saving the file to disk and not displaying ito on the screen, soon it is more practical you cut this character before printing instead of trying to "cut it" inside the file.
– Giovanni Nunes
How can I do that?
– user68537
Voc}and is subject to glaring errors already in line
open("C:\Zabbix\prm2.txt", 'r')
- precisely why the\
is escape prefix for some special characters - use either "/" forward - is compatible even in Windows, or a string with prefix "r" :open(r"C:\Zabbix\prm2.txt", 'r')
– jsbueno