Here's what I have:
import pickle
data = open(r'C:\pickle_data.txt', 'w')
image = open(r'C:\peakhell.jpg')
pickle.Pickler(data)
data.dump(image)
data.close()
image.close()
First off, I'm not sure the second line is the way to do that. But my
main problem is I don't know how to define the steps when pickling an
object. How do you first create the object? Does it return a value? I tried:
pickler = pickle.Pickler(data)
pickle.Pickler(data)
Then I tried:
pickler.dump(image)
data.dump(image)
Basically, I'm just confused about all the syntax involved. Which
objects do I operate on, and when? I can't find these answers in the
documentation or in the interactive help, because I don't see any examples.
Furthermore, I get this error every time:
Traceback (most recent call last):
File "C:\Documents and Settings\jsaler01.TUFTS\My
Documents\Python24\myscripts\challenges\pickle.py" , line 3, in -toplevel-
import pickle
File "C:\Documents and Settings\jsaler01.TUFTS\My
Documents\Python24\myscripts\challenges\pickle.py" , line 7, in -toplevel-
pickle.Pickler(data)
AttributeError: 'module' object has no attribute 'Pickler'
So that makes me really confused, because I must have the syntax totally
wrong if it can't even get past the initial creation of a pickler object. 16 5517
John Salerno wrote: Here's what I have:
import pickle
data = open(r'C:\pickle_data.txt', 'w') image = open(r'C:\peakhell.jpg') pickle.Pickler(data) data.dump(image) data.close() image.close()
First off, I'm not sure the second line is the way to do that. But my main problem is I don't know how to define the steps when pickling an object. How do you first create the object? Does it return a value? I tried:
pickler = pickle.Pickler(data) pickle.Pickler(data)
Then I tried:
pickler.dump(image) data.dump(image)
Basically, I'm just confused about all the syntax involved. Which objects do I operate on
any object that supports pickling.
file handles does not belong to that group (what did you expect
pickle to do with a file handle ?)
or did "object" refer to the Pickler instance? you don't really need to
bother with that; just use the dump *function* instead:
pickle.dump(object, file)
but if you insist on using your own Pickler instance, you have to save
the pickler instance in a variable, and call the dump method on that in-
stance:
myfile = open(somefilename, "wb")
mypickler = pickle.Pickler(myfile)
mypickler.dump(object)
</F>
Fredrik Lundh wrote: file handles does not belong to that group (what did you expect pickle to do with a file handle ?)
or did "object" refer to the Pickler instance? you don't really need to bother with that; just use the dump *function* instead:
pickle.dump(object, file)
but if you insist on using your own Pickler instance, you have to save the pickler instance in a variable, and call the dump method on that in- stance:
myfile = open(somefilename, "wb") mypickler = pickle.Pickler(myfile) mypickler.dump(object)
I'm sorry, but I'm terribly confused. Nothing seems to be working for
me. I *think* what I need to pickle is an image file, but so far I think
all I'm doing is passing the file handle in as the 'object', which
probably isn't correct. How would I get the actual image object to pass
in? But I also tried pickling a string and that didn't work either.
I tried it both ways you suggest, but I can't get past the errors. I
keep getting either
AttributeError: 'module' object has no attribute 'dump' (when I use the
function)
or
AttributeError: 'module' object has no attribute 'dump' (when I create
an instance)
Is there something special I need to do to use the pickle module? My
program seems to recognize the import, but it keeps saying that nothing
is an attribute of it.
John Salerno wrote: AttributeError: 'module' object has no attribute 'dump' (when I create an instance)
That should be:
AttributeError: 'module' object has no attribute 'Pickler' (when I
create an instance)
John Salerno wrote: I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file,
SNIP
Hint: Read the source for that page more carefully.
John Salerno wrote: but if you insist on using your own Pickler instance, you have to save the pickler instance in a variable, and call the dump method on that in- stance:
myfile = open(somefilename, "wb") mypickler = pickle.Pickler(myfile) mypickler.dump(object) I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file, but so far I think all I'm doing is passing the file handle in as the 'object'
define "image file". the data in the file, the file name, or some other
representation?
I tried it both ways you suggest, but I can't get past the errors. I keep getting either
AttributeError: 'module' object has no attribute 'dump' (when I use the function)
did you, by any chance, name your test script "pickle.py" ?
</F>
Fredrik Lundh wrote: John Salerno wrote:
but if you insist on using your own Pickler instance, you have to save the pickler instance in a variable, and call the dump method on that in- stance:
myfile = open(somefilename, "wb") mypickler = pickle.Pickler(myfile) mypickler.dump(object) I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file, but so far I think all I'm doing is passing the file handle in as the 'object'
define "image file". the data in the file, the file name, or some other representation?
I tried it both ways you suggest, but I can't get past the errors. I keep getting either
AttributeError: 'module' object has no attribute 'dump' (when I use the function)
did you, by any chance, name your test script "pickle.py" ?
DOH!
Fredrik Lundh wrote: define "image file". the data in the file, the file name, or some other representation?
I was being dense again. I was just opening the file, but not reading
it! After reading it, it's easy to pickle it.
did you, by any chance, name your test script "pickle.py" ?
That did the trick! Thanks!
Pythor wrote: John Salerno wrote:
I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file,
SNIP
Hint: Read the source for that page more carefully.
Hmmm...the source doesn't say much. Is there more to do with the source
beyond using it to figure out what 'peak hell' means?
John Salerno wrote: Pythor wrote: John Salerno wrote:
I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file,
SNIP
Hint: Read the source for that page more carefully.
Hmmm...the source doesn't say much. Is there more to do with the source beyond using it to figure out what 'peak hell' means?
Yes... It mentions a whole different file, which you need to use pickle
on.
Pythor wrote: John Salerno wrote: Pythor wrote: John Salerno wrote:
I'm sorry, but I'm terribly confused. Nothing seems to be working for me. I *think* what I need to pickle is an image file, SNIP
Hint: Read the source for that page more carefully. Hmmm...the source doesn't say much. Is there more to do with the source beyond using it to figure out what 'peak hell' means?
Yes... It mentions a whole different file, which you need to use pickle on.
Yikes, I even took a second look at that after you said re-read the
source and then I ignored it! Thanks!
John Salerno wrote: Pythor wrote: John Salerno wrote: Pythor wrote: John Salerno wrote:
> I'm sorry, but I'm terribly confused. Nothing seems to be working for > me. I *think* what I need to pickle is an image file, SNIP
Hint: Read the source for that page more carefully.
Hmmm...the source doesn't say much. Is there more to do with the source beyond using it to figure out what 'peak hell' means?
Yes... It mentions a whole different file, which you need to use pickle on.
Yikes, I even took a second look at that after you said re-read the source and then I ignored it! Thanks!
Whis is why I said carefully ;) I missed it several times myself when
I was working on the challenge.
Pythor wrote: Whis is why I said carefully ;) I missed it several times myself when I was working on the challenge.
Ok, frustration has set in again. I see the file name in the source
code, but am I meant to actually access a file, or just use the name
itself? I also had to look up what 'banner' meant in Unix, which wasn't
a very fun thing to have to do for a Python puzzle.
John Salerno wrote: Pythor wrote:
Whis is why I said carefully ;) I missed it several times myself when I was working on the challenge.
Ok, frustration has set in again. I see the file name in the source code, but am I meant to actually access a file, or just use the name itself? I also had to look up what 'banner' meant in Unix, which wasn't a very fun thing to have to do for a Python puzzle.
Ah, I should have known we weren't done with URL manipulation yet. Now I
just need to figure out what to do with this source code.
John Salerno wrote: John Salerno wrote: Pythor wrote:
Whis is why I said carefully ;) I missed it several times myself when I was working on the challenge.
Ok, frustration has set in again. I see the file name in the source code, but am I meant to actually access a file, or just use the name itself? I also had to look up what 'banner' meant in Unix, which wasn't a very fun thing to have to do for a Python puzzle.
Ah, I should have known we weren't done with URL manipulation yet. Now I just need to figure out what to do with this source code.
Incidentally, there's a forum specifically for posting an receiving
hints on the challenges here: http://www.pythonchallenge.com/forums/viewforum.php?f=1
Not that I mind helping. ;)
Pythor wrote: John Salerno wrote: John Salerno wrote: Pythor wrote:
Whis is why I said carefully ;) I missed it several times myself when I was working on the challenge. Ok, frustration has set in again. I see the file name in the source code, but am I meant to actually access a file, or just use the name itself? I also had to look up what 'banner' meant in Unix, which wasn't a very fun thing to have to do for a Python puzzle. Ah, I should have known we weren't done with URL manipulation yet. Now I just need to figure out what to do with this source code.
Incidentally, there's a forum specifically for posting an receiving hints on the challenges here:
http://www.pythonchallenge.com/forums/viewforum.php?f=1
Not that I mind helping. ;)
Yeah, I read the whole thread for this level and even posted a question,
but the forums are pretty dead. Not only that, but I'm starting to get
the feeling that these challenges are going to require a little more
programming expertise than I have, because all of the 'hints' are still
too vague for me.
Like I said in my post on the hints forum, I really enjoy figuring out
how to use Python to solve the puzzles, but it's not very fun when I
don't know *what* to do in the first place, and I think knowing what to
do has a lot to do with how experienced you are with certain CS subjects
and how quickly you can identify the problem and a possible solution.
All I see is huge bunch of string characters with no idea what to do
with it to extract any kind of information.
John Salerno wrote: Pythor wrote: John Salerno wrote: John Salerno wrote: Pythor wrote:
> Whis is why I said carefully ;) I missed it several times myself when > I was working on the challenge. Ok, frustration has set in again. I see the file name in the source code, but am I meant to actually access a file, or just use the name itself? I also had to look up what 'banner' meant in Unix, which wasn't a very fun thing to have to do for a Python puzzle. Ah, I should have known we weren't done with URL manipulation yet. Now I just need to figure out what to do with this source code.
Incidentally, there's a forum specifically for posting an receiving hints on the challenges here:
http://www.pythonchallenge.com/forums/viewforum.php?f=1
Not that I mind helping. ;)
Yeah, I read the whole thread for this level and even posted a question, but the forums are pretty dead. Not only that, but I'm starting to get the feeling that these challenges are going to require a little more programming expertise than I have, because all of the 'hints' are still too vague for me.
Like I said in my post on the hints forum, I really enjoy figuring out how to use Python to solve the puzzles, but it's not very fun when I don't know *what* to do in the first place, and I think knowing what to do has a lot to do with how experienced you are with certain CS subjects and how quickly you can identify the problem and a possible solution. All I see is huge bunch of string characters with no idea what to do with it to extract any kind of information.
Only a bunch of string characters? If that's true, you missed
something. I get a bunch of lists of tuples. Each tuple has a meaning
associated with the original filename, and an old unix command. Which
is what confused the heck out of me the first time, not knowing much
Unix. The command is used to make large signs using old-style dot
matrix printers. If you want a more coherent hint than that, email
me at pythor @ pythor dot com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Hohn |
last post by:
Hi,
under python 2.2, the pickle/unpickle sequence incorrectly restores
a larger data structure I have.
Under Python 2.3, these structures now give an explicit exception from...
|
by: Mike P. |
last post by:
Hi all,
I'm working on a simulation (can be considered a game) in Python where I
want to be able to dump the simulation state to a file and be able to load
it up later. I have used the standard...
|
by: Jim Lewis |
last post by:
Pickling an instance of a class, gives "can't pickle instancemethod
objects". What does this mean? How do I find the class method creating
the problem?
|
by: crystalattice |
last post by:
I'm creating an RPG for experience and practice. I've finished a
character creation module and I'm trying to figure out how to get the
file I/O to work.
I've read through the python newsgroup...
|
by: Chris |
last post by:
Why can pickle serialize references to functions, but not methods?
Pickling a function serializes the function name, but pickling a
staticmethod, classmethod, or instancemethod generates an...
|
by: fizilla |
last post by:
Hello all!
I have the following weird problem and since I am new to Python I somehow cannot figure out an elegant solution. The problem reduces to the following question:
How to pickle a...
|
by: Michele Simionato |
last post by:
Can somebody explain what's happening with the following script?
$ echo example.py
import pickle
class Example(object):
def __init__(self, obj, registry):
self._obj = obj
self._registry =...
|
by: Nagu |
last post by:
I am trying to save a dictionary of size 65000X50 to a local file and
I get the memory error problem.
How do I go about resolving this? Is there way to partition the pickle
object and combine...
|
by: Nagu |
last post by:
I am trying to save a dictionary of size 65000X50 to a local file and
I get the memory error problem.
How do I go about resolving this? Is there way to partition the pickle
object and combine...
|
by: IceMan85 |
last post by:
Hi to all, I have spent the whole morning trying, with no success to pickle an object that I have created.
The error that I get is : Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
| |