小编Ric*_*ard的帖子

在python中剥离空格

好的,我知道这应该很简单......反正说:

line = "$W5M5A,100527,142500,730301c44892fd1c,2,686.5  4,333.96,0,0,28.6,123,75,-0.4,1.4*49"
Run Code Online (Sandbox Code Playgroud)

我想剥掉空间.我以为你会这样做的

line = line.strip()
Run Code Online (Sandbox Code Playgroud)

但现在行仍然是'$ W5M5A,100527,142500,730301c44892fd1c,2,686.5 4,333.96,0,0,2.6.6,123,75,-0.4,1.4*49'而不是'$ W5M5A,100527,142500,730301c44892fd1c,2,686.54,333.96 ,0,0,28.6,123,75,-0.4,1.4*49'

有什么想法吗?

python string

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

在循环中查找列表的索引

我有一个简单的问题.如果我在python中有一个for循环,如下所示:

for name in nameList:
Run Code Online (Sandbox Code Playgroud)

我如何知道元素名称的索引是什么?我知道我可以这样:

i = 0
for name in nameList:
    i= i + 1
    if name == "something":
        nameList[i] = "something else"
Run Code Online (Sandbox Code Playgroud)

我觉得应该有一种更易读的方式来做这件事......

python loops

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

如何从一个wx笔记本页面到另一个wx笔记本页面获取变量?

我想知道如何从wx笔记本将一页中的变量转换为另一页中的变量。我想如果我知道变量名称和页面ID,应该有某种方法可以引用变量。例如,如果我有以下代码,如何从面板y引用变量x,反之亦然

import wx

class PanelX(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        x = 3

class PanelY(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        y=4

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Main Frame", size = (500,450))

        p = wx.Panel(self)
        nb = wx.Notebook(p)

        nb.AddPage(PanelX(nb), "Panel X")
        nb.AddPage(PanelY(nb), "Panel Y")


        sizer = wx.BoxSizer()
        sizer.Add(nb, 1, wx.EXPAND)
        p.SetSizer(sizer)


if __name__ == "__main__":
    app = wx.App()
    MainFrame().Show()
    app.MainLoop()
Run Code Online (Sandbox Code Playgroud)

python wxpython

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

twitter Bootstrap折叠菜单不起作用

我正在使用这里为Bootstrap 找到的入门模板.css渲染得很好,但是当页面最小化时,可折叠菜单不起作用.IE,当我点击折叠按钮时,没有任何反应.

这是我到目前为止的代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap, from Twitter</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="../assets/js/html5shiv.js"></script>
    <![endif]-->

    <!-- Fav and touch …
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap

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

更改MySQL时区是否会更改数据库中DateTime字段的值?

我有一个设置为本地时区的MySQL数据库。尽管数据库使用不同的时区,但时间仍作为UTC时间插入。我想将时区更改为MySQL服务器上的UTC。我已经找到了有关如何执行此操作的文档,但是不愿意,因为我不知道这是否还会更改数据库中已存储的值。

我的问题:更改MySQL服务器的时区还会更改已经存储的值吗?

mysql

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

我如何在python中进行线程化?

使用本网站的代码:http://www.saltycrane.com/blog/2008/09/simplistic-python-thread-example/

代码是

import time
from threading import Thread

def myfunc(i):
    print "sleeping 5 sec from thread %d" % i
    time.sleep(5)
    print "finished sleeping from thread %d" % i

for i in range(10):
    t = Thread(target=myfunc, args=(i,))
    t.start()
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

sleeping 5 sec from thread 0
sleeping 5 sec from thread 1
sleeping 5 sec from thread 2
sleeping 5 sec from thread 3
sleeping 5 sec from thread 4
sleeping 5 sec from thread 5
sleeping 5 sec …
Run Code Online (Sandbox Code Playgroud)

python multithreading

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

如何保持Windows服务运行

下面是我正在运行的Windows服务的框架.如果发生错误,将记录错误并可在事件查看器中查看.问题是,即使我已将恢复设置为在第一次,第二次和后续故障时重新启动服务,脚本也会退出并且不会再次重新启动.目前我几乎没有错误处理,因为我想看看事件查看器中可能出现的错误,以便我可以编写代码来相应地处理这些错误.

from win32api import CloseHandle, GetLastError, SetConsoleCtrlHandler
import os
import sys 
import time
import pythoncom
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket

class AppServerSvc (win32serviceutil.ServiceFramework):
    _svc_name_ = "my_service_name"
    _svc_display_name_ = "my service"

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        SetConsoleCtrlHandler(lambda x: True, True)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)
        self.run = False

    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_,''))
        self.run = True
        self.main()

    def main(self):
        while self.run == True
            pass          

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)
Run Code Online (Sandbox Code Playgroud)

编辑:

我试着尝试:除了自我.但结果仍然是相同的.当它崩溃时服务没有重新开始......请有任何想法吗?如果一个服务在崩溃的情况下无法重新启动,那么这个服务并不是那么有用......不妨将它作为.pyc运行它

编辑:

下面是我的脚本中可能出现的错误示例...我不相信这个错误消息特别有用,因为我试图实现的是重新启动服务但是这里的一个例子是一个例子.在没有重新启动的情况下崩溃我的服务的错误:

The instance's SvcRun() …
Run Code Online (Sandbox Code Playgroud)

python windows-services

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

将dec数转换为6位二进制数

我希望将dec数转换为6位二进制数.. bin()工作正常,但省略重要的前导零.

例如:

  • 0 = 000000
  • 1 = 000001
  • 2 = 000010

等...允许的最大分数为63.

python binary bin

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

sh脚本找不到变量

我正在关注如何运行反向ssh隧道的教程,该隧道位于http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling我遇到的问题是当我运行tunneling.sh脚本时:

#!/bin/sh
a=`ps -ef | grep 19999 | grep -v grep`
if [ ! "$a" ]; then
    ssh -fN -R 19999:localhost:22 <middle-usename>@<middle-hostname>
fi
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

tunnel2.sh: 2: tunnel2.sh: a: not found
Run Code Online (Sandbox Code Playgroud)

编辑:

我将shebang改为#!/ bin/bash

现在我收到这个错误:

tunnel2.sh: 2: tunnel2.sh: pi: not found
Run Code Online (Sandbox Code Playgroud)

linux sh

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

更改jpgraph的边距颜色

我试图改变jpgraph上边距的颜色.我似乎无法弄明白.我试过$graph->SetMarginColor("khaki:0.6");但似乎什么也没做.下面是生成示例图表以及示例输出的代码.如果有帮助,我正在使用jpgraph 3.5.

$datay1 = array(20,15,23,15);
$datay2 = array(12,9,42,8);
$datay3 = array(5,17,32,24);

// Setup the graph
$graph = new Graph(300,250);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Filled Y-grid');
$graph->SetBox(false);

$graph->img->SetAntiAliasing();

$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->xgrid->SetColor('#E3E3E3');

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');

// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Line 2');

// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('Line 3');

$graph->legend->SetFrameWeight(1);

// Output line …
Run Code Online (Sandbox Code Playgroud)

php jpgraph

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