« first day (4212 days earlier)      last day (751 days later) » 
02:00 - 23:0023:00 - 00:00

2:49 AM
hi guys greeting, do anybody have knowledge in image processing and filtering, I just wanted to know a few things
 
 
4 hours later…
Wes
6:46 AM
is there a way to provide a default argument that is evaluated at instantiation time rather than definition time?
eg def foo(start_time: float = factory(time.time)):
 
provide None as default, then inside function use an if condition against None, and set it there
 
Wes
7:07 AM
ok, thanks
what does it mean "default argument value is mutable"?
arg: list[list[str]] = [[]]
aren't tuples, sets, dicts, mutable too? :thinking:
 
@Wes Tuples aren't mutable.
 
@roganjosh Got an answer after the ticket has been escalated, the guy literally copy-pasted the documentation to tell me what I want to do is impossible... Which was the point of my enhancement request... :)
 
@MisterMiyagi I don't read the spamblog. Can you pinpoint the issue?
 
7:36 AM
@AndrasDeak--СлаваУкраїні Almost the entire article, actually. Gems like "Examples of sets include [5, 10, 15, 20] and [5, 10, “Hello”, “World”]."
There's a for x in range (0,3): loopname = locals()['btcwallet' + (str(x+1))] at the end, for good measure.
 
That describes it well.
 
> There are many more advanced data types in Python, including classes, instances, and exceptions.
too bad I can't be yammed to post a critique on meta
 
I thought these articles were supposed to be written by people who actually know what they are talking about
I mean, it's not 'easypythonblog.net'
 
7:56 AM
@MisterMiyagi Wow, what a ride that was! From terrible code to indentation errors, wrong quotes and even broken syntax highlighting as the cherry on top. I rate this a 5/7 sh*tpost
 
8:12 AM
@Aran-Fey What would be the two missing points ?
 
You don't understand. 5/7 is a perfect score
 
I guess xkcd really isn't radical enough anymore...
 
if self.color = ‘red’ or self.color = ‘black’
	return True
