get script directory name – Python [duplicate]

import os os.path.basename(os.path.dirname(os.path.realpath(__file__))) Broken down: currentFile = __file__ # May be ‘my_script’, or ‘./my_script’ or # ‘/home/user/test/my_script.py’ depending on exactly how # the script was run/loaded. realPath = os.path.realpath(currentFile) # /home/user/test/my_script.py dirPath = os.path.dirname(realPath) # /home/user/test dirName = os.path.basename(dirPath) # test

Is there a C++ equivalent to getcwd?

Ok, I’m answering even though you already have accepted an answer. An even better way than to wrap the getcwd call would be to use boost::filesystem, where you get a path object from the current_path() function. The Boost filesystem library allows you to do lots of other useful stuff that you would otherwise need to … Read more

shell init issue when click tab, what’s wrong with getcwd?

This usually occurs when your current directory does not exist anymore. Most likely, from another terminal you remove that directory (from within a script or whatever). To get rid of this, in case your current directory was recreated in the meantime, just cd to another (existing) directory and then cd back; the simplest would be: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)