somenone能把这个从Ruby翻译成Python吗。这是一个基本的地图功能

somenone能把这个从Ruby翻译成Python吗。这是一个基本的地图功能,python,ruby-on-rails,ruby,mongodb,Python,Ruby On Rails,Ruby,Mongodb,此功能来自mongodb站点: def self.threaded_与_字段(故事,字段名称='vows')) comments=find(:all,:conditions=>{:story\u id=>story.id},:order=>“路径asc,{field\u name}desc”) 结果,map=[],{} 评论。每个人都做评论| 如果comment.parent\u id.blank? 结果该方法不能直接翻译。它依赖于几种只存在于ActiveRecord或Mongoid::Doc

此功能来自mongodb站点:

def self.threaded_与_字段(故事,字段名称='vows'))
comments=find(:all,:conditions=>{:story\u id=>story.id},:order=>“路径asc,{field\u name}desc”)
结果,map=[],{}
评论。每个人都做评论|
如果comment.parent\u id.blank?

结果该方法不能直接翻译。它依赖于几种只存在于
ActiveRecord
Mongoid::Document
类中的框架方法(例如
Model#find
)——除非您在Python中使用相同的框架,您还必须自己实现这些方法。

因此,要回答有关操作符的问题,例如
,您了解Ruby还是Python?您需要帮助理解上述代码的作用吗?最好问一个特定的问题。这听起来像是你想让别人来做你的工作;-)我懂python。我同意,听起来我确实希望有人来做我的工作。在本例中,我只是想了解这段代码使用的基本方法。然后,我将为我的应用程序编写一些特定的内容。
def self.threaded_with_field(story, field_name='votes')
    comments = find(:all, :conditions => {:story_id => story.id}, :order => "path asc,  #{field_name} desc")
    results, map = [], {}
    comments.each do |comment|
      if comment.parent_id.blank?
        results << comment
      else
        comment.path =~ /:([\d|\w]+)$/
        if parent = $1
          map[parent] ||= []
          map[parent] << comment
        end
      end
    end
    assemble(results, map)
  end