return False
@MisterMiyagi People insist on doing this rather than return self.color in {'red', 'black'}. I should start a campaign about Python anti-patterns (if there isn't one already).
 
8:29 AM
@holdenweb Please do so! I think it would actually be very useful to have such things as a reference.
 
@holdenweb can we solve the problem of people remembering the DON'T version in a DO-DON'T comparison?
 
@AndrasDeak--СлаваУкраїні There's a DON'T version?
 
9:04 AM
I figured it's hard to say "use return self.color in {'red', 'black'} instead" without saying the DON'T version
 
@holdenweb I've seen so much worse than that
 
9:59 AM
Hello, what type of merge do I use to not lose any data on neither of my dataframes? I want to merge a 229 lengt df1 with a 30000 length df2, and the 229 lenght values shall be duplicated in case they appear multiple times in df2. I tried outer and left merge, but I always lose a significant amount of data. does someone know why? thank you
 
could you make a mcve?
 
10:33 AM
@MisterMiyagi oh god. "Class", "comlex", "if bool()", variable variables, spaces before () in call. Nooo
This is genuinely upsetting
 
Should we write something up on meta after all? I'd love to not read that if possible.
 
"useful sequence functions like get_item(), set_item()", spaces in argument names (self, char1, char 2) Yaaam
 
late april fools?
Has anyone mentioned 8-space indentation yet?
but only sometimes
I can see a 16-space indent too
> [Note: code operation was verified using the ExtendsClass Python checker.]
not the best kind of spam
 
:D
Maybe they "got hacked", or whatever the standard excuse is for stuff like that
 
28
Q: Many bad typos in the "Underscoring (or dunder-scoring) the importance of native type methods in Python" blog post

richardecI was skimming the latest SO blog post, when I quickly noticed a rather obvious typo in the table of numeric built-ins: comlex should be complex! I wouldn't normally take much notice of a typo, but as this in a rather exalted position (and in large font)... ;) The Car class example also has a l...

6
I need to wash my brain
 
11:02 AM
Yes, it's so bad it's a terrific example of damaging misinformation. I feel sorry for whoever wrote it. It reads like it might have been Zed Shaw ...
 
I'm not a huge fan of his but I don't think I've seen any typos like that or gross syntax errors coming from him.
 
At least the author is protected by Stack Overflow's CoC, which prohibits subtle put-downs
 
@AndrasDeak--СлаваУкраїні I'm unclear on the meaning you are ascribing to DO-DON'T comparison. I imagine you aren't thinking of return self.color not in {'red', 'black'}?
 
@holdenweb no, I imagined "campaign about Python anti-patterns" to include the anti-pattern as well. Hard to talk about anti-patterns without showing the bad pattern itself.
# DON'T:
if self.color = 'red' or self.color = 'black'
	return True
return False

# DO:
return self.color in {'red', 'black'}
on one way or another you'd have both options, and people have a tendency to often remember the DON'T version
 
Sure. As in towardsdatascience.com/…, which would make a good start on such a list.
# DO:
return self.color in {'red', 'black'}

# DON'T:
if self.color = 'red' or self.color = 'black'
	return True
return False
Might be a more helpful way to present it.
 
11:54 AM
Don't forget to include the DON'TN'T case, if (self.color == 'red' or self.color == 'black') == True:
 
I must admit, bad case first, then good case, is so much more common that seeing the good followed by bad feels jarring at first. Not sure if that's just me or others also
But it might be the better way to present things perhaps. Not sure.
 
Might be a good idea to have the bad cases first but collapsible.
That way you don't give people too many funny ideas, and the good approach will be the one they see in the end.
 
The /do(n't)+/ series is infinite, so it does seem prudent to put it in a collapsible container
 
nested collapsible containers?
 
Give this man a raise
 
12:01 PM
a triple chocolate vanilla cookie coffee would suffice
 
I have configured my cosmic energies so that you are 1% more likely to encounter cookies today
 
that explains why I got one an hour ago. Nice!
 
Mmm, retrocausal
 
cabbage
anyone here doing pycon this year?
 
12:49 PM
Not I
 
I thought all those examples using if condition: return True ... return False instead of return condition were ... unfortunate. But then I saw that for loop at the end, with the locals() stuff. Yikes! — PM 2Ring 15 hours ago
Actually, return self.color == 'red' or self.color == 'black' is ok because it short-circuits. self.color in {'red', 'black'} is nice, and its efficient because it builds the set at definition time, but a set is overkill for only 2 items. A tuple uses less RAM, and the lookup time is (probably) faster, since it's only a short linear search & a set lookup requires hashing.
 
semantically speaking the set is the correct choice there
 
Sure, and it's a good pattern to teach (& to learn).
IIRC, the break-even point's around 8 or 9 items. I have some timeit code for this somewhere... But there have been some changes since I wrote that code. :)
 
In current versions, Python will automatically use a tuple in this case AFAIK.
Frozenset, actually. (CPython 3.8.12)
 
Nice
 
1:04 PM
@MisterMiyagi probably to keep the hashability check
>>> [] in frozenset({1})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> [] in (1,)
False
 
Hm, true, removing that would change things.
 
Of course, the "new" hash function is still very fast, and has better properties than the old one.
Feb 15 at 11:16, by PM 2Ring
FWIW, the built-in hash used to be a modified version of FNV, but now it's SipHash. See https://www.python.org/dev/peps/pep-0456/
 
1:48 PM
There's perhaps something to be said for BEST/OK/DON'T or some such, because much as there ought to be one and only one obvious way to do things, we all know that circumstances alter cases (e.g. short lists are sometimes as good as sets).
 
2:20 PM
how to parse xml based rss like this site
https://www.antaranews.com/rss/terkini.xml
tried using xml element tree. it produced invalid token
tried using parserfeed it wont read anything
I'm really confused
 
elementtree should be able to read it
 
i got this error with ET not well-formed (invalid token): line 1
 
import xml.etree.ElementTree as ET
import requests
data = requests.get("https://www.antaranews.com/rss/terkini.xml").content
root = ET.fromstring(data)
print("Succesfully parsed data. Root tag is:", root.tag)
Output: Succesfully parsed data. Root tag is: rss
 
thankyou!. i was doing it wrong
 
No problem :-)
 
2:47 PM
@Kevin I found out too late to register for in person events. I'm doing the online event. Sad, though, since it's like 30 mins from where I live.
 
Alas
 
I'm not currently doing much python lately, so pycon wasn't high on my things to pay attention to.
 
 
2 hours later…
4:40 PM
Can anyone please help me; How do i get all values in between two points in an array, for example, x = [1, 2, 3, 4, 5, 6, 7, 8, 9], I now need to get everything in between 2 and 7. Thank you!
 
x[x.index(2):x.index(7)+1]?
 
@Combobulated When you say "array", do you mean "list", and when you mean "two points", do you have indices or values?
 
start = x.index(2); x[start:x.index(7, start + 1) + 1]
 
for a less ambiguous example input: x = [10, -1, 3, 8, 42].
 
For a less clear example input, what is the desired outcome if the list is [10, 2, 2, 11, 7, 12, 7, 13, 2, 14 7]?
 
4:48 PM
So to make things more complicated I have a 2d array, ([1, 2], [3,4], [5,6], [7,8], [9,10]). I need to get the Second value, based on all the first values in between 2 points.
Is there a way to do this?
 
:S
 
alright then, keep your secrets
 
p.s By "array" I think I mean list, (x=[1, 2]...) and for "two points" I think I have values
Im not realy sure of the diffrence
 
I don't understand the question. Can we have an MRE? Your inputs are ([1, 2], [3,4], [5,6], [7,8], [9,10]) and what else? And the output you want is what?
 
4:54 PM
These are good questions. Please answer these questions, Combobulate.
 
For example, ([1, 200], [2, 866], [3, 14], [4, 98], [5, 32], [6, 9], [7, 0]) The output I need is everything in between 2 and 6 (for example), so that would be [866, 14, 98, 32, 9]
 
This is the kind of question that would benefit from 4-5 test cases
 
Strictly speaking, that doesn't answer the question
 
Which question?
 
@Aran-Fey yes, Thank you, that does work (for my first question)
 
Interesting problem. It's not hard, and yet I can't think of a nice way to do it...
 
I'll revise my question, since the input I asked about is no longer in the right shape. What is the desired output when the input is [(10, 15), (2, 16), (2, 17), (11, 18), (7, 19), (12, 20), (7, 21), (13, 22), (2, 23), (14, 24), (7, 25)]?
 
@AndrasDeak--СлаваУкраїні How?
 
5:01 PM
By my count, you have four unanswered questions remaining
 
@Kevin - If my two points are 2 and 7, the output should be [16, 17, 19, 21, 23, 25]
(But the first numbers will be in order anyway, as well as no duplicates)
 
Ok, makes sense.
 
Wait what
 
If the first numbers were also guaranteed to be sequential, and to always start at 1, then you could find the answer quite easily
 
Ps the faster the program runs the better
@Kevin - They will not start at 1
 
5:04 PM
catching up... but answer to first question: [*filter(lambda y: 2 <= y <= 7, x)]
 
@Combobulated That's not everything between 2 and 7, that's the 2nd tuple element of every tuple that starts with 2 or 7. This is completely different from what you said you want...
 
I suppose it's sufficient to only guarantee that they're sequential. You could start at 1234, as long as 1235 follows that, and 1236
 
They will not be sequential, but in order
 
@Aran-Fey Oh, you're right. I retract my "makes sense", regretfully
 
Oh, it makes sense if we're talking about values between 2 and 7. I thought we were talking about indices
 
5:07 PM
Oh, darn. With sequential-ness, we could have had an O(1) solution*. Well, ordered-ness might let us reach O(log N), which beats using a loop
 
@Aran-Fey Whats the diffrence?
 
(*for the problem as I imagine it)
 
@Kevin I doubt that
oh, you mean sequential as in redundant index
 
@Combobulated Say the input is [2, 9, 7, 4]. What you want is [2, 7, 4]. What I thought you wanted is [2, 9, 7].
 
@Aran-Fey Yes, but the second number in that 2d array
 
5:10 PM
No idea how that relates to my example with 1d arrays
 
@Aran-Fey Meaning to say, that is what I mean by between
 
>>> left = 2
>>> right = 6
>>> seq = ([1, 200], [2, 866], [3, 14], [4, 98], [5, 32], [6, 9], [7, 0])
>>> [item[1] for item in seq if left <= item[0] <= right]
[866, 14, 98, 32, 9]
 
import numpy as np

x = np.array((
    [1, 200],
    [2, 866],
    [3, 14],
    [4, 98],
    [5, 32],
    [6, 9],
    [7, 0]
))

x[(2 <= x[:, 0]) & (x[:, 0] <= 6), 1]

# array([866,  14,  98,  32,   9])
 
Anyway, since you said the input list is sorted, it doesn't really matter
 
My approach is O(N). The theoretically possible O(log N) approach is left as an exercise to the reader, unless someone wants to pay for my premium tier service
 
5:16 PM
left = bisect.bisect_left(x, 2)
right = bisect.bisect_right(x, 7, left+1)
result = [pair[1] for pair in x[left:right]]
(Untested, and needs a key function)
 
did we get an answer to the question on whether the index can be redundant? and are they always integers? (as in no floats) this is possible [2, 3, 4, 7, 9] but this is not [2, 4, 4, 5]
 
@Kevin @piRSquared They both work, but don't include 7. Is there a way to do that
?
@piRSquared They are floats
 
Mine doesn't include 7 because you specified "the output I need is everything in between 2 and 6 (for example)"
To answer your question, yes, there is a way to do that.
 
@Kevin Oh right :)
@Kevin Your solution seems to work as intended, thank you
 
