我想要一个函数在主程序仍在运行时每 5 分钟运行一次。
我发现了多个关于如何使函数每隔几秒运行一次的帖子,但它们似乎对我不起作用。
这是我的程序:
from Read import getUser, getMessage
from Socket import openSocket, sendMessage
from Initialize import joinRoom, Console
from question import query_yes_no
from Settings import AIDENT
import string
import sched, time
import urllib.parse
import requests
import subprocess
import sys
import os
s = openSocket()
joinRoom(s)
while True:
try:
try:
readbuffer = s.recv(1024)
readbuffer = readbuffer.decode()
temp = readbuffer.split("\n")
readbuffer = readbuffer.encode()
readbuffer = temp.pop()
except:
temp = ""
for line in temp:
if line == "":
break
if …Run Code Online (Sandbox Code Playgroud) 我试图创建一个JSON对象并将其附加到列表,但没有成功。我收到此错误消息:
Traceback (most recent call last):
File "/projects/circos/test.py", line 32, in <module>
read_relationship('data/chr03_small_n10.blast')
File "/projects/circos/test.py", line 20, in read_relationship
tmp = ("[source: {id: '{}',start: {},end: {}},target: {id: '{}',start: {}, end: {}}],").format(parts[0],parts[2],parts[3],parts[1],parts[4],parts[5])
KeyError: 'id'
Run Code Online (Sandbox Code Playgroud)
用下面的代码
def read_relationship(filename):
data = []
with open(filename) as f:
f.next()
for line in f:
try:
parts = line.rstrip().split('\t')
query_name = parts[0]
subject_name = parts[1]
query_start = parts[2]
query_end = parts[3]
subject_start = parts[4]
subject_end = parts[5]
# I need: [source: {id: 'Locus_1', start: 1, end: 1054}, …Run Code Online (Sandbox Code Playgroud)