Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Using cPickle

Reply
Thread Tools

Using cPickle

 
 
mmcclaf
Guest
Posts: n/a
 
      02-06-2009
Hi there,

I have to make a small database using cPickle. I'm having troubles
trying to read in the information if it's more than one line. I'm
pretty sure it's in the line "for line in stuff:" Can anyone help me
out? Basically the end result is wanting it to look something like
what is down below when list is typed in:

Last name First Name Email Address
Doe John



Code:
# @author: Ocdt Murray McClafferty 24656
# This will manage a small database using the cPickle module.
# It must maintain a list of last names, first names and email
addresses, and must let a user interact with the program

#
#!usr/bin/python
# -*- coding: utf-8 -*-

import sys
import cPickle

#
format = '%s             %s                  %s'

try:
	filename = sys.argv[1]
	input = open(filename, 'r')

except IOError:
	print 'File is not available, will create a new file now'
	lastName='Last Name'
	firstName='First Name'
	email= 'Email'
	#input.close()
	output=open (filename, 'w')
	total = format%(lastName, firstName, email)
	cPickle.dump(total,output)
	#cPickle.dump(firstName,output)
	#cPickle.dump(email,output)
	output.close()
except EOFError:
	print 'File is empty'

#datas = cPickle.load(input)

while True:
	command=sys.stdin.readline()[:-1]
	if command=='list': #lists the data in the file
		input = open(filename, 'r')
		stuff=cPickle.load(input)
		for line in stuff:
			#firstName=cPickle.load(input)
			#email=cPickle.load(input)
			#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
(email).rjust(20)
			stuff=cPickle.load(input)
			print stuff
			print line

		input.close()

	if command=='exit' or command=='quit' : #NEVER forget the exit!!!
		print 'Save changes? y for Yes, n for No'
		commandSave=sys.stdin.readline()[:-1]
		if commandSave =='y': #if the user wants to save
			output=open(filename, 'w')
			cPickle.dump(work,output)
			output.close()
			sys.exit(0)
		if commandSave =='n': #no save
			input.close()
			sys.exit(0)

	if command=='add': #adds an entity to the file
		print 'Last name?'
		lastName=sys.stdin.readline()[:-1]
		print 'First name?'
		firstName=sys.stdin.readline()[:-1]
		print 'Email address?'
		email=sys.stdin.readline()[:-1]
		work = format%(lastName, firstName, email)
		#output=open(filename, 'w')
		#data=cPickle.load(output)
		#data.append(work)
		#output.close()
		output=open(filename, 'a')
		cPickle.dump(work,output)
		output.close()
All help would be appreciated. I am new to Python and this seems to be
quite a challenge for me.
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      02-06-2009
mmcclaf wrote:
> Hi there,
>
> I have to make a small database using cPickle. I'm having troubles
> trying to read in the information if it's more than one line. I'm
> pretty sure it's in the line "for line in stuff:" Can anyone help me
> out? Basically the end result is wanting it to look something like
> what is down below when list is typed in:
>
> Last name First Name Email Address
> Doe John
>
>
>
>
Code:
> # @author: Ocdt Murray McClafferty 24656
> # This will manage a small database using the cPickle module.
> # It must maintain a list of last names, first names and email
> addresses, and must let a user interact with the program
> 
> #
> #!usr/bin/python
> # -*- coding: utf-8 -*-
> 
> import sys
> import cPickle
> 
> #
> format = '%s             %s                  %s'
> 
> try:
> 	filename = sys.argv[1]
> 	input = open(filename, 'r')
> 
> except IOError:
> 	print 'File is not available, will create a new file now'
> 	lastName='Last Name'
> 	firstName='First Name'
> 	email= 'Email'
> 	#input.close()
> 	output=open (filename, 'w')
> 	total = format%(lastName, firstName, email)
> 	cPickle.dump(total,output)
> 	#cPickle.dump(firstName,output)
> 	#cPickle.dump(email,output)
> 	output.close()
> except EOFError:
> 	print 'File is empty'
> 
> #datas = cPickle.load(input)
> 
> while True:
> 	command=sys.stdin.readline()[:-1]
> 	if command=='list': #lists the data in the file
> 		input = open(filename, 'r')
> 		stuff=cPickle.load(input)
> 		for line in stuff:
> 			#firstName=cPickle.load(input)
> 			#email=cPickle.load(input)
> 			#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
> (email).rjust(20)
> 			stuff=cPickle.load(input)
> 			print stuff
> 			print line
> 
> 		input.close()
> 
> 	if command=='exit' or command=='quit' : #NEVER forget the exit!!!
> 		print 'Save changes? y for Yes, n for No'
> 		commandSave=sys.stdin.readline()[:-1]
> 		if commandSave =='y': #if the user wants to save
> 			output=open(filename, 'w')
> 			cPickle.dump(work,output)
> 			output.close()
> 			sys.exit(0)
> 		if commandSave =='n': #no save
> 			input.close()
> 			sys.exit(0)
> 
> 	if command=='add': #adds an entity to the file
> 		print 'Last name?'
> 		lastName=sys.stdin.readline()[:-1]
> 		print 'First name?'
> 		firstName=sys.stdin.readline()[:-1]
> 		print 'Email address?'
> 		email=sys.stdin.readline()[:-1]
> 		work = format%(lastName, firstName, email)
> 		#output=open(filename, 'w')
> 		#data=cPickle.load(output)
> 		#data.append(work)
> 		#output.close()
> 		output=open(filename, 'a')
> 		cPickle.dump(work,output)
> 		output.close()
> 
>
>
> All help would be appreciated. I am new to Python and this seems to be
> quite a challenge for me.


