Need help on a program.

Doug Stanfield DOUGS at oceanic.com
Wed Oct 18 17:07:31 EDT 2000


With this:

> IOError: [Errno 2] No such file or directory: 'p7.dat'

Python is telling you it can't find a file with that name.  This means the
file is either not there or its looking in the wrong place.  Assuming you've
put that file in the same place as your program, try to change the open
statement on line 37 to be (untested):

        infile = open(r"C:\Jim's Stuff\College Stuff\CS120\Python
Programs\p7.dat", "r")

That (or something like it) tells Python exactly where the file is.  At some
point you should start to look at what you have in your PATH environmental
variable and figure out where it thinks it should be looking.

-Doug-

> -----Original Message-----
> From: Captain Obvious [mailto:captainTRASHobvious at rocketTRASHmail.com]
> Sent: Wednesday, October 18, 2000 5:33 AM
> To: python-list at python.org
> Subject: Need help on a program.
> 
> 
> I am taking a Python class in college, and am stuck on a 
> program I am writing.
> 
> Here is the error I get:
> Traceback (innermost last):
>   File "<string>", line 1, in ?
>   File "C:\Jim's Stuff\College Stuff\CS120\Python 
> Programs\JRC_07.py", line 37, in ?
>     main()
>   File "C:\Jim's Stuff\College Stuff\CS120\Python 
> Programs\JRC_07.py", line 17, in main
>     infile = open("p7.dat", "r")
> IOError: [Errno 2] No such file or directory: 'p7.dat'
> 
> Here is the program I wrote:
> 
> # JRC_07.py
> # Program written by James Cory for October 18, 2000
> # This program, using p7.dat, will keep a running total of 
> heating degree days
> # and cooling degree days.  One heating degree day is added 
> for every degree the
> # temperature is over 80 degrees Fahrenheit, and one cooling 
> degree day is added
> # for every degree the temperature is below 60 degrees Fahrenheit.
> 
> def main():
>     #Greeting Section
>     print "This program, using p7.dat, will keep a running 
> total of heating degree days"
>     print "and cooling degree days.  One heating degree day 
> is added for every degree the"
>     print "temperature is over 80 degrees Fahrenheit, and one 
> cooling degree day is added"
>     print "for every degree the temperature is below 60 
> degrees Fahrenheit."
>     hdd = 0
>     cdd = 0
>     day = 0
>     infile = open("p7.dat", "r")
>     temp = eval(infile.readline())
>     while temp != "":
>         if temp > 80:
>             amount = temp-80
>             hdd=hdd+amount
>             day=day+1
>             print "Day: ", day, "Cooling Degree Days: ", cdd, 
> "Heating Degree Days: ", hdd
>         elif temp < 60:
>             amount = 60-temp
>             cdd=cdd+amount
>             day=day+1
>             print "Day: ", day, "Cooling Degree Days: ", cdd, 
> "Heating Degree Days: ", hdd
>         else:
>             day=day+1
>             print "Day: ", day, "Cooling Degree Days: ", cdd, 
> "Heating Degree Days: ", hdd
>     infile.close
>     print
>     print 
> "+------------------------------------------------------------
> ---------------+"
>     print "The final results are:" cdd, "Cooling Degree Days: 
> ", hdd, "Heating Degree Days."
> main()
> raw_input ("Press <enter> to quit")
> 
> Thanks in advance.  I can't get ahold of my professor, and am 
> really stuck.
> 
> 
> -- 
> ===
> 
> Thanks for taking the time to read my posting. 
> 
> Take out the TRASH to respond via email.
> 
> Any views expressed in this USENET posting and/or 
> attachments are not necessarily those of
> Wartburg College.
> 
> Go Knights!
> 
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list