Learning Basics

B

Brad

So I've been studying python for a few months (it is my first foray
into computer programming) and decided to write my own little simple
journaling program. It's all pretty basic stuff but I decided that I'd
learn more from it if more experienced programmers could offer some
thoughts on how I could do things better.

#simple little journal

from time import asctime
myjournal=file('journal.txt','a+')

formatter="*"*80+"\n"
todaysdate=asctime()
myjournal.write(formatter)
myjournal.write(todaysdate + "\n\n")

loop="set"

while loop!=':a':
loop=raw_input(':')
if loop!=':a':
myjournal.write(loop+"\n")
if loopz==':a':
myjournal.close()

#end of stuff

So I'd appreciate some good feedback or ideas.
 
D

Dan Bishop

So I've been studying python for a few months (it is my first foray
into computer programming) and decided to write my own little simple
journaling program. It's all pretty basic stuff but I decided that I'd
learn more from it if more experienced programmers could offer some
thoughts on how I could do things better.

#simple little journal

from time import asctime
myjournal=file('journal.txt','a+')

formatter="*"*80+"\n"
todaysdate=asctime()
myjournal.write(formatter)
myjournal.write(todaysdate + "\n\n")

loop="set"

while loop!=':a':
loop=raw_input(':')
if loop!=':a':
myjournal.write(loop+"\n")
if loopz==':a':
myjournal.close()

#end of stuff

So I'd appreciate some good feedback or ideas.

#!/usr/bin/env python

"""simple little journal"""

import sys
import time

EXIT_COMMAND = ':a'
HEADER = "*" * 80

def add_journal_entry(filename='journal.txt'):
"""
Prompt the user to enter text, and write it into the journal file.
"""
print "Enter your journal entry."
print "When done, type %r." % EXIT_COMMAND
journal_file = file(filename, 'a+')
journal_file.write(HEADER + "\n")
journal_file.write(time.asctime() + "\n\n")
while True:
line = raw_input(':')
if line == EXIT_COMMAND:
break
journal_file.write(line + "\n")
journal_file.close()

def _main(argv=None):
"""Executed when file is run as a script."""
if argv is None:
argv = sys.argv
if len(argv) == 1: # No filename specified; use the default
add_journal_entry()
else:
add_journal_entry(argv[1])

if __name__ == '__main__':
_main()
 
B

BartlebyScrivener

So I'd appreciate some good feedback or ideas.

I addition to Dan's suggestions, you could add a Tk text entry box to
make it easier to enter text.

I can send you some code if you'd like, as Steve Holden just
generously helped me make a text entry box for my quote database. Or
you can make your own starting here:

Alan Gauld's "GUI Programming with Tkinter"
http://www.freenetpages.co.uk/hp/alan.gauld/tutgui.htm

These also came in very handy for cutting and pasting.

Jeff Eppler's clp post - 3 August 2005
cut and paste text between Tkinter widgets"
http://tinyurl.com/2d97gj

rd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top