Tagged Questions
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.
0
votes
0answers
9 views
PsuedoCode Algorithm Simple MUD poker
Using the following code, can anyone dream up of an algorithm to see who has the better hand in my little game?
#Sorting Algorithm PsuedoCode generously offered by
from random import *
coins=100
...
0
votes
0answers
4 views
error of compiling GMP in 32 bit cygwin on win7
I would like to install PyGLPK on win 7.
http://tfinley.net/software/pyglpk/readme.html
But, I need to install glpk and GMP.
I downloaded and installed glpk (4.34) from
...
0
votes
0answers
4 views
gobject.timeout_add not working in nose tests
I've added a module to mopidy core that uses gobject.timeout_add() for a repeating function. It works fine when running normally, however when running tests it appears that the handler function never ...
0
votes
0answers
18 views
Find minimum, maximum, and average value of a text file
i've been desperately trying to find an answer to this for a class, and I cannot seem to find one. I need to find the minimum, maximum, and average value from given values received from a text file. ...
2
votes
2answers
34 views
How do i make a list a list of list? [duplicate]
How I get the items from the "list" to look like the "new_list" which has the same amount of items in each list
list = [1,0,1,1,1,0,1,0, new_list = [[1,0,1,1,1,0,1,0],
...
0
votes
0answers
10 views
Iteration of body content extract p tags in list. How to join p tags in python
I have created a code that will open an excel sheet with a list of urls. In these URLS I extract the url, title tag and body content. As the ptags in the body content has the google analytics tag that ...
0
votes
0answers
8 views
lxml - how to remove element but not it's content?
Let's assume I have following code:
<div id="first">
<div id="second">
<a></a>
<ul>...</ul>
</div>
</div>
Here's my code:
div_parents = ...
-1
votes
1answer
23 views
Python hyphenated module “No module named foo-bar”
I'm trying to import a hyphenated module, I know Python isn't supposed to have dashes in module names, but this still should work. I have an __init__.py file in foo-bar with read permissions allowed ...
1
vote
1answer
28 views
Number of unique items in a list in Python [duplicate]
If I have a set of items in a list say:
MyList = ["a", "b", "c", "c", "b"]
And I want to get the count of the total number of unique items (in this case 3)
I figure it needs to be some variant on ...
0
votes
2answers
31 views
for loop in python skips [duplicate]
I have a for loop as below in python 3.4
def checkCustometers(self):
for customer in self.customers_waiting:
if customer.Source == self.location: #if the customer wants to get on at this ...
0
votes
3answers
13 views
How can I get a Python program to kill itself using a command run through the module sys?
I want to see how a Python program could kill itself by issuing a command using the module sys. How could I get it to kill itself using a command of the following form?:
os.system(killCommand)
...
0
votes
1answer
13 views
Pandas dataframe incorrectly including data type in output
In iPy Notebook (see below) I am doing a bit of data massage to pull wanted data from a CSV file. I am doing this by creating new pandas dataframes, and I'm having an issue that I have never seen ...
-2
votes
5answers
28 views
Most efficient way to convert string-time to time
I have to run about a million operations to do:
"Runtime": "01:12:00" --> datetime.time(1,12)
What would be the most performant way to do this? Right now I'm just doing a split on the ...
0
votes
2answers
19 views
Writing multiple lists to the same .dat file simultaniously in Python 2.7?
This is my translation from pseudocode. The code suggests that multiple lists or arrays can be written to a .dat file. I'm trying to stay as true to the pseudocode format as I can so that I don't get ...
0
votes
0answers
2 views
Python Google App Engine. Upload html file with images in datastore
I am developing a application that will take html and its images from user and save it in data-store. So far this part is done. I am confuse how to serve these images as resources of html page when ...
0
votes
0answers
8 views
SqlAlchemy commit slow
I have some items in table User (about 12000) and i want to do smth like this:
items = db.session.query(User).all()
for item in items:
item.active = 0
... many logic ...
...
0
votes
0answers
5 views
Linking sqlite3 with Tkinter
As a part of an inventory system I am making, I want Tkinter to collect the values of the data I wish to insert into a database through the user typing in entry boxes and clicking an 'Add Stock' ...
0
votes
0answers
12 views
Using “with” inside a thread in python + picamera + opencv
I am using the raspberry pi with the picamera and opencv python modules trying to do some rapid capture and processing.
Currently I am using the recipe in ...
0
votes
0answers
8 views
tkinter python script does not work windows
I am studying Python. Doing exercises from a book.
I wrote a simple example script using Tkinter module.
I use Windows XP Pro.
This is it: ( literally from the book )
from Tkinter import *
root = ...
-1
votes
3answers
17 views
Store a list (ArrayList?) of integers in python
I'm a java guy and doing a little project with python, I need to have a list that stores integers that is, by default empty (null) but I need to be able to eventually add multiple integers to it (one ...
0
votes
1answer
13 views
Django primary key in tests
Now I writing tests for my first django application and have the problem with primary keys, looks like in tests pk isn't auto incrementing.
I set all data for tests, like this:
Work(title="Test ...
1
vote
0answers
11 views
chaining coroutines in asyncio
I'm having trouble wrapping my head around how coroutines are chained together. In a slightly less trivial example than hello world or factorials, I'd like to have a loop which continually watches ...
-2
votes
1answer
13 views
How do I auto-update date and time in django?
This is my Django project.
How do I auto-update date and time? My code is allowing user to update it manually?
class Join(models.Model):
email = models.EmailField()
...
0
votes
0answers
8 views
Python mock error: stop called on unstarted patcher
I have a function let's say def temp.i am mocking it the following way:
msg = "Mocked!!!!!!!"
...
0
votes
1answer
5 views
How do you permanently save a 3rd party module in Python 2.7.9?
I am new to programming and have been following some tutorials for learning the basics of Python 2.7.9 syntax. I am also using Ubuntu 14.04.2 LTS.
The tutorial is discussing how to create, save, ...
1
vote
0answers
6 views
How do I get a developer id for google custom search api?
I have a GAE app , so I selected :
Public Access API
Browser (or should I have selected server)
*.mysite.appspot.com/*,
*.googleapis.com/*,
http://localhost:8080/*
I make a api call as :
from ...
0
votes
0answers
5 views
The value of databases in wxpython
I have a wxpython script that opens 10's, or 100's or 1000's or more items from a users system. I store this information in memory and use what is needed by my script. Later if the user decides to ...
0
votes
0answers
5 views
Raspberry Webiopi GPIO one time Email Trigger
I have been trying to make this code I have to only email once after the Door pin has been tripped. I am newish to python and have been reading the posts with similar question and trying what I have ...
0
votes
0answers
17 views
Speed up numpy indexing resulting from unravel_index?
I have some code that uses the result of an unravel_index command to access elements of some matrices. I did some line-profiling and just accessing these elements and storing them in new arrays is ...
0
votes
2answers
20 views
Taking the data from one file, altering it, and then rewriting it to a new file using python
So I'm somewhat new to python and I am trying to write a program that takes the numerical grades in one file and changes them to letter grades. I am also trying to do this without using "with" or ...
0
votes
1answer
5 views
Accessing related record data in SQLalchemy
I am creating database of ethernet switches that contains its name and IP address. Also I store list of active ports in that switch (those that are in UP state for the moment). In case of switch I use ...
0
votes
0answers
10 views
Efficient Linux Container monitoring
I want to be able to monitor my Linux Containers. Stuff like, memory usage, CPU usage, network usage etc ...
I was thinking of using Python to write scripts that would run once every minute and would ...
0
votes
1answer
7 views
uWSGI - Serving multiple python files with only uWSGI behind nginx
Pardon me, this question is going to be too basic but i have not been able to get the solution anywhere. So, here goes ..
I have set up an instance nginx on Ubuntu 14.04 and an instance of uWSGI on ...
0
votes
1answer
7 views
jinja2: convert string to dict object?
I have a json string stored in the database and when this is pulled out and shown on the template it is a string. I want to convert this into a dict object so I can access the contents directly.
...
-2
votes
1answer
28 views
How to add space between strings in Python List without the underscore
I am learning Python and was playing around with lists. This is my code:
current_list = "Red_shirt Blue_shirt Blue_Jeans Black_Jeans Black_Jacket"
print("Is that all you got?")
thislist = ...
1
vote
1answer
18 views
Drawing a indian flag chakra in python turtlee
I am drawing the Indian flag using turtle and python. I have got the rectangles and colours down so far, but am struggling to make the chakra in the middle.
It has 24 spokes, and is surrounded by a ...
-1
votes
3answers
21 views
Python - An “if” statement if an exception occurs
I want an if statement to occur once an exception goes off. What is the function for that, or is it even possible?
This is what I'm trying to get
try:
save_this_number_file(s)
except:
...
0
votes
0answers
13 views
Pandas with Fixed Effects
I'm using Pandas on Python 2.7. I have data with the following columns:
State, Year, UnempRate, Wage
I'm teaching a course on how to use Python for research. As the culmination of our project, I ...
-1
votes
0answers
7 views
convert csv to kml and upload it to google maps
How can i convert my csv to kml and upload it to google maps to display the output of my traceroute using python, used by my code below
import socket
import sys
import csv
import getopt
import os
...
-2
votes
1answer
37 views
Using regular expression to pull out all data between two html functions in Python
I'm looking to create a regular expression to pull out html from a file. I'd specifically like it to pull out all the data between two functions inclusive.
For example, below is my attempt at ...
1
vote
3answers
34 views
Import module scope and variables
My question is about python 2.7 namespaces and module imports. My problem is understanding why this works:
If I have a module file memory.py:
memory={}
def insert_into(a,b):
memory[a]=b
And then ...
0
votes
1answer
17 views
How do i select random quiz 12 times and display my quiz result scores in different manners
After Hours of research i have had a very hard time to code such criteria :
#select random question 12 times
#Display highest to lowest score in (alphabetical order)
#Display highest to lowest ...
-1
votes
2answers
18 views
using timeit functions with len functions in python
I'm trying to calculate the program's runtime . How do I use timeit functions with len functions in this code.
code:
import timeit
def shellSort(alist):
sublistcount = len(alist)//2
while ...
0
votes
1answer
4 views
How to Reuse Database Connection under Python CGI?
I'm new to python and mysql-python module. Is there any way to reuse db connection so that we may not connect() and close() every time a request comes.
More generally, how can I keep 'status' on ...
0
votes
5answers
23 views
Python code for finding number of vowels in the parameter
I am a python newbie, and am struggling for what I thought was a simple code. My instructions are, Write a function that takes one string parameter word and will return the number of vowels in the ...
0
votes
0answers
17 views
Models not showing in admin page (Django on heroku)
My models.py contains 3 models, but they do not show up in my admin page. I tried registering my models in admin.py, and added admin.autodiscover(), but none of these things seem to make a difference.
...
0
votes
1answer
8 views
object takes no parameters
I'm getting the above answer when I run the following code:
class Song(object):
def _init_(self,lyrics):
self.lyrics=lyrics
def sing_song(self):
for line in self.lyrics:
...
-1
votes
0answers
20 views
Flask Request Signal - request_tearing_down workflow?
Please comment if the attached workflow is a correct description of how Flak handles an request and when and how signals are triggered
I'm particularly interested in the request_tearing_down signal. ...
0
votes
0answers
15 views
How to install pylab/matplotlib in OSx?
I have following error while importing pylab. I already installed matplotlib version - 1.4.1 and OS - Yosemite 10.10.2
>>> import pylab
Traceback (most recent call last):
File ...
0
votes
2answers
22 views
Networkx Statistical Inference
I have a directed weighted graph which I created successfully using networkx.
I'm trying to generate some statistical inferences on this network, but I'm having trouble. Here they are:
(i) The ...