Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python unpack convert error #13

Open
asukaminato0721 opened this issue Feb 23, 2022 · 2 comments
Open

python unpack convert error #13

asukaminato0721 opened this issue Feb 23, 2022 · 2 comments

Comments

@asukaminato0721
Copy link

Describe the bug
A clear and concise description of what the bug is.

tuple unpack

Python code example
The simplest possible Python code example to demonstrate the bug.

def main():
  zz,*x = (0,0,0,0)
  print(zz,x)

if __name__ == '__main__':
  main()

Current behavior
What the program currently outputs for the code example.

package main

import "fmt"

func main() {
	zz, x := 0, 0, 0, 0
	fmt.Println(zz, x)
}

Expected behavior
A clear and concise description of what you expected to happen.

x becomes a tuple.

Go code example
Optional. An example of a satisfactory Go code output for the Python example.

this may helps

https://stackoverflow.com/questions/19832189/unpack-slices-on-assignment

@Elara6331
Copy link

The only way to do this in Go would be:

package main

import "fmt"

func main() {
	zz := 0
	var x []int
	x = append(x, 0, 0, 0)
	fmt.Println(zz, x)
}

I don't know how easy this would be to implement, but it seems like it would be pretty difficult.

@Elara6331
Copy link

Actually, I just realized, there is a better way that's probably a bit easier:

package main

import "fmt"

func main() {
	zz, x := 0, []int{0, 0, 0}
	fmt.Println(zz, x)
}

Don't know how I didn't think of this before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants