« first day (4435 days earlier)      last day (514 days later) » 

12:01 AM
Anyone know how to move the terminal cursor to after all the info I printed after the program ends? I'm using blessed and currently C:\Users\user\python\> always covers up the second line since I cleared the entire screen
 
generally terminals operate on a behavioral line-parse property. check how to manipulate your particular terminal's properties.
 
So there isn't a way to do it in code?
 
"how to get the thing I'm controlling to change the way the thing I'm not controlling to behave after the thing i'm controlling no longer has control" is what I just heard...
sure you aren't just missing a newline at the end of your embedded script?
I don't know anything about Blessed....but if you did some python equivalent to manipulating print('abc', end='\r\n') the original terminal may have a hard time based on it's logic for carriage returns.
Interesting library though...truly, Python libs are getting out of hand for functional abstraction :D
 
 
8 hours later…
8:18 AM
Is there any nice tool/library for making simple html dashboard? preferably something I can combine with Jinja2, and it doesn't need much interactivity
 
@matszwecja there Dash. Don't know much about it, but others here probably know
 
mad
8:51 AM
@matszwecja Yeah, I can recommend Dash as well. It is very powerful. If you want something for quick prototyping that is easier to get started but less flexible/customizable, have a look at streamlit.
 
looks good, although seems the async fork is a bit outdated
 
9:06 AM
You could just use flask too, which has direct integration with jinja2
 
yeah but then I need to create all the infographics manually
although that's probably what I'll end up doing
with some bootstrap thrown in
 
I've used dash a bit recently and you still end up using bootstrap. All said and done, it felt just like I was writing the HTML anyway but it's all just in python which might give people the fuzzies
 
What would you name a callable that should be used as a filtering condition? The "filter" method that exists in Python has a argument named "__function", which is not that good of a name.
I know that there is a word for this type of callable, but can't remember what it is.
 
condition?
 
9:52 AM
how normal is it to change the state of an instance passed to a method? something like this
class Foo:
    def bar(self, foo):
        self.i = foo
        foo.j = self
foo is an instance of Foo
self.i = foo seems ok to me, I am not sure if changing the state for foo.j is ok
 
It's rare, but not necessarily bad
Especially if you have a tree-like structure, then it's common to do things like self.children.append(foo); foo.parent = self
 
It should be considered side effect, so it is ok as long as people using bar are aware that it changes foo as well as self
 
@Aran-Fey i and j are relations, not a tree, but yeah
would it be better to instead, make bar something like create_and_return which then creates the instance and returns the instance once the relations are done?
on an unrelated note, does anyone here agree with wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/…
I am not a huge fan of := but I dont necessarily hate that, but wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/… also stops me from the one or two places I actually use it
I am forced to use this at work, wanted to get opinions on what others use
 
10:11 AM
Banning f-strings is dumb, banning walruses is debatable
Every tool has a purpose, and pretending that they don't is dumb - unless your workers are too stupid to use them correctly
 
I guess they dialed this up to a 11 with the configs at my org
 
the only somewhot understandable issue is that f-strings do 2 things at once
 
"Create a string" sounds like 1 thing to me ¯\_(ツ)_/¯
 
11:00 AM
How to I determine if a variable is of type IO[str] or IO[bytes]? Is that even possible?
 
 
1 hour later…
12:14 PM
Nope
Not without calling .read(n) anyway
 
12:55 PM
I guess I should mention, if you're lucky then an IO[str] will inherit from io.TextIOBase
 
1:47 PM
Alright, thanks! :P
By the way...
subprocess.Popen(
   stdout=?
)

How would a method look that can be assign to "stdout"? A simple use case, if I would have a method called just "print_stdout", how would it look to make it useable in the pipe?
subprocess.Popen(
   stdout=print_stdout
)
I know that I can do it like this, but wondering how to make it able to set it directly as an argument:

process = subprocess.Popen(
    stdout=subprocess.PIPE
)

print_stdout(process.stdout)
 
That's just simply not possible, Popen doesn't take a function as input there
 
Oh, it doesnt? So I should do it like my second example, right? :)
 
Yeah
 
General question... I'm wondering how folks here are tracking (Python) version specific workarounds in their projects. As context, we're still bound to support Python 3.6 but that means we add more and more stopgaps that become obsolete the instant we drop Python 3.6 support.
 
