在python中,我可以在迭代时轻松获得索引
>>> letters = ['a', 'b', 'c']
>>> [(char, i) for i, char in enumerate(letters)]
[('a', 0), ('b', 1), ('c', 2)]
Run Code Online (Sandbox Code Playgroud)
我怎么能用linq做类似的事情?
我正在编写一个C代码,其中我的长度为2的char数组包含String My但是使用puts()将其打印到Screen.我得到了这个输出
我的£■0√"
这样的代码是什么原因???
如果我的数组长度为2,那我怎样才能获得长度为2+的输出?
在我的layout.phtml档案中,我有:
<?php echo $this->Test(); ?>
Run Code Online (Sandbox Code Playgroud)
我已经创建了一个Test视图助手 application/views/helpers/Test.php
<?php
class My_View_Helper_Test extends Zend_View_Helper_Abstract {
public function Test() {
return 'test';
}
}
Run Code Online (Sandbox Code Playgroud)
我的配置文件@ configs/application.ini:
resources.view[] = ''
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
Zend_Loader_PluginLoader_Exception:在注册表中找不到名称为"Test"的插件; 使用的路径:第406行的Zend_View_Helper_:Zend/View/Helper /:./ views/helpers/in /usr/share/php/Zend/Loader/PluginLoader.php
在类似的说明我也无法注册我的管理员视图助手..
resources.view.helperPath.Admin_View_Helper = APPLICATION_PATH "/modules/admin/views/helpers"
Run Code Online (Sandbox Code Playgroud)
我的modules/admin/views/helpers/AdminPanel.php:
<?php
class My_View_Helper_AdminPanel extends Zend_View_Helper_Abstract {
public function AdminPanel() { return 'test'; }
}
Run Code Online (Sandbox Code Playgroud)
除了使用addHelperPath在Bootstrap中做到这一点,我别无选择吗?如果是这样,有人可以证明我将如何使用我的路径?
在类构造函数中使用异常处理代码是否合法,还是应该避免?应该避免在构造函数中生成异常代码吗?
警告:Noob在这里.
我知道这是一个微不足道的主题,但是我很难弄清楚如何通过将他们的部分内容转化为帮助来简化我的观点.例如,我一直认为你的视图中的条件是提取助手的主要候选者,但我无法找到这样的例子,而我实现这一目标的尝试失败了.
例如,假设我有:
#index.html.erb
<% for beast in @beasts do -%>
<% if beast.dead? -%>
<%= beast.body %>
<%= link_to "bury", bury_beast_path( :id => beast.id ) %>
<% else -%>
<%= beast.body %>
<%= link_to "kill!", kill_beast_path( :id => beast.id ) %>
<% end -%>
<% end -%>
Run Code Online (Sandbox Code Playgroud)
在我看来,这让我有点恼火,但我怎么能把它转移到助手呢?如果可能的话,进一步简化它.(我已经读到某个条件很糟糕的地方,但是如果没有它们,你可以编程任何东西.)
又如:我需要id我body的格式标记controller_action.到目前为止我得到的最好的是:
#index.html.erb
<body id="<%= controller_action %>">
Run Code Online (Sandbox Code Playgroud)
…和…
#application_helper.rb
def controller_action
@id = @controller.controller_name + "_" + @controller.action_name
end
Run Code Online (Sandbox Code Playgroud)
我不是专家,但即使对我来说,这仍然是丑陋的.
为了使事情变得更复杂,Ryan Singer说了一些我喜欢的事情:将ERB视为图像标签,使用帮助器"揭示意图".然后在下一次呼吸说你应该没有助手的HTML,这是地狱的方式.WTF?两者如何兼容?如果它可以在视图中声明行为,那么肯定应该在幕后呈现大量的HTML吗?我无法掌握它.
所以,基本上就是这样.我很感激,如果有人可以分享一些关于这方面的想法,或者指出我对这个主题有一些深入的阅读 - …
我希望能够做的是构建一个LINQ查询,当其中一个字段发生变化时,它会从某些DataRows中检索一些值.这是一个人为的例子来说明:
Observation Temp Time
------------- ---- ------
Cloudy 15.0 3:00PM
Cloudy 16.5 4:00PM
Sunny 19.0 3:30PM
Sunny 19.5 3:15PM
Sunny 18.5 3:30PM
Partly Cloudy 16.5 3:20PM
Partly Cloudy 16.0 3:25PM
Cloudy 16.0 4:00PM
Sunny 17.5 3:45PM
Run Code Online (Sandbox Code Playgroud)
当观察从前一个观察发生变化时,我只想检索条目.所以结果将包括:
Cloudy 15.0 3:00PM
Sunny 19.0 3:30PM
Partly Cloudy 16.5 3:20PM
Cloudy 16.0 4:00PM
Sunny 17.5 3:45PM
Run Code Online (Sandbox Code Playgroud)
目前有代码迭代DataRows并进行结果的比较和构建,但希望使用LINQ来实现这一目标.
我想做的是这样的事情:
var weatherStuff = from row in ds.Tables[0].AsEnumerable()
where row.Field<string>("Observation") != weatherStuff.ElementAt(weatherStuff.Count() - 1) )
select row;
Run Code Online (Sandbox Code Playgroud)
但这不起作用 - 并且不会编译,因为它在声明之前尝试使用变量'weatherStuff'.
可以用LINQ做我想做的事吗?我在SO上没有看到像这样的另一个问题,但可能错过了它.
我正在为作业编写一个"日期"类,我无法完成其中一项功能.
这是该类的头文件.
class Date
{
public:
Date(); // Constructor without parameters
Date(int m, int d, int y); // Constructor with parameters.
// accessors
int GetMonth(); // returns the size of the diamond
int GetDay();
int GetYear();
// mutators
bool Set(int m, int d, int y);
bool SetFormat(char f);
// standard input and output routines
void Input();
void Show();
void Increment(int numDays = 1);
int Compare(const Date& d);
private:
int month, // month variables
day, // day variable
year; // year …Run Code Online (Sandbox Code Playgroud) 我更喜欢在我声明参数的同一行记录每个参数(根据需要)以便应用DRY
如果我有这样的代码:
def foo(
flab_nickers, # a series of under garments to process
has_polka_dots=False,
needs_pressing=False # Whether the list of garments should all be pressed
):
...
Run Code Online (Sandbox Code Playgroud)
如何避免重复doc字符串中的参数并保留参数说明?
我想避免:
def foo(
flab_nickers, # a series of under garments to process
has_polka_dots=False,
needs_pressing=False # Whether the list of garments should all be pressed
):
'''Foo does whatever.
* flab_nickers - a series of under garments to process
* needs_pressing - Whether the list of garments should all be pressed.
[Default …Run Code Online (Sandbox Code Playgroud) 我怀疑我们是否可以使用'模块'概念实现多重继承?还是有任何其他关键字或概念在ruby中实现多重继承?
我正在使用Eclipse Android插件来构建项目,但是我在控制台窗口中收到此错误:
[2010-02-03 10:31:14 - androidVNC]Error generating final archive:
Debug certificate expired on 1/30/10 2:35 PM!
Run Code Online (Sandbox Code Playgroud)
我如何解决它?