如何在Python中动态添加If Else语句?

2023-12-13

目前,我开发了一个脚本,该脚本将读取传入/最新的电子邮件并根据某些条件(例如电子邮件主题和文本)过滤电子邮件。当用户选择subject or text,他们可以选择要过滤电子邮件的条件(等于、不包含等)。

我的问题我有一个演示网站,可以让用户添加不同的条件来过滤电子邮件。但现在我的脚本只能处理一种条件并同时执行。如何使我的脚本检测多个条件并根据多个规则过滤电子邮件?我使用 Django 来做我的网站

我之前的脚本: 用户点击后OK,脚本在view.py将直接执行,并且仅根据当前条件解析电子邮件

enter image description here

我想要实现的目标: 我修改了我的 html 模板,它会不断地让用户添加几个条件,而不是只执行一个条件。示例:当用户选择参数等并单击OK新行将被存储,脚本将根据用户想要解析的规则数量来解析电子邮件。 (点击后submit只有满足所有规则时才会触发脚本)

enter image description here

预期输出(基于上图)系统能够使用这两个规则解析传入的电子邮件:电子邮件主题必须等于测试并且文本必须包含文本包含

可能的解决方案当有新规则进来时,是否能够动态添加If Else语句?并计数直到规则的最后一行然后执行。

我的py脚本(此代码是以前的版本,它只能在用户单击“确定”时执行一次)

from django.http import HttpResponse
import datetime
import email
import imaplib
import mailbox
import smtplib

def index(request):

    return render(request,'DemoApp/hi.html')

def send(request):
    EMAIL_ACCOUNT = "[email protected]"
    PASSWORD = "xxx"

    mail = imaplib.IMAP4_SSL('imap.gmail.com')
    mail.login(EMAIL_ACCOUNT, PASSWORD)
    mail.list()
    mail.select('inbox')
    result, data = mail.uid('search', None, "UNSEEN")  # (ALL/UNSEEN)
    i = len(data[0].split())

    for x in range(i):
        latest_email_uid = data[0].split()[x]
        result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)')
        # result, email_data = conn.store(num,'-FLAGS','\\Seen')
        # this might work to set flag to seen, if it doesn't already
        raw_email = email_data[0][1]
        raw_email_string = raw_email.decode('utf-8')
        email_message = email.message_from_string(raw_email_string)

        # Header Details
        date_tuple = email.utils.parsedate_tz(email_message['Date'])
        if date_tuple:
            local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
            local_message_date = "%s" % (str(local_date.strftime("%a, %d %b %Y %H:%M:%S")))
        email_from = str(email.header.make_header(email.header.decode_header(email_message['From'])))
        email_to = str(email.header.make_header(email.header.decode_header(email_message['To'])))
        subject = str(email.header.make_header(email.header.decode_header(email_message['Subject'])))

        # Body details
        for part in email_message.walk():

            if part.get_content_type() == "text/plain":
                body = part.get_payload(decode=True)


                #Get all value from
                ParameterGet = str(request.POST.get('Parameter', None))
                ConditionGet = str(request.POST.get('Condition', None))
                valuetomatch = str(request.POST["valuetomatch"])

                def emailSendDetails():
                    server = smtplib.SMTP('smtp.gmail.com', 587)
                    server.starttls()
                    server.login(EMAIL_ACCOUNT, PASSWORD)
                    msg = "ALERT NOTICE!"
                    server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                    server.quit()

                #<----------------Parameter---------------->
                #Subject
                if ParameterGet == "Subject":
                    # <----------------Condition---------------->
                    #Equals
                    if ConditionGet == "Equals":
                        if valuetomatch == subject:
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "subject equals!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");

                    # Contain
                    if ConditionGet == "Contain":
                        if valuetomatch in subject:
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "subject contain!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");

                    # Does not contain
                    if ConditionGet == "NotContain":
                        if valuetomatch not in subject:
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "subject not contain!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");


                # <----------------Parameter---------------->
                #Text
                if ParameterGet == "Text":
                    # <----------------Condition---------------->
                    # Equals
                    if ConditionGet == "Equals":

                        if valuetomatch == body.decode('utf-8').rstrip():
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "text equals!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");

                    # Contain
                    if ConditionGet == "Contain":
                        if valuetomatch in body.decode('utf-8'):
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "text contain!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");

                    # Does not contain
                    if ConditionGet == "NotContain":
                        if valuetomatch not in body.decode('utf-8'):
                            server = smtplib.SMTP('smtp.gmail.com', 587)
                            server.starttls()
                            server.login(EMAIL_ACCOUNT, PASSWORD)
                            msg = "text notcontain!"
                            server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                            server.quit()
                        else:
                            print("no email");
            else:
                continue


    return render(request, 'DemoApp/hi.html', {'key': "Send successfully"})

