我正在读取一个文本文件以提取姓名和姓氏,但是如果python在其中找到“ enter”,则会中断换行。
例如,如果python找到姓Armenteros
,则第一行写Armenter
,然后换行,而第二行写os
:
发现:
Armenteros
返回:
Armenter
os
你能帮我吗?
df = pd.DataFrame(columns=('extension','empleado','mac_address','validado','neqt','ipv4_address','dominio','nodo'))
num_cs = 0
with open('/shared/scripts/01_extraccion.txt', 'r', encoding="utf8", errors='ignore') as file:
iloc_number = 0
for linea in file:
iloc_number = iloc_number + 1
if "Welcome to cpuanode" in linea:
nodo = linea[19:21]
if "------------------------------------------------IP couplers defined in domain " in linea:
dominio = linea[78:81].replace(" ","")
campos = linea.split("|")
if len(campos) > 10:
if "QMCDU" not in campos[1]:
extension = campos[1].strip()
empleado = campos[2].strip()
mac_address = campos[3].strip()
validado = campos[4].strip()
neqt = campos[5].strip()
ipv4_address = campos[7].strip()
dominio = dominio.strip()
nodo = nodo
print(extension,empleado,mac_address,validado,neqt,ipv4_address,dominio,nodo)
df = df.append([{'extension':extension,
'empleado':empleado,
'mac_address':mac_address,
'validado':validado,
'neqt':neqt,
'ipv4_address':ipv4_address,
'dominio':dominio,
'nodo':nodo}],
ignore_index=True)
print(df)
file.close()
谢谢。