OpenPayments Developer Contest

how are these two variables unpacked?

Through tutorials I had learned that you can define two variables in the same statement, e.g.:

In [15]: a, b = 'hello', 'hi!'

In [16]: a
Out[16]: 'hello'

In [17]: b
Out[17]: 'hi!'

well how does that apply to here?

fh, opened = cbook.to_filehandle(fname, 'w', return_opened = True)

I prodded further:

In [18]: fh
Out[18]: <open file 'attempt.csv', mode 'w' at 0xaac89d0>

In [19]: opened
Out[19]: True

my issue comes really with 'opened'. Well normally if two variables are being defined, there would be a comma and then whatever is there would define 'opened.' This is not the case. Even with that issue looming, 'opened' is equal to True which I assume is because 'return_opened = True.' Well that's weird because I don't remember in any tutorial that you could just add a 'return_' before a variable to affect that variable.

I play with it some more and I change the True to False and I get this:

In [10]: fh, opened = cbook.to_filehandle(fname, 'w', return_opened = False)
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)

/home/blahblahblah/Documents/Programming/EXERCISES/piece.py in <module>()
----> 1 
      2 
      3 
      4 
      5 

IOError: [Errno 9] Bad file descriptor

so I guess it only accepts False.

I guess I'd like if someone could explain what is going on here.

Gracias amigos!



Bookmark and Share   Read more Read more...   Source: Stack Overflow