« first day (4211 days earlier)      last day (738 days later) » 
00:00 - 18:0018:00 - 00:00

@JakeSteffan I'd have to agree with Andras here re: structured learning... are you actually following a tutorial or guide or anything like that?
 
I've completed Mimo beginner guide and Sololearn Beginner and Core courses.
 
What is the proper way to sort list?
import random


def Shuffle(x):
    for i in range(len(x) - 1, 0, -1):
        j = random.randint(0, i)
        x[i], x[j] = x[j], x[i]
    return x


n = 0
while n < 10:
    y = list(range(1, 10))
    Shuffle(y)
    print(y)
    z = y.sort()
    print(z)
    n += 1
 
@JakeSteffan okay... that doesn't actually mean anything to me I'm afraid - not things I've heard of... have that pushed you towards OOP stuff or is that you deciding to give it a go?
 
I am self taught and in my 6th week now, trying to get the hang of it but struggling in some aspects. Most of my time has been spent just learning the basics. This is the first actual program I've tried to make lol.
 
12:05 AM
@TheCodeMocker unless you're asking why your weird algorithm doesn't work... then use the builtin functions you've already got in Python... your_list.sort()... ?
 
z = y.sort()
print(z)
produces None
 
.sort() is inplace so it returns None... if you want a copy then use z = sorted(y)... otherwise, .sort() will alter y... so you can do print(y)...
 
@JonClements: Good point. THanks. it works now.
 
import random

stuff = list(range(1, 10))
print('start:', stuff)
random.shuffle(stuff)
print('shuffled stuff:', stuff)
stuff.sort()
print('sorted stuff:', stuff')
 
I'm getting unresolved reference self errors so that's why I haven't used self.age, self.quality etc as arguments.
 
12:10 AM
@JakeSteffan so what's this Tree supposed to do?
 
I'm trying to create trees in an environment that contain randomized values within it's attributes.
 
I see. y.sort() mutates y. It looks counter intuitive at a glance. Because I assume python is immutable-oriented language. :-)
 
@JakeSteffan right... so you want to create a tree with no arguments and just have each attribute random?
@TheCodeMocker it contains mutable/immutable types and a list is mutable...
 
OK. Thanks.
 
Well honestly I have no idea what I want. I'm completely scramble egged right now.
I just want to be able to create an environment like a map for a character to walk in, with trees that have random qualities and such.
 
12:13 AM
@JakeSteffan that's the time to take a break and do something else and come back to it later :)
 
Well the reason I'm here is because I know that when I come back I'll be just as lost. :D
 
@JakeSteffan let's put it this way then... you define Tree as needing three arguments but don't call it with anyway?
 
Well I had in mind to call using self.age, self,quality, and self.wetness, but for some reason the self part receives errors.
 
and those errors more specifically are?
 
Unresolved reference "self"
 
12:17 AM
and you get a full exception pointing out the line for that, right?
 
I'm getting nine of the unresolved reference "self" errors, because of the missing 9 arguments.
3 each from the tree objects I tried to create.
 
@JakeSteffan yup... like I said... you've defined __init__ to expect 3 arguments and you're not giving it any
 
Well the thing is I can't give it any because let's say I give the Tree object a specific age right, let's say "Mature", well that's not going to be randomized.
Or since it's randomized I shouldn't give parameters to init?
 
it looks like __init__ should take no arguments and then you use your functions to do your values
 
Interesting.
Would that be the best way then?
 
12:24 AM
class Tree:
    def __init__(self):
        self.age = self.tree_age()
        self.quality = self.tree_quality()
        self.wetness = self.tree_wetness()
 
Ahhhhh.
:D
A big thanks to you man.
 
you should probably think about whether they should actually be functions that return something or modify the instance directly... but... that's probably something for later
 
Yeah what's interesting is earlier a lady helped me and told me they'd be better as functions because the problem is when they aren't the random.choices causes issues to the values of the attributes and produces copies. So she turned them into functions which I thought was a good idea.
But then I couldn't figure out how to get my code back to working again.
But apparently it fixed the original problem, at least I hope lol.
 
def display_stats(self):
    print(f"""
        Age: {self.age}
        Quality: {self.quality} out of [30]
        Wetness: {self.wetness}
    """
    )
 
Oh, I like that. :D
 
12:28 AM
that's probably a better idea for that as well - you're using a f-string but still doing weird stuff with str(...) and concatenation that's not needed
 
