Questions tagged [argument-unpacking]

Use this tag for questions related with argument unpacking, a technique that allows Arrays and Traversable objects to be extracted/unpacked into argument lists/sequences.

is usually found in PHP, Python and Go.

144 questions
0
votes
2 answers

python argument unpacking puzzling behaviour

I have a problem understanding the process of argument unpacking from a list using the star operator in python. I have followed the documentation entry and tried to re-create my own little example. So I've defined a simple list of numbers: list =…
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
0
votes
1 answer

How to unpack a tuple while calling an external method in Python?

I call a method of an external library multiple times in my class like this: class MyClass: const_a = "a" const_b = True const_c = 1 def push(self, pushee): with ExternalLibrary.open(self.const_a, self.const_b,…
-1
votes
1 answer

Why do I need '**' when loading json (Python)

t1 = Tournament("Aeroflot Open", 2010) json_data = json.dumps(t1.__dict__) print(json_data) t = Tournament(**json.loads(json_data)) # <------------------- print(f"name = {t.name}, year = {t.year}") Could someone explain me why do I need these two…
David
  • 27
  • 5
-1
votes
2 answers

not enough values to unpack (expected 4, got 1) within a funtion, python

def reademail(): f = open("Y11email.csv", "r") line= "email"+ ","+"fname"+","+"sname"+"password"+"\n" for line in f: email,fname,sname,password=line.split(", ")#splits each line however creates an extra space between the lines because of enter …
Ray
  • 1
  • 1
  • 4
-1
votes
3 answers

Merging two dic in python3 using Unpacking Generalisations in Python3.5

There are two dictionaries as follow which I want to merge them, my point is to select those keys that I am interested in, for example I am interested in all the keys except county. Solution I 've used is using del function after creating your new…
pm1359
  • 622
  • 1
  • 10
  • 31
-1
votes
2 answers

How to convert the x of for x in seq to seq

This is a follow-up question to this SO-post. Given this block of code (csvData1 is a .csv file.) let mappedSeq1 = seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) } for x in mappedSeq1 do printfn "%A" x What if I don't want to…
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
-2
votes
2 answers

python variable unpacking fails

7.10 and for some reason the following code snippet is producing an error... device_info = {'username': 'test', 'password': 'test', 'appliance': 'name', 'hostname': 'hostname', 'prodcut': 'juice'} print "{} {} {} {} {}".format(**device_info) This…
-3
votes
1 answer

How to fix "Need more than 1 value to unpack"

I'm writing a program from "Learn Python the Hard Way - Third Edition" by Zed A. Shaw. I am new to programming and I am completely stuck on Exercise 12. Please look at my code and help me with what I am doing wrong, as for all I know it is exactly…
DamonT
  • 15
  • 4
-4
votes
2 answers

Splatpacking versus array_values() to re-index an array with numeric keys

As of PHP7.4, there is a newly available technique to re-index an array with numeric keys. I'll call it "array re-packing" or maybe something fun like "splatpacking". The simple process involves using the splat operator (...) -- aka "spread…
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
1 2 3
9
10