相同的脚本,但它不链接到 Html 或 django 模板,它的所有硬编码参数,但它有助于调试

import datetime
import email
import imaplib
import mailbox
import smtplib

while True:
    EMAIL_ACCOUNT = "[email protected]"
    PASSWORD = "xxx"

    mail = imaplib.IMAP4_SSL('imap.gmail.com')
    mail.login(EMAIL_ACCOUNT, PASSWORD)
    mail.list()
    mail.select('inbox')
    result, data = mail.uid('search', None, "UNSEEN")  # (ALL/UNSEEN)
    i = len(data[0].split())

    for x in range(i):
        latest_email_uid = data[0].split()[x]
        result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)')
        # result, email_data = conn.store(num,'-FLAGS','\\Seen')
        # this might work to set flag to seen, if it doesn't already
        raw_email = email_data[0][1]
        raw_email_string = raw_email.decode('utf-8')
        email_message = email.message_from_string(raw_email_string)

        # Header Details
        date_tuple = email.utils.parsedate_tz(email_message['Date'])
        if date_tuple:
            local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
            local_message_date = "%s" % (str(local_date.strftime("%a, %d %b %Y %H:%M:%S")))
        email_from = str(email.header.make_header(email.header.decode_header(email_message['From'])))
        email_to = str(email.header.make_header(email.header.decode_header(email_message['To'])))
        subject = str(email.header.make_header(email.header.decode_header(email_message['Subject'])))

        # Body details
        for part in email_message.walk():

            if part.get_content_type() == "text/plain":
                body = part.get_payload(decode=True)
                print("From:", email_from)

                print("Email To:", email_to)
                print("date:", local_message_date)
                print("Subject:", subject)
                print("body:", body.decode('utf-8'))

                '''If subject have "Consent" it will send specific email to recipient'''
                if "Consent" in subject:
                    server = smtplib.SMTP('smtp.gmail.com', 587)
                    server.starttls()
                    server.login(EMAIL_ACCOUNT, PASSWORD)

                    msg = "ALERT NOTICE!"
                    server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
                    server.quit()
                else:
                    print("no email");

            else:
                continue

我当前的 Html 模板

<!DOCTYPE html>
<html lang="en">
<html>
<head>
    <link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <style>


.buttonSubmit{
background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}




table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

body {font-family: 'Quicksand', sans-serif;}
.button {
  border-radius: 50px;
  background-color:  #ff9633;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 15px;
  padding: 10px;
  width: 80px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
  margin-left:500px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  position: relative;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  border: 1px solid #888;
  width: 45%;

  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s
}


/* Add Animation */
@-webkit-keyframes animatetop {
  from {top:-300px; opacity:0}
  to {top:0; opacity:1}
}

@keyframes animatetop {
  from {top:-300px; opacity:0}
  to {top:0; opacity:1}
}

