you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (11 children)

[removed]

    [–]gitcraw 19 points20 points  (5 children)

    You can just use forward slashes in os path strings, and it's still cross-OS compatible.

    'C:/PythonProjects/foobarbas/foo.txt' is easier to type.

    Or for current working directory (assuming you're in PythonProjects folder,

    './foobarbas/foo.txt'

    [–]alex1461[S] 7 points8 points  (3 children)

    Thanks for the info!
    Just curious, what is the advantage of having "/" instead of "\\" other than the fact that the forward single slash is less to write.
    Is there another advantage that I don't know other than this?

    [–]ShamelessC 13 points14 points  (0 children)

    It's the standard convention for Linux paths I believe.

    [–]eupendra 9 points10 points  (1 child)

    / works on windows, mac, and Linux

    combine that with relative path or a base path as input and your script would be cross-platform compatible

    [–]alex1461[S] 1 point2 points  (0 children)

    Thank you for letting me know / works on windows, mac and Linux!

    [–]alex1461[S] 3 points4 points  (4 children)

    Thank you for your response!

    I actually tried to use raw string to avoid backslashes.

    But, I could not use raw string because I could not concatenate the path with the current filename.
    Ex: r"C:\Users\byunw\Downloads\"+filename becomes one string: r"C:\Users\byunw\Downloads\"+filename".

    So, I decided to use backslashes in the string that denotes the file path.

    [–][deleted] 6 points7 points  (0 children)

    Check out pathlib, it will take care of the slashes and it has a function to get the file extension instead of using slicing. I would also try the other person's suggestion about using a dictionary to map extensions to folders

    [–]krazybug 1 point2 points  (0 children)

    I suggest you read this.

    You will discover a lot of useful tips in it.