题:
我开始学习hadoop,但是,我需要使用python将很多文件保存到其中。我似乎无法弄清楚我做错了什么。谁能帮我这个?
下面是我的代码。我认为这HDFS_PATH是正确的,因为我在安装时没有在设置中更改它。该pythonfile.txt是我的桌面上(所以是通过命令行运行Python代码)。
代码:
import hadoopy
import os
hdfs_path ='hdfs://localhost:9000/python'
def main():
hadoopy.writetb(hdfs_path, [('pythonfile.txt',open('pythonfile.txt').read())])
main()
Run Code Online (Sandbox Code Playgroud)
输出 当我运行上面的代码时,我得到的只是python本身的一个目录。
iMac-van-Brian:desktop Brian$ $HADOOP_HOME/bin/hadoop dfs -ls /python
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
14/10/28 11:30:05 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-rw-r--r-- 1 Brian supergroup 236 2014-10-28 11:30 /python
Run Code Online (Sandbox Code Playgroud) 题:
我想从我的.txt文件中删除空行.因为我的.txt文件是由Python通过HTML下载生成的,我想将它们保存在某个位置,所以我必须使用Os.path.join.
这是在删除所有TAGS并仅保留标记内部后将HTML保存在该位置的代码:
cntent = re.sub('<[^>]+>',"\n", str(cntent))
with open(os.path.join('/Users/Brian/Documents/test',titles), "wb") as file:
file.writelines(str(cntent))
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这个目标?
文件的结果:
Productspecificaties
Uiterlijke kenmerken
Gewicht
185 g
Run Code Online (Sandbox Code Playgroud)
我尝试了什么:
filtered = filter(lambda x: not re.match(r'^\s*$', x), original)
Run Code Online (Sandbox Code Playgroud)
期望的结果
Productspecificaties
Uiterlijke Kenmerken
Gewicht
185Gr
Run Code Online (Sandbox Code Playgroud)
请注意,在第一行代码中re.sub...我使用"\n",因为否则根本就没有空格.
题
我想在Object上实现一个BinarySearch方法,我该Klant怎么做?
Klant有一些变数.
public class Klant {
public String klantID;
private String voornaam;
private String tussenvoegsel;
private String achternaam;
private int leeftijd;
private static boolean MAN = true;
private String plaats;
private String email;
/*
* Getters and setters included
*/
}
Klant toevoeging = new Klant("FirstName", "middleName", "\Lastname\"", 20, false, "Location", "email@email.com");
klanten.add(toevoeging);
Run Code Online (Sandbox Code Playgroud) 题
我正在尝试从BeautifulSoup下载的html文件中删除类似<h2>和的样式标签<div class=...>。我确实想保留标签包含的内容(例如文本),但是这似乎不起作用。
我尝试过的
for url in urls:
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find("div", {"class": "product_specifications bottom_l js_readmore_content"})
print "<hr style='border-width:5px;'>"
for style in table.find_all('style'):
if 'style' in style.attrs:
del style.attrs['style']
print table
Run Code Online (Sandbox Code Playgroud)
我尝试过的Urls