#๐Ÿ”’ Im trying to make this code into a module so i can import it later.

45 messages ยท Page 1 of 1 (latest)

steel sunBOT
#

@drifting orchid

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

drifting orchid
#

oh wait i accidentally loaded 2 files of it

#

[im using pycharm]

hardy valley
#

it's already a module! all you have to do is just from Vector2 import Vector2

drifting orchid
#

oh ok that sounds good

hardy valley
#

also, why the pyi file?

#

your Vector2.py already includes type hints, no need to write a type stubs file

drifting orchid
#

wait whats that

hardy valley
#

whats the builtins.pyi file for?

drifting orchid
#

oh yeah the builtins

#

idk

#

proabily something related to pycharm

hardy valley
#

oh well

drifting orchid
#

btw about magic methods, is it okay?

hardy valley
hardy valley
drifting orchid
drifting orchid
hardy valley
#

which magic method in specific are you talking about?

drifting orchid
#

idk

#

the only im unsure about tho

#

floordiv

#

when i simply use the __floor__ method it crashed

hardy valley
#

that just overrides the // operator

drifting orchid
#

oh ok

hardy valley
#

don't quote me on this, but i don't think __floor__ is a magic method that exists

#

do you want it to floor when math.floor is called on it?

drifting orchid
#

not really..
thank you tho

hardy valley
#

nevermind, __floor__ is a magic method that exists

#

it only gets called when you call math.floor on it though

drifting orchid
#

alr im gonna add it

#

btw

#

what is the other=float argument in __floordiv__

#

im bad at math

hardy valley
#

!d object.floordiv

steel sunBOT
#

object.__floordiv__(self, other)``````py

object.__mod__(self, other)``````py

object.__divmod__(self, other)```
These methods are called to implement the binary arithmetic operations (`+`, `-`, `*`, `@`, `/`, `//`, `%`, [`divmod()`](https://docs.python.org/3/library/functions.html#divmod), [`pow()`](https://docs.python.org/3/library/functions.html#pow), `**`, `<<`, `>>`, `&`, `^`, `|`). For instance, to evaluate the expression `x + y`, where *x* is an instance of a class that has an [`__add__()`](https://docs.python.org/3/reference/datamodel.html#object.__add__) method, `type(x).__add__(x, y)` is called. The [`__divmod__()`](https://docs.python.org/3/reference/datamodel.html#object.__divmod__) method should be the equivalent to using [`__floordiv__()`](https://docs.python.org/3/reference/datamodel.html#object.__floordiv__) and [`__mod__()`](https://docs.python.org/3/reference/datamodel.html#object.__mod__); it should not be related to [`__truediv__()`](https://docs.python.org/3/reference/datamodel.html#object.__truediv__). Note that [`__pow__()`](https://docs.python.org/3/reference/datamodel.html#object.__pow__) should be defined to accept an optional third argument if the ternary version of the built-in [`pow()`](https://docs.python.org/3/library/functions.html#pow) function is to be supported.

If one of those methods does not support the operation with the supplied arguments, it should return [`NotImplemented`](https://docs.python.org/3/library/constants.html#NotImplemented).
hardy valley
#

read that

drifting orchid
#

k!

drifting orchid
#

!close

steel sunBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.