Yeah funnily I learned that exact thing about 3 hours ago lol.
Thanks for all the help man, it's incredibly appreciated.
 
 
6 hours later…
6:38 AM
def nse_write_oi():
    mydb = mysql.connector.connect(
        host="localhost",
        user="root",
        password="",
        database="bot"
    )
    if type(mydb) == mysql.connector.connection.MySQLConnection:
        return create_table(mydb)
    else:
        return "Not Connected"
def create_table(mydb):
    mycursor = mydb.cursor(buffered=True)
    mycursor.execute("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = %s AND table_name = %s", ('bot', 'trend',))
    print(mycursor.rowcount)
mycursor.rowcount is always returning 1 even though there is no such record. Any idea?
 
what's the point of that type check and string return in the first function?1
and selecting a COUNT always returns exactly one row, even a row with the count of 0 is a row...
 
@ThiefMaster I just wanted to make sure that connection established properly and I am returning string just for temporary purpose on the UI.
I also tried with
mycursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = %s AND table_name = %s", ('bot', 'trend',))
still no change.. Always returning 1
 
6:56 AM
ThiefMaster already gave you your answer: "and selecting a COUNT always returns exactly one row, even a row with the count of 0 is a row..."
 
There's no COUNT in that one though
 
True. Ok, selecting a table name where you have specified that the table name is "trend" would only return a single value provided that the string "trend" appears only once
I'm not familiar with information_schema but I'm assuming that's metadata and not their own schema. If it's the former, it could only return one row because you can't have more than one table sharing a name on a single schema
In any case, nothing has been specified about what the code is supposed to do. It's just given without context and a statement of "this doesn't do what I think it should"
 
7:34 AM
DenverCoder9 strikes again: unix.stackexchange.com/questions/477736/… I transformed by memory leak into a cached memory leak, now I'm out of my depth, since valgrind doesn't tell me much
 
7:46 AM
My serializer: Collects all objects that need to be dumped, looks for reference cycles, and tries to dump the objects in the correct order if it finds one
Pickle: Ooga booga, me recursively dump everything
Guess which one's the superior approach? That's right, it's pickle's. Which means I can throw a lot of code into the garbage bin :|
 
8:20 AM
That's a pickle... I had to :D
 
*shakes fist*
 
Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

Well I'm used to seems statement from me, but if even my os can't tell me if things are up to date then I don't know anymore. Quite weird that they decided to word it that way
 
Perhaps it's worded that way because you may have to update before upgrade
 
@AndrasDeak--СлаваУкраїні @MisterMiyagi do you teach Python or another CS topic ?
 
8:44 AM
@AlexandreMarcq Fairly sure he teaches Karate :p
 
... I knew I heard that before, never clicked!
 
9:00 AM
@AlexandreMarcq not even close
 
9:43 AM
Right now I'm preparing for "Collaborative Software Design", which is basically a superposition of "do you know how to turn on a computer?" and "ah, so you implemented your own OS when you were in Kindergarten?".
@JonClements *treats on, treats off*
 
ON ON ON !
 
Wes
apparently this is a good lightweight desktop ui library for python. too bad i didn't find it earlier github.com/joaoventura/pylibui
 
@Wes last commit in 2018?
 
> Documentation
>
> Needs to be written. Consult ui.h and the examples for details for now.
 
owner pretty much disappeared from github in the last year (probably more) it seems
 
9:51 AM
That's a no thanks from me
 
Wes
10:04 AM
i am sure it's still better than the alternatives
 
Wes
pysimplegui feels like half of it is held together with duct tape. the other half just doesn't work at all
but it gets daily commits
 
What if I told you that being still maintained is merely a necessary rather than sufficient condition for safely relying on a library?
 
Wes
it's a gui toolkit, it's not like new types of buttons or checkboxes get invented every day?
 
The abandoned wrapper has 11 open issues, the abandoned wrapped library 174. But I'm sure those are just noise.
you should go for it
81 open PRs too, probably just typo fixes in the documentation. The one that needs to be written.
 
Wes
10:16 AM
do you ever not talk sarcastically
 
Judging by the examples, it seems you have to create a subclass every time you want a widget to have an event handler? That's nuts
 
Wes
that was sarcasm again
 
10:35 AM
At least Andras' sarcasm is easily detectable
 
Aran-Fey and vaultah, a match made in communication hell
 
I didn't even say anything!
 
yeah, you're that bad at it
 
And I was about to congratulate you on your well-honed sarcasm, too
 
hehe
never too late to compliment me
 
10:38 AM
Is it really a compliment if I say you've mastered the art of sarcasm?
 
I'll take what I can get
 
Alright then. Andras, you've mastered the art of sarcasm. Congratulations.
 
Tkinter is a decent GUI, although documentation is lacking
 
look at Kevin probing the sarcasm detectors
 
