这是我的代码,但我想要一个更好的解决方案,您如何看待这个问题?
def get_all_substrings(string):
length = len(string)
alist = []
for i in xrange(length):
for j in xrange(i,length):
alist.append(string[i:j + 1])
return alist
print get_all_substring('abcde')
Run Code Online (Sandbox Code Playgroud) 我正在使用Python apscheduler处理期间任务,我希望代码在每天的9:00,11:00,16:00,17:00执行,这里是作业的示例代码:
#coding=utf-8
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
logging.basicConfig()
from time import ctime
sched = BlockingScheduler()
@sched.scheduled_job('cron', hour=16)
def timed_job_one():
print "16"
print ctime()
@sched.scheduled_job('cron', hour=17)
def timed_job_one():
print "17"
print ctime()
@sched.scheduled_job('cron', hour=9)
def timed_job_two():
print ctime()
print '9'
@sched.scheduled_job('cron', hour=11)
def timed_job_two():
print ctime()
print '11'
sched.start()
Run Code Online (Sandbox Code Playgroud)
它工作,但重复四次代码似乎很愚蠢,所以我的问题是如何使代码简短设置功能运行在每天9:00,11:00,16:00,17:00?
我需要这样做:
paste file1 file2 file3 > result
Run Code Online (Sandbox Code Playgroud)
我的python脚本中有以下内容:
from subprocess import call
// other code here.
// Here is how I call the shell command
call ["paste", "file1", "file2", "file3", ">", "result"])
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到此错误:
paste: >: No such file or directory.
任何帮助都会很棒!