what am I doing wrong

I have a theory (that I have totally misinterpreted the nature of names).

But my theory doesn’t really give me an idea how to proceed so…

NameError: name ‘mytask’ is not defined <----this is the error I am getting.

I am setting the name of the task when an instance is created:

class Task(object):
        Count = 0
        def __init__(self):
                 self.id = Task.Count
                 Task.Count += 1
                 self.name = input("Enter task name: ")

it prompts me as it says but then what I enter is rejected with the above error (where ‘mytask’ is what I typed).

further down however what seems to me to be basically the same thing seems to work fine:

class Schedule(object):
         def __init__(self):
                 now = datetime.datetime.now()
                 self.name = current.name + now.strftime("%Y-%m-%d")

  1. clicking modify causes a thing saying “loading…” to just sit there for ages.

  2. raw_input works fine, nothing to see here, move along :stuck_out_tongue:

Ok, your code maybe is a little confusing at first sight;

This is defining a class …

class Task(object):

This is setting a property of the class called ‘Count’ to zero.

Count = 0

This is generating a property on the fly called ‘id’ and setting it to a component of the class. Not something I would do, but I guess that Task.Count would effectively be a global variable - not sure if this is what you intended? Either way it’s a novel way of handling globals, not sure it’s something I’d recommend from a readability point of view. Also, why are you using class Task(object): rather than class Task: ??

self.id = Task.Count

You will find that if you replace the input line with;

x=input(">") self.name=x

It works for you, also if you enter your value in quotes, it will also work.

Take a look at the documentation for input vs raw_input, if you use raw_input, this will work fine for you … but with input it’s trying to evaluate your input as a python expression and failing.

someone else told me that if something doesn’t have another parent you should make object it’s parent.

As for the count thing, that’s just so that I can tell that the id of the thing is the same as the number in the array that that task is.

(tasks[0] will have the task.id 0)

But I am open to other ideas.

The point of this if for me to get my head round this classes thing anyway :stuck_out_tongue:

someone else told me that if something doesn't have another parent you should make object it's parent.

Erm, what does this mean?

As for the count thing ...

Well you could use globals, or you could use a settings class … globals would be more efficient, settings class more readable / safer …

class SettingsClass: Count = 0 def next_free_id(self): self.Count += 1 return self.Count

settings = SettingsClass()

self.id = settings.next_free_id()

Classes are essentially there to aid in encapsulation and readability (and hence reliability/robustness) , if you find yourself putting something together that looks odd or is difficult to immediately see what’s going in, you’re doing it wrong … :wink: