« first day (4210 days earlier)      last day (730 days later) » 

12:00 AM
That's modern Python for ya, you can never be too sure
 
Wes
lol
 
 
4 hours later…
4:13 AM
stackoverflow.com/questions/72003195/… Does anybody know how to fix this problem ?
 
 
2 hours later…
6:16 AM
@Wes Just do if foo is False: continue. A ternary would require an else anyway.
 
Wes
6:30 AM
doesn't one get murdered if they put two statements on the same line? :P
 
Not in civilised locations.
 
Wes
there should be more python jokes tho
 
Wes
7:31 AM
i have found a solution to the import problem medium.com/@hamana.hadrien/…
also i am glad i am not the only thinking it's insane
> Remember when I said “once a module has been fully loaded”? I lied.
 
Not to beat a dead zombie horse, but obligatory frame challenge: Are you sure the issue isn't having circular dependencies in the first place?
 
Wes
i improved the modules' hierarchy a bit and it helped but i couldn't do much with type hints
 
That's actually the thing I'm wondering about. In my case things that depend so strongly on each other usually either belong even closer together or further apart.
"These two things don't work without each other" is my criteria for putting things in the same file.
 
7:46 AM
We already solved Wes' import problem. About twice.
 
Twice resurrected dead zombie horse?
 
But I'm glad Wes finally found a solution
 
Wes
@AndrasDeak--СлаваУкраїні success!!!!!1
 
8:05 AM
We did everything we could. Short of having you send us your code and fixing it for you.
 
Wes
it's not your fault folks i know you did your best
i just refuse to put conditionals around imports. i'd rather scratch python and redo the whole thing in another language tbh
it's nuts
 
8:27 AM
my solution is to not use a language feature that was half-thought out and then hamfisted in
or program in a language that supports the thing as a first-class citizen
 
8:55 AM
wow chmod -x file.sh doesn't do anything, it's a +x. But that's so easy to miss :D
 
@Hakaishin well it removes x
 
makes sense :D It's usually most cli have just - and a letter and don't interpret the - literal
 
I usually use it as chmod a+x file.sh which would also make chmod a-x file.sh obvious
 
Imagine a programming language where functions only take positional arguments and the only data type is string. Imagine further that there are various flavors of this programming language. And finally, imagine that there are people who voluntarily program in this language...
 
Using assembler, are we?
 
9:14 AM
Over my zombie's dead body!
 
 
2 hours later…
11:04 AM
That moment when you prepare slides and don't have enough space left for xkcd 1987... goes get a wrecking ball
 
add another slide?
Or is this one of those "next slide please" setups with a fixed number of slides
 
One of those "get students interested in the topic by pretending I'm still hip and totally radical" situations.
 
so why not just flash it on a slide then go back to the previous one?
Side note: I'm not sure students know xkcd anymore. My freshman students definitely don't.
 
That's what I was about to say
 
It's a cruel world when you cannot carry an entire conversation just by subtle web comic references anymore.
 
11:13 AM
it's all tiktoks now
grampa
 
you should show dank python memes
 
@AndrasDeak--СлаваУкраїні angrily shakes walking stick Get off my lawn!
 
@Kevin In case you were wondering (From the other day mocking a function and dynamically returning the input as a its return value in pytest is very simple:
def return_input_values(*args, **kwargs):
    return args, kwargs

def test_fake_test(mocker):
    mocked_function = mocker.patch('path.to.function', side_effect=return_input_values)
    result = function_mocked()
^ terrible demo but Im sure you get the idea
 
@MisterMiyagi 😲 you want to say you are not :O
 
11:24 AM
well he's trying to be hip and totally radical with xkcd strips of all things
 
That kinda gave it away, didn't it?
At least Disco will never die...
 
12:02 PM
Irony of the day: Twitter's "Don't miss what's happening!" popup that quite literally makes me miss what's happening because it prevents me from reading further
 
that's less irony and more twitter being jerks on purpose
"see more posts"... well, show me
 
that's an Onion kind of site, right?
yes, yes it is
 
I'll put a disclaimer next time
 
Side note: Do students these days still know twitter?
 
12:10 PM
I believe so, but after learning that students don't even know what file paths are, nothing would surprise me anymore
 
Admittedly, when I don't program files are just the stuff I drag and drop around.
 
so hip and totally radical
if you drag and drop across directories it doesn't count
 
12:28 PM
I still remember floppy disks, so it doesn't count anyway. ;)
 
and you mean actually floppy ones
 
^^^ for the win :)
 
