my code is working on its own but wont run/print in my project as a whole

Question:

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
Asked By: sybergeko

||

Answers:

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.

(pasting @jasonharper’s comment so this question is answered)

Answered By: Alex
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.