471,318 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Learning Basics

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.

Jul 8 '07 #1
2 878
On Jul 8, 12:10 pm, Brad <deviantbunnyl...@gmail.comwrote:
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()

Jul 8 '07 #2
On Jul 8, 12:10 pm, Brad <deviantbunnyl...@gmail.comwrote:
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

Jul 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

29 posts views Thread by Jhon smith | last post: by
90 posts views Thread by Jhon smith | last post: by
25 posts views Thread by Shawn Ferguson | last post: by
7 posts views Thread by Max | last post: by
26 posts views Thread by mfasoccer | last post: by
5 posts views Thread by Amai | last post: by
78 posts views Thread by arnuld | last post: by
7 posts views Thread by Dick Moores | last post: by
6 posts views Thread by Rui Maciel | last post: by
16 posts views Thread by John Salerno | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.