12:58 PM
@metatoaster Can't agree with "half-thought out," as I followed (some of) the tortuous discussions on python-dev. The issues were beaten to death. My own reservations are more to do with the fact that the language is being biased towards the needs of the industrial-scale software engineering organisations, with not enough developer time devoted to the needs of "incidental" users.
 
1:19 PM
the whole type annotation thing was what I was basically referring to
Python was not designed from the beginning to support what amounts to static typing from the very beginning, which inevitably result in more edge cases than necessary when developers try to make use of it
 
That's why I tell people, when you hit an edge case, that's the signal that you've type-annotated enough.
 
Meh, I feel typing works well enough in practice. For libraries, having a proper structure that is comfortable with typing is good anyway; for messy scripts, there's little benefit anyway.
 
yeah.. for one off/quick jobbies... I think that just meaningful enough names instead of agonising over exactly what should be done typing wise etc...
 
1:39 PM
@MisterMiyagi Perhaps. The django-annotations file gave me some good laughs. One of our teams tried it and gave up because ... too many edge cases!
And as to "hamfisted in" I couldn't agree more. It came in on promises of optionality, but it's only a matter of time before it intrudes everywhere. And I do see the uses of type annotations (I've used them to clarify my own code at times)
 
@holdenweb Heh, I can guess so. Annotating our old code... wasn't worth it. ^^
There's code I write with annotations in mind, and there's code I don't annotate.
 
After all the python ecosystem needs an incentive to move to Rust
 
At least it's not async/await. 😭
Anyone got a good example for try:/except: one can show to beginners without at least three hidden bad practices?
 
@MisterMiyagi missing file EAFP?
Not completely obvious, but idiomatic
 
try:
	1 / 0
except:
	print('it worked fine')
finally:
	print('yup... definitely fine')
@MisterMiyagi how's that? :p
decent indentation thrown in for for free :p
 
1:49 PM
there are a lot of statisticians in here, so I might be lucky. But kmeans does not balance the clusters right?
 
@Hakaishin I know of 0
Not sure what balancing means but I'm sure kmeans doesn't do it
 
balance meaning? equal number of points? then no.
 
@JonClements Good puppy! throws a treat
@AndrasDeak--СлаваУкраїні I hear students don't know what file paths are! This is tricky business...
Conjecture: k-means is the regex of clustering. Discuss.
 
@MisterMiyagi my Python just keeps getting better day by day!
 
oh don't get me started on the whole async stuff...
 
1:57 PM
@metatoaster don't you mean "oh get the async whole on stuff... don't me started"
4
oh darn it... I meant: "oh don't started the on me stuff... whole get async" - maybe next time... :p
 
In statistics, prettiness is negatively correlated with usefulness. kmeans is pretty, so you can't guarantee that it does anything at all. </half serious>
 
@Kevin very late to the party, but congrats!
 
Thanks :-) it's going pretty well so far.
 
