10 examples of 'python get current directory' in Python

Every line of 'python get current directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
71def get_directory():
72 return os.path.abspath(os.path.join(os.getcwd(), 'python'))
1447def get_current_dir(self):
1448 """Gets the working directory of the current tab to create a
1449 new one in the same dir.
1450 """
1451 active_terminal = self.notebook.get_current_terminal()
1452 directory = os.path.expanduser('~')
1453 if active_terminal:
1454 active_pid = active_terminal.get_pid()
1455 if active_pid:
1456 cwd = os.readlink("/proc/{0}/cwd".format(active_pid))
1457 if os.path.exists(cwd):
1458 directory = cwd
1459 return directory
283def getcwd():
284 """
285 Wrap os.getcwd()
286
287 On Windows return ShortPathName (8.3 filename) that contain only ascii
288 characters.
289 """
290 cwd = os.getcwd()
291 # TODO os.getcwd should work properly with py3 on windows.
292 if is_win:
293 try:
294 unicode(cwd)
295 except UnicodeDecodeError:
296 # Do conversion to ShortPathName really only in case 'cwd' is not
297 # ascii only - conversion to unicode type cause this unicode error.
298 try:
299 import win32api
300 cwd = win32api.GetShortPathName(cwd)
301 except ImportError:
302 pass
303 return cwd
102def DirectoryOfThisScript():
103 return os.path.dirname(os.path.abspath(__file__))
705def get_current_path( self ):
706 if self.CGIdata.has_key( "path" ):
707 relativ_path = posixpath.normpath( self.CGIdata["path"] )
708 else:
709 relativ_path = "."
710
711 cfg.base_path = posixpath.normpath( cfg.base_path )
712
713 absolute_path = posixpath.join( self.absolute_basepath, relativ_path )
714 absolute_path = posixpath.normpath( absolute_path )
715
716 self.check_absolute_path( absolute_path )
717
718 return relativ_path, absolute_path
143def get_path():
144 if getattr(sys, 'frozen', False):
145 return os.path.dirname(sys.executable)
146 else:
147 return os.path.abspath(os.path.dirname(sys.argv[0]))
15def get_pwd():
16 return os.path.abspath(os.getenv('PWD'))
24def getCurrentDir(self):
25 """returns the script directory name to locate the correct dictionary path"""
26 return os.path.dirname(os.path.abspath(__file__)) + '/';
57def get_data_files_path():
58 """Get a direct path to the data files colocated with the script.
59
60 Returns:
61 The directory where files specified in data attribute of py_test
62 and py_binary are stored.
63 """
64 return _os.path.dirname(_inspect.getfile(_sys._getframe(1)))
655def getcwd():
656 """
657 Wrap os.getcwd()
658
659 On Windows return ShortPathName (8.3 filename) that contain only ascii
660 characters.
661 """
662 cwd = os.getcwd()
663 # os.getcwd works properly with Python 3 on Windows.
664 # We need this workaround only for Python 2 on Windows.
665 if is_win and is_py2:
666 try:
667 unicode(cwd)
668 except UnicodeDecodeError:
669 # Do conversion to ShortPathName really only in case 'cwd' is not
670 # ascii only - conversion to unicode type cause this unicode error.
671 try:
672 cwd = win32api.GetShortPathName(cwd)
673 except ImportError:
674 pass
675 return cwd

Related snippets