10:40 AM
It can't be sarcasm, he's said it too often. Unless... it's a long con?
 
Hi i need help in to find regular which could find comma separated values [i,VCharg_Act1,fixdt(1,32,16),(0,1,2)]
 
result = i ,VCharg_Act1,fixdt(1,32,16),(0,1,2)
 
that might get a bit messy since you probably want commas inside parentheses to stay intact
 
yes
 
10:42 AM
@Lalitkumar that second line is not valid Python (unless all those names are defined)
I assume you want to end up with 4 strings containing the same thing
 
I'm being sincere, for certain definitions of "decent" and "lacking"
 
yep i know ,just represented what I intended to have as a result
 
@Kevin for what it's worth I have no horse in the GUI race, I just found the timing of your remark amusing
 
yes u r right
 
@Lalitkumar OK, just trying to make sure we don't misunderstand each other. You could say you want the same as result = 'i VCharg_Act1 fixdt(1,32,16) (0,1,2)'.split() and we'll be on the same page
 
10:43 AM
If you're trawling github for GUIs and are considering abandonware with 120 issues, you should carefully consider the available alternatives. Particularly first-party modules that have a million questions on SO for every conceivable newbie problem
 
i want 4 strings from this[i,VCharg_Act1,fixdt(1,32,16),(0,1,2)]
 
There are no horses in the GUI race. There are a few zebras, a couple donkeys, even a giraffe and 2 hippos. But no horse in sight. Humanity has not yet managed to produce an actual horse.
 
@Lalitkumar yes, yes, I was just pointing out that showing the exact strings is the highest signal-to-noise ratio. Just for future reference.
we now know what you need
 
haha ok
 
@Lalitkumar I'm not sure this is easy to tackle with regex. Are your strings long? Parsing with something else might work better.
If I knew how to wrangle the output of ast.parse I could do something with that, I hit a wall at an ast.List
 
10:47 AM
hah... I was just playing with that as well :p
 
There's no universally followed formal specification for CSV (cf en.wikipedia.org/wiki/Comma-separated_values#Standardization) so I'd advise figuring out exactly what variant of CSV you want to match, before touching anything regexy
 
string will remain same , only thing going to change is last value ....like (0,1,2) change to (1,2) or (1)
okk
 
Something like (?=[\w(])\w*(?:\(.*?\))? might work well enough:
>>> re.findall(r'(?=[\w(])\w*(?:\(.*?\))?', 'i,VCharg_Act1,fixdt(1,32,16),(0,1,2)')
['i', 'VCharg_Act1', 'fixdt(1,32,16)', '(0,1,2)']
 
@Lalitkumar Have you looked at the csv module? I often find it useful for reading csv data. docs.python.org/3/library/csv.html
 
10:51 AM
mine eyes! :p
 
i am aware of csv module, file contains other information too
 
@Kevin I haven't found a way yet to protect the inside commas when the string fields aren't explicitly quoted
 
@Kevin not enough reliable quoting for that to work
 
If the string is short and always the same format I'd be very tempted to write a manual parser using a stack, counting parentheses. Perhaps I had one too many AoC challenges :P
 
Oh, I see. if you only want to split on commas that are not inside any pair of matched parens, then the problem is simply impossible to solve with regex.
 
10:54 AM
@Kevin well Aran-Fey showed a regex given certain assumptions :P
but I agree the problem is not very regular
 
Here I was, thinking how rare that we had a question about parsing a non-recursive format like CSV
@AndrasDeak--СлаваУкраїні True. And it's a fine approach if it meets the asker's needs. I'm just grumpy that I've been deprived of a good theoretical puzzle.
 
well it wouldn't be the first time that you could generalise a practical problem to nerd snipe yourself
assuming there's an interesting generalisation
 
Yeah. Not feeling it today though. Let me check my decision flowchart... Local humidity has exactly two prime factors, and Jupiter is in the ninth house... Nope, no generalization for me for at least the next 17 minutes
 
11:36 AM
[ast.unparse(node) for node in ast.walk(ast.parse(text)) if isinstance(node, ((ast.Call, ast.Tuple, ast.Name)))]
# ['i', 'VCharg_Act1', 'fixdt(1, 32, 16)', '(0, 1, 2)', 'fixdt']
@Andras ^^^ meh... I give up... not going to faff around with a NodeVisitor...
 
Oh! For a long I time I've been wishing for an ast unparse method. I had no idea it made it into the stdlibs.
> Warning: Trying to unparse a highly complex expression would result with RecursionError.
Naturally the first thing I want to do with my new toy, is try to break it
 
Uh oh, my potato powered laptop can't install Python 3.9. Is this the end of our journey?
 
You mean you're going back to 2.7? Nice knowing you.
 
wonder if it'd be cheating to do result = [s.replace(' ', '') for s in the_above[:-1]] :)
 
11:47 AM
I'll allow it.
 
11:59 AM
Normal programmers: "I like to split up my source file into multiple modules once it's around 50 lines or so." CPython devs: "hold my beer." github.com/python/cpython/blob/…
 
Yeah. (for certain definitions of "normal")
 
TIL normal programmers develop on a tamagotchi screen ;)
 
