Tagged Questions
0
votes
1answer
17 views
str object has no attr keys in BFS
I am trying to implement a Breadth First Search function with my data set. My data is a list filled with dictionaries and have list values. An example of my data would be:
a = [
...
0
votes
1answer
52 views
While loop is taking forever and freezing screen?
I have this large program, one of whose parts includes the click of a button (this GUI was made in wxPython). Basically, the button is a timer, and when you click on it, the text of the button ...
-2
votes
2answers
30 views
what type of object is returned when calling a function
`I wrote a function that returns a dictionary and then called this function within another function to get a value using key x:
def buildCoder():
return dict
def apply():
coder=buildCoder()
...
0
votes
4answers
31 views
Combine list of lists with similar values in python
I have a list of lists, like so:
items = [['118', 'white'], ['118','Jack'], ['118','guilty'], ['200','black'], ['200','mark'], ['200','not guilty']]
Is there a way to use a for loop to grab the ...
-1
votes
1answer
42 views
make output look nice and clean in python
I'm really new to python. I was just wondering, how do you make the output to look nice and clean? because my output for search and sort functions looks like this
"[{u'id': 1,
u'name': ...
0
votes
0answers
11 views
Installing MayaVi on Windows, working with Python 2.7
I am trying to install the MayaVi package using pip, but I keep getting an error message saying (ImportError: No module named vtk). How do I fix this problem?
So on command prompt:
$pip install mayavi
...
0
votes
2answers
29 views
ValueError: could not convert string to float in simple code
# -*- coding: cp1250 -*-
print ('euklides alpha 1.0')
a = raw_input('podaj liczbę A : ')
b = raw_input('podaj liczbę B : ')
a = float('a')
b = float('b')
if 'a'=='b':
print 'a'
elif 'a' ...
0
votes
2answers
16 views
pypokereval library configure script fails with “No python development environments found”
I'm trying to compile the pypoker-eval-138.0 library for python2.7 (default on mint linux):
source tarball dir
GNA pokersource site
So when running the configure script via ./configure, I get ...
0
votes
1answer
9 views
Anritsu Pyvisa Issues
I'm having issues comminicating with the Anritsu MG69377B microwave generators.
I have no problem going into remote mode and identifying the instrument, but any other command which returns a value is ...
0
votes
3answers
39 views
Python find closest match out of list [on hold]
I have a list with tuples of rgb color values:
colors = [
(0, 0, 0),
(0, 0, 170),
(0, 170, 0),
(0, 170, 170),
(170, 0, 0),
(170, 0, 170),
(255, 170, 0),
(170, 170, 170),
(85, 85, 85),
(85, 85, 255),
...
1
vote
1answer
33 views
extracting nested items with beautifulsoup
this may very well be a duplicate. I have read a lot of table-related questions -- like this one -- attempting to understand how to extract web page contents that're more deeply nested.
Anyhow ...
0
votes
0answers
6 views
Does HappyBase support row_start filter while scanning to filter where key is long
I am using Java to insert data in HBase table where key is long data type
I am using Python happy base to extract the data.
I am trying to scan the table by doing following
...
1
vote
3answers
38 views
Questions regarding Python and Class specific variables
I have a question regarding python and class initialized variables.
So I recently noticed in Python (2.7.X) that if you set a class variable that hasn't been defined or initialized, you are still ...
0
votes
2answers
31 views
How to extract href, alt and imgsrc using beautiful soup python
Can someone help me extract some data from the below sample html using beautiful soup python?
These are what i'm trying to extract:
The href html link : example
...
0
votes
1answer
31 views
Not Getting Correct Answer for sine & cosine in Python
I am going through some of my old C++ school assignments and re-doing them using Python. I am now re-doing an assignment where we had to approximate sin() and cos(). I am using the same math I used in ...
0
votes
0answers
31 views
Cannot get python IDLE 2.7, 3.3 to run - OS X
I am running a MacBook Pro with 8gb of memory and a 2.5GHz processor. I run OS X Mavericks, but this problem has happened on other operating systems as well. when I try to open the editor, or even ...
1
vote
1answer
22 views
Python Server-Client Communication with each other
I am trying to modify a tcp/ip server-client communication. Only the server can communicate with the client. I am trying to find an easy a way to send a message back to the server. Not a chat !! Just ...
1
vote
4answers
79 views
Finding the square root in python with the ** operator
I am slightly confused on what the ** operator means in python
import math
radius = raw_input("Enter your radius")
area_of_circle = radius ** math.pi
print area_of_circle
What I am trying to do ...
0
votes
1answer
33 views
Continue printed text to next line in Python
I have a line of text that I want to make look better by cutting off the end and printing it to the next line. I am using Tkinter and trying to make a Label use 3 lines instead of 1 as the text is WAY ...
2
votes
0answers
45 views
Global variables declared within function are still considered local
I am trying to write the program battleship. I have two gameboard matrices: one for player, one for computer. These are defined outside of main because I want them to be global variables because ...
1
vote
4answers
35 views
Indexing a nested list in python
Given data as
data = [ [0, 1], [2,3] ]
I want to index all first elements in the lists inside the list of lists. i.e. I need to index 0 and 2.
I have tried
print data[:][0]
but it output the ...
2
votes
2answers
32 views
How to kill a process been created by subprocess in python?
Under Linux Ubuntu operating system, I run the test.py scrip which contain a GObject loop using subprocess by:
subprocess.call(["test.py"])
Now, this test.py will creat process. Is there a way to ...
1
vote
2answers
46 views
Cannot find the file specified when using subprocess.call('dir', shell=True) in Python
On a 64-bit system with 32 bit python 2.7 installed I am trying to do the following:
import subprocess
p = subprocess.call('dir', shell=True)
print p
But this gives me:
Traceback (most recent call ...
2
votes
3answers
29 views
ValueError: unconverted data remains: 02:05
I have some dates in a json files, and I am searching for those who corresponds to today's date :
import os
import time
from datetime import datetime
from pytz import timezone
input_file = ...
1
vote
2answers
23 views
Can you use csv.DictReader without a file?
I have some comma-separated input I want to parse into a dictionary, so csv.DictReader seemed like a good fit. However, the input is already in string form and not a file as the interface to ...
0
votes
0answers
30 views
How to pass parameters into remote server python script?
I'm writing python script. How to pass (username, filename, Hex_format) parameters from client side into remote server side.
Client Side:
#!/usr/bin/python
import socket
import urllib
import ...
1
vote
1answer
60 views
python sys.argv[1] vs. sys.argv[1:]
I wrote this code:
#!/usr/bin/env python
import sys
if sys.argv[1] :
print sys.argv[1]
Try this in console when typed:
$ python py.py xxx
that prints xxx
When i leave it with no parameter an ...
3
votes
1answer
39 views
Python3.3 header preferred over Python2.7 header by gcc
I am trying to compile a code which uses the Python.h header. In fact it is the lcm library.
Now, I have Python2.7 and Python3.3 installed on my system. The respective header filer are found in ...
1
vote
2answers
32 views
Trying to import a list of words using csv (Python 2.7)
import csv, Tkinter
with open('most_common_words.csv') as csv_file: # Opens the file in a 'closure' so that when it's finished it's automatically closed"
csv_reader = csv.reader(csv_file) # ...
6
votes
0answers
96 views
Utilising Genetic algorithm to overcome different size datasets in model
SO I realise the question I am asking here is large and complex. As such I will award a 250 point bounty to anyone who can help me overcome this problem.
Background
I am making a complex (by my ...
0
votes
1answer
37 views
What's faster: temporary SQL tables or Python dicts for session data?
Have some programming background, but in the process of both learning Python and making a web app, and I'm a long-time lurker but first-time poster on Stack Overflow, so please bear with me.
I know ...
0
votes
3answers
38 views
Python 2.7.5 Palindrome code confusion
So i was looking around on here and i found the code for a working palindrome
def isPalindrome():
string = input('Enter a string: ')
string1 = string[::-1]
if string[0] == ...
0
votes
2answers
20 views
Need help writing a Python script that will input a sentence and count the number of words it contains
def main():
p =input("Enter your sentence: ")
words = p.split()
wordCount = len(words)
print ("The word count is:", wordCount)
main()
I get the read out:
Enter your sentence: Hello ...
1
vote
1answer
39 views
So why did this Pygame move code work, but not this one?
So I have these two blocks of code, both which are designed to move a beetle NPC in a circle around a screen.
The first one works fine.
##beetle moving code
if beetle_list[0].rect.x == 400:
...
0
votes
0answers
17 views
TypeError: 'float' object has no attribute '__getitem__' when using reportLab
I know that there are loads of questions with the same name, but I couldn't find a question with the same point of problem.
I am using reportLab for creating a chart, and want to save a drawing to the ...
0
votes
3answers
62 views
Python code not writing into file
I have several text files in a folder, containing a list of names and adjectives. I have managed to create a script that takes random names, second names and such and creates a character from that ...
0
votes
0answers
37 views
Why does Python follow symlinks? How do I work around that?
This is my directory layout:
projects/
+-projectA/
|---moduleA.py
|---script.py -> ../projectB/script.py
+-projectB/
|---script.py
This is what script.py contains:
import ...
1
vote
1answer
21 views
Index error where I think there isn't
print "Qual deve ser o tamanho do tabuleiro?"
while 1:
tamanho = input()
if 1 < tamanho < 6:
print "Que o jogo comece!"
break
else:
print "Nao posso usar isso ...
0
votes
0answers
18 views
py2exe doesn't include entire package
I am trying to build an exe file using py2exe. The script is to create some word clouds using pytagcloud.
The issue is that py2exe doesn't include the entire pytagcloud package because of which the ...
0
votes
1answer
15 views
fnmatch does not work with variables but with static strings
The following code does not find any of the patterns defined in the file patterns.
#!/usr/bin/env python
import os
import fnmatch
patternFile = open('patterns', 'r')
patterns = ...
0
votes
1answer
67 views
Removing Stopwords in Python
I'm trying to remove the stopwords from a user input string using the .join fuction. It looks like this:
while True:
line = raw_input()
if line.strip() == stopword:
break
...
0
votes
1answer
26 views
Python modules not found in virtualenv
I can't get modules to run in my virtual environment. Using pandas as an example:
With the virtual env on I run yolk -l and get back (shortened version):
...
0
votes
0answers
13 views
Relationship id doesn't saved in sqlalchemy one-to-many relation
I'm learning Flask with SQLAlchemy, and I have created a relationship as described in the page:
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
...
2
votes
0answers
21 views
Error in using Python freeze.py
I want to package my Python file on Ubuntu so I installed python2.7-examples. When I used python freeze.py my_file.py I got the following error:
Error: needed directory /usr/lib/python2.7/config not ...
1
vote
2answers
37 views
How do I count the user input in a while loop to stop at 10 inputs?
I have recently started creating a Python program for my coursework.
I have pretty much the main skeleton of the program but I have created a while loop and I need it to stop when the user enters ten ...
1
vote
1answer
22 views
Python Turtle compare colour
my problem is I wanted to compare the Turtle colour but apparently there is a failure:
>>> turtle.color("green")
>>> turtle.color()
('green', 'green')
>>> ...
0
votes
1answer
27 views
argparse: how to make group of options required only as group
I am using python2.7 and argparse for my script. I am executing script as below:
python2.7 script.py -a valuefora -b valueforb -c valueforc -d valueford
Now what I want is that,
if option -a ...
-1
votes
1answer
30 views
Downloading file with python [on hold]
I am trying to download a file using a python program using a REST API.
The response has the following headers set:
Content-Type - will correspond to the file's mime-type
Content-Disposition: ...
1
vote
1answer
22 views
Extracting images from contours
I am trying to figure out how to make a script that cuts out images from a sheet of images. I can't understand what to do after I get the contours of the images. My train of thought is to load a ...
-3
votes
0answers
53 views
python interactive interpreter around a python application [on hold]
I want to write a program which has an interactive interpreter around it.
This interpreter should read multiline Python code with indentation and stuff (not like the raw_input() or Cmd.commandloop() ...