Anyone know how to affect the value of a dictionary when I do val = dictionary.get().get() ? I know that .get returns a copy so is there a different way to do that?
 
2:01 PM
So far I've started collecting such workarounds in a mega issue, but those need maintaining as well. Are there any in-code solutions for Python, say specific comments to mark version dependencies?
@12944qwerty .get doesn't return a copy. Do you have a practical example?
 
This is for the aoc...
 
@MisterMiyagi I usually sometimes hide all of that stuff behind a module. Like from ._compat import Literal or whatever
 
Is there anyway to partially build a constructor call?
 
Instead of using ternarys for some arguments.
Hmm, will check that out!
 
2:11 PM
@MisterMiyagi I actually wanted to do something similar, so I could support every major python versions. I don't think I found any public codebase that did this (yet) though, so I think I might have to do this from scratch (or maybe use 2to3 as a basis or something)
I don't know if you do this on your end using marshal/bytecode or ast, but yeah
 
```
dictionary = {"foo": {"a": 1, "b": 2}}

stuff = dictionary.get("foo").get('a')
stuff = 100

print(stuff["a"]) # 100
print(dictionary["foo"]["a"]) # 100 or 1?
```
ok replies with codeblocks don't work, but would this have worked?
 
We don't have workarounds really isolated. It's mostly stuff like backports needed as dependencies, not using modern operators/operations (think dict's |), not using dataclasses, using outdated asyncio APIs, that sort of thing.
 
stuff = dictionary.get("foo")
stuff['a'] = 100
 
@12944qwerty No, but for a completely different reason. stuff isn't the value you get, it just refers to it.
 
:55654602 How would that work, in practice? The code is implemented like this now (kind of):

if something:
    self._attribute = Class(
        ...
        add_this="Hello"
    )
else:
    self._attribute = Class(
        ...
    )
 
2:17 PM
When you re-asign stuff, you just tell it to refer to something else.
 
@MisterMiyagi ah, got you
 
@Warcaith There isn't really a good solution to that, I don't think. If you don't care about static typing, maybe something like
 
I have no idea what the keys are, and they may be going deep in the dict at an unknown depth.
 
kwargs = {}
if something:
    kwargs['add_this'] = 'Hello'
self._attribute = Class(**kwargs)
 
Hmm, yeah, that would work. But well, it makes my code a bit harder to understand, so I guess I'll stick with what I have.
Thanks anyway! <3
 
2:20 PM
Or
constructor = Class
if something:
    constructor = partial(constructor, add_this="hello")
self._attribute = constructor()
 
Hm, I might just use a linkedlist or exec
Exec would be easier
 
@Aran-Fey What happens with all other arguments in that case?
 
What other arguments?
Ah, constructor = partial(Class, ...)
 
if something:
    self._attribute = Class(
        argument_1=123,
        argument_2=456,
        argument_3=789,
        add_this="Hello"
    )
else:
    self._attribute = Class(
        argument_1=123,
        argument_2=456,
        argument_3=789,
    )
I don't want to repeat myself like this, which is why I had this question from the start.
Yeah, I thought about that, but as you said.. a bit hacky :D
 
And a pain to write...
self._attribute = Class(
    argument_1=123,
    argument_2=456,
    argument_3=789,
    **({"add_this": "Hello"} if something else {})
)
 
2:27 PM
constructor = partial(
    Class,
    argument_1=123,
    argument_2=456,
    argument_3=789,
)

if something:
    constructor = partial(constructor, add_this="Hello")
 
if re.match(pattern, string) is None:
    print('XYZ happened')
    raise
 
@aeiou You can't use a bare raise outside of an except clause. This shouldn't work fine.
 
@MisterMiyagi How to terminate code execution in if clause otherwise? Exit()?
It works btw. It seems smth similar was discussed in discuss.python.org/t/….
 
Use sys.exit() or raise SystemExit to stop execution.
 
But before that, make sure you actually want to stop execution. 99% of the time that's a bad idea. You probably just want to raise an exception
 
2:36 PM
I fear exit() or sys.exit() are too invasive. I do want to stop the execution but is not there any gentler way, similar to raise exception?
I used previously raise Exception('XYZ happened') but linting tool did not like it either.
 
Probably because Exception doesn't tell the caller anything about the reason for the error. Be more specific, like ValueError
 
@aeiou you can't be "gentle" about "kill a program immediately regardless of what it's doing", this is supposed to be invasive
 
:-)
 
