473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ValueError: need more than 1 value to unpack

So I am trying to write a program to use a cypher to code a textfile. There is a textfile holding the cypher, and the program is supposed to ask the user which file they want encoded. This is my program so far
Expand|Select|Wrap|Line Numbers
  1. #program
  2. textfile = input("What is the name of the file that holds a cypher?")
  3. code = {}
  4. for line in textfile:
  5.         (char, shadow_char) = line.split()
  6.         code[char]= shadow_char
  7. infile = input("What is the name of the file that holds a text?")
  8. outfile = input("Choose a name of a file where the encoded text should be printed?")
  9.  
  10. INFILE = open(infile, "r")
  11. OUTFILE = open(outfile, "w")
  12. for line in INFILE:
  13.     for char in sentence:
  14.         if char in code:
  15.             encoded_sentence += code[char]
  16.         else:
  17.             encoded_sentence += char
  18.  
  19.     OUTFILE.write(sentence+ "\n")
  20.     OUTFILE.write(econded_sentence)
  21.  
  22. INFILE.close()
  23. OUTFILE.close()


i keep getting "ValueError: need more than 1 value to unpack"
for line 4, (char, shadow_char) = line.split()

any help?
Mar 14 '10 #1
1 4573
Glenton
391 Expert 256MB
line.split() will just return one value. Your code is trying to assign two variables to the result, so Python is telling you that it does not love this.

Try myChar=line.split(), and then myChar[0] for char and myChar[1] for shadow_char.
Mar 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
0
by: sj | last post by:
Im trying to read sample values from aiff files but can not seem to get the unpacking right. Ths following code reads n frames from a sample file and prints the amplitudes to the terminal. In the...
5
by: grant | last post by:
Hi All, I am pretty new to python and am having a problem intepreting binary data using struct.unpack. I am reading a file containing binary packed data using open with "rb". All the values are...
3
by: Nx | last post by:
Is there a better solution to following problem : I want to unpack a list into variables the list is created at runtime and I do not know how many items there will be , but I know not more than...
3
by: Elezar Simeon Papo | last post by:
Hello All, I have a tab separated input file (data.txt) in text format - the file looks like this SCHOOL DEPART1 DEPART2 DEPART3 Harvard Economics Mathematics Physics...
4
by: enigmadude | last post by:
As many have heard, IronPython 1.0 was released. When I was looking through the listed differences between CPython and IronPython, the document mentioned that using large exponents such as 10 **...
0
by: laxmikiran.bachu | last post by:
ValueError: need more than 1 value to unpack . This is the error I get when I am using pyRXPU in the one of the scripts to get the strings from an application. Can anybody throw some light on...
8
by: Shawn Minisall | last post by:
I am trying to read a few lines of a file with multiple values, the rest are single and are reading in fine. With the multiple value lines, python says this "ValueError: too many values to...
3
by: Shawn Minisall | last post by:
I am trying to read a few lines of a file with multiple values, the rest are single and are reading in fine. With the multiple value lines, python says this "ValueError: too many values to...
1
Eclipse
by: Eclipse | last post by:
G'day all In the code below I am trying to catch an error thrown if i enter any other value than an integer. (I used the string 'six' and the float '1.5') The error thrown in the command...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.