Python Forum
Saving text file with a click: valueerror i/o operation on closed file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving text file with a click: valueerror i/o operation on closed file
#6
vizier87 Wrote:Though I wonder why it works if it's out of the class?
That's the way scopes work in Python, or rather namespaces. Inside a method, the names that are defined in the class are not directly available.
foo = 1  # name in the **global** namespace

class Spam:
    bar = 2  # in the namespace of the class body

    def method(self):
        qux = 3 # in the method's **local** namespace

        print(qux) # works. We see the local namespace
        print(foo) # also works. We see the global namespace
        print(bar) # doesn't work. We don't see the class' namespace
        print(self.bar) # works. We can access the class' members through the instance self.
Reply


Messages In This Thread
RE: Saving text file with a click: valueerror i/o operation on closed file - by Gribouillis - Nov-16-2020, 07:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 809 Yesterday, 05:47 AM
Last Post: Bronjer
  very newbie problem on text file zapad 2 219 Apr-12-2024, 06:50 PM
Last Post: zapad
  This result object does not return rows. It has been closed automatically dawid294 6 1,060 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  file open "file not found error" shanoger 8 1,132 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Replace a text/word in docx file using Python Devan 4 3,423 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 772 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 932 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  save values permanently in python (perhaps not in a text file)? flash77 8 1,235 Jul-07-2023, 05:44 PM
Last Post: flash77
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,110 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Read text file, modify it then write back Pavel_47 5 1,616 Feb-18-2023, 02:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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