0

I'm writing a program that I would like to make a stand alone for my company. It works perfectly when I run it from the sublime text shell and I have everything set up to go except one issue that I can't seem to solve; file paths that involve usernames. Does anyone have any suggestion on how to handle this?

An example is wb.save(r'C:\Users******\Desktop\Excel.xlsx')

I want to make the ****** part either be automatic or an input box.

aaron
  • 81
  • 1
  • 8
  • https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python – NobbyNobbs Jul 31 '18 at 15:23
  • Possible duplicate of [How to get the home directory in Python?](https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python) – syntonym Jul 31 '18 at 15:28
  • Please add details of what you experience when you provide file paths with user names. – dgumo Jul 31 '18 at 15:39

3 Answers3

0

os.getlogin() will do

import os
path = os.path.join(r'C:\Users',os.getlogin(),'Desktop','Excel.xlsx')
print(path)
Ochmar
  • 284
  • 2
  • 10
0

Use os.path.expanduser() with '~' where you want the home directory:

import os
print(os.path.expanduser('~/Desktop/Excel.xlsx'))

Alternatively use pathlib.Path:

from pathlib import Path
print(Path.home() / 'Desktop' / 'Excel.xlsx')
Duncan
  • 79,697
  • 10
  • 108
  • 148
  • Thanks for the help, I posted a follow up in the answers above this. What you suggested worked really well but then another problem presented itself. – aaron Aug 02 '18 at 16:06
0

Awesome! Looks like that worked but it presented another error now when I create it as a stand alone.

Wait originally works when I run it from the shell using this code, where EC is expected conditions:

wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_name('AppBody')))   

Whenever I run it as a stand alone though I get the following error:

Traceback (most recent call last):
  File "Stand_Alone_CAS_Automation", line 57, in <module>
NameError: name 'wait' is not defined
[17344] Failed to execute script Stand_Alone_CAS_Automation
Nic3500
  • 5,007
  • 10
  • 26
  • 33
aaron
  • 81
  • 1
  • 8