![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Is there a way to update a variable in a module from the program that imported this module? So other programs importing this module later can also use the update.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Make the variable stored in a data file? Then the module will open the data file everytime it is loaded/called to use that variable?
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
You can use the shelve or pickle modules to maintain persistant variables. The __file__ variable contains the filepath of the currently executing module. Combine the two, and you could have something like:
import shelve import os # Open a shelve file in the same directory as the module filename = os.path.join(os.path.dirname(__file__), "data.shelf") shelf = shelve.open(filename) # Store a variable in the file: shelf["something"] = 10 # Retrieve a variable from the file: print shelf["foobar"] # Delete a variable del shelf["old"] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|