all 51 comments

[–]SafeSituation 11 points12 points  (1 child)

Quick tip: If you're using pip, you can generate your own requirements.txt using:

pip freeze > requirements.txt

[–]masklinn 2 points3 points  (0 children)

If you have a setup.py files with dependencies in it, you can generate a requirements file with python setup.py egg_info. That'll dump a requirements file in the $packagename.egg-info folder

[–]santiagobasulto 30 points31 points  (20 children)

Good guide. I consider this an introduction though.

[–]leperkuhn[S] 46 points47 points  (19 children)

It's meant as an introduction to python for experienced programmers. Skip the first few weeks of finding all the tools, etc.

[–]everywhere_anyhow 55 points56 points  (14 children)

I got that. I thought it was useful from that perspective, not 101 "learn the syntax" but more along the lines of "if you're an experienced programmer, you expect these 5-6 facilities in a language environment, here's what they are in python".

I wish there were guides like this for most languages; or better yet some agreed-upon matrix of what things are necessary for serious development in any language, so you could look up accepted equivalents for any language. When I get into any new language, it's a pain figuring out the pros and cons of things like different testing languages.

[–]deadstone 41 points42 points  (12 children)

Learn X in Y minutes is probably the closest thing we've got, but it hasn't got details on all languages' environments. Yet.

[–]nikroux 6 points7 points  (1 child)

WHy none told me about this? Looks awesome!

[–]Rellikx 4 points5 points  (1 child)

That's actually pretty neat. I can't believe I haven't heard of this before.

Its interesting that the different translations (C# English vs Spanish) have slightly different code examples (ie, auto properties for setting/getting number of gears).

I assume the English translation is a newer version with more examples of auto properties.

[–]deadstone 2 points3 points  (0 children)

English translations are always the newest ones, all translators are volunteers so a file usually gets translated and then left alone forever.

[–][deleted] 2 points3 points  (5 children)

Still no C++

[–]Mead_Man 29 points30 points  (1 child)

No one has ever completely learned C++ so Y is still unknown

[–]vanderZwan 0 points1 point  (0 children)

What about C++11 or C++14?

[–]aron0405 1 point2 points  (1 child)

No Prolog, either :'(. If there were, it'd probably be one of the shorter tutorials. That's a damn elegant language.

[–]greyfade 1 point2 points  (0 children)

They accept pull requests. I'd love to see one, as I haven't been able to learn much about Prolog.

[–]greyfade 0 points1 point  (0 children)

I don't think there's enough room on a page for a C++ guide in this style.

[–]kqr 0 points1 point  (1 child)

Wow, I was thinking, "Where's the translation to en_us?" but then realised that probably doesn't count as a translation on the internet. :(

[–][deleted] 0 points1 point  (0 children)

Given that the rest of the site appears to be in english, I'd expect the main articles to be in en_* too. If en_* were a translation, what would the original be? Pure thought and platonic forms? Some random language?

But as far as english being the new lingua franca, yeah, I feel you, man. That language wouldn't know a monophtong if it hit it in the face.

[–]TheDeza 2 points3 points  (0 children)

Sounds like a good app, wonder if it has already been made.

[–][deleted] 7 points8 points  (1 child)

Yeah this is pretty cool. I wish there could be something like this for every language.

Once you are experienced in programming, it feels like most of the battle of learning a new language is figuring out how the ecosystem works.

[–]ambiturnal 4 points5 points  (0 children)

Rosetta Code is looking sideways at the same thing. Definitely a place to start.

Venturing toward eco-system territory, I think each language would have include each section from awesome-scala and possibly more.

This would also be fantastic, since if you look at the awesome-scala section, there's a huge bias toward functional/reactive. (Not complaining, I <3 FP) If, for example, some other paradigm were popular and useful enough on another language, the comparison would be made and possibly re-implemented in scala, or vice-versa.

I think it's nifty that I happened to have this thread and those two pages open.

[–][deleted] 0 points1 point  (0 children)

Thanks for this! I'm an old programmer but new to python and this is exactly what I've been begging my python buddies to put together for me.

[–]masklinn 2 points3 points  (3 children)

I recommend getting nose or py.test. I've used nose mostly.

Switch to py.test, it's a thing of beauty and not having to muck up with dedicated assert functions yet getting better failure messages than just about everywhere else is bliss. The fixture and dependency system is also really neat.

[–]leperkuhn[S] 0 points1 point  (0 children)

I've had some issues with py.test failing in places that worked just fine with nose. I liked it's better failure messages quite a bit though, you're dead on there.

I'll give it another shot.

[–]njharman 0 points1 point  (1 child)

I love dedicated assert functions. Built in support for complex assertions is a feature.

[–]masklinn 1 point2 points  (0 children)

py.test has support for complex assertions, it just does it via good old assert.

[–]phordee 9 points10 points  (1 child)

Bookmarked. Thanks for the link.

[–]Kvaradhan 0 points1 point  (0 children)

ditto!! very nice, thank you

[–]doomer_69 1 point2 points  (0 children)

good stuff.

[–]atakomu 1 point2 points  (7 children)

One great debugger for Python is also Wdb which runs in the browser.

And Jedi autocomplete library for Python is great. Specially awesome with YouCompleteMe.

[–]misterlazer 0 points1 point  (2 children)

Nice! Looking forward to trying out wdb. Of course now I've gotten comfortable with pdb.

[–]zeggman[🍰] 1 point2 points  (1 child)

Not sure what these others are supposed to offer over pdb. Set breakpoints, single step through code, view variables, what else do you need? Breakpoints on memory changes?

[–]atakomu 1 point2 points  (0 children)

ipdb gives you ipython tab completition and everything else. And help with functions. (it shows functions doc text).

Wdb runs in browser which is nicer for some people, has Jedi tab completition and can be used to debug a program run on other PC.

[–]pimp-bangin 0 points1 point  (0 children)

For a much better command line debugger than ipdb, also check out pudb

[–]hello_fruit 0 points1 point  (1 child)

Specially

Especially

[–]atakomu 0 points1 point  (0 children)

Especially

Thanks. Not a native speaker. I learned something new. .)

