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)

0
votes
0answers
10 views

Genetic Algorithm in Django: Defining an Individual?

I'm working on a campus assignment for creating a TimeTable using Genetic Algorithm. I'm using a C++ guide at this site but coding in django using this guide. I'm a beginner in Django programming ...
0
votes
0answers
22 views

What's the best way to search records when there's no option to fetch All?

I am trying to get names of all students of UGA by using this interface but somehow I don't find option to get all records by name. One way I figured out to use permutations like aa, ab till z. I ...
1
vote
0answers
10 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 +----------------------------+----------------------------------------------------+ | ...
-5
votes
0answers
72 views

How can an experienced programmer learn C# fast? [on hold]

I'm an experienced programmer and do most of my day-to-day coding in Python, though I've also used C, C++, and Perl professionally, and am pretty familiar with JavaScript as well. I'm wondering if ...
2
votes
1answer
117 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 ...
-4
votes
0answers
25 views

Converting from python 3.x to 2.x? [on hold]

My informatics prof told me that today would be an online informatics olympiad of sorts. I was very happy to notice that python was allowed, but it was only python 2.7.3. I have been using python 3.x ...
-3
votes
2answers
42 views

How to perform deferred tasks in backend [on hold]

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 ...
-5
votes
0answers
59 views

Help and opinions on learning higher level language (python) for web and software development [on hold]

I am looking into learning a high level language like Python for software and web development I already have some web development experience with php and mysql and I'm already very familiar with web ...
-3
votes
0answers
22 views

Python libraries research [on hold]

I want to do a project in python. Briefly explain what my idea is, what I am trying to achieve. Develope an app with a UI or web based. the system should get the logs from ftp. Parse logs and ...
1
vote
4answers
101 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: ...
-5
votes
0answers
29 views

Project help and advice? [closed]

I am looking for advice and help if you kindly could. I need to find a ggod set up for my project. I am working on a project. I am at beginner level in python !! I want to learn Python and refine my ...
3
votes
1answer
61 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 ...
-3
votes
1answer
71 views

Python simpliest UI solution [closed]

I make simple Python programs. For example my friend wants a program which can get all updated classifieds from one web page and put it into the excel file each week. I'm curious, whether is there a ...
-4
votes
2answers
89 views

How can i convert for loops to while loops for a list? [closed]

total_count = 1937 a = [1,53,24,19,89,8,51,831] freq = (float(each)/total_count for each in a)) I want to use while loop instead of for loop. How can do that for this code? My attempt is so ...
-2
votes
0answers
51 views

How can I use %i format for a string? [closed]

L_freq = [[9,'e', 0.298323234], [6,'j',0.978204], [4,'f', 0.241341],[8,'p',0.81804]] i = 0 while i < len(L_counts): row_str = "| %5i | %.4f |" % (L_freq[i][1], L_freq[i][2]) print(row_str) ...
-6
votes
0answers
34 views

How 'popular' are the various Python distribution relative to each other? [closed]

"Popular", as is more downloads/installations. (And not which has the most vocal fanbois.) I understand that folks use various Python versions and distributions depending upon what they are up to. ...
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
503 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
82 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
34 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
98 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
166 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
46 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
189 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 ...
-4
votes
0answers
14 views

how to sum lists in lists pairwise in python and put this sum in a new list [migrated]

the question is pretty clear but an example: a = [[1,2],[3,4],[5,6],[7,8]] then the list I want to make is: a_new = [ 1+3+5+7 , 2+4+6+8] The lists within the list are always of the same length ...
2
votes
3answers
89 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
99 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
57 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
150 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 ...
-4
votes
0answers
30 views

Dictionary - Find the key by entering the value [migrated]

i have a little code but i don't know how to find the key in a dictionary by using the value. Here i have my code and what i want to do: NAMES = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', ...
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
99 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
116 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
115 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
182 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 ...
13
votes
5answers
1k views

Is it a good practice to declare instance variables as None in a class in Python?

Consider the following class: class Person: def __init__(self, name, age): self.name = name self.age = age My coworkers tend to define it like this: class Person: name = ...
1
vote
2answers
116 views

Is creating and writing to one large file faster than creating and writing to many smaller files in Python on Linux?

If using Python on a Linux machine, which of the following would be faster? Why? Creating a file at the very beginning of the program, writing very large amounts of data (text), closing it, then ...
36
votes
2answers
4k views

How do I move away from the “for-loop” school of thought?

This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
3
votes
2answers
200 views

Which programming idiom to choose for this open source library?

I have an interesting question about which programming idiom is easier to use for beginner developers writing concrete file parsing classes. I'm developing an open source library, which one of the ...
2
votes
2answers
228 views

Why doesn't Python have a “flatten” function for lists?

Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] ...