@Combobulated So we could be looking for all items between 1.001 and 3.141?
 
5:24 PM
yes...
im still testing
It seems to work for that as well
 
I endorse Aran-Fey's bisect approach as worth investigating. It's what I would have started with if anyone had sprung for my premium service.
 
@Kevin Why is it better?
 
Needs a key=operator.itemgetter(0) and some research into what happens if the input doesn't contain 2 or 7
 
If the index items are unique, I'm still inclined to use Numpy and searchsorted to find the first index from the left side then again from the right side and be done.
 
@Combobulated Bisect uses a "divide and conquer" search algorithm that performs significantly better on very long inputs, compared to regular loops.
 
5:29 PM
So is the bisect aproach possible? Iv never used it before, so im not realy sure what it does
 
@Combobulated time to look it up then
 
It's possible.
 
@AndrasDeak--СлаваУкраїні :) I will
ps as for my data size, it is an array with around 300 values altogether. I am working on a millisecond basis
So out of all the above approches can anyone advise me on what would be the fastest?
 
With only 300 values, bisect might not even be worth using
 
@Combobulated depends on many things so you'll have to compare options
 
5:33 PM
But the only way to know for sure is to try and see
 
Performance benchmarking is infamously difficult to do remotely
 
@Aran-Fey every millisecond counts. Do you nevertheless think it is not worth using?
 
