Dumbo(Python)/ Hadoop意外输出(Dumbo(Python)/Hadoop unexpected output)
我正在尝试使用dumbo(Python)/ haddop执行以下代码https://github.com/klbostee/dumbo/wiki/Short-tutorial#jobs-and-runners
我正确地遵循了教程,我已经完成了每一步,但是当我在hadoop环境中运行代码时,我获得如下输出:
SEQ / org.apache.hadoop.typedbytes.TypedBytesWritable /org.apache.hadoop.typedbytes.TypedBytesWritable ޭq % O 172.16.1.10 172.16.1.12 172.16.1.30
它应该返回带有连接计数器的IP地址列表。 为什么出现这些角色? 这是编码问题吗? 我如何解决它? 谢谢
另外,如果我在教程中尝试其他程序,我也会遇到同样的问题。
I'm trying to execute the following code with dumbo(Python) / haddop https://github.com/klbostee/dumbo/wiki/Short-tutorial#jobs-and-runners
I followed the tutorial correctly, I have done every step but when I run code in hadoop environment I obtain as output as follows:
SEQ/org.apache.hadoop.typedbytes.TypedBytesWritable/org.apache.hadoop.typedbytes.TypedBytesWritable�������ޭǡ�q���%�O��������������172.16.1.10������������������172.16.1.12������������������172.16.1.30������
It should return a list of IP addresses with connections counter. Why those characters appear? Is it an encoding problem? How do I fix it? Thanks
Also if I try other programs in the tutorial, I have the same problem.
原文:https://stackoverflow.com/questions/15611478
最满意答案
在模块
my_module
执行以下操作:class MyThing(object): ... _inst = MyThing() say = _inst.say move = _inst.move
这正是
random
模块所使用的模式。自动执行此操作有点麻烦。 首先,需要找出哪些实例/类属性是要导出的方法...可能只导出不以
_
开头的名称,类似于import inspect for name, member in inspect.getmembers(Foo(), inspect.ismethod): if not name.startswith('_'): globals()[name] = member
然而,在这种情况下,我会说明确比隐含更好。
In module
my_module
do the following:class MyThing(object): ... _inst = MyThing() say = _inst.say move = _inst.move
This is exactly the pattern used by the
random
module.Doing this automatically is somewhat contrived. First, one needs to find out which of the instance/class attributes are the methods to export... perhaps export only names which do not start with
_
, something likeimport inspect for name, member in inspect.getmembers(Foo(), inspect.ismethod): if not name.startswith('_'): globals()[name] = member
However in this case I'd say that explicit is better than implicit.
相关问答
更多-
以下是在Python中使用单例的三种方法。 使用metaclass和decorator来达到目标。 使用__new__ class Singleton(object): def __new__(cls, *args, **kw): if not hasattr(cls, '_instance'): orig = super(Singleton, cls) cls._instance = orig.__new__(cls, *args, ...
-
如果确保输入有效,并且实例包含具有该名称的成员 a.__dict__[name] 将访问存储在那里的值。 那是, a.__dict__["x"] 是相同的 a.x 更新: 正确的方法是 vars(a)[name] 这相当于a.__dict__[name] 。 If you ensure the input is valid, and that the instance contains a member with that name a.__dict__[name] Will access the ...
-
Python - 通过模块属性(按字符串名称)访问类实例(Python - Getting access to class instance via module property (by string name))[2022-12-04]
@ payne的查找表创建10个Foobar实例,然后返回您想要使用的实例; 这看起来很浪费。 为什么不按需求实例化,像这样? class Foobar(): def __init__(self, foo, bar, choo): self.foo = foo self.bar = bar self.choo = choo def doIt(self): return self.foo + self.bar makeFoo ... -
你尝试过__name__类的__name__属性吗? 即type(x).__name__将给你类的名字,我认为是你想要的。 >>> import itertools >>> x = itertools.count(0) >>> type(x).__name__ 'count' 此方法仅适用于新式类 。 您的代码可能会使用一些旧式类。 以下工作适用于两者: x.__class__.__name__ Have you tried the __name__ attribute of the class? ie ...
-
在模块my_module执行以下操作: class MyThing(object): ... _inst = MyThing() say = _inst.say move = _inst.move 这正是 random模块所使用的模式。 自动执行此操作有点麻烦。 首先,需要找出哪些实例/类属性是要导出的方法...可能只导出不以_开头的名称,类似于 import inspect for name, member in inspect.getmembers(Foo(), inspect.ismeth ...
-
Python中的实例模块(Module of Instance in Python)[2022-05-13]
所以 - Python的动态允许函数检查帧对象的来源。 。 但是,如果您可以将模块显式传递给类构造函数会更好: class MyObject: def __init__(self, module): self.module = module ... 在其他文件中: m = MyObject(__name__) 但是,正如我在第一行中提到的那样,您可以访问调用模块的代码 - 除非您有专门的元类,否则调用一个类的__init__的代码就是实例化对象的位置。 所以 ... -
请允许我提出一个不同的例子。 想象一下,有了Vector类。 现在你想要一个Point类。 Point可以用向量定义,但也许它具有Vector没有的其他额外功能。 在这种情况下,您从Vector派生Point。 现在你需要一个Line类。 Line不是任何上述类的特化,因此您可能不希望从它们中的任何类派生它。 但Line使用积分。 在这种情况下,您可能希望以这种方式启动Line类: class Line(object): def __init__(self): self.point1 ...
-
尝试这个: # env.py se = None def create_env_obj(file_exists): global se if file_exists: print("Creating environment A") se = SetEnvForExistingFile() else: print("Creating environment B") se = SetEnvForNoExistingFile( ...
-
你用一个字符串文字调用parse : reissues = pitchfork_reissues.parse('response') 我想这应该是一个变量名称? 像这样: reissues = pitchfork_reissues.parse(response) 编辑 Spider的parse方法需要scrapy.http.Response的实例作为第一个参数,而不是包含单词'response'的字符串文字。 我自己并没有使用Scrapy,所以我只知道我在文档中读到的内容,但显然这样的Response实 ...
-
如何知道导入了哪个python模块类?(How to know that from which python module class has been imported? [duplicate])[2022-05-16]
您可以访问类的module属性以签出它所属的模块。 尝试: print Model.__module__ You can access the module property of a class to checkout to which module it belongs. try: print Model.__module__