首页 > 解决方案 > Python 代码部分无法在 Jupyter 笔记本中运行

问题描述

我正在构建一个代码来下载一些数据并重命名文件。当我在 Jupyter 笔记本中通过在单独的单元格中运行 A 部分和 B 部分来测试它时,它可以工作,但是在单个单元格中运行时它不起作用。

A部分

driver.find_element_by_xpath("//input[@value='Submit & Clear History']").click()
time_to_wait = 10
time_counter = 0
while not os.path.exists(r"C:\Users\rkmaheshwaran\Downloads\CSV\Py-files"):
    time.sleep(1)
    time_counter += 1
    if time_counter > time_to_wait:break
print("done")

B部分

os.chdir(r"C:\Users\rkmaheshwaran\Downloads\CSV\Py-files")
for file in os.listdir(r"C:\Users\rkmaheshwaran\Downloads\CSV\Py-files"):
    src=file
    if src=='printcsvreports.csv':
        dst="inflowdata-" + time.strftime("%Y%m%d") + ".csv"
        os.rename(src,dst)
print("renamed")

标签: python

解决方案


推荐阅读