微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果在变量中分配了两次,则无法调用“ datetime.date”对象

如何解决如果在变量中分配了两次,则无法调用“ datetime.date”对象

我有以下代码,由于某种原因我不能拥有

lastMonthEnd.strftime("%d"),lastMonthEnd.strftime("%b") and lastMonthEnd.strftime("%Y")一个变量中两次。

我声明了时间变量。


today = date.today()
first = today.replace(day=1)
lastMonthEnd = first +  dateutil.relativedelta.relativedelta(days=-1)

lastQuaterBegin = first + dateutil.relativedelta.relativedelta(months=-3)
lastMonthBegin = first + dateutil.relativedelta.relativedelta(months=-1)

我得到的第一个URL没有任何问题

# Get P&L monthly
    plUrl = "https://go.xero.com/Reports/Report2.aspx?"\
                "reportId=ca205001-1651-4947-bf95-9b1436926f09&report=&statement"\
                "=a22c12ce-7b22-49ff-a674-1a509552f6de&attPage=Compare%20Periods&"\
                "date="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+\
                "&timeframe=1&periods=3&budgetID=%20&total=null&ytd=null&"\
                "&CompareDaterangePeriods=1&sortByForAccount=Formattedname&cashOnly=null"
               
    driver.get(plUrl)

但是,当我在下面的代码中两次在网址中有lastMonthEnd.strftime("%d"),lastMonthEnd.strftime("%b") and lastMonthEnd.strftime("%Y")的位置运行代码时,会得到一个

文件“ XXX”,第145行,在模块中 “ toDate =” + lastMonthEnd.strftime(“%d”)+“%20” + lastMonthEnd.strftime(“%b”)+“%20” + lastMonthEnd.strftime(“%Y”)+“&” \

TypeError:“ datetime.date”对象不可调用

错误

plUrl = "https://go.xero.com/Reports/Report2.aspx?reportId=ca205001-1651-4947-bf95-9b1436926f09&report=&"\
                "statement=a22c12ce-7b22-49ff-a674-1a509552f6de&attPage=Show%20Date%20Range&"\
                "date="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+"&"\
                "timeframe=1&periods=3&budgetID=%20&total=null&ytd=null&"\
                "fromDate="+lastQuaterBegin("%d")+"%20"+lastQuaterBegin("%b")+"%20"+lastQuaterBegin("%Y")+"&"\
                "toDate="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+"&"\
                "CompareDaterangePeriod=none&CompareDaterangePeriods=1&sortByForAccount=Formattedname&cashOnly=null"
                            
    driver.get(plUrl)

有人可以帮助解决这个问题吗?

解决方法

似乎您忘记了在某些.strftime对象上添加DateTime

编码愉快, 面包果

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。