Questions tagged [python]

Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.

Filter by
Sorted by
Tagged with
13
votes
3answers
5k views

In Python 3.4+, why should I use namedtuple over SimpleNamespace when not using dict, they seem very similar

At one point or another you might come over functions with a lot of arguments. Sometimes it makes sense to combine some of the arguments into super-arguments. I've often done this with dicts, but now ...
13
votes
8answers
3k views

Choosing between CL and Python for web development

I'm coming from a Java background and after I read this little essay by Paul Graham I started wondering about picking up a new language namely Common Lisp to speed up my work (I'm a web developer). I'...
13
votes
2answers
7k views

Draw a Call Graph

I'm maintaining an old code base written in python. In particular there is a complex piece of code that from a module calls other functions from other modules that call other functions and so on. It ...
13
votes
1answer
11k views

Why is flask CLI recommended over Flask.run?

In Flask 0.11 a flask CLI was introduced. Both the docs and the changelog state this is recommended. Development Server docs: Starting with Flask 0.11 there are multiple built-in ways to run a ...
13
votes
1answer
13k views

Is modifying an object's __dict__ to set its properties considered Pythonic?

I have a class that inflates objects from rows found in a database (or another source, e.g. MongoDB, a CSV file, etc.). To set the object's properties, it does something like self.__dict__.update(**...
13
votes
3answers
6k views

Global request context - anti-pattern?

I was talking today to a colleague of mine about Python web frameworks and our impressions about them. I told him I think Flask having a global request smells badly and is an anti-pattern. The docs ...
13
votes
2answers
1k views

Early attempt to remove Python GIL resulted in bad performance: Why?

This post from Python creator, Guido Van Rossum, mentions an early attempt to remove the GIL from Python: This has been tried before, with disappointing results, which is why I'm reluctant to put ...
12
votes
3answers
3k views

Working through the single responsibility principle (SRP) in Python when calls are expensive

Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and ...
12
votes
4answers
1k views

Do you think that GAE alone is enough to justify learning Python over Ruby? [closed]

Considering the fact that you don't have to get involved in setting up/buying a server or even buying a domain, do you think that fact alone is enough to choose one over the other? I don't ...
12
votes
1answer
4k views

Is it possible/advisable to combine unit testing and integration testing?

I've built a Python script that consists of about 20 functions that extract data from MySQL via .sql files (I'm currently trying to learn SQLAlchemy ORM), do something to it and then put it back in ...
12
votes
6answers
2k views

As a beginning programmer, should I favor building my own libraries over using 3rd-party libraries?

