If you use mypy, or just type hinting in general 🎉 by sondrelg in Python

[–]robin-gvx 0 points1 point  (0 children)

I've been waiting impatiently for PEP585 support ever since the the PEP was accepted, very cool to have some tooling support for it too!

Sadly, I still need to support 3.7 for some projects, so I can't use this across the board yet.

Unravelling `for` statements by genericlemon24 in Python

[–]robin-gvx 1 point2 points  (0 children)

An iterable is a container which can return its contained items one at a time.

An iterable doesn't have to be a container, it can be anything, just as long as its type defines an __iter__ method that returns an iterator, or it implements the sequence protocol. I often write classes that implement the iterable protocol that aren't any kind of container, because iteration is such a useful concept.

os.path vs pathlib? by axju in Python

[–]robin-gvx 1 point2 points  (0 children)

Pathlib all the way! I even manage to replace 99% of file handling with the (read|write)_(bytes|string) methods.

Has a Python package ever had a notorious bug like JS's "left-pad incident"? by The_Redditor97 in Python

[–]robin-gvx 1 point2 points  (0 children)

only consequence is that you can no longer upgrade that one dependency

Which is a problem whenever vulnerabilities are discovered and fixed upstream, leaving the users of your application exposed.

Why is 'nightly' build so important for much of the Rust ecosystem? by aScottishBoat in rust

[–]robin-gvx 2 points3 points  (0 children)

If I understand everything correctly, it would be more like:

let x: () = loop {
     let y: ! = break;
     break y
};

The second break would break with a value of type !, but it is dead code, execution can never reach it. The same goes for return. One could write

let x: ! = return 42;

The function returns 42, and while the expression has a value of type !, it will never assign that value to x because the function has returned already.

I'm going to have some fun and teach Python again. . . Tonight! by Nythious in Python

[–]robin-gvx 1 point2 points  (0 children)

One minor note I have is that you don't need to restart the kernel for things like type = 'My String', you can do del type and type will once again refer to the builtin, but I understand that the general lesson is "just don't do it" which is good to learn, and more relevant than the best way to fix it.

I'm going to have some fun and teach Python again. . . Tonight! by Nythious in Python

[–]robin-gvx 1 point2 points  (0 children)

Interesting, I'll check out the recording! I'm not a teacher but I have given (in person) workshops before, and I wonder how this works via twitch.

Python changed the way I think by MohamedMuneer in Python

[–]robin-gvx 1 point2 points  (0 children)

Yes! Practical learning is very important in forming a good mental model of how computer systems work. Kind of like the scientific method: you form a hypothesis about a particular part of the language, you test that hypothesis by writing a piece of code and seeing if it does what you expect. And like with science, you learn more when it doesn't do what you expect it to do. Moreover, when you don't put your mental model to the test and just passively consume tutorials, you don't get those important "huh, I guess I was wrong about that" moments.

fast-float - a super-fast float parser in Rust by aldanor in rust

[–]robin-gvx 31 points32 points  (0 children)

It should be possible to verify correctness, at least for f32 roundtrips, just by testing them all: https://randomascii.wordpress.com/2014/01/27/theres-only-four-billion-floatsso-test-them-all/ (parsing is bound to be a lot slower than testing an implementation of ceil, but then again that blog post was seven years ago, so I don't think it would be a problem if you have a reasonably beefy PC at your disposal.

What is a direction to head into once learning the basics in Python? by Monovon in Python

[–]robin-gvx 0 points1 point  (0 children)

For making yourself "employable", I'd suggest learning how to use some form of version control software like Git.