Unless you want to give us remote desktop access and administrator permissions... [I steeple my fingers sinisterly]
 
@Kevin will my bank pin help as well?? :)
 
I think it's fairly likely that bisect will be slower than other solutions. If every millisecond counts, then go and measure which solution is the fastest.
 
5:35 PM
Well, it couldn't hurt*!
(*specifically, it couldn't hurt me)
 
@Kevin :p
Ok il try all of the above, thank you everyone for your time.
 
Hello everyone. :D
 
@JakeSteffan Hi
 
cbg
 
Last night I learned about a lot of the other magic methods, like add but it was confusing me. Will knowing these various magic methods help me at all when it comes to building my game or are they not used very much?
Hi Combobulate
I also learned about properties, and decorating methods like class methods and static methods. It's all pretty confusing to be honest. What's the best source to understand all of this clearly?
 
5:45 PM
A good amount of my graphics-related projects make extensive use of dunders
More specifically, they all depend on a custom Point class I wrote to make vector mathematics easier. Without implementing __add__, you won't be able to do Point(23,42) + Point(7,11)
 
@JakeSteffan not the new stackoverflow blog post. Don't read that one.
 
Oh I see, thanks a lot.
 
Kivy might already have a Point-like class. It's fairly typical in frameworks that draw stuff on the screen.
Rect is also both common and helpful
 
Yeah I'm going to be making my game in Kivy, although I still have to get that "aha!" when it comes to OOP first lol.
 
5:51 PM
I finished most of Python Core in Sololearn, and the comments for each exercise and question are very useful. Their OOP segment is so bad and confusing, almost all of the comments now are like "I have no idea what any of this means." But there was a guy who said "For two weeks studying OOP had my brain in scrambled eggs, but then one night I had a dream and it all clicked." So I'm hoping that happens to me soon.
Oh I wonder if I can create a map using that.
Since it has x, y.
I'm following a youtube video right now where a guy is creating a text based RPG game, but only in the interpreter he's not using a GUI, and his map system isn't even object oriented but it's a start lol.
 
I've implemented map-like objects using Points in a dict. Depends on what the map needs to be capable of, and how quickly it needs to do it
 
Well the thing about why I'm okay with creating this game in Python is I'm not going to be using any animations, and the visuals are going to be pretty minimalistic, although I do want it to look sharp and aesthetically pleasing.
 
For roguelikes, an ordinary list-of-lists may be the right approach
 
So the map will basically be a bunch of map tiles, similar to Civ games, except just squares and not hexagon shaped.
So okay let me know what you think about this:
So my character is going to be able to travel through the map tiles, but each map tile is going to be kinda packed full of info. In each tile I'd like to be able to create a menu that allows the player to select options. For example:
One option would be to Examine the Area, and when it's Examined there will be things like Trees, Plants, Mushrooms, Rocks and things that can be examined.
But then there will also be another menu that pops up, for each of the different resource types. Do you think this will be difficult to create?
 
"packed" is a useful detail. a dict of points is more suited for sparse maps where most cells are totally empty. If every single tile contains something, a list of lists is very likely to have better performance
 
6:00 PM
Okay cool, I noticed this guy creating his RPG game without a GUI is using a dictionary within a dictionary to create the map.
So you say it's better to use a list within a list?
 
Yeah, but if your map is like 100x100 tiles, it won't be a huge difference in performance
 
I think I'm gonna go something like 200 tiles total, I'm going to try to go deeper not wider if you know what I mean.
So will that be a problem?
 
@JakeSteffan I think each small piece of your design is fairly simple to implement. I think the challenge will be keeping everything neatly organized as you put it together.
@JakeSteffan It should be fine.
 
Hey all riddle here that I dont understand
brand = 'mádara'
brand1 = 'mádara'
print('á' in brand)
print('á' in brand1)
print(brand == brand1)
difference = set(brand1).symmetric_difference(set(brand))
print(difference)
False
True
False
{'á', '́'}
why are the two brand variables different when they sem to be the same
 
Okay also one thing will be that every resource object will have different randomly chosen attributes, so with a map that's 20x20 do you think because of this the performance will take a big hit? Or is performance more based on the fact that your game has animations?
 
6:06 PM
If clicking on tile A opens menu B, and clicking on B's subitem C opens menu D, and clicking on D's subitem E opens Plant Status Popup Window F, then you're juggling six different entities at once, most of which need to be accessible even after you're done rendering this one frame... It's easy to end up with a big plate of spaghetti
@JakeSteffan No, performance should be the same whether the attributes are random or not
 
Oh man, that was really helpful.
Yeah I'm constantly worried that my code will become what I've been hearing is "spaghetti code", I'm afraid to do anything lol.
Do you think this will be difficult to make using Kivy? Or pretty easy? As far as the pop up menus going down that type of rabbit hole.
 
@Kwsswart they don't compare equal because they use different sets of characters
They are visually different too
 
'mádara' && 'mádara'
They look the same to me
 
@Kwsswart Perhaps they have different unicode representations. Try print([ord(c) for c in the_string]) on both of them. I bet the results are different.
@JakeSteffan I'll go with "medium difficult"
I've always found menus a bit fiddly, regardless of what framework I'm using
 
çHMM interesting so it seems the typing of brand has an additional character in it
print([ord(c) for c in brand])

[109, 97, 769, 100, 97, 114, 97]
print([ord(c) for c in brand1])

[109, 225, 100, 97, 114, 97]
 
6:12 PM
Thanks for all the help Kevin, I'll go practice more OOP stuff now.
 
Quite strange how they look the same but they are different
 
@vaultah You have an extremely good eye
 
The strings look the same in Notepad++, but here's what they look like when pasted into cmd
Windows, you hot mess
 
Lol I am on linux so even linux has it wrong
 
6:16 PM
@Kevin I see you have a good eye too
 
:-)
import unicodedata
brand = 'mádara'
brand1 = 'mádara'
print([unicodedata.name(c) for c in brand ]) # ['LATIN SMALL LETTER M', 'LATIN SMALL LETTER A', 'COMBINING ACUTE ACCENT', 'LATIN SMALL LETTER D', 'LATIN SMALL LETTER A', 'LATIN SMALL LETTER R', 'LATIN SMALL LETTER A']
print([unicodedata.name(c) for c in brand1]) # ['LATIN SMALL LETTER M', 'LATIN SMALL LETTER A WITH ACUTE', 'LATIN SMALL LETTER D', 'LATIN SMALL LETTER A', 'LATIN SMALL LETTER R', 'LATIN SMALL LETTER A']
 
