我试图将今天日期中的一年日期转换为变量。下面是我的代码。
import time
import datetime
today = time.strftime("%m/%d/%Y")
today_format = datetime.datetime.strptime(today, "%m/%d/%Y")
print (today_format)
exp_date = str(today_format + datetime.timedelta(days=365)).split(" ")
exp = exp_date[0]
print (exp)`
Run Code Online (Sandbox Code Playgroud)
上面的代码打印:
2017-12-14 00:00:00
2018-12-14
Run Code Online (Sandbox Code Playgroud)
知道如何让它在 12/14/2018 打印吗??
我想尝试所有数字b/1 1和1000包含7.
尝试:
lst=[y for y in range(1,1000) if 7 in y]
print (lst)
Run Code Online (Sandbox Code Playgroud)
得到以下错误:
TypeError: argument of type 'int' is not iterable
Run Code Online (Sandbox Code Playgroud)
尝试:
lst=[y for y in range(1,1000)]
newlst=[]
str1=list(map(lambda x:str(x),lst))
for i in str1:
if any('7') in i:
newlst.append(i)
print (newlst)
Run Code Online (Sandbox Code Playgroud)
这给了
if any('3') in i:
TypeError: 'in <string>' requires string as left operand, not bool
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
有没有想过用列表理解来完成这个?
import pypyodbc as pyodbc
model_name = 'test'
model_name1 = Master_Cursor.execute("select col1,col2,col3 from tablename where col3 like '%s' order by col3" %(model_name)).fetchall()
Run Code Online (Sandbox Code Playgroud)
上面的代码返回一条匹配的记录model_name = test。我如何取回其他记录model_name=123test123,abctestabc,ABCtestABC等?
基本上是在寻找
select col1,col2,col3 from tablename where col3 like '%test%'.
Run Code Online (Sandbox Code Playgroud)