我有一个python字典,其定义不适合单行.谁能告诉我python词典的指南.我目前有这个对我的眼睛不好看.
initialstate = {
'state':grid,
'f':find_manhattan_distance(grid,goal),
'g':0,
'h':find_manhattan_distance(grid,goal),
'ancestor': None
}
Run Code Online (Sandbox Code Playgroud) 我正在使用scrapy来抓取域下的所有网页.
我见过这个问题.但是没有解决方案.我的问题似乎与此类似.我的crawl命令输出如下所示:
scrapy crawl sjsu2012-02-22 19:41:35-0800 [scrapy] INFO: Scrapy 0.14.1 started (bot: sjsucrawler)
2012-02-22 19:41:35-0800 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, MemoryUsage, SpiderState
2012-02-22 19:41:35-0800 [scrapy] DEBUG: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, RedirectMiddleware, CookiesMiddleware, HttpCompressionMiddleware, ChunkedTransferMiddleware, DownloaderStats
2012-02-22 19:41:35-0800 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2012-02-22 19:41:35-0800 [scrapy] DEBUG: Enabled item pipelines:
2012-02-22 19:41:35-0800 [sjsu] INFO: Spider opened
2012-02-22 19:41:35-0800 [sjsu] INFO: Crawled 0 pages (at 0 pages/min), …Run Code Online (Sandbox Code Playgroud) 这是我的代码.我的parse_item方法没有被调用.
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
class SjsuSpider(CrawlSpider):
name = 'sjsu'
allowed_domains = ['sjsu.edu']
start_urls = ['http://cs.sjsu.edu/']
# allow=() is used to match all links
rules = [Rule(SgmlLinkExtractor(allow=()), follow=True),
Rule(SgmlLinkExtractor(allow=()), callback='parse_item')]
def parse_item(self, response):
print "some message"
open("sjsupages", 'a').write(response.body)
Run Code Online (Sandbox Code Playgroud) 如何使Scala对象具有线程安全性.
class Stack {
case class Node(value: Int, var next: Node)
private var head: Node = null
private var sz = 0
def push(newValue: Int) {
head = Node(newValue, head)
sz += 1
}
def pop() = {
val oldNode = head
head = oldNode.next
oldNode.next = null
sz -= 1
}
def size = sz //I am accessing sz from two threads
}
Run Code Online (Sandbox Code Playgroud)
这个类显然不是线程安全的.我想让它成为线程安全的.
提前致谢,
生命值
我第一次使用http://typesafe.com/stack/,我创建了简单的akka项目.我的scala版本是2.9.2我收到以下错误.
[info] Done updating.
[info] Compiling 1 Scala source to /Users/hrishikeshparanjape/git-public/web-service/target/scala-2.9.2/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.9.2. Compiling...
sbt appears to be exiting abnormally.
The log file for this session is at /var/folders/26/hqgjyf0j7192hmjdsz17f3v80000gn/T/sbt2587622650679130928.log
java.lang.OutOfMemoryError: PermGen space
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at sbt.CompletionService$$anon$1.take(CompletionService.scala:29)
at sbt.Execute.next$1(Execute.scala:74)
at sbt.Execute.processAll(Execute.scala:77)
at sbt.Execute.runKeep(Execute.scala:57)
at sbt.EvaluateTask$.run$1(EvaluateTask.scala:109)
at sbt.EvaluateTask$.runTask(EvaluateTask.scala:124)
at sbt.Aggregation$$anonfun$7.apply(Aggregation.scala:87)
at sbt.Aggregation$$anonfun$7.apply(Aggregation.scala:85)
at sbt.EvaluateTask$.withStreams(EvaluateTask.scala:87)
at sbt.Aggregation$.runTasks(Aggregation.scala:85)
at sbt.Aggregation$$anonfun$applyDynamicTasks$1.apply(Aggregation.scala:141)
at sbt.Aggregation$$anonfun$applyDynamicTasks$1.apply(Aggregation.scala:136)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:64)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:64)
at sbt.Command$.process(Command.scala:92)
at sbt.MainLoop$$anonfun$next$1$$anonfun$apply$1.apply(Main.scala:121)
at sbt.MainLoop$$anonfun$next$1$$anonfun$apply$1.apply(Main.scala:121)
at sbt.State$$anon$1.process(State.scala:154) …Run Code Online (Sandbox Code Playgroud) 我有以下实体:
@RooEntity
Class X {
@NotNull
private Locale locale;
}
Run Code Online (Sandbox Code Playgroud)
是否可以在数据库中存储Locale对象的toString()表示,并且在检索时我仍然可以获取Locale对象?
我可以在这里使用@Basic注释吗?
我有一个数组(树)像:
['Humidity\n', ['High', ['Outlook\n', ['Sunny', ['Temp\n', ['Hot', ['Wind\n', ['Weak', ['No']], ['Strong', ['No']]]], ['Mild', ['No']]]], ['Overcast', ['Temp\n', ['Hot', ['Yes']], ['Mild', ['Yes']]]], ['Rain', ['Temp\n', ['Mild', ['Wind\n', ['Weak', ['Yes']], ['Strong', ['No']]]]]]]], ['Normal', ['Wind\n', ['Weak', ['Outlook\n', ['Rain', ['Yes']], ['Overcast', ['Temp\n', ['Cool', ['Yes']], ['Hot', ['Yes']]]], ['Sunny', ['Yes']]]], ['Strong', ['Temp\n', ['Cool', ['No']], ['Mild', ['Outlook\n', ['Rain', ['Yes']], ['Sunny', ['Yes']]]]]]]]]
Run Code Online (Sandbox Code Playgroud)
我想把它打印成树.这是我的尝试
def printTree(treeToPrint, tab):
print tab + treeToPrint[0]
newTab = tab + "--"
nextTree = treeToPrint[1:]
for tree in nextTree:
print newTab + tree[0]
printTree(tree[1], newTab + "--") …Run Code Online (Sandbox Code Playgroud) 我的EmailHandler类如下:
Class EmailHandler {
...
@Autowired
protected Configuration config;
}
...
protected Template getTemplate(String templateName, Locale locale) throws IOException, TemplateException {
return config.getTemplate(templateName, locale);
}
...
}
Run Code Online (Sandbox Code Playgroud)
在我的applicationcontext.xml中,我有
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="classpath:/templates/email"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的模板目录结构如下:
--src
----main
------resources
--------templates
----------email
------------template1.ftl
------------template2.ftl
------------template3.ftl
------------template4.ftl
------------multilanguage
--------------fr
----------------template1.ftl
Run Code Online (Sandbox Code Playgroud)
目前,getTemplate始终使用(string,Locale.US)进行调用。但是,将来,我希望能够使用(string,Locale.FR)调用getTemplate。
以下是我的问题:1.如何更改目录结构以指定法语模板。2. config.getTemplate(templateName,locale)是什么?到底是做什么的?该方法如何在模板目录中找到Locale.US的模板?3.我想从email / multilanguage / fr目录加载我的法语模板。我怎么做?
谢谢,
里士
我可以如下指定log4j格式化程序来打印spring mvc应用程序中的当前线程id
log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m%n
Run Code Online (Sandbox Code Playgroud)
如何在我的spring应用程序中以编程方式获取当前线程ID.更确切地说,我想在拦截控制器方法的方面获取当前线程id.我的方面如下:
@Configurable
@Aspect
public class TimingAspect {
@Autowired
private HttpServletRequest httpServletRequest;
//Generic performance logger for any mothod
private Object logPerfomanceInfo(ProceedingJoinPoint joinPoint) {
// do something with thread id
// do something with httprequest
...
}
// Performance info for API calls
@Around("execution(* package.controller.*.*(..))")
public Object logAroundApis(ProceedingJoinPoint joinPoint) throws Throwable {
return logPerfomanceInfo(joinPoint);
}
}
Run Code Online (Sandbox Code Playgroud) python ×4
java ×3
scala ×2
scrapy ×2
arrays ×1
coding-style ×1
database ×1
freemarker ×1
hibernate ×1
localization ×1
pretty-print ×1
racket ×1
scheme ×1
spring ×1
spring-roo ×1
tree ×1
web-crawler ×1
web-services ×1