473,385 Members | 1,919 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,385 software developers and data experts.

unpack tuple of wrong size

I want to do

t = (1,2)
a,b = t # get a=1 and b=2

However when
t = (1,)
a,b=t

I got a "ValueError: unpack tuple of wrong size"

What I want is for a=1 and b=None. Is there a good way to do this?
Wai Yip Tung
Jul 18 '05 #1
2 3231
Tung Wai Yip wrote:
I want to do

t = (1,2)
a,b = t # get a=1 and b=2

However when
t = (1,)
a,b=t

I got a "ValueError: unpack tuple of wrong size"

What I want is for a=1 and b=None. Is there a good way to do this?


t = (1,None)
a,b = t

(1,) means that the tuple has only one element. Remember that tuples are
defined by the comma, except on those cases where it would be unclear
what the intention is.

--
Andres Rosado
Email: an*****@despammed.com
Homepage: http://andres980.tripod.com/

"Well, well. Look-who's-BACK!"
-- Megatron
Jul 18 '05 #2
Tung Wai Yip <tu********@yahoo.com> wrote in
news:c7********************************@4ax.com:
However when
t = (1,)
a,b=t

I got a "ValueError: unpack tuple of wrong size"

What I want is for a=1 and b=None. Is there a good way to do this?


Probably the simplest is:

a, b = (t + (None, None))[:2]

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ahsan Imam | last post by:
Hello All, I am trying to move an application from python 1.5.2 to 2.3. The code works fine in 1.5.2 but gives the exception (exceptions.TypeError unpack non-sequence) in python 2.3. I did not...
5
by: Geoffrey | last post by:
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer:...
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: Linh Luong | last post by:
Hi All, 1. I have been reading and the max size of a tuple is 8K. I have also read that I can it to a larger size in some config file. Where is this file? is it called pg_config.h and is the...
3
by: Eric Jacoboni | last post by:
Hi, To experiment with unpacking, i've written a little C code which stores one record in a file. Then, i try to reread this file to unpack the record. Here's the struct of a record: ...
3
by: Andrew Robert | last post by:
Hey everyone, Maybe you can see something I don't. I need to convert a working piece of perl code to python. The perl code is: sub ParseTrig {
4
by: OhKyu Yoon | last post by:
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=HHHH', infile.read(8)) # do...
3
by: echo | last post by:
i have never contacted to python language before this, i want to use the following py file to convert a pgm image to *.coe file, which is initial file of Xilinx memory.And this py file was written by...
2
by: ram | last post by:
Here's a little issue I run into more than I like: I often need to unpack a sequence that may be too short or too long into a fixed-size set of items: a, b, c = seq # when seq = (1, 2, 3,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.