我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用site.getuserbase()。
def test_getuserbase(self): site.USER_BASE = None user_base = site.getuserbase() # the call sets site.USER_BASE self.assertEqual(site.USER_BASE, user_base) # let's set PYTHONUSERBASE and see if it uses it site.USER_BASE = None import sysconfig sysconfig._CONFIG_VARS = None with EnvironmentVarGuard() as environ: environ['PYTHONUSERBASE'] = 'xoxo' self.assertTrue(site.getuserbase().startswith('xoxo'), site.getuserbase())
def run(self): """Before executing run command, download data files. """ for f in self.data_files: if not isinstance(f, tuple): continue for i, u in enumerate(f[1]): base = path.basename(u) f[1][i] = path.join(sys.prefix, f[0], base) if not path.exists(f[1][i]): f[1][i] = path.join(sys.prefix, "local", f[0], base) if not path.exists(f[1][i]): f[1][i] = path.join(site.getuserbase(), f[0], base) if not path.exists(f[1][i]): f[1][i] = urllib.urlretrieve(u, base)[0] return distutils.command.install_data.install_data.run(self)
def load(graph): """Load the Trip Advisor dataset to a given graph object. The graph object must implement the :ref:`graph interface <dataset-io:graph-interface>`. Args: graph: an instance of bipartite graph. Returns: The graph instance *graph*. """ base = "TripAdvisorJson.tar.bz2" path = join(".", base) if not exists(path): path = join(sys.prefix, "rgmining","data", base) if not exists(path): path = join(sys.prefix, "local", "rgmining","data", base) if not exists(path): path = join(site.getuserbase(), "rgmining","data", base) R = {} # Reviewers dict. with tarfile.open(path) as tar: for info in _files(tar): with closing(tar.extractfile(info)) as fp: obj = json.load(fp) target = obj["HotelInfo"]["HotelID"] product = graph.new_product(name=target) for r in obj["Reviews"]: name = r["ReviewID"] score = float(r["Ratings"]["Overall"]) / 5. try: date = datetime.datetime.strptime( r["Date"], _DATE_FORMAT).strftime("%Y%m%d") except ValueError: date = None if name not in R: R[name] = graph.new_reviewer(name=name) graph.add_review(R[name], product, score, date) return graph