« first day (3296 days earlier)      last day (1655 days later) » 
03:00 - 21:0021:00 - 23:00

9:02 PM
Huh. I just noticed that os.path isn't actually a module itself, so now I'm wondering how crazy/irresponsible it would be to replace all my import os.path with just import os
>>> import os
>>> os.path
<module 'posixpath' from '/usr/lib/python3.7/posixpath.py'>
Is that, like, documented...?
 
and it's even there with python3 -S, I just checked
 
The documentation mentions that os.path is posixpath or ntpath depending on the platform, but doesn't say how that's implemented, so I guess it's still an awful idea to rely on import os making os.path available
also, what the yam
> using bytes objects cannot represent all file names on Windows (in the standard mbcs encoding), hence Windows applications should use string objects to access all files.
not all paths can be represented as bytes? bytes?! how is that even possible
 
because b' is a valid filename
 
wim
@Aran-Fey no, you got it backwards - actually should have import os and not import os.path.
it's even mentioned in help(os.path)
 
9:17 PM
Huh. It doesn't say that in the online docs, though.
 
wim
hmm
it might be that they are trying to say don't import posixpath, ntpath, etc directly
 
oh yeah, that'd make sense
 
Yeah, but it is ambiguous.
 
Wait a minute. So on linux all paths can be represented as bytes, and on Windows all paths can be represented as strings. So, technically speaking, the correct way to, say, list all files in a folder, would be to do os.listdir(path_as_bytes) on linux and os.listdir(path_as_string) on Windows?
 
sounds like it
 
9:21 PM
Writing perfect code sure is needlessly difficult sometimes
 
there was also some recent problem where there was an error because some path thingie expected bytes vs strings...
can't see it in the transcript so I may have seen it on main
it may have been something else because random tests suggest that os.path things accept both
 
wim
it's a little bit more subtle than that
on linux os.listdir(b'.') will return bytestring filenames
and os.listdir('.') will return decoded filenames
 
that makes sense to me so far
 
wim
the problem with returning decoded filenames is that there is no one true filesystem encoding (linux path names are bytes)
and you can have a filename that won't decode at all
 
now I have mojibake file name flashbacks
 
wim
9:26 PM
it pains me to say it, but windows actually does it better here (there is a correct filesystem encoding, and file paths are text)
 
Is there no "please try to use this encoding" on linux?
 
wim
there is sys.getfilesystemencoding but it's a guess at best
 
or they just say that bytes are unambiguous, and it's your problem if you can't guess
 
linux treating paths as just bytes is oddly... typical
who cares about user-friendliness anyway, amirite?
 
wim
use whatever encoding you want for the filesystem! (you didn't want to share a directory with anyone else, right?)
 
9:34 PM
only sociopaths use non-ascii filenames, so it's fine
 
10:11 PM
I want to print only if there is an object of the wrong type in a list.
How do I say "if type in importantList:"?
 
you need to loop over the list and check each item, no way around it
 
AAAAAAAAHHHHHH
 
no reason to panic, though
 
but what if Johnny's at the Disco?
 
03:00 - 21:0021:00 - 23:00

« first day (3296 days earlier)      last day (1655 days later) »