/* The Close Button */
.close {
  color: white;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

.modal-header {
  padding: 2px 16px;
  background-color: #ff9633;
  color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
  padding: 2px 16px;
  background-color: #ff9633;
  color: white;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #ff9633;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover {
  background-color:
#fa7d34;
}






    </style>
</head>
<body>


<ul>

    <li>
        <div id="myBtn1"><a href="#AddCon">Alert Policies</a></div>
    </li>
    <li><a href="#contact">Test3</a></li>
    <li><a href="#about">Test4</a></li>
</ul>


<!-- The Modal -->
<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <div class="modal-header">
            <span class="close">&times;</span>
            <h2>Alert Policies</h2>
        </div>
        <div class="modal-body">

            <p style="font-size:14px">Please select an event parameter as well as the condition type and value that
                apply.</p>

            <!-- parameter drop down -->
            <form method="post">

                <label for="Parameter"> <b style="font-size:13px"> Event parameter to evaluate </b></label>
                <select name="Parameter" id="Parameter" style="width:340px; font-family: 'Quicksand', sans-serif;">
                    <option disabled selected value>select a parameter</option>
                    <option value="Subject">Subject</option>
                    <option value="Text">Text</option>

                </select>
                <br><br>

                <label for="Condition"> <b style="font-size:13px"> Type of condition </b></label>
                <select name="Condition" id="Condition"
                        style="width:340px; margin-left:69px; font-family: 'Quicksand', sans-serif;">
                    <option disabled selected value>select a condition</option>
                    <option value="Equals">Equals</option>
                    <option value="Contain">Contain</option>
                    <option value="NotContain">Does not contain</option>

                </select>
                <br><br>

                <label for="valuetomatch"> <b style="font-size:13px"> Value to match</b></label>
                <input type="text" id="valuetomatch" name="valuetomatch"
                       style="width:333px; margin-left:80px; font-family: 'Quicksand', sans-serif;">
                <br>
                <br>
            </form>
            <button class="button"><span>OK</span></button>


        </div>


    </div>

</div>
<table id="myTable">

    <tr>
        <th>Event Parameter</th>
        <th>Condition</th>
        <th>Value to match</th>
        <th>Action</th>

    </tr>

</table>
<br>

<a href="#" class="buttonSubmit">Submit</a>




<script>

//add tablebox
$(document).ready(function(){
    $(".button").on('click', function () {

   para = document.getElementById("Parameter").value;
   condi = document.getElementById("Condition").value;
   value2match = document.getElementById("valuetomatch").value;

  if (para && condi && value2match !== null) {
  var table = document.getElementById("myTable");
  var row = table.insertRow(-1);
  var cell1 = row.insertCell(0);
  var cell2 = row.insertCell(1);
  var cell3 = row.insertCell(2);
  var cell4 = row.insertCell(3);

  cell1.innerHTML = document.getElementById("Parameter").value;
  cell2.innerHTML = document.getElementById("Condition").value;
  cell3.innerHTML = document.getElementById("valuetomatch").value;
  cell4.innerHTML = '<button  class = "del_img "onClick="delSpec(this)">Delete</button> </div>';

  //close the modal
  modal.style.display = "none";
}else
{
 alert("All the input box cannot be empty!");
}

    });
});

function delSpec(node)
    {
    r=node.parentNode.parentNode;
    r.parentNode.removeChild(r);
    }

// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn1");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
  modal.style.display = "block";
}


// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}






</script>

</body>
</html>

这个问题看起来很有趣。让我尝试一下,

我可以看到只需要执行三个条件。因此,让我们用它制作一个字典:

con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}

我可以看到您已在此处准备好所需的值:

#Get all value from
ParameterGet = str(request.POST.get('Parameter', None))
ConditionGet = str(request.POST.get('Condition', None))
valuetomatch = str(request.POST["valuetomatch"])

让我们以for loop迭代表alert policies用于迭代的行,

con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}

for each_row in rows:
  ***your other logic goes here***
  ParameterGet = str(request.POST.get('Parameter', None))
  ConditionGet = str(request.POST.get('Condition', None))
  valuetomatch = str(request.POST["valuetomatch"])
  text = "body.decode('utf-8').rstrip()"
  current_condition = "(valuetomatch "+ con[ConditionGet] + " " + ParameterGet.lower() + ")"
  if eval(current_condition):
          server = smtplib.SMTP('smtp.gmail.com', 587)
          server.starttls()
          server.login(EMAIL_ACCOUNT, PASSWORD)
          msg = "subject not contain!"
          server.sendmail(EMAIL_ACCOUNT, "[email protected]", msg)
          server.quit()
  else:
          print("no email");

