我已经在我的Mac上使用Eclipse中的PyDev大约两年了.今天更新了Eclipse,突然PyDev完全丢失了.尝试了一切,包括一个完整的卸载和全新安装,但虽然PyDev显示在菜单中安装,它似乎没有其他地方.
PyDev版本:3.0.0.201311051910 Eclipse:版本:Kepler Service Release 1 Build id:20130919-0819
我无法打开PyDev透视图,我无法创建新的Python文件,并且我无法打开现有的Python文件而不将其视为纯文本.
今晚我有一份巨大的任务,帮助赞赏.
我有一个问题要解决涉及控制彼此利益的公司.如果A拥有超过50%的B,或者A拥有一系列其他公司,并且拥有超过50%的B,则公司控制另一家公司.
我正在用一个顶点和边的图表来接近这个,它代表了与所有公司的所有关系.
我认为我需要实现的是广度优先搜索(或者可能是最长路径而不是最短路径的Dijkstra算法设备)沿着企业之间的路径,只要从A到B的路径总和加权大于50% .我不知道如何实现这一点,因为我只能使用标准的Python 3.x库来解决这个问题.任何帮助将不胜感激!
样本输入
CompanyA CompanyB 30
CompanyB CompanyC 52
CompanyC CompanyD 51
CompanyD CompanyE 70
CompanyE CompanyD 20
CompanyD CompanyC 20
Run Code Online (Sandbox Code Playgroud)
样本输出
CompanyA has a controlling interest in no other companies.
CompanyB has a controlling interest in CompanyC, CompanyD, and CompanyE.
CompanyC has a controlling interest in CompanyD, and CompanyE.
CompanyD has a controlling interest in CompanyE.
CompanyE has a controlling interest in no other companies.
Run Code Online (Sandbox Code Playgroud)
我的代码到目前为止:
import sys
class Vertex: …Run Code Online (Sandbox Code Playgroud) 我的目标是创建一个可用于测量另一个函数的执行和资源使用情况的函数。通过教程,我使用 Python 的 ThreadPoolExecutor 创建了以下内容:
from resource import *
from time import sleep
from concurrent.futures import ThreadPoolExecutor
class MemoryMonitor:
def __init__(self):
self.keep_measuring = True
def measure_usage(self):
max_usage = 0
u_run_time = 0
s_run_time = 0
while self.keep_measuring:
max_usage = max(max_usage, getrusage(RUSAGE_SELF).ru_maxrss)
u_run_time = max(u_run_time, getrusage(RUSAGE_SELF).ru_utime)
s_run_time = max(s_run_time, getrusage(RUSAGE_SELF).ru_stime)
sleep(0.1) # run this loop every 0.1 seconds
return [max_usage, u_run_time, s_run_time]
def execute(function):
with ThreadPoolExecutor() as executor:
monitor = MemoryMonitor()
stats_thread = executor.submit(monitor.measure_usage)
try:
fn_thread = executor.submit(function)
result = fn_thread.result() …Run Code Online (Sandbox Code Playgroud) python encapsulation python-multithreading python-3.x concurrent.futures
快速问题(使用Python 3.x) - 我正在编写一个Python程序,它接受多行输入,然后搜索该输入,查找所有整数,对它们求和,并输出结果.我有点难以找到最有效的搜索方式并找到多位整数 - 如果一行包含12,我想找到12而不是[1,2].这是我的代码,未完成:
def tally():
#the first lines here are just to take multiple input
text = []
stripped_int = []
stopkey = "END"
while True:
nextline = input("Input line, END to quit>")
if nextline.strip() == stopkey:
break
text.append(nextline)
#now we get into the processing
#first, strip all non-digit characters
for i in text:
for x in i:
if x.lower() in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','!',',','?']:
pass
else:
stripped_int.append(x)
print(stripped_int)
tally()
Run Code Online (Sandbox Code Playgroud)
这打印出一个包含所有整数的列表,但是我对如何将整数保持在一起感到困惑.有任何想法吗?