Make sure you use modes "rb" and "wb" when you open the pickle files. If
you are running on Windows this can make a difference.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

 
Reply With Quote
 
 
 
 
mmcclaf
Guest
Posts: n/a
 
      02-06-2009
On Feb 6, 10:25*am, Steve Holden <st...@holdenweb.com> wrote:
> mmcclaf wrote:
> > Hi there,

>
> > I have to make a small database using cPickle. I'm having troubles
> > trying to read in the information if it's more than one line. I'm
> > pretty sure it's in the line "for line in stuff:" Can anyone help me
> > out? Basically the end result is wanting it to look something like
> > what is down below when list is typed in:

>
> > Last name * * * * * * * * First Name * * * * * * * *Email Address
> > Doe * * * * * * * * * * * * *John
> > j...@doe.com

>
> >
Code:
> > # @author: Ocdt Murray McClafferty 24656
> > # This will manage a small database using the cPickle module.
> > # It must maintain a list of last names, first names and email
> > addresses, and must let a user interact with the program
Code:
>
> > #
> > #!usr/bin/python
> > # -*- coding: utf-8 -*-
>
> > import sys
> > import cPickle
>
> > #
> > format = '%s * * * * * * %s * * * * * * * * *%s'
>
> > try:
> > * *filename = sys.argv[1]
> > * *input = open(filename, 'r')
>
> > except IOError:
> > * *print 'File is not available, will create a new file now'
> > * *lastName='Last Name'
> > * *firstName='First Name'
> > * *email= 'Email'
> > * *#input.close()
> > * *output=open (filename, 'w')
> > * *total = format%(lastName, firstName, email)
> > * *cPickle.dump(total,output)
> > * *#cPickle.dump(firstName,output)
> > * *#cPickle.dump(email,output)
> > * *output.close()
> > except EOFError:
> > * *print 'File is empty'
>
> > #datas = cPickle.load(input)
>
> > while True:
> > * *command=sys.stdin.readline()[:-1]
> > * *if command=='list': #lists the data in the file
> > * * * * * *input = open(filename, 'r')
> > * * * * * *stuff=cPickle.load(input)
> > * * * * * *for line in stuff:
> > * * * * * * * * * *#firstName=cPickle.load(input)
> > * * * * * * * * * *#email=cPickle.load(input)
> > * * * * * * * * * *#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
> > (email).rjust(20)
> > * * * * * * * * * *stuff=cPickle.load(input)
> > * * * * * * * * * *print stuff
> > * * * * * * * * * *print line
>
> > * * * * * *input.close()
>
> > * *if command=='exit' or command=='quit' : #NEVER forget the exit!!!
> > * * * * * *print 'Save changes? y for Yes, n for No'
> > * * * * * *commandSave=sys.stdin.readline()[:-1]
> > * * * * * *if commandSave =='y': #if the user wants to save
> > * * * * * * * * * *output=open(filename, 'w')
> > * * * * * * * * * *cPickle.dump(work,output)
> > * * * * * * * * * *output.close()
> > * * * * * * * * * *sys.exit(0)
> > * * * * * *if commandSave =='n': #no save
> > * * * * * * * * * *input.close()
> > * * * * * * * * * *sys.exit(0)
>
> > * *if command=='add': #adds an entity to the file
> > * * * * * *print 'Last name?'
> > * * * * * *lastName=sys.stdin.readline()[:-1]
> > * * * * * *print 'First name?'
> > * * * * * *firstName=sys.stdin.readline()[:-1]
> > * * * * * *print 'Email address?'
> > * * * * * *email=sys.stdin.readline()[:-1]
> > * * * * * *work = format%(lastName, firstName, email)
> > * * * * * *#output=open(filename, 'w')
> > * * * * * *#data=cPickle.load(output)
> > * * * * * *#data.append(work)
> > * * * * * *#output.close()
> > * * * * * *output=open(filename, 'a')
> > * * * * * *cPickle.dump(work,output)
> > * * * * * *output.close()
>
> > 

