小编lod*_*kkx的帖子

将zip文件内容解压缩到Python 2.7中的特定目录

这是我目前用于提取与脚本位于同一当前工作目录中的zip文件的代码.如何指定要提取的其他目录?

我试过的代码并没有在我想要的地方提取它.

import zipfile

fh = open('test.zip', 'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
    outfile = open(name, 'wb')
    outfile.write('C:\\'+z.read(name))
    outfile.close()
fh.close()
Run Code Online (Sandbox Code Playgroud)

python windows compression

53
推荐指数
3
解决办法
9万
查看次数

查找字符串中所有出现的字符

我有逗号分隔的字符串,我需要从中提取值.问题是这些字符串永远不会是固定大小.所以我决定迭代逗号组并阅读其间的内容.为了做到这一点,我创建了一个函数,它返回样本字符串中每个匹配项的位置.

这是一个聪明的方法吗?这被认为是不好的代码吗?

#include <string>
#include <iostream>
#include <vector>
#include <Windows.h>

using namespace std;

vector<int> findLocation(string sample, char findIt);

int main()
{
    string test = "19,,112456.0,a,34656";
    char findIt = ',';

    vector<int> results = findLocation(test,findIt);
    return 0;
}

vector<int> findLocation(string sample, char findIt)
{
    vector<int> characterLocations;
    for(int i =0; i < sample.size(); i++)
        if(sample[i] == findIt)
            characterLocations.push_back(sample[i]);

    return characterLocations;
}
Run Code Online (Sandbox Code Playgroud)

c++ algorithm stl vector

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

C中主要功能的样式

可能重复:
主要的正确声明是什么?

我正在研究我的C技能,我注意到了这一点

int main(int argc,char*argv [])

返回(EXIT_SUCCESS)

代替

int main()并返回0

为什么是这样?

c coding-style

4
推荐指数
1
解决办法
1657
查看次数

使用Python和regex解析Windows命令结果

我使用以下代码ping网站以检查连接.如何解析结果以获得"Lost ="以查看丢失了多少?

def pingTest():
    host = "www.wired.com"
    ping = subprocess.Popen(
        ["ping","-n","4",host],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

    out,error = ping.communicate()
    print out
Run Code Online (Sandbox Code Playgroud)

这是我从中获得的回报

Pinging wired.com [173.223.232.42] with 32 bytes of data:
Reply from 173.223.232.42: bytes=32 time=54ms TTL=51
Reply from 173.223.232.42: bytes=32 time=54ms TTL=51
Reply from 173.223.232.42: bytes=32 time=54ms TTL=51
Reply from 173.223.232.42: bytes=32 time=54ms TTL=51

Ping statistics for 173.223.232.42:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = …
Run Code Online (Sandbox Code Playgroud)

python regex windows

4
推荐指数
1
解决办法
1227
查看次数

Python使用gmail从不同的地址发送电子邮件

我试图让电子邮件看起来像是来自我们公司内的特定用户的自动客户端后续电子邮件.出于某种原因,我无法将"FROM"更改为除了我登录gmail的帐户之外的任何人.

我知道PHP邮件程序库可以从任何人那里获取FROM地址而没有任何问题 - 但由于某种原因我不能在python中.如果有帮助,我们有一个企业Gmail帐户.

这是我正在使用的代码

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.MIMEImage import MIMEImage

def sendFollowupEmail(html):
  msg = MimeText('body')
  msg['Subject'] = 'subject'
  msg['From'] = "THIS IS THE EMAIL I WANT TO CHANGE@domain.com"
  msg['To'] = "client@client.com"




  username = 'accessaccount@gmail.com'
  password = 'password'
  server = smtplib.SMTP('smtp.gmail.com:587')
  server.starttls()
  server.login(username,password)  
  server.sendmail(me, you, msg.as_string())
  server.quit()    








  if __name__ == '__main__':
    sendFollowupEmail("test123")
Run Code Online (Sandbox Code Playgroud)

这是PHP,允许您从地址更改为您想要的任何内容

function sendFollowUpEmail($options) {

        /*
         * Send an email to a person or group.
         * Dependencies: PHPMailer
         * options: { …
Run Code Online (Sandbox Code Playgroud)

php python email smtp

4
推荐指数
1
解决办法
2546
查看次数

在jquery中可以使表行但不是表标题可单击

目前我正在使用

$('#mytable tr').click(function() {
    blah blah
});
Run Code Online (Sandbox Code Playgroud)

这使得所有行,包括标题可点击.如何排除标题或者<th>

javascript jquery

3
推荐指数
1
解决办法
2480
查看次数

从jquery mobile multiselect获取字符串以放入数据库

我试图从jquery移动应用程序的选择列表中获取值.

这是我的选择标记:

<div data-role="fieldcontain">
                <label for="stuff" class="select">Stuff:</label>
                <select name="stuff" id="stuff" multiple="multiple">
                    <option value=''>Select One</option>
                    <option value="Stuff 1">Stuff 1</option>
                    <option value="Stuff 2">Stuff 2</option>
                    <option value="Stuff 3">Stuff 3</option>
                    <option value="Stuff 4">Stuff 4</option>
                    <option value="Stuff 5">Stuff 5</option>
                    <option value="Stuff 6">Stuff 6</option>
                </select>
            </div>
Run Code Online (Sandbox Code Playgroud)

如何从此多选中获取逗号分隔的值字符串

javascript jquery html5 jquery-mobile

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

为什么这个程序通过引用传递参数

我正在为我正在研究的linux程序编写一些代码,需要libssh.我正在查看他们的教程页面,我看到它通过ssh_options_set()引用传递所有参数.这是为什么?

#include <libssh/libssh.h> 
#include <stdlib.h>

int main()
{
  ssh_session my_ssh_session;
  int verbosity = SSH_LOG_PROTOCOL;
  int port = 22;

  my_ssh_session = ssh_new();
  if (my_ssh_session == NULL)
    exit(-1);

  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
  ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); //here
  ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port); //here

  ...

  ssh_free(my_ssh_session);
}
Run Code Online (Sandbox Code Playgroud)

c linux pointers libssh

0
推荐指数
1
解决办法
140
查看次数