473,836 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3261
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*****@despamm ed.com
Homepage: http://andres980.tripod.com/

"Well, well. Look-who's-BACK!"
-- Megatron
Jul 18 '05 #2
Tung Wai Yip <tu********@yah oo.com> wrote in
news:c7******** *************** *********@4ax.c om:
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
8049
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 write this code so I am not sure what is happening here. Here is the code snippet: for (item, agent) in self.lItems:
5
13888
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: '\x00\x00\xb9\x02\x13EXCLUDE_CREDIT_CARD' # the above was printed using repr(xbuffer). # Note that int(0x13) = 19 which is exactly the length of the visible text #
5
5462
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 coming through fine when using (integer1,) = struct.unpack('l', line) except when line contains "carriage-return" "linefeed" which are valid binary packed values. Error = unpack string size dows not match format. It seems that
3
3274
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 variable called BLKSZ?? 2. Is there a way I can find the actual size of the tuple? Do you go into each column and find the length of each value and sum it up? I am out of ideas.. if someone knows how please shine some light on my situation..
3
5530
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: typedef struct { char nom;
3
3848
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
2806
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 something tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32)) # do something
3
1892
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 I. Chuang, MIT, downloaded from MIT web site. i just use python 2.4(for windows idle) to run this file,but it shows error: Thanks for your help! the py file:pgm2coe.py #!/usr/bin/python #
2
1917
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, 4, ...) or seq = (1, 2) What I usually do is something like this: a, b, c = (list(seq) + )
0
9656
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10526
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9349
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7771
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4437
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3100
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.