问题列表 - 第43345页

如何按字符串的长度排序,然后按字母顺序排序?

我现在是python的新手并且遇到了这个问题,似乎找不到合适的答案.

问题:给定一个单词列表,按照长度(最长到最短)的顺序返回一个具有相同单词的列表,第二个排序标准应该是按字母顺序排列的.提示:你需要考虑两个功能.

这是我到目前为止:

def bylength(word1,word2):
    return len(word2)-len(word1)

def sortlist(a):
    a.sort(cmp=bylength)
    return a
Run Code Online (Sandbox Code Playgroud)

它按长度排序,但我不知道如何将第二个标准应用于此类,即按字母顺序降序.

python sorting

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

为什么不能抓住内在的异常呢?

我试图在数据库服务器关闭时捕获数据库异常.我们使用Sybase IAnywhere.

我使用常规的C#try catch来获取数据库异常的名称.

try
{
//code here
}
catch (Exception ex)
{
Logging.Log.logItem(LogType.Exception, "Exception in isDBRunning", "App_Startup::isDBRunning() ", "GetBaseException=" + ex.GetBaseException().ToString() + "\nMessage=" + ex.Message + "\nStackTrace: " + ex.StackTrace + "\nInnerException: " + ex.InnerException);
}
Run Code Online (Sandbox Code Playgroud)

打印例外是这样的:

GetBaseException=iAnywhere.Data.SQLAnywhere.SAException: Database server not found
   at iAnywhere.Data.SQLAnywhere.SAConnection.Open()
   at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
Message=The underlying provider failed on Open.
StackTrace:    at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
   at System.Data.EntityClient.EntityConnection.Open() …
Run Code Online (Sandbox Code Playgroud)

.net c# exception-handling exception

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

在另一个git仓库中维护git repo

这是我想要的:

REPO-A
  /.git
  /otherFiles
  /REPO-B
    /.git
    /moreFiles
Run Code Online (Sandbox Code Playgroud)

我希望能够将所有 REPO-A的内容推送到REMOTE-A并且只将 REPO-B 推送到REMOTE-B.

可能?

git version-control github

106
推荐指数
5
解决办法
6万
查看次数

Android,在谷歌地图上绘制路线

在我的android项目中,我想在Google地图上绘制路线.我有起点和终点的坐标.在这一点上,我km从谷歌网络服务获得-file,其中包含跨越路线的分数.对于绘制路径的部分,我使用Overlay类的实例.这个解决方案有效,但速度很慢.还有其他方法吗?可能存在能力使用内置谷歌地图应用程序或任何其他方式?

api android google-maps geolocation google-directions-api

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

openGL纹理只显示纹理的红色成分

我试图将图像纹理映射到单个多边形.我的图像正在被正确读取,但只有图像的红色平面被纹理化.

我在QGLWidget中这样做

我在读完后检查了图像,并且正在正确读取组件 - 即,我得到绿色和蓝色平面的有效值.

这是代码

QImageReader    *theReader = new QImageReader();

theReader->setFileName(imageFileName);
QImage  theImageRead = theReader->read();
if(theImageRead.isNull())
    {
        validTile = NOT_VALID_IMAGE_FILE;
        return;
    }
else
    {
        int newW = 1;
        int newH = 1;
        while(newW < theImageRead.width())
            {
                newW *= 2;
            }
        while(newH < theImageRead.height())
            {
                newH *= 2;
            }
        theImageRead = theImageRead.scaled(newW, newH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
// values checked in theImageRead are OK here
        glGenTextures(1,&textureObject);
        theTextureImage = QGLWidget::convertToGLFormat(theImageRead);
// values checked in theTextureImage are OK here
        glBindTexture(GL_TEXTURE_2D, textureObject);
        glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,newW, newH, 0, …
Run Code Online (Sandbox Code Playgroud)

opengl qt texture-mapping

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

如何在xmlrpc服务器上查看回溯,而不是客户端?

我有简单的xmlrpc服务器代码:

from SimpleXMLRPCServer import SimpleXMLRPCServer

port = 9999

def func():
    print 'Hi!'
    print x # error!
    print 'Bye!'

if __name__ == '__main__':
    server = SimpleXMLRPCServer(("localhost", port))
    print "Listening on port %s..." % port
    server.register_function(func)
    server.serve_forever()
Run Code Online (Sandbox Code Playgroud)

示例会话.

客户:

>>> import xmlrpclib
>>> p = xmlrpclib.ServerProxy('http://localhost:9999')
>>> p.func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\Python26\lib\xmlrpclib.py", line 1253, in request
    return …
Run Code Online (Sandbox Code Playgroud)

python multithreading simplexmlrpcserver xmlrpclib xmlrpcclient

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

将嵌入的CSS文件嵌入到多部分MIME电子邮件中

是否有可能像图像一样将CSS文件嵌入到mutlipart Mime电子邮件正文消息中,并使用cid在消息正文中引用这些样式:(与图像可能的方式相同)?

css mime html-email

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

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

Matplotlib:在多个线程中同时绘图

我正在尝试并行绘图以更快地完成大批量作业.为此,我为我计划制作的每个剧情开始一个主题.

我曾希望每个线程都能完成它的绘图并自行关闭(据我所知,当Python通过run()中的所有语句时,它会关闭线程).下面是一些显示此行为的代码.

如果创建图形的行已注释掉,则按预期运行.另一个看似合情合理的消息是,当你只生成一个线程时,它也会按预期运行.

import matplotlib.pyplot as plt
import time
import Queue
import threading

def TapHistplots():
    ##  for item in ['str1']:
# # it behaves as expected if the line above is used instead of the one below
    for item in ['str1','str2']:
        otheritem = 1
        TapHistQueue.put((item, otheritem))
        makeTapHist().start()

class makeTapHist(threading.Thread):
    def run(self):
        item, otheritem = TapHistQueue.get()
        fig = FigureQueue.get()
        FigureQueue.put(fig+1)
        print item+':'+str(fig)+'\n',
        time.sleep(1.3)
        plt.figure(fig) # comment out this line and it behaves as expected
        plt.close(fig)

TapHistQueue = Queue.Queue(0)
FigureQueue = Queue.Queue(0) …
Run Code Online (Sandbox Code Playgroud)

python multithreading matplotlib python-multithreading

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

使用DefaultHttpClient设置语言环境?

我正在使用DefaultHttpClient建立http连接.我认为我们可以在建立连接时在http标头[http accept-language]中设置首选语言环境,服务器可以检查并以匹配语言(如果需要)发回内容.

任何人都知道这是否可行,或者如何使用DefaultHttpClient进行此操作?

谢谢

java android httpclient

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