Python: is the current directory automatically included in path?

Python adds the directory where the initial script resides as first item to sys.path: As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or … Read more

How do I redirect to root – public/index.html?

You can assign a named route to a static file by passing any non-empty string as :controller and the path to the file as the :action for the route: Application.routes.draw do root :controller => ‘static’, :action => “https://stackoverflow.com/” # or # root :controller => ‘static’, :action => ‘/public/index.html’ end # elsewhere redirect_to root_path # redirect … Read more

In Node.js how can I tell the path of `this` module?

As david van brink mentioned in the comments, the correct solution is to use __dirname. This global variable will return the path of the currently executing script (i.e. you might need to use ../ to reach the root of your module). For example: var path = require(“path”); require(path.join(__dirname, ‘/models’)); Just to save someone from a … Read more

How do I read an image from a path with Unicode characters?

It can be done by opening the file using open(), which supports Unicode as in the linked answer, read the contents as a byte array, convert the byte array to a NumPy array, decode the image # -*- coding: utf-8 -*- import cv2 import numpy stream = open(u’D:\\รถ\\handschuh.jpg’, “rb”) bytes = bytearray(stream.read()) numpyarray = numpy.asarray(bytes, … Read more

How to make an absolute path relative to a particular folder?

Yes, you can do that, it’s easy, think of your paths as URIs: Uri fullPath = new Uri(@”C:\RootFolder\SubFolder\MoreSubFolder\LastFolder\SomeFile.txt”, UriKind.Absolute); Uri relRoot = new Uri(@”C:\RootFolder\SubFolder\”, UriKind.Absolute); string relPath = relRoot.MakeRelativeUri(fullPath).ToString(); // relPath == @”MoreSubFolder\LastFolder\SomeFile.txt”