News for hackers. Stuff that matters.
Re:Using Enumerated Types in Python by BiteCode_dev on Saturday June 06, 2020 @03:18PM (#23441577)
So, you don't use open("w"), do you ? You use the non magic open(os.O_WRONLY) of course.

Because magic strings are bad.

Re:Using Enumerated Types in Python by MikeTheGreat on Saturday June 06, 2020 @03:42PM (#23441718)
I will now - thanks for the tip! :)

And, moreover, this will inspire me to ask "How many other traditional magic numbers/strings/etc have I gotten used to that might be defined more readably?" strcmp, I'm looking at you!

I know your post was sarcastic/snarky but it was genuinely helpful

Re:Using Enumerated Types in Python by 1wd on Saturday June 06, 2020 @05:19PM (#23442311)
f.tell(offset, os.SEEK_CUR) over f.tell(offset, 1)

https://docs.python.org/3/library/os.html#os.SEEK_CUR

I wish the docs on f.tell at least mentioned the option

https://docs.python.org/3/tutorial/inputoutput.html#methods-...

Re:Using Enumerated Types in Python by remram on Saturday June 06, 2020 @10:25PM (#23444267)
Except it wasn't, os.O_WRONLY is for os.open() (equivalent of open syscall, takes numeric flags), not the built-in open() (equivalent of C fopen, takes "w" and similar strings).
Re:Using Enumerated Types in Python by comfydragon on Saturday June 06, 2020 @03:36PM (#23441687)
Python 3.8 has typing.Literal for this.
Re:Using Enumerated Types in Python by zo1 on Sunday June 07, 2020 @07:20AM (#23446577)
That's a fair point, and I'll be sure to keep an eye out for that type of magic-string usage going forward. Though most "magic string" usages are not nearly as official as the one you mention and usually occur in business-level code written by ordinary developers that may not be disciplined or experienced. Those spots most certainly need all the assistance they can get instead of relying on magic-strings, hence my comment of magic strings being bad.
Re:Using Enumerated Types in Python by 1wd on Saturday June 06, 2020 @05:23PM (#23442342)
You would have to use os.open
Re:Using Enumerated Types in Python by BiteCode_dev on Sunday June 07, 2020 @03:46AM (#23445555)
I would also have to pass the path as a first param. This was not meant to be correct, just teasy.