首页 \ 问答 \ 叉和分支在github上的区别(difference between fork and branch on github)

叉和分支在github上的区别(difference between fork and branch on github)

如果我分叉一个托管在github上的项目。 我分叉所有的分支吗? 我如何知道我的叉是哪个分支? 换句话说,哪个分支将被下载到我的电脑?


If I fork a project that's hosted on github. Do I fork all the branches? How do I know which branch my fork is based on? In other words which branch will be downloaded to my PC?


原文:https://stackoverflow.com/questions/5009600
更新时间:2022-04-12 14:04

最满意答案

您可以使用@property装饰器来管理您的type属性:

class Ship(object):
    def __init__(self, type):
        self.fixed = define_direction()

        self.row = random_row(board, self)
        self.col = random_col(board, self)
        self.type = type
        print "Type:", str(self.type)

    @property
    def type(self):
        return {
            "Patrol boat": 0,
            "Destroyer": 1,
            "Submarine": 2,
            "Battleship": 3,
            "Aircraft carrier": 4,
        }.get(self._type, 0) 

    @type.setter
    def type(self, type):
        self._type = {
            0: "Patrol boat",
            1: "Destroyer",
            2: "Submarine",
            3: "Battleship",
            4: "Aircraft carrier",
        }.get(type, "Patrol boat") 

    def __repr__(self):
        return "Ship. Type: " + self._type

你的__repr__应该总是返回一个字符串; 你回来了一个元组。 您的错误是由您的self.type()调用引起的; 因为self.type在您的代码中存储了一个字符串,所以您试图将该字符串视为可调用的。

可以从__init__调用其他函数(类之外); 它只是你的实例上的另一种方法,只考虑具有和尚未设置的属性。 但是,如果函数依赖于self信息并且在类外没有用处,我会将它移动到带有_前缀的类中,以指示它是类实现的内部。


You can use a @property decorator to manager your type attribute:

class Ship(object):
    def __init__(self, type):
        self.fixed = define_direction()

        self.row = random_row(board, self)
        self.col = random_col(board, self)
        self.type = type
        print "Type:", str(self.type)

    @property
    def type(self):
        return {
            "Patrol boat": 0,
            "Destroyer": 1,
            "Submarine": 2,
            "Battleship": 3,
            "Aircraft carrier": 4,
        }.get(self._type, 0) 

    @type.setter
    def type(self, type):
        self._type = {
            0: "Patrol boat",
            1: "Destroyer",
            2: "Submarine",
            3: "Battleship",
            4: "Aircraft carrier",
        }.get(type, "Patrol boat") 

    def __repr__(self):
        return "Ship. Type: " + self._type

Your __repr__ should always return a string; you were returning a tuple instead. Your error was caused by your self.type() call; since self.type stores a string in your code, you were trying to treat that string as a callable.

It is fine to call other functions (outside of the class) from __init__; it is just another method on your instance really, just take into account what attributes have and haven't been set yet. However, if the function relies on information on self and has no uses outside the class, I'd move it into the class with a _ prefix to indicate that it is internal to the class implementation.

相关问答

