Python is a dynamic, high-level 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, exceptions, had an extensive standard module library. Python can also be embedded in other ...

learn more… | top users | synonyms (1)

16
votes
8answers
1k views

What are good unit tests to cover the use case of rolling a die?

I'm trying to get to grips with unit testing. Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.): import random class Die(): def __init__(self, ...
0
votes
0answers
87 views

Approach to statically analyze a Python code base

What approach should I use to statically analyze a Python code base? In particular, I am looking for ways to: extract and display the class hierarchy, extract and display class relationships, ...
3
votes
2answers
123 views

Inform caller or just let them deal with exception?

I'm not sure how to proceed in the following situation. say we have a function as so: def runsATask(codes): myDicts = [helperFunc(code) for code in codes] for item in myDicts: # some ...
5
votes
4answers
592 views

Why doesn't Haskell have a 'format' function for string interpolation?

I'm trying to use Shake and I stumbled upon the following problem: there's no easy and convenient way to interpolate a string. I know about Text.Printf — it's not what I'm looking for. The ...
7
votes
3answers
676 views

Python - 'if foo in dict' vs 'try: dict[foo]'

This is less a question about the nature of duck typing and more about staying pythonic, I suppose. First of all - when dealing with dicts, in particular when the structure of the dict is fairly ...
-2
votes
1answer
210 views

Extracting data from log files

I will be extracting certain bits from log files using regular expressions to filter out bit of data. Initially I was going to do this with Python. I later started to think about the fastest way I can ...
2
votes
2answers
132 views

Automated testing of programs with graphical output

I am a lecturer for a post-graduate module where I expect my students to write Python code that replicates examples from the textbook. The project has been running for a couple of years and this year ...
18
votes
3answers
1k views

Why do so many languages treat numbers starting with 0 as octal?

I've read Where are octals useful? and it seems like octals are something that were once upon a time useful. Many languages treat numbers preceding with a 0 as octal, so the literal 010 is actually ...
1
vote
2answers
108 views

Is there a way to efficiently allow a user to upload multiple content at once for e-commerce type sites?

Sellers on large sites like Amazon and Newegg need to provide names, descriptions, and images for their products to be displayed on the e-commerce sites. These sellers could have 10000+ products to ...
1
vote
2answers
157 views

Documenting/defining data structures in Python

What is the preferred way to document the contents of and logic behind dynamically generated data structures in Python? E.g. a dict which contains the mapping of a string to a list of lists of ...
3
votes
2answers
179 views

What are the advantages of dynamically binding a method to class instance?

I came across Instagram's API client written in Python. In their class InstagramAPI, they bind the methods to a function in bind.py. When called, the function returns an instance of the class ...
0
votes
5answers
316 views

How to create a Python interview question to write a method

If I'm giving an interview coding question in Java, I can specify the most of the question just by giving a method signature. (Made-up example follows.) public class Table { public String ...
0
votes
0answers
149 views

Extending user registration in Django site that uses both site admin tables and my own module?

I'm writing a Django site that registers a particular type of user and this is done by the resources that come with the framework, the site administration. The issue: I'd like to create a new model ...
3
votes
3answers
174 views

conditional expressions, correct usage

I've recently become quite taken with conditional expressions in Python. Apparently some people consider it unpythonic and whether or not conditional/ternary expressions are even A Good Thing seems to ...
1
vote
1answer
88 views

Additional actions in setup.py for install

Background So, I'm developing a project, and I'm writing setup.py script for it, using distutils. I'm using CPython3.3. I use some libraries that have invalid distributions in PyPI, so they have to ...
4
votes
3answers
355 views

Which is better API: table.add_row() or table.rows.add()?

I'm writing a library to create and manipulate Word .docx files in Python. In general, I take a lot of influence from the Microsoft VBA/C# API for Word in designing the API, figuring they've given it ...
4
votes
3answers
224 views

Python: How to decide which class' methods should provide behavior (functionality) affecting multiple classes

I have a question about object oriented design that is not specific to Python but since my code is in Python, I tagged it as such. How do I decide which of my classes should be responsible for ...
0
votes
2answers
198 views

Google App Engine overview

I have gone through many Google App Engine tutorials, and I became quite familiar with how to do basic stuff like implementing a webapp2.RequestHandler, and using ndb.Models to manage your data. Now, ...
1
vote
4answers
446 views

How should you cleanly restrict object property types and values in Python?

I have been learning python from no long time ago. But nearly at the beginning I stumbled on simple question: how to set a restriction (limitation) on object value or object's properties without ...
3
votes
2answers
204 views

Writing a unit test for a platform dependent unit

I have a method to be tested which depends on the OS, what's the best approach for testing the method depending on the OS? Is it to test on every OS that I have I require? Is there a better approach ...
0
votes
2answers
826 views

Model-View-Controller — Where does a factory class go?

I'm working (slowly) on a small Flask project. One of my models is a class called Post, which is a lightweight namedtuple. Post objects are created by a PostFactory, because creating a Post involves ...
2
votes
2answers
179 views

Python - defining exit method before importing

This breaks nothing (in my experience), but lots of things "don't break anything" and are still wrong. #! /usr/bin/env python """Short description of this module.""" def ...
0
votes
3answers
278 views

What is the difference between 'code readability' and 'language conventions' used within a community? [closed]

When I'm looking at questions asked on sites like stackoverflow on how to make a particular piece of code "more pythonic" there are usually suggestions offered to use complex list comprehensions or ...
1
vote
2answers
161 views

How can I automate the process of code review

I have a team that works on multiple technologies. I want to know how can I automate the process of code review for .Net, .Net MVC, Python, PHP, Drupal and HTML5/CSS with JavaScript. I have read ...
1
vote
1answer
120 views

How do we pass data between two Amazon instances?