As a beginning Python programmer, is it a good idea to build and understand my own libraries before jumping to advanced 3rd-party libraries that contains the functionality I need? Some projects (e.g. ...
12
votes
1answer
688 views

Why was “self” chosen over “this” for the name of the first parameter of python methods?

What was the rationale for choosing the name self instead of this when defining class methods in Python? Yes, of course, you can name it whatever you want - but the widely agreed-upon name for the ...
12
votes
8answers
10k views

How does rapid prototyping fit into an agile methodology?

I work for a large company, which dictates the use of agile processes. For example, for our projects, we use cloud-based services that are specifically targeted at managing agile development. The ...
12
votes
7answers
18k views

Is Python a good choice to develop UIs? If so, wxPython or Tkinter?

I'm looking forward to develop a desktop application using Python. I'm a beginner and I don't have sufficient expertise in Python. I'm also a Java programmer. Although I have some experience in ...
12
votes
6answers
17k views

What are some characteristics of Python that makes it unique as its own language? [closed]

What are some characteristics of Python that makes it unique as its own language? I'm looking for any sort of characteristics ranging from good to bad, useful to hindrance, syntax to real-world usage, ...
12
votes
2answers
7k views

What is the relationship between scope and namespaces in Python?

In many resources I found "scope" and "namespaces" are used interchangeably, which seems a bit confusing since they mean different things. Scope defines the region of the code where a name is ...
12
votes
5answers
2k views

How is the JVM and Java's WORA different from other high level languages?

In the Java world, we often talk about the JVM, and when Java was new it had the supposedly killer feature of "Write Once, Run Anywhere." From the way people talk and write, this seems different from ...
12
votes
1answer
19k views

How Python random shuffle works?

How shuffle from random works in Python? I ask because it works very fast. When I try to write shuffle it works 1 minute for 10^6 element, but Python shuffle does that in 8 sec?
12
votes
2answers
5k views

In python, is it considered better to define a module with functions or a module with a class that contains functions? [closed]

In my code either of the above two options would work equally well but I am interested in finding out the pros and cons of both approaches.
12
votes
1answer
4k views

How do I deal with projects within projects in python?

Note I realise this could be subjective question to answer, but I don't expect an answer in the form of "Do this and everything will work out". I am aware there will probably be some decisions to be ...
12
votes
1answer
799 views

How mature is PyPy? [closed]

I am trying to determine the maturity of PyPy by other means than reading the opinion of the developers. Therefore, I am interested in hearing about any high-profile mission-critical projects using ...
12
votes
2answers
5k views

Python for large projects

Are there any resources out there on how to architect large, industrial strength Python projects? I'd like to start on an ambitious personal project, but I'm not really sure how to architect it and ...
11
votes
10answers
8k views

Do Python programmers find the whitespace issue inconvenient? [closed]

Many programmers, upon first encountering Python, are immediately put off by the significance of whitespace. I've heard a variety of reasons that this is inconvenient, but I've never heard a complaint ...
11
votes
7answers
2k views

Is there anyone who has used Python/Ruby and PHP for a long time and still prefer PHP? [closed]

I am usually fascinated by articles defending PHP and the arguments being used. Quite often authors of these types of articles don't mention what experience they have with other languages. Personally ...
11
votes
3answers
33k views

Cross-platform desktop programming: C++ vs. Python [closed]

Alright, to start off, I have experience as an amateur Obj-C/Cocoa and Ruby w/Rails programmer. These are great, but they aren't really helpful for writing cross-platform applications (hopefully ...
11
votes
3answers
24k views

Is it a better practice pre-initialize attributes in a class, or to add them along the way?

I'm sorry if this is a ABSOLUTELY sophomoric question, but I'm curious what the best practices are out there, and I can't seem to find a good answer on Google. In Python, I usually use an empty class ...
11
votes
2answers
29k views

Python classes with only one instance: When to create a (single) class instance and when to work with the class instead?

Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of ...
11
votes
2answers
10k views

Why does Python use hash table to implement dict, but not Red-Black Tree? [closed]

Why does Python use hash table to implement dict, but not Red-Black Tree? What is the key? Performance?
11
votes
2answers
493 views

How to select a most probable option from the list based on user text Input

I am working over a OCR Application where I need to select a option based on user text input. Ex: Available Options: ["python", "ruby", "java", "clojure", "haskell"] Input: kava Output: java Input: ...
11
votes
3answers
1k views

Do I need to understand the Internals of a programming language?

I am beginner to Python and I really like it so far. One question that comes to my mind very often is if I need to understand and therefore learn the Internals of a programming language (as in my case ...
11
votes
3answers
2k views

How is type checked in a dynamic language interpreter/compiler, such as JavaScript?

In dynamic languages, such as JavaScript or Python, the type of a variable is determined at runtime. This is one reason why they are slower than typed languages such as Java. How is type checking ...
11
votes
1answer
1k views

Using Python's Method Resolution Order for Dependency Injection - is this bad?

I watched Raymond Hettinger's Pycon talk "Super Considered Super" and learned a little bit about Python's MRO (Method Resolution Order) which linearises a classes "parent" classes in a deterministic ...
11
votes
4answers
3k views

How do I model partial dates in Python? Like an unknown year, or unknown day of the month?

I want to be able to capture facts like Bob was born in 2000 and Bill's birthday is May 7th. In both examples we know only part of the person's birth date. In one case we know only the year; in the ...
11
votes
1answer
4k views

Duck typing, data validation and assertive programming in Python

About duck typing: Duck typing is aided by habitually not testing for the type of arguments in method and function bodies, relying on documentation, clear code and testing to ensure correct use. ...
11
votes
3answers
6k views

How to properly handle global parameters for unit testing in python?

We are implementing many algorithms which typically have lots of shared, publicly known and security-relevant parameters. Currently, we simply use a class holding all the parameters and two ...
10
votes
11answers
16k views

Do I have to learn html and javascript to create web applications? [closed]

I am an experienced Java programmer, and I want to create a complex web application requiring dynamic pages, drawings, etc (take SO as an example). Do I have to learn javascript/html in order to ...
10
votes
9answers
1k views

Omitting inheritance in programming languages

I am developing my own programming language. It's a general purpose language (think staticlly typed Python for the desktop, i.e. int x = 1; ) not intended for the cloud. Do you think it's okay not ...
10
votes
5answers
1k views

Are there technical limitations or language features that prevent my Python script from being as fast as an equivalent C++ program?

I'm a long-time Python user. A few years ago, I started learning C++ to see what it could offer in terms of speed. During this time, I would continue to use Python as a tool for prototyping. This, it ...
10
votes
3answers
2k views

Ensure unsafe code is not used accidentally

A function f() uses eval() (or something as dangerous) with data which I created and stored in local_file on the machine running my program: import local_file def f(str_to_eval): # code.... ...
10
votes
8answers
2k views

How to end my dependency on .NET? [closed]

I have been developing Windows GUI applications since many years and jumped into .NET in early 2005. .NET is a undoubtedly a remarkable platform and I am still using it, but with a variety of ...
10
votes
3answers
7k views

Why does Python need both a compiler and an interpreter?

I can understand the fact that Java needs both a compiler and an interpreter. It compiles source code to bytecode and then a virtual machine (on Windows, on Linux, on Android, etc.) translates that ...
10
votes
5answers
15k views

Moving to Python (SciPy and NumPy) for Scientific Computing [duplicate]

Just read a presentation about using Python for Scientific Computing. I am currently using MATLAB (student license FTW, which will expire when I graduate soon). So I was wondering how matured SciPy ...
10
votes
3answers
1k views

What are the challenges related to typing in writing a compiler for a dynamically typed language?

In this talk, Guido van Rossum is talking (27:30) about attempts to write a compiler for Python code, commenting on it saying: turns out it's not so easy to write a compiler that maintains all the ...
10
votes
3answers
5k views

Why is the _replace method of Python namedtuple classes protected?

In the section Method Names and Instance Variables, the Python Style Guide (aka PEP 0008) says, "Use one leading underscore only for non-public methods and instance variables." Why then, does the ...
10
votes
3answers
13k views

How does Python work?

This question may seems a little bit silly, but what the heck. I started to learn Python. I know basic syntax, etc. When I work with HTML, PHP, etc., I simply write code, put it inside .html or ....
10
votes
4answers
704 views

Good code style to introduce data checks everywhere?

I have a project that is sufficiently large in size that I can't keep every aspect in my head any more. I'm dealing with a number of classes and functions in it, and I'm passing data around. With ...
10
votes
4answers
1k views

Why do python generators and functions share the “def” keyword?

Consider the following: def some_function(): return 1 def some_generator(): yield 1 In the code above, some_function is a function, while some_generator is a generator. They look quite ...
10
votes
2answers
9k views

`var is None` vs `var == None`

I often see var is None in Python code, using is to test equality only works for a very few objects like None. I used to think that it's better practice to use == to compare equality even if is is ...
10
votes
2answers
5k views

Is there a convention for returning multiple items?

In Python specifically (I don't know if this generalizes) is there a "best" way to return multiple items from a function? def func1(): return a,b #equivalent to (a,b) def func2(): return[a,...
10
votes
2answers
15k views

Is it safe to catch ImportError when trying to import optional modules?

I usually see this pattern at least once in every Python project I work on. For example, in a Django project, this is often added at the bottom of the base settings file: try: from .local_settings ...

1 2 3
4
5
34