I think my assessment is skewed because I have encountered one zillion beginner programmers and about 20 experts
Statistics show that 99.99% of developers can only write two functions before they have to take a tylenol and lie down
Size aside, _Unparser looks surprisingly clean to me... I expected at least one gnarly corner of the language to require a logic block with 10+ layers of indent. But no.
 
@AndrasDeak--СлаваУкраїні wow... that's a blast from the past :)
 
12:21 PM
Hi, I was wondering if it's possible to pass a tkinter widget to a function? for example i have a tree view called data_tv and i want to pass it to this function:

def delete_selected():
selection = data_tv.selection()
for record in selection:
data_tv.delete(record)

I have tried

def delete_selected(tree):
selection = tree.selection()
for record in selection:
tree.delete(record)
 
@Harris92 please see our code formatting guide to chat and practice in the sandbox if necessary
To answer your question, why would you not be able to pass it to the function? When you tried that, what happened?
 
tkinter widgets can indeed be passed to a function. All widgets are objects, and all objects may be passed to functions.
(except for extraordinarily weird objects that do silly things with weakrefs or something)
 
The only issue I can see a priori is if you then call your function as delete_selected() rather than actually passing it the widget during the call.
 
I love a good tkinter question, but I'll need an MCVE before I can give more specific advice
 
and I half suspect delete_selected() to actually be a method
 
12:27 PM
The M is negotiable though, I don't need Minimal as long as the Example is Complete and Verifiable
 
Kevin is content with a verifinable example. One to which you can say "mmmh yes, very fine".
 
veri veri fine
A while back I described an alternate approach to problem solving, where the asker may only provide test cases, and the answerer can only provide code that passes those tests. I have an idea for a new alternative where questions are allowed, but they deplete your limited MP bar.
 
text = '[i,VCharg_Act1,fixdt(1,32,16),(0,1,2)]'
[
    ast.unparse(node).replace(' ', '') for node in ast.walk(ast.parse(text))
    if isinstance(node, (ast.Call, ast.Tuple)) or
    isinstance(node, ast.Name) # and something here???
]
okay - it's gotten under my skin now grrrrr
 
Something like... At the beginning of the challenge, you have 100 mp, and your mp rate is 0/sec. Whenever you are asked a question, your mp rate decreases by 1/sec. Whenever you answer a question, it increases by 1/sec.
For example, if Harris92 had agreed to this variant, he would currently have an mp rate of -2/sec, since Andras asked him two questions and he hasn't gotten a reply. Maybe -3/sec if you count my "I need an MCVE" as a question.
Sometime in the first minute of this, his MP would have reached zero, and a trap door would have dropped him into a vat of Nickelodeon Slime. Nontoxic, but yucky.
Fig A. The typical outcome of this game
 
12:56 PM
Sorry I had to copy cover my code from another laptop and rip out the parts that are needed then make sure I was formatting it correctly for the chat
from tkinter import *
from tkinter import ttk

ws = Tk()
ws.geometry('400x300')

def delete_selected():
    selection = tv.selection()
    for record in selection:
        tv.delete(record)

tv = ttk.Treeview(ws)
tv['columns']=('Rank', 'Name')
tv.column('#0', width=0, stretch=NO)
tv.column('Rank', anchor=CENTER, width=80)
tv.column('Name', anchor=CENTER, width=80)
tv.heading('#0', text='', anchor=CENTER)
tv.heading('Rank', text='Id', anchor=CENTER)
tv.heading('Name', text='rank', anchor=CENTER)
 
Sensible. We'll need to create some kind of Freeze spell where the player can halt their MP loss while they draft up replies
Anyway. The problem is that the command argument of Button, expects a function that takes zero arguments. Perhaps you could wrap your one-argument function in a zero-argument lambda.
Oops, phone meeting. I will elaborate later.
 
This is a general problem of callbacks
The button doesn't know what to pass when it calls the callback function
 
@AndrasDeak--СлаваУкраїні Nope, because * doesn't auto-import submodules
 
