我最近在Python中编写了大量代码.我一直在处理以前没有使用过的数据,使用以前从未见过的公式和处理大文件.所有这些让我写了很多印刷语句来验证它是否一切顺利并确定失败点.但是,一般来说,输出如此多的信息并不是一种好的做法.如果我想调试时如何使用print语句,当我不希望它们被打印时让它们被跳过?
我有一个测试用例,我添加一个实体,更新它并删除它.因此,执行顺序在这里很重要.我希望它是:
奇怪的是,对于一个测试用例(15个中),JUnit按以下顺序执行:
如何告诉JUnit以特定顺序执行它们?在其他情况下,JUnit完全正常(串行执行).为什么JUnit在这种情况下表现得很奇怪?
以下相关代码段:
private static Date date;
private static int entity;
static Parking p;
public ParkingTests(String name) {
super(name);
}
public void testAdd() throws Exception {
//Add code here
}
public void testUpdate() throws Exception {
//update code here
}
public void testDelete() throws Exception {
//delete code here
}
}
Run Code Online (Sandbox Code Playgroud)
它变得更奇怪了.作为套件的一部分,我运行了很多测试用例.如果我只运行停车箱,则维持订单.如果我和其他人一起运行它,有时会保持,有时不会!
我需要访问lucene索引(通过使用Nutch抓取几个网页创建)但它给出了上面显示的错误:
java.io.FileNotFoundException: no segments* file found in org.apache.lucene.store.FSDirectory@/home/<path>: files:
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:516)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:185)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:148)
at DictionaryGenerator.generateDict(DictionaryGenerator.java:24)
at DictionaryGenerator.main(DictionaryGenerator.java:56)
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索,但给出的理由不符合要求.显示文件(路径)的事实可能意味着该目录不为空.
谢谢
我最近在单节点CDH 5设置上设置了Kafka,目的是在移动到真实集群之前在单个节点上播放它.最初,我刚用kafka服务器启动了zookeeper服务器,一切都很好.我可以看到zookeeper在2181运行,而Kafka在9092运行.然后我创建了一个主题,并启动了消费者和生产者,消费者可以看到生产者发送的消息.
幸福的是,我带着动物园管理员的日志搬到了标签,看到了这个:
[2015-05-27 16:46:07,016] INFO Got user-level KeeperException when processing sessionid:0x14d97bf0a020002 type:create cxid:0x2 zxid:0x1f txntype:-1 reqpath:n/a Error Path:/consumers/test-consumer-group/ids Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/ids (org.apache.zookeeper.server.PrepRequestProcessor)
[2015-05-27 16:46:07,021] INFO Got user-level KeeperException when processing sessionid:0x14d97bf0a020002 type:create cxid:0x3 zxid:0x20 txntype:-1 reqpath:n/a Error Path:/consumers/test-consumer-group Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group (org.apache.zookeeper.server.PrepRequestProcessor)
[2015-05-27 16:46:07,306] INFO Got user-level KeeperException when processing sessionid:0x14d97bf0a020002 type:create cxid:0x19 zxid:0x24 txntype:-1 reqpath:n/a Error Path:/consumers/test-consumer-group/owners/test Error:KeeperErrorCode = NoNode for /consumers/test-consumer-group/owners/test (org.apache.zookeeper.server.PrepRequestProcessor)
[2015-05-27 16:46:07,307] INFO Got user-level KeeperException when processing sessionid:0x14d97bf0a020002 type:create cxid:0x1a …Run Code Online (Sandbox Code Playgroud) 我有一个9GB的推文文本文件,格式如下:
T 'time and date'
U 'name of user in the form of a URL'
W Actual tweet
Run Code Online (Sandbox Code Playgroud)
总共有6,000,000个用户和超过60,000,000条推文.我使用itertools.izip()一次读取3行,然后根据名称将其写入文件.但它采取的方式太长(26小时和计数).怎么能更快?
发布完整性代码,
s='the existing folder which will have all the files'
with open('path to file') as f:
for line1,line2,line3 in itertools.izip_longest(*[f]*3):
if(line1!='\n' and line2!='\n' and line3!='\n'):
line1=line1.split('\t')
line2=line2.split('\t')
line3=line3.split('\t')
if(not(re.search(r'No Post Title',line1[1]))):
url=urlparse(line3[1].strip('\n')).path.strip('/')
if(url==''):
file=open(s+'junk','a')
file.write(line1[1])
file.close()
else:
file=open(s+url,'a')
file.write(line1[1])
file.close()
Run Code Online (Sandbox Code Playgroud)
我的目标是在小文本上使用主题建模(例如,在一个用户的所有推文上运行lda,因此每个用户需要一个单独的文件),但它花费了太多时间.
更新:我使用了S.Lott用户的建议并使用了以下代码:
import re
from urlparse import urlparse
import os
def getUser(result):
result=result.split('\n')
u,w=result[0],result[1]
path=urlparse(u).path.strip('/')
if(path==''):
f=open('path to junk','a')
f.write('its …Run Code Online (Sandbox Code Playgroud) 之前我曾计划使用MySQL对Netflix和Twitter数据进行一些分析.然后我想到尝试SQLite.直到现在我的经验是:
将数据从具有100,480,057行和4列的文件加载到数据库中的时间比率:MySQL:sqLite :: 1:1.6
在给定列上创建索引的时间比例:MySQL:sqLite :: 1:3
丢弃表的比例(我犯了一个错误,想要丢弃并重启):
差异很大.花了很多时间在SQLite中删除一个表.
我认为SQLite比MySQL更快,同时提供了正常任务所需的大部分功能.我错过了什么?
我想对大文件进行10倍交叉验证(每个运行成数十万行).我想在每次开始读取文件时执行"wc -l",然后生成固定次数的随机数,每次都将该行号写入单独的文件中.我用这个:
import os
for i in files:
os.system("wc -l <insert filename>").
Run Code Online (Sandbox Code Playgroud)
如何在那里插入文件名.它是一个变量.我浏览了文档,但他们主要列出了ls命令,没有这个问题.
我有一个文本文件的形式(用户ID,电影ID,评级,时间),我想对数据集做一个vanilla回归.(只有4个功能,> 400万个实例)
model <- glm ( UserId ~ MovieId+Ratings+Time,data=<name>)
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
ERROR: cannot allocate 138.5MB vector .
Run Code Online (Sandbox Code Playgroud)
文件大小只有93MB.如何用R进行回归并且没有内存问题?我应该以不同方式存储数据吗?
谢谢 .
更多信息:在具有3GB RAM的Linux机箱上工作.我已经google了一下,但大多数链接我都谈到了数据集,这些数据集通常都是RAM,在我的情况下并非如此:(只有93MB).
我正在使用Mahout在一组推文上运行NaiveBayes.两个文件,一个100 MB,一个300 MB.我将JAVA_HEAP_MAX更改为JAVA_HEAP_MAX = -Xmx2000m(之前为1000).但即便如此,在抱怨堆空间错误之前,mahout还是运行了几个小时(确切地说是2个小时).我该怎么办才能解决?
更多信息,如果它有帮助:我在一个节点上运行,我的笔记本电脑实际上它有3GB的RAM(仅).
谢谢.
编辑:我第三次运行它与第一次使用的数据的1/2(第一次使用550万条推文,第二次使用2百万)我仍然有堆空间问题.我发布完整错误以完成目的:
17 May, 2011 2:16:22 PM
org.apache.hadoop.mapred.JobClient monitorAndPrintJob
INFO: map 50% reduce 0%
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:62)
at java.lang.StringBuilder.<init>(StringBuilder.java:85)
at org.apache.hadoop.mapred.JobClient.monitorAndPrintJob(JobClient.java:1283)
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1251)
at org.apache.mahout.classifier.bayes.mapreduce.common.BayesFeatureDriver.runJob(BayesFeatureDriver.java:63)
at org.apache.mahout.classifier.bayes.mapreduce.bayes.BayesDriver.runJob(BayesDriver.java:44)
at org.apache.mahout.classifier.bayes.TrainClassifier.trainNaiveBayes(TrainClassifier.java:54)
at org.apache.mahout.classifier.bayes.TrainClassifier.main(TrainClassifier.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:68)
at org.apache.hadoop.util.ProgramDriver.driver(ProgramDriver.java:139)
at org.apache.mahout.driver.MahoutDriver.main(MahoutDriver.java:184)
17 May, 2011 7:14:53 PM org.apache.hadoop.mapred.LocalJobRunner$Job run
WARNING: job_local_0001
java.lang.OutOfMemoryError: Java heap space
at java.lang.String.substring(String.java:1951)
at java.lang.String.subSequence(String.java:1984)
at java.util.regex.Pattern.split(Pattern.java:1019)
at java.util.regex.Pattern.split(Pattern.java:1076) …Run Code Online (Sandbox Code Playgroud) 我有4亿条推文(实际上我认为它几乎像450但不记得),形式如下:
T "timestamp"
U "username"
W "actual tweet"
Run Code Online (Sandbox Code Playgroud)
我想最初以"username\t tweet"的形式将它们写入文件,然后加载到DB中.问题是在加载到数据库之前,我需要做一些事情:1.预处理推文以删除RT @ [名称]和网址2.从http://twitter.com/中取出用户名用户名".
我正在使用python,这是代码.请让我知道如何更快地:)
'''The aim is to take all the tweets of a user and store them in a table. Do this for all the users and then lets see what we can do with it
What you wanna do is that you want to get enough information about a user so that you can profile them better. So , lets get started
'''
def regexSub(line):
line = re.sub(regRT,'',line)
line …Run Code Online (Sandbox Code Playgroud)