Why os.move() Sometimes Does Not Work And Why shutil.move() Is The Savior?

Recently I ran into an issue where this, for example, code fails: import os os.rename('/foo/a.txt', '/bar/b.txt') Traceback (most recent call last): File "", line 1, in OSError: [Errno 18] Invalid cross-device link The documentation for the os module says that sometimes it might fail when the source and the destination are on different file-systems: os.rename( src, dst, *, src_dir_fd=None, dst_dir_fd=None) Rename the file or directory src to dst. If dst is a directory, OSError will be raised. On Unix, if dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if dst already exists, OSError will be raised even if it is a file. ...

January 28, 2018 · 5 min · giedrius

What is Actually True and False in Python?

Intro Did you know that in Python 2.x you can do the following? $ python2 Python 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> True = False >>> False False >>> True False >>> not True True >>> True == False True >>> True != False False How can it be that not True is True and True is equal to False? Why is it even possible to do this? Isn’t what is True and False in the language defined to be constant and unchangeable? What sense does it make to change the meaning of what is True and what is False? In any way, to fix this bug in the matrix, do this: ...

January 4, 2018 · 9 min · giedrius