1:14 PM
@Harris92 long story short:
delete_btn = ttk.Button(ws, text = "Deleted Selected", command = lambda: delete_selected(tv))
delete_btn.place(relx=0.5, rely=0.94)
Also your final line should be ws.mainloop(), since root is not defined. But I'm guessing that's not a problem in your real code.
 
@Aran-Fey huh, my bad then, sorry
And thanks
 
Semi-relatedly, you should never do delete_btn = ttk.Button(whatever).place(whatever). That won't assign the Button widget to the delete_btn variable; it will assign the return value of the place method. Which happens to be None.
Same goes for all widgets in both tk and ttk. And for all geometry methods, including place and grid and pack
 
Joe
Is there a code example for a human activity recognition model using LSTM and TimeSeriesGenerator ?
 
Yes I've noticed that it returns none. I've separated them out in my actual code. Thank you all for your help.
 
1:33 PM
import ast
def deeply_nested_list(depth):
    node = ast.List(elts=[])
    for _ in range(depth):
        node = ast.List(elts=[node])
    return ast.Module(body=[ast.Expr(value=node)], type_ignores=[])
print(ast.unparse(deeply_nested_list(245))) #[[[[[...etc...]]]]]
print(ast.unparse(deeply_nested_list(245))) #RecursionError
New toy: broken
Interestingly, it seems like you can't break ast.unparse using a node you created using parse, because anything that would crash unparse will crash parse first. The maximum recursion depth for parse seems to be around 200. I wonder if they intentionally bumped the limit up a bit for unparse.
Oops, transcription error. That final 245 should be 246.
 
Wes
1:47 PM
this is evaluated at definition time, is there a way to evaluate it at instantiation time?

@dataclass(frozen=True)
class XX:
    # ...
    creation_date: float | None = time.time()

i am guessing i need a full blown __init__ right?
 
creation_date: Optional[float] = dataclasses.field(default_factory=time.time)
 
Wes
neat. what's the difference with Optional[float] tho?
 
just preference
 
Wes
okay
thanks
 
2:01 PM
That reminds me, I have a design quandary with my DB... My grommets table has two columns named num_splines and price, both integers. I wrote a nice function to print the contents of the table. But I'd like price to be displayed with a dollar sign.
It would be easy enough to put if col_name == 'price': print("$" + value) in my print_table function. But there's no guarantee that I won't define a second table later that also has a price column, and I won't want to display it with a dollar sign.
I could call print_table with some kind of style_preferences object, which indicates which columns should have a dollar sign. Then I can specify dollarful formatting for grommets.price, and non-dollarful for other_table.price. I'm not really sure who "owns" that data though.
 
Hard to give advice here, because it depends on the scale of the program, the database, and a dozen other things. It sounds a lot like you're overthinking (and overengineering) it though. I'd say just go with the if col_name == 'price' for now; that's easy to change later if necessary
 
Rename to price_dollars and parse the name for unit suffixes ;)
 
I see a fair share of hungarian notation in the legacy code, so the team probably would be fine with me encoding type information in the name.
 
I feel culturally compelled to support that
 
But yeah, I'm overengineering. Probably because I know there's an assignment for me in the backlog to create a second table-rendering function, which produces HTML instead of plaintext.
So I may as well start thinking abstractful thoughts, since I'll be doing it sooner or later anyway
Writing if col_name == 'price' in one function is tolerable, but copy-pasting that logic into print_html_table will deal 2d8 psychic damage to me
 
2:17 PM
Do people still play minesweeper? A company asked me to implement it during a technical interview and had to explain it to me first, because I didn't know the rules
 
I last played a game of minesweeper about a month ago. Probably my only one this year.
 
@vaultah What :D How old are you?
 
@Hakaishin 25
Not that young
 
Isn't that way too much code for an inverview?!
 
Old enough to have played minesweeper then
 
2:21 PM
@Aran-Fey They only asked to generate the board randomly, return the number of mines in neighbouring cells, and write a function that opens the cell, so just about 50 lines of code
 
I think I could make an ugly command-line minesweeper in about an hour. But I have a special interest in both minesweeper and manipulating rectangles of data, so perhaps I'm not a representative data point.
If clicking on a cell only opens that cell exactly, the problem is easier. Compared to actual Windows Minesweeper, where clicking a cell will cause a chain reaction of cells opening, as long as there are zero mines nearby
 
They asked for the latter
 
You can do chain reactions with a flood fill algorithm. Not too painful, but fencepost errors are aplenty, which may eat up your precious time
 
@vaultah I see. In that case it actually sounds like a good interview problem
 
2:25 PM
Just do a brute force, on any hardware it doesn't matter to be efficient nowaydays :)
 
