Questions tagged [expanduser]

7 questions
59
votes
3 answers

How do I use '~' (tilde) in the context of paths?

To fix a problem in code for work, I was told to "use a path relative to ~". What does ~ mean in a file path? How can I make a path that is relative to ~, and use that path to open files in Python?
captcadaver
  • 1,093
  • 2
  • 9
  • 7
1
vote
1 answer

os.path.join seems sensitive to opening slash, why?

Adding a slash to Documents in os.join produces different results when I think it should not. Why? Just trying to write code that does reasonable things for multiple users. import os # Initialize output files and folders, following principle of…
1
vote
2 answers

Automatic transfer files to folder (OpenCV)

First, here is the code I have: import cv2 import os,errno from os.path import expanduser from datetime import datetime import glob import numpy as np ##################### Creating folder & subfolders ##################### b_temp_folder =…
BlueTrack
  • 442
  • 3
  • 7
  • 19
0
votes
0 answers

Using blockchain_parser to parse blk files stored on S3

I'm trying to use alecalve's bitcoin-parser pkg for python. The problem is, my node is saved on an s3 bucket. As the parser uses os.path.expanduser for the .dat files dir, expecting a filesystem, I can't just use my s3 path. The example from the…
Tero
  • 31
  • 1
  • 3
0
votes
0 answers

Expand user for paths in argparse arguments

I'd like to allow the user of my program to use the "~" shortcut in the arguments that are paths to some files, i.e., the "home" shortcut for linux systems. But to do so, as far as I understand, I need to all the os.path.expanduser function over…
rgalhama
  • 314
  • 1
  • 4
  • 14
0
votes
1 answer

Error when verifying folder creation (Python)

I am stuck in an "error" during my folder creation. First of all, this is the code I am using: import os import errno import subprocess try: folder = os.makedirs(os.path.expanduser('~\\Desktop\\FOLDER')) except OSError as e: if e.errno !=…
lucians
  • 2,239
  • 5
  • 36
  • 64
0
votes
1 answer

Would os.path.expanduser('~/') return no directory?

From How to get the home directory in Python? and How to find the real user home directory using python?, it's possible to find the user's home directory with: import os os.path.expanduser('~/') But would there be a chance that os.path.expanduser()…
alvas
  • 115,346
  • 109
  • 446
  • 738