Tagged Questions
0
votes
0answers
8 views
Why is my Python for loop altering a variable declared prior to the loop?
Here is a simplified version of my function that compares three sets of numbers and finds the two sets with the highest correlation:
inputs = ['vars_one', 'vars_two', 'vars_three']
def ...
0
votes
1answer
26 views
Can i access python function inside in same function?
Can i access python function inside in same function or sub function of main function?
def main_function():
def sub_function():
main_function() # i need to call main function.can i or ...
4
votes
1answer
36 views
Debugging strategy for a bug (apparently) affected by timing
I'm fairly inexperienced with python, so I find myself at a loss as to how to approach this bug. I've inherited a python app that mainly just copies files and folders from one place to another. All ...
0
votes
1answer
20 views
Pygames Random number and corresponding picture
I want to make a uncrate/unbox simulator game. I want it so when I press the mouse button down a random number would generate and that number would correspond to a picture, then pygame would display ...
0
votes
1answer
19 views
Construct object (Rectangle) without arguments when __init__ of class requires parameters
I am working on an assignment that requires a Rectangle class that computes the area and perimeters given. We are given the main() function already and have to build around it. It seems to run up ...
0
votes
1answer
17 views
Get Function Not Working
I have this code using a .get() function to retrieve the input from a Tkinter Entry:
from Tkinter import *
def access():
access_window = Toplevel(root)
access_window.title("Access a Contact")
...
1
vote
1answer
19 views
Scraping Biography.com using urllib2
So I've scraped websites before, but this time I am stumped. I am attempting to search for a person on Biography.com and retrieve his/her biography. But whenever I search the site using urllib2 and ...
2
votes
2answers
46 views
add what was printed to a dictionary
I have two lists:
list1 = ['a', 'b', 'c', 'd']
list2 = ['A'. 'B', 'C', 'D']
I print out every time I called my function a random element of each list:
def whatever():
print 'Element of list ...
0
votes
2answers
42 views
Insert Element in list during iteration
I need to insert element during iteration of list and did in following way. But I feel it can be written in better. Here B's dictionary which contain A element Length
_leftcell = leftcell[:]
index = ...
3
votes
2answers
34 views
Python split string with space unless a \ is in front
Sorry if this post is a bit confusing to read this is my first post on this site and this is a hard question to ask, I have tried my best. I have also tried googling and i can not find anything.
I am ...
0
votes
2answers
46 views
Python: Nesting Dictionaries?
So I need to nest some dictionaries in python.
The dictionary code I have so far is this:
dict[counter] = {'title': title, 'year': year}
So, this adds to the dictionary dict a key with the value ...
0
votes
1answer
27 views
sort a python date string list
I have a list:
a = ['7-Mar-14', '10-Mar-14', '11-Mar-14', '14-Mar-14', '15-Mar-14', '17-Mar-14', '22-Mar-14', '23-Mar-14', '25-Mar-14', '1-Nov-13', '5-Nov-13', '8-Nov-13', '23-Nov-13', '24-Nov-13', ...
1
vote
1answer
23 views
how to fix the 'AnonymousUser' object has no attribute 'profile' error?
I'm writing a chat app for a hypothetical social network but when I try to open the chat page I give the following error 'AnonymousUser' object has no attribute 'profile' error .
I think there may be ...
0
votes
1answer
22 views
“Connect 4” code seems to not detect game piece
I'm working on a "Connect 4" game in python and my code doesn't seem to be detecting the existence of a game piece. I can't see why. The only thing I can think of is somewhere my code is getting the ...
-2
votes
1answer
26 views
How do I test the exceptions for my inputs in python?
i want exceptions for my python coding for user_input, pay,and for my newpayment can you help me to correct my codings pls...Pls this is my assignment...im doing ticketing system project for my ...
1
vote
2answers
26 views
Fitting Guassian curve to data in python
I'm trying to fit and plot a Gaussian curve to some given data. This is what I have so far:
from numpy import loadtxt
from scipy import *
from matplotlib import *
import matplotlib.pyplot as plt
...
0
votes
2answers
67 views
How can i speed up this python code?
So I recently coded this as a little challenge to see how quick I could do it. Now since its working an such I want to speed it up. It finds all the proper devisors of a number, the highest proper ...
1
vote
1answer
23 views
Multiple File Handles for the Same File
So this question got me thinking. I did some testing with multiple file handles for the same file, and found some odd results that I was hoping someone could explain.
>>> f1 = ...
2
votes
3answers
40 views
Python file reading after file is all read
Using python 2-7:
msg = self.infile.read(1500)
I am reading pieces of 1500Bytes from a file inside a possibly infinite while loop,
when the file is all done and I have read it all what happens? ...
1
vote
1answer
34 views
Python deque of strings
msg = 'afdssav'
MYQ = deque(msg)
MYPQ.append('asdf')
Here I am trying to create a deque of strings, however when I pop elements or try to read elements from it using Python 2.7 I get char by char ...
1
vote
1answer
29 views
TypeError: super(type, obj) when running pyprocessing script interactively
Python 2.7.3:
Create the simplest possible pyprocessing file and save it as foo.py:
from pyprocessing import *
def setup():
size(100,100)
def draw():
rect(10,10,10,10)
run()
Now in ...
1
vote
1answer
47 views
How to pass the list starting from nth element [duplicate]
Suppose I have a list [1,2,3,4,5]. Now I want to pass the elements of this list, starting from 3rd element to a method.
i.e. i want to invoke:
myfunction([3,4,5])
How can I do this in python. ...
0
votes
3answers
30 views
How to convert Zäune to Zäune in Python 2.7
I receive a text string from a third party api with garbled character encodings.
When I print that string to the command line, the string contains words like
Zäune instead of Zäune
Gartenmöbel ...
0
votes
1answer
22 views
Why is DictWriter not Writing all rows in my Dictreader instance?
I'm new to coding and by default new to Python, so please excuse my ignorance...I'm working on it.
I am trying to write some code (Python 2.7) to take specific headers from multiple CSV files and ...
0
votes
0answers
24 views
N-ary tree in python
I want to create a N-ary tree in which each node will contain a key(name) and a value.
1 root then N children with two fields = name and associate value
and again each children have N-children with 2 ...
-1
votes
2answers
23 views
Django - handle user information
Say I have a login procedure in my website and that I login successfully.
After the user credential's successful authentication, I redirect to some page like
...
0
votes
2answers
19 views
Python: Modifying external variables from within a thread
I have a thread that runs within a class.
But I want to modify a variable (say, self.variable) within that class from the thread.
Since the thread creates a copy of self.variable, but I need to ...
-2
votes
3answers
67 views
Check if list of strings exists in another string sequentially
How can I check if a list of strings exists in another string sequentially?
I have found a link which will do the same thing without sequential check.
Check if multiple string exists in another ...
0
votes
1answer
48 views
Check if a python function is builtin
How can I check whether a python function is a built-in function?
I want something like this:
def abc(x):
return x
is_builtin(abc)
should return False
import os
is_builtin(os.path.join)
...
0
votes
1answer
16 views
matplotlib multiple xticklabel for bar graph
I've a set of data as shown below, is it possible to label each bar graph with their own index? For eg, for the first group of 3 bar graphs, the xticklabel should be [data1a, data1b, data1c] for ...
0
votes
0answers
9 views
how to run a external daemon-process then kill it in anytime
I want to achieve this.
I can run the process by os.system('PROCESS_NAME &')
But I don't know how to kill it.
And I don't wanna the external process blocking in my process
run external daemon ...
1
vote
1answer
15 views
How do I specify the number of Inputs to store?
Programming newbie here.
The first line of the input contains an integer N, the number of cases.
N lines follow each line containing an array, P, with details on the case.
How do I do the IO thing ...
1
vote
1answer
34 views
sympy solve() unable to find solution
I have a fairly basic code right now that's supposed to solve the equation shown below but it's not converging to a solution. It just hangs on a pulsing "_"
from sympy import *
gamma = 1.4
M_a = 1.0
...
1
vote
1answer
15 views
How to write imported functions that can be run ad-hoc but are also called by a master script?
Say I have a master script that runs weekly via cronjob. This script imports a bunch of different functions from other Python files and runs their functions in sequence. I'd also like to be able to ...
0
votes
3answers
35 views
Think Python Chapter 10 Exercise 6 Stuck
Exercise:
Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in ascending order and False otherwise. You can assume (as a precondition) that ...
0
votes
1answer
18 views
How to create files to and open files from a sub directory in Python?
I am a beginner at Python programming (2.7; and Pygame) and I was wondering; how do you create and read files from a sub directory? In other words, I want to take sprite images, data, BGM, etc. from a ...
1
vote
0answers
15 views
AppEngineLauncher no longer shows status icons?
The latest version of appengine launcher for mac does not show status icons. What's the best way to report this? I'm on the latest Mac OS 10.9.2
0
votes
1answer
29 views
sorting list of lists Python 2.7
To remove duplicates in list of lists (named 'povijest'), I used:
povijest=[ list(set(x)) for x in povijest ]
But I makes some structure problem when printed because its not sorted.
Whats the syntax ...
0
votes
2answers
31 views
Python Queue-Like Container
I would like a container to do the following in python 2-7:
I need that container to behave like a queue: first in first out, I append to it objects and then get them in the same order "from the ...
0
votes
0answers
11 views
Emacs inlineimages display in org mode as soon as the cell is excetuted
Hi I have this cell block in org mode. When I execute by C-c C-c on aquamacs, I also want to see images without typing C-c C-x C-v . Can I combine two commands with one short cut keys ?Thanks,
...
0
votes
1answer
37 views
How do I make a C wrapper (written in 32 bit Python) work on a new machine that runs 64 bit Python?
I wrote a C wrapper using the Python C API on our development machine (which is 32 bit and runs 32 bit Python 2.7). I have since had to move the wrapper and C source code to another machine which is ...
-2
votes
2answers
47 views
Python lottery game [duplicate]
This is one of my first projects done entirely on my own without any tutorial and I am sure it is a little sloppy. Right now, I cannot figure out why my payout is always output as the payout for a ...
-6
votes
0answers
40 views
Code works fine on Python 2.7 but incompatible with python 3.2? [on hold]
I have wrote a small text encryption code in Python 2.7. I tried to run it on a 3.2 machine. But it shows error. I don't know what part of my code is incompatible with the latest version.Here is my ...
0
votes
1answer
46 views
os.system('clear') printing white space
I'm coding a console-based program. I use os.system('clear') a lot, and this causes a white space to be written in the first position in the screen (top left character in the console).
The problem ...
-1
votes
0answers
23 views
Quotation Coloring within a Text Widget Tkinter
I am wanting to find a way to color all words within quotes in a text widget a certain color. I am hoping to do this something like a programming text editor. Thanks for any help.
0
votes
1answer
17 views
Parse 2 different XML attributes together in a single python for loop
I hope my title is a bit clear, as I'm not too sure how to phrase it.
I'm working on a script to pull movie titles from my Plex server's XML output, and feed them to other functions later on. I've ...
1
vote
1answer
23 views
Python CSV edit fields with numbers greater than a specific number
I have a csv file containing a distance matrix, and the part of it looks like,
There are many fields containing number greater than 1000000, and I want to write a python script to change numbers ...
0
votes
1answer
23 views
Substituting an exception for a value during a trace
In python (2.7.5) , when settraceing a target program, is there a way, whenever an exception in the program being traced occur, to substitute the exception for a normal return value (thus, clearing up ...
1
vote
1answer
27 views
segment paragraph to sentences
I'm trying to segment a paragraph to sentences. I selected '.', '?' and '!' as the segmentation symbols. I tried:
format = r'((! )|(. )|(? ))'
delimiter = re.compile(format)
s = delimiter.split(line)
...
0
votes
1answer
28 views
Python function “source” in not visible?
I got next line in my python 2.7 script:
source (findFile("scripts", "main.py"))
And when I'm trying to start script I got next error msg:
name 'source' is not defined
What did I miss?