Tagged Questions

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)

-4
votes
0answers
36 views

Glued code performance: How does this approach change your code performance? [on hold]

I recently stumbled over this idea when I was optimizing my Python code. How much of a difference does it make if you produce code in a language like Java versus a program architecture written in ...
-2
votes
0answers
32 views

Measuring Damerau-Levenshtein distance in Python

I'm working on a searching in dictionary. I want to check all words from the dictionary whether they have Levenshtein (or better Damerau-Levenshtein) distance lower than (for example) 2 compared to ...
-5
votes
0answers
43 views

Why doesn't my program see the # boundary condition? [migrated]

There is the program I have been writing. All the variables have been defined in the main function. When I compile, it does not give me errors, but it just does seems to see the #boundary condition ...
-5
votes
0answers
49 views

What technology should I use to build website like Quora (Q & A)? And How should I approach building something like that? [on hold]

I heard Quora is built by Python and Javascript. I was thinking about doing it by PHP. What is better ? Python or PHP ? Also does Quora uses only Python and Javascript ? What about HTML and CSS ?
0
votes
1answer
35 views

Is there a canonical way to cache instance methods in python?

I have some computationally intensive functions in my python script that I would like to cache. I went looking for solutions on stack overflow and found lots of links: ...
-3
votes
1answer
59 views

Understanding searching through dicts in python [on hold]

I'm trying to understand the differences between dict, dict.items and dict.iteritems. I know that items returns a list of all the items, while iteritems returns an iterator, which for large lists can ...
0
votes
1answer
38 views

No repeated coordinates in random walker ensemble

i'm simulating an ensemble of random walkers in 2D in python, I set [x,y] coordinates of my walkers to be gaussian in a 2D grid, then use a rand array of -1 and +1 to move up down left right: N=20 ...
-2
votes
0answers
70 views

Solving a programming puzzle using Python [closed]

I am trying to solve a seemingly simple programming puzzle as mentioned below using Python: Using digits from 0 to 9 only once, find two numbers such that their product is maximum. I will give the ...
0
votes
0answers
21 views

Python - Function - Argument said to be “undefined” [migrated]

I'm currently taking a Python course, and got to the chapter in our book that talks about functions. (Please note, this is my first time learning any programming.) One of the exercises I'm working on ...
-4
votes
1answer
61 views

How biggest is determined in this case (Python) [on hold]

I'm learning introduction to computer science on Udacity and have the following code. First part with bigger function is understood but i don't understand the second function biggest please explain me ...
2
votes
2answers
102 views

How much should I break up my unit tests?

I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). ...
-4
votes
0answers
41 views

Python loading contents into a directory? [closed]

Is it possible to load the contents of a txt file into a python directory along with a key in basic python. What i want to happen is for a text file called items.txt with the contents coke:1.40 ...
1
vote
1answer
195 views

Should I couple these classes?

I am programming in Python. I have several complicated/hard-to-understand XML files that describe the structure of an election. I am trying to write a python wrapper that makes it easy to access this ...
0
votes
1answer
137 views

Best practices for developing desktop application for Windows and Linux? [closed]

I have to provide a small application that should be run on both Windows and Linux \UNIX. A desktop application. It should provide one screen and a few buttons on it. It should run some commands in ...
1
vote
1answer
67 views

Transferring information between a web server and a Python backend?

I have been Googling my problem but haven't been able to come up with anything; here's the situation: I have a PHP / MySQL website hosted with 1and1.com. I also have a Python program that runs on a ...
0
votes
1answer
30 views

Plugins and exporting an API between python scripts

I've got a python script, which should read a subdirectory and make all the scripts within it callable like this: python mainscript.py subscript arguments I've figured out most of the details but ...
1
vote
2answers
147 views

How-To: a browser based, real time, shared memory inspection/debugger application [closed]

Background: I have a C application running under Linux utilizing shared memory. I also have a debugger written in Python that can link to said shared memory and access individual variable values of ...
0
votes
0answers
38 views

Behavior Driven Testing / Acceptance Tests for python script [on hold]

I have to write a script which consists of several functions like searching for a text inside a file, checking processes, querying databases ... I am planning to write several classes, each fulfilling ...
1
vote
0answers
24 views

Breaking a table over multiple lines in Sphinx

