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
2answers
87 views

Should serialization and deserialization be the responsibility of the class being serialized?

I'm currently in the (re)design phase of several model classes of a C# .NET application. (Model as in M of MVC). The model classes already have plenty of well-designed data, behaviors, and ...
2
votes
1answer
76 views

How do I distinguish derived code from original code?

I'm working on a Python project which extends the functionality of some other python modules. Some are part of the standard Python library and mostly use the PSF License agreement while some are ...
0
votes
1answer
37 views

Normalizing a numpy array

I checked a while back for questions relevant to my own about normalizing numpy arrays but couldn't find any. So I'll pose my question following this line of code: for i in ...
-2
votes
0answers
11 views

Using SAML with Python (client application) [on hold]

I am writing a script that need to authenticate against a site that uses SAML to verify the user's identity. Can anyone provide a sample or point me to a simple working example of doing this with the ...
1
vote
1answer
51 views

Should I automatically install needed modules?

I'm writing a program for my grandpa. Occasionally an update will require a new module that's not installed on his computer. I don't want to have to manually install new modules every time, but he's ...
2
votes
1answer
87 views

Python Classes and Design Questions

What is the best way to design a class to see if an update occurs on a property? I have a whole bunch of classes, and current am going through a re-design of the python package I created. ...
-5
votes
0answers
13 views

Why does next(some_generator_func()) yield a different result from next(a_var), where a_var = some_generator_fun()? [migrated]

Let some_generator_func() be the function: def some_generator_fun(): yield 1 yield 2 Why is it that >>>>next(some_generator_func()) 1 ...
0
votes
0answers
52 views

Will this data mining approach work? Is it a good idea?

I need to extract fields like the document number, date, and invoice amount from a bunch of .csv files, which I believe are referred to as "unstructured text." I have some labeled input files and will ...
-7
votes
3answers
125 views

Why different languages have different syntax? [duplicate]

Different programming language always/most of the time use different syntax. For example take PHP, Java and Python. In Php & Java semicolons are compulsory at the end of the line, yet Python ...
-5
votes
0answers
28 views

trouble in printing row from two text files [closed]

i have two txt files of three columns each,but unequal rows. from the two files i have to perform an operation using 2nd and 3rd column of both files simultaneously. do an operation and then if ...
4
votes
3answers
217 views

What's special about “non-blocking” node.js?

In the short chapter, What is Node by McLaughlin, he writes: "Node has no blocks, no threads competing for the same resource (Node is happy to just let things happen however they happen), ...
-3
votes
0answers
26 views

Programming design on heavy web I/O Django based scrapping application [on hold]

I've started a project few month ago for closest to real time database operations next to HTTP requests. I choose Django + Celery as a first place, then tried with home made multiprocessing + ...
-1
votes
0answers
22 views

Create/run a script, which securely stores account info, searches, scrapes targets, and then displays targets in canvas, without installing Python [closed]

I made the title as brief and to the point as I could but I'll be more detailed here. I have a Python project in mind that I'd like to start working on now even though I'm still learning and should be ...
4
votes
2answers
896 views

Does this code follow duck typing?

The principle of duck typing says that you shouldn't care what type of object you have - just whether or not you can do the required action with your object. For this reason the isinstance keyword ...
0
votes
0answers
27 views

list is editing all values instead of just one [migrated]

snake = [] snake_size = 10 snake.append([display_width / 2, display_height / 2]) snake_dx = 10 snake_dy = 0 #I then declare some more lists in snake in an identical fashion for i in ...
-3
votes
0answers
39 views

set() is the value in a key:value pair?

I'm working on dictionary comprehension for a database so that I can save various database tables as nested dictionaries for easier data manipulation. SQLAlchemy Core has a good tutorial with an ...
2
votes
1answer
46 views

Best practices for a daemon that forks and becomes user

