Python - Yahoo News Search Results

Python Challenge will return to Florida Everglades in 2016

Florida is bringing back a public hunt for invasive Burmese pythons in the Everglades.  The Florida Fish and Wildlife Conservation Commission plans to hold the next Python Challenge early next year. Registration opens in October. About 1,600 people participated in 2013 during the first month-long python hunt on state lands. Most of the 68 pythons collected were caught by experienced hunters ...

Stephen Hawking sings Monty Python

'Monty Python': Where are they now? 7 photos From left, Graham Chapman, Eric Idle, Michael Palin, Terry Jones, John Cleese and Terry Gilliam (foreground) in 1975's "Monty Python and the Holy Grail."

Stephen Hawking sings Python song

Famed cosmologist Stephen Hawking has proved his comedy chops on shows like "The Big Bang Theory," and now he's trying his hand at musicals.

Stephen Hawking Covers Monty Python Classic

Last year he appeared on film during Monty Python's live shows, but now Professor Stephen Hawking can be heard covering one of the comedy troupe's classic songs. The physicist sings the famous Galaxy Song, which is being released digitally this week and will be available on vinyl this weekend as part of Record Store Day 2015. In the video, the A Brief History Of Time author can be seen whizzing ...

How Monty Python and the Holy Grail Influenced Film by Satirizing It

Any writer, comic or otherwise, can attest that beginnings are the hardest part, but Monty Python never seemed to have that problem. Television was still chintzy and cheerful when Monty Python first aired in 1969, so to satirize it, the show had to be as dramatic as possible. The trappings of film are inherently epic, particularly in 1975, and in scraping together the funds to make Holy Grail ...


recent bookmarks tagged Python

