Tagged Questions
0
votes
4answers
27 views
Python: “subprocess.Popen” check for success and errors
I want to check if a subprocess has finished execution successfully or failed. Currently I have come up with a solution but I am not sure if it is correct and reliable. Is it guaranteed that every ...
1
vote
1answer
18 views
Selenium WebDriver Python: How to stop 'send_keys' from hitting return after sending a string
I am trying to automate signing into a website using twitter, and to enter the twitter login info I am using the elem.send_keys("username") method in Selenium WebDriver
The method seems to also 'hit' ...
-1
votes
0answers
19 views
Import rpy2.robjects gives error
I have a data which contains 10 millions records. I have an R code which requires to estimate the coefficient of a model using 3000 iterations. Running the R code on this data is very time consuming ...
-1
votes
0answers
18 views
Trying to add a timer to my game
This is a really simple question, and I don't know why I haven't got the answer to it, but does anyone know how to correctly add a timer in pygame for Python 3.4.1?
Here's what I have so far:
texta ...
0
votes
0answers
22 views
Windows 7 Python installation: Works with full command, but “file.py --version” returns “Could not load Python dll”
This is a followup to this question: The *only* way to successfully execute Django python command is with "python ...PATH...django-admin.py [options]". Why can't it be reduced?
I can ...
-2
votes
0answers
28 views
Exclude dirs not working. Is there a something wrong with my code?
#!/usr/bin/python2.7
import os
import sys
import re
import fnmatch
from pprint import pprint
def findit(root, exclude_files=[], exclude_dirs=[]):
exclude_files = (fnmatch.translate(i) for i in ...
2
votes
4answers
37 views
Is there a better way to do an “unravel” function in python?
I was faced with the problem of executing n number of concurrent events that all return iterators to the results they aquired. However, there was an optional limit parameter that says, basically, to ...
1
vote
1answer
31 views
Intersection and difference of two rectangles
Searching the internet has not given a satisfactory solution for the following problem. Given a class Rectangle defined as the following:
class Rectangle:
def __init__(self, x1, y1, x2, y2):
...
1
vote
1answer
22 views
Import object from module of same name using __import__
I have a directory structure as follows:
root/
__main__.py
files/
__init__.py
foo.py
bar.py
baz.py
each file has an object in it with the same name as the ...
0
votes
0answers
26 views
Python Tkinter / How to let OptionMenus share one item list?
i'm trying to build multiple option menus sharing the same "base item list". A multiple selection of one item in different menus should not be possible, so all menus have to be updated when an item is ...
0
votes
0answers
30 views
How to reduce “python …PATH…django-admin.py startproject myprojname” to “django-admin.py startproject myprojname”?
UPDATED: See the bottom
The first step of the Django tutorial instructs you to create a new project like this
django-admin.py startproject mysite2
When I do that, it fails:
...
0
votes
3answers
30 views
Testing that a string DOES NOT have specific characteristics in a small program (python 3)
I am trying to write a program that will ask the user to input a string in all uppercase that ends with a period. Then have it come back with responses when the input doesn't meet the criteria. I ...
-2
votes
1answer
30 views
how to print lines using regur expression in python?
I want to print only the paricular strings from all lines in the file using re.search. i want to print only from is to script
For example file.txt contains:
python is a nice script language
dogs ...
-5
votes
2answers
40 views
Syntax error on print “hello” [duplicate]
I just installed 3.4 on a new machine, tried to run something I know works and it failed. I then tried to just type the following into IDLE and it failed:
>>> print 'hello'
SyntaxError: ...
0
votes
1answer
30 views
Receiving unexpected content in http response
I'm working through the Python Challenge in an effort to learn Python. Throughout these challenges grabbing the page source can be very beneficial. However, I am not receiving the page source that I'm ...
1
vote
4answers
63 views
Python - checking whether indexed element of a list exist - Best Practice?
I have something like this:
for i in range(0,100,5):
text = ("Price\t",
foo[i+0].bar, "\t",
foo[i+1].bar, "\t",
foo[i+2].bar, "\t",
...
0
votes
1answer
28 views
Different PYTHONPATHs for Python2.7 and Python3.4
I've got both Python2.7 and Python3.4 installed on my computer.
I've installed Numpy for both 2.7 and 3.4, but can't figure out how to specify the PYTHONPATH variable so that 2.7 uses Numpy2.7 and ...
0
votes
2answers
25 views
Sort list of list with key and locale (here: german umlauts)
I know how to customize sort with the (simple) key=function. But how to do that, if I need a more complex key= function. I have problems in getting it together.
Here's the snippet:
In the first ...
0
votes
1answer
9 views
Select reference level in y-variable/ LHS/ endogenous side using patsy
I'm trying to use Patsy to make endogenous and a exogenous datamatrices, for use in binary logistic regression. I'm having problems setting the reference level of the endogenous side.
The problem ...
0
votes
2answers
33 views
Can't find split() method or replacement in string module in python 3.4.1? [duplicate]
I'm trying some text manipulation stuff out and am bumping into the error:
wordlist = string.split(" ")
AttributeError: 'module' object has no attribute 'split'
I have imported the string module ...
0
votes
2answers
29 views
Is 'encoding is an invalid keyword' error inevitable in python 2.x?
Ansi to UTF-8 using python causing error
I tried the answer there to convert ansi to utf-8.
import io
with io.open(file_path_ansi, encoding='latin-1', errors='ignore') as source:
with ...
0
votes
1answer
17 views
Nothing happens for either input
I have a feeling I've made a silly mistake somewhere but at nearly 2am I just can't see it...
Here's the code in question. It is part of a function:
running = True
while (running):
playerName = ...
0
votes
1answer
54 views
Multithreading python (using _thread), doesn't do anything
First of all, here are my two python files:
sred.py:
import _thread,time
class Thread:
def __init__(self,time:int,say:str):
self.time=time
self.say=say
def create():
id = ...
-1
votes
0answers
29 views
Py3 Reverse list comprehension, explanation
I've got a list comprehension in python3 and I don't really understand what it does, or how exactly it does what it does.
board = ['A', 'B', 'C', 'D'] * 2
board_visible = list('_'*8)
flipped = []
...
0
votes
1answer
21 views
How does one take a listbox selection and depending on that selection a second list box is created?
So I am still learning tkinter. I have three list boxes and the first one has a certain number of options. When the user selects an option, the second list box needs to fill depending on previous ...
1
vote
0answers
28 views
Filling in with the last entry of the group
Say I have the following dataframe:
> df
C D E
A B
bar one -1.350006 0.260339 2
three -0.236451 -0.056614 0
flux six ...
0
votes
0answers
29 views
get values of a same tag in multiple places in an XML file using Minidom
I wrote a script to pull out a tag value in an XML file. That works fine. Here comes the challenge for me. I have an XML file that has the following structure in numerous places.
<chl ...
0
votes
1answer
36 views
Can't output Float values to text file using Python 3
My code currently produces an array (ra) containing only float values. If a value in this array meets a certain condition, I want to output that specific value to a text file. Here is the part of my ...
1
vote
1answer
16 views
TypeError: can't concat bytes to str, trying to use python3
So the following site explains how to make an irc bot, using socket, but it only works for python2, so I tried to make it compatible, but I get the error mentioned in the title.
Here is my code:
...
4
votes
1answer
50 views
Selenium: page displayed differently
I lanuch firefox with the below URL (do not run it, it is blacklisted, I use it just for a security test). Here is the simple code I used:
from selenium import webdriver
driver=webdriver.Firefox()
...
-2
votes
1answer
28 views
Cannot unpack a zip object multiple times
Why is this not working?:
t = zip([3],[4],[3])
print("1:",*t)
print("2:",*t)
We cannot unpack a second time in Python, why is that?
0
votes
1answer
20 views
Tkinter not working as expected in Python 3
I have this snippet of code and I expect it to create a gui with a bunch of buttons and a text box. But I only see the empty box with the title:
from tkinter import *
root = Tk()
root.title("title")
...
0
votes
0answers
52 views
Error in calling a class in Python
I am unable to use a example from there
I am testing out the sample here
http://cloud.verizon.com/documentation/AuthenticationRESTCallExample.htm
I am calling them by using (This is for sample)
...
0
votes
1answer
41 views
Runtime Error with Recursion Algorithm
I was trying to come up with a piece of code that sums every possible combination of the given list.
class Answer:
possible = False
def addAll(self, added, rest, answer):
if ...
0
votes
1answer
26 views
Python iterator is empty after performing some action on it
I was trying to do a challenge on codeeval in python3 and got stuck trying to improve my solution. Every time i tried to iterate (or print, or some other action) two times consecutively over the same ...
0
votes
1answer
20 views
Why doesn't Python sqlite3 insert auto-incremented ID
In Python 3.4.1, why doesn't sqlite3 insert the auto-incremented ID into the table in the below program? According to the SQLite documentation, an integer primary key column should auto-increment, and ...
0
votes
1answer
25 views
Is it possible to limit Flask POST data size on a per-route basis?
I am aware it is possible to set an overall limit on request size in Flask with:
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
BUT I want to ensure that one specific route will not accept ...
0
votes
1answer
23 views
Protocol Buffers in Python 3 - NotImplementedError
I am trying to use Google Protocol Buffers in a Python 3 project. However the generated python files do not want to cooperate with the google.protobuf library. Trying to use the protobuf objects ...
0
votes
2answers
35 views
Python - addition
I'm trying to make a program that adds the input, which will be in the form of '7 5 4 1' etc with a space between each number, and will add 7, 5, 4 and 1 for the output. So far I've got nothing ...
-3
votes
1answer
31 views
How to store value instead of the list that the symbol stands for in python?
So I have similar things to this following code:
for k in RANGE:
delta = array(range(n_stack))
while delta[2:-2].max()>0.001:
phi_check=copy(phi0)
...
-1
votes
0answers
32 views
Can i change this code to make it stop my raspberry pi car when no key is pressed? (python)
First off, I have Q set to the stop function for my car, but I would like to make it so the car only moves when a key is pressed. E.g., when I press W the car goes forward, but I have to use Q to stop ...
-1
votes
1answer
23 views
Python - how to access class method variable from another class level
Below you can see some code from DrawClass class. I want to read text from entryConnection variable in one of ActionClass methods(another class). How to access it? I were looking for answer on ...
0
votes
1answer
19 views
Reading stock data from Yahoo using Python 3.4 and not able remove the data
I'm using Python 3.4 and I'm trying to download the data from Yahoo finance.
Below is my code:
import urllib.request
url = ...
2
votes
2answers
39 views
logger creating multiple files
The following piece of code creates 3 or 4 log files. How should it be written so that only 1 file is created while keeping the format of the filename? Also, this seems to be a Windows only issue. ...
0
votes
0answers
14 views
Python 3.* Changing window background via button click
I've been using the site for a while, very helpful for many things linux and python, so thanks :) I have found out how to put a background on an application window. I made a button that leads to a ...
-6
votes
2answers
37 views
How to create a 2d grid?
How do I create a 2D grid in python? Could someone give me an example of how to do it?
It would really help.
Here is what I have so far:
board = []
a = ["O", "O", "O", "O", "O"]
for i in range(0, ...
0
votes
1answer
29 views
Boolean expressions and control flow involving manipulating index numbers
Tried this in Python as part of a function, and predictably, it did not work:
outputlist = [-5,-4,-3,-2,-1,0,1,2,3,-2,-1,0,2,4,-3,-2,1,0,2]
def counter(outputlist):
outputlistcut = ...
0
votes
1answer
30 views
Parse HTML, 'ValueError: stat: path too long for Windows'
I'm trying to scrape data from NYSE's website, from this URL:
nyse = http://www1.nyse.com/about/listed/IPO_Index.html
Using requests, my I've set my request up like this:
page = ...
-4
votes
0answers
36 views
Convert input integers to list of tuples
I am passing input file with integers and I want to returns a list of tuples.
The input is string since we are passing through file but I am not able to convert it to below format. I got it upto ...
0
votes
2answers
36 views
Python prime number code giving runtime error(NZEC) on spoj
I am trying to get an accepted answer for this question:http://www.spoj.com/problems/PRIME1/
It's nothing new, just wanting prime numbers to be generated between two given numbers. Eventually, I have ...