这段代码
#!/usr/bin/env python
import pynotify
import time
import datetime
c='5/1/12 1:15 PM'
print c
dt = time.strptime(c, "%d/%m/%y %H:%M %p")
Run Code Online (Sandbox Code Playgroud)
产生
5/1/12 1:15 PM
Traceback (most recent call last):
File "tmp.py", line 9, in <module>
dt = time.strptime(c, "%d/%m/%y %H:%M %p")
File "/usr/lib/python2.7/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: PM
Run Code Online (Sandbox Code Playgroud)
删除import pynotify
,
#!/usr/bin/env python
import time
import datetime
c='5/1/12 1:15 PM'
print c
dt = …
Run Code Online (Sandbox Code Playgroud) 有没有办法执行一些仅在控制台启动时运行的代码?有点像一个RC文件(.bashrc
,.zshrc
,等)?我发现自己总是做很多事情.
例如,我会把它放在哪里
u = User.find_by_username('my_console_user')
Run Code Online (Sandbox Code Playgroud)
这u
是可用的rails console
吗?
我已经诉诸于此,使用了$
全局变量声明,并使用了晦涩难懂console do
.我认为有些东西更优雅......
class Application < Rails::Application
#this is only executed in the console, also doens't seem to be documented anywhere but here: https://github.com/rails/rails/pull/3139
console do
$u1 = User.find_by_username('user1')
$u2 = User.find_by_username('user2')
end
end
Run Code Online (Sandbox Code Playgroud) Core Java API中的许多类都是final(包装类,字符串,数学).为什么会这样?
在我的CakePHP应用程序中,通过使用cake.bat我创建了POT文件并使用PoEdit我创建了PO文件.因此,通过编写__('myword'),我可以成功地在我的应用程序中看到本地化的单词.
但现在我需要本地化"timeAgoInWords".当我运行饼国际化提取物,剧本没有得到_dn()的话在CakeTime http://api20.cakephp.org/view_source/cake-time#line-522
所以我创建了一个dummy.ctp文件和从cake-time文件复制粘贴的内容到虚拟文件.我再次运行蛋糕脚本和POEdit.它创建了如下所示的实例到文件app/Locale/tur/LC_MESSAGES/default.po中
#: View\App\dummy.ctp:30;33
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] "%d dakika"
msgstr[1] "%d dakika"
Run Code Online (Sandbox Code Playgroud)
在core.php中,我已经将默认语言设置为土耳其语:
Configure::write('Config.language', 'tur');
Run Code Online (Sandbox Code Playgroud)
但是当我检查我的申请时,timeAgoInWords的结果是英文的.
我怎样才能解决这个问题
localization cakephp internationalization cakephp-2.0 timeago
嗨,大家好!
这不是一个大问题,但是,我想知道当你启用选项"公共语言运行时支持(/ clr)"时它是否需要".net框架"?
我有一个访问函数,它返回一个对类型(std :: map)的const引用......
myMap_t const& getMap() const {return paramMap;}
Run Code Online (Sandbox Code Playgroud)
该类型具有重载[]
运算符.然后[]
,以类似下面的方式直接从getter函数使用运算符的语法是什么,但这实际上有效.
parameter = contextObj.getMap()[key];
Run Code Online (Sandbox Code Playgroud)
错误信息是:
context.cpp:35: error: passing
'const std::map<
std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
float,
std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
std::allocator<std::pair<
const std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
float> > >'
as 'this' argument of
'_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&)
with
_Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
_Tp = float,
_Compare = std::less<std::basic_string<char, std::char_traits<char>, td::allocator<char> > >,
_Alloc = std::allocator<std::pair<
const std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
float> >]'
discards …
Run Code Online (Sandbox Code Playgroud) 我知道在unix世界中,如果编辑.profile或.cshrc文件,可以使用source~/.profile或source~/.cshrc来获取当前会话的效果.如果我在Windows上更改了系统变量中的某些内容,如何在不退出命令提示符会话并打开另一个命令提示符会话的情况下使其影响当前的命令提示符会话?
我正在使用d3来构建散点图,我对x和y轴的值集都有正值和负值.这是我第一次尝试使用d3,我从介绍性教程中收集过,例如在圣诞节的第十天,使用d3.js弄脏数据,关键是正确设置x和y比例.
接下来,我发现了这个教程:带有负值的条形图,这几乎帮助我做到了正确(我认为).我的数据集太大了,不能放在这里,但这里是代码我有一个我的数据样本:
<div id="compareAll"></div>
<script>
window.onload = function() {
var dataSet = [ [4,4], [-4,4], [-4,-4], [4,-4], ];
var x0 = Math.max(-d3.min(dataSet[0]), d3.max(dataSet[0]));
var xScale = d3.scale.ordinal()
.domain([-x0,x0])
.range([0,10]);
var yScale = d3.scale.ordinal()
.domain(d3.range(dataSet[1])
.rangeRoundBands([0,10]);
var svg = d3.select("#compareAll")
.append("svg")
.attr("width", 10)
.attr("height",10)
svg.selectAll("circle")
.data(dataSet)
.enter()
.append("circle")
.attr("cx", function(d) {
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
.attr("r",4);
var xAxis = d3.svg.axis()
.scale(xScale)
.tickSize(1);
var yAxis = d3.svg.axis()
.scale(yScale)
.tickSize(1);
svg.append("svg:g")
.attr("class", "x axis") …
Run Code Online (Sandbox Code Playgroud) 我为项目实现了自定义UITabBar解决方案.基本上,如果有超过5个项目,我使用scrollView,允许用户滚动其他选项卡项并禁止更多按钮.在Weather Channel应用程序中可以看到类似的外观.
每个标签栏项对应于管理每个选项卡的视图堆栈的UINavigationController.我遇到的问题是,当我有超过5个标签项时,从标签5开始不能正确维护导航堆栈.似乎每次返回到该选项卡时,moreNavigationController都会杀死导航堆栈,并且您将再次进入初始页面.
我已经重写了setSelectedViewController方法,如下所示:
- (void) setSelectedViewController:(UIViewController *)selectedViewController {
[super setSelectedViewController:selectedViewController];
if ([self.moreNavigationController.viewControllers count] > 1) {
self.moreNavigationController.viewControllers = [[NSArray alloc] initWithObjects:self.moreNavigationController.visibleViewController, nil];
}
}
Run Code Online (Sandbox Code Playgroud)
此代码将删除左侧导航按钮上的"更多"功能,但不能解决维护导航堆栈的问题.所有其他标签工作正常.我可以遍历几个视图,并在离开并返回到该选项卡后保持堆栈.我知道这是一个复杂的问题,所以如果有一些方面我可以提供清晰度,请告诉我.谢谢!
我正在尝试使用以下方法将十六进制值转换为float(Python 2.7):
def hex2float(x):
y = 0
z = x.decode('hex')
try:
y = struct.unpack('!f', z)[0]
except:
print sys.exc_info()[1]
print 'z = ' + z
print 'y = %s' % (y)
print 'x = ' + x
return
def foo28():
x = '615885' #8.9398e-039
hex2float(x)
Run Code Online (Sandbox Code Playgroud)
输出如下:
unpack requires a string argument of length 4
z = aXà
y = 0
x = 615885
Run Code Online (Sandbox Code Playgroud)
我注意到我得到了非常小的值的异常消息.在这种情况下,是否有正确的方法将十六进制值转换为浮点值.