Newbie programmer needs a little help

Volucris volucris at hotmail.com
Thu Apr 19 22:07:06 EDT 2001


> from sys import *

First off I don't see anything here that uses sys. Did you just leave that
stuff out of the post?

> print
> print "Welcome to the LARP character program"
> print
> filename = raw_input("Please enter a path/filename: ")
> filename = open

open is a function, so this just makes filename a 'shortcut'(longcut, I
suppose) to the function. Like instedd of:
>>>g = open('spam')
you could now have:
>>>g = filename('spam')
It doesn't really accomplish much here, you could leave it out.

> print "Following are several character options"
> playername = raw_input("What is your name? ")
> charname = raw_input("Enter your character name: ")
> nature = raw_input("What is the nature of your
> character? ")
> demeanor = raw_input("What is your demeanor? ")
> info = [playername, charname, nature, demeanor]
> print info
>
> file = open(filename, list[0:3] "r")

This one is close. it's open(filename, mode). Then you need to write the
info and close the file. So this is what I've got:

print
print "Welcome to the LARP character program"
print

filename = raw_input("Please enter a path/filename: ")

#get all of the player's info
print "Following are several character options"
playername = raw_input("What is your name? ")
charname = raw_input("Enter your character name: ")
nature = raw_input("What is the nature of your character? ")
demeanor = raw_input("What is your demeanor? ")

#and write it to a text file
file = open(filename, 'w')
file.writeln('player=' + playername)
file.writeln('character=' + charname)
file.writeln('nature=' + nature)
file.writeln('demeanor=' + demeanor)
file.close()

It should give you a file like this:

player=greg
character=Bobo the Flying Circus Monkey
nature=nasty
demeanor=spastic


Cool? Hope so.
greg





More information about the Python-list mailing list