>
> > All help would be appreciated. I am new to Python and this seems to be
> > quite a challenge for me.

>
> Make sure you use modes "rb" and "wb" when you open the pickle files. If
> you are running on Windows this can make a difference.
>
> regards
> *Steve
> --
> Steve Holden * * * *+1 571 484 6266 * +1 800 494 3119
> Holden Web LLC * * * * * * *http://www.holdenweb.com/


I've tried both rb and wb as well as r and w, there appears to be no
difference in the running of the code.
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      02-06-2009
mmcclaf wrote:
> On Feb 6, 10:25 am, Steve Holden <st...@holdenweb.com> wrote:
>> mmcclaf wrote:
>>> Hi there,
>>> I have to make a small database using cPickle. I'm having troubles
>>> trying to read in the information if it's more than one line. I'm
>>> pretty sure it's in the line "for line in stuff:" Can anyone help me
>>> out? Basically the end result is wanting it to look something like
>>> what is down below when list is typed in:
>>> Last name First Name Email Address
>>> Doe John
>>> j...@doe.com
>>>
Code:
>>> # @author: Ocdt Murray McClafferty 24656
>>> # This will manage a small database using the cPickle module.
>>> # It must maintain a list of last names, first names and email
>>> addresses, and must let a user interact with the program
>>> #
>>> #!usr/bin/python
>>> # -*- coding: utf-8 -*-
>>> import sys
>>> import cPickle
>>> #
>>> format = '%s             %s                  %s'
>>> try:
>>>    filename = sys.argv[1]
>>>    input = open(filename, 'r')
>>> except IOError:
>>>    print 'File is not available, will create a new file now'
>>>    lastName='Last Name'
>>>    firstName='First Name'
>>>    email= 'Email'
>>>    #input.close()
>>>    output=open (filename, 'w')
>>>    total = format%(lastName, firstName, email)
>>>    cPickle.dump(total,output)
>>>    #cPickle.dump(firstName,output)
>>>    #cPickle.dump(email,output)
>>>    output.close()
>>> except EOFError:
>>>    print 'File is empty'
>>> #datas = cPickle.load(input)
>>> while True:
>>>    command=sys.stdin.readline()[:-1]
>>>    if command=='list': #lists the data in the file
>>>            input = open(filename, 'r')
>>>            stuff=cPickle.load(input)
>>>            for line in stuff:
>>>                    #firstName=cPickle.load(input)
>>>                    #email=cPickle.load(input)
>>>                    #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
>>> (email).rjust(20)
>>>                    stuff=cPickle.load(input)
>>>                    print stuff
>>>                    print line
>>>            input.close()
>>>    if command=='exit' or command=='quit' : #NEVER forget the exit!!!
>>>            print 'Save changes? y for Yes, n for No'
>>>            commandSave=sys.stdin.readline()[:-1]
>>>            if commandSave =='y': #if the user wants to save
>>>                    output=open(filename, 'w')
>>>                    cPickle.dump(work,output)
>>>                    output.close()
>>>                    sys.exit(0)
>>>            if commandSave =='n': #no save
>>>                    input.close()
>>>                    sys.exit(0)
>>>    if command=='add': #adds an entity to the file
>>>            print 'Last name?'
>>>            lastName=sys.stdin.readline()[:-1]
>>>            print 'First name?'
>>>            firstName=sys.stdin.readline()[:-1]
>>>            print 'Email address?'
>>>            email=sys.stdin.readline()[:-1]
>>>            work = format%(lastName, firstName, email)
>>>            #output=open(filename, 'w')
>>>            #data=cPickle.load(output)
>>>            #data.append(work)
>>>            #output.close()
>>>            output=open(filename, 'a')
>>>            cPickle.dump(work,output)
>>>            output.close()
>>>
>>> All help would be appreciated. I am new to Python and this seems to be
>>> quite a challenge for me.