what do you do now? (feel free to link me to your previous post because you've answered this too many times)
 
2:08 PM
howdy @inspectorG4dget
 
@JonClements heya puppy! How's life treatin ya? I've been running around like my head's on fire for a little too long
 
as always, the same old mate... what's going on with the the head on fire (dare I ask! :p)
 
I was just interrupted by a customer. I meant in that if I have 100 data points it doesn't make 50/50 clusters. I want unbalanced clusters and kmeans seems to be doing that, just wanted to a confirmation from you guys, thanks :)
 
had to update our process/procedure for internal stuff, while delivering to internal customers. Now that things are mostly updated, I'm writing out the new procedure docs so that people will hopefully follow them next time.

Meanwhile, I've had to learn machine vision from scratch for a new project that "needed this capability yesterday". Finally got a little breathing room today :P
 
what can I say... go go gadget! :p
 
2:17 PM
@inspectorG4dget Pretty similar to my previous job. Oracle, .NET, HTML, JS.
 
@Kevin sweet! minimized ramp-up time
@JonClements oh lol! how've you been, mate? I feel like I just got back from a vacation and I already need another one
 
like I said... always the same... still the cutest 3 legged, big blue eyed yellow cartoon puppy Python programmer as far as I know :p
 
Yeah. Most of my ramping up time has been spent on the database end. I'm glad to be getting hands-on experience there, because I almost never wrote raw SQL at my last place, and I felt like it was an imperfection on my professional record.
 
you're still the cutest 3 legged, big blue eyed yellow cartoon puppy Python programmer as far as I know, too! :P
 
One might argue that in a world of ORMs, a web developer that knows SQL should be as in-demand as a web developer that knows assembly. But alas, we do not live in that perfect society.
 
2:26 PM
The Common Question part of sopython seems to be down, is it the case for anyone else ?
 
I have come to accept that ORMs are magic and that they are far too underappreciated by mere mortals
@AlexandreMarcq I see a 502
 
I like ORMs when their magic is working in my favor. I've had a fair share of experiences where the project magically fails to build because the ORM is magically finding my local Oracle install and noticing that it doesn't perfectly match the table structures on the dev server.
You know what doesn't mysteriously fail to build when a runtime dependency is not available ten deployment steps before runtime? Raw SQL.
 
@AlexandreMarcq seems to be the case... maybe it's a glitch in the matrix or something
 
@Kevin fair, also sounds a bit xy problemy, then again all your problems sound that way :D XY is basically your area of expertise :D
 
True
 
3:14 PM
The good thing about learning SQL is that it lets you add two selling points to your resume: "I know SQL" and "I know about SQL injection"
 
3:30 PM
1. SO isn't really the right place to ask design questions
2. Please don't post fresh questions here as per our [rules](https://sopython.com/chatroom)
Multi-line formatting strikes again
 
4:13 PM
@Kevin youch... reckon someone's going to come up with something quite nasty using that one
maybe keep upping the gideon that has indestructibility when a creature or something...
or some weird stuff where you can double counters blah blah blah
 
Wait, you can equip planeswalkers? Is that a new mechanic?
 
4:54 PM
It's a new mechanic, yeah
Somewhat reminiscent of Darksteel Garrison from Future Sight. It's the only "Fortification" ever printed. Basically an equipment for lands. It's interesting that they didn't opt to make a new equipment-like type here for planeswalkers.
I guess they decided that the card is already complicated enough, without creating rules for an all new subtype. Historically it has been a rules minefield to add and remove types from a permanent. The infamous "Opalescence + Humility" being an example of such.
Considered by some [who?] to be the most complicated rules problem in the game
Fortunately most of the rulings for "what happens when a planeswalker is a creature?" got hammered out shortly after the type was first introduced. It's always been possible to make them into creatures, even the non-Gideon ones, thanks to March of the Machines + Mycosynth Lattice.
 
cabbage
I live in the land of ORMs and will never go back to using raw SQL in production.
on the other hand, I use SQL for troubleshooting and poking at the production database when needed.
probably needlessly since I can just write ORM code in a console, too...
 
There was a brief period where "you can only activate one loyalty ability per permanent per turn" applied only to cards with the Planeswalker type, so if you managed to get a planeswalker ability onto a nonplaneswalker creature (for example Experiment Kraj), then you could activate it an unlimited number of times.
Ok, I'm done talking about MTG. Return to your business.
@Code-Apprentice Same. Since it's production, I press each key very gently.
 
5:10 PM
@Kevin I wear felt gloves when working with production
 
Gotta make sure I don't sneeze and accidentally type drop table users; commit;
yes_I_am_sure; email_transcript_to_ceo;
 
you don't regularly drop the users table? How else do you ban the unpleasant ones?
 
I had to resort to raw SQL more than I would like to, when the query generated by ORM was too resource-heavy or when the query couldn't have been adequately expressed in ORM
 
I gradually move system requirements backwards until they can only visit our site in Netscape Navigator 1
 
yah, ORMs are sometimes limited from more powerful features.
although, I recently learned about windowing functions in SQL and Django's support for them.
I still didn't entirely wrap my head around them, though.
 
5:14 PM
I suspect that ORMs can do anything a direct query can do, but it becomes very hard to determine how to do it
 
Django still doesn't support CTEs and probably never will, which is sad, but understandable
And I had to write one query involving window functions in raw SQL because of some weird Django bug that should be resolved in Django 3+
 
5:34 PM
Man Breadwinners is awful
 
 
2 hours later…
7:32 PM
Browsing through the Oracle documentation, I find a page whose first section header reads, Footnote ' + footnum + '. Then the first paragraph starts with '); msg.document.write(footnote); msg.document.write('. Yes, I entrust my data with these people.
 
Folks, python % behaves differently compared to c++, c# and typescript. Is there any better way to make python % behaves like those three languages? I made the following but I think there should be better approach.
def mod(a, b):
    if(a < 0):
        return - mod(-a, b)
    if(b < 0):
        return mod(a, -b)
    return a - floor(a / b) * b


for i in [mod(5, 3), mod(5, -3), mod(-5, 3), mod(-5, -3)]:
    print(i)
 
I don't see a single percent sign in there
 
Yes. Because I think python cannot overload the existing operator.
SO I made a function.
for i in [5%3,5%-3,-5%3,-5%-3]:
    print(i)
produces different result compared to TS for example:
[5 % 3, 5 % -3, -5 % 3, -5 % -3].forEach(i => console.log(i));
 
make sure that -5 % 3 is not -(5 % 3) in your favourite language
 
7:42 PM
>>> (-5) % 3, -(5 % 3)
(1, -2)
 
IIRC You can't change how % works on integers, but I believe you can define its behavior on custom types. Probably not useful in this context, granted.
 
>>> (-5) % (-3), -(5 % -3)
(-2, 1)
OK, this doesn't explain the discrepancy
 
the 3 other languages mentioned above produce [2,2,-2,-2] for [5 % 3, 5 % -3, (-5) % 3, (-5) % -3]. But python produces [2,-1,1,-2].
 
Here's the definition of Python's modulus behavior on mixed-sign ints: "if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b)." from docs.python.org/3/library/functions.html#divmod
 
>>> for i, j in zip([5, 5, -5, -5], [3, -3, 3, -3]):
...     print(math.fmod(i, j))
...
2.0
2.0
-2.0
-2.0
this is shorter but iffy... if your integers can't fit into double precision exactly you'll get the wrong result
 
7:48 PM
OK. Thanks all. :-)
 
