Home > Back-end >  my code is working on its own but wont run/print in my project as a whole
my code is working on its own but wont run/print in my project as a whole

Time:09-21

Hello I'm new to python and jumped into trying to automate reading my work schedule for fun really and have run into a block...

I've written some code and it just won't print in my main project but when taken out to test independently it runs just fine.

what am I doing wrong?

the with statement is what isn't working, nothing gets printed to console, but again works on its own in a separate project and correctly prints.

(I took out the xpaths and stuff for safety)

from selenium import webdriver
from datetime import date
import sys 

driver = webdriver.Chrome()
driver.get('')
userid = driver.find_element_by_xpath('')
password = driver.find_element_by_xpath('')

userid.send_keys('')
password.send_keys('')

loginbutton = driver.find_element_by_xpath('')
loginbutton.click()

schedule = driver.find_element_by_xpath('')
schedule.click()

date = date.today()
currentdate = date.strftime("%d")


wholeschedule = driver.find_element_by_xpath('').text
outF = open("schedule.txt", "w")
outF.write(wholeschedule)

with open('schedule.txt',"r") as file:
    for line in file:
        if ':' not in line and currentdate in line:
            print('today is the: '   currentdate)
            print(next(file), end='')
            break

CodePudding user response:

You never closed outF, so the data written to it likely never got physically written to the disk. Insert outF.close() after the with block.

  • Related