Why is Python used for high-performance/scientific computing (but Ruby isn't)? - Programmers

Posted on 18 January 2038

Posted on 3 April 2015

Posted on 3 April 2015

Posted on 3 April 2015

Notebook Gallery

Posted on 3 April 2015

Python Programming Resources -

Posted on 2 April 2015

Here's a big list of Python Programming resources : learnpython

Posted on 2 April 2015

Valued Lessons: python

Posted on 2 April 2015

Python - 十分鐘入門 « I try | MarsW

Posted on 2 April 2015

Talks and Presentations

Posted on 1 April 2015

Top Answers About Python (programming language) on Quora

Top Answers About Python (programming language) on Quora

Should I learn C++ or Python?

Are you asking "Should I learn (C++ or Python)?" or are you asking "Should I learn Python or should I learn C++?"? See how annoying it is when something even so simple can be interpreted differently by a compiler? C++ is like that. Python is easier to learn and reads better. That said, C++ gives you a LOT of individual power as a programmer to make stack-level and system-architecture level decisions, which is not possible with Python very easily. While memory management is a pain, in some cases it's good to have that kind of power if you can use it. If not, better stick to Python.

See Questions On Quora

Posted on 4 August 2015

To make a career in web development is it necessary to learn Python?

No. For web development, knowing Javascript and one or more Javascript frameworks like AngularJS, BackboneJS or EmberJS is perhaps more important than which backend language you use.

This past year I've built web apps using Ruby, Python, and C# (Backbone & Angular for UI). Each backend languages has its pros and cons. I'm currently building a product using Python against Google's Python NDB Datastore for a local Google partner.

All things equal, if I like my teammates, and the product we're building seems worthwhile, the backend language doesn't matter to me much.

Pushed to choose my framework/language preference would be an AngularJS front-end with Ruby on Rails as the backend. I'd give Ruby the slight edge over Python because the Ruby community tends to be more helpful. I love C#, but the .Net community seems broken by comparison.

See Questions On Quora

Posted on 30 June 2015

Which is better, Perl or Python?

I like and use both,  few quick points:
  • Python is easier to learn, Perl takes a while to get used to and is not intuitive. Perl is great, if you already know it.
  • I use Perl to write quick scripts using regular expressions, to perform text/data manipulations. If there is anything Perl can do well, it is string manipulations.
  • I use Python for writing reusable code. I personally think OO in Perl is a little odd, and find Python to be more consistent. For example, I find it easier to create modules in Python.
  • Perl scripts are often messy (it takes me a while to understand my own scripts), whereas, Python is very clean.

I can't think of anything that you can do with Perl that you can't with Python. If I were you, I'd stick with Python.

See Questions On Quora

Posted on 20 May 2015

I am new at programming. I've taken two semesters of C++ but I need to learn a language that I can completely use. I think I'd love Java and Python but Should I learn Java first or Python?

"Fully understand"

This is an unrealistic expectation. You should focus on "can use competently."

Python is a tremendously useful language, especially for quickly executing time saving utilities like process automation. If you are picking a second language to learn it's a great choice.

See Questions On Quora

Posted on 9 May 2015

Can an operating system be written completely in Java or Python? What are the difficulties associated with writing an OS in Java or Python?

An OS has to run on top of the hardware. High level languages like Java and Python run in a VM, and a VM runs on top of an OS. Technically, you cannot take a JVM and turn it into an OS.

If you do want to write an OS in Java/Python, you will have to first implement a compiler that takes Java/Python code and converts it into machine code. And that means you will have to implement a compiler for each kind of hardware that it will run on

Of course your Java/Python program needs access to the underlying hardware too right? But these programs are designed to work at a level of abstraction above the OS. For example, a FileOutputStream assumes that there is an OS that manages the file system. However, if you don't have an OS, you don't have a file system. Your OS has to provide the file system. This means that your code will need some way of sending commands to the disk. This means you need to provide API that can send commands to the disk.

Essentially, this means that you have to throw away all the APIs that are specified by Java/Python, and come up with a whole new native API that can access the hardware.

What you will end up with is a new language that is uses Java/Python syntax!

See Questions On Quora

Posted on 7 May 2015

Why do websites like Facebook and YouTube use a mixture of different programming languages? Eg. C++, Python, Java

Those are sophisticated products with many complex moving parts, hearing them called "websites" (like they're WordPress blogs) makes my head vibrate!

As these are usually a result of clever integrations of isolated services, each of these services have special requirements and as such often require specific toolchains.

Also, each of these isolated services often have dedicated teams with different core competencies so the carpenters grab the hammers they are most comfortable with.

Another thing to take note of is that these products are powered by innovative companies who might take advantage of specific situations to pioneer a new technology (e.g HipHop making Facebook's PHP play it cool on a C++-based infrastructure -- if I'm correct).

There's no godfather programming language to "rule 'em all," so in sane scenarios you usually end up using the best tool for each component.

I must point out that the definition of "best" is usually determined by sensitive tradeoffs involving maintainability, cost, time to market, efficiency, performance, community/enterprise adoption, and other similar factors.

See Questions On Quora

Posted on 24 February 2015

Does Google hire programmers who use Python as their main programming language?

Can you get into Google as a smart programmer whose main language is Python? Yes. That said, you're going to want to learn C++ if you're planning for a career in Google, because it's the most respected of the "Google Languages" (Go was too new for me to evaluate in that regard, when I was there) and the machine learning projects are most likely going to be using it. Python's reputation is that it's not fit for production, and Java would make you a Java programmer. (Doing Java at Google-- at least, as of my experience which is 3 years dated, but I doubt much has changed-- means actually writing Java, not Scala or Clojure, so the cool kids write C++ and you should too.) The good news is that Google C++ is a lot more civilized than C++ in the wild. Google has some rotting projects but, averaged across the company, code quality is pretty damn high there. So the C++ that you encounter will probably be better than what you'd expect in a C++ shop.

See Questions On Quora

Posted on 10 February 2015

How do you identify a good programmer?

A good programmer is someone who understands the larger picture of programming. Not just from a technical perspective. They know multiple methods of solving a problem and can pick the best one. They know when to use existing libraries/source and when to tackle a problem themselves. They can balance clarity and complexity. They know when to optimise and when not to. They understand that maintaining messy code is far more painful and takes far longer than initially writing it. They also understand where to put in effort and when to give up on something.

I once worked with a guy who described himself as a 'hacker'. He was knowledgeable about programming and could get things done, but he refused to change is attitude regarding comments, style and naming conventions. Basically his code was an impenetrable, commentless mess of single-letter global variable names, short cryptic function names and inconsistent non-conformist style. That's cool if you are working alone and nobody has to see what you've written. But that kind of attitude has no place on MY team.

I would take an amiable programmer who produces slow clear code to an egotistical rock-star who produces fast but buggy obfuscated gibberish any day.

See Questions On Quora

Posted on 24 January 2015

Why do many people programming in artificial intelligence choose Python and JavaScript?

There are two main reasons:
  1. Good frameworks. Python has scikit-learn: machine learning in Python, which fulfills almost every need in this field. There's also D3.js - Data-Driven Documents in JS, which is one of the most powerful and easy-to-use tools for visualization.
  2. Fast prototyping. Artificial intelligence is 80% research, so if you need a 500 KB boilerplate code in Java to test a new hypothesis, you will never finish the project. In Python almost every idea can be quickly validated through 20-30 lines of code (same for JS with libs).

See Questions On Quora

Posted on 4 December 2014

As a starting Python programmer I see a lot of praise for the Python language (and so far I can only agree). Isn't there anything bad to say about it? What is a real con?

Python s fantastic in many ways.  It's very clean in many ways, and the huge number of modules make it a snap to do electrical engineering, Fourier transforms, data plotting, reading/writing excel spreadsheets, doing 2D and 3D graphics, and much more, with a very few lines. 

But if there isn't a built-in feature or plug-in module and you have to write a complex and explicit loop to do something, it can be a bit slow.  What I do is google "How in Python can I swap rows and columns" and someone will very often have an answer of a built-in that will do the trick very quickly.

As an example of a success then a failure, I needed to parse a huge 33 gigabyte text data file and collate the data.   It only took about 60 lines of Python to do all the work.  However it took many minutes to run, and it eventually used all 4 gigabytes of memory and hung.

I had to rewrite the code in Delphi, and that program was more like 600 lines, but it ran about 10 times faster and used about 1/4 the memory.

So Python is very good in many ways, it's just not a solution for every problem.

See Questions On Quora

Posted on 29 October 2014

What are some cool Python tricks?

Python 3 supports Unicode identifiers:

Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import math
>>> π = math.pi
>>> π
>>> Σ = sum
>>> Σ(n for n in range(1, 101))

Also IPython Notebook is a pretty neat "trick" - generally because it's what literate programming deserves to be, but especially because the editor is web-based and allows you to work from your tablet and still use the processing power and storage of a (super)computer :)

See Questions On Quora

Posted on 16 October 2014

What are some great questions testing knowledge for someone new to Python?

The best question you can ask for testing someone's knowledge are those which are most relevant to your goals.  In a job interview you're trying to predict how well this person will perform the work and interact with your team, your customers, or others in your business environment.  In an educational context you may be attempting to assess their readiness for a given course, their progress through some material, their worthiness for some grade or certificate of achievement.

In other words I don't know that any questions are inherently "great" because I don't really know your purpose for posing them.

You say "for someone new to Python."  Why are you asking a novice questions?  Do you want to see if they have some pre-requisite skills or aptitude before you invest time and effort into trying to teach them this particular language?  Do you want to discourage them from learning it?  Do you think their are some questions which might pique their curiosity and, in some Socratic way, inspire them to deep insights?

Here are some questions I'll put forth in my ignorance of your goals:

  • What is the difference between a statement and an expression?
  • Why is Python's print a statement rather than a function or expression?
  • What would be different if Python implemented print as a function?
  • What does the statement if __name__ == '__main__': do and why is that important?
  • What advantages are there for using the following header in your Python scripts: #!/usr/bin/env python? Under what circumstances would you omit such a line and when and how might you change it?
  • What's the difference between an "argument" and a "parameter?"  Is that distinction important?
  • Why should you use if something is None (or is not None) in lieu of something == None or something != None?  How would you create a sentinel value for some case where your code might have to handle the None singleton?
  • Why are for loops so much more common than while loops in common Python usage?
  • How is the with statement used in Python and how would you implement a class such that it was suitable for use with with?
  • What is __dict__ and when would you see an instance that lacked this attribute? What attribute would you seen instead of __dict__ in such cases?
  • How do you define objects in Python?  How do you instantiation them? What's the difference between defining classes and instantiation?
  • Why Isn't the __init__() method a constructor? What would you use as an object oriented constructor method or hook in Python and when would you use it?
  • Why does the list.sort() method return None and what alternatives do you have when you want to return a sorted sequence within an expression?
  • Have you heard of the "decorate, sort, undecorate" (DSU) pattern?  Why would you use it?
  • Why are Python strings and tuples immutable?  When is this important?
  • If a colleague showed you some code which looped over some data to iteratively built a result string, and complained about the its run-time performance, what would you recommend?
  • What's an exception and why are the standard exceptions defined in a class hierarchy?  How do you define and use custom exceptions and learn about any exceptions defined by any modules that you're using or software that you're maintaining?
  • How do you use regular expressions in Python?  Can you use shell "globbing" (wild card matching) from within Python?  If so, how?
  • Consider a function being defined like: def somefunc(anarg, otherarg=[]): ... what's different and notable when somefunc() is called with only one argument vs. two arguments?
  • How do you implement a function taking a variable number of arguments in Python?  (Compare to C's varargs mechanism?
  • Are Python functions "call by value" or "call by reference?"
  • What's the difference between a generator and an iterator?
  • What is a list comprehension?  What other types of comprehension are supported in Python?
  • What are the most important differences between a list comprehension and a generator expression?
  • Does Python support any syntax similar to the "ternary operator" in C, Perl and some other languages?
  • What is the Python form for a "case" or "switch" statement?
  • Why do Python for and while loops support an else: clause and how might you use it?
  • In Python what is a "static" method or attribute (member) and how this differ from normal methods and members?  How
  • How can you create a class that behaves like a list?  Like a "mapping" (dictionary)?  Could you create a class that offers a mixture of sequence and mapping features supporting iteration, member testing (the Python in operators) and other features?  How?
  • How might you create a class whose instances behave like functions (are callable)?
  • How, why, and when should you chain the initialization of any of your classes up into their parent classes?
  • How would you implement an "abstract" or "virtual" class in Python?
  • Whats are the salient differences between "binding" and "assignment" and the difference between a Python "name" and the concept of a "variable" in most other programming languages?
  • What is "composition" and how does it compare to inheritance?
  • How might you implement the "SIngleton" pattern in Python (from the "gang of four" Design Patterns book)?
  • What is "duck typing" and how is it used in Python?
  • What's a decorator and how would you implement something like a decorator in an older version of Python ... before the feature was added to the language?  Do any of the Python standard libraries use decorators?
  • What is "blocking I/O" and how can you do non-blocking I/O in Python?
  • Does Python including any features or modules in its standard libraries to facilitate "test driven development" (TDD)?  Are there any third party modules which are likely to be useful for code testing?
  • What are the important differences between multithreading and multiprocessing in Python?  How do you use multiple threads and when should you consider using the multiprocessing module?
  • What is the GIL and are there versions or implementations of Python that are unaffected by it?
  • What are some other alternatives to threading and multiprocessing?  How can one do "event driven" programming in Python?
  • What is the Python alternative to the C standard library function named sprintf() and how do you use it?  What are some alternative string formatting and template rendering options for Python?
  • When might you use the subprocess module instead of multiprocessing and why?
  • Have you ever used the mmap module?  What are the primary uses for memory mapping under Unix and similar operating systems?
  • What are some ways to share memory among multiple Python threads or processes?
  • What's the most concise way that you might return a list of the letters in common between two words?  How might you find the list of letters NOT in common between them?
  • What is ipython and why would you use it?
  • If some module was working in a Python script but raised import errors when trying to use it in ipython or in some other script or program ... how would you troubleshoot and resolve the issue?
  • What are some standard library modules you might use in a web scraping program that you were writing in Python?  Are there any third party modules you might consider using?
  • Where would you look for third party Python modules?  Does Python have something like Perl's CPAN or Ruby Gems systems?
  • What is a PEP and why would you care?
  • What's the difference between input() and raw_input() in Python 2.x and earlier, and how would you adapt code using the old input() builtin to run correctly under Python 3.0 or later?
  • What is a "mix-in" class?  How are they used in Python?  Are there any examples included in the Python standard libraries?
  • What is the MRO (method resolution order) for multiple inheritance for Python?
  • Can you summarize Python's LEGB scoping rules?
  • How do you access SQL database services under Python? Are there any standards to provide portability and consistency among different SQL modules for Python?
  • What is an SQL injection vulnerability and how do you avoid these in Python?
  • What's an ORM and are there any notable ORMs for Python?
  • What is WSGI?
  • What is Pexpect?  Paramiko?  Twisted?

(Incidentally the third item on this list is a bit of a trick question).

This definitely progresses very rapidly beyond what a novice could reasonably be expected to know.  I've put a little effort into making it somewhat progressive and trying to pick questions which would pique curiosity and encourage discussion.  Most of this wouldn't be appropriate for a job interview.

See Questions On Quora

Posted on 17 June 2014

Will Python suffer the same fate as Perl?

Not yet.

I think it turns out that Python 3 was a bad move strategically. But it's not the disaster that Perl 6 was because it noticably "exists". Whereas Perl 6 was vapourware for a long time. And Python 2.7 and 3.x continue to develop similar libraries in parallel.

 Worse still for Perl 6. Its first implementation was written in Haskell, which got Perl programmers thinking about Haskell. After which there were fewer Perl programmers.

So I don't think that Python programmers are going to fall out through the gap between 2.x and 3.x.

Still, it's a regrettable confusion. I suspect Python will continue with people recognising that it comes in two different "dialects" much as people accepted that there were different dialects of BASIC. And eventually one will just quietly die.

See Questions On Quora

Posted on 14 June 2014

What are some cool Python tricks?

Problem: you're calling a function that returns a list of results when you know that there's only one result.  It will be a singleton list, but you don't want to bother with that--- you just want the value of the one item.

Pedestrian solution: put a [0] at the end of the expression:
result = getResults()[0]

Slick solution: put a comma (,) at the end of the variable:
result, = getResults()

Why does this work?  The trailing comma turns the variable into a single-element tuple.  When you assign to a tuple, Python unpacks whatever is on the right-hand side into each element of the tuple.  (You've probably seen
x, y = first(), second()

or something like that.)  In this case, it unpacks the only item.  If the function actually returns 0 or more than 1 result, you'll get a ValueError ("need more than 0 values to unpack" or "too many values to unpack").  If you had used the pedestrian method with the square brackets, you'd get an IndexError.

I find that I need to unpack things quite often, and it's good to have little idioms like this to remind yourself of your assumptions.  (In this case, the comma indicates that you expect exactly one result; a [0] would suggest that you expect at least one result.)

See Questions On Quora

Posted on 22 May 2014

When, why, and to what extent did Bank of America rebuild its entire tech stack with Python?

Below is an answer I posted to a very similar question.....Why are banks like JP Morgan and Bank of America Merrill Lynch using Python to replace historic legacy systems built in Java/C++?

My answer should give some colour on the reasoning for using Python for Quartz and Athena (JP Morgan's equivalent project).

Here you go:

I am not technical and don’t write code (yet), so I’ll leave it to others to cover the low level technical details for Python’s adoption.

From a high level perspective, the decision to go with Python to rewrite core systems at firms such as BOAML and JP Morgan is to build a more transparent and collaborative system in firms that have people of varying technical ability and who’s chief role is not always to write software.

The 2008 financial crisis will be remembered as the year of terrible events at corporate and systemic level. Banks up until this point failed due to a lack of collaboration.

Despite what might seem as a logical step to those in the tech industry of building one Risk management system across all individual business areas and so creating a greater level of transparency and leveraging economies of scale, banks continued until 2008 to build individual risk management systems that didn’t talk to each other. Various reasons for this, but essentially it prevented collaboration. 

Since 2008, the major banks have embarked on a roadmap for a true enterprise front-to-back, cross-asset, ‘best of breed’ systems. This is no longer the sole agenda of technology teams but is also necessitated at boardroom level and demanded from external institutions that look for transparency for us, the tax payer.

Since early 2009, JP Morgan have been rolling out the Athena Platform (a Python along with C++ and Java for speed), a cross-market risk management and trading system.

BOAML after the merger between BOA and ML also decided at management level to also build a similar system to Athena called Quartz.
At this juncture, it’s JP Morgan and BOAML that are the two banks using Python in anger.

Ironically, or maybe deliberately as there is some legal issues around this: both senior managers spearheading the move to cross asset risk at JP Morgan and BAOML had initially worked at Goldman Sachs.

As a bank, Goldman Sach’s proprietary risk management platform built using SecDB/Slang has been seen in the eyes of many as having done a better job in comparison to its competitors. SecDB is a GS prop database and Slang is a lightweight scripting language similar to Python/Perl with the ORM layer baked in.

Not much is known of Slang/SecDB because it’s a prop language/DB, but one of the major advantage noted of Slang (like Python) is its lightweight language that anyone can get up to speed with in a short space of time. Also, given that Slang is used everywhere at GS front/middle/back office, it allowed 15 years ago something multiple systems at other banks built using multiple languages couldn’t do - collaboration. May seem trivial these days, but GS as a bank could, with ease, do database replication allowing changes in London to be seen in Tokyo almost instantly.

Just like Slang, Python is a simpler (ish) language than C++/Java for people that don’t have a strong grasp of software engineering and when choosing to build a true enterprise front-to-bank cross asset risk systems for the new financial era, JPM and BOAML have opted for Python.

See Questions On Quora

Posted on 14 April 2014

If I had to choose between learning Java and Python, what should I choose to learn first?

The fact is, you may have to learn both in the end if you are determined to pursue a career in the IT field, so the order of learning is what matters here.

I think Python is more friendly to novices, and this is why it is sometimes called 'executable pseudo code'.

For software engineering, Java is more widely used, as for larger applications, a compiled language is way efficient than an interpreted language such as Python.

For doing data science, Python is more powerful with its libraries such as numpy, scipy, sklearn and so on, although Java also has some awesome packages.

Hope this helps.

See Questions On Quora

Posted on 13 April 2014

What are some common mistakes that could slow down one's Python scripts?

Repeatedly adding elements to the beginning of a list:

results = []
for i in range(1000000):
    results = [f(i)] + results

This requires copying the whole list (so far) 1000000 times, taking quadratic time. It's better to construct the list in the opposite order and then reverse it, which only takes linear time:

results = []
for i in range(1000000):
    results += [f(i)]

See Questions On Quora

Posted on 27 February 2014

How do I get interested in programming in Python if I find the experience dull, boring, tedious and hard?

Start programming in C/C++ and make the transition to Python. Believe me, you'll get really excited!!!

Edit. So I've been a little tongue and cheek with my response here and for some people this is true, but in your case I'd actually recommend that you investigate why you dislike it, if you truly find it dull and boring, then do something else!!! Life's too short to waste on things you don't care about !!!! Good Luck!!!

See Questions On Quora

Posted on 28 January 2014

How can I email multiple people on their Gmail accounts using a Python program?

You can do this:

import smtplib

#this is your list of email addresses to which email has to be sent.
addresslist = ['',''] 

fromaddr = ''

for address in addresslist:
    toaddrs  = address
    TEXT = 'This is a test message sent from python'
    SUBJECT = 'python test'
    msg = 'Subject: %s\n\n%s' % (SUBJECT, TEXT)

    # Your gmail Credentials
    username = '
    password = 'your_email_password'

    # Sending the mail
    server = smtplib.SMTP('',587)
    server.sendmail(fromaddr, toaddrs, msg)

Hope that helps!

See Questions On Quora

Posted on 11 January 2014

Does Python (Programming Language) pass a variable to function by-value or by-reference?

Everything is passed by reference:

>>> def id(x):
...     return x
>>> x = 9203409249024
>>> x is 9203409249024
>>> x is id(x)

Keep in mind that in Python
x is y
returns true if the two sides evaluate to the same object; that is, it checks pointer equality.

This creates a variable x that holds some large integer value (small integers don't work here, because their storage is reused). x is not the same as a new instance of the same integer, but it is the same as itself passed back from a function. You'll see the same behavior with any other type, as far as I'm aware:
x is id(x)
will always return True.

Although everything is passed by reference, you don't normally see that because instances of primitive types like integers, strings, and booleans cannot be modified, so the only way to tell whether they were passed by value or by reference is by using
—and even that won't always work, as Python may reuse the same object if it's immutable anyway. Types like lists and objects, on the other hand, are mutable, so you can directly observe the call-by-reference behavior by doing something like
x[0] = 1

It's important to distinguish between a variable and the value it is holding. A function can put a different value inside a variable used as an argument, like this:
def foo(x):
    x = 42
    return x

and calling
won't modify the variable y in the calling code, whether it's an integer or a list. However, if y is a list and foo does something like
, that will modify the list stored in y, since the same underlying object is passed to the function.

One confusing point is the
operator. It works both on integers, where
x += 1
is basically equivalent to
x = x + 1
and therefore simply puts a new value inside the variable (and similarly for strings), and for lists, where
x += [1]
is equivalent to
: a method call that modifies the list in place. In my mind, this is a minor design flaw in Python.

See Questions On Quora

Posted on 5 January 2014

What is the difference between Scala and Python?


I'm not an expert, but I'll share my experiences using them.  These lists combine both bad and good things, some may be both.


  • Has nice pattern-matching syntax. The NLP guys like this.
  • Forces you to start thinking like a software developer rather than a scripter
  • Compilation speed is irritatingly slow.
  • Gets you into transition from mutable to immutable data structures.
  • Is really easy to make it hard to read. It's both great and terrible that you can just string together so many functions.
  • The sheer number of data structures is staggering with a highly developed hierarchy. This makes it hard for newcomers I think.
  • Some people like Scala's Option[] as a fix for null
  • Statically typed. I like this.
  • Debugging can be hellish, obscure.
  • It's weird that people can just put spaces where I would use a . to conjoin functions. This would bother me in a team setting.
  • Not truly functional. It has functional aspects, but you can program in python for a lifetime without ever using them. Really, there are more idiomatic ways to accomplish some of the things. List comprehension versus filtering, for example. Scala's syntax for lambdas is just better.
  • Arguably easier to read.
  • Harder to transition to thinking like a software developer.
  • Larger community
  • For me at least, it's still faster and more enjoyable to develop in.


More trivially, I couldn't find a good plug-in to code in Scala in Sublime. I was forced to use Eclipse, which was a little disappointing. Scala worksheets were a nice surprise though.

See Questions On Quora

Posted on 12 December 2013

When learning a new programming language from a book should I keep notes on a notebook or is it enough to practice what I learn?

I always take notes when learning a programming language, and I find it easiest to do so in a text editor rather than a physical notebook. I sync the notes to my Dropbox to make them available on all of my machines.

I love learning new languages; in my Dropbox now, I have notes for roughly 20 languages, totaling about 18,000 lines. When I was in school, I would take notes primarily to help cement the information in my brain; I would rarely revisit them later, even when studying for finals. However, I've come to find notes about programming languages extremely useful in my usual development workflow as a convenient reference. And this is the main reason I use a text editor instead of a physical notebook -- you can't grep a notebook.
Beyond that, I read through them again every time I need to reacquaint myself with a language I have not used in a while, which is orders of magnitude faster than re-reading the language reference, old code, or any other literature I used to learn the language in the first place.

Using my own notes instead of Google has other advantages, and chief among them is the ability to put explanations for difficult concepts in my own words, and potentially with my own examples I have personally tried. Obviously, it also makes it very easy to copy/paste example code and play around with it. And since the notes are files on my hard drive, I suffer no loss of productivity when offline.

Sadly, I also speak from experience when I say that learning a new language without taking notes is folly. No matter how comprehensive you think your understanding is of the language when you're learning it, you will forget massive portions of it over time, and when you do, it's so much faster and more convenient to remember it by reading through your notes.

See Questions On Quora

Posted on 2 December 2013

Is it better to create your own framework, or would it be best to just use Django or something like that?

You should absolutely use an existing framework such as Django rather than writing your own.

Doing so will let you work faster, and take advantage of code written by others. This will dramatically increase your chances of building a successful website as opposed to spending months tinkering with your own framework rather than solving the unique problems that make your website interesting.

If your site is a big success, you'll be able to scale Django to meet your demands. There are plenty of huge sites running on Django - such as Pinterest, Instagram, Eventbrite and Disqus. They all end up having their own customisations for scale but that doesn't mean that they didn't benefit enormously from using an existing framework rather thank rolling their own from scratch.

Concentrate on getting to a point where your site is so successful that it causes problems. Those are good problems to have!

See Questions On Quora

Posted on 1 November 2013

What is the right age to start learning 'how to code'?

The right age to start learning anything is when it interests you. People learn best when they're interested, and two people are unlikely to become interested at exactly the same age. I've seen six-year-olds become fascinated by programming; I've seen others not get into it until they were older. Some people never show any interest in it.

Most kids are able to understand the concept of an instruction set at a very early age.

See Questions On Quora

Posted on 18 August 2013

Some of the languages like Java, Python, C# has references instead of pointers. What is the mean reason and does it have any advantages (how crucial is it to have the garbage collector beside)?

The Short Explanation

Pointers can be very useful for passing large objects as function arguments and storing them efficiently in arrays. Pointer arithmetic, however, is more trouble than it's worth.
References are pointers without pointer arithmetic: they grant the advantages of pointers without suffering the worst of their disadvantages.

The Full Explanation

Pointers are primarily useful for passing large data structures to functions.
In a normal function call, the arguments are loaded onto the function call stack. If the arguments are very large -- which they tend to be in Java, since you're primarily passing around large and complicated objects -- the arguments take up a lot of room on the call stack.
However, passing by reference allows us to simplify this: instead of putting the entire object onto the call stack, all we have to do is put the memory address at which the object can be found, which is only 4 or 8 bytes.
Not only is this easier on stack space, it avoids duplicating the objects in memory: passing a large object by value creates a copy of it on the call stack every time it is used as an argument, but passing by reference only requires you to store the object once and pass around very small references to it.
(Of course, there is a small amount of overhead in having to fetch the object when it's needed, whereas it would be immediately available if its value was right there on the stack.)

Pointers also make it easier to implement arrays of large objects. The advantages are pretty much the same as you find in pass-by-reference: instead of making an array by copying giant objects to sequential memory addresses, it is only necessary to store their addresses in sequential memory addresses. This way, we again avoid having multiple copies of potentially-large objects in memory.

I don't know how much C you're familiar with, but here's a simple example of the above concepts:
struct gigantic {
    char buffer[1048576]; // 1 megabyte
    int flags;
    char name[80];
    /* ...and a bunch of other members */

Each instance of this struct takes up more than a megabyte of RAM.
If we were to make an array like this:
gigantic naive_array

It would take up 100 megabytes of RAM. In memory, it would be represented as one giant structure, each more than a megabyte in size, after another.
But if we instead made an array that stores pointers to these structs:

This entire thing will only be 400-800 bytes, because all it actually stores is the addresses where we can find these hundred structs; in memory, it would be represented as one memory address after another.

Pointers are just memory addresses, which means they are just numbers. When their values are exposed to the programmer, as they are in C and C++, the programmer is free to specify exact memory addresses, add them, subtract them, multiply them, take their square roots, and so on (although if you find yourself doing any of these latter things to pointers, you are probably doing something wrong).
Consequently, in C and C++, arrays are represented as the memory address of the first element, and you refer to their other elements by calculating their memory addresses beyond that point. For example, if your machine's
s are 4 bytes each, the array
allocates 40 bytes of memory and stores the start address of that region in
. When you say
to access the sixth element of
, your compiler finds the element by adding to the address stored in
. Because you're adding to a pointer, that
is implicitly multiplied by the size of the array's element type, meaning you're really accessing the data stored at memory address:

It's important to understand that that last statement is literally just arithmetic on three numbers to find a memory address. There is no concept of an "array" here anymore. When your processor follows a pointer, it doesn't care about why or how this address came to be; it just follows it. Neither does the processor keep track of what part of the memory is valid, which contains data, and which contains code.
If you mess up your arithmetic, you can end up telling the processor to read or modify the wrong data, unallocated memory, or code, and the processor is dumb enough to try.

For example, consider the following code:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

int main(void) {
    // set up our data space:
    //   16 bytes for four 4-byte integers
    // + 16 bytes for a string of up to 15 characters
    // = 32 bytes total
    void *data = malloc(32);

    // set up numbers[4] = { 1, 2, 3, 4 }
    int32_t *numbers = (int32_t*)(data + 0);
    int i;
    for (i = 0; i < 4; i++)
        numbers[i] = i + 1;

    // set up msg[16] = "Hello, World!"
    char *msg = (char*)(data + 16);
    strncpy(msg, "Hello, World!", 16);

    // incorrectly set last index of "numbers":
    numbers[4] = 6778223;   // should be numbers[3]

    // expecting "Hello, World!":
    printf("msg = \"%s\"\n", msg);

    return EXIT_SUCCESS;

(I allocated the entire data region up front to enforce a certain memory layout, because it tends to vary wildly on different platforms and compilers. The memory layout used above is one in which
are allocated contiguously, which is very likely to happen, but ordering is not guaranteed across platforms.)
$ gcc -o tst tst.c
$ ./tst
msg = "omg"

...which is not quite what we were expecting.
The problem here is that the programmer has the responsibility to verify that his memory addresses are correct, and in this case he made an all too common off-by-one error in specifying the last element of the
array, resulting in the corruption of completely different data.
Leaving the task of memory management to humans instead of machines also tends to leave the program open to some nasty security vulnerabilities, such as buffer overflows and return-to-libc attacks.

Languages that only allow references make the observation that programmers shouldn't need to concern themselves with memory addresses and pointer arithmetic; that should be the compiler's job. It's not only an annoying detail that is unnecessary to know, but human brains are much less consistent and tend to make simple mistakes.
This is why, even though Java uses pointers (i.e. memory addresses, i.e. integers) to implement references, it doesn't expose that memory address to you as a value to perform arithmetic on. And if you do manage to get the actual address that a reference points to, you aren't able to turn an address back into an object. If Java allowed these things, Java programmers would use them and shoot themselves in the foot.

However, one pointer-related problem you are not protected from by only being given access to references is trying to follow a reference to an unallocated object. You might recognize this as the infamous
in Java. This tends to be a problem with statically-typed languages that expose the concept of a "reference". (Languages that don't give you this kind of control over argument-passing mechanisms, such as Python, do not suffer this problem.)

See Questions On Quora

Posted on 27 July 2013

What are some "practice problems" that everyone should work on in-order to get better at programming (in any programming language)?

I don't think there are any that will be suitable for "everyone." It's going to depend largely on what you've done before, and perhaps also what you aim to do next.

Linked lists: In the first two or three C/C++ programs that I wrote on my own, I wrote my own linked-list classes. Not because good ones couldn't be found elsewhere, just because I wanted to try it. It took a couple iterations (pun intended) before I was satisfied that I had done it right, and I learned a lot in the process.

When you have a good singly-linked implementation, make a doubly-linked list.

It helps immensely if you have an app that needs a list. It's one thing to write one to pass a few unit tests - it's another to write one that meets the needs of an application.

State machines: In school, I had an assignment once to write something that would solve equations like:

X=(1+2)*(3 * (4 + 5 * 6)) / 7

That was kinda fun. We were studying grammars and state machines at the time, and this exercise was a fun way to put those ideas together.

Network protocols: Write something that can retrieve web pages via HTTP. You don't have to display them - just save them to disk. For bonus points, save the inline images, too. For more bonus points, write something that downloads entire web sites - and don't let it run unattended, or you'll embarrass yourself!

Then write an HTTP server, and test it with two or three browsers, and your own HTTP client.

If that was fun, try again with SMTP....  Write something that can send mail via SMTP. Test it against your ISP's SMTP server. When you get that working, write something that can receive messages via SMTP. Send mail to it from a few different pieces of software, including your own.

See Questions On Quora

Posted on 26 July 2013

Do Java, C++, etc. programmers look down on Python developers?

Generally, if someone look down on you just because you are a xxx developer, he/she sucks.

Python is a great programming language for people to write really useful scripts/programs and various projects. One thing engineers should know is that all techs, including programming languages, frameworks, editors, operating systems and so on are just tools for people to make world better. So it's all about how you can use these tools to build something great, to just show off what tool you're using is stupid.

So, if someone look down on Python developer, just say fuck off and enjoy whatever you wanna hack with Python.

BTW, I'm a C / Ruby developer.

See Questions On Quora

Posted on 17 July 2013

Where can I find implementations of standard data structures and algorithms in Python?

A good place to start might be in the core Python library itself. The raw dictobject.c source (Python dictionary/hashtable implementation) is here:

The list implementation is here:

aaaand you can probably find the rest of the core Python data structures' implementations yourself:

There are also some textbooks you can check out if you Google a bit. This one, for example, seems to optimize for learning/readability over speed or efficiency, which might make a good starting point:

Welcome to Problem Solving with Algorithms and Data Structures

See Questions On Quora

Posted on 8 July 2013

What are the most useful optimization tricks in Python?

Improving big O and using correct data structures will have a bigger impact than most language specific tweaks. That being said...

Profile Your Code

Optimizing for performance without first checking where the bottlenecks are is a waste of time. Use cProfile. For small snippets of code use timeit.

If you're ever curious why one implementation is faster than another, the dis[assembler] module is useful.

String Concatenation

# yes
result = ''.join(list_of_words)

# no
result = ''
for word in list_of_words:
    result += word

Get Rid of Intermediary Lists / Use Iterators

and itertools module liberally. Python 3 typically defaults to the iterative version of a function when available.

Understand List's Time Complexity

These operations are all [math]O(n)[/math]

if x in xs:

xs.insert(0, x)


If you're adding/removing to the head of the list often, you should be using a deque.

Using Multiple Cores

Use multiprocessing module over threads for CPU intensive work.


There are various ways to optimize for number crunching:

  • use specialized libraries: numpy, scipy
  • use another implementation: PyPy (JIT compiler), cython (type annotations)
  • rewrite critical sections in C / C++

Avoid Unnecessary Function Calls

While I enjoy a functional programming style, Python function calls are really expensive and call stack performance is near the bottom of the pack (fib-benchmark).

There are other benefits for writing functional code, but a functional implementation will be relatively slower than its imperative counterpart (negligible most of the time).

Avoid recursion whenever possible.

Additional Material

See Questions On Quora

Posted on 29 June 2013

Why does + and += behave differently for python lists?

In general, the difference between
depends on whether
is mutable
  • For an immutable object
    (such as an
    , or
    ), they do the same thing.
  • But for a mutable object
    (such as your
    ), the difference is that
    in place. This mutation will be observed by anyone with a reference to the same object

Why? The Python
operator works roughly* by invoking the first of whichever of three methods are defined and does not return
  1. a 
    . Typically this mutates
    in place and returns
  2. a 
    . Typically this creates a new object and modifies neither the original
  3. a 
    . Typically this creates a new object and modifies neither the original
On the other hand,
only tries the last two of these.

(* The full story is somewhat more complicated.)

See Questions On Quora

Posted on 13 June 2013

Which one should I learn? Python or Scala?

Scala IMHO is a better language then Python and just about anything. Scala is a statically typed language which means you get more help from the compiler and IDE while programming in a way no dynamic language does.
Scala is both Functional and Object Oriented and though learning the syntax of Scala is no more difficult then any other language mastering these paradigms can take a while. So learning to write "good" Scala code is harder then Python.
I believe the JVM is the best environment to develop for currently and in the foreseeable test which is another advantage to Scala over Python. When you write python you use only python libraries. When you write Scala you can also use Java libraries as well as many other emerging JVM languages: Cloujure/Groovy/Kotlin/...
Learning python may allow you to get a job programming in python while the market demand for Scala is currently much smaller(though growing)
Learning Scala will teach you Functional programming and important concepts like immutable code. Learning Scala will make you a better Java programmer (or any other language). learning python will only teach you python.
All around I prefer Scala.

See Questions On Quora

Posted on 17 May 2013

How do companies like Dropbox and Quora maintain large Python projects?

I can not answer for Dropbox or Quora but having worked for two companies that have very large Python source codebases I would like to point out that maintaining large Python source codebase is not as easy as you would first think.  Here are some random facts that hope help you:
  • Almost everyone is using 2.7 (if you have existing codebase there is little incentive to migrate to 3.x).  I don't have experience with 3.x so I can't recommend it.
  • You would want to use python packages to modularize your code.  Put your code in folders.  Add an empty in all of them including root.
  • Be consistent when naming folders, modules, classes, variables.  If you don't have a clue - pick PEP-8.
  • Be consistent when importing - Python (at least 2.x) is not very consistent and it is very easy to mix up module, package and function imports.  Pick a system and stick with it (preferably one that does not conflict with standard naming schemas (my personal favorite is full path "import util.file.crc").
  • Document the system and make sure everyone follows it (code-reviews and water-cooler mockery are two systems you could use ;) ).
  • Put in place scripts or conventions to start programs and unit tests.  It pays to invest time in this.
  • I would recommend an automatic build system - but this is something that needs more time than the previous item.
  • I highly recommend picking an install method early and stick with it.  My personal preference is pip.  But scripting this is very helpful so that people are not banging their heads against problems because they are using a different version of a library.
  • Source Control Systems are mandatory - for all coding work.
  • Pick an editor with syntax highlighting and good full text search - you tend to use that a lot.  My personal favorite is PyCharm.

See Questions On Quora

Posted on 18 March 2013

If I want to build web applications, do I need to learn about data structures and algorithms?

Great question! Here's the answer:

You "need" to know literally nothing.

Modern web development is so advanced is that it basically amounts to gluing stuff together (this is good) - people have spent years refining and shoving the CS-y stuff behind abstractions.

Another way to say it:
To start building stuff, just build it. You'll learn as you go along - through Google, Stack Overflow, and trial-and-error. Some people who want to "just build" get caught up in the trap of learning as much background as possible. Don't bother doing this.

Along the way (especially if you get popular) you'll find that you need to learn about certain basic CS and engineering concepts like hash tables, arrays, trees, as well as networking, HTTP, and so forth. This is great. Don't be afraid to learn. But "Just Start Building" first.

See Questions On Quora

Posted on 1 February 2013

How does the GIL impact concurrency in Python? What kinds of applications does it impact more than others?

Python's GIL ensures that the underlying C-implemented interpreter safely accesses Python data without causing any issues.

Unfortunately, only one thread can hold the GIL at a time, giving it access to Python data.

When multiple Python threads are running, the interpreter will constantly check between them and check which ones have code pending execution.

In normal threading (such as in C), multiple threads can be running simultaneously, making use of multiple cores in a CPU. In Python, only one thread can possibly run at a time, because the GIL prevents multiple threads from holding it.

This means that in Python we can't perform parallel tasks that we can perform in other programming languages (image processing is the only one that comes immediately to mind, but it's a great example).

For someone new to parallelism/concurrency, this may seem to make Python threads useless, but they aren't. Python threads still allow us to take advantage of some aspects of concurrency that we get from other languages, most notable being asynchronous input/output. A Python thread waiting on disk to read a file can allow another thread to run. This means that certain uses of Python threads can still offer significant speedups, mostly during I/O intensive tasks (disk read/write, socket communication, etc.)


The GIL prevents us from exploiting concurrent computation that we may get from other languages (ie. Parallel problem solving), but it doesn't prevent us from getting speedup on costly/frequent I/O operations.

See Questions On Quora

Posted on 15 December 2012

How fast is Python 3.x compared to 2.7?

On my Ubuntu VM running inside OSX, python 3.2.3 is benchmarking slightly slower than 2.7.3:

$ python2.7 -c "from test import pystone; pystone.main()"
Pystone(1.1) time for 50000 passes = 0.35
This machine benchmarks at 142857 pystones/second

$ python3.2 -c "from test import pystone; pystone.main()"
Pystone(1.1) time for 50000 passes = 0.42
This machine benchmarks at 119048 pystones/second

Several iterations of those tests returned similar results.

See Questions On Quora

Posted on 28 September 2012

What are some cool Python tricks?

Circular lists :)

>>> def make_circular_list(a_list):
...   while True:
...     for an_item in a_list:
...       yield an_item
>>> a_list = [1,2,3]
>>> a_circular_list make_circular_list(a_list)

See Questions On Quora

Posted on 22 July 2012

What explanation of the concept "functions may or may not return a value in python" will be intuitive and definitive enough for newbies to understand?

Actually, every Python function returns a value. If the function doesn’t have a
statement or if it has a
statement with no explicit value, then the return value is implicitly

So these three functions are equivalent:
def func1():
    print('Hello, world!')

def func2():
    print('Hello, world!')

def func3():
    print('Hello, world!')
    return None

Perhaps you might object that
represents the absence of a value, but that’s as silly as saying that zero represents the absence of a number.
is a legitimate value (of type
) that can be passed around and stored in variables like any other Python value.

behaves a little specially in the interactive Python interpreter, in that a result value of
is not shown by default. You can force it to be shown with, say,

See also Defining Functions in the Python tutorial.

See Questions On Quora

Posted on 22 July 2012

Is python really slow? What does this experiment ( ) prove?

I really like Python.

Python is pretty damn slow (~100x slower than C).  Numpy isn't that bad (2x-5x).You don't write things in Python to make them fast.  You write things in Python because you want to get them done quickly and without hassle.  Prototyping in Python and rewriting slow/memory inefficient bits in C(++) is a great way to do real software development.

See Questions On Quora

Posted on 3 July 2012

Is there anything Django can do that Flask can't with blueprints/extensions?

Having used both - Django for full-fledged sites, and Flask for API backends, Django's benefit is in its community, insanely good documentation, easy-to-extend middleware and context processors, and of course the built-in admin site.

Flask is capable, but I found myself mimicking a lot of the functionality in the fashion of Django while using it. SQLAlchemy is pretty cool but requires a MUCH larger learning curve. Testing is much more manual. Documentation is severely lacking compared to Django.

I don't really buy in to the separation-of-apps thing in Django. It works as psuedo-namespacing but i've rarely if ever seen apps be able to exist completely independently of each-other... so I won't tout that as a feature.

That said, if your site is significantly small... or as in my case, if you are building say, an API that only passes JSON back and forth, or may only have one or two pages to the entire site, Django can be an elephant gun for an ant. I used Flask, SQLAlchemy, and the "apy" Flask extension to build an API to backend a turn-by-turn iOS game. It scales just fine, and is less resource-heavy than Django.

Most importantly, though, is due to the maturity in Django, things like JohnnyCache exist and are amazing, stable, and scalable. SQLAlchemy has serious issues with putting objects in memcached, for instance, that you have to work around from scratch (and won't find out about until you think you're almost done.)

In either case, use Jinja2 - so much faster, more capable, and binary-cacheable. :)

That's a lot of words, I hope you find it helpful.

See Questions On Quora

Posted on 4 May 2012

What are the benefits of developing in Node.js versus Python?

Maybe there are none? I know that sounds like a troll, but you should consider it as a possibility. A lot is made of Node's asynchronous nature, but you can do event-driven apps in Python (and many other languages as well). It's not that hard, there is no magic.

Of course if you really love JavaScript programming then obviously Node has an advantage there. That's purely subjective though. Most programmers that I have worked with are pretty good at using different programming languages for different tasks.

Pragmatically there are some disadvantages as well. Being a younger language, you can expect more bugs, less documentation, and missing pieces. Of course all of these things are getting better all the time and there is an active community around Node. There's also a very active community around Python, Django, Twisted, etc. as well. In exchange for those bugs you get to use a technology that is considered very hip currently. You get "credibility" with some kinds of people. It's like Rails circa 2006-2007. If that kind of stuff matters to you, then that would be a huge advantage.

See Questions On Quora

Posted on 27 December 2011

How long should it take to learn how to program?

How long to learn "how to program" - all your life.

I've been coding professionally for 10+ years, and I'm learning something new every week. When a week passes and I haven't, I'm sad. When I get to learn a lot of new things in a week, I'm thrilled. And I know there's always a ton more to learn ... always (see

Now, how long does it take to master "a programming language"? Suppose you focus on one domain, such as web programming, and one language such as python. I believe that within about one year of doing actual 9-hours-a-day work, you can "master" a language - that is, know all the major idioms and data structures, have at least one IDE that makes you feel super comfortable, know a good many important 3rd party libraries, and know how to investigate new problems.

You won't know all the hidden features, internal compiler details, and esoteric libraries in a year ... that simply takes time. But the good news this gets much easier after your second or third programming language. You start seeing patterns, and even though it always takes time to get productive in a new language, it really gets down to only a few months of re-wiring some brain patterns in new ways.

See Questions On Quora

Posted on 2 December 2011

How can I learn to write idiomatic Python?

No, no, no. You start by reading Python. Python source. As in, the code.
  • Not a book. When I was in China, one of my friends showed me an English proficiency test she had to take to get qual'd. It was hard as balls; even I had no idea what some of the answers to the questions were, and I'm a native speaker. She did know the answers, though. All of them. And the result is that she knew a lot about English. In spite of this though she could not speak it.

    Programming is more or less the same. It's a community event: you are operating in a system with other people, and the shorthand, the hacks, the abbreviations, are all part of this system. If you want to learn these things, you need to be a part of this system. You need to read Python.
  • Not PEPs. When I learned Chinese, I picked up a book called Making Out In Chinese. It was great, full of idioms. It explained where they came from, and why they were idioms. But it did not teach me idiomatic Chinese. It just taught me Chinese idioms. This is a subtle but crucial difference: imagine someone who clearly does not know English at all walks up to you and says (in a heavy accent), "What's up?" This is not the same thing as when I say this to my friends. This person has just used an English idiom, but they are not speaking English idiomatically.

    In the real world, idiomatic English (just like idiomatic Python) requires good judgement and understanding of context[1]. I'd say this is actually more important in programming since one big component of these systems is that they need to be correct. And at the end of the day, this is something that you can't really get without being a part of the dialogue. You need to read Python.

Caveat: This is not to say that these aren't great resources. For learning about Python. Learning about Python will help you to be a better programmer, and I say this from experience. But it will only get you so far. So roll up your sleeves and get out there.

If you're looking for projects to look at, I like the source of Brubeck framework[2] and Mercurial[3]. Per Shashwat Anand's (correct) suggestion, standard library stuff like heapq and shutil are also worth looking into.

I'M NEW HERE. Please leave me any criticisms that might be helpful as I slowly learn to be a better writer!

[1] Also, it's easy to make mistakes when judging idioms. Do you know the best way to create a 2-D List of
's? A quick perusal of the internet might lead you to believe it's
, but this is very very wrong, and in order to understand why, you need to have spent time with it.

See Questions On Quora

Posted on 19 August 2011

What is the status of Unladen Swallow?

As of now there have been no commits to Unladen Swallow in months. The big problem with it is that Pypy, a much more ambitious project with more developers and more excitement around it, is now posting better CPU gains than Unladen Swallow is, which raises into question what's the point of contributing to Unladen Swallow when it's going to be replaced with Pypy in very short order anyway.

While the future is unclear, my money would be on Unladen Swallow being dead in the water at this point.

See Questions On Quora

Posted on 12 March 2011

What are good Python interview questions?

There is a large number of elementary algorithmic interview questions you can use with any language (memory addressing, networking, trees, hash tables, sorts, concurrency, etc), but if you're looking for Python-specific questions, here are a few, in no particular order of difficulty or relevancy:

  • Talk to me about the GIL. How does it impact concurrency in Python? What kinds of applications does it impact more than others?
  • How does Python's garbage collection work?
  • What is the difference between range and xrange? How has this changed over time?
  • Here's a function. Optimize it for me.
  • How do you iterate over a list and pull element indices at the same time?
  • I'm getting a maximum recursion depth error for a function. What does this mean? How can I mitigate the problem?
  • How do you enforce ordering for a dictionary-style object?
  • How does Python's list.sort work at a high level? Is it stable? What's the runtime?
  • What's the difference between a list, dictionary, and array in Python?
  • What does this list comprehension do?
  • Here's a class hierarchy with some methods defined. When I call this function, what gets printed?
  • What is monkeypatching? How can you do it in Python?
  • What are some caveats to pickling? Marshaling?
  • How many ways can you append or concatenate strings? Which of these ways is fastest? Easiest to read?
  • Print me the full pathname of every file in this directory tree.
  • What's wrong with this function?
  • What's your preferred editor? (vim, of course - anything else and they fail.)

See Questions On Quora

Posted on 19 January 2011

Why is Python preferred at Google over PHP?

When Google was founded, PHP was only three years old and in its third major version. Frankly, PHP 3 was a mess, and engineering a maintainable system in PHP would have been a major challenge. For instance, PHP 3 didn't support any sort of OOP. It was basically a turing-complete template language.

Also, Python is a good general purpose language whereas PHP is only really suited to web.

There are plenty of other good reasons to choose Python over PHP, but they are more subjective, so I'll avoid starting a flame-war by keeping those to myself :-)

See Questions On Quora

Posted on 14 July 2010

What are common uses of Python decorators?

I've found the following memoization decorator useful on a number of occasions:

def memo(fn):
    cache = {}
    miss = object()

    def wrapper(*args):
        result = cache.get(args, miss)
        if result is miss:
            result = fn(*args)
            cache[args] = result
        return result

    return wrapper

With this little tool in your toolchain, you can write functions in a naive, mathematically elegant style, and get away with it:

def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

Goodbye, exponential time.  Hello, linear time.

Of course, the original function must be pure, and the arguments must all be hashable, but python does a great job synthesizing a hash function for the
tuple, provided those assumptions hold.

See Questions On Quora

Posted on 19 May 2010 search results

I recently released "Intermediate Python", a free and open source Python book. After receiving a LOT of positive feedback and support it is in Beta stage now!

Hi guys! You might already know that I released a free and open source book on Intermediate Python. The name of the book itself is also intermediate Python. After my last post the book received a lot of patches and it is in a whole lot better shape now. It also received a LOT of positive response from the community. It remained on the front page of Hacker News and /r/Python. It is currently a trending project on GitHub under the Python tab. I am happy to say that it has entered beta stage now. This is the best time to take a look if you haven't already.

Moreover, if you want to add anything to the book or just want to polish it further then you are more than welcome to submit a Pull request on GitHub.

I just wanted to write a quick note that a lot of people asked me last time whether I accept donations. I wasn't accepting donations untill recently. I have uploaded the latest build of the book on Gumroad so if you feel like tipping me then you can buy the donation version of the book from Gumroad. It would mean a lot to me and would help me to continue writing free quality content.


submitted by yasoob_python to Python
[link] [22 comments]

Posted on 23 August 2015

I just released alpha version of "Intermediate Python", my first and free E-Book.

Hi guys! After a lot of hard-work and sheer determination I have mostly completed my book, "Intermediate Python". It will receive updates over time :)

It has a couple of issues related to grammar and technical info in it. I am working on ironing them out one by one.

I was a bit lazy so didn't upload it earlier but here it is now.

I have decided to distribute it for free! I wanted to give back to this awesome community so this is what I have to offer for now. I am sure that it would help those who really want to be helped. Best of luck!

Here are the links:

If you like this book then a simple tweet and a personal email <yasoob DOT khld AT gmail DOT com> would mean a lot to me!

P.S: The book is open-source so if you find typo or technical error or just want to expand it's contents with your own knowledge then just send over a pull request :) Moreover, if you want to give me any tip then kindly pm me your email and I would let you know once I setup a tip-collection system.

Note: This is not related with that paid "intermediate Python" book in any way. I became aware of it today. I had been using this name internally for a couple of months. If the author of paid "Intermediate Python" has any issue with this I would be more than happy to change the name of my book because he definitely beated me to the finish line. :)


Hey guys! All those of you who are going to use this book can really help me and motivate me by letting me know how this book supplements your day to day learning and if you are a Teacher, Assistant Professor or something of that sort then kindly let me know if you would be willing to offer this book to your students or not. :)

You already have my email address or if you want to tweet about it then you can do so at @yasoobkhalid.

Moreover, I really can't thank this community enough. This community has helped me a LOT over the years. If you see my Reddit profile then you can easily guess that this is the only community (/r/python) where I spend most of my time.


You guys can donate me if you want to by buying the donation version of Intermediate Python from @gumroad :)

It is only for $10 but if you want to pay less then kindly let me know (pm) and I can give you a custom link.


submitted by yasoob_python to Python
[link] [77 comments]

Posted on 17 August 2015

Coming from a C background, I LOVE PYTHON!

I dont know how others new to python feel , but coming from a C (bit of java and cpp as well) systems background , I totally love python! I just love how easy it is to build useful stuff , in the last week I have worked on simple but somewhat useful things like : 1) getting weather for your location 2) automating file creations from db data , handling error cases better (as compared to bash the code was much more cleaner ) 3) currently working on scraping an ecommerce website for checking on price drops for wishlisted products . Love the power the libraries like pickle,soup, smtp etc provide !

I would have taken a considerable amount of time and coding to build any basic useful thing with C , and would cringe everytime I need to implement a map,list etc ! BTW I do know the usecases of C are very different but the freedom python provides just leaves me wide eyed!

Only thing is I know very little of how and why python works the way it works . Am currently going thru more usage based tutorials and googling the rest , but unlike C I have a very slight discomfort of the lvl of abstraction .

Any good resources for taking my knowledge to the next level and some good projects to take up next?

submitted by shashank88 to Python
[link] [185 comments]

Posted on 19 May 2015

Experienced Python Users: what's the most recent new thing you learned about the language?

I ask this because I just learned something new that I feel like I should have known for a long time... if you define a class with a __len__() and a __getitem__() method, it automatically becomes iterable! e.g.

class Foo(object): def __len__(self): return 10 def __getitem__(self, i): if i > len(self): raise IndexError return i for i in Foo(): print(i) 

What's the most recent new Python feature you have learned?

submitted by jakevdp to Python
[link] [305 comments]

Posted on 17 April 2015

When do you *NOT* use python?

Hi everyone,

We're all python fans here, and to be fair I may use it a bit more than I should. I'd like to hear other people's thoughts on which tasks they want to solve in a non-python language and which one they'd choose for that job.

Thanks in advance...

submitted by RealityShowAddict to Python
[link] [421 comments]

