I recently found out about pickle, which is amazing. But it errors on me when used for my actual script, testing it with a one item dictionary it worked fine. My real script is thousands of lines of code storing various objects within maya into it. I do not know if it has anything to do with the size, I have read around a lot of threads here but none are specific to my error.
I have tried writing with all priorities. No luck.
This is my output code:
output = open('locatorsDump.pkl', 'wb')
pickle.dump(l.locators, output, -1)
output.close()
This is my read code:
jntdump = open('locatorsDump.pkl', 'rb')
test = pickle.load(jntdump)
jntdump.close()
This is the error:
# Error: Error in maya.utils._guiExceptHook:
# File "C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\pymel-1.0.0-py2.6.egg\maya\utils.py", line 277, in formatGuiException
# exceptionMsg = excLines[-1].split(':',1)[1].strip()
# IndexError: list index out of range
#
# Original exception was:
# Traceback (most recent call last):
# File "<maya console>", line 3, in <module>
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 1370, in load
# return Unpickler(file).load()
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 858, in load
# dispatch[key](self)
# File "C:\Program Files\Autodesk\Maya2011\bin\python26.zip\pickle.py", line 880, in load_eof
# raise EOFError
# EOFError #
Try using pickle.dumps() and pickle.loads() as a test.
If you don't recieve the same error, you know it is related to the file write.
Related
I'm making a console based game that saves input history, to help with debugging I created a function that will automatically input commands on start
def __readfile (self) -> None:
lines = None
with open("insts.txt", "r") as f:
lines = f.read().split("\n")
if (lines == None):
print("attempted to read insts.txt for instructions, could not find file")
return
self.__initfile = True
for line in lines:
self.parse_input(line)
self.__initfile = False
in the instance of the error "self.parse_input" ultimately leads to "readline.read_history_file" and none of the code in between the two has any effect on the error
but it gives this error message:
Traceback (most recent call last):
File "main.py", line 9, in <module>
game.start()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1353, in start
self.__readfile()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1345, in __readfile
self.parse_input(line)
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1223, in parse_input
self._parse_dialog(text)
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1128, in _parse_dialog
self._parse_dialog("leave")
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1101, in _parse_dialog
self._load_hist_scope()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1331, in _load_hist_scope
readline.read_history_file("history.txt")
PermissionError: [Errno 1] Operation not permitted
I have looked everywhere for an answer to where this error is coming from and can't find one
I've tried changing the file read operation from the "with open("insts.txt")" to a hardcoded list but that didn't work, os.access("history.txt", os.R_OK) also returns true when called just before "readline.read_history_file"
It appears to be a Mac-specific issue with readline. According to this answer, you need to use gnureadline on the Mac, rather than readline.
import gnureadline as readline
I can't find a way of reading the Minecraft world files in a way that i could use in python
I've looked around the internet but can find no tutorials and only a few libraries that claim that they can do this but never actually work
from nbt import *
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
I expected this to work but instead I got errors about the file not being compressed or something of the sort
Full error:
Traceback (most recent call last):
File "C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py", line 2, in <module>
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 628, in __init__
self.parse_file()
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 652, in parse_file
type = TAG_Byte(buffer=self.file)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 99, in __init__
self._parse_buffer(buffer)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 105, in _parse_buffer
self.value = self.fmt.unpack(buffer.read(self.fmt.size))[0]
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 276, in read
return self._buffer.read(size)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 463, in read
if not self._read_gzip_header():
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x00\x00')
Use anvil parser. (Install with pip install anvil-parser)
Reading
import anvil
region = anvil.Region.from_file('r.0.0.mca')
# You can also provide the region file name instead of the object
chunk = anvil.Chunk.from_region(region, 0, 0)
# If `section` is not provided, will get it from the y coords
# and assume it's global
block = chunk.get_block(0, 0, 0)
print(block) # <Block(minecraft:air)>
print(block.id) # air
print(block.properties) # {}
https://pypi.org/project/anvil-parser/
According to this page, the .mca files is not totally kind of of NBT file. It begins with an 8KiB header which includes the offsets of chunks in the region file itself and the timestamps for the last updates of those chunks.
I recommend you to see the offical announcement and this page for more information.
So on my game I'm making, I'm trying to load the data files needed for the game, and when I load the file with pickle (The file has been loaded, I've double-checked that.) I get this error:
Traceback (most recent call last):
File "/Users/user/Downloads/Deeper-master/Deeper.py", line 257, in <module>
tutorialData = pickle.load(tutorialFile)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1075, in load_inst
klass = self.find_class(module, name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named __main__
I saw a question like this on Stack Overflow, but it's a little different than my situation, so sorry if this is a duplicate, I'm just trying to figure it out.
You can find my code here. The main script is Deeper.py, just to save time.
If you notice in your repo, you have a Deeper.pyc and Deeper.py. If I run Deeper.py, it raises the same exception as yours. If I run Deeper.pyc, it raises another exception:
Traceback (most recent call last):
File "Deeper.py", line 7, in <module>
ToolbarTile = pygame.image.load("ToolbarTile.png")
pygame.error: Couldn't open Toolbar Tile.png
So, the code (bytecode, some previous version) references ToolbarTile.png, but the exception is about Toolbar Tile.png (with a space). So I changed the file name to account for that.
Now it raises:
Traceback (most recent call last):
File "Deeper.py", line 766, in <module>
else:
File "Deeper.py", line 394, in __init__
def displayCraft(self):
pygame.error: Couldn't open options.png
There's an Options.png in your files, but it looks for options.png (lower case) (even your new code in Deeper.py looks for that). So I changed that.
Now it works, albeit with Deeper.pyc so that must be why you thought:
(The file has been loaded, I've double-checked that.)
Maybe delete the Deeper.pyc and do a git-bisect to see when the bug was introduced (ps: check your toolbar.dat, does it seem okay to you? Also check the way you're using pickle.load. Maybe you should use rb instead of r?)
Currently I cannot
pkl_file = open(item, 'rb')
meta = pickle.load(pkl_file)
print type(meta)
I get:
Traceback (most recent call last):
File "blob-pickles.py", line 16, in <module>
meta = pickle.load(pkl_file);print type(meta)
File "C:\Anaconda\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Anaconda\lib\pickle.py", line 858, in load
dispatch[key](self)
KeyError: '\x00'
pointing to the pickle.load() line
Originally i saved the pickle like this :
output = open(fileName+'.pkl', 'wb')
pickle.dump(meta, output)
where meta was a list with 4 strings
So I tried
pickle.loads()
And I get EOF error. The files are not blank...
When I wrote the pickles i used wb mode and also to read them..
What went wrong or what can i do to retrieve the information within which is just a small list?
pickle left a bad taste in my mouth. Next time I'll try dill. Maybe their code is more kosher.
I am new to python. I have a file data.pkl. What I would like to do is get the data from the file. I looked at http://docs.python.org/library/pickle.html, 11.1.7 example and tried exactly that.
My code looks like this:
import pprint, pickle
pkl_file = open('data.pkl', 'rb')
data1 = pickle.load(pkl_file)
pprint.pprint(data1)
pkl_file.close()
But it is giving me error:
Traceback (most recent call last):
File "/home/sadiksha/workspace/python/test.py", line 5, in <module>
data1 = pickle.load(pkl_file)
File "/usr/lib/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 966, in load_string
raise ValueError, "insecure string pickle"
Can anyone please tell me what am I doing wrong here?
It seems that your pickle file was either not written correctly (specifying 'wb') or the file was somehow corrupted. Try creating your own pickle file and reading that back in. That should do the trick.
As for the pickle file specified, it is definitely corrupted.