小编lqh*_*gbl的帖子

如何在Python中获取字符串的所有连续子字符串?

这是我的代码,但我想要一个更好的解决方案,您如何看待这个问题?

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 string substring python-2.7

33
推荐指数
4
解决办法
6万
查看次数

如何设置Python apscheduler运行作业每天9,11,14,17,18时钟

我正在使用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?

python apscheduler

2
推荐指数
1
解决办法
2815
查看次数

Python:执行shell命令

我需要这样做:

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.

任何帮助都会很棒!

python subprocess

1
推荐指数
2
解决办法
387
查看次数

标签 统计

python ×3

apscheduler ×1

python-2.7 ×1

string ×1

subprocess ×1

substring ×1