Dec-27-2023, 09:01 PM
(This post was last modified: Dec-27-2023, 09:01 PM by deanhystad.)
Quote:i changed DirectorySize class( i added the line print(self.obj,objtype)). the output was:That is what I would expect. self is a DirectorySize object and obj is a Directory object. Do you have a question related to this?
<__main__.DirectorySize object at 0x000001E97B187A10> <__main__.Directory object at 0x000001E97B187FD0> <class '__main__.Directory'>
Quote:why d=Directory('C:\Users\akbar\Desktop\') causes error?In Python you cannot end a string with a single backslash. There is also a problem that "\U" is the start of an escape sequence. Python expects \U to be followed by numbers. This is the error I see.
Error:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Bad error reporting is yet another reason for not using IDLE.You could try: d=Directory("C:\\Users\akbar\Desktop"), but if you don't know all the escape sequences it is probably better to use:
d=Directory("C:\\Users\\akbar\\Desktop")Or better yet:
d=Directory("C:/Users/akbar/Desktop")Stop using "\" as a separator in a file path. Start using "/".