I'm trying to create a website where the user enters a few numbers, these numbers are fed into some equations, and the output of these equations is emailed to the user. I'm using Python 2.7 for ...
1
vote
1answer
145 views

Is using os.environ to store the value of command line switches pythonic?

I write CLI-executable Python 3 scripts regularly to do data compilation and some maintenance tasks, and try to adhere to PEP 8 and the Google Python Style Guide when doing so. Google's guide says to ...
0
votes
2answers
88 views

How to make the leap from classification to clustering

I have a clustering problem which I can't seem to solve, although if I treat it as a labeled classification problem, I can solve it with satisfactory precision. Is there an elegant way to make the ...
0
votes
1answer
140 views

Python: Counter for Simultaneous calls of a PHP script?

I'm trying to create a queue processing script that's purpose is to find particular files and apply actions based on specific parameters, with the result being to call a PHP script that serves to ...
0
votes
1answer
227 views

processing Postfix log with python

I need to process all log messages from Postfix (/var/log/mail/mail.log), and print a summary/statistics (how many emails were sent/received and from/to which email addresses) The situation is made ...
0
votes
3answers
184 views

Tips for developing a mobile app with a team [duplicate]

I am currently a high school student, I've been assigned to manage a group in my school to develop a mobile app and the problem is that all of us have no experience in making a project in a team and ...
2
votes
1answer
240 views

Python garbage collection giving me a hard time

Context: I am developing a web application using webapp2 web-framework with python to be hosted on GAE. The web application (web-app from now on), is a chess variant. Being a first timer, I have ...
4
votes
2answers
304 views

Is using static-typing the solution to domain-driven design and decreasing the number of errors?

We are using PHP (a dynamically-typed language) in our project. However, I have found my colleagues asking questions such as ...
4
votes
1answer
352 views

Will loop constructs become obsolete? [closed]

By loop constructs I mean for… and while… constructs with nested statements. Currently I am coding a tool in Python and decided out of curiosity not to use the regular loops - and rely on ...
3
votes
2answers
355 views

What was the need of introducing Python 3 when we already had Python 2 [duplicate]

I am still learning python and I started with Python 3. This question not Python 2 vs 3 or difference between them like print() is a function and not language construct and 3/2 = 1.5 My question is ...
1
vote
2answers
232 views

Using a web framework as python GUI

If I built some useful piece of python code to e.g. scrape a website or to calculate something big, at some point I might want to add a GUI to my project. For this I could use Tk, Qt, Pygame or any ...
2
votes
3answers
291 views

is it really necessary for python to differentiate between tuples, lists, dicts, ordered dicts and sets?

i have been learning python over the past month or so. i like many of the things about the language, but i find the differentiation between tuples, lists, dicts, ordered dicts, and sets to be ...
0
votes
0answers
104 views

How to algorithmically add notes to an existing midi file relative to positions of existing notes in python

I have a midi file that I'd like to algorithmically add notes to relative to other notes that already exist in the midi file using python, or if it's easier using a different language I'm open to that ...
2
votes
3answers
251 views

How should I go about bringing this code under test?

I'm working on an open-source test framework. 90% of my codebase has good test coverage. My main problem area is the command-line entry point. This module began life as a very short script for ...
8
votes
3answers
587 views

When and how should I use exceptions (in Python)?

The Setting I often have trouble determining when and how to use exceptions. Let's consider a simple example: suppose I am scraping a webpage, say "http://www.abevigoda.com/", to determine if Abe ...
1
vote
0answers
169 views

Benefits of using object document mapping (ODM)

I am creating a web app on Flask and was planning to use mongodb. Most of the examples using this stack that I've come across have used an ODM of some kind and was wanting to figure out whether or not ...
4
votes
6answers
1k 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 ...
2
votes
1answer
236 views

Shuffling algorithm with no “self-mapping”?

To randomly shuffle an array, with no bias towards any particular permutation, there is the Knuth Fischer-Yeats algorithm. In Python: #!/usr/bin/env python import sys from random import randrange ...
-1
votes
1answer
801 views

Packaging PHP/Python files inside android .apk files?

I am developing an android app using HTML5. I want to make it work completely offline. I know that it is possible to package the .html, .css and .js files inside the .apk file itself in the ...
1
vote
1answer
360 views

Web application / Domain model integration using JSON capable DTOs

I'm a bit confused about architectural choices for the web-applications/java/python world. For c/c++ world the available (open source) choices to implement web applications is pretty limited to zero, ...
14
votes
1answer
758 views

How can I tell if I am overusing multi-threading?

I currently feel like I am over-using multi-threading. I have 3 types of data, A, B and C. Each A can be converted to multiple Bs and each B can be converted to multiple Cs. I am only interested in ...
-1
votes
1answer
133 views

Building a regex builder [closed]

I am a beginner in programming in general and web development in particular. I am especially bad at regular expressions. Recently I was involved in building a couple of cPanel plugins(Perl-CGI) and ...
3
votes
2answers
201 views

Improving the performance of a db import process

I have a program in Microsoft Access that processes text and also inserts data in MySQL database. This operation takes 30 mins or less to finished. I translated it into VB.NET and it takes 2 hours ...
4
votes
1answer
3k views

Why did Apple remove Python support in Mavericks, aka Mac OS X 10.9? [closed]

In a rather unceremonious way - Apple has removed Python support (at least from the SDK) in 10.9. Python IS still installed on the system in... /System/Library/Frameworks/Python.framework but ...
-2
votes
1answer
153 views

Python scripts link to GUI using an IDE [closed]

I am studying python. Now I can write python scripts(codes) to some extent. I am interested in making GUI to those written programs.I like to do it using an IDE rather than using PyGTK or Tkinter. Can ...
3
votes
1answer
777 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?