@Kevin My lord that is handy! thank you
 
Ah yes, combining characters, bane of programmers everywhere that want to find the "width" of a string rather than its len
 
Thank you @Kevin && @vaultah
 
unicodedata.name("\U0001f44d")
 
6:26 PM
🆒
or 'SQUARED COOL', like a cool person would say
 
6:51 PM
Hi. What can be reason appearing nan values in loss of pytorch? I tried to gradient clipping,decrease learning rate but none of them worked.
 
 
1 hour later…
8:01 PM
@piRSquared hey... long time no see - how's things?
 
@JonClements o/ going well. Working hard. Kids growing up. You?
 
the same but without the kids bit :)
 
8:15 PM
Hey guys I'm using PyCharm and it says I don't have a system interpreter, I looked at the jetbrains manual but it still isn't allowing me to access it. Is this a common issue?
 
8:32 PM
ps1 cannot be loaded because running scripts is disabled on this system. For
more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
I'm getting this message.
Nevermind, I fixed it lol.
 
8:56 PM
I have another question lol.
So a few weeks ago I created a text based game, nothing great. But I played around with how to manipulate text to the interpreter to make it read a certain way, well I'd like to use this same setup for a new one just to practice on, but I'm sure there's a more efficient way of doing this. Anyone know how to make it more efficient?
import sys
import os
import random
import time

