0

I have a python file on path: ...Desktop/Python_files/python_file.py

I want to create an excel file stored on path: ...Desktop/Excel_files/exceL_file.xlsx

I want to do this using a relative path. This means that I want to step back from Python_files, go into Excel_files and create exceL_file.xlsx. The syntax below is not working for this. How should I modify it?

workbook = xlsxwriter.Workbook(' ../Excel_files/exceL_file.xlsx')

I am using python 2.7.

Filip Eriksson
  • 975
  • 7
  • 30
  • 47
  • https://stackoverflow.com/questions/918154/relative-paths-in-python Have you tried this? – Nitin Pawar Aug 28 '18 at 11:21
  • 2
    You need to tell your script what it's working directory is [link]https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory – Jamie_D Aug 28 '18 at 11:24

1 Answers1

0
import os.path

path=os.path.relpath("Your Path/Excel_files/exceL_file.xlsx")

workbook = xlsxwriter.Workbook(path)

You can use os.path to get your relative path just replace "Your Path" with your full path

Ori Arbes
  • 303
  • 3
  • 13