Python Forum

Full Version: I have a problem saving the file in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a problem saving the file When it is finished, tell me it is finished and go see the LIVE.txt file I find it empty, even though it tells me it was saved ..

from selenium import webdriver
import time

live = open('LIVE.txt', 'w')
die = open('DIE.txt', 'w')
list = input("Input Mail List :")
while True:
    driver = webdriver.Chrome()
    list = open(list, 'r').readlines()
    for line in list:
        email = line.strip()
        checkemail = driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[2]/form/div/input[1]')
        loginButton = driver.find_elements_by_css_selector("#submit-button")
        emailcheck = driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]')

        if emailcheck == driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]') :
            print("\033[32;1mLIVE\033[0m | " + email + " | [(Checked)]")
            live.write(email + '\n')
            print("\033[31;1mDIE\033[0m | " + email + " | [(Checked)]")
            die.write(email + '\n')
Need to close file before anything get written.
Here also trow in f-string as a example.
if emailcheck == driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]'):
    print(f"\033[32;1mLIVE\033[0m | {email} | [(Checked)]")
He gave me this problem ..
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\_pydev_bundle\", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\_pydev_imps\", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/abdlwafitahiri/Desktop/Python/cours", line 21
    print(f"\033[32;1mLIVE\033[0m | {email} | [(Checked)]")
SyntaxError: invalid syntax
Try the older .foramt() method.
print("\033[32;1mLIVE\033[0m | {} | [(Checked)]".format(email))
You should upgrade python version,recommend Python 3.7 or newer.
f-string was new in Python 3.6,which was the biggest version upgrade for Python 3.