Python is a dynamic and strongly typed programming language that is designed to emphasize usability. Two similar but incompatible versions of Python are in widespread use (2 and 3). Please consider mentioning the version and implementation that you are using when asking a question about Python.

learn more… | top users | synonyms (3) | python jobs

0
votes
1answer
20 views

Why is operator giving different output for immutable objects?

code "python" is "python" returns "true". But why (1,2,3) is (1,2,3) returns "False". Even though both are immutable objects "is" operator computing differently why?
-2
votes
1answer
12 views

python for loop expression of iterator

I have a for loop in which I use the iterator always in the same manner, like this for dict in mylist: var = dict['prop'] var2 = f( dict['prop'] ) ... This is clumsy. The only ...
0
votes
0answers
5 views

How do I convert Python POST data to JSON?

I have the following code in Python: def post(self): example = self.request.get("example") other = self.request.get("other") How do I get all post data if unknown? I'm very new to Python ...
-3
votes
0answers
13 views

Recommended Language/Framework to Build a New Recommendation Engine [on hold]

Next week I'm going to begin prototyping a recommendation engine for work. I've implemented/completed the Netflix Challenge in Java before (for college) but have no real idea what to use for a ...
0
votes
1answer
12 views

ferris wheel animation (making things move in a circle) python

I am trying to make a ferris wheel animation (in practice for object oriented programming) but I am struggling to get the carriage around the wheel. #ferris wheel(circle) pygame.draw.circle(screen, ...
0
votes
0answers
17 views

How to do complex query like this