def quicker_print(str, delay = 0.03):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay)

def quick_print(str, delay = 0.05):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay)

def slow_print(str, delay = 0.08):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay)

def slower_print(str, delay = 0.10):
 
Technical note: that's a bit too much code for chat. Consider using a code paste service like pastebin or github gists next time.
 
Okay I'll note that.
How would I make it DRYer, would you say?
 
These are all the same function with different delays. So not defining all of them with different default delays would be a start.
 
Yeah I figured that'd be what I need to do, does time.sleep take a second parameter?
 
How does time.sleep's arguments come into play?
 
9:07 PM
Or could I do this: def slow_print(str, delay=n): and then have time.sleep(delay, n)?
 
I'm talking about using that_one_timey_print(s, delay=delay_value)
@JakeSteffan yes, just like you are doing now, for various values of n hardcoded
 
yeah... you definitely don't really need 3 functions doing the same thing except a value :)
 
If I wanted to do something like this I'd take one function and give it tiers of speed, that_one_timey_print(s, speed=0), then pass speed=-2 for slow and speed=5 for lightning, or whatever. The function would map speed tiers to delays.
 
John, you haven't seen the rest of the code. :D
 
9:09 PM
@AndrasDeak--СлаваУкраїні I'm use to it Andreas :p
 
Lol sorry.
Interesting...
I kinda follow but not really, as far as speed tiers.
 
you'd have thought going for "Jon" would be simpler than "Jonathan" (and I've had way more "interesting" spellings of than I can count)... :p
 
@JakeSteffan I just want to save you from having to do that_one_timey_print(s, delay=0.05), having to work out the delay each time you call the function
Alternatively you could have a "constant" dict that maps speeds to delays which you could use. Doesn't matter.
Just end up using the same function with various parameter values to set the speed.
 
Sometimes I wonder if you remember how absolutely noob I am at this haha.
 
9:12 PM
@JonClements Jonatan because the h is missing
@JakeSteffan your being a noob doesn't change how you could solve the problem, it just means you need more time to get there
 
Alright so how about this: def speed_dict:
well def speed_dict():
 
