小编Luk*_*eFu的帖子

Python datetime TypeError,期望的整数

我是Python的新手,所以希望我遇到的问题有一个简单的解决方案.

在工作中,我们总是使用Shell(ksh)或Perl进行所有脚本编写工作.由于python已经与Solaris一起发售了一段时间,它已经(最终)被作为脚本平台获得了绿灯.我已经开始使用Python对我们的脚本进行一些改进的原型设计.

我想要完成的是获取时间戳和表示时间戳的字符串,并为某些日期算术创建日期时间对象.

我的示例代码如下:

#!/bin/python

import datetime

fileTime="201009211100"
format = "YYYYmmdd"

yIdxS = format.find('Y')
yIdxE = format.rfind('Y')

if not fileTime[yIdxS:yIdxE+1].isdigit():
    print "ERROR: Year in wrong format"
    exit
else:
    print "Year [" + fileTime[yIdxS:yIdxE+1] + "]"

mIdxS = format.find('m')
mIdxE = format.rfind('m')

if not fileTime[mIdxS:mIdxE+1].isdigit():
    print "ERROR: Month in wrong format"
    exit
else:
    print "Month [" + fileTime[mIdxS:mIdxE+1] + "]"

dIdxS = format.find('d')
dIdxE = format.rfind('d')

if not fileTime[dIdxS:dIdxE+1].isdigit():
    print "ERROR: Day in wrong format"
    exit
else:
    print "Day [" + …
Run Code Online (Sandbox Code Playgroud)

python scripting

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

C++ STL Set:找不到()最后插入的元素

我正在编写一个应用程序,在该应用程序中我使用C++ STL中的Set类.我发现当我查询插入的最后一个元素时,对set-> find()的调用似乎总是失败.但是,如果我遍历集合,我能够看到我最初查询的元素.

为了试图弄清楚出了什么问题,我创建了一个示例应用程序,它展示了我所看到的相同行为.我的测试代码发布在下面.

对于实际的应用程序本身,我需要存储指向集合中对象的指针.这是导致奇怪行为的原因.或者是否有一个运算符我需要在类中重载我存储指针?

任何帮助,将不胜感激.

#include <stdio.h>
#include <set>

using namespace std;

#define MySet set<FileInfo *,bool(*)(const FileInfo *, const FileInfo*)>

class FileInfo
{
    public:
        FileInfo()
        {
            m_fileName = 0;
        }
        FileInfo( const FileInfo & file )
        {
            setFile( file.getFile() );
        }
        ~FileInfo()
        {
            if( m_fileName )
            {
                delete m_fileName;
                m_fileName = 0;
            }
        }
        void setFile( const char * file )
        {
            if( m_fileName )
            {
                delete m_fileName;
            }
            m_fileName = new char[ strlen( file ) + 1 ]; …
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

标签 统计

c++ ×1

python ×1

scripting ×1

stl ×1