Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Buffis
Apr 29, 2006

I paid for this
Fallen Rib
I don't really see the point but if I'm understanding this correctly, then this is nicer

code:
def dec(f):
    f.clowns = 1
    return f

@dec 
def f():
    print f.clowns

f() # prints 1

Adbot
ADBOT LOVES YOU

Buffis
Apr 29, 2006

I paid for this
Fallen Rib

deimos posted:

Yeah but what happens if you call foo(clowns=20)?

He didnt want to be able to do that?

quote:

but I'm wondering if there's a way to do it without having to place the `clowns` argument in the function definition for `bar`.

Buffis fucked around with this message at 17:23 on Jan 9, 2008

Buffis
Apr 29, 2006

I paid for this
Fallen Rib

Ferg posted:

I read this book cover-to-cover electronically, and then purchased a copy. Definitely a fantastic resource to learn the language.

Seconded. It is a really great book if you have some prior development knowledge in any other language.

Buffis
Apr 29, 2006

I paid for this
Fallen Rib
Is it weird to write a program only targeting Python 3 nowadays?
I know that the migration from 2 to 3 was in a weird limbo for years, but I don't really know what the state of things is nowadays.

Want to target mainly linux and OSX, but potentially also Windows (less important). All deps are available through pip in both Python 2 and 3.
There's some things in 3 that I'd like to depend on without having to implement backwards compatibility if possible though.
The app is terminal based if that matters.

Buffis
Apr 29, 2006

I paid for this
Fallen Rib

Dominoes posted:

Is there a reason why python doesn't implement numpy/matlab-style indexing with multiple keys or indices?

Ie for a list of dicts:
Python code:
adict[3, 'akey']
As a cleaner alternative to
Python code:
adict[3]['akey']

Tuples are (usually) allowed to omit the parenthesis, as in:
>>> a={}
>>> a[1, "hey"]=2
>>> a
{(1, 'hey'): 2}
>>> a[1, "hey"]
2

So the syntax mentioned above implies that a tuple is being looked up in a dict.

Adbot
ADBOT LOVES YOU

Buffis
Apr 29, 2006

I paid for this
Fallen Rib
Comedy answer:

code:
class LULZ(dict):
  "Don't do this"
  def __getitem__(self, plzno):
    if type(plzno) == tuple: dict.__setitem__(self, *plzno)
    else: return dict.__getitem__(self, plzno)

d=LULZ()
d[3, 'akey']
print d[3] # outputs 'akey'

  • Locked thread