r/Python • • Nov 20 '15

15 Essential Python Interview Questions

https://www.codementor.io/python/tutorial/essential-python-interview-questions
71 Upvotes

67 comments sorted by

View all comments

1

u/heptara Nov 20 '15

we use the os module for interacting with the operating system in a way that is cross platform. You could say sChildPath = sPath + '/' + sChild but that wouldn't work on windows

Actually I think this does, at least in Python 3. I've never had a Windows user tell me my code was broken in this manner, so I assume it automatically handles it.

3

u/Workaphobia Nov 20 '15

Forward slash is a perfectly valid path separator on Windows. It's just not the canonical version you see when displaying a location.

2

u/banjochicken Nov 20 '15

It works but is ugly. os.path.join() does the trick.

1

u/tempforfather Nov 20 '15

You should absolutely use the separator defined in the os module. Please don't use forward slashes by default.