Posted on 16 February 2015 should stop steering web visitors away from v3 docs

$ curl --head HTTP/1.1 301 Moved Permanently Date: Fri, 06 Feb 2015 23:22:21 GMT Server: nginx Content-Type: text/html Location: 

This is another contributing factor to why v3 adoption is slow, and new users are confused. This configuration affects everything from StackOverflow links (how I first noticed it) to Google pagerank.

It's why Python3 docs don't often show up in search results. should default to v3. Or, at the very least, display a disambiguation page, a la Wikipedia.

submitted by caninestrychnine to Python
[link] [68 comments]

Posted on 6 February 2015

What do you *not* like using Python for?

Maybe sounds like a silly question, but here's the context: Been programming for ~10 years, professionally for the past 7. Matlab, C#, C++ (in decreasing order of proficiency). Per management, it looks like I'll now be getting into some Python for an upcoming project... which is cool, as with how prevalent Python seems to be, I've wanted to get my feet wet for a while.

Obviously all languages have their bounds... or at least things they do better than others. So - as I'm getting my feet wet here, does anything stand out as far as areas where Python is weak and there may be better alternatives?

submitted by therealjerseytom to Python
[link] [353 comments]

Posted on 18 October 2014

Python subreddit has largest subscriber base of any programming language subreddit (by far).