>> Make sure you use modes "rb" and "wb" when you open the pickle files. If
>> you are running on Windows this can make a difference.
>>
>> regards
>> Steve
>> --
>> Steve Holden +1 571 484 6266 +1 800 494 3119
>> Holden Web LLC http://www.holdenweb.com/

>
> I've tried both rb and wb as well as r and w, there appears to be no
> difference in the running of the code.
>

"cPickle.dump(work,output)" writes a string and
"stuff=cPickle.load(input)" just reads that string, so "for line in
stuff:" is iterating through the characters if the string. You need to
use cPickle.load() to read each string (line).
 
Reply With Quote
 
mmcclaf
Guest
Posts: n/a
 
      02-06-2009
On Feb 6, 3:09*pm, MRAB <goo...@mrabarnett.plus.com> wrote:
> mmcclaf wrote:
> > On Feb 6, 10:25 am, Steve Holden <st...@holdenweb.com> wrote:
> >> mmcclaf wrote:
> >>> Hi there,
> >>> I have to make a small database using cPickle. I'm having troubles
> >>> trying to read in the information if it's more than one line. I'm
> >>> pretty sure it's in the line "for line in stuff:" Can anyone help me
> >>> out? Basically the end result is wanting it to look something like
> >>> what is down below when list is typed in:
> >>> Last name * * * * * * * * First Name * * * * * * * *Email Address
> >>> Doe * * * * * * * * * * * * *John
> >>> j...@doe.com
> >>>
Code:
> >>> # @author: Ocdt Murray McClafferty 24656
> >>> # This will manage a small database using the cPickle module.
> >>> # It must maintain a list of last names, first names and email
> >>> addresses, and must let a user interact with the program
> >>> #
> >>> #!usr/bin/python
> >>> # -*- coding: utf-8 -*-
> >>> import sys
> >>> import cPickle
> >>> #
> >>> format = '%s * * * * * * %s * * * * * * * * *%s'
> >>> try:
> >>> * *filename = sys.argv[1]
> >>> * *input = open(filename, 'r')
> >>> except IOError:
> >>> * *print 'File is not available, will create a new file now'
> >>> * *lastName='Last Name'
> >>> * *firstName='First Name'
> >>> * *email= 'Email'
> >>> * *#input.close()
> >>> * *output=open (filename, 'w')
> >>> * *total = format%(lastName, firstName, email)
> >>> * *cPickle.dump(total,output)
> >>> * *#cPickle.dump(firstName,output)
> >>> * *#cPickle.dump(email,output)
> >>> * *output.close()
> >>> except EOFError:
> >>> * *print 'File is empty'
> >>> #datas = cPickle.load(input)
> >>> while True:
> >>> * *command=sys.stdin.readline()[:-1]
> >>> * *if command=='list': #lists the data in the file
> >>> * * * * * *input = open(filename, 'r')
> >>> * * * * * *stuff=cPickle.load(input)
> >>> * * * * * *for line in stuff:
> >>> * * * * * * * * * *#firstName=cPickle.load(input)
> >>> * * * * * * * * * *#email=cPickle.load(input)
> >>> * * * * * * * * * *#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
> >>> (email).rjust(20)
> >>> * * * * * * * * * *stuff=cPickle.load(input)
> >>> * * * * * * * * * *print stuff
> >>> * * * * * * * * * *print line
> >>> * * * * * *input.close()
> >>> * *if command=='exit' or command=='quit' : #NEVER forget the exit!!!
> >>> * * * * * *print 'Save changes? y for Yes, n for No'
> >>> * * * * * *commandSave=sys.stdin.readline()[:-1]
> >>> * * * * * *if commandSave =='y': #if the user wants to save
> >>> * * * * * * * * * *output=open(filename, 'w')
> >>> * * * * * * * * * *cPickle.dump(work,output)
> >>> * * * * * * * * * *output.close()
> >>> * * * * * * * * * *sys.exit(0)
> >>> * * * * * *if commandSave =='n': #no save
> >>> * * * * * * * * * *input.close()
> >>> * * * * * * * * * *sys.exit(0)
> >>> * *if command=='add': #adds an entity to the file
> >>> * * * * * *print 'Last name?'
> >>> * * * * * *lastName=sys.stdin.readline()[:-1]
> >>> * * * * * *print 'First name?'
> >>> * * * * * *firstName=sys.stdin.readline()[:-1]
> >>> * * * * * *print 'Email address?'
> >>> * * * * * *email=sys.stdin.readline()[:-1]
> >>> * * * * * *work = format%(lastName, firstName, email)
> >>> * * * * * *#output=open(filename, 'w')
> >>> * * * * * *#data=cPickle.load(output)
> >>> * * * * * *#data.append(work)
> >>> * * * * * *#output.close()
> >>> * * * * * *output=open(filename, 'a')
> >>> * * * * * *cPickle.dump(work,output)
> >>> * * * * * *output.close()
> >>>
> >>> All help would be appreciated. I am new to Python and this seems to be
> >>> quite a challenge for me.
> >> Make sure you use modes "rb" and "wb" when you open the pickle files. If
> >> you are running on Windows this can make a difference.