Hard mode: do a cool animation where the chain reaction uncovers cells in an expanding blastwave centered on the clicked cell
Full credit if you do flood fill with BFS, and calculate each cell's "when to flip over" time based on which generation of the BFS it was in. Partial credit if you base it on euclidean distance to the clicked cell.
1 pity point if you play cool_explosion.mp4 on top of the playfield, and flip the cells simultaneously while they're obscured
 
Successfully playing a video should earn you all the points IMO
 
I'll compromise. Full points, but only if you're a visual design student taking my CS course as an elective.
CS majors are permitted to change their major halfway through the semester in order to claim the points. Even if they change it back the next day. That demonstrates a good grasp of manipulating logical systems.
 
2:43 PM
One of my first 'real' Python program was a pygame minesweeper, I was quite proud of it even if I did not have any clue how to make the said chain reaction
 
special effects that change state over a length of time, is a concept that most game tutorials do not reach. And consequently, there also aren't a million StackOverflow questions about it from askers having trouble with the tutorial they're using.
One of those "easy to describe, hard to code" features
 
3:08 PM
Is Community Bot removing old post a common thing, or was it an error?
I'd say its weird because I also lost the correct answer rep along with it
 
Link?
 
It routinely deletes low-score low-traffic questions, but I'm a bit surprised it deletes questions that have been answered
 
This wasn't an error
 
Would've been considered okay, but it also took away the 15 rep, I see
@vaultah Is it because the user itself was removed?
 
@vaultah Ah wow, there it is
I did have a 0 but it was marked as the correct answer I assume.
Its becoming usual, this points reducing on old posts :P
 
@DelriusEuphoria Yeah, that doesn't count. You also probably wouldn't lose reputation gained from upvotes
 
Have to aim for the upvotes next time :P
Thanks mate!
 
Ah there're additional conditions: "First, reputation earned for posts with a score of 3 or higher, and where the post has been visible on the site for at least 60 days, is retained". I forgot about the "3 <=" rule
 
3 it is, then :D
 
3:31 PM
umm... I'm not qualified in the TK area but it seems to be a valid q/a pair?
okay... so since it seems the OP self-deleted their account and it seems reasonable enough... I've undeleted the question and cleared up on the comments on the Q @DelriusEuphoria
(so your 15 should come back after caching or something :p)
 
Could benefit from some editing, to improve discoverability
 
I'll leave that to someone else...
 
@JonClements oh wow, thanks a lot
@vaultah yep, very less text and more code
 
@JonClements I was commenting on the "valid q/a pair" part :P
 
@vaultah fair enough... I'm just a puppy ya know!? :p
 
4:00 PM
I am trying to extract feature maps from the source code of segmentation models pytorch from here github.com/qubvel/segmentation_models.pytorch/blob/master/… , if anyone has any clue about that, let me know.
 
@DelriusEuphoria BTW, it's nice to get the green check mark, and it does tend to draw the attention of future readers, but that doesn't imply that the answer is correct. ;)
Bear in mind that the OP is generally not an expert in the topic they're asking about, so they may not be a good judge of which answer is best. Of course, that's not very relevant when there's only one answer. :) But it's not unusual for the accepted answer to be sub-optimal, or just plain wrong. Which is why the accepted answer is no longer pinned to the top.
 
@PM2Ring Ah the answer itself is almost 2 years old so I would say it might not be the best. But it works for sure, atleast :P
 
if(ans == works):
    accept()
 
@DelriusEuphoria It looks fine to me, apart from having two calls to entry.grid(). You should fix that.
 
Since we're on this topic, I think you shouldn't put that much code into a try block. try: float(...) except ValueError: ... would be better IMO
 
4:12 PM
It baffles me when people post answers with code that doesn't work. I hate posting code that I haven't tested. It's just too easy to make a typo, or mess something up, even when the code's simple & straightforward.
Good point, vaultah.
@Kevin A fun problem with rectangular grids is to randomly place a bunch of items without them being clustered too much. I guess it doesn't matter much for Minesweeper, since the mine density is pretty low, and if you don't want clusters your placement loop can just avoid placing a mine adjacent to an existing one.
But if you need a lot of randomly placed items, that technique's not very efficient. Recently, I've been playing with blue noise, mostly in the context of dithering algorithms. There's a nice article on it here: momentsingraphics.de/BlueNoise.html with links to Python code on GitHub.
Here's a little demo of a tileable blue noise 16×16 dither matrix, created using Christoph's code.
 
4:36 PM
Thanks, this is interesting
 
4:46 PM
@PM2Ring Haha, done
and fixed the try block too
 
