小编Wor*_*Bee的帖子

Python:timezone.localize()不起作用

我有一些问题timezone.localize()正常工作.我的目标是抓住今天的日期并将其从CST转换为EST.然后在吐出之前最后格式化日期时间.我能够正确格式化日期,但日期时间不会从CST更改为EST.另外,当我格式化日期时,我没有看到包含时区的文本表示.

下面我列出了一个我创建的简单程序来测试它:

#! /usr/bin/python
#Test script

import threading
import datetime
import pexpect
import pxssh
import threading
from pytz import timezone
import pytz

est = timezone('US/Eastern')
curtime = est.localize(datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Z %Y"))
#test time change
#curtime = datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Z %Y")

class ThreadClass(threading.Thread):
  def run(self):
    #now = (datetime.datetime.now() + datetime.timedelta(0, 3600))
    now = (datetime.datetime.now())
    print "%s says Hello World at time: %s" % (self.getName(), curtime)

for i in range(3):
  t = ThreadClass()
  t.start()
Run Code Online (Sandbox Code Playgroud)

python timezone datetime

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

C ++ 错误:[函数名称] 之前的预期初始化程序

我正在用 C++ 更新我的自我(从学校开始就没有这样做过),我写了一个简单的程序只是为了捣乱。我的问题是,当我编译程序时,它会提示“错误:'stringThing' 之前的预期初始化程序”是否有这样做的原因?我知道这可能是一个菜鸟问题,所以我检查了 stackoverflow 并找不到任何给我答案的相关问题。

*我正在使用 GNU GCC 编译器

代码:

#include <iostream>

using namespace std;

void string stringThing (string shiftdir, string &teststring)
    {
        if (shiftdir == "right")
        {
           teststring = teststring >> " " >> "Bit Shifted right";
        }
        else
        {
           teststring = teststring << " " << "Bit Shifted left";
        }
    }
int main()
{

    string test;

    cout << stringThing("right", "I have done a ") << endl;

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

c++ gcc compiler-errors

7
推荐指数
1
解决办法
6万
查看次数

python pexpect:SSHing然后更新日期

我终于让我的python pexpect脚本工作,除了更新日期最重要的部分!我能够在框中SSH,但我的第二个命令没有正确执行.我一直在墙上试着找出原因.我检查了刺痛的输出,它应该基于编码的什么工作.我不是python或pexpect的专家所以我需要一些帮助来弄清楚为什么我的时间不更新.

我原来的代码:

list = ["089"]
sn = 0

ssh_new_conn = 'Are you sure you want to continue connecting'

class ThreadClass(threading.Thread):
def __init__(self, index):
super(ThreadClass, self).__init__()
self.index = index
def run(self):

sn = storelist[self.index]


#easterndate = (currenttime + datetime.timedelta(0, 3600))
#easterndate = easterndate

est = timezone('US/Eastern')
cst = timezone('US/Central')
#currenttime = (datetime.now())
currenttime = cst.localize(datetime.now())
#easterndate = (currenttime + timedelta(0, 3600))
#easterndate = easterndate.strftime("%a %b %d %H:%M:%S %Z %Y")
easterndate = currenttime.astimezone(est).strftime("%a %b %d %H:%M:%S %Z %Y")
command1 = …
Run Code Online (Sandbox Code Playgroud)

python ssh pexpect

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

如何使用 curl --ftp-create-dirs?

背景

我一直在网上搜索,试图找到一个--ftp-create-dirs.

总的来说,我的目标是使用“--ftp-create-dirs”自动创建必要的文件夹,如果它们在我上传文件时不存在。

问题

问题是我不知道正确使用的确切语法--ftp-create-dirs,有人可以帮助我吗?

我目前的卷曲:

curl -k -T 000-0000-0000-000.png -u [username]:[pass] --ftp-create-dirs /test --ftp-ssl  ftp:[ftp server]
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我尝试上传 .png 图像并/test在 ftp 服务器上创建(如果它不存在)。

bash curl centos curl-commandline

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

在LINUX上打开C中的O_NONBLOCKING

***背景****我是TCP的新手,所以我的问题可能有点基础.我试图在接收数据的套接字上打开O_NONBLOCK.到目前为止,我尝试了不同的方法来设置O_NONBLOCK,itcl()和fcntl().现在我想让fcntl()工作.

我的问题:您是否应该在连接套接字之前或之后设置O_NONBLOCK?

**我当前的fcntl()实现基于代码之前的链接:

如何将套接字重置回阻塞模式(在我将其设置为非阻塞模式后)?

//set socket to NONBlocking
on = fcntl(Socket,F_GETFL);
on = (on | O_NONBLOCK);
if(fcntl(Socket,F_SETFL,on) < 0)
    {
       perror("turning NONBLOCKING on failed\n");
    }

// DO CONNECT
rc = connect()
Run Code Online (Sandbox Code Playgroud)

感谢您抽出宝贵时间来看看这个

c sockets linux tcp

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

标签 统计

python ×2

bash ×1

c ×1

c++ ×1

centos ×1

compiler-errors ×1

curl ×1

curl-commandline ×1

datetime ×1

gcc ×1

linux ×1

pexpect ×1

sockets ×1

ssh ×1

tcp ×1

timezone ×1