Python 80,220 (learnpython 26,519) Javascript 51,971 Java 33,445 PHP 31,699 AndroidDev 29,483 Ruby 24,433 C++ 22,920 Haskell 17,372 C# 14,983 iOS 13,823 C 11,602 Go 10,661 .NET 9,141 Lisp 8,996 Perl 8,596 Clojure 6,748 Scala 6,602 Swift 6,394 Rust 5,688 Erlang 3,793 Objective-C 3,669 Scheme 3,123 Lua 3,100 "Programming" 552,126 "Learn Programming" 155,185 "CompSci" 73,677 
submitted by RaymondWies to Python
[link] [118 comments]

Posted on 21 September 2014

What are the top 10 built-in Python modules that a new Python programmer needs to know in detail?

I'm fairly new to Python but not to Programming. With the programming languages that I've learned in the past I always see a recurring pattern — some libraries (modules) are more often used than others.

It's like the Pareto Principle (80/20 rule), which states that 80 of the outputs (or source code) will come from 20 of the inputs (language constructs/libraries).

That being said, I would like to ask the skilled Python veterans here on what they think are the top 10 most used built-in modules in a typical Python program, which a beginner Python programmer like me would benefit to know in detail?


Thanks to all that have replied :)

I found a site where I can study most of the modules that you suggested:

