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)

2
votes
2answers
844 views

Front-end structure of large scale Django project

Few days ago, I started to work in new company. Before me, all front-end and backend code was written by one man. As you know, Django app contains two main directories for front-end: /static - for ...
1
vote
1answer
252 views

Merge two different API calls into One

I have two different apps in my django project. One is "comment" and an other one is "files". A comment might save some file attached to it. The current way of creating a comment with attachments is ...
0
votes
1answer
112 views

How to structure GUI program with a database

I am fairly experienced with web design and programming, C, C++ and a little java (used it to build some small GUI). I am trying to work with Python, and I am faced with some technical structuring ...
0
votes
0answers
25 views

Extending the interface of existing (python) classes

I use a library with an existing well-defined interface, that I have extended for my purposes. I.e. most classes in that library inherit of one abstract base class class Parent(object): def ...
-2
votes
0answers
32 views

What are the big pros and cons of using Kivy over Java and Java over Kivy? [on hold]

I know python very well and would like to use it as a medium of developing, but Java is fine with me too. Things like... (all these are theoretical) worse workflow with kivy? cannot use native ...
3
votes
1answer
50 views

Structure project based on platform or design?

I have a medium sized project (~10,000 lines) that runs on Windows and Linux. However it is only specific components of the program that are platform dependent and are located in a folder called ...
8
votes
4answers
1k views

Returning a boolean when success or failure is the sole concern

I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method ...
-3
votes
0answers
93 views

How much programming should I know at the age of 17? [on hold]

I love programming, I will study computer science in college, I am a junior in high school right now. I want to work for big IT companies such as Facebook, Google, Dropbox, Apple.. I want to have a ...
1
vote
2answers
86 views

Technique to synchronize error codes in a same-project-API

In the project I am working right now, we have some python and some C# code. At some point, I call from python a subprocess which starts a C# executable. This C# code returns an error code, which has ...
-4
votes
0answers
134 views

PHP vs Python. Which is best for me and my situation? [on hold]

As a beginner programmer, should I learn PHP or Python? I know this has been beaten to death but I would like opinions based on my specific situation. Programming Background - I am a complete newbie ...
-2
votes
0answers
23 views

Python pandas and matplotlib or MySQL? [closed]

Pandas is a great Python library that provides easy-to-use data structures and data analysis tools. I have been using it to aggregate, and analyze daily weather observation data which I get from an ...
-1
votes
0answers
16 views

How can I pass String value from EditText In Android Activity to Python Script and also retrieve the result from a function in the python script? [migrated]

How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying ...
3
votes
3answers
104 views

How to write tests for function that depends on a config file?

I have a function that uses information from a config file. How do I test the function? Ideally, I'd want to inject my own version of the config file and test from there, but I'm not using dependency ...
1
vote
1answer
105 views

What is ## used for?

I have looked at other questions about this and the general consensus seems to be that ## is used for commenting out code. However, in the Interactive Editor for Python, prefixing a line with ## ...
0
votes
1answer
46 views

Program design - how to improve it and how to avoid coupling (Python)?

In the Python program structure below there are two modules with functions. Problem description: Functions are used inside other functions all over the place. Strong coupling (dependency). For ...
0
votes
0answers
21 views

Python, selenium, phantomjs, and multiprocessing pool - bad work [closed]

Sorry for my english, i use google translate from russian. # I run selenium grid, like this: java -Xms512m -Xmx2048m -jar selenium-server-standalone-2.45.0.jar -role hub -log ./out.log And ...
0
votes
1answer
90 views

Does the phrase “range for R1-1 through R10H” actually have an agreed-upon meaning?

I was recently sent a code test by a potential employer to complete on my own time. The first question has to do with identifying whether a given zoning code falls within a range of codes. I'm not ...
0
votes
1answer
56 views

Is it reasonable to use a decorator to instantiate a singleton in Python?

Suppose I have a class like this: class Foo(object): # some code here As it happens, Foo is a singleton. There are numerous ways to write singletons in Python, but most of them don't really ...
-5
votes
0answers
21 views

How can I make a Python function examine every element of a list? [migrated]

I was ordered to build a Bulean Function that takes a list of numbers and execute "True" if the list is a proper grade list(i.e every number is between 0 to 100) and "False" otherwise. I however ...
0
votes
1answer
63 views

Python, namespace vs module with underscores

I'm developing a project that uses several independent modules, but all related to the same project. However, I face this choice: module names with underscore vs. namespaces. For example there is ...
1
vote
2answers
96 views

Efficient datastructure to create size-limited dictionary

I need a class that acts like a dictionary but will constrain the total number of key/value pairs it contains. For instants, let's say the maximum number of entries is 1000 and the class already ...
0
votes
1answer
32 views

Aggregate documentation comments from multiple scripts into README?

After having written some python scripts with comments for documentation inside, is it a good idea and possible to aggregate the documentation comments from multiple scripts into some standalone ...
2
votes
3answers
70 views

Preferred way to expand a command line script to be used as a library in Python

I have a useful Python script that I've been invoking from the command line. It has decent number of options, maybe 20, and it's not unusual to run the script with six or seven flags. Then the rest of ...
8
votes
4answers
1k views

Write two versions of class with two different super classes without violating DRY?

I have a class called LimitedDict which is a dictionary that limits the number of entries it can contain by deleting old entries when a new one is added. It currently inherits from Python's dict ...
0
votes
0answers
56 views

Ordering of methods in class [duplicate]

How do you order the methods in your classes? I am aware of the alphabetical approach and the telling a story approach and so far I prefer the story approach, but how do you handle private/helper ...
0
votes
1answer
44 views

