Tagged Questions
Python is a dynamically and strongly typed programming language whose design philosophy emphasizes code readability. Two significantly different versions of Python (2 and 3) are in use. Please mention the version that you are using when asking a question about Python.
0
votes
0answers
3 views
python logging with multiple modules does not work
I created some Python files keeping my functions a bit seperated to ease working / fixing. All files are in one directory. The structure may get broken down to something like:
a.py (a class A with ...
0
votes
0answers
2 views
CherryPy static content from different paths
I have read some Q&A like load-static-content-with-cherrypy
However, I am unable to figure out how to do it to be shared by different paths.
I have the following Class:
class Root(Base):
...
1
vote
0answers
7 views
Built-in view login : Error handling and good practice
I would like to use the Django's built-in login view : django.contrib.auth.views.login
This view does a great job. It detects when a login is wrong and when the account is not yet validated BUT the ...
-3
votes
3answers
20 views
python:cant figure out whats wrong in this code but still i am getting an taberror
getting an error in line 28 having if count<10 : ^
TabError: inconsistent use of tabs and spaces in indentation.
count= input('Give me no. of donuts: ') if count<10 : print('No. of donuts: %s' ...
0
votes
0answers
6 views
Web Development - How to access custom host, defined in my hosts file, from another device in the same network
Ok, I hope i'll be able to explain the issue im experiencing.
I'm working on a project, that has 2 parts: one takes all requests from usual localhost, the other handles requests from myhost.local.
...
0
votes
0answers
17 views
Python json, unnecessary slashes
I am creating a simple server side app, i use built in module "json" for creating an answer to client.
if isinstance(obj, (list, tuple)):
return json.dumps({key: [o.to_json() for o in obj if
...
0
votes
3answers
18 views
spliting list into smaller lists
def group(l,size):
length = len(l)
new = []
for i in range(0,length):
for j in range(i,size):
new[i].append(l[j])
print new
The above function group(list, size) ...
0
votes
1answer
17 views
Adding ManyToManyField in correct order
I am facing an interesting problem, I don't know whether it is a problem, but it is not giving the expected value that I need. Here is my two models for example.
class Name(models.Model):
""" """
...
0
votes
2answers
23 views
new row with empty spaces added in windows
I have the following code where am writing some data to a .csv file and reading it..data is being written as follows when the script is run on windows,there is a new row with empty spaces being ...
2
votes
2answers
16 views
Getting a grid of a matrix via logical indexing in Numpy
I'm trying to rewrite a function using numpy which is originally in MATLAB. There's a logical indexing part which is as follows in MATLAB:
X = reshape(1:16, 4, 4).';
idx = [true, false, false, true];
...
0
votes
3answers
24 views
Review: Built-In Functions
This is a two-parter: first, define a function, distance_from_zero, with one parameter (choose any parameter name you like).
Second, have that function do the following:
Check the type of the input ...
0
votes
0answers
3 views
Finding path for corpus in NLTK
I am using the Natural Language Toolkit for python to write a program. In it I am trying to load a corpus of my own files. To do that I am using code to the following effect:
from nltk.corpus import ...
0
votes
0answers
11 views
How can First request to certain site already contain 'Cookie' header?
I'm trying to scrape some site. But it seems to be protected somehow.
When I open the page in browser (all cookies deleted first), First request to the site already shows that session cookies are set ...
0
votes
0answers
14 views
Simple Flask app and Bad HTTP/0.9 request type over time
I wrote simple flask application like here: http://flask.pocoo.org/docs/quickstart/ It's really minimalistic, has only three pages and login form. And I run this application on my own computer. ...
0
votes
2answers
17 views
How to specify column names while reading an Excel file using Pandas?
I read an Excel Sheet into a pandas DataFrame this way:
import pandas as pd
xl = pd.ExcelFile("Path + filename")
df = xl.parse("Sheet1")
the first cell's value of each column is selected as the ...
0
votes
0answers
12 views
Python PIL: from form file to image
I want to save an image that is uploaded from a form. Not sure how to do this.
I get the file:
photo = request.FILES
and have tried various things along the lines of:
import cStringIO, PIL
from ...
0
votes
0answers
15 views
Read floats from file as numpy array without knowing the data size
I have this code which reads a Fortran unformatted data file and writes the ascii output to
a new file output.dat. I want to read this output.dat file into a numpy array. However, the fromfile ...
0
votes
2answers
19 views
shell script for getting csv with curl
I think this question is very simple, but I just started using shell scripts.
I have this so far:
#!/bin/bash
new_url=$(python get_url.py)
echo $new_url
curl -o mycsv_file.csv $new_url
And it is ...
-1
votes
0answers
34 views
How to execute two tasks simultaneously in python ?
I am very new to Python programming. What I am trying to do is simultaneously play remote video in Python while capturing video from a camera.
I have tried with openCV module but frames from video ...
0
votes
2answers
34 views
Python: Trying to create the equivalent of and(or(value,value,value))
Okay so here's my dilemma:
I'm working on a FAQ bot for a subreddit. I'm having trouble with boolean logic and could use a pair of more experienced eyes (this is my first adventure in Python). Right ...
0
votes
0answers
8 views
Gimp: python script not showing in menu
I followed this tutorial and this is what I have come up so far:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#http://www.ibm.com/developerworks/library/os-autogimp/
from gimpfu import*
def ...
0
votes
1answer
13 views
Serial communication between two Linux running laptops using Python
I'm trying to send and receive messages between two Linux running laptops via serial communication using Python. The receiver system must see the message "waiting for the message" until it receives ...
0
votes
3answers
56 views
inserting a new entry into adjacency list
I have an adjacency list maintained between 2 sets of entities
dict1={'x1':[y1,y2],'x2':[y2,y3,y4]...}
dict2={'y1':[x1],'y2':[x1,x2],'y3':[x2]....}
Given a new entry coming in ,what is the ...
1
vote
2answers
40 views
How to generate an image in python pixel by pixel?
I'm having a go at writing an image generator for a graphical format that I created that uses 0 as a delimiter:
Here is an example.
An extract from a sample file:
...
2
votes
3answers
42 views
Tuple Subtract statement in Python
using python I am wanting to subtract 256 from a value in the list if a value is greater than 256, but i want the output to be in a tuple format, this is where i need help.
x = [85, 229, 162, 45, ...
0
votes
2answers
27 views
How to change timedelta into time duration in Python?
I have a timedelta time like this:
datetime.timedelta(0, 175, 941041)
I want to convert this into duration. For example:
1 second
2-59 seconds
1 minute
2minutes-59minutes
1 hour
1 hour 50 minutes
...
-1
votes
1answer
105 views
What is wrong with my code? The recruiter said it didn't meet their bar [on hold]
I applied for a job and they asked me to write a code with the following requirements:
Get a "toolbar offer" description from http..update.utorrent.com/installoffer.php?offer=conduit
Parse the ...
0
votes
1answer
24 views
Python — multiplication in GF(2)
This function is returning unusual values in the list g. It should return 32774, 65548, 1048768 but instead it's values are more like it's treating the entire binary like a big slinky and just moving ...
0
votes
3answers
34 views
printing only the last 8 entries in a .csv file
I have an input csv file as below,I want to print only the most recent 8 entries..can anyone provide inputs on how to do this?
INPUT:-
trend.csv
['2013-06-25 20:01', '10']
['2013-06-25 20:06', '9']
...
0
votes
1answer
23 views
how to add column name present in the list object into table
how to do like this
cursor.execute("create table" + config.table + config.cols)
all the config names are in different files and cols is a list object like this
cols = [
"name varchar(50)",
...
0
votes
1answer
20 views
scikit learn use multinomial naive bayes for a trigram classifier?
I have taken a look and try out the scikit-learn's tutorial on its Multinomial naive bayes classifier.
I want to use it to classify text documents, and the catch about the NB is that it treats its ...
1
vote
0answers
42 views
How to do nested loop to search the string in a file
I have 2 excel file having thousands of data.I want to take the row from file1 and search the entire file2 and output the repeated to file3.
file 1 file2 ...
0
votes
2answers
34 views
Python3: Read a .txt and print the title of that file and its path
I have about 100 files that I'm looking at. Is there a way to print the title of the files with code rather than doing it manually? Same with its path?
Thanks
0
votes
1answer
26 views
What are the differences between os.putenv(key, value) and os.environ[key]=value in python?
I need build a system environ variable, and I use os.putenv(key, value) to build one, then print os.getenv(key), the console outputs "None".
But the console outputs value(here is print os.getenv(key) ...
1
vote
1answer
17 views
Pandas DataFrame: transforming frame using unique values of a column
I have a pandas dataframe/csv of the form
date Country Type Val
2013-01-01 USA x 23
2013-01-01 USA y 13
2013-01-01 MX x 11
2013-01-01 MX ...
0
votes
0answers
13 views
Compile pygame with python 3.3
I'm trying to compile a Tetris type game using pygame in python 3.3. The program uses various folders and modules. I've tried using CX_FREEZE, so far it hasn't seemed to work. If someone would be able ...
0
votes
0answers
12 views
Selenium: do javascript actions reflect in driver.page_source?
If I click on a button that executes some javascript that updates the page (e.g. adds some html somewhere), will this be reflected in driver.page_source?
I tried it (clicked on a button that executed ...
1
vote
3answers
53 views
python list compare and replace
i have 2 lists. First list, listA is a list of lists.
listA=[[1,2,5,3],[3,1,5],[7,9,2]]
Second list, listB is a list that i am gonna compare against other lists in listA
...
0
votes
0answers
8 views
Correlation structure corAR1() “not defined” in rpy2 generalised least squares model gls
I'm using the rpy2 module in python to calculate regressions between two timeseries (ts1 and ts2). The residuals are autocorrelated, so I need to use the gls model rather than lm. I should be able to ...
0
votes
2answers
20 views
Python - connecting sockets, client/server agnostic
I want 2 processes to communicate on a given port without either one having a defined client or server role. Either of the processes may be running alone. Either may stop and restart at any time, in ...
1
vote
0answers
16 views
Appengine app is 404ing on /_ah/warmup out of nowhere; spinning up useless instances and causing a lot of cost
I noticed that the App Engine mailing list suggested I direct my problems to Stack Overflow, so I am filing my bug report here.
Starting at 2013-06-25 23:05:40.756 US/Pacific my app behavior ...
0
votes
1answer
21 views
Python 3.3: Hex and Dec converting
I'm able to convert Hex data to Decimal with:
file = open("my_text.txt", "r+")
data = input("Type Hex: ")
hex = int(data, 16)
str(hex)
print(str(hex))
file.write(str(hex))
file.close()
input("close: ...
0
votes
1answer
22 views
Problems with importing data into code
So I'm trying to make a code that will import data from a text file and graph it with matplotlib here what i have so far:
import matplotlib.pyplot as plt
x = []
y = []
readFile = open ...
1
vote
1answer
11 views
Parse table with BeautifulSoup Python
If I want to read entries in a table which follows the format:
<table cellspacing="0" cellpadding="4">
stuff
</table>
I'm using this as my current method:
pg = ...
1
vote
3answers
38 views
Python's type() function and its 'if' related problems
So I have the following code:
user_input = raw_input("Enter an integer, string or float:")
input_type = type(user_input)
if input_type == "str":
print "Your string was %s." % user_input
elif ...
1
vote
1answer
12 views
convert selected datetime to date in sqlalchemy
I have a database of test records with one column 'test_time' defined as datetime. I want to query how many distinct dates there are as I want to dump test results to csv according to dates. I now ...
0
votes
2answers
20 views
Python __init__ return failure to create
First off, I know that the __init__() function of a class in Python cannot return a value, so sadly this option is unavailable.
Due to the structure of my code, it makes sense to have data ...
1
vote
0answers
11 views
How to find the angle between North and horizon for given altaz coords using pyephem?
I've got a set of many astrophotos taken with the camera on a tripod. Used a bubble level to make sure that the long side of the frame is parallel to the horizon, and I know the alt/az (and ...
0
votes
1answer
24 views
matplotlib- code compiles but does not display graph
I have been struggling a lot with matplotlib. Some solutions have already been given for my problem here - matplotlib does not show my drawings although I call pyplot.show()
I have tried all ...
1
vote
1answer
28 views
Finding Vectors with 2 points
Im helping my friend out with a pygame but we are stuck
so were are trying to get the direction of a projectile but we cant find out how
for example:
[1,1] will go SE
[1,-1] will go NE
[-1,-1] ...