Jump to content
Twiff

Stergere linie dupa scriere PYTHON

Recommended Posts

Posted

Deci am urmatorul cod :

def esl():
return random.choice(list(open('plex.txt')))

def czr():
user = {
"raa": esl(),
"maa": randomword(5)+'-da',
"taa": '0'+str(random.randint(300000000, 560000000))
}

browser.find_element_by_css_selector('#da').send_keys(user['raa'])
browser.find_element_by_css_selector('#da1').send_keys(user['raa'])
browser.find_element_by_css_selector('#da2').send_keys(user['raa'])

ciorap = "%s%s%s%s%s" % (user['raa'],'|',user["maa"],'|',user["taa"])

f = open('zc.txt', 'a')
f.write(ciorap+"\n")
f.close()

Vreau ca dupa ce se scrie 'user['raa']' in "zc.txt" sa il stearga din "plex.txt" . Ma tot chinui s-a fac asta dar nu prea am idee cum as putea face asta. Ideei ?

  • Upvote 1
Posted (edited)

Poti liniile ce le vrei sterse sa le memorezi intr-un array, apoi fisierul tau ce il vrei rescris, il deschizi si parcurgi linie cu linie ca sa scrii in alt fisier continutul fara liniile ce le vrei scoase (care le-ai memorat cum am zis in array).

Deschizi fisieru vechi citire linie cu linie, la fiecare linie verifici daca nu cumva aceasta exista in array, daca exista nu o scrii in cel nou, altfel o scrii in cel nou (acela fiind deschis cu append).

La final fisierul tau nou va avea continutul celui vechi fara liniile pe care le vrei scoase.

E doar o idee, evident sunt implementari mai rapide etc, chiar si threaded de preferat daca ai fisiere mari.

Edited by Gio33

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...