1

In django.core.management on row 133 there is a class defined with the following code:

class ManagementUtility(object):
    """
    Encapsulates the logic of the django-admin and manage.py utilities.
    """
    def __init__(self, argv=None):
        self.argv = argv or sys.argv[:]
        self.prog_name = os.path.basename(self.argv[0])
        self.settings_exception = None

...and so on.

  1. How can the variable self.argv be set to an expression which contains or?
  2. How is the statement self.argv = argv or sys.argv[:] evaluated?
Wronski
  • 1,022
  • 2
  • 12
  • 26
  • It's not set to an expression that contains `or`, it's set to *whatever that expression evaluates to*. It's not clear what part of that line exactly you do not understand. – jonrsharpe Jul 01 '17 at 20:52
  • and the evaluation of that is, take `argv`, otherwise take `sys.argv[:]` if `argv` is `None`. – idjaw Jul 01 '17 at 20:53
  • sys.argv[:] means all the arguments provided from command line – Arpit Solanki Jul 01 '17 at 20:54
  • @idjaw if `argv` is *falsy*. Which Is why I think it is better to explicitly check `if argv is None` – juanpa.arrivillaga Jul 01 '17 at 20:56
  • @juanpa.arrivillaga Agreed. But I didn't write the code :P I'm just explaining what it's currently doing. – idjaw Jul 01 '17 at 20:57
  • 2
    Yep. I think people try to get too cutsie sometimes. This one in particular drives me nuts. Just write the `if-else` statement people! It saves so little time using an alternative that isn't doing *exactly* what you want! – juanpa.arrivillaga Jul 01 '17 at 20:59
  • 2
    @juanpa.arrivillaga Yup!. If there is one thing I learned on SO, is that there seems to be some attraction to shove everything in to one line. Especially if you get to use the words "comprehension" and "lambda". Once you start throwing in requirements for testability and maintainability, that just bites you in the behind and the quickest way to get your code reviews rejected. Cute != good code. – idjaw Jul 01 '17 at 21:01

0 Answers0