Tiffany M.

asked • 06/21/15

Hello, I am trying to open a file in read mode using Python.

The error I am receiving suggest I am using the wrong filename or read mode. When I type the file path into my computer, it works. I tried to assign the input filename to a variable and then opening the variable in read mode. I also tried typing in the full path and opening the path in read mode. Both gave me an error. Error for opening variable:IOError: [Errno 2] No such file or directory: 'full_original'. Error for opening full path, [Errno 22] invalid mode ('r') or filename
Current code  attempting to open and read original file:
import os
def main():
    "houses main structure of program "
def information(filenames):
    "houses all neseccary files "
workingDirec = raw_input("What is the working directory?")
original_file = raw_input("The input filename is?")
chi_square = raw_input("The name of the chi-squared stats table file is?")
out_file = raw_input ("What is the output filename?")

def calculateZscore():
    "Z score calc"
full_original = os.path.join(workingDirec,original_file)
print full_original

f = open ('C:\Users\tpmorris\ProgramingAndScripting\Lab 2 Data\Lab 2 Data\NCSIDS_ObsExp.txt','r')
print f

3 Answers By Expert Tutors


Matthew B. answered • 03/16/20

5.0 (62)

Founder, CEO, and Lead Developer: Apteryx Labs | Stanford, 2015

James G. answered • 07/28/17

4.9 (85)


Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.