On 26/9/2013 07:29, Rafael Knuth wrote:
   <snip>
>  Can you advise how I should proceed in order to
> improve my To Do List program based on the code I wrote so far
> (insofar it's usable at all) ..? Weirdly, writing and reading to files
> is not covered in those tutorials I am working with.
>
>>
>>> print("This is my to do list")
>>>
>>> Monday = input("Monday ")
>>> Tuesday = input("Tuesday ")
>>> Wednesday = input("Wednesday ")
>>> Thursday = input("Thursday ")
>>> Friday = input("Friday ")
>>> Saturday = input("Saturday ")
>>> Sunday = input("Sunday ")
>>>
>>> print("So, here are your plans for:" +
>>> "\nMonday " + Monday +
>>> "\nTuesday " + Tuesday +
>>> "\nWednesday " + Wednesday +
>>> "\nThursday " + Thursday +
>>> "\nFriday " + Friday +
>>> "\nSaturday " + Saturday +
>>> "\nSunday " + Sunday)
>>

First comment:  learn to use functions.  Don't put anything in top-level
code except:
     imports
     global constant values, in all uppercase NAMES
     the canonical
             if  __name__ == "__main__":
                    main()

Later, with more experience, you'll find times to make exceptions to
that rule.

Your functions should usually take paramaters and return their results.
Avoid writable global values.  If you need to return more than one
results, learn to use tuples for that, with automatic tuple unpacking
where appropriate.

Next, look for places where you do practically the same thing many
times.  They are a good candidate for factoring into a loop, or a loop
calling a common function.

Next, look for data structures that can naturally describe the data
you're manipulating.  For example, instead of the variables "Monday",
"Tuesday", etc, you could make a dict where those are the keys, and the
"todo items" are the values.

Once you're used to writing (small) functions, figure on separating
input, output, and data manipulation into three (usually) functions. 
For example, you'll be filling in those values from the user, and also
from an input file.  You'll be saving the results to the screen, and
also to an output file.

Now, consider the user and what he'll want to do.  He may not know all 7
days items at the same time, or he may be entering Friday's value, and
suddenly remember a change needed on Tuesday's.  So give him a way to
tell-the-program what he wants to do next.

In my earlier message, I mentioned the standard module configparser. 
That's because it's similar to a dictionary. And also because it can
be readily understood and edited with a text editor.  It's not the most
commonly used tool for the purpose, but it'd suit your present needs
pretty well, and be easy to experiment.  My reason is the next comment.

Try to write functions that can be tested independently.  So if you're
saving and reloading data, if you can manually create the data
(file) easily, then you can test your "reloading" function independently
of the "saving" function.


-- 
DaveA


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to