小编Mar*_*nen的帖子

RAM 中的静态指针是什么?它们如何存在?

我已经通过教程学习 C++ 游戏黑客一两周了,我几乎全部掌握了。然而,有件事却一次又一次地困扰着我。

要自定义一个值(例如玩家的生命值),我们必须使用作弊引擎(或类似引擎)搜索内存地址并将该值设置为其他值。每次我们启动程序时,这些内存地址显然都是不同的,因为它不会总是使用 RAM 中的相同位置。

为了解决这个问题,人们会尝试找到一个指向包含该值的内存地址的静态指针;指针如何是静态的,它们如何从 RAM 中保留静态地址?

memory static pointers

4
推荐指数
1
解决办法
3425
查看次数

Python 3和 - 或vs if-else

以下是否有任何区别?

print(x if x else 'no x available')
# compared to:
print(x and x or 'no x available')
Run Code Online (Sandbox Code Playgroud)

python if-statement operators logical-operators python-3.x

4
推荐指数
3
解决办法
939
查看次数

列的属性行为(getter 和 setter),而不是正常的属性行为

SQLAlchemy 是否支持这样的东西:

class Character(Base):
   __tablename__ = 'character'
   id = Column(Integer, primary_key=True)
   level = Column(Integer)

   @ColumnProperty(Integer)
   def xp(self):
       return self._xp

   @xp.setter
   def xp(self, value):
       self._xp = value
       while self._xp >= self.xp_to_level_up():
           self.level += 1
           self._xp -= 100

   def __init__(self, level=0, xp=0):
       self.level = level
       self._xp = xp
Run Code Online (Sandbox Code Playgroud)

其中idlevel、 和xp将存储到数据库中。所以基本上是一个Column属性,而不是属性。

python sqlalchemy properties python-3.x

3
推荐指数
1
解决办法
2113
查看次数

如何在组件中访问 IntlProvider 的语言环境和消息?

所以我的 index.js 有这样的东西:

import trFi from './translations/fi_FI.json';
import trSv from './translations/sv_SE.json';

ReactDOM.render(
  <IntlProvider
    locale={my_locale}
    messages={{ fi: trFi, sv: trSv }[my_locale]}
  >
      <Root />
  </IntlProvider>
);
Run Code Online (Sandbox Code Playgroud)

并且Root有多个子组件等等。现在我怎样才能在这些子组件中获得所提供的localemessages?我知道我可以将它们作为道具传递给Root,它再次将它们传递下去,但是我的树相当深,维持这个很麻烦。

是否可以访问它locale并直接messages传递给IntlProvider子组件?

javascript json reactjs react-intl

3
推荐指数
1
解决办法
5618
查看次数

How to type hint a return value of Exception's subclass?

I have an abstract method in my base class, and I want all the subclasses to return an iterable of their expected Exception classes:

class Foo(metaclass=ABCMeta):
    @abstractmethod
    def expected_exceptions(self):
        raise NotImplementedError()

class Bar(Foo):
    def expected_exceptions(self):
        return ValueError, IndexError

class Baz(Foo):
    def expected_exceptions(self):
        yield from self.manager._get_exceptions()
Run Code Online (Sandbox Code Playgroud)

How do I type hint this return value? At first I thought of -> Iterable[Exception], but that would mean they are instances of Exception, as opposed to subclasses.

python type-hinting python-3.x python-typing

3
推荐指数
1
解决办法
60
查看次数

为不同形状实现抽象'重叠'方法?

我有一个名为的抽象基类Shape,它看起来像这样:

class Shape {
    public:
        Shape(Point center);
        virtual bool overlaps(Shape *other) = 0;

    private:
        Point m_center; // has getter&setter
};
Run Code Online (Sandbox Code Playgroud)

我遇到了这个overlaps(Shape *other);方法的问题; 我不知道如何在子类中实现它.

让我们举两个例子,(我可能只有两三个形状)CircleRect.基本上我试过的是在使用前向声明允许CircleRect"相互"知道之后在两个类中创建两个重载:

virtual bool Rect::overlaps(Circle *other);
virtual bool Rect::overlaps(Rect *other);
virtual bool Circle::overlaps(Circle *other);
virtual bool Circle::overlaps(Rect *other) { return other->overlaps(this); }
Run Code Online (Sandbox Code Playgroud)

现在很容易在所有重载中实现数学; 不过,我会得到一个错误cannot allocate an object of abstract type 'Circle'note: virtual bool Unit::overlaps(Unit *).这是因为我CircleRect类只有方法Circle *和 …

c++ oop overriding class

2
推荐指数
1
解决办法
755
查看次数

Python使用自定义__new__对类进行子类化

有一个类(不是我创建的,来自第三方库)没有__init__声明(除了object's __init__),这是它的__new__:

def __new__(cls, uid):
    self = super().__new__(cls, uid)
    self._info = get_info_from_uid(uid)
    return self
Run Code Online (Sandbox Code Playgroud)

我不明白他们为什么不在__init__这里使用,但他们没有.

现在我想继承它并给它一个额外的属性; 在我检查类的源代码(仅文档)之前,我认为它只是__init__像其他人一样使用,所以这就是我所做的:

class MyClass(TheirClass):
    def __init__(self, uid, my_stuff=()):
        super().__init__(uid)
        self.my_stuff = my_stuff
Run Code Online (Sandbox Code Playgroud)

显然,这引发了一个object.__init__()不参加参数的TypeError .我应该如何将这个类子类化__new__?我只是覆盖__new__方法吗?

python inheritance subclassing python-3.x

2
推荐指数
1
解决办法
4353
查看次数

在修饰方法中赋值之前引用的局部变量

我正在创建一个装饰器,该装饰器将允许我执行以下操作:

@cooldownf(lambda self, **eargs: 30 - self.level)
def method(self, **eargs):
    ...
Run Code Online (Sandbox Code Playgroud)

这将简单地装饰方法,使其具有冷却时间。所有这些工作都很好,并且该方法现在可以每秒钟执行一次30 - self.level

但是,我想添加一条消息,如果该方法仍处于冷却状态,则会显示该消息。我messagecooldownf装饰器添加了一个参数,但是随后我的装饰器代码UnboundLocalError: local variable 'message' referenced before assignmentìf message:中出现错误:

def cooldownf(fn, message=None):
    """Decorates a method to have a dynamic cooldown.

    Decorator function for easily adding cooldown as a dynamic time
    (function) into skill's methods. The function gets called when the
    cooldown is needed, and the skill is passed to the function.

    Args:
        fn: Function to determine the …
Run Code Online (Sandbox Code Playgroud)

python decorator python-3.x python-decorators

2
推荐指数
1
解决办法
1332
查看次数

真的可以像PyCharm主张那样简化这种链式比较吗?

我有一个带有两个整数属性的类,_xp并且level。我有一个while循环比较这两个,以确保它们都是正数:

while self.level > 0 and self._xp < 0:
    self.level -= 1
    self._xp += self.get_xp_quota()
Run Code Online (Sandbox Code Playgroud)

我的PyCharm声称这可以简化:

简化链式比较

可以吗 我想确定在向PyCharm报告错误之前。

我也发现了类似的问题,但是在这种情况下,两个变量相同,我的变量具有两个不同的属性。

python comparison pycharm python-3.x

2
推荐指数
1
解决办法
300
查看次数

os.system('cls') 不清除 Pycharm 中的屏幕?

os.system('cls')在 Pycharm 中使用从之前打印的内容中清除屏幕。但是,在运行代码时,它不会清除以前打印的内容,而是在末尾打印一个向上箭头。问题是什么?

python pycharm python-3.x cls

2
推荐指数
2
解决办法
3152
查看次数