-2

I was wondering if there is a decent way to avoid repeating "IGNORED" when assigning it to multiple values in python, something like *"IGNORED" maybe:

raw_size, size, content_type, last_modified, error = "IGNORED", "IGNORED", "IGNORED", "IGNORED", {}

I got this link but it was not quite the answer I was looking for.

4
  • 1
    raw_size = size = content_type = last_modified = error = "IGNORED" ? or raw_size, size, content_type, last_modified = ('IGNORED',) * 4 ? Commented Mar 28, 2021 at 18:28
  • Because the last variable, i.e. error should be a different value, i.e. {} Commented Mar 28, 2021 at 18:30
  • 2
    This doesnt appear good to me but you could do a, b, c, d = ('IGNORED',) * 3 + ({},) Commented Mar 28, 2021 at 18:34
  • a, b, c, d = ('IGNORED',) * 3 + ({},) works fine, Thanks. And I would be thankful if you tell me why that doesnt appear good. Commented Mar 28, 2021 at 18:40

2 Answers 2

3

If you insist,

raw_size, size, content_type, last_modified, error = ('IGNORED', ) * 4 + ({},)

might work.

Sign up to request clarification or add additional context in comments.

Comments

1

What you're looking for is:

raw_size = size = content_type = last_modified = "IGNORED"
error = {}

If this isn't what you're looking for, please rewrite your question to have more clarity.

3 Comments

This is working, but I was looking for a way to do it all in one line.
If I may ask, what's the reason behind that?
No special reason. I just personally prefer fewer lines. And I'm realizing it is not always a good idea!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.