Tagged Questions
Python is a dynamic and strongly typed programming language designed to emphasize usability. Two similar but mostly incompatible versions of Python are in widespread use (2 and 3). If you have a version-specific Python question consider using the [python-2.7] or [python-3.x] tags in addition to the [...
0
votes
0answers
6 views
I have two tables in my HTML page and from app.route() function I am passing two objects that I got from cursor.fetchall() call.
I have two tables in my HTML page and from app.route() function I am passing two objects that I got from cursor.fetchall() call. This is how my app.route() looks:
_name = request.form['s1']
...
0
votes
0answers
4 views
Python - Read TXT file and comparing its contents with multiple CSV files
This is how the python script is supposed to work:-
It will check the content of "words.txt" in all csv files within a folder and extract the result from beginning to where there is exact match found ...
0
votes
0answers
10 views
How to pass string variable into search function in python?
Hello Everyone and thank you in advance for your help,
I'm new to the world of Python and am having issues passing a string variable into a search function. I have done my best to google my way ...
0
votes
0answers
2 views
customizing qdial in pyqt with stylesheets
I have a QDial that I'm using as a speedometer. I want to customize it so I can use this image as the background:
And create my own (or use an image of a needle)
I'm aware that this question exists ...
0
votes
0answers
16 views
occurrence of words with same length python
My function takes a string as input that is the name of a file and should return a dictionary. The dictionary will have key/value pairs where keys are integers that correspond to word lengths and the ...
0
votes
0answers
3 views
OpenCV snap corner to grid
I am trying to take a pixelated image and make it look more like a cad drawing / blueprint.
Here is the source image:
I am using python and openCV 2. So far I am able to find some corners using ...
0
votes
1answer
12 views
How to prevent Requests from decompress gzip automatically in Python?
I used Requests module in Python, and sent a request and got a response.
The response seems to be gzip, given that r.headers has the following information:
{'Date': 'Tue, 06 Dec 2016 17:35:44 GMT', '...
0
votes
0answers
6 views
How to return a value from a coroutine that was run with Tornado's IOLoop?
Let's say I have this asynchronous function (Python 3.5)
async def func():
return '42'
I have a Tornado I/O loop and I'm looking for a way to execute it.
import tornado.ioloop
ioloop = ...
0
votes
0answers
2 views
PyQt4 GUI crashes whenever I run my socket method for open connections
I'm currently working on my instant messaging program for my A2 coursework, I'm using PyQt4 as a GUI framework and python sockets as a network interface. Whenever the method that allows the program to ...
1
vote
0answers
18 views
Python ctypes: Passing an array of strings
I have an array of strings in Python 2.7, which I would like to pass to a C function via ctypes:
unsigned int SetParams(unsigned int count, const char **params)
So I can define the parameters in ...
0
votes
0answers
4 views
ArcGIS Pythong Create TIN
I'm trying to use toe Create TIN tool
import arcpy
... from arcpy import env
... arcpy.CheckOutExtension("3D")
... env.workspace = "C:\Users\pvictor\Desktop\Test TIN Python"
... arcpy....
-1
votes
0answers
18 views
Read multiply .txt in one folder
enter image description here
The name of the files are like this.
enter image description here
This is an example of the content of the txt.
This is my code, and it prints nothing.
import glob
...
-1
votes
0answers
16 views
Python list count method not returning unique elements [duplicate]
i'm trying to find unique elements in a list in Python.
I imagined putting the condition:
if data.count(ele) == 1
it would encounter all unique elements.
He is the code:
data = [1,2,3,4,5,6,7]
def ...
0
votes
0answers
6 views
Python - PyCharm - DataFrame Variable Prints Out Correctly But Cannot Be Viewed With The Debugger
I have recently started using PyCharm and the Pandas library and am running into an issue when trying to view a dataframe from the debugger tool in PyCharm.
The dataframe in question (df) prints out ...
0
votes
0answers
8 views
Python3 and tkinter GUI button to open a file
I have created a program that uses PIL to examine an image and return the size, amount of colors, dpi, and so on, but now I want to put my code into a GUI system to help the user.
I have used ...
-1
votes
1answer
22 views
Python 3.5.1 : NameError: name 'json' is not defined
#!/usr/bin/env python
# encoding: utf-8
import tweepy #https://github.com/tweepy/tweepy
import json as simplejson
#write tweet objects to JSON
file = open('tweet.json', 'wb')
print ("...
0
votes
1answer
14 views
Returning a python generator for timing analysis
I wrote a snippet that uses generators to return the elapsed time since the last time it has been called.
def time_gen(start_time):
start = start_time
while True:
elapsed =...
0
votes
0answers
4 views
Add PyQt toolbar to a MEL-defined window
I've been asked to add a PyQt toolbar to an existing custom Maya mel tool. The tool contains buttons to select rig controls and the toolbar's buttons work on whatever is selected in the scene.
The ...
0
votes
0answers
3 views
Troubleshooting Authentication Issue in Google+ Domains API
I am trying to set up posting for some Google+ accounts via the Google+ Domains API using a Python script. I am following the `Hi all, I'm trying to work with the Google+ Domains API to set up posting ...
0
votes
0answers
5 views
Load and view Meshlab textured surface in Mayavi
How can I load and view a Meshlab-textured surface in Mayavi?
Here's what I've tried:
.ply
I'm able to view the mesh using plyfile, but I am not able to view the texture (that module doesn't ...
0
votes
0answers
9 views
How can I Install Pygame for Python 3.4 on Mac?
Are there any DMG files?
If not, how else can I download and install it?
Thank you!
-1
votes
0answers
15 views
Convert SAS code to Pandas equivalent
I have SAS code i need to convert into python pandas.
data df1;
set df;
by id;
retain flag_final;
if first.id then do;
if flag eq 0 then flag_final=flag;
...
-4
votes
1answer
14 views
Python Files(Write/Read)
So my proffessor has assinged us to write a file in Python that contains this..
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
...
0
votes
0answers
7 views
deleting Flask memory cache
I have a web app that starts like this:
#It starts here
@app.route('/game')
def game():
Inside game, it dynamically builds an image with PIL and saves it to /static/testing_image.png
It then ...
0
votes
0answers
8 views
How to make PyCharm correctly remember recently opened files?
I'm having a problem in PyCharm where I open a .py file and do some work, then close PyCharm. Then when I open PyCharm again I see that it says one of the recently opened files has the same name as ...
2
votes
2answers
21 views
How to use Python `secret` module to generate random integer?
In Python 3.6, new module, secrets, was added.
What is the most efficient way to generate random integer in range [n, m) using this module?
I tried choice(range(n, m)), but I doubt it is the best ...
1
vote
1answer
9 views
attribute override concept in multiple inheritance (Django-Mixin)
Please refer to following code:
from django.views.generic.edit import DeleteView
from .models import Course
class OwnerMixin(object):
def get_queryset(self):
qs = super(OwnerMixin, self)....
-2
votes
0answers
15 views
Python decorator function incorrect *args value
Here is my isNone decorator and function
import functools
def isNone(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
print(args) # >> Encounter error
return ...
0
votes
1answer
22 views
Unpacking a tuple with dictionaries in Python
I have a tuple with multiple dictionaries and I wish to unpack them for further use.
Let's say I have this:
tuple_to_add = {'name': 'custom1', 'value': 'first value'},{'name': 'custom2', 'value': '...
-1
votes
0answers
16 views
Why google search result in phantomjs is different from Chrome?
I'm trying to scrape google search results using selenium and I want the browser to run in background so I'm using phantonjs.
Search result on normal browser chrome/firefox can be seen with the link
...
0
votes
1answer
16 views
How to run manage.py inside venv?
I have been given an existing project to work on and I am really struggling to get the environment set up.
The project folder firstly contains manage.py server, which I use as an entry point to run ...
2
votes
0answers
23 views
How to ignore Python warnings for complex numbers
I have a list that I need to include both real values and complex values. However, when I don't initialize the array using numpy.zeros(dtype=complex), I get the following error:
n[2] = 3.7095 + 0....
0
votes
0answers
6 views
Python pyaudio recording big wav file
I am trying to record a long microphone session with pyaudio. However, I get a Memory error after some time. I managed to split it using threading, and record 3 minutes and then process it to a file, ...
6
votes
4answers
73 views
Python open() vs. .close()
Regarding syntax in Python
Why do we use open("file") to open but not "file".close() to close it?
Why isn't it "file".open() or inversely close("file")?
0
votes
0answers
11 views
Issue on custom loss function with Keras with TensorFlow backend
I'm trying to define a loss function of a three-class classification problem as the following:
def func_loss(y_true, y_pred):
return -K.mean(K.prod(K.cast(K.argmax(y_pred, axis=1), K.floatx()) - ...
0
votes
0answers
17 views
Use Python to iterate through a list of date range and append to a set of data in csv
Need help with appending a date from a list (range of dates) to a set of data in csv.
I am able to create a range of dates. Then use csv reader to go through csv. But I am stuck on how to append a ...
2
votes
2answers
19 views
Performant filling of NAs with grouping
I am looking for a solution regarding a problem with a very big dataframe in pandas.
Let's say I have a very big dataframe that has NAs in it. I want to fill the NAs by the mean of the rows with the ...
2
votes
1answer
28 views
Inspect lambda code from Python interpreter
this simple python program that is extracted from more complex codebase:
#insp.py
import inspect
L = lambda x: x+1
print("L(10)=" + str(L(10)))
code = inspect.getsource(L)
print(code)
works if i run ...
-1
votes
2answers
32 views
How to recreate text from a list?
So far in my code I have asked for user input. The user input should be several sentences that are punctuated and should include some capitalised letters. I have converted those sentences into a list ...
0
votes
0answers
6 views
How can I create rules for a variable number of facts in PYKE
I'm trying to create to make a knowledge based system to diagnose diseases.
I'm using PYKE for this. (http://pyke.sourceforge.net/)
I have a facts base like the example given below
symptom_of(...
5
votes
1answer
32 views
How can we pass bytes as the key of keyword arguments to functions?
Let us have the following example:
def fun(**args):
print(str(args))
dic = {'name': 'Pulkit'}
fun(**dic)
This code works fine and I have the following output:
{'name': 'Pulkit'}
Now lets pass ...
2
votes
0answers
20 views
Why do I get a STATUS_ACCESS_VIOLATION when I run this Python script on Windows but not on Mac OS?
I'm currently working on some geological analysis and came across this error when loading a .tif file of size 65MB, so relatively small. On my Macbook Air, which has 4GB of RAM, I can run the ...
0
votes
1answer
20 views
Speeding up code to download files from a SFTP
I wanted to check if there was a faster way to download data from an SFTP which doesn't exist in a folder on a physical computer. The issue is that these files are 5 minute interval snapshots and the ...
2
votes
1answer
13 views
generic.edit.CreateView Assign Default Values and Insert Into Database
I have the following class-based view that uses my model to generate a "Create" screen:
class ProjectCreateView(generic.edit.CreateView):
model = Project
fields = ['project_title','...
1
vote
0answers
8 views
How to force MagicMock to copy function signature?
I want to mock few not important functions for the test subject (other function) - time.sleep(), etc.
I can replace them with simple mock, and this will work. But I want it to report errors if they ...
-2
votes
2answers
16 views
Convert image of game board to 2D array
I have an image that contains tiles of different colors. A section of the board looks like this:
I'm trying to convert this to a 2d array with each element representing a distinct tile such as this:
...
0
votes
1answer
17 views
Drop rows where column contains a certain value conditional on the value of the columns on the row above
I have the following dataframe
df = pd.DataFrame({'State': {0: "case_created", 1: "case_reopened", 2:"email_sent", 3: "case_reopened", 4: "email_sent", 5: "case_reopened", 6 : "email_sent", 7: "...
1
vote
1answer
17 views
Pandas TimeGrouper by column
I have a csv file with dates as columns headers and binary a matrix of 1, 0 or np.nan.
I'd like to take the mean of each index, grouped by month. I am running into a problem because my columns are ...
0
votes
0answers
10 views
paramiko client make a tunnel
i'm learning Python net programming . Now i want to make a tunnel with paramiko or sshtunnel .can i use it like a putty or Bitvise . Because i only want to connect it ,port forward and surf internet ...
0
votes
0answers
14 views
python 3d plot in spherical coordinates
I want to create a 3d plot of function that is represented in spherical coordinates with contour lines on it.
Here's how I want it to look like:
I managed to create the surface itself but I have ...