Python Forum
Getting a "Cannot be Opened"" error Message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a "Cannot be Opened"" error Message
#1
Hi Folks,
I'm having a "Cannot opened" error message even though i have the file in my directory. below is my code which consist of reading a file and determining the average game won.


Quote:
#! /usr/bin/python3
def team_average(filename):
        numberOfGames = 0
        soxWins = 0
        try:
                file = open(filename, 'r')
                for line in file:
                        numberOfGames += 1
                        game = line.split()
                        scores = game[1]
                        scores_list = scores.split('-')
                        for score in scores_list:
                                if int(score[0]) - int(score[1]) > 0:
                                        soxWins += 1
                average_win = int(s0xWins/numberOfGames) * 100
        except:
                print (filename, "Cannot be opened")

team_average('xxxxx')
print(team_average('red_sox.txt'))
Quote:# This is my output (which is not what i was expecting )

xxxxx Cannot be opened
red_sox.txt Cannot be opened
None


Please what did i get wrong ?
Best,
valerydolce

Below is the content of the "red_sox.txt" file

2011-07-02      Red Sox @  Astros       Win 7-5
2011-07-03      Red Sox @  Astros       Win 2-1
2011-07-04      Red Sox vs Blue Jays    Loss 7-9
2011-07-05      Red Sox vs Blue Jays    Win 3-2
2011-07-06      Red Sox vs Blue Jays    Win 6-4
2011-07-07      Red Sox vs Orioles      Win 10-4
2011-07-08      Red Sox vs Orioles      Win 10-3
2011-07-09      Red Sox vs Orioles      Win 4-0
2011-07-10      Red Sox vs Orioles      Win 8-6
2011-07-15      Red Sox @  Rays         Loss 6-9
2011-07-16      Red Sox @  Rays         Win 9-5
2011-07-17      Red Sox @  Rays         Win 1-0
2011-07-18      Red Sox @  Orioles      Win 15-10
2011-07-19      Red Sox @  Orioles      Loss 2-6
2011-07-20      Red Sox @  Orioles      Win 4-0
2011-07-22      Red Sox vs Mariners     Win 7-4
2011-07-23      Red Sox vs Mariners     Win 3-1
2011-07-24      Red Sox vs Mariners     Win 12-8
2011-07-25      Red Sox vs Royals       Loss 1-3
2011-07-26      Red Sox vs Royals       Win 13-9
2011-07-27      Red Sox vs Royals       Win 12-5
2011-07-28      Red Sox vs Royals       Loss 3-4
2011-07-29      Red Sox @  White Sox    Loss 1-3
2011-07-30      Red Sox @  White Sox    Win 10-2
2011-07-31      Red Sox @  White Sox    Win 5-3
Reply


Messages In This Thread
Getting a "Cannot be Opened"" error Message - by valerydolce - Feb-09-2017, 11:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 1,118 Aug-17-2023, 07:53 PM
Last Post: Visiting
  does not save in other path than opened files before icode 3 1,047 Jun-23-2023, 07:25 PM
Last Post: snippsat
  Another Error message. the_jl_zone 2 1,040 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,597 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question How to get html information from a tab of my default browser opened with webbrowser? noahverner1995 2 4,693 Jan-14-2022, 10:02 AM
Last Post: noahverner1995
  understanding error message krlosbatist 1 1,968 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Error message pybits 1 51,235 May-29-2021, 10:26 AM
Last Post: snippsat
  Rmarkdown opened by python code - errors Rav013 0 2,156 Apr-27-2021, 03:13 PM
Last Post: Rav013
  f-string error message not understood Skaperen 4 3,454 Mar-16-2021, 07:59 PM
Last Post: Skaperen
  Overwhelmed with error message using pandas drop() EmmaRaponi 1 2,452 Feb-18-2021, 07:31 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020