(Python Module of the Week)



Of course, there is no substitute for the official documentation when it comes to detailed information:

Python 2.7.*:

Python 3.4.*:

submitted by ribbon_tornado to Python
[link] [135 comments]

Posted on 24 June 2014


Русскоязычная группа посвященная языку Python. [link]

Posted on 18 May 2014

Learning python earned me a 50% raise, and it's about to again.

(Sorry for the throwaway, but I wanted to be able to answer questions honestly without any hesitation.)

I've been in IT since I was 17 in 1999. I started off at a help desk, and worked my way up to a Systems Administrator where I was making 60k USD/yr. (I currently have only an associates degree with no plans to go back to school.) I was primarily a Windows domain/ network admin, with a few *nix boxes spread throughout. I had known windows batch scripting, and way back in the day had programmed in BASIC before the world was.

I had tossed around the idea of learning a programming language before, but when asked I'd often say "Developers' brains just work differently than mine. I'm not a coder." Programming seemed so abstract and I couldn't really wrap my head around it. I finally decided though, to try something.

It was 2010 and I had heard a lot of Ruby on Rails and thought that Ruby would be a great language to learn. I ran through the tutorial of making a polls app at least 5 times, but I just couldn't wrap my head around it. So I gave up.

One year later I heard about python. Despite all the negative talk about python while googling for "python vs ruby vs php vs ..." (GIL, speed, whitespace, duck typing, (not that I knew what ANY of that meant anyway)) I decided that I really wanted to give it a shot. I started out with codeacademy to get my feet wet, I'd tinker with idle while my wife and I would watch netflix after the kids went to bed. Then I started dreaming in code.

