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 [...
-1
votes
0answers
12 views
Adjacent elements in a 2D python list/matrix
If I have the 2D list/matrix:
m=
'''
[1,2,3]
[4,5,6]
[7,8,9]
'''
for each element is there any way to distinguish if the adjacent 8 spaces contain an other element or are blank.
for example:
'' ...
0
votes
0answers
10 views
subprocess or threads for checking pings to a server?
I've never used multithreaded processes before or tried to make them and I'm a noob to coding subprocesses but I understand what forking is conceptually and it isn't that hard to understand per se.
...
0
votes
0answers
9 views
cpu/memory monitor using wxpython matplotlib and funcanimation
I have designed cpu/memory monitor using wxpython matplotlib and funcanimation.
Problem description:
self.line_animation = animation.FuncAnimation(self.figure, self.update_lines, frames = 25, ...
0
votes
0answers
5 views
OpenSubtitle API, returning blank data with status 200
(A same question is available in Stackoverflow. But that didn't help me because it used other function)
Hello, I am trying to implement Opensubtitle API with Python. I prefer trying to search ...
0
votes
0answers
13 views
Why I can't install the dependencies for the Flask application?
I'm following the tutorial for creating a microblog using the Flask from the Miguel Grinberg website. The link is as following:
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-...
0
votes
0answers
6 views
adidas script: 'NoneType' object is not subscriptable
Need help with an adidas auto checkout script. Getting the following error:
Traceback (most recent call last):
File "adidas.py", line 169, in <module>
checkout()
File "adidas.py", line 80, ...
0
votes
1answer
9 views
Possible causes of CUDA get device properties error with Python3 / Theano?
I'm trying to use multiple GPUs with multiprocessing in Python3. I can run a simple test case, like the following:
import theano
import theano.tensor as T
import multiprocessing as mp
import time
# ...
0
votes
0answers
4 views
pypy5.1.1 errors installing packages
Environment:
$cat /etc/issue
Red Hat Enterprise Linux Server release 6.2 (Santiago)
Kernel \r on an \m
$pypy
Python 2.7.10 (b0a649e90b6642251fb4a765fe5b27a97b1319a9, May 26 2016, 05:22:09)
[PyPy 5.1....
0
votes
0answers
28 views
Python adding to dictionary wth multiple values from file ..getting error
I am getting error ..list out of range with this code.. can someone help pls?
def classGrade(infile):
inf=open(infile)
contents=inf.readlines()
inf.close()
classg={}
for line in ...
0
votes
0answers
7 views
Retrieving hdf5 index given literal name
I have an hdf5 database with 3 keys (features, image_ids, index). The image_ids and index each have 1000 entries.
The problem is, while I can get the 10th image_ids via:
dbhdf5 ["image_ids"][10]
&...
0
votes
1answer
16 views
Django trying to use wrong Database User
SOLVED: I was using USERNAME, not USER from previously attempting Postgres driver.
I'm trying to connect my django project to an RDS MySQL database. I can connect fine using my credentials in MySQL ...
0
votes
0answers
32 views
Java lambda expressions exercise
Our teacher gave us an exercise about Java lambda expressions, we got code samples which are written in python and it has to be done in Java. Unfortunately i am not good in both python and lambda ...
0
votes
0answers
6 views
What is the difference between EOF and quit/exit in pdb
Hi I'm trying to understand the command EOF in pdb. When I type EOF it quits pdb and the repl too. The command quit have exit has an alias. So I do understand why quit/exit will exit the program. In ...
0
votes
0answers
3 views
Unable to sniff outgoing traffic using raw sockets in python2.7
Following is my code :
!/usr/bin/python
import socket
import struct
import binascii
rawSocket = socket.socket(socket.PF_PACKET,socket.SOCK_RAW,socket.htons(0x0800))
# use 0x0800 ...
0
votes
2answers
24 views
Appending to array while iterating over it
I'm trying to create a python script that loops through an array of entries and adds a new day object with a date if that date is not already in the date list.
entryList = [aDate,anotherDate,fooDate]
...
1
vote
1answer
17 views
How to pass parameters from front end to python script
I'm trying to pass the parameters defined by a user in the front end to a python script being run on the server. I'm using a Django framework in the back end (probably too heavy for my purposes at the ...
1
vote
3answers
34 views
How to convert multiple ELIF statements into one method (PYTHON)
I am wondering how I can go about condensing these elif statements into a method of some sorts. I also don't know how to go about storing a chosen coordinate so that I can perform checks of ...
0
votes
1answer
12 views
Custom Domain issue for Application
I designed one Web Application(MOOC) on Google Course Builder and want a custom domain for this application.
I performed all the steps exactly mentioned in the documentation.
After this the ...
0
votes
0answers
16 views
Making a table that matches a table in the database not working for me
I'm trying to make a table which matches with a table in a database so I can devlop code which changes data in that table. I found this code which makes the connection with the table in the database.
...
1
vote
3answers
24 views
Jump It Number Game - Python
I'm trying to create a simple game of "Jump It", it's supposed to take the numbers in a line (input obtained from an file), and find the cheapest route to get to the end. It takes the numbers in ...
1
vote
1answer
11 views
Python nltk counting word and phrase frequency
I am using NLTK and trying to get the word phrase count up to a certain length for a particular document as well as the frequency of each phrase. I tokenize the string to get the data list.
from nltk....
0
votes
0answers
10 views
Pass REST API session_id (or cookie) to selenium
I have been trying to access my Salesforce account home page using Selenium but I have struggled to go through the login page. I found out the work around was to use the module simple_salesforce to ...
-1
votes
3answers
32 views
Links in python
I got a regex which is suitable for getting the Hyperlinks in a page source.
When I run this piece of code
import sys,re
import webpage_get
def print_links(page):
print '[+] print_links()'
...
1
vote
3answers
24 views
How to find and count each line in a text file using regular expressions in python?
say i have a text file that says:
motion
black
lotion
mansion
cardio
sensational
The code i have so far is:
import re
f = open("file.txt","r")
ex = re.findall("", f)
print ex
Im just not sure ...
-1
votes
0answers
16 views
Raspbian - crontab task not running when reboot
I have added a bash script in crontab -e which execute when machine reboot but it's not working.
That is a simple bash script
#!/bin/bash
python test1.py &
python test2.py &
I am thinking ...
1
vote
1answer
21 views
String representation of an HEX array
Please i need some help, i have a python script that parses serial data, the data is stored on a byte array.
the problem, i ave an array with the string representation of a datetime:
bytearray['\x01'...
-1
votes
1answer
18 views
issue with hangman code
I am trying to make hang man and I came into a little issue.
The game us going to be based on lists and comparing them.
Usually when someone plays hang man for example lets say the word is "hello" ...
0
votes
1answer
20 views
Python - Writing Multiple Monthly CSV Files from One Large CSV File - Automating Filenames to Reflect Month
I've researched this question heavily for the past few days and I still cannot find suggestions to my problem.
Below is an example of my dataframe titled 'dfs'. There are around 80 columns, only 4 ...
1
vote
1answer
26 views
Is it possible to create a method by an argument
Say I have two functions
def do1(x, y):
return x + y
def do2(x, y):
return x - y
I can create a class like this
class foo(object):
def __init__(self, func):
self.func = func
...
0
votes
1answer
13 views
Can you keep track of indices using a map in python or other higher order functions?
In Javascript, when we perform higher order functions we maintain access to the element, index, and iterable we perform the function on. For example:
[10,20,30].map(function(element, index, array) {
...
3
votes
3answers
31 views
Conditional terms in Python list initialization
I want to do something like this:
a = some_funct()
b = [ 1, a if a is not None ]
The list b should be one element long if a is None, and two elements long if a is not None. Is this possible in ...
1
vote
0answers
30 views
How to replace a double loop with mask and indexing?
I have a couple of nested for loops that do the right thing. However the performance is too slow, and I feel there must be a better Pythonesc way to do this. The goal is use the mask to determine when ...
1
vote
0answers
29 views
Python Quadratic Equation Class
I am currently creating a class in python to make a quadratic equation. I wrote down a discriminant function within the class, and I'm trying to call on it within the roots function, however, I'm not ...
1
vote
1answer
8 views
Populate rows of empty matrix from another matrix by index array in numpy
I have an array:
arr = np.array([[ 5.1, 3.5, 1.4, 0.2],
[ 4.6, 3.1, 1.5, 0.2],
[ 5. , 3.6, 1.4, 0.2]])
and an index array:
index_arr = np.array([True, False,...
1
vote
1answer
34 views
Converting python for loop to while loop
I am trying to convert for loop to while loop in python and I am not very sure how to do it. Need some help here, thanks! This is what I am working with :
with open('name.csv') as labelcsv:
...
1
vote
3answers
14 views
How to add multiple Columns into Sqlite3 from a for loop in Python
Admittedly I a still very new to both Python and Sqlite3, and I am attempting to add the contents of two lists into a database so that one list is in the first column and the second list shows up in ...
1
vote
0answers
19 views
Tree not functioning as exspected
I am trying to have my program load a tree of every possible tic-tac-toe board and then when given a random board input it can print out all the possible next moves based on the tree. However, when I ...
0
votes
0answers
25 views
getting dynamic data using python
I'm new to Python and got interested in writing scripts. I'm currently building a crawler that goes on a page and extract copy from tags. Write now I can only list tags; I'm having trouble getting the ...
1
vote
1answer
9 views
Enqueue and increment variable in Tensor Flow
How can I make a Tensor Flow graph push an incrementing number to a queue?
I am just doing this for learning purposes, so I'd prefer if you kept it similar to what I'm doing (and correct what I'm ...
0
votes
0answers
12 views
how to avoid having a '\' cutting off a row when printing large tables?
in python 3.5 when printing a large table out, i did not code anything like'\n', but i always got something like this:
RULE_PACKAGE SCORE RISK_TYPE RULE_TYPE CREATE_TIME \
612 ...
2
votes
1answer
20 views
python library for neural networks and deep learning
I'm evaluating python packages that can implement neural networks for my project. Since I'm a user of sickit-learn, so I prefer user-friendly command and function. And my project will need to build a ...
0
votes
0answers
8 views
Python gTTS not accepting strings within variables
I am writing a python script to scan a photo which contains text with google vision OCR, then use Google gTTS to speak the text. Here is the code:
#BookrBasic
from os import system
from time import ...
0
votes
0answers
9 views
How to access individual elements within a rolling window on a dataframe
I have a dataframe with the quarterly U.S. GDP as column values. I would like to look at the values, 3 at a time, and find the index where the GDP fell for the next two consecutive quarters. This ...
0
votes
0answers
12 views
What is the code doing in a Python queue “peek”?
This python code below uses a queue system with two stacks. From what I understand, during the "peek" function--we are looking at the top of the list and returning it.
def peek(self):
#looks at ...
0
votes
0answers
12 views
Difference between [0]*x and [0 for i in range(x)] in python [duplicate]
So i was trying to do the commonly known knapsack(0-1) problem in python and came across something that stumped me.
The way i declare my array gave me different answers.
Below is my code:
def ...
1
vote
2answers
24 views
Trying to set a character in a string in a particular position to another character
I'd like to try and do this without using indexing.
def SSet(s, i, c):
#A copy of the string 's' with the character in position 'i'
#set to character 'c'
count = -1
for item in s:
if count >= ...
-2
votes
2answers
14 views
running python def and cipher text
So I have this function which is suppose to de-crypt a cipher text but I do not know how to run this function, I barely use python any help would be must appreciated.
def decrypt1(ctext, key):
...
0
votes
0answers
17 views
How to connect AWS RDS MySQL from Django app from local
I am able to connect to the RDS instance from both MySQL Workbench and the mysql CLI command, so it is not the credentials that are the issue. I am trying to run python manage.py migrate but I get the ...
1
vote
2answers
13 views
Django Rest Framework - Router Register not working
I'm using django rest framework to generate an api. In it I have two models, associated views and serializers. These are beers and pours. The beers api endpoint works as expected, but whenever I try ...
1
vote
2answers
21 views
Regex String Slicing
I am using Python flavor if regex, and I need to slice a string while replacing text. The regex I am using to match my needed string is this, abc .+ cba. If it matched abc Hello, World cba, that ...