Lets say I have the following function with a docstring: def foo(*args): """ do some fooness +----------------------------+----------------------------------------------------+ | ...
2
votes
1answer
129 views

What exactly is this Python statement doing?

I'm trying to port a very basic dual contouring algorithm written in Python (here) to C++. I'm not a Python programmer so some of the language syntax is a bit foreign to me. Specifically, this block ...
-3
votes
2answers
47 views

How to perform deferred tasks in backend [closed]

Actually the problem is very common. Let me describe this by example. Imagine you have a web service where users register and pay for some gold status. There is expiration date. The question is how to ...
1
vote
4answers
109 views

How to clean up nested try/except/else?

When writing code, I often want to do something like this: try: foo() except FooError: handle_foo() else: try: bar() except BarError: handle_bar() else: ...
3
votes
1answer
69 views

Seeking Guidance on Thread Safe Scripting

I am trying to write a script that will take multiple paths to files on various servers, search them all simultaneously, and return a single list of results to a user. Initially, I was just using ...
0
votes
0answers
5 views

python py2exe can't find pywinusb [migrated]

I am using Python 2.7.8. I installed the following: py2exe-0.6.9.win32-py2.7.exe and pywinusb-0.3.3 I have a script that I am trying to run. When I do I get the following error: ...
-3
votes
0answers
44 views

Rock, Paper, Scissors on Python - Can't get computer to play? [migrated]

# This program will generate a random game of Rock, Paper, Scissors # in which the player will be able to win/lose against the computer import sys import random ...
-2
votes
0answers
47 views

How can I count the length of the output of print in Python? [migrated]

Is there a way to count the length of an output from print in Python? For example, I want to count the length of the output: print ("|L|",*L, sep='') where L is a list. I am not trying to get ...
0
votes
0answers
34 views

Advice on which approach to follow for sandboxing the input in an intentional “vulnerable” web app (sandbox in python) [duplicate]

my question is about which is the best approach/practice on building a "sandbox mechanism" in Python in a web application. The app will provide intentional vulnerable scenarios, and the user has to ...
4
votes
3answers
511 views

How to avoid large function arity / exposure of underlying implementation

Currently reading Clean Code, and the authors seem to imply that any function with an arity greater than 3 should be avoided at all costs. I am unfortunately running into an issue where I am faced ...
0
votes
2answers
87 views

Prime symbol in Python variable name

So I'm a terrible person and I want to name a variable in my mathy-python3 code s′ (that's a prime symbol). I was under the impression Unicode literals work as identifiers in Python 3, which is why ...
-4
votes
0answers
12 views

Read File strip whitespace [migrated]

Working through CorePytho I can print a file using code below w/ eachLine, If I remove the comma it is doublespaced. I am trying to strip the whiteaspace w/o using the comma - no looking for an ...
0
votes
0answers
6 views

How to get string in a function in Python? [migrated]

I am current writing a game with tkinter GUI Python. import sys from tkinter import* #Functions to handle button click def startgame(): player21abel=Label(text=" Guess a Letter ...
0
votes
1answer
35 views

Is there a cleaner way to test extras_require

I have code reviewed a piece of Python code, but to me it looks really ugly, hacky and complex for something that can be achieved very easily. The code looks something similar to the following: ...
1
vote
2answers
100 views

Function has two sets of arguments, the latter of which calls a nested function? [closed]

The function foo, has a nested function; bar. Calling foo with a second set of arguments feeds them into bar if bar is returned at the end of foo. How does this work and what is it called? Are there ...
0
votes
1answer
169 views

Is there a way to prevent variables from changing their type in Python?

It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto keyword in C++11. However, in Python variables can change their type after ...
0
votes
0answers
48 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 ...
-2
votes
1answer
190 views

Base Class, with method that returns Derived Class. design flaw?

I'm writing a Math equation solver in python (for fun). The first design that came to my mind: Expression: base class for every item in an equation (maybe bad name). BinaryExpression extends ...
-2
votes
0answers
14 views

Print the longest common sequence [migrated]

I am trying to implement solution of the classical problem, but I am confused as I get some cases where I don't find good results. Output: "The Longest common sequence", "Length" def ...
2
votes
3answers
93 views

Lambda expressions with no parameters in Haskell and / or lambda calculus

In eager languages like Scheme and Python, you can use a lambda expression without parameters to delay evaluation, e.g. in Scheme (Chicken Scheme): #;1> (define (make-thunk x) (lambda () (+ x 1))) ...
0
votes
1answer
62 views

Should instance variables be bound to the instance right in the beginning of the method they are created in?

A common problem for me - and it's not really a problem, but somehow I again and again ask myself, what is the normal way to handle this - is that there is a method and within this method a couple of ...
2
votes
1answer
100 views

Building a string parser for user command and control?

My goal is to build a command parser that has basic syntax and multiple possible branches at each point. These commands come from users of the system and are text input (no GUI). The basic syntax is ...
2
votes
1answer
59 views

Python property best practices [closed]

Is there any situation where it makes sense to define a python property, where getting (not setting) it would raise an exception? I don't think this ever happens for fields in classes, hence the ...
0
votes
3answers
151 views

Is this a pattern: stand-alone classes

Having recently discovered python, I attempted to write a simple logger. Data is read from a device, processes, displayed and stored on disc. Those different tasks belong to different modules, of ...
1
vote
1answer
66 views

writing functional/integration tests for python

I am new to python and functional/integration tests as a whole. I know how to write unit tests, but in this case i do not need isolation for specific functions, rather i need my python script to be ...
3
votes
2answers
134 views

Is a bad practice create database structure on the runtime?

Im creating a crawler app that will always in the beggining, when the Class constructor, ensure that the basic database structure exists. Is this a bad practice? What is the advantage os creating the ...
-1
votes
1answer
102 views

Unevenly distributed random number generation [duplicate]

Let's say I have to generate random number from 1 to 100, however, the probability of each number is not 1/100, but a predefined probability. How to generate that number? I use Ruby/Python.
1
vote
4answers
118 views

Efficient “Object with weights” structure

I need to find an "efficient" data structure / set of algorithms to do the following things: I have a list of objects. I need to assign them weights and later on increase or decrease these weights. ...
0
votes
1answer
117 views

Simple unicode application?

I want to create simple language learning applications to help friends in learning languages. A simple Java console application would do the trick, but the Windows console does not seem to handle ...
0
votes
2answers
124 views

At what point should you start putting functions in a new file? [closed]

I'm currently writing a python script. It's currently about 400 lines long, and it seems like it's getting a bit long, as when I'm trying to scroll through it with eclipse it takes a bit to get from ...
0
votes
1answer
92 views

Should an object query its owner?

I have a World class World: def __init__(self): self.size = 10 self.n_busStops = 10 self.busStopMatrix = SpatialGraph(self.size, self.n_busStops, 1.0) self.buses ...
4
votes
6answers
187 views

Should I store x,y coordinates as an array, a class object, or two variables?

I have a MyObject which has an x and y coordinate. as far as I can see, I can store it in three ways: class MyObject: def __init__(self, x, y): self.x = x self.y = y class ...