@AndrasDeak--СлаваУкраїні I had a birthday card one year "Jhonothon"... I've kept that somewhere as I found that the most hilarious card I've received... but also one of the most important in my heart as it was from a friend that is no longer with us and he still managed to do it after a rather serious stroke
 
(the writing's completely yammed... but you can make it out... and that's precious to me)
 
9:15 PM
That was an emotional plottwist.
speed_dict = {1: delay=.03, 2: delay=.05, etc?
 
That's invalid syntax
Don't get bogged down in my specific suggestion. What is logical to me might not be logical to you. There's one hard constraint: use the same (one) function to do that timed printing of yours. How you wrangle your various times into that is up to you.
 
Okay I'll be back with something.
def slow_print(str, delay=n):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay=n)
It's showing errors with n. :/
 
so far so good
@JakeSteffan well, that means you don't have n defined by the time the function is defined
 
So... I have a Python program that runs a while True loop to collect data. I now need a GUI to display the data my while loop is getting. The problem is that all the GUI libarys for python do not let any code run after the app is displayed, (since they themselfs use while loops). I am currently using GUIZero, though I am open to use anything. Does anyone know of diffrent GUI libary that will do better, or an elegant way to avoid this problem?
I cant imagine .repeat will be very fast or optimized. Ps the speed of my program is of essence (to the millisecond)
 
@JakeSteffan on function call you'd probably get an error from time.sleep
 
9:24 PM
Sorry to break into a conversation :)
 
@Combobulated always feel free. Directed replies are here to disentangle parallel discussions.
 
def slow_print(str, delay=n):
    n = {1: 0.1, 2: 0.3, 3: 0.5, 4: 0.7, 5: 0.9}
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay=n)
Closer?
 
@JakeSteffan really?
it might be time for you to take a break. Go take a walk, take a nap, something. When you're playing guessing game it's a good sign you're no longer focussing.
 
Anyone else know how to get this working correctly? I'm lost lol.
I'm not even sure what stdout or flush means, I just took it from this other guy that was making his rpg game.
 
9:40 PM
@JakeSteffan yes, but also Andras is right
 
n = {1: .01, 2: .03, 3: .05, 4: .07, 5: .09, 6: .11, 7: .13, 8: .15, 9: .17, 10: .19,
     11: .21, 12: .23, 13: .25, 14: .27, 15: .29, 16: .31, 17: .33}


def slow_print(x, delay=n):
    for letter in x:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay=n)
It says default argument value is mutable.
But I think I'm almost there.
The default argument value n apparently can't take in a dictionary.
 
Anyone have any suggestions for me?
 
@JakeSteffan Why are you passing time.sleep a dict? Also, time.sleep doesn't take a named arg.
And there's no need for a dict. You can just calculate the delay.
import sys, time

def slow_print(text, speed=1):
    delay = (2 * speed - 1) / 100
    for letter in text:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(delay)

slow_print("This is a test", 3)
 
10:05 PM
@JakeSteffan Why do you declare delay in def slow_print(x, delay=n): but then never use it?
 
@Combobulated This is a big topic. You need to learn how to do stuff in conjunction with the GUI event loop. It's a different mindset to how simple terminal-based programs work. Any good GUI library tutorial will have basic examples.
Typically, your program "sits" in the loop, waiting for events, and responds to them when they happen. And there are Gui library functions you can use to schedule tasks in various ways. It's not easy for us to teach this stuff from scratch in a chat room, but we can help with specific focused questions. And there are numerous examples on the main site.
 
10:26 PM
I've been asking this question in the regular ask questions section and a guy is helping me out with this, this is what I have so far:
char_delay = {"1": .01, "2": .03, "3": .05, "4": .07, "5": .09, "6": .11,
              "7": .13, "8": .15, "9": .17, "10": .19, "11": .21, "12": .23,
              "13": .25, "14": .27, "15": .29, "16": .31, "17": .33}


def slow_print(x):
    for letter in x:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(char_delay[letter])
It's almost working but I don't understand what parameters I'm supposed to give slow_print now, x is clearly not it. But I have 2 warnings and no errors which is a lot better than what it was.
 
Sigh
 