>
> >> regards
> >> *Steve
> >> --
> >> Steve Holden * * * *+1 571 484 6266 * +1 800 494 3119
> >> Holden Web LLC * * * * * * *http://www.holdenweb.com/

>
> > I've tried both rb and wb as well as r and w, there appears to be no
> > difference in the running of the code.

>
> "cPickle.dump(work,output)" writes a string and
> "stuff=cPickle.load(input)" just reads that string, so "for line in
> stuff:" is iterating through the characters if the string. You need to
> use cPickle.load() to read each string (line).


Ok, so I just modified that section to:
Code:
	if command=='list': #lists the data in the file
		input = open(filename, 'r')
		stuff=cPickle.load(input)
		for line in stuff:
			#firstName=cPickle.load(input)
			#email=cPickle.load(input)
			#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
(email).rjust(20)
			stuff=cPickle.load(input)
			print stuff


		input.close()
And now it's printing it out ok, but then I get an EOFError at
stuff=cPickle.load(onput) at line 45.
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      02-06-2009
mmcclaf wrote:
> On Feb 6, 3:09 pm, MRAB <goo...@mrabarnett.plus.com> wrote:
>> mmcclaf wrote:
>>> On Feb 6, 10:25 am, Steve Holden <st...@holdenweb.com> wrote:
>>>> mmcclaf wrote:
>>>>> Hi there,
>>>>> I have to make a small database using cPickle. I'm having troubles
>>>>> trying to read in the information if it's more than one line. I'm
>>>>> pretty sure it's in the line "for line in stuff:" Can anyone help me
>>>>> out? Basically the end result is wanting it to look something like
>>>>> what is down below when list is typed in:
>>>>> Last name First Name Email Address
>>>>> Doe John
>>>>> j...@doe.com
>>>>>
Code:
>>>>> # @author: Ocdt Murray McClafferty 24656
>>>>> # This will manage a small database using the cPickle module.
>>>>> # It must maintain a list of last names, first names and email
>>>>> addresses, and must let a user interact with the program
>>>>> #
>>>>> #!usr/bin/python
>>>>> # -*- coding: utf-8 -*-
>>>>> import sys
>>>>> import cPickle
>>>>> #
>>>>> format = '%s             %s                  %s'
>>>>> try:
>>>>>    filename = sys.argv[1]
>>>>>    input = open(filename, 'r')
>>>>> except IOError:
>>>>>    print 'File is not available, will create a new file now'
>>>>>    lastName='Last Name'
>>>>>    firstName='First Name'
>>>>>    email= 'Email'
>>>>>    #input.close()
>>>>>    output=open (filename, 'w')
>>>>>    total = format%(lastName, firstName, email)
>>>>>    cPickle.dump(total,output)
>>>>>    #cPickle.dump(firstName,output)
>>>>>    #cPickle.dump(email,output)
>>>>>    output.close()
>>>>> except EOFError:
>>>>>    print 'File is empty'
>>>>> #datas = cPickle.load(input)
>>>>> while True:
>>>>>    command=sys.stdin.readline()[:-1]
>>>>>    if command=='list': #lists the data in the file
>>>>>            input = open(filename, 'r')
>>>>>            stuff=cPickle.load(input)
>>>>>            for line in stuff:
>>>>>                    #firstName=cPickle.load(input)
>>>>>                    #email=cPickle.load(input)
>>>>>                    #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
>>>>> (email).rjust(20)
>>>>>                    stuff=cPickle.load(input)
>>>>>                    print stuff
>>>>>                    print line
>>>>>            input.close()
>>>>>    if command=='exit' or command=='quit' : #NEVER forget the exit!!!
>>>>>            print 'Save changes? y for Yes, n for No'
>>>>>            commandSave=sys.stdin.readline()[:-1]
>>>>>            if commandSave =='y': #if the user wants to save
>>>>>                    output=open(filename, 'w')
>>>>>                    cPickle.dump(work,output)
>>>>>                    output.close()
>>>>>                    sys.exit(0)
>>>>>            if commandSave =='n': #no save
>>>>>                    input.close()
>>>>>                    sys.exit(0)
>>>>>    if command=='add': #adds an entity to the file
>>>>>            print 'Last name?'
>>>>>            lastName=sys.stdin.readline()[:-1]
>>>>>            print 'First name?'
>>>>>            firstName=sys.stdin.readline()[:-1]
>>>>>            print 'Email address?'
>>>>>            email=sys.stdin.readline()[:-1]
>>>>>            work = format%(lastName, firstName, email)
>>>>>            #output=open(filename, 'w')
>>>>>            #data=cPickle.load(output)
>>>>>            #data.append(work)
>>>>>            #output.close()
>>>>>            output=open(filename, 'a')
>>>>>            cPickle.dump(work,output)
>>>>>            output.close()
>>>>>
>>>>> All help would be appreciated. I am new to Python and this seems to be
>>>>> quite a challenge for me.
>>>> Make sure you use modes "rb" and "wb" when you open the pickle files. If
>>>> you are running on Windows this can make a difference.
>>>> regards
>>>> Steve
>>>> --
>>>> Steve Holden +1 571 484 6266 +1 800 494 3119
>>>> Holden Web LLC http://www.holdenweb.com/
>>> I've tried both rb and wb as well as r and w, there appears to be no
>>> difference in the running of the code.

