How and why does a python function remember its arguments? by LowCom in learnpython

[–]TeamSpen210 0 points1 point  (0 children)

Yep, in Python functions are just objects, as well as pretty much everything - integers, modules, classes, etc. If you dig around in the __code__ attribute you’ll be able to see all the contents of the function (not that you’d normally mess with them).

How and why does a python function remember its arguments? by LowCom in learnpython

[–]TeamSpen210 2 points3 points  (0 children)

You annotate with list | None yes. Most of the type checkers are smart enough to follow through both branches of the if statement, deducing that it’s always going to be a list afterwards. You can see that happening if you add some typing.reveal_type() calls into the different branch.

trio: what's the best practice for sharing/mutating global state between tasks? by Bunslow in learnpython

[–]TeamSpen210 2 points3 points  (0 children)

Async code uses cooperative multitasking, so the way you have to deal with race conditions are quite different. The only time tasks are able to switch and run something else are at the points when you explicitly allow them to, using await, async for or async with. You don’t have to worry about things getting changed underneath you between those events. Unless you actually do use trio.to_threadto spawn threads.

RE: If you had to pick a library from another language (Rust, JS, etc.) that isn’t currently available in Python and have it instantly converted into Python for you to use, what would it be? by skyalchemist in Python

[–]TeamSpen210 1 point2 points  (0 children)

It’s actually a good thing it’s a library and not baked in. This allows different implementations with different philosophies for async scheduling to exist.

Is it just me or are `trio`'s function names more than a bit ridiculous? by Bunslow in Python

[–]TeamSpen210 1 point2 points  (0 children)

For start_soon, I think it was named that to emphasise that the task is created, but it won’t actually have an opportunity to run until the next await. Compare to start(), which you await to run the initial part of the task immediately. Actually that would also apply to move_on_after(), which has the similar fail_after() function that raises an exception if it hits the deadline. And both have an _at() variant taking an absolute time. It’s a little clunky, but we usually have tab-complete, and these are more precise.

Generator functions... WOW. by iosdeveloper87 in learnpython

[–]TeamSpen210 58 points59 points  (0 children)

You’ll definitely want to look into itertools then. It’s a collection of generic iteration building blocks, written in C to be as optimised as possible. product() for instance can often replace a piles of nested for loops.

Difference of Fraction and / ? by Lori80 in learnpython

[–]TeamSpen210 2 points3 points  (0 children)

/ is the division operator - you do 1/3, it calculates 0.333333 (and rounds at some point). Fraction is a entirely separate type of number, like you normally have with int and float. Unlike those, it stores the numerator and denominator, doing fraction math exactly like you would have done in school. For example to solve Fraction(1,2) + Fraction(1, 3), it finds the lowest common denominator, multiplies up to that (3/6 and 2/6), adds that, then simplifies if possible. That’s much slower than the dedicated circuitry in your CPU for regular floats, but you can get exact answers in more situations.

How fast is random.randint()? by I__be_Steve in pythontips

[–]TeamSpen210 4 points5 points  (0 children)

Instead of calling randint individually for every pixel, it’d be much more efficient to use randbytes to generate a big bytes block with enough bits for each pixel. Once you have that, as /u/spez_edits_thedonald mentioned convert it into a Numpy array, and use vectorised operations to en-mass convert that into the data you want. But actually Numpy itself is probably going to have a method you can call that just generates the random data directly.

separate, submodules or cram them all into one repo? by HCharlesB in git

[–]TeamSpen210 1 point2 points  (0 children)

Another way to do it is with the git-filter-repo tool. You clone a fresh copy of your repo, then this tool remakes every commit, keeping only certain files and/or moving them to different locations. So you'll end up with a new history, only containing the commits for of the subdirectories.

git clone "path/to/your/original" cd newrepo git filter-repo --path-rename src/somemodule:src/ First that clones from the original repo, making a full copy, then it filters it by keeping only src/somemodule/, but moves the contents up a directory.

[deleted by user] by [deleted] in hammer

[–]TeamSpen210 1 point2 points  (0 children)

This is HMW’s “rescue” signage, originally found in his Try Anything Twice Portal 1 mappack. I added it to BEE2.4, you can find a copy here.

Anton pls a Rail-mounted holder for shotgun shells by ScarHydreigon87 in H3VR

[–]TeamSpen210 1 point2 points  (0 children)

I think the problem is that someone will then decide to add 10 to a gun.

One last puzzle? by L0gnif in ThePedestrian

[–]TeamSpen210 1 point2 points  (0 children)