@JakeSteffan time.sleep(char_delay[letter]) doesn't make much sense. What do you think will happen if letter isn't one of the keys in char_delay?
Try my version. It works. ;)
@vaultah I love the smell of cargo in the morning
@Combobulated I haven't heard of GUIZero before, but it looks interesting. It has .after & .repeat methods you can use for scheduling stuff. I assume the GUIZero book tells you how to use them.
 
That's what one of the guys in my answers told me to do.
 
Good thing they didn't recommend rm -rf
 
Part of the reason I can't see the issue is because I really don't understand sys.stdout or flush or what's really going on, since it's borrowed code.
I'm not actually that familiar with the time module either, I just started learning OOP a couple weeks ago.
 
But I've already said that a few times.
 
We keep saying things, you keep saying things. That's how it goes.
 
Well if you want to play some chess we can do that, then when you lose I can be like "dude, why did you move there" LOL
 
sys.stdout.write is just a lower level way of printing stuff to the terminal. The main difference (as far as this code is concerned) is that it prints without sending a newline. The sys.stdout.flush call says we want that stuff to be printed now. Normally, the terminal prints stuff a line at a time. The flush tells the terminal not to wait for a newline. (Roughly speaking)
 
10:41 PM
@JakeSteffan if you feel that your lack of understanding of sys.stdout and sys.stdout.flush is what's holding you back, what have you tried to understand those things?
 
Oh okay that's interesting. Between learning a million things a day I just honestly haven't gotten around to it yet lol.
Actually there's a couple other things that I've wondered about too, like the os.clear thing.
What's the difference between this:
def reset_console():
    print("\n")
    os.system('cls||clear')
and:
 
@JakeSteffan I think I was more than generous yesterday helping you out, as are others here right now and also then, however - it seems that when we suggest things to help you - there's an element of "someone told me to..." - I'm not sure what's going on here?
 
A system exit which I forgot how to do, I'm guessing it's exit().
 
@JakeSteffan how about you don't guess and do a simple search :p
 
I'm trying to switch up my search routines that's why I'm here, to color up my learning lol.
There's only so much python documentation I can handle in one day, I'm doing this like 10 hours a day.
 
10:45 PM
fastest way to get an answer is to post a wrong one etc.
 
right... but if you've already got a mentor - shouldn't you be nudging them?
 
@JakeSteffan it's almost like you need a tutorial and a rest
 
Oh I don't have a mentor, he's the guy that answered in the ask a question section.
 
Suggested multiple times, in that order
 
@JakeSteffan umm... but the other day... wasn't it "she suggested that..."?
 
10:47 PM
Well I've been watching a lot of youtube tutorials, then I'll look at documentation, then come here, then play on my IDE and just switch it up here and there.
Oh and I have a bunch of Python learning apps that I bounce around in when I don't have my laptop.
Just remember guys 6 weeks ago I didn't know what a variable was lol.
 
@JakeSteffan Actually, we don't need that sys.stdout stuff at all. I only used it because your existing code did, and I wanted to make minimal changes. That technique was necessary in ancient Python. Modern Python can do char by char printing with the print function.
def slow_print(text, speed=1):
    delay = (2 * speed - 1) / 100
    for letter in text:
        print(letter, end="", flush=True)
        time.sleep(delay)
 
pondering why one would need char by char for stdout... normally you'd use stderr so you don't have to worry about buffering or you'd from the outset unbuffer stdout...
 
@JakeSteffan you may have noticed that you were given a lot of help with open arms at the start, but now enthusiasm is dwindling. That's because patience is a non-renewable resource. We love helping newbies and non-newbies learn. But the more we see "because some guy gave me that code" and "I tried this random thing, is it correct?", the more people will feel they're wasting their time. You ask for our help, but then don't make good use of it. We told you to take a break, you doubled down.
You can't ask for help and then try to shake the magic 6-ball until it gives you the answer you demand.
 
@AndrasDeak--СлаваУкраїні (much better put than my message)
 
@JonClements Well, it looks cute in a game that runs in terminal.
 
10:57 PM
okay... so that site I occasionally use seems to be working fine lmao
unless everything's styled white on white (which it's not...) ugh
how do companies let things like this slip through QA and UAT
(guess the main reason is they don't bother with either)
 
02:00 - 23:0023:00 - 00:00

« first day (4212 days earlier)      last day (751 days later) »