[Tutor] Editing Pickled .dat files

ryan luna ryan_gm at sbcglobal.net
Sat Mar 4 14:28:50 CET 2006


Hey, thanks for the help but when i try i get a error
Bad file descripter, here is the code im using

elif choice == "2":
        pickle_file = open("dictionary.dat", "a")
        sentence = raw_input("Enter the word youd like
to add: ")
        if sentence not in pickle_file:
            definition = raw_input("Whats the
translated version: ")
            pickle_file[sentence] = definition
            print "\n\t'",sentence,"'", "Has been
added to the dictionary."
        else:
            print "\n\tThat term already exists!"

--- Liam Clarke <ml.cyresse at gmail.com> wrote:

> Hi Ryan,
> 
> Technically, you don't.
> 
> You haul your dictionary out, as you're doing here -
> 
> dictionary = cPickle.load(pickle_file)
> 
> And when you're finished, you pickle it again.
> 
> Regards,
> 
> Liam Clarke
> 
> On 3/5/06, ryan luna <ryan_gm at sbcglobal.net> wrote:
> > Hello, this is like my 3rd question today lol
> which is
> > making up for not asking any for months =P,
> anyways
> > I have a pickled .dat file named dictionary, maybe
> > youv guessed this but its a dictionary of the
> > Alphabet, the program is a translator right now
> all it
> > does is translate the Alpabet (its a stupid made
> up
> > language helping someone out cuz i needed a
> project)
> > anyways im pretty sure i have the reading the
> pickled
> > file, taking input from the user, looking on the
> word
> > in the .dat file and printing out the translation,
> > Here is where im stuck.
> > I want the program to be able to translate full
> words
> > to (the only way i know to do that is to put every
> > word in the dictionary, aka .dat file)
> > im not goin to put all the english words and there
> > translation in there myself! so i have a option
> for
> > the user to put there own definitions,
> > What i need to know is how do i take input from
> the
> > user, collect the word and its definitions and
> then
> > pickle it into the .dat but editing the dictionary
> in
> > the .dat file.
> > heres my code for reading so you get a better idea
> of
> > what i mean
> >
> > pickle_file = open("dictionary.dat", "r")
> >         dictionary = cPickle.load(pickle_file)
> >         while sentence != "0":
> >             sentence = raw_input("\nInput a
> english
> > letter/word to be translated: ")
> >             if sentence in dictionary:
> >                 definition = dictionary[sentence]
> >                 print "\n", definition
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 



More information about the Tutor mailing list