def binary_search(target, num_list):
if len(num_list) == 0:
return False
left, right = 0, len(num_list)-1
while(left < right):
mid = (left + right)>>1
if num_list[mid] == target:
return True
elif num_list[mid] < target:
left = mid + 1
else:
right = mid - 1
return False
def binary_search_recursive(target, num_list):
if len(num_list) == 0:
return False
mid = len(num_list) // 2
if num_list[mid] == target:
return True
elif num_list[mid] < target:
return binary_search_recursive(target, num_list[mid+1:])
else:
return binary_search_recursive(target, num_list[:mid])
num_list = [1,3,4,5,6,7,8,9]
print(binary_search_recursive(7, num_list))
?完美解决Pyinstaller 打包exe 出现PermissionError: [Errno 13] Permission denie 问题-CSDN博客
import win32file
def file_occupied(file_name): # occupied:占用
# 自己加的模块,防止出现错误:PermissionError: [Errno 13] Permission denied:exe_path
# 如果检测到文件被占用,则关闭该文件句柄
try:
fp = open(file_name,'wb')
except:
vHandle = win32file.CreateFile(file_name, win32file.GENERIC_READ, 0, None,win32file.OPEN_EXISTING,win32file.FILE_ATTRIBUTE_NORMAL, None)
win32file.CloseHandle(vHandle)
else:fp.close()
result = subprocess.run(['nslookup', url], capture_output=True, text=True, shell=True)
之前没有加shell=True的时候,会出现弹框,加上这个之后再打包就没有弹框出现了。
// 结束指定端口进程
int killPortProcess(const char* targetPort) {
// 构造Shell命令
char command[100];
snprintf(command, sizeof(command), "fuser -k -n tcp %s/tcp", targetPort);
// 使用system调用执行Shell命令
int status = system(command);
// 检查命令执行结果
if (status == 0) {
printf("Processes on port %s have been terminated.\n", targetPort);
return 0;
} else {
printf("No processes found on port %s.\n", targetPort);
return -1;
}
}
?