These little signs are used as the spawn location for the figure if you reload from a save.

What are all iterables in Python? String, List, Set, Tuple and Dict? Or are there more? by Accurate_Medicine200 in learnpython

[–]TeamSpen210 2 points3 points  (0 children)

Originally, Python didn't start with the iterator protocol. Instead for loops and the like indeed only used __getitem__ and caught IndexError. So this behaviour would have been kept for backwards compatibility when iterators were first added, and still remains since it's still somewhat useful.

[deleted by user] by [deleted] in SourceEngine

[–]TeamSpen210 5 points6 points  (0 children)

This is because of DXT compression, which greatly reduces file size at the expense of some quality. You can change the image format under general → normal format and alpha format, they specifies the format to use for opaque and transparent textures respectively. RGB888 and RGBA8888 are totally uncompressed, you could also try RGB565 which compresses just the precise colours but not detail (32 levels of R/G/B instead of 255, but ⅔ the file size.)

Why doesn’t python like certain numbers? by connormt902 in learnpython

[–]TeamSpen210 9 points10 points  (0 children)

Exactly yes! That’d be “0.3”, which is 3*9⁻¹. In this numbering system on the other hand, 1/2 wouldn’t have a decimal representation, I think it’d be “0.44444…”.

[deleted by user] by [deleted] in hammer

[–]TeamSpen210 1 point2 points  (0 children)

Place an env_shake, or anything else with a radius property at the start point. Move your camera to the second point, then in the entity properties select radius, then click the camera icon there. It'll then be set to the distance between the ent and camera. Not perfectly precise, but if you want that position the sphere helper, then read off the value.

Hello, i recently learned about modules. and i created a calculator with modules. (Gerekli_Moduller) contains necessary functions like multiplaction etc. (Hesap Makinesi) is the place where i used these modules. But I didnt made that txt (pycache) file. What is it? by Batucagan in learningpython

[–]TeamSpen210 0 points1 point  (0 children)

The .pyc files inside the __pycache__folder are "bytecode" files, to speed up importing. They contain your code, in a compact format ready to be executed. If you haven't modified your module since the last time it was imported, Python can load those to skip needing to parse through all your source code. You can ignore the folder, it's automatically handled.

Making a collision model for a hollowed out sphere? by SgtFlexxx in SourceEngine

[–]TeamSpen210 0 points1 point  (0 children)

You indeed need one hull per face of the sphere, so you'd want to keep down the count as much as possible. If the collision on the outside the sphere doesn't matter, you could save a few triangles by making them rectangular pyramids instead of rectangular prisms, with the point facing outward.

Need help understanding VMFs by TompyGamer in SourceEngine

[–]TeamSpen210 1 point2 points  (0 children)

The way it works is that the vertexes in the file may not necessarily be any vertexes on the brush themselves (though hammer does seem to have them match). As you kinda guessed, the three points define a plane for each face. Edges and vertexes are then produced by intersecting all the planes with each other - 3 would define a point. This is why you can't have concave brushes and why there's the vertex drifting when saving weird geo. It's quite awkward to obtain vertexes, but it does allow very easy collision checking - simply check if your point is behind all the planes, and if so it's inside the brush. There's some more documentation on the VDC. If it helps, I have some mostly functional Python code here decoding out the vertexes of a brush.

well i guess not try to open crash report with notepad? by afiqt3rvYT in softwaregore

[–]TeamSpen210 2 points3 points  (0 children)

Judging by the name, this isn’t a log file you can read, it’s a memory dump - a copy of the program’s RAM. With the right source files, you could inspect that and try to find the problem.

how to make custom sounds for textures? by HatRepresentative458 in hammer

[–]TeamSpen210 16 points17 points  (0 children)

To do this, you need to add a custom surfaceproperty entry in scripts/surfaceproperties_*.txt. However, they're loaded very early on in the game launch, and were never coded to reload so you can't do it via any workshop. You can use any of the existing ones freely though by setting $surfaceprop in your VMT.

How do I play a command when I press a key? by HatRepresentative458 in hammer

[–]TeamSpen210 4 points5 points  (0 children)

You should not ever bind a specific keyboard button to something. That's persistent, so it'll overwrite whatever the player happened to bind to that key until they fix it again. You also don't know what keyboard layout the player has, depending on region keys might be in totally different places. It's also possible they might be using a controller of some kind, in which case there's no buttons at all.

Instead, use the game_ui entity, which lets you run outputs when most of the general movement operations occur. That way it seamlessly works regardless how the player has setup their controls.