所以我试图使用os.walk()来生成目录结构的XML表示.我似乎得到了大量的重复.它正确地将目录放在彼此之间,并将文件放在xml文件的第一部分的正确位置; 但是,在它正确完成后,它会继续错误地遍历.我不太清楚为什么......
这是我的代码:
def dirToXML(self,directory):
curdir = os.getcwd()
os.chdir(directory)
xmlOutput=""
tree = os.walk(directory)
for root, dirs, files in tree:
pathName = string.split(directory, os.sep)
xmlOutput+="<dir><name><![CDATA["+pathName.pop()+"]]></name>"
if len(files)>0:
xmlOutput+=self.fileToXML(files)
for subdir in dirs:
xmlOutput+=self.dirToXML(os.path.join(root,subdir))
xmlOutput+="</dir>"
os.chdir(curdir)
return xmlOutput
Run Code Online (Sandbox Code Playgroud)
fileToXML只是解析列表,所以不必担心.
目录结构很简单:
images/
images/testing.xml
images/structure.xml
images/Hellos
images/Goodbyes
images/Goodbyes/foo
images/Goodbyes/bar
images/Goodbyes/square
Run Code Online (Sandbox Code Playgroud)
并生成的xml文件变为:
<structure>
<dir>
<name>images</name>
<files>
<file>
<name>structure.xml</name>
</file>
<file>
<name>testing.xml</name>
</file>
</files>
<dir>
<name>Hellos</name>
</dir>
<dir>
<name>Goodbyes</name>
<dir>
<name>foo</name>
</dir>
<dir>
<name>bar</name>
</dir>
<dir>
<name>square</name>
</dir>
</dir>
<dir>
<name>foo</name>
</dir>
<dir>
<name>bar</name>
</dir>
<dir> …Run Code Online (Sandbox Code Playgroud) 我一直在寻找答案,并找到了许多更复杂的问题,但没有一个给我足够的洞察力来解决这个问题.
我在做什么:
1-打开一个可能很大的数字的页面
2-获取该数字所在的X路径并将其存储到变量
3-做一个javascript来比较上面存储的变量来查看是否它大于10,如果是这样,将一个新变量设置为true; 否则为false(因为这是默认值)
4-验证#3中的变量是否为真
听起来很简单,不是吗?
出错的地方:
在步骤3,不允许比较步骤#2到10的变量,至少不是我写它的方式.
为什么?
细节:
<tr>
<td>open</td>
<td>http://www.google.com/search?hl=en&q=selenium+verifyEval</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>/html/body/div[5]/div/p/b[3]</td>
<td>resultCount</td>
</tr>
<tr>
<td>storeEval</td>
<td>var isMoreThan10 = new Boolean(); isMoreThan10 = (resultCount > 10);</td>
<td>isMoreThan10</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${isMoreThan10}</td>
<td>true</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我只想到了一个可能的解决方法:扩展javascript代码以获取值并将其分配给变量,这样我就更有可能在javascript中使用该变量.不知道到底怎么做 - 有人想帮忙吗?
但肯定有更好的方法,不是吗?我必须能够在Selenium中为变量赋值,然后在下一行中使用javascript中的变量,对吗?
关于Microsoft的通知区域建议,我正在寻找想法或Delphi组件来实现Notification Area Flyouts.