Is it OK to use name like `CLASS_CONSTANT` for class constant variables according to PEPs? [python]

On the code I'm viewing, I saw a class like this: class User(ModelBase): """# User: docstring""" COMBAT_RANK_KEY_PREFIX = 'combat_rank' LEVEL_RANK_KEY_PREFIX = 'level_rank' ...
0
votes
0answers
25 views

What are some ways to modify a Numpy matrix? [migrated]

I have a numpy matrix C and want create a copy of it cPrime which has some operation of the original matrix to all non-zero values of it. For example, I might want multiple by 30 and then add 1, as ...
0
votes
0answers
3 views

Reading in TSV with unescaped character in Pandas [migrated]

I have a TSV file where each line is a word token and its POS tag, separated by tabs. The DET boy NOUN said VERB " PUNCT Hi INTJ Mum NOUN " PUNCT This will be used as a basis ...
2
votes
0answers
45 views

Method object creation in Python data model

I've been reading the article on the data model of Python on its Reference website, and have been confused about this part: When the attribute is a user-defined method object, a new method ...
4
votes
1answer
856 views

Should I avoid using style like `for k, v in dict_sample.items()`?

Today I was viewing my colleague's code and I saw a function like this: def manager_skill_tree_func(*args, **kwargs): """# manage_skill_tree: Initialize the manage skill tree """ ...
-1
votes
0answers
19 views

Python: Replace URLEncoded characters in String with what they represent [migrated]

I've been banging my head against the wall with this for a while. I'm trying to parse an RSS feed with Python's BeautifulSoup, and every now and then I get errors like: I don't know what I ...
1
vote
0answers
42 views

Code structure with MongoDB in python

I am new to MongoDB and python. I know how to make basic use of pymongo in order to manipulate documents. I am having trouble finding how to create some structure or governance in what gets inside ...
0
votes
2answers
54 views

How do I find out what type of exception I am supposed to raise?

I suppose this question is valid for any programming language that can handle (or at least throw) an exception. However I will stick to Python as an example. The top 2 answers to the following ...
0
votes
1answer
156 views

Facing MemoryError in Python

I wrote a program to find prime factors of a number. When I give a large number(600851475143) as input, MemoryError pops up. Below is the code: def fact(a): factors = [] for i in ...
0
votes
0answers
54 views

Algorithm for the Simplication and Evaluation of Equations

As a new programmer messing around in python, I've been playing about with writing small programs which can calculate some of the stuff I did in maths at school. I've been trying to think of a way ...
1
vote
0answers
134 views

How to Use Python as a “Macro” runner for a C# Application

I am working on an application that the user may wish to automate some features of (but we don't know what at the moment) I would like to provide them some kind of scripting interface so they can play ...
1
vote
0answers
75 views

Why does recursive function for travelling to front of doubly linked list not work? [migrated]

I am a novice who has just finished edX's introductory course MIT 6.00.1x; the following is related to a problem on that course's final exam (now concluded, so I can seek help). Let def class ...
3
votes
3answers
171 views

closure property of datatype “tuple” in python

From this link, below is the slide that I would like to understand: The Closure Property of Data Types A method for combining data values satisfies the closure property if: The result of ...
2
votes
2answers
202 views

Don't repeat yourself vs do only one thing in a method

I am currently writing some test cases in python. I often end up calling the same two or three lines of code at the start of a test case in order to get the program I am testing going. For example: ...
29
votes
6answers
20k views

'import module' vs. 'from module import function'

I have always been using this method: from sys import argv and use argv with just argv. But there is a convention of using this: import sys and using the argv by sys.argv The second method ...
1
vote
1answer
75 views

adding the digits of a number

I am trying to write a program that asks the user for a decimal number and then calculates the sum of its digits. for example if the number is 123.25 then the sum will be 1+2+3+2+5=13. I decided to ...
0
votes
1answer
87 views

Best strategy for converting change in longitude and latitude to north, south, east, west in degrees

This is not a class assignment but a conceptual question I'm struggling with for a personal project. I need to convert a large paired group of long and lat coordinate values that show a ...
2
votes
3answers
916 views

Opinions on logging in multiprocess applications

We have written an application that spawns at least 9 parallel processes. All processes generate a lot of logging information. Currently we are using Python’s QueueHandler to consolidate all logs ...
10
votes
3answers
1k 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 ...
-4
votes
1answer
81 views

Understanding If Statement Syntax in Python [closed]

I've recently started learning python, I'm using Python 3.4. I'm trying to understand If-Else statement syntax x=2 if x: print(x) But I'm always encountering this Error IndentationError: ...
4
votes
1answer
66 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 ...
0
votes
1answer
100 views

Functional dependencies diagram

I'm searching for the correct type of diagram in which I can see all dependencies between the functions, classes and files of my Python program (multiple files). It's for cleaning purposes. So my ...
-1
votes
0answers
10 views

Splinter, opens up browser but won't visit webpage [migrated]

from splinter import Browser browser = Browser() browser.visit('http://www.google.com/') Straight from their tutorial, and all it does is open up a window, and I do not recieve any errors. I've ...
4
votes
8answers
520 views

Confusion regarding def function within Python

I've been learning Python for about 2 months now (Started with Learn Python The Hard Way, now reading Dive Into Python), and within both books, I still seem to be confused over this one bit of code. ...
0
votes
1answer
75 views

using one database connection across multiple functions in python

whats the best way to go about this in python? I have a number of like so def test1() .... code ..... def test2() .... code ..... def test3() .... code ..... how could I create one ...