Answers for "path python"

1

PYTHON INSTALL DIR = os.path.dirname(os.path.dirname(os.__file__)) AttributeError: module 'os' has no attribute '_file_'

# Python program to explain os.path.join() method  
    
# importing os module  
import os 
  
# Path 
path = "/home"
  
# Join various path components  
print(os.path.join(path, "User/Desktop", "file.txt"))
Posted by: Guest on August-29-2020
0

python path from string

from pathlib import Path
str_path = "my_path"
path = Path(str_path)
Posted by: Guest on April-22-2020
0

pathlib path forward or back slahses

>>> import pathlib
>>> p = pathlib.PureWindowsPath(r'diranotherdirfoodirmore')
>>> print(p)    
diranotherdirfoodirmore
>>> print(p.as_posix())
/dir/anotherdir/foodir/more
>>> str(p)
'\dir\anotherdir\foodir\more'
>>> str(p.as_posix())
'/dir/anotherdir/foodir/more'
Posted by: Guest on November-09-2020
0

windows how to store filepath as variabley python

from pathlib import Path

docs_folder = Path("some_folder/some_folder/")
text_file = docs_folder / "some_file.txt"
f = open(text_file)

#note must use forward slashes as pathlib will convert these to \ for windows
Posted by: Guest on October-03-2020
0

path in python

data_folder = "source_data/text_files/"

file_to_open = data_folder + "raw_data.txt"

f = open(file_to_open)

print(f.read())
Posted by: Guest on March-27-2021
-1

what does filename = path(file).stem python

from pathlib import Path

Path('/root/dir/sub/file.ext').stem

# returns 'file'
Posted by: Guest on June-03-2020

Python Answers by Framework

Browse Popular Code Answers by Language