帮助,在翻译Python脚本的过程中

2024-05-14 01:11:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在翻译:http://thinkstats.com/survey.py这个脚本。在

下面是我现在正在翻译的内容(Python):

"""This file contains code for use with "Think Stats",
by Allen B. Downey, available from greenteapress.com

Copyright 2010 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""

import sys
import gzip
import os

class Record(object):
    """Represents a record."""

class Respondent(Record): 
    """Represents a respondent."""

class Pregnancy(Record):
    """Represents a pregnancy."""

斯卡拉:

^{2}$

问题: 我做了class Respondentclass Pregnancy正确吗?这些类的注释是否正确?逻辑正确吗?我刚刚读过关于类型参数化的文章,所以我对此有点怀疑,想看看我是否走在正确的道路上。在

谢谢你抽出时间。在


Tags: pyimport脚本comhttp内容recordsurvey
1条回答
网友
1楼 · 发布于 2024-05-14 01:11:01

我记得,您展示的Python语法是针对类扩展(继承)。相当于Scala

/** Represents a record.
 */
class Record

/** Represents a respondent.
 */
class Respondent extends Record

/** Represents a pregnancy.
 */
class Pregnancy extends Record

形式为/** ... */的Scala注释将在ScalaDoc中显示为文档。在

这里不需要类型参数化。它的主要用途是允许类接受或返回任意参数化类型的值。例如,List[Int]和{}分别是整数和字符串的列表。在

相关问题 更多 >