Have you ever had "work dreams"? The kind you have for about 2 weeks after starting a new job that's really hard? That was python for me. Being primarily in a Windows environment it was hard to find anything for python to do initially at work. My boss didn't program, and really didn't see the value in it. Then one day I found myself needing to compare a list of files. I needed to find all the files that were in one column but not in the other. I had them in excel and after working through a formula I had my answer, but I hated it. All I wanted to do was write something like--

select name from column1 where name not in (select name from column2); 

Enter python and sqlite. It probably took me about 3 hours to figure it out, but I imported a csv into a sqlite table in python so I could query it. BAM! I was hooked from then on.

Every night I would tinker, read, and play. I found tons of things to automate at work, making my time so much more effective. I loved it. I became a python evangelist. I'd like to say that my boss was impressed, but really he never came around, and it frustrated me. Fast forward a year.

I had heard about the DevOps movement and though I didn't understand it completely at the time I thought that being a Developer and Systems Admin mutant sounded like a lot of fun, and something I could really be good at.

After having a rough time with my boss one day I decided to check the local classifieds. I saw an ad for a DevOps Admin. Basically this guy needed to know hardware, networking, provisioning, something called puppet, and one of three scripting languages- ruby, bash, or python.

I looked at puppet, and after having learned about booleans and strings and syntax from python, picking it up wasn't a problem. I got hired on the spot for $90k USD. A clean 50% raise. I use python every single day. I write scripts to check if databases back up properly, if services are up, if all 1000 of my physical servers are getting their updates, to provision RAIDs, you name it. I integrate what I write into puppet, fabric, and a host of other tools that I've learned along the way.

After doing that for a little over a year now, I'm about to hire 2 guys under me as we expand and I'm moving up to $120k USD. I'm learning django for fun and am just starting into machine learning. I check out /r/python every day, you guys have been so helpful to me along my way. And if I can learn python, anybody can!!!

TL;DR I learned python in a year and got a 50% raise. 1 year later I got another 25% raise, all from python!

edit: percentages, oh math...

submitted by self_made_sysad to Python
[link] [142 comments]

Posted on 6 May 2014

What is the best part of python you wish people knew about?

I just quit my job at a major software company to be with a startup in downtown seattle and it looks like our stack is Python based. I'm new to Python but I want to learn fast; So please, let me what you like the most (or hate the most?) about python, other python developers code, etc so I can take all the good and not use the bad as I learn this new language.

Who knows, maybe you will need to maintain my code someday, so you could only be helping yourself!

Thanks in advance!

submitted by honestduane to Python
[link] [226 comments]

Posted on 16 December 2013

Eric Idle here. I've brought John Cleese, Terry Gilliam, Terry Jones and Michael Palin with me. We are Monty Python. AUA.

Hello everybody. I had so much fun last November doing my previous reddit AMA that I decided to return. I'm sure you've seen the exciting news, but here we are to confirm it, officially: Monty Python is reunited. Today is the big day and as you can imagine it's a bit of a circus round here, but we'll be on reddit from 9am for ninety minutes or so to take your questions. We'll be alternating who's answering, but everyone will be here!:

  • J0hnCleese
  • Terry_Gilliam
  • TerryJonesHere
  • _MichaelPalin


Update: We're running a little late but will be with you 10-15 minutes!

Update 2: The url for tickets - - available Monday

Update 3: Thank you for all the questions. We tried to answer as many as we could. Thanks everyone!

submitted by ericidle to IAmA
[link] [7717 comments]

Posted on 21 November 2013

What you do not like in Python?

I'm a big fun of Python! I use it every day! But there are things which are annoying, strange and so forth in Python (you really don't like it). If any, please, share your thoughts. For example:

  • built-in set type has method like symmetric_difference_update. I don't like so long methods in built-in types.
submitted by krasoffski to Python
[link] [891 comments]

Posted on 18 September 2013

Python interview questions

I'm about to go to my first Python interview and I'm compiling a list of all possible interview questions. Based on resources that I've found here, here and here I noted down the following common questions, what else should I add?


  • What are Python decorators and how would you use them?
  • How would you setup many projects where each one uses different versions of Python and third party libraries?
  • What is PEP8 and do you follow its guidelines when you're coding?
  • How are arguments passed – by reference of by value? (easy, but not that easy, I'm not sure if I can answer this clearly)
  • Do you know what list and dict comprehensions are? Can you give an example?
  • Show me three different ways of fetching every third item in the list
  • Do you know what is the difference between lists and tuples? Can you give me an example for their usage?
  • Do you know the difference between range and xrange?
  • Tell me a few differences between Python 2.x and 3.x?
  • The with statement and its usage.
  • How to avoid cyclical imports without having to resort to imports in functions?
  • what's wrong with import all?
  • Why is the GIL important? (This actually puzzles me, don't know the answer)
  • What are "special" methods (<foo>), how they work, etc
  • can you manipulate functions as first-class objects?
  • the difference between "class Foo" and "class Foo(object)"

tricky, smart ones

  • how to read a 8GB file in python?
  • what don't you like about Python?
  • can you convert ascii characters to an integer without using built in methods like string.atoi or int()? curious one

subjective ones

  • do you use tabs or spaces, which ones are better?

Ok, so should I add something else or is the list comprehensive?

submitted by dante9999 to Python
[link] [185 comments]

Posted on 19 August 2013

Common misconceptions in Python

What are some common misconceptions that people have when programming in Python? Here are a couple that were passed around a mailing list I'm on:

'list.sort' returns the sorted list. (Wrong: it actually returns None.)

Misconception: The Python "is" statement tests for equality.

Reality: The "is" statement checks to see if two variables point to the same object.

This one is especially nasty, because for many cases, it "works", until it doesn't :)

In [1]: a = 'hello'

In [2]: b = 'hello'

In [3]: a is b

Out[3]: True

In [4]: a = 'hello world!'

In [5]: b = 'hello world!'

In [6]: a is b

Out[6]: False

In [7]: a = 3

In [8]: b = 3

In [9]: a is b

Out[9]: True

In [10]: a = 1025

In [11]: b = 1025

In [12]: a is b

Out[12]: False

This happens because the CPython implementation caches small integers and strings, so the underlying objects really are the same, sometimes.

If you want to check if two objects are equivalent, you must always use the == operator.

submitted by rhiever to Python
[link] [243 comments]

Posted on 13 May 2013

What is Python not a good language for?

I am moving from writing one-off code and scripts to developing tools which are going to be used by a larger group. I am having trouble deciding if Python is the right tool for the jobs.

For example I am responsible for process a 1gb text file into some numerical results. Python was the obvious choice for reading the text file but I am wondering if Python is fast enough for production code.

Edit: Thanks for the all responses. I will continue to learn and develop in Python.

submitted by Hopemonster to Python
[link] [229 comments]

Posted on 6 May 2013

Are there any things about Python that you do *not* like, or that you wish were done differently, or that you flat out think are wrong?

I lightheartedly joked in another thread that if the person had agreed with my point (that Python 3 seems very slightly harder to code in than Python 2.x - also a lighthearted, almost completely unfounded critique), that it would be the first time I'd ever seen any Python user online agree with any criticism of any part of the language. In this last bit I'm not really joking.

I had many newbie critiques a few years ago - 'self', the fact that you can't join a string list with myList.join(', '), something about slicing that I forget now, that it was confusing which things worked in-place, and which worked on a copy, etc. - and in a forum (not reddit) where I posted up my lengthy list (mostly to see what people thought of these things), I was met with a wall of responses, all strongly in favor of every last part of all of it, and even of things I hadn't mentioned. In 3 years I realize now I have never once seen anyone critique any part of the language and not be met with all manner of deep, philosophical justifications as to why that thing or those things must be that way.

It's the perfect language, I guess.

So my new question is just straight up: IS there anything about Python you don't like? I mean, it is moving to 3, and there are changes, so clearly 2.x had room for improvement, so let's hear it. Be prepared for a battle on all fronts from everyone else in here, though, whatever you say :) I'd love to hear from the real experts, the people who usually wield seemingly powerful reasoning and long strings of computer science words in their arguments.

This itself isn't a critique, nor even a jab, but just another attempt to learn more.

submitted by gfixler to Python
[link] [576 comments]

Posted on 16 November 2011

A website that lets you browse Reddit like you're reading/coding in Python!

...or Java (and soon, Ruby, PHP, C#, etc.).

It's my first website with Flask (my first real dynamic website?). I wanted the domain to be, but it was too expensive :(. So I just asked my brother to help me host it.

Comments appreciated. :)


  • NSFW indicator for Python (can't figure out where/how to place it in Java, but it still checks for NSFW so it won't load image previews)
  • don't preload all images (thanks to canuckkat)
  • use def instead of class in Python


I just opened up the repo at bitbucket :)

Thanks everyone!

submitted by ares623 to Python
[link] [73 comments]

Posted on 6 September 2011

Python Educational

Subreddit for posting content, questions, and asking for general advice about learning Python programming language. [link]

Posted on 2 October 2009


news about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python [link]

Posted on 24 January 2008