I've said it before and I'll say again: Error messages are evil. Exceptions should look like raise XyzHappenedException()
 
I mean, they are fine for info that can't be predicted before runtime, e.g. KeyError('foo')
 
2:43 PM
@Aran-Fey This requires you to set up a class for each custom error?
 
Yes!
 
I vaguely recall seeing someone raising custom errors using strings, but I probably hallucinated that hmm
I don't know if this was on github or SO though
 
@aeiou this?
 
linting was fine with `raise ValueError('XYZ')`. Still weirded out by tool classifying `raise Exception('XYZ')` as code smell.

Do not see how ValueError tells you more, especially when Exception is combined combined with `XYZ` message.
 
Well, at least you know that it's not a TypeError
But yeah, I'm not a huge fan of ValueError either. XyzHappenedError() would be ideal.
 
2:52 PM
I think linter's problem with raise Exception('XYZ') is less about it not telling YOU anything, but rather not telling PROGRAM anything.
As in, you can't except this specific error without a) using generic except or b) parsing error message of each exception and reraising it if it does not contain 'XYZ'
 
attribute.value if attribute else None

Is there any nicer way returning None if the attribute is None?
It feels a bit ugly doing it like this.
 
attribute.value or None?
 
Hmm, what happens if attribute is None there?
 
@Warcaith Nope
 
Wouldn't that throw an exception?
 
2:54 PM
ret = None
if attribute:
    ret = attribute.value
return ret
Not sure if that's cleaner though
 
@matszwecja Well, it's clear, but not suitable if you need a one-liner (for example when initializing things in a constructor call)
 
@matszwecja Shall not there be a way to raise a general exception in if clause?
 
Not sure how if clause would change anything
 
 
1 hour later…
4:30 PM
@NordineLotfi This was possible in Python 2.
 
4:52 PM
I see :o Thanks for the heads up
 
5:37 PM
I was trying to zip 2 values and then append them in a list.. one of which gets incremented in a loop. I am getting this error TypeError: 'float' object is not iterable

This is what i have written : DUT1_zipped.append(list(zip(v_avg1, v_dut1[v])))
Can anyone help me out?
 
 
1 hour later…
6:44 PM
@SajeevPillai Not without an Minimal, Reproducible Example
 
6:55 PM
Hello, I have a question. I am trying to create a function that produces random variables of exponential distribution, but in what was given there is something that confuses me. The function has as arguments N (nr. of random variables), tau(which is present in the exponential decay),tmin(lower boundary) and tmax(upper one). My question is, why do i need tau here?
I can easily produce random variables with exp. distribution, without the need of tau
is there a reason for that?
 
7:20 PM
@imbAF This sounds not like a Python question, but Mathematics. What I read: "I need to create a function that produces random variables of exp dist...I have done so. What does Tau do?"
 
I can produce random numbers with exp distribution without using np.random.exponential
but in doing so, that involves no constant
and I am given that constant in what i need to do
 
Sounds like a question for your Professor...
 
Indeed
But, do they reply on time, is the question xD
 
If it helps - the source on exp dist formulae here may clarify one way or the other for you: eg.bucknell.edu/~xmeng/Course/CS6337/Note/master/node50.html
@imbAF Python board is not a substitute for that. Sorry
Best of luck.
You are aware of math.stackexchange.com ?
 
Ok thanks for the link
Will look at it
 
7:26 PM
may wish to try there instead
 
it's not a math problem per say
I can easily find on the net, or do it myself, that is, produce a set of random numbers with values within an interval, that have an exp. distribution
I can do that
the issues is that, how it is presented in my exercise
I need to also incorporate the tau
which is that factor in the exp. distribution
but you don't need to do that
if you are asked to produce random numbers
of that distribution
 
But you can do it? Then just do it
 
@Aran-Fey Let it be - that's not his actual question. Ask yourself, WWRD (what would rogan do)
 
7:40 PM
I cannot do it, because it tells me to use a constant /factor
which isn't necessary if I only have to produce random nr. of that distiribution
unless there are some qualities that they need to fulfill, which is not mentioned
 
 
2 hours later…
9:42 PM
@Elysiumplain I read the link. The thing is, that what is described there gives me random variables with exp. distribution withing the 0-1 interval. All I need is that but to change the interval values
 

« first day (4435 days earlier)      last day (514 days later) »