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
5 views
python pexpect clearing or flushing the line
I am trying to clear any characters on the line after recovering from an unknown state, as in some cases they contain prompts and other keywords that I use in future expect method calls. I have tried ...
0
votes
0answers
4 views
Permission denied after using PyInstaller to create Python executable
I've created a little web server using the Bottle framework to serve up one webpage. This is done by my python script "hello.py". From the webpage generated by "hello.py", I'm able to edit the ...
0
votes
3answers
18 views
Unicode to string in python
If I define the variable
x = 'Ááa Éée'
then the output of
print x
is
Ááa Éée
But I have an unicode variable, for example
x = u'Ááa Éée'
and I need the same output that before. To do this I ...
1
vote
0answers
14 views
Efficient way of making a list of pairs from an array in Numpy
I have a numpy array x (with (n,4) shape) of integers like:
[[0 1 2 3],
[1 2 7 9],
[2 1 5 2],
...]
I want to transform the array into an array of pairs:
[0,1]
[0,2]
[0,3]
[1,2]
...
so first ...
0
votes
0answers
10 views
kernel density in python
I want to calculate kernel density surfaces for each of 9 different fields within a Food Outlet Points shapefile (foodpts.shp) using 4 different search radii (805meters, 1609 meters, 4828meters, and ...
0
votes
0answers
14 views
Send an image from Google Glass to a HTTP server [duplicate]
We are working on a google glass app project and one of the goals is to make the glass send a picture it takes using the camera to a python server that we already have running. So far it looks like ...
0
votes
1answer
10 views
Running Python - 500 Internal Service Error
I have the following code (test.cgi):
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print
print "Hello ...
1
vote
1answer
9 views
Open text file and search on OS X
I would like to open a text file and then search immediately for a certain string and highlight it.
I use:
command ="open "+'"'+ file +'"'
os.system(command)
But I want something like:
command ...
0
votes
0answers
9 views
Plotting pandas time and category
I really can't get out of this. Here is my table:
where grade can be A,B,C
doc_id, grade, timestamp
1, A, 27/01/15
2, A, 27/01/15
3, B, 27/01/15
...
My aim is to show a graph with three lines, ...
0
votes
0answers
20 views
Unable to find and execute python script in shell [duplicate]
I'm attempting to test a python script I wrote but when I attempt to run it with this command:
./simpletax.py
I get the following message:
: No such file or directory
I believe it is a ...
0
votes
0answers
16 views
Trying to “break” the Collatz Conjecture and generate 3n-1 sequences (there will be cycles)
This is what I have done so far:
def collatz_sequence(x):
seq = [x]
if x < 1:
return []
y = x*2
while x != 1 and x != y:
if x % 2 == 0:
...
1
vote
1answer
27 views
Python - isinstance returns false
I'm having an issue with isinstance().
I'm using Python 2.7.8, and running scripts from the shell.
The array element I'm testing for contains a number, but this function returns false; using ...
0
votes
0answers
13 views
PHP output in browser different than in command line
I am running a php script that uses the exec function to run a script in a different directory. I have Apache set up so that I can access this script from the browser through the IP address:
$a = ...
0
votes
1answer
11 views
Monte Carlo Method. Triple Integral. Python. unsupported operand parent(s) for '+'
I try to approximate triple integral ∫∫∫xyzdV , where S=[0,1]×[0,1]×[0,1] using Monte Carlo method.
I have this code:
from numpy import *
import time
from scipy.integrate import tplquad
...
0
votes
0answers
7 views
ReflectedProperty is being returned in IronPython
So I am making a call to ControlledApplication.VersionName method using Iron Python 2.7 and instead of getting a version name in form of a string back I am getting a ...
0
votes
0answers
4 views
How to cancel a download made with POST and urllib2.open running inside a QThreadPool?
I'm trying to cancel a started download that is running in a QThreadPool. But every time a tried something I make the QGIS (my main application) to crash. This is the code I'm using in my QRunnable.
...
1
vote
1answer
13 views
ValueError: need more than 0 values to unpack(python lists)
I'm getting an error while I'm writing my code
tmp = c.pop(0) # taking out the first element from the list as the starting point
complete = tmp[0][-1]
print(complete)
while c != []:
complete += ...
0
votes
1answer
15 views
Assembling Python module on fly, dynamic import
I'm trying to get myself familiar with importlib hooks. I want to implement an ability to directly import non-pythonic files written in other language, and maintain source maps, so raising ...
0
votes
1answer
24 views
Python .json() moving first item to end?
Response data:
{
"total": 488,
"rankings": [
{
"name": "ABC",
"class": 8,
"spec": 1,
"total": 48801.38671875,
"duration": 270381,
"startTime": ...
0
votes
2answers
22 views
Error “'type' object has no attribute '__getitem__'” when iterating over list[“a”,“b”,“c”]
I'm new to Python and I keep getting this error:
TypeError: 'type' object has no attribute '__getitem__'
when I try to run this code:
import arcpy,os
from arcpy import env
from arcpy.sa import*
...
0
votes
0answers
6 views
Meanings of parameters when generating pre-signed URL using boto S3
I am using boto to create pre-signed URLs to permission users to upload directly to S3.
I know that we can use generate_url method (available both for Connection and Bucket classes) for this, but ...
0
votes
2answers
24 views
ValueError: need more than one value to unpack when parsing /etc/passwd
I created a simple app where it prints a readable information of the output of /etc/passwd, but I get an error message after parsing most entries in the file:
Traceback (most recent call last):
...
0
votes
0answers
18 views
How do I mock and unit test the following code?
import module
from x import X
class A:
def method():
return module.something(arg=X())
I created the following to unit test:
with patch('filename.module.something') as something_mock:
...
2
votes
1answer
20 views
What's the proper way to break nested function/constructor calls in Python?
According to PEP 8:
When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly ...
0
votes
1answer
17 views
How to Make a Simpler Python Fibonacci Sequence Prompt? [duplicate]
So just for fun I created a small little python script that prompts the user for a number and then prints out that many digits of the Fibonacci sequence. The script that I came up with works, but I ...
0
votes
0answers
10 views
how to create a folder from path name in current directory [duplicate]
I am using python and I want to get folder name from a given path and create that folder in the current directory.
For Example:
if path = C:\Users\John\Desktop\use\Application.pdf
then a folder named ...
-2
votes
1answer
32 views
Returning a sliced list
I am stuck on this question:
Write a function lossy_merge(list_1, list_2) that returns a new list
containing all the elements of list_1 except the last followed by all
the elements of list_2 ...
0
votes
0answers
2 views
Problems installing and running igraph for Python 2.7.9 Anaconda 2.2.0 Mac osx 10.10.2
I'm struggling to get igraph successfully installed and running on my Mac. I'm using Python 2.7.9, Anaconda 2.2.0 on Mac OSX 10.10.2
It appears that I have installed igraph successfully and when I ...
0
votes
1answer
26 views
Python while loop, pause while not, continue again when true?
Here is a bit of python I'm borrowing. Its on a raspberry pi monitoring three pins with reed switches on doors. If the door opens it says "door open".
The problem is that it keeps repeating open. I ...
0
votes
1answer
15 views
Python 3.3: Obtaining multiple lines of input, then calculating them separately
I am very new to Python and I am trying to create a program that will calculate the distance between two X and Y coordinates given by the user, separated by a space. I was able to do it for a single ...
0
votes
1answer
11 views
How to read a .csv file specific items that hold this contrait?
I have a pretty large file like this:
SynsetTerms,PosScore,NegScore
a prueba de,0.208333333333,0.0833333333333
a reacción,0,0.0625
a salvo,0.1875,0.0625
a través de,0.1875,0.0
a ultranza,0.125,0.0
...
-1
votes
0answers
9 views
Suggestions for Python UI and project
I would like to ask the community, for suggestions regarding modeling of data in GUI form with Python.
An example I would like to use is that for work, an example I would like to use is that I want ...
0
votes
0answers
3 views
Using Raven, how to save exception to file and sent later to Sentry?
In my Python app, I have been working with Raven+Sentry to catch exception and sent it to sentry at the time of the exception occur, code below:
if __name__ == '__main__':
from raven import Client
...
-1
votes
1answer
25 views
Can the Python interpreter and Python app source code be embedded into a compiled program?
I want to put the Python interpreter and all the source files of a fairly large Python application with multiple .py files into an executable Linux file.
Thus when running the application, the Python ...
0
votes
0answers
14 views
Unable to decode yml file … utf8' codec can't decode byte #xa0: invalid start byte
Im trying to read yaml file and it convert into dictionary file. Im seeing an issue while loading the file into dict variable.
I tried to search for similar issues. One of the replies in ...
0
votes
2answers
24 views
execute c program with an input using python
I am trying to execute a c program with an input string argument on a python script. But I am getting a type error.
p -> is a string variable
vuln -> is a c binary that I can execute fine using the ...
0
votes
2answers
18 views
How do you make a Python script executable on Mac?
My google searching has failed me. I'd like to know how to make an executable Python file on OS X.
0
votes
0answers
11 views
error converting qt file with pyqt
I did a search and found what I thought would be the answer to my question but it seems like I've already done the recommended 64 bit PyQt version initially
So I downloaded Qt from ...
0
votes
1answer
17 views
Scrapy inside javascript
I'm trying to scrape data from http://apps.cu-citizenaccess.org/
It looks like they are trying to extract data from JSON, so I used code similar to that recommended in Scrapy, scrapping data inside a ...
-4
votes
0answers
23 views
Operating on dictionaries in python [on hold]
I have a dictionary wherein the keys are strings and their corresponding values are lists. Lets say there are 5 keys and 5 corresponding lists. I need to select the 4 minimum values out of the 5 ...
0
votes
1answer
6 views
Getting Redis to run in Python on Cloud9
I have seen examples getting Redis to run on Python on Cloud9, but I keep hitting a fundamental error.
Just running:
import os
import redis
#r = redis.Redis()
Yields module and socket errors as ...
0
votes
1answer
19 views
Python-need help on how to make a crpyter shifting+1 on alphabet
Im making a menu and everything in it is perfect but what i need now is to make a crypter in a sense by when the end user inputs a sentence, all the letters he/she inputs will shift up the alphabet by ...
0
votes
1answer
16 views
Extending django admin custom view for user
I have a database of businesses around my city, and I want to allow individual businesses to submit data to the database, but under their respective business names. my business table looks like this:
...
0
votes
1answer
10 views
print the value of the checkbox tkinter
I am trying to write a program so every time the checkbox is clicked it prints "hello world to the output file" I've got it printing the stuff in the entry widgets so far but how do I get the state of ...
-2
votes
0answers
33 views
How to replace certain part of a string?
This is the first time I am asking a question so sorry if I do this wrong. I am trying to make a hangman GUI program but I can't see how to replace the letter when it is guessed.
Here is my code, I ...
0
votes
0answers
11 views
How can I remove a character from a match object?
A bit of data contains an an extra whitespace that I would like to get rid of, but unfortunately at that point it is a match object and so how can I delete it?
for string in sl:
for keyword in ...
-5
votes
3answers
35 views
Count number of occurrences in a list
I have 2 lists like this:
prefix = ['b', 'bo', 'br']
word = ['bring', 'boring', 'bold', 'bells']
How do I count how many times is each prefixes within the list word?
It should return
[4, 2, 1]
...
1
vote
1answer
25 views
Reading continuous data from a named pipe
I have been trying to read continuous data from a named pipe. But for some reason if I don't put a delay, the receiver will just stop reading and only a blank screen is shown after a few samples.
I ...
0
votes
0answers
19 views
Why do I get “ImportError: No module named pdb”
I am running a python virtualenv in OS X.
I have installed pdb using pip in the virtualenv.
But when I run pdb, I get the following error.
Traceback (most recent call last):
File ...
0
votes
1answer
14 views
Is it a good a practice to patch all calls within the method when creating a unit test?
Supposedly, I have the following class. Just using this as an example.
class Connect:
def __init__(ip_address):
self.ip_address = ip_address
def get_ip_address():
return ...