>> "cPickle.dump(work,output)" writes a string and
>> "stuff=cPickle.load(input)" just reads that string, so "for line in
>> stuff:" is iterating through the characters if the string. You need to
>> use cPickle.load() to read each string (line).

>
> Ok, so I just modified that section to:
>
Code:
> 	if command=='list': #lists the data in the file
> 		input = open(filename, 'r')
> 		stuff=cPickle.load(input)
> 		for line in stuff:
Code:
You're still iterating over the string.

> 			#firstName=cPickle.load(input)
> 			#email=cPickle.load(input)
> 			#print repr (lastName).rjust(10), repr(firstName).rjust(20), repr
> (email).rjust(20)
> 			stuff=cPickle.load(input)
> 			print stuff
> 
> 
> 		input.close()
> 

>
> And now it's printing it out ok, but then I get an EOFError at
> stuff=cPickle.load(onput) at line 45.
>

You can just keep reading until EOFError occurs, at which point you know
you've reached the end of the file:

input = open(filename, 'rb')
try:
while True:
stuff = cPickle.load(input)
print stuff
except EOFError:
pass
input.close()
 
Reply With Quote
 
mmcclaf
Guest
Posts: n/a
 
      02-26-2009
Thanks! All fixed!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing large dictionaries to file using cPickle perfreem@gmail.com Python 11 04-26-2009 09:12 PM
Strange KeyError using cPickle Rune Strand Python 3 06-02-2005 02:19 AM
problem using pickle / cPickle Jesse Bloom Python 1 01-03-2004 05:25 AM
Jython: jythonc and cPickle Carsten Gips Python 0 09-09-2003 02:40 PM
cPickle alternative? Drochom Python 13 08-17-2003 07:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57