working with classes, inheritance, _str_ returns and a list

2017-01-15 Thread David D
I am creating a parent class and a child class.  I am inheriting from the 
parent with an additional attribute in the child class.  I am using __str__ to 
return the information.  When I run the code, it does exactly what I want, it 
returns the __str__ information.  This all works great. 

BUT

1) I want what is returned to be appended to a list (the list will be my 
database)
2) I append the information to the list that I created
3) Whenever I print the list, I get a memory location

So how do I take the information that is coming out of the child class (as a 
__str__ string), and keep it as a string so I can append it to the list?

pseudo code

allcars=[]

parent class()
   def init (self, model, wheels, doors)
  self.model= model etc

child class (parent)
   def init(self, model, wheels, doors, convertible)
   super(child, self).__init__(model, wheels, doors)
   self.convertible = convertible

   def __str__(self):
return "model: " + self.model + etc

car1= child(model, wheels, doors, convertible)
print car1



Here is where it goes wrong for me


allcars.append(car1)

I am sure I am making a silly mistake in here somewhere...





-- 
https://mail.python.org/mailman/listinfo/python-list


Multi-threading with a simple timer?

2018-07-02 Thread David D
Is there a SIMPLE method that I can have a TIMER count down at a user input 
prompt - if the user doesn't enter information within a 15 second period, it 
times out.  I am going to be using pycharm and not the shell.  Thanks in 
advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multi-threading with a simple timer?

2018-07-03 Thread David D
This works, but does not do exactly what I want. What I want to happen is : 
when the user enters in a correct answer, the program and threading stops.  Any 
ideas on what I should change? 

import time 
from threading import Thread 

class Answer(Thread): 
def run(self): 
a=input("What is your answer:") 
if a=="yes": 
print("yes you got it") 
finished() 
else: 
print("no") 

class myTimer(Thread): 
def run(self): 
print() 
for x in range(5): 

time.sleep(1) 

Answer().start() 
myTimer().start() 
print("you lost") 

def finished(): 
print("done")

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multi-threading with a simple timer?

2018-07-03 Thread David D
This works, but does not do exactly what I want. When the user enters in a 
correct answer, the program and threading stops.  Any ideas on what I should 
change?

import time
from threading import Thread

class Answer(Thread):
def run(self):
a=input("What is your answer:")
if a=="yes":
print("yes you got it")
finished()
else:
print("no")

class myTimer(Thread):
def run(self):
print()
for x in range(5):

time.sleep(1)

Answer().start()
myTimer().start()
print("you lost")

def finished():
print("done")

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multi-threading with a simple timer?

2018-07-03 Thread David D
I have some success with this.  I am not sure if this would work longer term, 
as in restarting it, but so far so good.  Any issue with this new code?

import time
from threading import Thread

th=Thread()
class Answer(Thread):
def run(self):
a=input("What is your answer:")
if a=="yes":
print("yes you got it")
th.daemon=False
else:
print("no")

class myTimer(Thread):
def run(self):
print()

for x in range(5):
if th.daemon==True:
print(x)
time.sleep(1)
else:
break

th.daemon=True

Answer().start()
myTimer().start()


def finished():
print("done")

-- 
https://mail.python.org/mailman/listinfo/python-list


Working with dictionaries and keys help please!

2017-05-31 Thread David D
I have a dictionary with a 10 people, the key being a number (0-10) and the 
value being the people's name.  I am in the processing of Insert, Adding and 
deleting from the dictionary.  All seems well until I delete a person and add a 
new one.  The numbers (keys) do not change and so I am getting an 
non-sequential set of numbers for the keys.  Is there a way of performing this 
where the key will update so that is continues to work sequentially?  Here is 
what I mean

Print dictionary
{0 John, 1 David, 2 Phil, 3 Bob}

remove 1 David
{0 John, 2 Phil, 3 Bob}

How can I get it so that the VALUE will reset and it will look like this after 
both adding or deleting?

{0 John, 1 Phil, 2 Bob}

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Working with dictionaries and keys help please!

2017-05-31 Thread David D
Learning about dictionaries for a database possibly in the future.

On Wednesday, May 31, 2017 at 8:58:39 PM UTC-4, MRAB wrote:
> On 2017-06-01 01:29, David D wrote:
> > I have a dictionary with a 10 people, the key being a number (0-10) and the 
> > value being the people's name.  I am in the processing of Insert, Adding 
> > and deleting from the dictionary.  All seems well until I delete a person 
> > and add a new one.  The numbers (keys) do not change and so I am getting an 
> > non-sequential set of numbers for the keys.  Is there a way of performing 
> > this where the key will update so that is continues to work sequentially?  
> > Here is what I mean
> > 
> > Print dictionary
> > {0 John, 1 David, 2 Phil, 3 Bob}
> > 
> > remove 1 David
> > {0 John, 2 Phil, 3 Bob}
> > 
> > How can I get it so that the VALUE will reset and it will look like this 
> > after both adding or deleting?
> > 
> > {0 John, 1 Phil, 2 Bob}
> > 
> Why are you using a dictionary instead of a list?

-- 
https://mail.python.org/mailman/listinfo/python-list