Question

In: Computer Science

I'm trying to use Jupyter (python) to convert the contents of a pkl file into a...

I'm trying to use Jupyter (python) to convert the contents of a pkl file into a dictionary, WITHOUT using pandas.

I'm able to import pickle and can open my file...but I'm not sure how to create the dictionary.

Solutions

Expert Solution

CODE:

OUTPUT:

RAW CODE:

import pickle # importing module

dic = {1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"g",8:"h",9:"i"} # dictionary
out_file = open("file.pkl","wb") # opening file in writebinary mode
pickle.dump(dic,out_file) # writing dictionary into file
out_file.close() # closing file

# opening same file
pkl_file = open("file.pkl","rb") # opening file in readbinary mode
dic = pickle.load(pkl_file) # converting file to dictionary
print(dic) # printing dicionary
pkl_file.close() # closing file

NOTE:
If You have any doubts feel free to comment in comment section.
DO VOTE(LIKE).


Related Solutions

I'm working on a to-do list program in Python 2. I'm trying to delete an item...
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue:...
In python Complete the function get_Astring(filename) to read the file contents from filename (note that the...
In python Complete the function get_Astring(filename) to read the file contents from filename (note that the test will use the file data.txt and data2.txt provided in the second and third tabs), strip off the newline character at the end of each line and return the contents as a single string.
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
in java File encryption is the science of writing the contents of a file in a...
in java File encryption is the science of writing the contents of a file in a secret code. Write an encryption program that works like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a simple...
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
Invalid entry code in python my code is pasted below. The last elif statement, I'm trying...
Invalid entry code in python my code is pasted below. The last elif statement, I'm trying to get the program to print "invalid entry" if the entry for user_input is invalid. The first user prompt should only allow for numbers 1-10 and "exit" and "quit" import math user_prompt = """Enter number of operation that you want to execute <type exit or quit to end program>: 1 sin(x) 2 cos(x) 3 tan(x) 4 asin(x) 5 acos(x) 6 atan(x) 7 ln(x) 8...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file...
USE BASIC PYTHON Focus on Basic file operations, exception handling. Save a copy of the file module6data.txt (Below) Write a program that will a. Open the file module6data.txt b. Create a second file named processed. txt c. Read the numbers from the first file one at a time. For each number write into second file, if possible, its I. Square ii. Square root iii. Reciprocal (1/number)use a math module function for the square root. use exception handling to trap possible...
Python regex How to write the regex in Python that only include the contents within a...
Python regex How to write the regex in Python that only include the contents within a parentheses? e.g. "uio" [ek3k 0die] 4229834 return "ek3k 0die"
Please Use Python 3.The Problem: Read the name of a file and then open it for...
Please Use Python 3.The Problem: Read the name of a file and then open it for reading. Read the name of another file and then open it for output. When the program completes, the output file must contain the lines in the input file, but in the reverse order. • Write the input, output, and the relationship between the input and output. • Develop the test data (A single test will be alright). Make the input file at least 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT