In python I have variables base_dir and filename. I would like to concatenate them to obtain fullpath. But under windows I should use \ and for POSIX / .
fullpath = "%s/%s" % ( base_dir, filename ) # for Linux
How can I make this platform independent?
You want to use os.path.join() for this.
The strength of using this rather than string concatenation etc is that it is aware of the various OS specific issues, such as path separators. Examples:
Under Windows 7:
Under Linux:
The os module contains many useful methods for directory, path manipulation and finding out OS specific information, such as the separator used in paths via os.sep