Skip to main content
added 63 characters in body
Source Link
Tomerikoo
  • 19.6k
  • 16
  • 57
  • 68

Try the pathlibpathlib package instead:

  >>> from pathlib import Path >>> Path() WindowsPath('.') >>> Path().absolute() WindowsPath('C:/Users/p00200284/test') >>> Path().absolute().parent WindowsPath('C:/Users/p00200284') >>> Path().absolute().parent / "all_files.tex" WindowsPath('C:/Users/p00200284/all_files.tex') >>> str(Path().absolute().parent / "all_files.tex") 'C:\\Users\\p00200284\\all_files.tex' >>> Path().absolute().parent.name 'p00200284' >>> f"{Path().absolute().parent.name}_all_files.tex" 'p00200284_all_files.tex' >>> parent_dir = Path().absolute().parent >>> parent_dir / f"{Path().absolute().parent.name}_all_files.tex" WindowsPath('C:/Users/p00200284/p00200284_all_files.tex') 

Try the pathlib package instead

  >>> from pathlib import Path >>> Path() WindowsPath('.') >>> Path().absolute() WindowsPath('C:/Users/p00200284/test') >>> Path().absolute().parent WindowsPath('C:/Users/p00200284') >>> Path().absolute().parent / "all_files.tex" WindowsPath('C:/Users/p00200284/all_files.tex') >>> str(Path().absolute().parent / "all_files.tex") 'C:\\Users\\p00200284\\all_files.tex' >>> Path().absolute().parent.name 'p00200284' >>> f"{Path().absolute().parent.name}_all_files.tex" 'p00200284_all_files.tex' >>> parent_dir = Path().absolute().parent >>> parent_dir / f"{Path().absolute().parent.name}_all_files.tex" WindowsPath('C:/Users/p00200284/p00200284_all_files.tex') 

Try the pathlib package instead:

>>> from pathlib import Path >>> Path() WindowsPath('.') >>> Path().absolute() WindowsPath('C:/Users/p00200284/test') >>> Path().absolute().parent WindowsPath('C:/Users/p00200284') >>> Path().absolute().parent / "all_files.tex" WindowsPath('C:/Users/p00200284/all_files.tex') >>> str(Path().absolute().parent / "all_files.tex") 'C:\\Users\\p00200284\\all_files.tex' >>> Path().absolute().parent.name 'p00200284' >>> f"{Path().absolute().parent.name}_all_files.tex" 'p00200284_all_files.tex' >>> parent_dir = Path().absolute().parent >>> parent_dir / f"{Path().absolute().parent.name}_all_files.tex" WindowsPath('C:/Users/p00200284/p00200284_all_files.tex') 
Source Link
abhilb
  • 5.8k
  • 2
  • 22
  • 26

Try the pathlib package instead

 >>> from pathlib import Path >>> Path() WindowsPath('.') >>> Path().absolute() WindowsPath('C:/Users/p00200284/test') >>> Path().absolute().parent WindowsPath('C:/Users/p00200284') >>> Path().absolute().parent / "all_files.tex" WindowsPath('C:/Users/p00200284/all_files.tex') >>> str(Path().absolute().parent / "all_files.tex") 'C:\\Users\\p00200284\\all_files.tex' >>> Path().absolute().parent.name 'p00200284' >>> f"{Path().absolute().parent.name}_all_files.tex" 'p00200284_all_files.tex' >>> parent_dir = Path().absolute().parent >>> parent_dir / f"{Path().absolute().parent.name}_all_files.tex" WindowsPath('C:/Users/p00200284/p00200284_all_files.tex')