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
9 views
An old-style class works, new-style class broken
>>> class A_old:
... def __getattr__(self, attr):
... print 'getattr', attr
... return super(A_old, self).__getattr__(attr)
... def __trunc__(self):
... return ...
0
votes
0answers
3 views
Flask-security default builtin login/register/logout is not working
I'm relatively new to Flask and I'm having some troubles calling the built in login,register, logout function for Flask-Security.
So I followed the below example from github..
https://github.com/...
-1
votes
1answer
19 views
if statement always giving same answer python beginner
python always answers you are likely to be eligible for work even though I typed a number under 18
question1= raw_input("are you fat?")
if question1== ("yes"):
print ("sorry you are not fit for ...
0
votes
0answers
2 views
Update Query Pymongo with $inc says invalid
I am new to python and I have just started using pyMongo
This code is throwing invalid syntax error, I don't know why
dbconnection.collectionname.update({
"$and":
[{
'tid': ...
-1
votes
0answers
28 views
Checking if a web site is open within a browser [duplicate]
I'm trying to make a program that runs in the background and constantly checks if you opened, for example, facebook. And if it is indeed opened it puts in my email and password. I have the part where ...
0
votes
3answers
23 views
Adding Values In A Dictionary
I'm having a problem with my dictionary code. What i have so far is this-
def get_info():
answer = "yes"
d = {}
while answer == "yes":
a = input("Enter name: ")
b = int(...
0
votes
0answers
7 views
setuptools local install requirement
I have multiple packages in my project like so :
project
|---common
| |---setup.py
| |---...
|---identity
| |---setup.py
| |---...
|---web
|---setup.py
|---...
The web package ...
0
votes
2answers
19 views
How to create a second None in Python? Making a singleton object where the id is always the same.
WARNING: The following question is asking for information concerning poor practices and dirty code. Developer discretion is advised.
Goal: I want to create a value (called NoParam) that simulates ...
0
votes
0answers
15 views
Is it a username or a message?
I'm working with sockets in Python. However, I have a doubt about something that I think that I'm doing in the wrong way.
I have a multiuser chat. In the server side I have classes that use threads ...
0
votes
1answer
31 views
What does “for x in sys.stdin” do exactly?
Simple question here, but I can't find a definitive answer. I'm writing some python code and I'm confused as to what this line does exactly:
a = []
for x in sys.stdin:
c = x.split()
a.extend(...
0
votes
0answers
10 views
Pandas groupby: Concatenate without resizing
I have a pandas data frame with 4 columns:
Col1 Col2 Col3 Col4
A1 B1 C1 X1
A2 B2 C2 X2
A3 B3 C3 X3
A1 B1 C1 X4
A4 B4 C4 X5
A3 B3 C3 X6
I want to identify ...
-5
votes
0answers
25 views
Looping Calculator for python 3.5 [on hold]
The coding I currently have is in one of the links down below. I need to make it so the user can for example add 3+4+12. In other words more than just two numbers together. I need to get the code to ...
-2
votes
3answers
46 views
Tring to figure out this while loop
The local TV station wants to send an alert to its subscribers any time the temperature drops below 32. What type of loop is best suited to do this, and how would you construct the code for that?
...
0
votes
1answer
24 views
Why do i get this output with this recurisve function?
def test(n):
if n == 0:
return
print("This should print n times")
test(n - 1)
print("This should not print")
test(2)
Output:
This should print n times
This should print n ...
-2
votes
1answer
27 views
Results from matrix multiplication differs on Python and MATLAB
I have a problem that I cannot understand and it drives me really crazy because I can't find a solution.
I am doing some matrix multiplication on MATLAB and Python. Imagine that I have two matrixes X ...
-6
votes
0answers
33 views
Why is this unknown bug happening in my code? [on hold]
I've made a pong game and a start menu. I've easily conected the start button to starting the pong game. Now when the user gets beaten or beats the ai, it should import menu but I'm having problems ...
0
votes
1answer
20 views
Python RegEx missing parenthesis error
I was visiting some old python code, which had not thrown up any errors before, but when I tried to run it I encountered an error. This is the code that was giving me an error:
import re
text = r"I ...
0
votes
1answer
17 views
Next day or next row index in Pandas Data frame
I am trying to find a way to get the next day (next row in this case) in a Pandas dataframe. I thought this would be easy to find but Im struggling.
Starting Data:
ts = pd.DataFrame(np.random....
0
votes
0answers
15 views
Converting large nested JSON to CSV in python
I am fairly new to Python and have several nested JSON files I need to convert to CSV's.
The structure of these is the following:
{'Z': {'@SchemaVersion': 9,
'FD': [{'FDRecord': [{'NewCase': {'@...
-2
votes
0answers
12 views
Write CSV file with results from trial list of Experiment in PsychoPy
I have a script that is very close to being done, but I need it to write the results to me! How do I get it to make a csv file for me?
Also it does not seem to record accuracy nor reaction time from ...
0
votes
1answer
41 views
Python code runs on one machine but gives error in another.
This code runs fine in Anaconda python 3.5 on my desktop, but gives Type error: uorderable types str() < int() on my laptop. The file can be downloaded from here https://archive.ics.uci.edu/ml/...
0
votes
1answer
25 views
How to append to a txt file [duplicate]
Hello so I have this text filed named students.txt with names inside.
Buddy Mike Freshman 3.00
Allen Hood Sophmore 3.45
Dave Beck Freshman 3.00
Jose Sanford Sophmore 3.45
Juan Castro Freshman 3.00
I ...
0
votes
0answers
6 views
python suds-jurko returns an empty array when only one Map is inside it
I've been struggling with a soap response giving me en empty array with the python module suds-jurko 0.6 (python 2.7) whereas the very same request with the php soap client does give results.
...
0
votes
0answers
10 views
Launching Python script from Google Apps Script
I've been searching for some time, and, as I couldn't find an answer, I'm asking this one. My issue is quite simple:
I have a form linked to a sheet. Bound to this sheet, I have a script running, ...
0
votes
1answer
7 views
How do i format a websocket request in python?
I'm trying to create an application in Python that powers a GPIO port when the balance of a Dogecoin address changes. I'm using the websocket API here and this websocket client.
My code looks like ...
2
votes
2answers
24 views
isinstance python return different values
I am a bit lost about how isinstance() works in Python. I have used the function before, and the behavior was quite clear, until now.
A bit of context. I have a class Classifier which has a method ...
0
votes
4answers
25 views
Boolean comparing two strings
def valid(s, alphabet):
""" (str, str) -> bool
Return True iff s is composed only of characters in alphabet.
>>> valid('adc', 'abcd')
True
>>> valid('ABC', '...
0
votes
1answer
20 views
CSV duplicate row method not finding output file
I'm trying to do something very simple, use more_itertools to output unique rows from CSV File 1 to CSV File 2 as an iterative process over many CSV files. However, I receive the error:
IOError: [...
0
votes
0answers
18 views
How to use a python library that is constantly changing in a docker image or new container?
I organize my code in a python package (usually in a virtual environment like virtualenv and/or conda) and then usually call:
python <path_to/my_project/setup.py> develop
so that I can use the ...
0
votes
2answers
10 views
Selenium and Python3 ChromeDriver raises Message: Can not connect to the Service chromedriver
Please how do get selenium working in this scenerio? I have seen this questions times with fewer or no answers and i hope luck is on my side today.
Let me start by detailing my environment.
I am ...
1
vote
0answers
10 views
add data in loop with db.commit() sqlalchemy PYTHON
I need help with Python code
copy_groups = Group()
groups = Group.query.filter(Group.project_id == curent_project_id)
for i in groups:
copy_groups.project_id = curent_project.id
copy_groups....
1
vote
2answers
25 views
Python beautifulsoup parsing speed improvement
Currently I have written my first python script in order to loop through some URL's listed in a CSV. over 14,000 links. I am trying to 1) get all the keyword tags 2) check page status (404 links need ...
0
votes
0answers
12 views
Python grid columnspan
I want to fill the hole column with a text widgets using grid columnspan.Is that possible?
import tkinter
root = tkinter.Tk()
text = tkinter.Text(root)
text.insert('end','Text')
text.grid(row=0,...
0
votes
1answer
43 views
Python: how to find values in a dataframe without loop?
I have two dataframes net and M.
net =
i j d
0 5 3 3
1 2 0 2
2 3 2 1
3 4 5 2
4 0 1 3
5 0 3 4
M =
0 1 2 3 4 5
...
-1
votes
1answer
32 views
Efficient method of comparing elements from two lists
I’m attempting to compare individual fields from one dataset to individual fields on another, and score the comparison using a fuzzy matching package (fuzzywuzzy). For each row in dataset1, I want to ...
-1
votes
0answers
15 views
Python/Flask add data to a returned object from the database
In my code I run something like this,
sel = select([staff.c.name,
staff.c.leave_allowance,
func.sum(leave.c.hours).label('hours_used'),
(staff.c....
0
votes
1answer
15 views
Python Insert vars with commas into MySQL
I have variable value with comma (ex. var='some text, with comma')
How to INSERT this whole text (with comma) into one column?
My code doesn't work:
c.execute("""INSERT INTO resumes (var) VALUES (%...
0
votes
0answers
12 views
PyQt. Get errors trying to separate GUI from logic
So I try to separate GUI part from logic part, but I can't call logic function from GUI part. Here's the simplified version of the code:
GUI part
import logic
class Program(QMainWindow):
def ...
0
votes
0answers
7 views
Flask: Ignore if one file is not uploaded in form (containing multiple file upload options)
I have a multi-upload form in flask.
<form class="form-group" action="{{ url_for('load') }}" method="POST" enctype="multipart/form-data">
<input id="file-picker" type="file" name="file1"...
0
votes
1answer
8 views
Python Selenium - Webdriver interacts with data from previous page
I am trying to create a piece of code that takes an input from the user and searches for that input in his gmail account and then checks all the boxes from the sender which is the same as the input.
...
2
votes
3answers
40 views
Tuple and Iterators in For Loops Python
Working through Programming Collective Intelligence by Toby Segaran, this part of code confused me slightly. Written in python2, the sqlite select statements return an iterator which he then retrieves ...
-1
votes
2answers
24 views
Can you use {} and .format to put values into a dictionary
I am writing a script to query an ArcGIS rest service and return records. I want to use {} and .format to allow a dictionary item to be changed a time. How do I write this:
time = '2016-10-06 19:18:...
1
vote
0answers
20 views
Cython - calculating an array of distances between 2D coordinates
I have a function that use a generator to loop over large 2D python lists of float coordinates in order to create flat lists of integers that represent the distance between coordinates.
point_input = ...
0
votes
1answer
11 views
Python encoding - error: 'latin-1' codec can't encode character
In my snippet below, I'm process a string of text thats: Déclaration.png
I return the description as unicode:
return self.render_json(request, {..."description": u''.join((instance.description)),.....
0
votes
0answers
7 views
Tensorflow: How do I export a model to be used by a different module? [duplicate]
I've trained my model and saved it, and now I want to call it from another Python module. I now want to evaluate a few items, but I want the evaluation function to be called from outside.
Is there an ...
-1
votes
0answers
14 views
combining multiple json files [on hold]
I am trying to combine multiple JSON files and store it in a variable. Is there a more elegant way to do this? So far I have this:
def _validate_json_specification(self):
basepath = os.path....
-1
votes
1answer
17 views
Plotting two datasets from different folders on one plot
I have two folders with similar number of files: maindirNo and maindirWith. I'm trying to plot each pair of similar files from folders on one plot:
for i in [maindirNo, maindirWith]:
for root, dirs, ...
0
votes
0answers
7 views
Transforming XML Using SAX to another XML
I have a XML file from which I want to read, then after checking some conditions (e.g removing some parent tags with inner tags having values > 100 ) make a new XML
I know I should make a subclass of ...
0
votes
0answers
11 views
how to check the dimension of each tensor when running a tensorflow model?
I tried the tf.Print thing but it seems not printing anything.
Here are my codes, and I tried to tf.Print the dimension of the reshape tensor. How should I fix the code to print out the dimensions of ...
2
votes
4answers
36 views
Classify a list of numbers based on their values in Python
I am trying to write a loop in python that reads a text file of 50 numbers and sorts through the numbers and assigns them to different variables based on their values. I would like variable A to ...