Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on How is this code "dividing" by a string?
Post
How is this code "dividing" by a string?
+5
−0
I found a strange expression in some Python code:
from library import HOME_DIRECTORY
file = HOME_DIRECTORY / "file.json"
It seems to be dividing a string by another string in order to do something with files.
However, I can't make this work in the REPL with my own strings:
>>> "one" / "two"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'str'
What is the code actually doing? Even if it didn't cause an error, I can't guess what dividing strings would mean, or why it would be useful.
2 comment threads