unpacking

Python update object from dictionary

Is there a built-in function/operator I could use to unpack values from a dictionary and assign it into instance variables? This is what I intend to do: c = MyClass() c.foo = 123 c.bar = 123 # c.foo == 123 and c.bar == 123 d = {'bar': 456} c.update(d) # c.foo == 123 and c.bar == 456 Something akin to dictionary update() which loa...

Python-like list unpacking in C#?

In python, I can do something like this: List=[3, 4] def Add(x, y): return x + y Add(*List) #7 Is there any way to do this or something similar in C#? Basically I want to be able to pass a List of arguments to an arbitrary function, and have them applied as the function's parameters without manually unpacking the List and callin...

maven-war-plugin vs. "Unexpected end of ZLIB input stream"

im using maven-war-plugin and sometimes i get Unexpected end of ZLIB input stream when deploying to jboss, its because file is made in jboss directory and not moved/copied there, is there any way to fix it(using maven)? my configuration: <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <configur...

Unpacking an executable from within a library in C/C++

I am developing a library that uses one or more helper executable in the course of doing business. My current implementation requires that the user have the helper executable installed on the system in a known location. For the library to function properly the helper app must be in the correct location and be the correct version. I wo...

Maven dependencies jar not usable

EDIT: I am basically running into the following documented issue. I am using the maven assembly plugin to generate a jar file that includes my dependencies so that my project can be run from a single file. However, the jar file is not being built properly it seems. The below was an attempt to try and work around the issue. Has anyone ru...

Unpacking rar on iPhone

Hi everyone, I created little download application with music player and now I want it to unpack archives, because quite often mp3s are packed in archive and you can play them before you unpack the archive. I found solution for .zip files on iPhone here on stackoverflow, but I'm wondering if there's a way to unpack .rar files, or other t...

Is 'shift' evil for processing Perl subroutine parameters?

I'm frequently using shift to unpack function parameters: sub my_sub { my $self = shift; my $params = shift; .... } However, many on my colleagues are preaching that shift is actually evil. Could you explain why I should prefer sub my_sub { my ($self, $params) = @_; .... } to shift? ...

How to pick certain elements of x-tuple returned by a function?

I am a newbie to Python. Consider the function str.partition() which returns a 3-tuple. If I am interested in only elements 0 and 2 of this tuple, what is the best way to pick only certain elements out of such a tuple? I can currently do either: # Introduces "part1" variable, which is useless (part0, part1, part2) = str.partition(' ') ...

Is it possible to unpack a tuple without using variables?

I'm using the os.path.split() function on a path in my program to get the filename and pathname of a file then passing them into another method, but my current solution seems rather ugly: path = os.path.split(somefile) some_class(path[0], path[1]) Is it possible to unpack the path tuple in a cleaner way within the call to some_class? ...

Javascript equivalent of Python's sequence unpack: a,b=(1,2) ?

Hi, is there a javascript equivalent to unpack sequences like in python (a,b=(1,2))? Thanks in advance. ...

Why does running rake gems:unpack result in a Gem::FilePermissionError

I'm attempting to upgrade the friendly_id gem in a rails project. I have removed the old gem from the vendor directory, installed the new gem from rubygems.org. When I type: rake gems:unpack I get the following response: ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /usr/lib...

How can I explode a tuple so that it can be passed as a parameter list?

Let's say I have a method definition like this: def myMethod(a, b, c, d, e) Then, I have a variable and a tuple like this: myVariable = 1 myTuple = (2, 3, 4, 5) Is there a way I can pass explode the tuple so that I can pass its members as parameters? Something like this (although I know this won't work as the entire tuple is consid...

How do I convert a tuple of tuples to a one-dimensional list using list comprehension?

I have a tuple of tuples - for example: tupleOfTuples = ((1, 2), (3, 4), (5,)) I want to convert this into a flat, one-dimensional list of all the elements in order: [1, 2, 3, 4, 5] I've been trying to accomplish this with list comprehension. But I can't seem to figure it out. I was able to accomplish it with a for-each loop: myLi...

Unpacking a 1-tuple in a list of length 1

Suppose I have a tuple in a list like this: >>> t = [("asdf", )] I know that the list always contains one 1-tuple. Currently I do this: >>> dummy, = t >>> value, = dummy >>> value 'asdf' Is there a shorter and more elegant way to do this? ...

Python pack arguments??

Hi, is to possible to "pack" arguments in python? I have the following functions in the library, that I can't change (simplified): def g(a,b=2): print a,b def f(arg): g(arg) I can do o={'a':10,'b':20} g(**o) 10 20 but can I/how do I pass this through f? That's what I don't want: f(**o) Traceback (most recent call last): ...

Unpacking argument lists for ellipsis in R

I am confused by the use of the ellipsis (...) in some functions, i.e. how to pass an object containing the arguments as a single argument. In Python it is called "unpacking argument lists", e.g. >>> range(3, 6) # normal call with separate arguments [3, 4, 5] >>> args = [3, 6] >>> range(*args) # call with argumen...