第一个"自然"的想法是使用标准的Delphi表单,但我面临两个问题:
我会感谢任何线索或组件来实现它:)
最好的祝福.
jachguate.
PS.在Win7(Delphi)中将通知区域图标转换为程序图标时存在相关问题.
更新[0] 我还在寻找建议.@skamradt答案看起来非常好,但遗憾的是在实践中效果不佳.
更新[1] 最后,在调用SetForegroundWindog强制弹出"激活"后,自动关闭行为正在使用WM_ACTIVATE消息
begin
FlyoutForm.Show;
SetForegroundWindow(FlyoutForm.Handle);
end;
Run Code Online (Sandbox Code Playgroud)
现在,我正在寻找建议来达到边界行为和视觉风格,因为最接近的行为是使用样式实现的WS_POPUP或WS_DLGFRAME,而最接近的视觉目标是将WSFOPUP或WS_THICKFRAME设置为样式.
我刚刚重构了一个同事的代码,粗略地看起来像这样......
public class Utility
public void AddHistoryEntry(int userID, HistoryType Historytype, int companyID)
{
// Do something...
}
public void AddHistoryEntry(int userID, HistoryType historyType, int companyID, string notes)
{
// Do something...
}
}
Run Code Online (Sandbox Code Playgroud)
对此......
public class HistoryEntry
{
public long UserID { get; private set; }
public HistoryType HistoryType { get; private set; }
public long CompanyID { get; set; }
public string Notes { get; set; }
public HistoryEntry(long userID, HistoryType historyType)
{
this.UserID = userID;
this.HistoryType = historyType; …Run Code Online (Sandbox Code Playgroud) 我正在使用PDO类创建的一系列查询,在某些情况下,我的查询需要相同的参数.我已经创建了一个在foreach语句中使用的数组,它保存数据,但是一些变量来自外部,我可以在一个查询中使用这两个数据吗?
这个例子:
// $connection is the PDO object;
// $full_data contains:
// $full_data[$i]["address"]
// $full_data[$i]["phone"]
// $full_data[$i]["email"]
// $full_data[$i]["user_id"]
// $full_data[$i]["surname"] // not used but present
// $full_data[$i]["name"] // not used but present
$sql = "UPDATE users_table SET city = :address, phone = :phone, email = :email, admin_id = :admin_id, admin_name = :admin_name WHERE user_id = :user_id";
$statement = $connection->prepare ($sql);
$statement->bindParam (':admin_id', trim($admin_id), PDO::PARAM_INT);
$statement->bindParam (':admin_name', trim($admin_name), PDO::PARAM_STR);
foreach ($full_data as $value) {
$ok = $statement->execute ($value);
$num = …Run Code Online (Sandbox Code Playgroud) Apple 改变了他们在Max OS X 10.6中计算KB,MB和GB的方式.他们使用1000而不是1024.
我的问题是如何在我的代码中处理这个问题?我正在尝试释放空间量,所以我得到了字节数NSFileManager.当我向用户显示时,我需要根据它们是10.5还是10.6将其转换为GB.
是否有GB大小的内置常量?(或者无论你怎么称呼1024号码?)定义自己的数字似乎有点傻.
## I'm currently doing something like this.
if (running10_6) {
double gbConst = 1000 * 1000 * 1000;
} else {
double gbConst = 1024 * 1024 * 1024;
}
NSDictionary *attr = [NSFM attributesOfFileSystemForPath:@"/" error:&error];
double bytes = [[attr objectForKey:NSFileSystemFreeSize] doubleValue];
double freeGB = bytes / gbConst;
Run Code Online (Sandbox Code Playgroud) 我想要一个在Windows上支持Unicode的shell.它出货的PowerShell似乎没有.
PowerShell V2(Windows 7 x64):
PS C:\> powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode_char=unichr(0xf12)
>>> unicode_char
u'\u0f12'
>>> print unicode_char
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python26\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0f12' in position …Run Code Online (Sandbox Code Playgroud) 对于一系列合格调用的Eclipse格式化规则(即Builder模式样式),我非常沮丧.例如,以下是我创建新的Apache Commons CLI Options对象的一些代码的首选格式:
Options options = new Options()
.addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit")
.addOption(OptionBuilder.withLongOpt(OPTION_PROPERTIES)
.hasArg()
.withArgName("FILE")
.withType(File.class)
.withDescription("specify a user properties file")
.create());
Run Code Online (Sandbox Code Playgroud)
即,参数在必要时被包装和缩进,除非必要,所有合格的调用都被包装并缩进(如果有多个).如果参数列表包含在限定调用内,则调用应首先包装.
Eclipse中的默认格式(参数和调用"仅在必要时换行")会产生以下混乱:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit").addOption(
OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName(
"FILE").withType(File.class).withDescription(
"specify a user properties file").create());
Run Code Online (Sandbox Code Playgroud)
进入"Java代码样式 - >格式化程序 - >行换行"和换行设置为"包装所有元素,除了第一个元素,如果没有必要",调用产生:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print …Run Code Online (Sandbox Code Playgroud) 我们有一个基于硒网格的自动化测试集群.
为了管理集群,我构建了一组Rake(Ruby)任务,可以启动,重启,ping和停止节点.我正在通过IE6,IE7和IE8等多种浏览器测试我们的应用程序.这意味着群集中的每个节点都必须知道安装了哪个版本的IE,以便它可以声明正确的selenium-grid配置文件名称(例如:"IE6 on Windows XP"vs. "IE8 on Windows Vista"),以便可以针对这些浏览器编写某些测试.
我的问题:
我想在这里减少配置工作.如何以编程方式确定当前系统上运行的IE版本?我尝试了以下技术:
wmic product where "Vendor like '%Microsoft%'" get Name, Version
Run Code Online (Sandbox Code Playgroud)
但这只返回随Windows Installer一起安装的程序版本,因此IE不会显示在此列表中.
理想情况下,我希望能够从Rake脚本中确定这个,或者至少可以从Rake脚本中调用.
在用户界面方面,我似乎总是有这种内部斗争.我构建了一个应用程序"引擎",并且在我的算法工作之后倾向于推迟用户界面.然后我来回试图决定如何让用户与我的程序进行交互.就个人而言,我是命令行的粉丝,但我不能指望我的用户.
我非常喜欢在web 2.0和ajax时代的浏览器中可能实现的功能.另一方面,制作Swing前端也不是那么难,而且你通常可以依赖于更一致的用户呈现(尽管使用像YUI或jQuery这样的好的javascript框架对于规范浏览器有很长的路要走).
显然,这两种方法都有其优点和缺点.那么,什么标准/参数/情况应该让我使用轻量级(例如基于Web的)GUI?什么标准/参数/情况应该让我使用更重(例如基于Swing)的GUI?
我不打算开始一场火焰战,只是对社区的建设性/客观意见感兴趣.
编辑#1 鉴于前几个回复,我想澄清一下,我想部署我的应用程序,而不是必须在某些互联网服务器上托管它.所以我必须部署一个轻量级的Web服务器基础设施,一个Jetty/Tomcat或类似的.
java ×2
python ×2
windows ×2
.net ×1
ajax ×1
class-design ×1
cocoa ×1
code-design ×1
delphi ×1
eclipse ×1
exception ×1
javascript ×1
math ×1
mysql ×1
objective-c ×1
os.walk ×1
pdo ×1
php ×1
powershell ×1
rake ×1
recursion ×1
ruby ×1
scripting ×1
selenium ×1
swing ×1
unicode ×1
windows-7 ×1
xml ×1