草庐IT

fixed_time

全部标签

python - 在 Python 中 : check if file modification time is older than a specific datetime

我用C#编写了这段代码来检查文件是否已过期:DateTime?lastTimeModified=file.getLastTimeModified();if(!lastTimeModified.HasValue){//Filedoesnotexist,soitisoutofdatereturntrue;}if(lastTimeModified.Value我如何用python编写这个?我在python中试过了。statbuf=os.stat(filename)if(statbuf.st_mtime我得到以下异常messagestr:unsupportedoperandtype(s)for-

python - "The set of methods, however, is fixed when the class is first defined"是真的吗?

来自ProgrammingLanguagePragmatics,byScottBothPythonandRubyaremoreflexiblethanPHPormoretraditionalobject-orientedlanguagesregardingthecontents(members)ofaclass.NewfieldscanbeaddedtoaPythonobjectsimplybyassigningtothem:my_object.new_field=value.Thesetofmethods,however,isfixedwhentheclassisfirstdefine

python - sklearn : User defined cross validation for time series data

我正在尝试解决机器学习问题。我有一个包含时间序列元素的特定数据集。对于这个问题,我使用了著名的python库-sklearn。这个库中有很多交叉验证迭代器。还有几个迭代器用于自己定义交叉验证。问题是我真的不知道如何为时间序列定义简单的交叉验证。这是我想要获得的一个很好的例子:假设我们有几个时期(年),我们想将我们的数据集分成几个block,如下所示:data=[1,2,3,4,5,6,7]train:[1]test:[2](ortest:[2,3,4,5,6,7])train:[1,2]test:[3](ortest:[3,4,5,6,7])train:[1,2,3]test:[4](

Python pytz : convert local time to utc. Localize 似乎没有转换

我有一个将日期时间存储为UTC的数据库。我需要查找特定时间的信息,但日期和时间是以本地时间给出的,比方说“欧洲/哥本哈根”。我得到的是:year=2012;month=12;day=2;hour=13;min=1;因此,我需要将它们转换为UTC,以便我可以在数据库中查找它们。我想使用pytz来做到这一点。我正在查看localize:local_tz=timezone('Europe/Copenhagen')t=local_tz.localize(datetime.datetime(year,month,day,hour,min))但我对localize()感到困惑。这是假设年份等是在本

python - 值错误 : time data '%Y-%m-%d %H:%M:%S' does not match format '2012-11-14 14:32:30'

这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭10年前。我正在尝试通过datetime.datetime.strptime将字符串'2012-11-1414:32:30'转换为datetime.datetime对象方法使用格式字符串'%Y-%m-%d%H:%M:%S'。这样做,我得到一个错误:ValueError:timedata'%Y-%m-%d%H:%M:%S'doesnotmatchformat'201

python - 内部类 : How can I get the outer-class object at construction time?

考虑以下Python(在2.x或3.x中运行):classOuter(object):passclassInner(object):def__init__(self):print("Inner.self",self)o=Outer()i=o.Inner()我想在Inner.__init__()中接触到o。但是:我不希望o成为Inner的显式参数。我希望O.Inner和o.Inner成为一个类对象,而不是像闭包那样奇怪的东西。你能建议我如何实现这一目标吗?目前我最好的想法是使用线程本地存储。在我的用例中,每当我构造一个o.Inner()时,我已经在某个地方的o上的方法中,这没什么大不了的

python - 计算time-1到time-2之间的时间?

entertime-1//eg01:12entertime-2//eg18:59calculate:time-1totime-2/12//i.etimebetween01:12to18:59dividedby12如何在Python中完成。我是初学者,所以我真的不知道从哪里开始。编辑添加:我不想要计时器。time-1和time-2都是用户手动输入的。预先感谢您的帮助。 最佳答案 您需要内置datetime模块中的datetime和timedelta类。fromdatetimeimportdatetime#Parsethetimestr

python - Pandas : histogram with fixed width

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭9年前。Improvethisquestion我有一些数据想做直方图,但我希望直方图从给定的值开始,并且条形的宽度是固定的。例如,对于系列[1,3,5,10,12,20,21,25],我想要,而不是>>>p.Series([1,3,5,10,12,20,21,25]).hist(bins=3).figure#||#|||#|||#08.517我希望条形的宽度为10:||||||||01020我该怎么做?编辑:我最终得到了我想要的

python - Python 中的 FIX 协议(protocol) - 实现流式报价的登录和请求

我正在尝试使用pythonquickfix(FIX4.2)实现基本的FIX请求,但是文档很少,我无法完全理解它(而且我做了很多研究,问题末尾的链接-所以请放心,这不是不做任何挖掘的问题)登录请求---A8=FIX.4.2|9=108|35=A|34=1|49=ACCOUNTXXX|52=20161116-00:00:15.281|56=CNX|553=ACCOUNTXXXSTR1|554=Stater123|98=0|108=60|141=Y|10=133|这将是预期的登录响应8=FIX.4.2|9=77|35=A|49=CNX|34=1|52=20161116-00:00:17.92

python - 正则表达式速度 : Python x6 times faster than C++11 under VS2013?

难道是python的Cregex实现快了6倍还是我遗漏了什么?Python版本:importrer=re.compile(r'(HELLO).+?(\d+)',re.I)s=r"prefixdfadfadfadfadfadfadfheasdfdHelloRegex123"%timeitr.search(s)1000000loops,bestof3:1.3µsperloop(769,000persec)C++11版本:#includeintmain(intargc,char*argv[]){std::strings="prefixdfadfadfadfadfadfadfheasdfdHe