OUTPUT:

>>> con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}
>>> valuetomatch = "hi"
>>> ConditionGet = "Contain"
>>> ParameterGet = "Subject"
>>> subject = "hi"
>>> current_condition = "(valuetomatch "+ con[ConditionGet] + " " + ParameterGet.lower() + ")"
>>> current_condition
'(valuetomatch in subject)'
>>> eval(current_condition)
True

Check eval以供参考。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在Python中动态添加If Else语句? 的相关文章

  • Python Pandas:返回连续缺失的工作日日期并为数据框中缺失的日期分配比率

    Dates rates 7 26 2019 1 04 7 30 2019 1 0116 7 31 2019 1 005 8 1 2019 1 035 8 2 2019 1 01 8 6 2019 0 9886 8 12 2019 0 965
  • 如何在 Django 中获取查询集中的倒数第二条记录?

    我有一个名为employees salary我需要获得员工第二高的薪水 我知道我可以过滤latest first last 这些都有效 但是如何过滤倒数第二个 我错过了什么吗 将 order by 与反向过滤器 一起使用 然后使用 1 抓取
  • 将 Python 脚本导入另一个脚本?

    我正在阅读 Zed Shaw 的 艰难学习 Python 正在学习第 26 课 在本课中 我们必须修复一些代码 这些代码从另一个脚本调用函数 他说我们不必导入它们来通过测试 但我很好奇我们将如何做到这一点 课程链接 http learnpy
  • IP保持不变

    我正在尝试通过代码连接到 Tor 并更改我的身份 到目前为止我得到的结果是我连接成功但无法更改我的身份 这是我的代码 import socket import socks import httplib def connectTor sock
  • 如何在 PyCharm 社区版中运行 Django 项目的调试服务器?

    有人在 PyCharm 社区版中为 Django 项目设置调试配置时遇到问题吗 IDE 的社区版缺少项目设置中的项目类型选项 然后当我设置 调试 或 运行配置 时 它会要求我提供应该运行的脚本 Django 需要什么脚本 manage py
  • 查找提供的 Sum 值的组合

    我有一系列这样的数字 myvar 57 71 87 97 99 101 103 113 114 115 128 129 131 137 147 156 163 186 现在我想计算所有这些可能的组合 长度为1到20 其总和等于给定的数字m
  • Django:在管理界面中显示多对多项目的列表

    这可能是一个简单的问题 但我似乎无法理解 我在 models py 中有两个简单的模型 Service 和 Host Host services 与 Service 具有 m2m 关系 换句话说 一台主机有多个服务 一个服务可以驻留在多个主
  • rpy2 传递 python 保留关键字参数

    我试图通过 python 使用 r 的密度函数 并且必须将 from to 参数传递给密度函数 然而 由于 from 这个词是Python中的保留关键字 我该如何实现这一点呢 谢谢 这是到目前为止的代码 r density robjects
  • 动态组装 Python 模块,动态导入

    我正在努力让自己熟悉importlib钩子 我想实现直接导入用其他语言编写的非Python文件并维护源映射的能力 因此提高SyntaxError带有行号的 s 仍然会给出有意义的堆栈跟踪 我加载外部文件的方法是组装 Pythonic 源代码
  • 如何获取 Flask 中当前的基本 URI? [复制]

    这个问题在这里已经有答案了 在下面的代码中 我想将 URL 存储在变量中以检查发生 URL 错误的错误 app route flights methods GET def get flight flight data mongo db fl
  • 在 python 中以半小时为增量创建选择列表

    我正在尝试创建一个
  • PyCrypto:生成受 DES3 密码保护的 RSA 密钥

    我已经能够使用 DES3 创建受密码保护的 RSA 密钥 嗯 I think因为我对这个加密世界非常陌生 使用以下命令 openssl genrsa out tmp myKey pem passout pass f00bar des3 20
  • django在服务器上同步数据库时出错

    我有一个完整运行的区域设置 django 应用程序 但我在迁移到 site5 服务器时遇到了麻烦 当我启动 django 时syncdb命令 我所有模型的表都已创建 但是然后 我猜当它创建关系表时 我收到以下错误 mysql excepti
  • SyntaxError:创建类实例时语法无效[关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我在 Python shell 3 3 2 中运行这段代码 但它给了我SyntaxError invalid syntax cla
  • 在 C++ 中运行 python [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我有一个用 C 编写的应用程序和一个测试系统 也是用 C 编写的 测试系统非常复杂并且很难改变 我只想做一些小的改变 我的班级是这样的
  • 无法使用 pandas 获取平均日期

    我有一个时间序列数据集 我想从中获取平均日期 这是一个人为的示例 显示 pandas datetime64 对象的溢出错误 import pandas as pd import numpy as np rng pd date range 2
  • 将人员分配到床位 - 自动化方法[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我每年都会帮助举办青年营 将与会者分配到卧室是一项艰巨的任务 有 92 个卧室 活动持续一周 与会者停留的时间长短不一 而且床需要重复
  • python - 从完整地址获取邮政编码

    我有一个数据框 其中一列中有完整地址 我需要创建一个仅包含邮政编码的单独列 有些地址只有五位数字的邮政编码 而其他地址则有额外的四位数字 如何拆分列以获取邮政编码 示例数据 d name bob john address 123 6th S
  • dump() 缺少 1 个必需的位置参数:python json 中的“fp”

    我正在尝试美化 json 格式 但收到此错误 import requests as tt from bs4 import BeautifulSoup import json get url tt get https in pinterest
  • 在 Django 1.7 中使用 html 发送电子邮件

    In 发送邮件 我们有一个新参数 html message Docs https docs djangoproject com en dev topics email send mail I have 电子邮件 html文件 我想发送我的消

随机推荐

  • mod_rewrite 似乎忽略了 [L] 标志

    我正在尝试使用 L 标记在RewriteRule 但似乎不起作用 如果您调用该页面 我希望如此 www domain com admin 它会将您重定向到 www domain com backend php 否则 如果您调用任何其他页面
  • 判断复选框是否被选中 php $_GET

    我只想让 php 确定是否选中复选框 但我遇到了获得正确返回值的问题 请帮助 我的html代码
  • Codeigniter flashdata 无法在 Internet Explorer 和 google chrome 中工作

    Codeigniter flashdata 无法在 Internet Explorer 和 Chrome 中运行 但可以在 Firefox 中运行 可能是什么问题 在我的控制器中 this gt session gt set flashda
  • 将 Jquery 数据表与 AngularJs 结合使用

    我正在尝试使用jquery 数据表插件在我的 angularjs 项目中 但我的问题是它支持吗延迟加载对 AngularJS 有价值吗 我想要 因为我有很多行 如何使用数据表管道与 AngularJS 一起 分页有一个解决方案here 如何
  • MySQL LEFT JOIN 带有 WHERE 子句的查询

    希望有人可以提供帮助 因为我很难理解如何正确查询 我有一个 Member 表和一个 Member Card 表 Member Card 有一个 Member 列 因此该卡与一个会员相关联 两个表都有一个 LastModifiedDate 列
  • 匹配名称的好算法?

    我正在开发一款手机应用程序 用于将联系人与 Facebook 帐户同步 所以基本上我有一个我的联系人姓名列表和我的 Facebook 好友列表 我希望获得两个列表之间的最佳匹配 当然 我可以自己写一些基本的东西 但也许有一种已知的算法可以得
  • ADT 23 不喜欢 NDK11

    Win7 x64 Eclipse Luna SR2 Android 工具 v23 0 7 我已经安装了 NDK r11 我试图将 Eclipse 指向D android ndk r11通过首选项窗口 但它说 不是有效的 NDK 目录 您需要
  • 在 PHP 中显示关联数组

    我正在尝试构建一个函数 该函数从数据库中提取信息并将其插入到 PHP 中的关联数组中mysql fetch assoc 并返回数组 以便另一个函数可以显示它 我需要一种方法来显示返回的关联数组 这应该是与第一个不同的函数 print r a
  • Fortran 到 C 库的链接器错误 - /usr/lib/libf2c.so:对“MAIN__”的未定义引用

    所以我在使用 fortran 到 C 库时遇到了一些麻烦 现在 在讨论这个问题之前 我可以告诉你 我不能像某些论坛网站所建议的那样使用 g2c 现在 解决问题 当我尝试编译一个非常大的项目时 我得到以下信息 from the makefil
  • 在 Python 中读取 .mat 文件

    是否可以在 Python 中读取二进制 MATLAB mat 文件 我看到 SciPy 声称支持读取 mat 文件 但我没有成功 我安装了SciPy版本0 7 0 但找不到loadmat method 需要进口 import scipy i
  • 如何将 xml 文件的“自定义工具”属性设置为 T4 文件?

    我们知道 asp net resx 文件有一个自定义工具用于生成一些 C 代码 ResX文件代码生成器 我有一个 xml 文件 我想将其自定义工具属性设置为T4 file 如何将 T4 文件绑定到 xml 文件 你可以这样做T4工具箱 在
  • 如何在ios中从Facebook SDK 4.0获取用户名

    如何获得username来自 iOS 中的 facebook sdk 4 0 IBAction LoginWithFacebook id sender if FBSDKAccessToken currentAccessToken self
  • C++ 中的编译器版本、名称和操作系统检测

    我需要使用 C 检测操作系统名称 编译器名称和编译器版本 因为我需要更改每种情况的设置 我怎样才能做到这一点 对于大多数编译器 您可以找到预定义宏的列表 VS http msdn microsoft com en us library b0
  • 在 Windows 上使用 Cygwin64 编译器和调试器为 C 设置 VS Code(错误:无法启动调试)

    我正在尝试将 VSCODE 设置为debugWindows 上使用 Cygwin64 的 C 程序 我使用了 stephw建议的配置 在 Windows 上使用 Cygwin64 编译器和调试器为 C 设置 VS Code 但它对我不起作用
  • 将 dplyr 查询保存到 dbplyr 中的不同架构

    我有一个 JDBC 连接 想要从一个模式查询数据并保存到另一个模式 library tidyverse library dbplyr library rJava library RJDBC access the temp table in
  • Plotly R:根据折线图中的不同线条更改悬停信息字体颜色

    我想更改一些折线图线的悬停信息字体颜色 但不是全部 这是一些与我的代码类似的代码 number lt rep c 00 01 02 each 4 animal lt rep c cat dog mouse each 4 year lt re
  • 按钮上的长文本会弄乱 GridLayout 行

    我有一个 GridLayout 用于承载多个按钮 按两列排序 所有按钮都有固定的高度和宽度 如果其中一个按钮包含太多文本 布局就会混乱 我希望布局能够正确维护行 无论按钮是否有太多文本 我将在稍后处理显示太多文本的情况 使用文本的自动大小
  • T/F:在过程中使用 IF 语句会产生多个计划

    在回应this问题 KM 说 如果您使用的是 SQL Server 2005 或更高版本 则可以使用 IF 在同一过程中进行多个查询 并且每个查询都会为其保存一个查询计划 相当于旧版本上的每个查询的过程 请参阅我的答案中的文章或此链接到正确
  • 如何在查询字符串中安全地包含密码

    是否可以在 C asp net 站点的查询字符串中安全地包含密码 我所知道的一些假设和事情 该网站没有也不会有与其他网站的链接 图像 javascript 分析 因此无需担心引用链接 与 Web 浏览器的所有通信都将通过 https 进行
  • 如何在Python中动态添加If Else语句?

    目前 我开发了一个脚本 该脚本将读取传入 最新的电子邮件并根据某些条件 例如电子邮件主题和文本 过滤电子邮件 当用户选择subject or text 他们可以选择要过滤电子邮件的条件 等于 不包含等 我的问题我有一个演示网站 可以让用户添