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)

8
votes
6answers
2k views

Which style to use for unused return parameters in a Python function call

Is there any recommended/generally accepted coding style for handling situations where a function returns a tuple of values but only one of those values is used afterwards (note that this is mostly ...
-4
votes
0answers
26 views

Printing Unicode elements in a loop [migrated]

Consider this: print u'\u2599' I get ▙ something like this, which is what I need But when I try to run it in a loop like this : for i in range(2500,2600): str1 = """u\'\\u""" + str(i) + ...
2
votes
1answer
305 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 ...
3
votes
3answers
141 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 ...
-6
votes
0answers
22 views

How to align a nucleotide sequence against a set of them in a database? [on hold]

How to align a nucleotide sequence against a set of them in a database? Need a sample Python , Java or Ruby code showing the alignment of an input 1000 bp sequence against a set of them. I could find ...
19
votes
5answers
1k views

Will Python 3.0's backwards-incompatibility affect adoption? [on hold]

I visited Slashdot this morning to find out that Python 3.0 has been released. I know C# and Perl, but have wanted to learn Python for some time, especially after I saw its ease of use to create ...
2
votes
1answer
74 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
41 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 ...
-7
votes
0answers
50 views

Is python supposed to run stand alone? [closed]

I am trying to make a stand alone application. after I wrote a program, I want it to be a stand alone program. But it seems that that's not quite easy. are all other programing language like this? or ...
-3
votes
0answers
20 views

Good code resource to learning database interaction [closed]

I am currently working on project with MySQL database and I am looking for good practices to working with database in Python. The next problem I have is that I want to start with unit testing ...
1
vote
1answer
64 views

Persist data downloaded by Celery workers

I'm working in a tool that downloads tweets from Twitter to process them later. For this purpose I'm using Celery with RabbitMQ, sending task with the keywords that must be tracked by the workers. My ...
-5
votes
0answers
22 views

Python programming - Output issue between each function call [migrated]

def displayChar(d): if d.isalpha(): print(d, "is a str") elif a.isdigit(): if 'float' in str(type(eval(d))): print(d, "is a float") else: ...
6
votes
1answer
1k views

Can one edit a built-in Python module?

I'm currently learning Python and I'm at the point in the book about using the Math library. I looked on the Python website and noticed the library was a bit scarce and am writing some more useful ...
5
votes
2answers
94 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 ...
3
votes
1answer
66 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. ...
2
votes
2answers
3k views

Python - assert vs if & return

I am writing a script that does something to a text file (what it does is irrelevant for my question though). So before I do something to the file I want to check if the file exists. I can do this, no ...
0
votes
1answer
40 views

Making API calls with celery

I'm designing a system for a client where the requirements are: they upload a JSON file (one object/line) make a call to an API with the JSON object as the payload record the state (success/failure) ...
0
votes
3answers
145 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 ...
1
vote
2answers
145 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 instance, let's say the maximum number of entries is 1000 and the class already ...
2
votes
3answers
987 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 ...
4
votes
8answers
539 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. ...
4
votes
3answers
89 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
106 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: ...
0
votes
1answer
54 views

Django urls.py runs only once. Why? How does it call views on next request?

While testing django cashing on our development server, one of our senior asked if is it possible to change the value of caching timeout on urls.py without restarting the http service. On first note, ...
1
vote
2answers
81 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, ...
5
votes
1answer
165 views

Python rectangle packing

I'm working on a project which involves packing multiple rectangles in a larger rectangle(the bounding box). Rectangles can't overlap with each other or with the boundaries of the bounding box. ...
0
votes
1answer
483 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
2answers
30 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
0answers
44 views

How to avoid the redefinition of a function (PEP8 error F811) [migrated]

I have the following code inside a Python function: strings = ('TIRS10', 'TIRS11') if any(string in fields for string in strings): def transform(row): ''' Transform an input row ...
0
votes
2answers
41 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
41 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 ...
0
votes
0answers
7 views

Python: Replace Numpy with new version [migrated]

I'm new to Python. I've installed Python 2.7.9, which comes with Numpy as default. The problem is, current Numpy version is 1.7 but I need to replace it with 1.9 version. I've downloaded Numpy zip ...
1
vote
0answers
52 views

Improve communication between controller and trackers in a Twitter fetcher tool using RabbitMQ or Apache Flume

I've been working for a time with some researches developing a tool to fetch tweets from Twitter and process them in some way. The first prototype "worked" but became a pain as we used sockets to ...
0
votes
1answer
147 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 ...
35
votes
5answers
3k views

Java dev learning Python: what concepts do I need to wrap my head around?

Background: I've run through a few tutorials and written some small projects. All is going well enough using Google and StackOverflow. Several times in the last few days I've found myself wondering ...
4
votes
4answers
325 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 ...
15
votes
11answers
11k views

Why is Python recommended as an entry level programming language?

I've read here on P.SE more questions in which beginner programmers are advised to pick Python as their first programming language. Don't get me wrong, I like Python. I like it a lot! But its ...
7
votes
4answers
3k views

Is it possible to write an anti-virus like thing using C# or Python? [closed]

C# and Python can't compete with C and Assembly when writing such tools is the need. I left C many years back and I don't think I will be able to cope up so fast. Is it possible to write Anti-Virus ...
0
votes
1answer
58 views

Setting up folders and importing modules in Python

I'm building an app to automate some processes that are annoying to do by hand (looking in a file, taking certain information out of a file, building another file with that information). My project ...
5
votes
2answers
1k views

Every function is a closure?

Wikipedia says, that closure - is a function, which has an access to variables, declared outside of the function. There is even an example: function startAt(x) function incrementBy(y) ...
0
votes
1answer
99 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 ...
3
votes
2answers
107 views

Should static analysis be integrated with code review? [closed]

I want to integrate various static analysis tools, and then add the results as comments on a file within code review tools, such as Stash or Review board. I am exploring the feasibility of writing ...
3
votes
1answer
1k views

What are your techniques for storing numpy structures in django database fields and how do you serialize them for http? [closed]

I want to publish a small web project that is supposed to contain some of my research results to present it to the scientific community. All my analysis I ran so far have been written in python ...
-5
votes
0answers
9 views

Python print function doesn't work [migrated]

I have followed this tutorial. But I do have a small question. I have copied the exact code in de text editor, and I have the exact same settings in Glade. But when I click the refresh button, I dont ...
5
votes
4answers
2k views

Behavior Driven Development and Unit Testing in Python [closed]

We might be interested in starting to incorporate a unit test suite to our project, which is coded in Python (and it uses Redis, PostgreSQL and some third-party libraries, if that bears into the ...
1
vote
3answers
226 views

Check distance between all elements in a list of numbers in O(n*lg(n))

I have an exercise for my algorithms and data structures class, where I basically have to implement a divide and conquer algorithm or function called check_distance to determine whether all numbers in ...
3
votes
4answers
141 views

Finding the first index in which the element and the index are the same

I am to build a python function that takes a sorted list of numbers and outputs the first index the is equal to the element in its place. It should run on O(log n) which I know how it should be ...
0
votes
1answer
70 views

How to write a suitable recurrence relation for a python function?

I have an exercise in which I am require to build a recursive function that takes a natural number and returns "True" if it is divisible by 3, or "False" otherwise, using the 3-divisibility rule. Then ...
29
votes
4answers
22k views

Why store a function inside a python dictionary?

I'm a python beginner, and I just learned a technique involving dictionaries and functions. The syntax is easy and it seems like a trivial thing, but my python senses are tingling. Something tells me ...
-3
votes
1answer
69 views

Executable File Size Difference Between Python and C [closed]

Does using lower level programming languages have benefit of generating lesser file size when creating an executable, in contrast to using higher level languages for the same algorithm?