我试图将我在Video :: Filename Perl模块中找到的以下Perl正则表达式转换为Python 2.5.4正则表达式来解析文件名
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]*)?(?<openb>\[)?(?<season>\d{1,2})[x\/](?<episode>\d{1,2})(?:-(?:\k<season>x)?(?<endep>\d{1,2}))?(?(<openb>)\])(?:[\s._-]*(?<epname>[^\/]+?))?$',
Run Code Online (Sandbox Code Playgroud)
我也想使用命名组,我在Python中知道命名组的正则表达式扩展是不同的,但我对语法不是100%肯定.
这是我试过的:
# Python (not working)
r = re.compile(r'^(?:(?P<name>.*?)[\/\s._-]*)?(?P<openb>\[)?(?P<season>\d{1,2})[x\/](?P<episode>\d{1,2})(?:-(?:\kP<season>x)?(?P<endep>\d{1,2}))?(?(P<openb>)\])(?:[\s._-]*(?P<epname>[^\/]+?))?$')
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
raise error, v # invalid expression
sre_constants.error: bad character in group name
Run Code Online (Sandbox Code Playgroud)
例如,这个我设法转换,它的工作原理.但上面的那个我似乎无法做对.我在Python中遇到了编译错误.
# Perl:
re => '^(?:(?<name>.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(?<season>\d{1,2})[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(?<episode>\d{1,2})(?:-?(?:(?:e|ep)[\s._]*)?(?<endep>\d{1,2}))?(?:[\s._]?(?:p|part)[\s._]?(?<part>\d+))?(?<subep>[a-z])?(?:[\/\s._-]*(?<epname>[^\/]+?))?$',
# Python (working):
r = re.compile(r'^(?:(?P<name>.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(?P<season>\d{1,2})[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(?P<episode>\d{1,2})(?:-?(?:(?:e|ep)[\s._]*)?(?P<endep>\d{1,2}))?(?:[\s._]?(?:p|part)[\s._]?(?P<part>\d+))?(?P<subep>[a-z])?(?:[\/\s._-]*(?P<epname>[^\/]+?))?$')
Run Code Online (Sandbox Code Playgroud)
我不知道从哪里开始寻找.
我想写一个模糊日期方法来计算iPhone的Objective-C中的日期.这里有一个流行的解释:
但它包含缺少的参数.怎么能在Objective-C中使用它?谢谢.
const int SECOND = 1;
const int MINUTE = 60 * SECOND;
const int HOUR = 60 * MINUTE;
const int DAY = 24 * HOUR;
const int MONTH = 30 * DAY;
if (delta < 1 * MINUTE)
{
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
}
if (delta < 2 * MINUTE)
{
return "a minute ago";
}
if (delta < 45 * MINUTE)
{
return ts.Minutes + …Run Code Online (Sandbox Code Playgroud) 最简单的说法是"项目档案".我有几个python项目,我使用emacs W32 for Windows使用ropemacs.理想的是,如果我可以在我的桌面上点击一个图标来打开emacs,打开绳子项目,并在该项目的顶级目录中设置速度栏.然后我也许可以有办法以相同的方式在自己的emacs中打开下一个项目(但是对于那个项目).当然,如果有一个emacs命令或一个shell命令我可以使用它来实现相同的效果而不是桌面上的图标也是可以接受的.
有没有办法做到这一点?我绝对没有elisp-fu.:-(
Perl中的$1穿越范围是什么$9?例如,在此代码中:
sub bla {
my $x = shift;
$x =~ s/(\d*)/$1 $1/;
return $x;
}
my $y;
# some code that manipulates $y
$y =~ /(\w*)\s+(\w*)/;
my $z = &bla($2);
my $w = $1;
print "$1 $2\n";
Run Code Online (Sandbox Code Playgroud)
会$1是什么?这将是第一个\w*从$x或第一\d*与第二\w*的$x?
当我试图从Eclipse开始我的JUnit-Test时,我得到一个"ClassNotFoundException".从控制台运行"mvn test"时 - 一切正常.此外,Eclipse中没有报告任何问题.
我的项目结构如下:
编辑:如何找不到课程?这是一个简单的HelloWorld-Application,没有特殊的库.
这是我的JUnit的运行配置: alt text http://www.walkner.biz/_temp/runconfig.png
Testclass(但正如我所说;它不适用于简单的HelloWorld ......):
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import biz.prognoserechnung.domain.User;
import biz.prognoserechnung.domain.UserRepository;
import biz.prognoserechnung.domain.hibernate.UserHibernateDao;
public class UserDaoTest {
/**
* the applicationcontext.
*/
private ApplicationContext ctx = null;
/**
* the user itself.
*/
private User record = null;
/**
* Interface for the user.
*/
private UserRepository dao = null;
@Before
public void setUp() throws Exception { …Run Code Online (Sandbox Code Playgroud) 我有一个QMainWindow.它有这个参数:
Run Code Online (Sandbox Code Playgroud)this->setWindowFlags(Qt::Tool); this->setFocusPolicy(Qt::StrongFocus); this->setAttribute(Qt::WA_QuitOnClose,true);
在showEvent调用后,我的窗口显示但未激活.我试着重载show function:
...
QMainWindow::showEvent(event);
this->activateWindow();
...
Run Code Online (Sandbox Code Playgroud)
但它对我没有帮助.
编辑: 当我评论行
this->setWindowFlags(Qt::Tool);
Run Code Online (Sandbox Code Playgroud)
一切正常,但我需要在工具标志.有任何想法吗?
编辑:
我可以使用Dashcode开发可以在应用商店中销售的应用程序吗?
如果成功,SQLite中的"insert"语句会返回什么?
我一直认为它应该是SQLITE_DONE,但最近在我的日志中我发现了以下字符串:
sqlite3_step error: 'not an error'
Run Code Online (Sandbox Code Playgroud)
以下是记录上述字符串的代码:
prepareStatement(addTranslationStmt2, "INSERT INTO translations(lang1_wordid, lang2_wordid) VALUES(?, ?)");
if (!addTranslationStmt2) return -2;
sqlite3_bind_int(addTranslationStmt2, 1, word_id);
sqlite3_bind_int(addTranslationStmt2, 2, translation_id);
if(sqlite3_step(addTranslationStmt2) != SQLITE_DONE)
{
NSLog(@"sqlite3_step error: '%s'", sqlite3_errmsg(database));
sqlite3_reset(addTranslationStmt2);
return -1;
}
sqlite3_reset(addTranslationStmt2);
Run Code Online (Sandbox Code Playgroud)
我想知道,为什么它在大多数情况下都有效.我应该将代码中的SQLITE_DONE更改为SQLITE_OK吗?
谢谢.
我刚刚开始使用Prolog,我无法弄清楚为什么以下内容无法正常工作.我正在尝试创建一个谓词,如果列表L2包含在L1中,则该谓词返回true.这就是我写的:
assert(contains (L1, L1)).
assert(contains(L1, [X|L2]):-member(X, L1), contains(L1, L2)).
assert(contains(L1, [])).
Run Code Online (Sandbox Code Playgroud)
我认为这将相当于"如果'L3 = X | L2'的X在L1中,并且L2在L1中则为真",包含(L1,L2)递归翻译,直到所有成员都被遍历为止我们留下最后一个选项,或者我们找到一个不在L1中的成员,它将使谓词失败.
不幸的是,它似乎没有这样的方式.它似乎只返回成员(X,L1)的值,因此包含([1,2,3],[1,4,5])通过,但包含([1,2,3],[4, 1,5])没有.
我究竟做错了什么?
这似乎是整个网络上一个臭名昭着的错误.因为我的情景不适合,所以我无法找到问题的答案.将图像保存到流时会抛出异常.
奇怪的是这与png完美配合,但是jpg和gif给出了上述错误,这是相当混乱的.
最相似的问题涉及将图像保存到没有权限的文件.具有讽刺意味的是,解决方案是使用内存流,因为我正在做....
public static byte[] ConvertImageToByteArray(Image imageToConvert)
{
using (var ms = new MemoryStream())
{
ImageFormat format;
switch (imageToConvert.MimeType())
{
case "image/png":
format = ImageFormat.Png;
break;
case "image/gif":
format = ImageFormat.Gif;
break;
default:
format = ImageFormat.Jpeg;
break;
}
imageToConvert.Save(ms, format);
return ms.ToArray();
}
}
Run Code Online (Sandbox Code Playgroud)
更多细节到例外.造成这么多问题的原因是缺乏解释:(
System.Runtime.InteropServices.ExternalException was unhandled by user code
Message="A generic error occurred in GDI+."
Source="System.Drawing"
ErrorCode=-2147467259
StackTrace:
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at Caldoo.Infrastructure.PhotoEditor.ConvertImageToByteArray(Image imageToConvert) in C:\Users\Ian\SVN\Caldoo\Caldoo.Coordinator\PhotoEditor.cs:line 139
at …Run Code Online (Sandbox Code Playgroud)