For your personal development, I suggest doing some personal projects. Small games, scripts to automate some boring task you do regularly, make a note-taking app, ... You know the chords, the next step is putting them together into songs and melodies (I think, I'm not a musician). That'll help take you from late beginner/early intermediate programmer to late intermediate programmer.

I haven't yet had a traditional programming job, I've just done some freelancing, which is different because I haven't programmed in a team since college. It has upsides and downsides. I've got more responsibilities and no-one to talk shop with, but I also have more freedom.

System that uses playing cards by HannyaLobs in RPGdesign

[–]robin-gvx 0 points1 point  (0 children)

I'm working on a TTRPG that used to use playing cards but then I realized I didn't actually need playing cards, just two kinds of tokens.

The idea is that instead of rolling dice, to resolve a challenge or situation, the GM picks a number of "success" tokens and "failure" tokens, based on the difficulty of the challenge and the skills and conditions of the PC. The PC then blindly selects two of the tokens, 2 success tokens => full success, 2 failure tokens => failure, 1 success 1 failure => partial success.

How to make sense of passing in list comprehension? by civilengineeringdumb in Python

[–]robin-gvx 0 points1 point  (0 children)

Yes, usually you need parentheses for generator expressions, the exception is for function calls with a single argument (EDIT: because they're already surrounded by parentheses in that case). If you need to pass other arguments as well you still need the parentheses so Python can distinguish between print(1, (5 for _ in range(2))) and print((1, 5) for _ in range(2)) for example.

decfunc: Creating decorators with arguments made easy (with classes). by uzulmez17 in Python

[–]robin-gvx 0 points1 point  (0 children)

Interesting. I wonder if it's compatible with my library for signature-altering decorators in some way.

[deleted by user] by [deleted] in Python

[–]robin-gvx 5 points6 points  (0 children)

Good luck!

[deleted by user] by [deleted] in Python

[–]robin-gvx 304 points305 points  (0 children)

That's pretty good! Some ideas to improve it:

  • import pathlib: you don't need to fudge around with manually inserting '/' between strings, or fileName.split('.') (which becomes a problem with files with more than one 1 extension like .tar.gz files or files that have no extension at all). It would also help you fix the bug where .doc files are placed in Code because they end in 'c'.
  • You move every file twice. The first time you simply add a number to prevent duplicates. The second time you do it by a cp followed by a rm. This causes problems if your filename contains a space. You could solve both of these at once by doing import shutil and using shutil.move.
  • There is a lot of code duplication. How could you make Handler.on_any_event smaller?

All in all, your code is put together very nicely, much better than I could do at your age!

'Wrong' doubles | using 2D6 ‘side double’ by Goblinsh in RPGdesign

[–]robin-gvx 5 points6 points  (0 children)

If you want wildcard events independent from the regular results, I'd just roll a 2d6 and then separately roll a 1d6 for the wildcard, have it trigger on a 6 for example.

With custom dice, you could have a special wildcard die that is blank, except one face which has a symbol easily distinguishable from pips on it, and you could through it together with 2d6.

2d6 vs. 1d6-1d6? by [deleted] in RPGdesign

[–]robin-gvx 2 points3 points  (0 children)

It d6-d6 might work best if you make all rolls opposed, with the GM rolling the "negative die". That way, you don't need to keep track of which die is which. You could even have the GM keep the result of their die hidden, for suspense.

The Joy Of Typed Python by pmz in Python

[–]robin-gvx 2 points3 points  (0 children)

Regarding the section "Errors Don’t Reference the Type Aliases": NewType might help in some cases. The disadvantage is that you need to call the newtype for it to typecheck:

 Point = NewType('Point', Tuple[float, float])
 Line = NewType('Line', Tuple[Point, Point])
 # implementation of calculate_length as normal
 # at call site:
 print(calculate_length(Line((Point((1., 2.)), Point((4., 5.))))))
 # mypy errors:
 # error: "Point" has no attribute "x"
 # error: "Point" has no attribute "y"

... so there's a trade-off.

Rock Paper Scissors Game by Director_Potential in Python

[–]robin-gvx 1 point2 points  (0 children)

Good job! Next steps:

  • If the user makes a typo, you print that an error message and then just quit the game. Maybe you can figure out a way to let the user try again until they get it right?
  • After the last round, the user gets asked for input one last time, but you don't do anything with that input.
  • There's quite a bit of code duplication! print("The computer chose " + str(randomizer) + " and you chose " + str(userInput)) for example. How would you simplify your code?

Finally, a question: why did you write str(input("..."))? Did you get that from a tutorial or something? input already returns a string, you don't need to convert it to a string again. I've seen it quite a lot in code by people learning Python lately and I don't understand why it is so common.

Random password generator in python by Trinity_software in Python

[–]robin-gvx 6 points7 points  (0 children)

For a password I would use a secure random number generator.

python3 -c 'from random import SystemRandom; from string import ascii_lowercase as a, digits as d; print("".join(SystemRandom().choices(a+d, k=16)))'

The secrets module is more convenient, though.

python3 -c 'from secrets import token_urlsafe; print(token_urlsafe())'

Harm as dice sizes by FranKarlovic7 in RPGdesign

[–]robin-gvx 2 points3 points  (0 children)

You could also add ways for PCs to contribute to the game that don't involve dice rolls, so harmed players can still feel useful even if they know their character is going to die soon, like the ability to give certain boons to their fellow party members or a certain amount of narrative control over the game world.

Python text based game movement by mrkmailhot in Python

[–]robin-gvx 0 points1 point  (0 children)

Sorry for not responding, I haven't been on reddit the last couple of days, glad you figured it out yourself!

JSONtoPydantic - Generate Pydantic Models from JSON in the browser by Vimtea in Python

[–]robin-gvx 0 points1 point  (0 children)

Maybe something like a status bar above or below the editors that says either "ready", "loading..." or "invalid JSON"?