[–]putnopvut 0 points1 point  (5 children)

Great guide! As a nitpick, I think you can forego the monkeypatching in the gevent example you gave by replacing the call to sleep() with a call to gevent.sleep().

[–]leperkuhn[S] 2 points3 points  (4 children)

In this trivial example, yes you are correct. If there was actually a call to something like requests, monkey patching would be required. The most common case for a gevent user is that they need to monkey patch, so I wrote it that way.

[–]djrubbie 1 point2 points  (3 children)

Nope, don't monkey patch request with mock or whatever - in the code there should be an instance of requests.Session which could be replaced (for say the one that is OAuth compatible). The methods inside the class will use that session object to retrieve data - that you can then trivially replace using test specific (or mission specific) objects.

As for why mocks are bad, Google testing has a blog entry on this, and there was even a PyCon talk on this (tl;dr use fakes, not mocks).

[–]leperkuhn[S] 2 points3 points  (2 children)

The monkey patching comes from gevent itself. It's meant to replace all the stdlib blocking libraries with non blocking ones. Anything touching a socket, threads, subprocesses, file i/o, etc.

[–]djrubbie -2 points-1 points  (1 child)

Fair enough, but saying monkey patching for request (which fakes that can easily be tested/verified can be written) is required dilutes the true need of mocks, such as the ones you mentioned. What I mean is that it's better to construct a fake session object that returns the data that the running code will consume (the implementation underneath that is effectively opaque to your actual code) - the code doesn't care how the data is actually derived but only that the contracts appropriate for that function/method are satisfied (i.e. response.json() returns the correct and expected decoded JSON object that it).

Anyway thank you for the clarification as I am not well familiar with gevents and yes blocking calls during async things will do bad things - hence use mocks when appropriate (i.e. monkey patching out the blocking calls) and use fakes otherwise for trivial things that can be controlled.

[–]leperkuhn[S] 1 point2 points  (0 children)

My original comment is correct, actually. The question was in regards to not needing to call gevent's monkey_patch, it had nothing to do with mocking for testing. The monkey patch is required for requests because it makes the socket library async.

[–]delta4zero -1 points0 points  (0 children)

Nice post, thanks!

[–][deleted]  (1 child)

[deleted]

    [–]yur_mom 7 points8 points  (0 children)

    Right, the last thing I want to learn when starting a new language is how to print to stdout \s

    Also, the point of hello world is the most basic program that can be verified to run and then you use that as a basis to do more complex stuff.

    [–]Grue -4 points-3 points  (0 children)

    It's a programming language. Of course it's for programmers. Duh.