is it okay to use os.sep instead of "/" in url

  • Last Update :
  • Techknowledgy :

It seems to be os.sep returns "/" as a separator, I wonder if I can use that to make a URL: eg. To get a url like

   protocol + request.get_host() + os.sep + get_file_name()

Suggestion : 2

I recommend you use os.path.sep for anycodings_python clarity, since it's a path separator, anycodings_python not an OS separator. If you import anycodings_python os.path as path you can call it anycodings_python path.sep, which is even better.,The character used by the operating anycodings_python system to separate pathname components. anycodings_python This is '/' for POSIX and '\' for anycodings_python Windows.,I'd use os.path.sep to make it very anycodings_python clear that it's the path anycodings_python separator… But consistency is anycodings_python more important, so if one is already anycodings_python being used, use that. Otherwise, pick anycodings_python one and use it all the time.,I guess the os.path.sep.join is more anycodings_python robust and can be used w/o modifications anycodings_python for any os.

Edit: Just to make sure you're not anycodings_python reinventing the wheel, though, the path anycodings_python module already has join, split, dirname, anycodings_python and basename functions… So anycodings_python you should rarely need to use path.sep:

>>> os.path.join("foo", "bar", "baz")
'foo/bar/baz' >>>
   ('foo/bar', 'baz')

The following examples could highlight anycodings_python the differences between os.path.join and anycodings_python os.path.sep.join.

import os
   os.path.join("output", "images", "saved")
'output/images/saved' >>>
os.path.sep.join(["output", "images", "saved"])

Both of them belongs to the same python anycodings_python class also.


# Output
<class 'str'>
   <class 'str'>

Both have them have the same anycodings_python documentation.


# The outputs of both print statements are the same.

Suggestion : 3

Updated: November 12, 2020

# Import necessary packages
import os
from glob
import glob

import earthpy as et
# Download data on average monthly temp
for two California sites
file_url = "" = file_url)
Downloading from https: //
   Extracted output to / root / earth - analytics / data / earthpy - downloads / avg - monthly - temp - fahr
# Set working directory to earth - analytics
os.chdir(os.path.join(, "earth-analytics"))

# Create a path to the data folder
data_folder = os.path.join("data", "earthpy-downloads",
# Get a specific directory
file_list = glob(data_folder)