I'm having an issue where it seems that information in a list is not "reseting" to defaults when i believe it should be. Please help me understand what is going on
I have 2 files, the first contains the following code.
File:testing.py
import sys
import getopt
import time
import testing2
entry = ["one","two"]
for input in entry:
obj = testing2.thing(input)
print ("{0}:\n Input:{1}\n Other:{2}").format(1,obj.needed_input,obj.other_thing)
obj.change()
print ("{0}:\n Input:{1}\n Other:{2}").format(2,obj.needed_input,obj.other_thing)
print ("\n")
for input in entry:
obj = testing2.expectedthing(input)
print ("{0}:\n Input:{1}\n Other:{2}").format(1,obj.needed_input,obj.other_thing)
obj.change()
print ("{0}:\n Input:{1}\n Other:{2}").format(2,obj.needed_input,obj.other_thing)
print("\n")
for input in entry:
obj = testing2.actualthing(input)
print ("{0}:\n Input:{1}\n Other:{2}").format(1,obj.needed_input,obj.other_thing)
obj.change()
print ("{0}:\n Input:{1}\n Other:{2}").format(2,obj.needed_input,obj.other_thing)
sys.exit(1)
And the second File is as follows:
File: testing2.py
def error_die(errstring):
print('A Fatal Error has occurred: "{0}"').format(errstring)
sys.exit(0)
class thing:
def __init__(self,needed_input,other_thing="something"):
if needed_input == None:
error_die('invalid input')
self.needed_input=needed_input
self.other_thing=other_thing
def change(self):
self.other_thing="something else"
#
class expectedthing:
def __init__(self,needed_input,other_thing=["one thing","two thing"]):
if needed_input == None:
error_die('invalid input')
self.needed_input=needed_input
self.other_thing=other_thing
def change(self):
self.other_thing=["one thing","three thing"]
#
class actualthing:
def __init__(self,needed_input,other_thing=["one thing","two thing"]):
if needed_input == None:
error_die('invalid input')
self.needed_input=needed_input
self.other_thing=other_thing
def change(self):
self.other_thing.append("three thing")
self.other_thing.remove("two thing")
#
And what I'm not getting is I would expect to see the functions "actualthing" and "expectedthing" to yield the same results, however they don't.
This is what I get as a result
>python testing.py
1:
Input:one
Other:something
2:
Input:one
Other:something else
1:
Input:two
Other:something
2:
Input:two
Other:something else
1:
Input:one
Other:['one thing', 'two thing']
2:
Input:one
Other:['one thing', 'three thing']
1:
Input:two
Other:['one thing', 'two thing']
2:
Input:two
Other:['one thing', 'three thing']
1:
Input:one
Other:['one thing', 'two thing']
2:
Input:one
Other:['one thing', 'three thing']
1:
Input:two
Other:['one thing', 'three thing']
Traceback (most recent call last):
File "testing.py", line 45, in <module>
obj.change()
File "Z:\scripts\testing2.py", line 25, in change
self.other_thing.remove("two thing")
ValueError: list.remove(x): x not in list
Clearly this isn't the actual code I'm using, however it yields the same result. Due to the way I have written this script the "other_thing" may change based on the options and arguments provided by the user during script execution, So I can't just say make it equal to this. It is a list because I need to be able to change in length, anywhere from 1 item to 40 items(once again based on the user input). Any idea on how I should handle this?
Thanks for help, anything is useful.