I have a question about game maps. I want to design a grid for a game where the player can walk around in. I'm not interested in visuals outside of using Kivy to create a window that displays all of the things that I'd like to put inside of that grid. Anyone know how I should go about this?
 
No worries, @vaultah. I wish I'd learned about blue noise earlier. I'd seen it mentioned from time to time, but I didn't delve into it because the articles talking about it were very technical.
 
For example, I enter into a new grid. The character examines the grid. Then a pop up window opens up explaining all of the things inside of the grid.
 
@DelriusEuphoria Excellent.
 
Very melon :p
 
4:54 PM
@JakeSteffan I don't know much about Kivy, but it looks like kivy.org/doc/stable/tutorials/pong.html talks about setting up basic graphics
If you want to get low-level and basically control every individual pixel, then "blit" is a useful term to research. Looks like Kivy lets you blit if you use kivy.org/doc/stable/api-kivy.graphics.texture.html
 
Thanks Kevin. I'm 6 weeks into learning how to code but I've put into a lot of hours, many days 10+ hours a day. Just when I feel like I'm about to get somewhere, there's new stuff to learn lol.
How much longer do you guys think it will take to create a game using Kivy? I've been studying OOP and understand Inheritance and Polymorphism. I thought I should at this point be able to start coding creatively but it's not really going anywhere yet.
 
5:17 PM
Once you know how to draw things on the screen and respond to user input, you'll have all the truly essential building blocks you need. Best case, you might be mere hours away from the creative coding you desire.
 
Really?
I'm excited, but I feel like a fraud. I imagined that since I learned all of these concepts so quickly that I'd be able to solve problems with ease, but my problem solving skills are embarressing.
 
@JakeSteffan There are some major differences between coding for a simple text terminal and interactive GUI coding. It can take a while to wrap your head around those differences. And there's a learning curve for any GUI library. It takes some time to learn all the bits & pieces, and how they work together. It shouldn't take too long to learn how to do some basic stuff, but it can take quite a while to master all the fiddly little details.
 
@JakeSteffan Yeah. Of course, it varies from person to person. Especially for game development.
 
Thanks for the comment, the problem is I might be rushing too quickly, since I've been trying to learn Kivy while I'm still getting the hang of implementing OOP best practices and learning the nuances of arranging everything. There's so many avenues it seems I need to go deeper into. Like learning the time module in order to implement day and night cycles. Then I have to learn how to create a map. Then have my character interact with it all.
 
@JakeSteffan yes, you might, see earlier discussion about structured learning
 
5:24 PM
From your recent questions here, I advise you to spend a bit more time solidifying your core Python skills in the terminal before getting into GUI stuff. Otherwise, you may get overwhelmed, or experience burnout. OTOH, there's no harm in messing around with small demo programs from a good GUI tutorial, and seeing what they do.
 
That being said, practice makes perfect
 
Thanks I think I needed to hear that. I'm just going to start working on basic stuff in a terminal for now.
 
Learning in an organised way avoids many pitfalls for you and helps you not teach yourself terrible practices by accident
 
I feel like I've been learning too much and not doing enough practicing lol.
 
A good tutorial makes you practice along the way
 
5:26 PM
I'm answering all the quizzes and exercises correctly but when it comes to staring at my IDE it's like...idk what to do.
For example let's just say this. I want to have a bunch of different trees inside different map tiles (when I create a map), you saw the tree class I made yesterday which wasn't that hard to make, but then actually implementing all of that into tile maps, I'm clueless.
 
I learned a lot about programming back in the day, by trying and failing to create a variety of overly ambitious games. I don't think it's necessarily bad to try to learn a lot of things at once. As long as you're emotionally prepared to run into a lot of dead ends, and trim back a lot of promised features, and maybe even give up with nothing to show for it except one or two hard-won lessons
 
Man, I foresee this happening to me lol.
I pride myself on learning things blazing fast, but this is a different animal. It's non-stop learning new things every day.
 
Coding (non-trivial) games is a popular beginner mistake. If your goal is only to make it work somehow, then ok, you'll probably manage that. But coding a game well? Even I can't do that yet.
 
How long have to been coding for Aran?
you*
 
Around 12+ years?
 
5:32 PM
ego has left the chat
LOL
 
A fun beginner level GUI game is Snake. A basic Snake game doesn't need too many GUI features, but you can add more stuff once the basic game works properly.
 
I'll try that right now and give it a shot. Thanks guys.
 
