我对Python还不熟悉,我就是不知道她怎么了:
def SomeDato():
today = datetime.date.today()
todayStr = idag.strftime('%d.%m.%y')
return todayStr
def AnotherFunctionWithinTestComplete()
strArg = SomeDato()
datoToCheck = dato.contentText #dato.contentText returns "13.12.15. 16:29"
if datoToCheck.startswith(strArg):
do something here....
我得到了这个错误:str object has no atribute '__getattr__'
在if datoToCheck.startswith(strArg)
行中。你知道吗
抱歉,我的代码是丹麦语,显然我没有翻译所有的东西。现在应该可以了:
我刚刚意识到,如果我这样写:
那就成功了。所以dateToCheck=日期.contentText+“”而不是dateToCheck=日期.contentText有区别。有什么区别?你知道吗
strftime
是datetime
类的一个方法(在datetime
模块中定义得有些混乱),因此用其中
today
是日期时间类型。这也可以用today.strftime('%d.%m.%y')
作为实例方法调用。在你的例子中idag
是什么?错误消息表明它是一个字符串。如果要将idag
转换为datetime
,可以通过datetime.strptime(idag, '%d.%m.%y')
实现,前提是它已经是'%d.%m.%y'格式。你知道吗相关问题 更多 >
编程相关推荐