I have the following get and get_queryset methods in my CustomersListView class: def get(self, request, *args, **kwargs): """ :param request: :param args: :param kwargs: :return: ...
-3
votes
0answers
21 views

Python Search for WHOLE words

I am running Python V2.7 I would like to pinpoint a whole word in a string, but I am having troubles. I have tried using the in statement but no luck. Heres and example: if "word" in "Sword" # This ...
-1
votes
0answers
6 views

How to compress a directory into 7zip password encrypted archive?

I want to compress a directory recursively into a password encrypted 7zip archive using Python in a platform-independent way. I considered using these approaches, but none of them I found acceptable: ...
1
vote
1answer
25 views

Import object declared inside __init__.py

I'm having trouble understanding how objects declared inside '__init__.py' are/should be imported to other files. I have a directory structure like so top/ | |_lib/ |_ __init__.py |_ ...
0
votes
1answer
17 views

importing numpy in python3

In the terminal I did pip install numpy. It seems as if I can access numpy in the terminal but not in the shell. How can I import numpy into the shell? I keep getting import error: no module named ...
-1
votes
1answer
31 views

How to find the nearest prime number in an array, to another number in that array?

I wanted to find out the nearest prime number (that is present in that array), to any another number in the array ? Example : list a -> [1,2,4,6,8,12,9,5,0,15,7] So the nearest prime number to 4 ...
-1
votes
2answers
29 views

How to find length of dictionary values

I am pretty new to all of this so this might be a noobie question.. but I am looking to find length of dictionary values... but I do not know how this can be done. So for example, d = ...
0
votes
0answers
6 views

How to use django-paypal to update a users account balance

I'm using the standard django-paypal module found here: https://github.com/spookylukey/django-paypal What I am trying to achieve is a person can add funds to their account on my website without ...
0
votes
0answers
7 views

3.4 urllib.request.urlretrieve time between block reads increase after a few MB

I'm using a little script to automatically download multiple large files. To achieve that I tried the urllib.request.urlretrieve function and my only problem is, that after downloading about 5MB the ...
1
vote
2answers
16 views

Pandas to_csv — date formatting other than 2 digits

There is a widely-quoted method in the following answer for specifying date format when using pandas to_csv: How to specify date format when using pandas.to_csv? This answer describes: ...
-1
votes
2answers
17 views

“None” output after raw_input in Python 2.7 bug

This is a part of a text adventure that I am working on. It works fine until the user inputs any button to start, and then it prints "None". I was wondering if there was a simple way that I either am ...
0
votes
1answer
17 views

Interpolating R objects into R code strings

I am using rpy2 to run some R commands. Dont ask why. It's necessary at this moment. So here's a part of the code. import pandas.rpy.common as com from rpy2.robjects import r #Load emotionsCART ...
0
votes
1answer
38 views

Python sort is not working appropriately

I am trying to sort a list in python by one of it's property, however, it's not sorted correctly, any hint. I try to print the value before and after sort, they are printing the same value. def ...
0
votes
1answer
19 views

Logging into a website and retrieving HTML with Python

I need to log into a website to access its html on a login-protected page for a project I'm doing. I'm using this person's answer with the values I need: from twill.commands import * ...
0
votes
2answers
16 views

Python - Sending “partial” GET requests

So I was reading about these partial GET requests that would make a server timeout the connection after a while on this request. How would send a partial GET request?.. import socket, sys host = ...
0
votes
1answer
23 views

Combining a small list with many tuples to create a dictionary in python

Currently I have a list of 6 items I want to use as a key inside a dictionary and assign each item to an individual item in a 6 tuple than throw the two into a dictionary, eg: l = [a,b,c,d,e,f] t = ...
-1
votes
1answer
22 views

Two Lists of strings: remove strings from list A that contain any string from list B?

I have two lists of strings. filters = ['foo', 'bar'] wordlist = ['hey', 'badge', 'foot', 'bar', 'cone'] I want to remove every word in the wordlist that contains a filter. def ...
0
votes
1answer
14 views

Python writing codes to get the most active customer and least customer

We are asked to design a GUI to calculate the most active and least active customers. There are two buttons at the bottom that will calculate the most and the least active customer. There is also a ...
-6
votes
1answer
23 views

How to print the codes in python? [duplicate]

How does one print the lines of code? Suppose we have here two variables. var1 = 2*8 msg = "Answer is: " What statement should i add here so that this program will print the source code?
0
votes
0answers
9 views

Python multiprocessing within a class method

I'm attempting to run Python methods using multiprocessing as: from pylab import * import multiprocessing class surface(multiprocessing.Process): def __init__(self,fE,fH,pm): ...
0
votes
0answers
13 views

Cython: are typed memoryviews the modern way to type numpy arrays?

Let's say I'd like to pass a numpy array to a cdef function: cdef double mysum(double[:] arr): cdef int n = len(arr) cdef double result = 0 for i in range(n): result = result + ...
0
votes
0answers
10 views

Append choices to choice list in Django models dynamically

I want to select the options from a list in my django models. But the options in the list are populated in the post_save() method.The situation is like this: I enter some attributes in the table1 ...
0
votes
1answer
16 views

How to find duplicates values in list Python

I was wondering how can I know if when a user inputs a value, that value already exists in a list. For example; lis = ['foo', 'boo', 'hoo'] user inputs: 'boo' Now my question is how can I tell ...
1
vote
1answer
10 views

Selenium Firefox webdrive, using Python, scrolling in div

I have been using python for a while, I want to save specific webpages which require prior login. Since this website uses javascript, I decided to use selenium for python with firefox webdrive. I was ...
1
vote
1answer
10 views

using bottlenose in python to extract product price from Amazon in different locale

I am using bottlenose to extract product prices from Amazon, things are doing OK for extraction from Amazon.com, I tried to expand the search to Amazon.co.uk, I applied an associate account in ...
1
vote
1answer
15 views

Populating “data” section of a post request with function

Trying to populate the "data" section of a urllib request in python with values from a list, and some formatting. Say I have a list like this [1492, 1493, 1493, ...] and I want to get those two ...
0
votes
3answers
47 views

Struggling with a project in python

My assignment is to make this program. A program that reads tests.txt, displays all of the scores, and the average of the scores. This program must also use a loop. This is what I have so far: def ...
0
votes
2answers
26 views

Searching through a 2D list?

I have a 2D list that contains a list of lists of music info like so: tracks = [(The Beatles, Yellow Submarine), (Green Day, American Idiot)] I'm trying to make a function that will ask the user ...
0
votes
3answers
48 views

python detect if any element in a dictionary changes

Rather than saving a duplicate of the dictionary and comparing the old with the new, alike this: dict = { "apple":10, "pear":20 } if ( dict_old != dict ): do something dict_old = dict How is ...
0
votes
0answers
9 views

ld: library not found for -lboost_python

I install boost using brew install --build-from-source --with-python --fresh -vd boost. Yet when I run make pycaffe in the Caffe project, I get this error: ld: library not found for -lboost_python. ...
0
votes
1answer
10 views

django remove value from select list when in edit template

I am using Django 1.4.6. I want to remove the 1st item in a html select list when the form is in edit mode. I have read I should use pop(0) to remove the 1st value of the select list, but I am ...
0
votes
1answer
13 views

Django Model OneToOneField from existing primary key

I'm working with an Account model and I want to inner join it with a Settings model without having to create an additional settings_id column in my Account model, because the PK on the Account table ...
0
votes
2answers
34 views

Print out all code in a Python script

How can I print out the contents of a Python script? For example, if I have this (pointless example) script: my_var = 1 + 1 another_thing = "this is my string" What line can I add to it, to get ...
0
votes
1answer
10 views

how do I get my paint program to contenue after user inputs wall info in python 3.4

Im writing a paint program that's supposed to determine the cost of painting the walls of a shed with a rectangular floor. Im supposed to assume the shed has no windows and that the paint cost is $40 ...
0
votes
0answers
18 views

Sending packets to an modem External IP and getting a return info

If I would send packets to my own IP, I would use HTTP packets, and get a return because I could connect to my IP through an HTTP (port 80) with socket.SOCK_STREAM. But if I were to connect to a ...
0
votes
1answer
6 views

Oct2PyError occurs in ipython when octavemagic is used

I want to use octave functionality from ipython. Therefore,I installed oct2py module by pip command. (To be precise, I'm using ipython3 and pip3 command) The installation itself was done ...
0
votes
0answers
6 views

Kivy Weather App list index out of range

main.py from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.properties import ObjectProperty, ListProperty from kivy.network.urlrequest import UrlRequest import json from ...
0
votes
0answers
8 views

Is the use of Parent and Child classes in SQLAlchemy documentation a red herring?

Immediately upon reading about relationship configuration in the SQLAlchemy docs, it's easy to wonder why Child and Parent classes were chosen for the examples. This usually implies subclassing, but ...
0
votes
2answers
11 views

SyntaxError: invalid syntax on commit

import sqlite3 import numpy conn = sqlite3.connect('lotto.db') cur = conn.cursor() def fun(a,b,c,d,e,f): list = [a, b, c ,d, e, f] print(list) return numpy.mean(list) numbers = ...
2
votes
1answer
15 views

Query about np.loadtext() function

I've been trying to parse through a CSV File using the NumPy Module as shown below, where I've had to hard-code dtype, which can be seen below too. def FileR(self,FileName): data = ...
0
votes
1answer
32 views

python 3.x - text based adventure game, save game function

I am making a text based adventure game. I am about half way done and before I get much farther with the story line I want to implement a save game function. I've been trying to figure it out all ...
1
vote
1answer
22 views

Python multithreading + multiprocessing BrokenPipeError (subprocess not exiting?)

I am getting BrokenPipeError when threads which employ multiprocessing.JoinableQueue spawn processes. It seems that happens after the program finished working and tries to exit, because it does ...
0
votes
0answers
17 views

Python objects.filter multiple tables

I'm trying to pull out information about a specific instructor from the objects I get back and relate them to each other? Say I have the following tables: Instructor: id name summary ...
0
votes
2answers
50 views

Python: splitting a file into two parts

I currently have a script that breaks off a file into multiple output files of 2 lines each. example, original file: AAA BBB CCC DDD EEE with the output files being: output1.txt and ...
0
votes
1answer
9 views

Generate random string from wxListBox in Pythong

My code below allows the user to enter a customer name (string) into a wxTextCtrl field and then click a button to add the customer's name to a wxListBox. if not self.addCustText.IsEmpty(): ...