Reading a file using a relative path in a Python project

Relative paths are relative to current working directory. If you do not want your path to be relative, it must be absolute. But there is an often used trick to build an absolute path from current script: use its __file__ special attribute: from pathlib import Path path = Path(__file__).parent / “../data/test.csv” with path.open() as f: … Read more

Relative URLs and trailing slashes

No. The problem is not so much related to the director/file mapping (which has never been expected as how mappings would happen, only allowed as a convenient mapping, which still often are convenient). It’s more related to the simple fact that dolor is not the same as dolor/ and you want to give a new … Read more

Codeigniter – dynamically getting relative/absolute path outside of application folder

In the index.php file in the root, most useful paths are defined so that you can use them within the rest of the code. Have you tried FCPATH in this case? FCPATH -> “https://stackoverflow.com/” BASEPATH -> ‘/system/’ APPPATH -> ‘/application/’ UPDATE: As mentioned in the comments, the path examples above are only to give an … Read more

MVC Bundling and CSS relative URLs

CssRewriteUrlTransform updates the CSS Url with absolute path, saying so if we use – bundles.Add(new StyleBundle(“~/Content/css”).Include(“~/Content/site.css”,new CssRewriteUrlTransform())); and we have following CSS class in “site.css” .Sandy { background-image: url(“Images/Sandy.jpg”); border: 1px solid #c8c8c8; border-radius:4px 4px 4px 4px; box-shadow: 1px 1px 8px gray; background-position:left; background-size:contain; -moz-background-size:contain; -webkit-background-size:contain; -o-background-size:contain; background-repeat:no-repeat; min-height:100px; min-width:100px; display:block; } and following folder … Read more

PHP absolute path to root

Create a constant with absolute path to the root by using define in ShowInfo.php: define(‘ROOTPATH’, __DIR__); Or PHP <= 5.3 define(‘ROOTPATH’, dirname(__FILE__)); Now use it: if (file_exists(ROOTPATH.’/Texts/MyInfo.txt’)) { // … } Or use the DOCUMENT_ROOT defined in $_SERVER: if (file_exists($_SERVER[‘DOCUMENT_ROOT’].’/Texts/MyInfo.txt’)) { // … }