更多
  • 那么这是一个经典的讨论。 Stack Overflow中有几个其他的线程关于这个。 但。 Get / Set的(自动属性?)并不全是坏的。 但是他们往往会让你将实体构建为只有prop和not方法的“死”数据容器。 这种迹象通常被称为贫血领域 - 并且行为很少。 我的建议是: 尝试尽可能少地使用道具。 尝试找到属于一起的数据组,应该像前一样。 名字中间名和姓氏。 另一个例子是Zipcode,City,Street。 这些数据最好通过一种方法来设置。 它最大限度地减少了您的实体无效的机会。 通常属于一起的数据可 ...
  • 使用_ClassName__attribute ,您可以访问该属性: >>> class MyClass(object): ... def __init__(self): ... self.__x = 3 ... @property ... def x(self): ... return self.__x ... @x.setter ... def x(self, value): ... if value != 3: . ...
  • 您可以使用@property装饰器来管理您的type属性: class Ship(object): def __init__(self, type): self.fixed = define_direction() self.row = random_row(board, self) self.col = random_col(board, self) self.type = type print "Type:", s ...
  • 喜欢的属性 。 这是他们在那里。 原因是Python中的所有属性都是公共的。 使用下划线或两个起始名称只是一个警告,指定的属性是在将来版本的代码中可能不一致的实现细节。 它不会阻止您实际获取或设置该属性。 因此,标准属性访问是正常的,Pythonic的方式,很好的访问属性。 属性的优点是它们与属性访问的语法相同,因此您可以从一个更改到另一个,而不会对客户端代码进行任何更改。 你甚至可以有一个版本的类使用属性(例如,按代码分包或调试)和一个不用于生产的版本,而不需要更改使用它的代码。 同时,您不必为所有事务编 ...
  • 实际上有很多很好的理由考虑使用访问器,而不是直接暴露一个类的字段,而不仅仅是封装的参数,并且使未来的更改更容易。 以下是我所知道的一些原因: 封装与获取或设置属性相关的行为 - 这允许稍后更容易添加其他功能(如验证)。 在使用替代表示方式暴露属性时隐藏属性的内部表示。 将公共界面与变更保持一致 - 允许公共界面保持不变,而实施变更而不影响现有消费者。 控制属性的生命周期和内存管理(处置)语义 - 在非托管内存环境(如C ++或Objective-C)中尤为重要)。 提供调试截取点,以便在运行时更改属性时调试 ...
  • 请参阅Python内置日志记录模块。 没有必要重新发明轮子。 以下是文档中的示例: import logging logging.warning('Watch out!') # will print a message to the console logging.info('I told you so') # will not print anything 如果要设置日志级别,以便打印INFO +更高优先级的消息: logging.getLogger().setLevel(logging.INFO) ...
  • 发生这种情况是因为您已经为MainPage和MiniGameOne类定义并检查nextLevel 。 当您将miniGameOne实例中的级别更改为2 ,它将变为2直到您将其更改为其他号码。 从这一点你有: mainPage.getNextLevel() == 1和miniGameOne.getNextLevel() == 2 所以在你的enterFrame()这两个条件都是真实的,你的miniGameOne被indeen添加到舞台上,但是在同一帧中它被删除,并且你的mainPage被再次添加。 作为最快的 ...
  • 如果你关心覆盖率指标,那么setter和getter可以杀死你。 无论如何,你绝对应该测试它们,特别是如果它们不仅仅是设置或获得它们。 此外,它可以在一次测试中测试set / get。 如果道具是私人的,那么你必须这样做,除非有一套副作用。 或者,您可以在测试其他方法时隐式测试它们。 例如,如果您正在测试DAO,则可以在编写testSave方法时使用setter和getter ... 为了使生活更轻松,您可以编写基于反射的测试实用程序来测试setter和getter。 或者只是编写简单的测试,虽然很无聊,但 ...
  • 您的好习惯是将您的逻辑包装到Service中 。 您必须知道,在Angular中,所有服务都是Singleton ,只有一个Service实例。 我做了一个简单的例子,使用$ q.defer() ,它是延迟API的promise管理器 。 $ q.defer()获得2种方法: resolve(value):通过给她最终值来解决我们的相关承诺 拒绝(原因):解决承诺错误。 调节器 (function(){ function Controller($scope, $q, Service) { //Use ...
  • 在代码示例中,我发现它们只有一个getter,但不是一个setter。 但我真的不明白为什么。 您描述的功能是在创建Person对象时,没有人可以set其gender和length 。 如果用户希望,他/她可以根据需要创建具有属性的新 Person ( new Person(...) )。 但是在创建Person之后,您无法set属性。 但是this.gender = gender可以作为制定者工作? 我似乎无法弄清楚它的功能是什么。 它确实可以作为一个setter(虽然它本身不是一个setter,因为它不 ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)