hi again i help with my carnival clubs fundraising and being lazy like i am, i wanted to make a program that would tell you how much to ask for after inputting information and would then save it into a text file.
using griboullis' help from my other thread about cPickle i have managed to complete that but firstly i can only use the data until i open the program again

i will add the code when i get home as i am in school at the moment :)

sorry i couldn't i post the code in the other post but here is the code

from pprint import pprint
TXTFILE = "takings.txt"

def dump_takings(takings):
  fout = open(TXTFILE, "rw")
  pprint(takings, fout)

def load_takings():
  fin = open(TXTFILE, "rw")
  dic = eval(fin.read())
  return dic

def user_interaction(takings):

  running = 1
  n = 1
  T = float(raw_input("what is the price of the item in pence?"))
  while running == 1:
      A = float(raw_input("How may tickets does the customer want?"))
      ta = T*A
      takings[n] = ta
      TC = T*A #Ticket price times ammt of tickets wanted
      TCG = TC/100 #Same as above but divided by 100
      if TC >= 100.0:
          print "Ask for ",TCG,"pounds"
          print "Ask for ",TC,"P"
          takings[n] = TC

      c = float(raw_input("What did they pay with?(use 1.00, 2.00)"))

      ch = c-TCG

      chp = c-TC/100
      if c < 1.00:
          print "Give ",chp,"P change"
          print "Give £",ch," change"
      takings[n] = TC
      n = n+1
      running = float(raw_input('press 1 to stay'))

def main():
  takings = load_takings()

it also has a txt file called takings.txt with the {} things in it

thanks in advance

yeah thanks that was when i was trying different things but ill try the r and w when i get home

A problem with your program is that each time you restart the program, it will overwrite takings[1], takings[2], etc . So you should consider replacing the line n=1 by n = 1 + len(takings) .

I also suggest that you modify load_takings so that you don't have to create the txt file manually the first time, like this:

import os.path

def load_takings():
    if not os.path.exists(TXTFILE):
    fin = open(TXTFILE, "r")
    dic = eval(fin.read())
    return dic
This question has already been answered. Start a new discussion instead.