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
12
votes
6answers
9k views

What is the simplest human readable configuration file format? [closed]

Current configuration file is as follows: mainwindow.title = 'test' mainwindow.position.x = 100 mainwindow.position.y = 200 mainwindow.button.label = 'apply' mainwindow.button.size.x = 100 ...
12
votes
7answers
17k 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
4k 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
772 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
1answer
9k 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(**...
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
10k views

Why do you need “self.” in Python to refer to instance variables?

I have been programming into a number of languages like Java, Ruby, Haskell and Python. I have to switch between many languages per day due to different projects I work on. Now, the issue is I often ...
11
votes
5answers
1k 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 ...
11
votes
3answers
32k 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
22k 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
5k 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 ...
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
462 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
1k 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
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 ...
11
votes
4answers
2k 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 ...
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
5answers
14k 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
6answers
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 ...
10
votes
3answers
3k 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 ...
10
votes
3answers
12k 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
652 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
2answers
21k 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 ...
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
5k 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 ...
10
votes
3answers
4k views

How to sync clocks over networking for game development?

I'm writing a game that has a lot of time based aspects. I use time to help estimate player positions when the network stalls and packets aren't going through (and the time between packet's being ...
10
votes
1answer
4k views

How to refactor a Python “god class”?

Problem I’m working on a Python project whose main class is a bit “God Object”. There are so friggin’ many attributes and methods! I want to refactor the class. So Far… For the first step, I ...
10
votes
2answers
626 views

Is Python's inheritance an “is-a” style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
10
votes
1answer
2k views

When should I subclass an exception in Python?

In my code there are about seven places where I raise an exception. All of these exceptions are treated the same: print an error to log file, return software state to default and exit. During code ...
10
votes
1answer
561 views

What is the mathematical model of a Python's class?

I understand that the classical model from the lambda-papers is not valid for Python. And the closures are not the mathematical model of the implementation of the Python system. So which model is it?...
10
votes
3answers
3k views

Python Multiprocessing with Queue vs ZeroMQ IPC

I am busy writing a Python application using ZeroMQ and implementing a variation of the Majordomo pattern as described in the ZGuide. I have a broker as an intermediary between a set of workers and ...
10
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. ...
10
votes
3answers
3k 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
3answers
1k views

How should private dependency links be handled in setup.py

At work we use a private pypi server. This pypi server is specified as a dependency link: ... from setuptools import setup config = ConfigParser.ConfigParser() rc = os.path.join(os.path.expanduser('~...
10
votes
2answers
2k views

How does key-based caching work?

I recently read an article on the 37Signals blog and I'm left wondering how it is that they get the cache key. It's all well and good having a cache key that includes the object's timestamp (this ...
9
votes
9answers
4k views

Is there any difference learning OOP on different programming languages? [closed]

I want to learn OOP. I know Python and I know very little things about OOP. But when I search for "learn OOP" in forums I saw a guy saying that "Python is so new that's why you can't learn OOP on ...
9
votes
11answers
15k 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 ...
9
votes
3answers
974 views

Sometimes private functions are simply yet-to-be-extracted internal units of functionality. So why not test them?

Sometimes private functions of a module or class are simply yet-to-be-extracted internal units of functionality, which might deserve their own tests. So why not test them? We will write tests for them ...
9
votes
2answers
2k views

What is the justification for Python's power operator associating to the right?

I am writing code to parse mathematical expression strings, and noticed that the order in which chained power operators are evaluated in Python differs from the order in Excel. From http://docs....
9
votes
5answers
801 views

What is the historical basis of using Javascript in web programming?

I come from a scientific biology background where we also use Python a lot. Now that I've begun to start with Web development, I've consistently found myself wondering just why it is that JavaScript ...
9
votes
3answers
6k 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 ...
9
votes
3answers
2k views

How is the development of languages like Python and Perl funded? [closed]

The title pretty much gives you the gist of the question, but allow me elaborate a bit nevertheless. Apart from Google's involvement on Python, and Activestate's on Perl development (Strawberry AFAIK ...
9
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 ...