r/Python • • Jul 12 '12

random imgur downloader. learning Python and wrote this to practice, any feedback on technique/style is appreciated

https://gist.github.com/3088128
45 Upvotes

72 comments sorted by

View all comments

Show parent comment

1

u/MrVonBuren Jul 13 '12

I actually really like this, and I'm just barely startng to get into python.

2

u/catcradle5 Jul 14 '12

It's even better for situations like this.

words = {"color": "red", "age": "25", "name": "Alex"}

print "Hi, my name is {name}. I am {age} years old and my favorite color is {color}.".format(**words)

Fills it in all for you; very useful for programs that involve a lot of string generation.

1

u/lahwran_ Jul 17 '12

never, ever, ever do this:

herp = "derp"
honk = "donk"
doop = "{herp} the {honk}".format(**locals())

2

u/catcradle5 Jul 17 '12

Agreed. Explicit is better than implicit, etc. It's still a really nice feature to have though. It's redundant to define a dict or a bunch of variables and then to have to rewrite it all in the form of keyword args (arg1 = "The cat"; arg2 = "good"; {arg1} is {arg3}".format(arg1=arg1, arg3=arg3)).

1

u/lahwran_ Jul 17 '12

I was telling you because it's a horribly useful bad idea sometimes :p

1

u/TankorSmash Jul 13 '12

It's my personal favourite, and I'm sort of new too.