I want to write a small daemon in python under Linux that accepts connections and authenticates the user (details for this don't matter) and then forks a child for the connection and becomes the user. ...
0
votes
0answers
20 views

Ipython3 development cycle

I am new to python (python3) and am using Ipython3 while writing the code just in my preferred text editor. I am not yet sure what is a good development cycle as I keep getting problems with reloading ...
2
votes
1answer
29 views

log method calls per object

How to log method calls on a per object basis for a particular class? I.e. after instanciating a = myClass() I somehow want to keep a log for what methods have been called on a like a.reverse() ...
-4
votes
1answer
62 views

How do I use a list of int to set the index of another list [closed]

I want to use a list called index with only ints to use it to set the index of another list. index = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26] dictionary = ["a", "b", ...
3
votes
3answers
76 views

How to structure project where a library and application using the library are concurrently developed?

I am planning to develop a new application that will heavily use a library that will be developed from scratch specifically for the application, but made general enough for it to be used for other ...
0
votes
1answer
50 views

Efficient way to handle foreign keys

I am building a script that checks a large network of sites for invalid links. The idea is to flag links that continuously show as not available so that they can be cleaned by the administration team. ...
-2
votes
0answers
24 views

Use Bisection Search to guess number [migrated]

I'm writing a program that is supposed to guess the user's secret number using bisection search. I feel like I understand the concept of bisection search quite well but my IDE (Canopy) won't let me ...
-6
votes
1answer
108 views

I wrote a Python Switch statement [closed]

I wrote a python switch statement. I have seen a number of of examples that were outlandish and I was wondering if my switch statement is worth having and as it is written, what is a better way to ...
-5
votes
1answer
63 views

Linux on USB for Python (or other) Programming on the go? [closed]

This is my first question and I didn't see a similar question asked. Sorry if I didn't search hard enough. To the point. I'm learning the Python programming language and I've read Linux plays very ...
-1
votes
0answers
17 views

Unique path for file upload [duplicate]

What is a best practice to follow for the following problem? Say you have a web service in which an authenticated user needs to upload a file and from this file (say a cv in pdf) other info might be ...
-1
votes
0answers
34 views

Taking screenshot of website with python results in blank page [migrated]

So I'm trying to take a screenshot of a website using a python script: #! /usr/bin/python import sys import time from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * ...
0
votes
0answers
41 views

Best practices for creating a project utilities module? [migrated]

Does anyone know of any best practices around creating a utilities module or class specific to your project? I have a project I've been working on that has three different moving pieces, but we keep ...
0
votes
0answers
6 views

Compilation difference in Spyder IDE and Python intrepeter [migrated]

This problem may seem a little strange, but a while (about 1-2 weeks) ago I wrote a little Python script which I tested and everything worked just fine. Today when I was taking lines from this latter ...
-1
votes
2answers
57 views

python code style for long lists [closed]

when coding a very long list in python, is it better to fit several items on each line or should I limit it to 1 per line? 99% of the time I would go with style2 below but I have 5 lists each about ...
0
votes
1answer
49 views

Python replace function for classes? Like namedtuple _replace?

Does the Python standard library offer anything similar to the custom replace function below? I can put this in my own *utils module, but I'd rather use a standard library implementation. Also, this ...
0
votes
0answers
33 views

Programming to multiple backends

My current project is a high-level abstraction package for GPIO programming on those nifty little SoC-Computers (Raspberry Pi, Cubieboard, Beaglebone Black, Pandaboard etc.). One of my goals is to ...
0
votes
0answers
25 views

Python 2.7, Binary & ASCII [migrated]

I'm new to Python and I've just completed my first book, so my knowledge is somewhat average of known terms etc, but as practice I've been accessing an API, Information on it is located here; ...
0
votes
3answers
158 views

Best algorithm to determine whether two arrays can be the same in a circular queue

I'm trying to figure out an efficient way to determine whether two distinct arrays of the same size can be shifted to form the same circular queue. For example: Array1 = ['A','B','C','D'] Array2 = ...
0
votes
2answers
95 views

Difference between PyPy and JVM

From my understanding the default Python interpreter(CPython) compiles source code into bytecode and then interprets the bytecode into machine code. PyPy on the other hand makes use of JIT to optimize ...
1
vote
2answers
201 views

Is it good programming practice to create files with no extension? [closed]

I often store data in external files when Python coding. Should I always save them with an extension - i.e. .txt? Is there any reason not to (other than saving bytes) to not give the extension? I ...
23
votes
6answers
3k views

Can you implement “object-oriented” programming without the class keyword?

Say we want to provide an abstraction of an "account" in a bank. Here's one approach, using a function object in Python: def account(): """Return a dispatch dictionary representing a bank ...
3
votes
3answers
157 views

How to best encapsulate features in code and enabling/disabling them at runtime?

I would like to be able to abstract each feature developed by the team in a way that it can be enabled or disabled at runtime by using a distributed shared configuration system. Features are small and ...
2
votes
1answer
82 views

Break big method into 2 methods, first containing a “for” loop and second a “break”

A method grew too big for its own good, and I need to break it up into two separate methods. def big_method(dct): # Initial code # ... for i in dct: # More code # ... ...
0
votes
1answer
47 views

Changing coordinate systems in python

I am working on a visual python program that is meant to model the orbit of an electron around the core of a Hydrogen atom. In order to avoid the singularity at r = 0 in the equation for coulomb ...
3
votes
1answer
80 views

Encapsulating mutable objects with special structure in Python

I am writing a library for working with special types of trees, called Foo trees. A Foo tree has very special structure. There some operations, called bar and baz, which only make sense on Foo trees. ...
0
votes
3answers
154 views

Python: Are all dictionary comprehensions just more expressive and compact for loops? [closed]

Recently, to describe dictionary comprehensions in Python, I wrote: dictionary comprehension is just a more compact & expressive way of writing the same logic as for loops (performance may ...
5
votes
2answers
105 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 ...
4
votes
3answers
100 views

Parent class using methods defined in child

I am working on a large program (more than 10k lines of code). Below is a (hopefully not over-simplified) example of a problem I sometimes face: class MyClass1(object): def func_1(self): ...
1
vote
2answers
123 views

Is it a good idea to install more libraries than you need? [closed]

I decided to try Anaconda, it seems that too many large companies are using it. I was amazed by the number of libraries included by default installing: python-2.7.9-2 ... installing: ...
1
vote
2answers
105 views

Complex data structure in python: just dict, etc, or some classes?

Consider a web service API that returns a complex Json object. Using the stock Python tools for the job, this will read in from the web service as a dict which contains, in turn, a mixture of arrays, ...
0
votes
2answers
36 views

Python packages from an operations perspective

As a developer I am used to keep my Python tools updated. Especially packages needed for installing and bundling. Using the most recent releases of pip, virtualenv and setuptools is in my personal ...
0
votes
2answers
49 views

Testing binary stream

I am building a binary file importer using Python. The specific file structure is defined in a specification. This looks like: File Map Block String, Short Integer, Long Integer, String, Short ...
1
vote
1answer
50 views

Python - best way to have interdependant variable in a class

Newbie Python questions: I want to model something that can have a several inter-connected instance variables and if I set one, I want to recalculate the others. Any can be set. E.g. a circle - each ...
4
votes
4answers
337 views

Legitimate cases of having .equals() behaving inconsistently with .compareTo()?

Java documentation says it's "strongly recommended" to have them behaving consistently. But are there legitimate cases of java/c#/python/etc Object.equals() method behaving inconsistently with the ...