My point is, if you start worrying about architecture too much you'll just waste your time. That's something you can spend an infinite amount of time on, without having much to show for it. Coding a game can be a worthwhile activity, but you have to make sure to keep going and not get stuck. Doesn't matter if the code is a mess. The primary goal is to finish the game, not to write flawless code
Or to put it differently, it's too early to develop grey hair worrying about how to avoid mistakes. You're at the point in the learning process where you should just go and make the mistakes
 
Ahhhhh, okay. That makes sense.
Actually forget the Snake game, I'm just gonna botch the game I'm currently working on lol.
 
Mistakes are an excellent educational experience. Especially in programming, where the majority of mistakes can be reversed with ctrl-Z.
 
5:42 PM
Hey, that's good to know. I've used the undo button plenty already. Aran what do you think about this:
 
Compare to, say, carpentry. Can't un-saw a plank once you realize it was supposed to be 12 inches long rather than 11. And you can't undo putting your thumb in the path of the band saw.
 
import random


### TREE CLASS ###

class Tree:
    def __init__(self):
        self.species = self.tree_species()
        self.age = self.tree_age()
        self.quality = self.tree_quality()
        self.wetness = self.tree_wetness()

### TREE CLASS FUNCTIONS ###

    def tree_species(self):
        species = ["Birch", "Oak", "Maple", "Serviceberry", "Basswood", "Cedar", "Pine", "Apple", "Hickory", "Walnut", "Osage"]
        return random.choices(species, weights=(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10), k=1)
Yeah Kevin, that's true.
 
It's an interesting topic to me because a lot of people seem to have the problem that they can't find a good balance between learning and practicing. There's people who get stuck in "tutorial hell" because they don't practice enough, and there's people like me who do nothing but practice (i.e. write code) and consequently write terrible code for the first 10 years because they didn't spend enough time learning
 
So here's one thing, is it really wise to use these functions in the init method like this? It seems to be a great workaround since the arguments are random lists. Also and this is the biggest question, would it be better to add each tree species as a seperate subclass of Tree?
Yeah I've heard of tutorial hell lmao.
I have honestly more of a tutorial hell personality, because I'm a perfectionist (although I'm getting better at not caring in my 30s)
 
It's a bit strange that every tree has randomly selected attributes. Are you sure you'll never want to create a tree with specific attribute values? Generally, the constructor should allow the user to set specific values
 
5:50 PM
Yeah so I'll give you my line of thinking on this, but be warned this explanation of why I want it this way stems from me just being a psycho lol.
 
If you want an easy way to create random trees, I'd recommend doing that as a factory method:
class Tree:
    def __init__(self, species, age, quality, wetness):
        self.species = species
        self.age = age
        self.quality = quality
        self.wetness = wetness

    @classmethod
    def random(cls):
        return cls(
            random_species(),
            random_age(),
            random_quality(),
            random_wetness(),
        )

tree = Tree.random()
 
So I'm trying to create this game world where the character can walk into it, but for each game the trees will be different, so that it's a dynamic world that is repeatable.
Oh wow.
You just blew my mind.
Oh sorry, that isn't repeatable.
I'm trying to wrap my head around what you wrote.
 
Consider this scenario: you are randomly generating a dynamic world. Your world generator decides that the starting area should be a desert. You want to populate it with random plants. It can have cacti, and desert flowers, and tumbleweeds; but it can't have weeping willows or giant redwoods.
 
Very true, then I should make a biome class where I can make methods that restrict certain resources within those biomes?
 
Yep, that sounds good
 
5:55 PM
Perhaps. Then the logic for generating random trees might go in those biome classes, rather than in the Tree class.
 
@JakeSteffan what do you mean by "repeatable"?
I'm not trying to pile on, but that remark stood out to me
 
It might suit me better to just make one biome for now, not to over extend myself. So that I won't have cactus or animals like polar bears. I'd preferably like an eastern wilderness (US) type setting.
Andras what I mean is having an environment for the user that isn't repeatable as far as playability.
 
wait a few months and you need not worry about polar bears
 
@JakeSteffan About creating Tree subclasses: Probably no. Only if the subclasses need to override some Tree methods or add new ones
 
So like if their character dies and they make a new game, the tree in x, y coordinate won't be the same quality, species, etc.
 
5:58 PM
@JakeSteffan that's a matter of being able to store and reload the state of the world
that is a problem that can be solved independently from the way you generate the world
 
Well the thing is Aran each tree species will give out unique resources, so for say Maple, they will give out sap and acorns, whereas Beech will give beech nuts, and Birch gives unique bark qualities.
 
I am reminded of how Minecraft generates random worlds, but you can also supply a starting seed value, and it will be guaranteed to be the same world as any other world made using that seed.
 
00:00 - 18:0018:00 - 00:00

« first day (4211 days earlier)      last day (738 days later) »