I like that a%b is positive whenever b is positive, since it makes it easy to create "wraparound indices" for lists. foobar[x%len(foobar)] is guaranteed to never go out of bounds, unless you're doing something really strange.
 
@Kevin wouldn't negative indices work just as well there?
 
I think so, but this way is 1% easier for me to comprehend
Ooh, data: en.wikipedia.org/wiki/Modulo_operation#In_programming_languages gives a big table of how modulus works in many languages.
C++: truncated. C#: truncated. typescript (and javascript): truncated. Python: floored. Well there you go.
 
There should be an ISO standard. :-)
 
I wonder if there's a simpler way to reconstruct the truncated version
 
7:59 PM
97 counts of Truncated, 58 counts of Floored. I expected floored to be a smaller minority, for some reason.
 
you know you are on treacherous ground when JS is the one following conventions
>>> def mod_floor(i, j):
...     return i - (i // j) * j

>>> for i, j in zip([5, 5, -5, -5], [3, -3, 3, -3]):
...     print(mod_floor(i, j))
2
-1
1
-2
is that it?
ah, no, this is Python's original :D
 
Knuth likes floored modulus, so therefore it is superior by reason of prestige
 
edited with a rename to make it true
I was going for "floored" but I forgot that this was the Python case
 
Understandable. This topic is a fencepost minefield
 
>>> def mod_trunc(i, j):
...     sign = (i * j) // abs(i * j)
...     return i - sign * (abs(i) // abs(j)) * j
...
... for i, j in zip([5, 5, -5, -5], [3, -3, 3, -3]):
...     print(mod_trunc(i, j))
...
2
2
-2
-2
How's this one then?
Is there no built-in/stdlib function for sign?
 
8:10 PM
I was just thinking that :-)
I feel like I've used such a thing before, but it might have been for some other type. float or fraction or something.
def trunc_mod(a,b):
    return abs(a%b) * a // abs(a)
for x in (-5, 5):
    for y in (-3, 3):
        print(f"trunc_mod({x}, {y}) = {trunc_mod(x,y)}")
#trunc_mod(-5, -3) = -2
#trunc_mod(-5, 3) = -1
#trunc_mod(5, -3) = 1
#trunc_mod(5, 3) = 2
No idea if this is the desired behavior
 
nope, this is floored at best
the desired one only has +-2
this looks like Python's mod except the sign is copied from the first parameter
 
Hmm, how about def trunc_mod(a,b): return abs(a)%abs(b) * a // abs(a)
 
yeah, that's exactly what you're doing
 
An error occurred somewhere in the brain-finger-keyboard system
 
yup, that gives the same result as my previous snippet
as long as the +-5 % +-3 case is representative, it's correct
 
8:23 PM
docs.python.org/3/library/math.html#math.fmod gives C-like modulus (i.e. truncated), but it bothers me that it always returns a float
 
>>> i, j = 10**50, 3**90
>>> math.fmod(i, j) == i % j
False
 
This is beyond science
You can use math.copysign to do something like the sign() function we wish existed
For example def trunc_mod(a,b): return math.copysign(abs(a)%abs(b), a). But alas, it too returns a float.
 
9:02 PM
@vaultah with Redshift (so, big queries that you probably don't face in web) I can have ~10 CTEs in a single query, trying to narrow down the scope. There's a lot of love for ORMs here but I'm glad you raised this limitation ;)
 
10:00 PM
Hello I'm new to Python, can someone help me out with a question.
 
@JakeSteffan welcome. Sure, just ask your question and if anyone can help, they'll reply.
 
10:32 PM
@AndrasDeak--СлаваУкраїні seems this is the case. Just skip adding credentials and you're all set. Welcome to the new life as "gitname". This looks like it can only be controlled on the repo level
 
surely onboarding or deployment or whatever procedures should inlude proper git setup...
 
I've created attributes on objects in the same class and used random.choices on them, but when I print them out I think they get attached to the same seed and it produces the same "random" values. How do I workaround this do you know?
 
^ especially since half of what you asked sounds confusing to me. "Get attached to the same seed"?
 
@AndrasDeak--СлаваУкраїні they're given a guide. If they choose to just press enter through the difficult questions like "User Name" and "Email" then there isn't much more to be done other than stand over their shoulder?
 
10:39 PM
random.choices(quality_list, weights=(10, 55, 25, 8, 2), k=1)
 
@roganjosh sounds like a management problem
 
One line of code is not an MRE
 
@JakeSteffan that's too minimal, and not reproducible
 
I have no idea what I'm doing, lol.
 
@JakeSteffan neither do we, so...
 
10:40 PM
Just demonstrate the problem with a code example.
 
Ok I'll try, so let's say I have a dog object, and he has a randomized quality of fur.
 
@JakeSteffan stop
No talk. Code.
 
Demonstrate, don't explain. Only explain if absolutely necessary
 
Okay I'll be right back to write it.
 
If you start talking we'll misunderstand each other. Code is exact.
@JakeSteffan thanks
@roganjosh I wonder if the server could be configured to deny pushes from the dummy credentials
I guess you could use a post-commit hook on the server and check (no idea how)
 
10:44 PM
I think they're about to upgrade to Enterprise so perhaps then. In the meantime, I might just run as a vigilante since I think I could name most people and just publicly post "you know you're not committing under a name, right?". I'll see how much I care
 
ah, no, pre-receive hook
> pre-receive

The first script to run when handling a push from a client is pre-receive. It takes a list of references that are being pushed from stdin; if it exits non-zero, none of them are accepted. You can use this hook to do things like make sure none of the updated references are non-fast-forwards, or to do access control for all the refs and files they’re modifying with the push.
 
"The hooks are all stored in the hooks subdirectory of the Git directory." this is the bit that worries me. ~700 repos :/ If people don't bother to set their credentials then it'll take some conscientious person to go through each repo and do it on their behalf. (Admittedly I haven't read the whole article yet)
 
@roganjosh make sure you distinguish client-side hooks from server-side ones
at least I'd expect that server-side hooks can't be meddled with by clients
 
Looks good, thanks. Onward I shall march
 
10:52 PM
class Dog:
    def __init__(self, fur_quality):
        self.fur_quality = fur_quality

    def display_fur_quality(self):
        print("Quality: " + str(self.fur_quality) + " out of [30]")

quality_fur_list = [random.randint(0, 5), random.randint(6, 20), random.randint(21, 25), random.randint(26, 28), random.randint(29, 30)]

spot = Dog(random.choices(quality_fur_list, weights=(10, 60, 20, 8, 2), k=1))
buddy = Dog(random.choices(quality_fur_list, weights=(10, 60, 20, 8, 2), k=1))
diogi = Dog(random.choices(quality_fur_list, weights=(10, 60, 20, 8, 2), k=1))
 
The title of that, though, is "Pre-receive hooks are scripts that run on the GitHub Enterprise Server appliance that you can use to implement quality checks." and I also mentioned that we were due to upgrade. I suspect that some of this arsenal isn't available yet (but, again, lots of reading for me). However, if it's tied to Enterprise, then I can try shape that
 
@JakeSteffan edit the message and click the "fixed font" button to the right of the edit box
for future reference here is out code formatting guide to chat because it's hard to get right
@roganjosh yes, sounds like github only offers this for Enterprise. If your git server is a github instance then you'll probably need that.
although the wording might be due to the link being enterprise-specific, I can try digging around
 
Thanks!
 
No need, you've given me enough insight, thanks :)
 
10:55 PM
It's barely my job, let alone yours. I'll do my best to get this hook implemented
 
also make sure it's the right hook (i.e. it has access to necessary information)
you'd have to figure out what to put in the hook, which would answer which hook you need anyway
 
@JakeSteffan Alright, so what's wrong with it?
Each dog has a different (randomly chosen) fur quality. Isn't that what you wanted?
 
So my question is every time I print these objects together the random.choices are often the same numbers. Tech with Tim said in a video that the seed of the choices is attached to the time so my guess is because I print them at the same time that's why they get stuck in the same seed.
 
@JakeSteffan seeding happens once unless you seed manually
Try changing quality_fur_list to range(5), and the weights to (20,)*5. Do you still see the same thing?
nevermind the first part, your intervals don't overlap
 
Yeah but since they both get printed at the same time when it gets run it outputs the same seed.
 
10:58 PM
Aha, I guess you fell victim to that misunderstanding. It doesn't matter when you print them. The value was already selected before that, when you called random.choices.
 
I tried doing a time.sleep in between each to see if it would change lol, it didn't work.
 
More importantly, forget everything about seeds and time. You're only confusing yourself with that
 
@JakeSteffan where does it print the "seed"?
 
@JakeSteffan wait, you said "often the same numbers". That's fine. Ask yourself what it means when one of 5 choices has 60% weight.
 
Yeah I know the weights are off, I just kinda threw it together.
 
11:00 PM
Are you aware that all 3 dogs draw values from the same quality_fur_list?
 
Yeah.
 
This list won't be filled with 5 new random numbers every time you call random.choices
 
Interesting.
Because it's drawing from the same list?
 
Because you picked 5 random numbers when you created the list. And then never again. The values in the list won't change willy-nilly
 
11:02 PM
Hmmmmm...
What should I do?
 
def fur_factory():
    return [random.randint(0, 5), random.randint(6, 20), random.randint(21, 25), random.randint(26, 28), random.randint(29, 30)]
 
Lol man, I knew I was supposed to make functions for all these things.
 
the functionness is less crucial than the creating a new list each time you want to generate new random values
if you put it in a function then each function call calls all those random.randints each time, generating new random integers
 
def random_fur_quality():
    quality_fur_list = [random.randint(0, 5), random.randint(6, 20), random.randint(21, 25), random.randint(26, 28), random.randint(29, 30)]
    return random.choices(quality_fur_list, weights=(10, 60, 20, 8, 2), k=1)

spot = Dog(random_fur_quality())
buddy = Dog(random_fur_quality())
diogi = Dog(random_fur_quality())
 
@Aran-Fey I never would've guessed that this was the crux of the issue
 
11:04 PM
In addition to that, and as a gross simplification, the only time you need to care about a "seed" to the Random Number Generator (RNG) is when you want to make things repeatable. You keep mentioning "seed" and, as a layman just wanting random numbers, that's really the only reason you'd ever care about the seed. And, in this case, you don't even need to care about that
 
Lol yeah.
 
As a final note, in your original snippet you can print(quality_fur_list) and observe that it's a regular list with regular ints inside.
 
Awesome, thanks for all this help. I'm still lost, but at least I'm one step closer to finding myself.
 
if you eventually locate any specific point of confusion you're welcome to ask
 
Okay I'll try to work on this and I'll come back, thanks again guys especially to Aran who figured it out. :)
 
11:06 PM
You're not the first person I've seen with this problem and you won't be the last...
 
Just for the seed. Exhibit A:
import random

for x in range(10):
    print(random.randint(0, 10))
Keep running that and you'll see different outputs each time
Exhibit B:
import random

random.seed(50)
for x in range(10):
    print(random.randint(0, 10))
 
(Pssst: You can just set the seed inside the loop)
 
Where is my footgun?
 
range()? :P
I meant seeding itself
I half expected the seed to be in the loop like Aran-Fey said, which would take only a very small mental leap to reach "let's seed randomly in each iteration to ensure randomness"
 
11:13 PM
Oh lord, that is so logical and so stupid at the same time I actually had to laugh haha
 
I only half followed the ensuing convo sorry. Just got myself very confused about what you both were expecting me to blow up. I was just trying to address the start of the convo where "seed" got some overly-prominent mention when it really didn't deserve it, and then it was clear there was misunderstanding on some other fundamentals
 
Sometimes you have a murderous insect sitting on the tip of your bulletproof boot, but by all means seeding is a footgun
@roganjosh I'm just musing, no worries
 
What am I missing in the following code?
import random


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


y = range(1, 10)
Shuffle(y)
print(y)
 
@TheCodeMocker that range objects are immutable?
 
why are you not just using random.shuffle?
 
11:16 PM
Just for learning purposes.
 
In other words, a helpful error message?
 
TypeError: 'range' object does not support item assignment
 
there we go
a range object x doesn't support x[j] = x[i] because you can't generally change values in a range and ensure it's still a range
you want to convert the range to a list and work with that
If you found that code somewhere, it was written in Python 2 (may it rest in peace).
 
OK. Thank you all!
y = list(range(1, 10))
problem solved.
 
yup
@TheCodeMocker side note: you can use the x[i], x[j] = x[j], x[i] idiom in Python to swap values
and you never touch x[0] which might be a bug
 
11:21 PM
@AndrasDeak--СлаваУкраїні Yes. It is a bug.
 
@AndrasDeak--СлаваУкраїні Pathetic! Real devs would write x[i:j+1:j-i] = x[j:i-1:i-j]
Ok, serious suggestion though: You can do reversed(range(x)) instead of range(x-1, -1, -1)
 
I spent 3 seconds wondering if that really works. I think it's time for bed
 
The outer index starts

A: from N-1 to 1 or

B: from N-1 to 0?
It should be A, right?
Done. Thanks all!
 
11:42 PM
I'm stuck again.
I can't pass functions as arguments to the class parameters.
 
@JakeSteffan again doubtful, so MCVE again please
 
What is MCVE?
 
Oh right, okay one sec.
 
For future reference: 1. Just ask if you have a question, 2. If it's a debugging problem, bring an MCVE
 
11:49 PM
import random


### TREE CLASS ###

class Tree:
    def __init__(self, age, quality, wetness):
        self.age = age
        self.quality = quality
        self.wetness = wetness

### TREE CLASS FUNCTIONS ###

    def tree_age(self):
        age = ["Seed", "Sprout", "Sapling", "Young", "Mature", "Dead"]
        return random.choices(age, weights=(1, 2, 4, 11, 7, 2), k=1)

    def tree_quality(self):
        quality = [random.randint(0, 5), random.randint(6, 20), random.randint(21, 25), random.randint(26, 28), random.randint(29, 30)]
The problem is near the bottom, where I have Tree() but no arguments passed, but I can't pass the functions into them, or can I?
 
What "the functions" do you want to pass into Tree()?
 
Basically I want the age, quality, and wetness passed in but I want them passed in so that they get randomized values.
 
one option is to call those methods inside __init__ with self being the only input parameter
 
So Tree(tree_age(), tree_quality(), tree_wetness()) wouldn't be a good option? I'm confused what I'm supposed to do.
 
But I'd call those methods generate_wetness etc. or similar
 
11:54 PM
Oh okay, yeah that sounds better.
 
@JakeSteffan that's not a good option because tree_age is not a name that exists
You only have Tree.tree_age or birch_tree.tree_age
@JakeSteffan Have you read a good intro python tutorial yet?
 
Okay, I'm still pretty new to OOP, sadly.
I'm 6 weeks into Python I'm brand new to coding lol.
 
so find a python tutorial aimed at total programming newbies
Structured learning might be a better investment than fumbling around blind
 
I think I'm doing pretty good but these lists and random stuff is throwing me off some.
How would you fill in the Tree( in this spot )?
 
By going to bed :) sorry
 
11:59 PM
Thanks for all the help earlier, I appreciate it. Have a good night!
 

« first day (4210 days earlier)      last day (730 days later) »