10 examples of 'os.getcwd()' in Python

Every line of 'os.getcwd()' 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
this disclaimer
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
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

400def getcwd(self):
401 return _getcwd()
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
211def getcwd(self):
212 return os.getcwd()
457def getcwdu(space):
458 """Return the current working directory as a unicode string."""
459 w_filesystemencoding = getfilesystemencoding(space)
460 return space.call_method(getcwd(space), 'decode',
461 w_filesystemencoding)
571def getcwd(self):
572 """Return the current path name."""
573 return self._cached_current_dir
201def chdir(dir):
202 r = chdir_(dir)
203 check_error(r)
106def getCWD(self):
107 return self.cwd
963def os_getcwd_oofakeimpl():
964 return OOSupport.to_rstr(os.getcwd())
1959def getcwdu(self):
1960 """Return current working directory. Deprecated in Python 3."""
1961 if sys.version_info >= (3, 0):
1962 raise AttributeError('no attribute getcwdu')
1963 return unicode(self.filesystem.cwd)

Related snippets