text stringlengths 226 34.5k |
|---|
Python get JSON object by index
Question: I have a JSON file that looks something like this:
{ data:
{ 123:
{ 212:
{ 343:
In python I load the JSON using json.loads(r.text). The strings inside the
data object are not guaranteed to be those but can be any num... |
PyOpenCL | Fail to launch a Kernel
Question: When I'm using PyOpenCL to run the kernel "SIMPLE_JOIN" it fails.
**HEADER OF THE KERNEL IN .CL FILE**
void SIMPLE_JOIN(__global const int* a, int a_col, __global const int* a_valuesPic,
__global const int* b, int b_col, __global const in... |
Why isn't the file lock released on close() if I launch a process while the file is locked?
Question: If I open a file, acquire a lock, then close the file:
import fcntl
file = open("some_file", "w")
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
file.close()
The file lock is released immedi... |
Python Dataframe new column based on conditional statement
Question: I have a dataframe consisting of a few columns of custom calculations for a
trading strategy. I want to add a new column called 'Signals' to this
dataframe, consisting of 0s and 1s (long only strategy). The signals will be
generated on the following c... |
how to make a variable take a html link without formatting in python?
Question: I need to take a url input and use it in subprocess.call().how is it possible?
I wanted to write a loop so that it keeps on downloading images until required
by doing this
for i in range(1,tot):
subprocess.call(["wget... |
Splitting an integer in python
Question: I'm new to python and trying to build a 10k running calculator from the
exercises in "Think Python"
what I'm trying to do is break down the input time ie:43.12 into 2 separate
numbers ... then perform (43x60)- which gives the seconds and then add the
remaining seconds +12 .. to... |
Python numpy ValueError: setting an array element with a sequence
Question: hi im trying to rotate an image 90 degree's but i keeep getting this error
"ValueError: setting an array element with a sequence" and im not sure whats
the problem.
when i try and run the function with an array it works, but when i try it with... |
cython build via setup.py does wrong thing (putting all .so files in extra src dir)
Question: I'm trying to convert from using pyximport to building via distutils, and I'm
being stumped by the weird choices its making on where to put the .so files.
So, I decided to build the tutorial out of the cython doc, only to find... |
iPython notebook on Mac OSX Yosemite: no module named jinja2, even if it's installed
Question: I am trying to run iPython notebook on OSX Yosemite. I have installed
everything via
pip install ipython[all]
and I see
mattia:~ mattiaspeziali$ pip freeze
backports.ssl-match-hostname=... |
Tweepy to access Twitter streaming API using python 3.4
Question: I'm unable to use tweepy to access Twitter streaming API using the following
example code using python 3.4. This code was running using python 2.4. What is
wrong ?
from tweepy import Stream
from tweepy import OAuthHandler
from twee... |
Python Mathematical Formula computation
Question: I'm writing a python program to calculate formula. I read in a list of strings
which hold the values, operators and functions.
The code shown below receives a string for example:
['not', 1.0, 2.0, '=', 'power', 2.0, 3.0, '+']
The code above is a po... |
Change string in file in python
Question: I have a problem changing a file in python. I need to change a string. The
file is not a text file but can be edited with a text editor.
Here is my code:
with open(esp,"r") as f:
content=f.readlines()
with open(esp_ca... |
Incorporate an icon to python .exe using py2exe
Question: I have this **setup.py** script for incorporating icon for my .exe file, but
the icon isnt appearing after the setup. the icon is 361 KB in size.
from distutils.core import setup
import py2exe
setup(
console = [
{
... |
How to recompile Python2.7 with 4-byte unicode enabled?
Question: I have tried `./configure --enable-unicode` and `./configure --enable-
unicode=ucs4` but the command `import sys; print sys.maxunicode` is still
65535.
How should I fix this and compile Python with 4-byte unicode enabled?
Answer: From the output of
... |
Python 2.7.6 dictionaries
Question: I'm having a bit of trouble with Python 2.7.6, getting information from a
dictionary and doing something useful with it. I have attached my entire code
below, as I'm not sure what specifically is wrong, it might not be something
I'm expecting.
I am trying to generate some test data;... |
referenced before assignment error
Question: i have the following code to create a pygame of snake ( very basic ), to
increase my snakes length i added a statement saying `snakeLength += 1 in line
142` it comes up with an error saying
Traceback (most recent call last):
File "C:/Python27/sjewgou... |
Why is serial.tools available within os.system but not without?
Question: I am working up to getting Python to read from a microcontroller which sends a
short status string every second over COM port.
As the μC (better not say which) has a fairly dodgy serial over USB
implementation, I need to regularly check if the C... |
Number of levels (depth) of index and columns in a Pandas DataFrame
Question: Python Pandas `DataFrame` can have hierarchical index (`MultiIndex`) or
hierarchical columns.
I'm looking for a way to know number of levels (depth) of index and columns.
len(df.index.levels)
seems to only work with Mult... |
Creating a comma delimited list in python
Question: I have a need for a list of numbers, they need to be hex numbers. The list
needs to be separated by commas (or anything really, just as long as they are
separate) so that I can use the list as input to another program.
I want to start at 0xffffffffff and go to 0xffff... |
BMI calculator always return 0. (Python)
Question: i was just writing this very simple script to calculate bmi in kg and cm. But
it always prints 0. Any ideas why?
code:
weight = int(raw_input("Weight in kg: "))
length = int(raw_input("Length in cm: "))
def bmi():
bmi = (weight) / (... |
Trouble with converting regex to python
Question: I have this regex
[^\\]["'&<>]
in order to match some unescaped characters. However trying to convert it into
a python string is giving me grief. I've tried
r'[^\\][\"\'&<>]'
but I end up with this error.
raise ... |
AttributeError when using validatecommand on a Spinbox
Question: I am doing a test writing a script that validate a spinbox to implement it on
a larger system, but I am struggling with python because it is warning that
there is no spinbox attribute on my `Window` class. Check my code:
from Tkinter import... |
Python - find out how much of an image is black
Question: I am downloading satellite pictures like this

Since some images are mostly black, like this one, I don't want to save it.
How can I use python to ch... |
plus/minus operator for python ±
Question: I am looking for a way to do a plus/minus operation in python 2 or 3. I do not
know the command or operator, and I cannot find a command or operator to do
this.
Am I missing something?
Answer: Another possibility: [uncertainties](http://pythonhosted.org/uncertainties/)
is a... |
Python: How does one use variables defined in main(), and/or use a lists with two classes without errors?
Question: Objective: I have tried using variables in main() and creating a random list
of messages in my code, which have partially worked, but are still coming up
with multiple errors that I don't know how to fix.... |
Django 1.7 python manage.py makemigrations polls SyntaxError
Question: I am following the official Django documentation and trying to make the polls
app. But when I run the command python manage.py makemigrations polls I get
the console error.
anupam@Anupam-HP:~/Python/django/mysite$ python manage.py mak... |
Python program is outputting a strange value to my 16x2 Character LCD
Question: I've built a small program with a Tkinter GUI to let me enter 2 lines of text
and make it display it on the character screen. It all works pretty neatly
until I press apply text, because then I just seem to get a weird value on
both lines o... |
Django - Dictionary update sequence element #0 has length 1; 2 is required
Question: After i created new URLs, i got this error
**ValueError at /blog/ dictionary update sequence element #0 has length 1; 2
is required**
Traceback
Request Method: GET
Request URL: http://127.0.0.1:8000/blog/
... |
python: sending a mail, fails when inside a "with" block
Question: I am wondering why this code
test = smtplib.SMTP('smtp.gmail.com', 587)
test.ehlo()
test.starttls()
test.ehlo()
test.login('address','passw')
test.sendmail(sender, recipients, composed)
test.close()
works, bu... |
How do I create a list, then len() it, then make an entry for every 'section' in that list in Python?
Question: So, I'm working on a project, which requires me to find how many 'objects' are
in a list, which I accomplished via `len()`, however, now I need to make it
where there is a choice (in easygui's `choicebox()`) ... |
Python Not Removing Char From String
Question: Iv tried multiple times and ways for removing the extra punctuation from the
string.
import string
class NLP:
def __init__(self,sentence):
self.sentence = sentence.lower()
self.tokenList = []
... |
Django Migrate issue
Question: A django model created as follows
from django.db import models
class Vender(models.Model):
id =models.IntegerField(primary_key=True)
name = models.CharField(max_length=30)
class Meta:
db_table="vendor"
class car(models.... |
Web crawler to extract from list elements
Question: I am trying to extract from `<li>` tags the dates and store them in an Excel
file.
<li>January 13, 1991: At least 40 people <a href ="......."> </a> </li>
**Code:**
import urllib2
import os
from datetime import datetime
... |
find all possible combinations of letters in a string in python
Question: I have a string in python, I need to find all the possible ways any substring
of that string (including itself) could be selected. A substring (for my
purposes) does not have to be contiguous, in the original string -- it could
have gaps.
Eg "f... |
Python filecmp.cmp('old_index.html', 'new_index.html') in if event
Question: how can I make this python command in a if question:
import filecmp
filecmp.cmp('old_index.html', 'new_index.html')
the answer from these command is True or False. So that I can execute
something when the files are the... |
Python: Convert xlrd sheet to numpy matrix (ndarray)
Question: What is the conversion syntax to convert a successfully loaded xlrd excel
sheet to a numpy matrix (that represents that sheet)?
Right now I'm trying to take each row of the spreadsheet and add it to the
numpy matrix. I can't figure out the syntax for conve... |
arduino turning on/off led using pySerial
Question: I am trying to communicate between arduino and pySerial but the serial monitor
is giving me back weird characters so the arduino is not turning on/off led
like it should. Thanks in advance.
Arduino code
int ledpin = 13;
int state; // 0 = le... |
Python time delay
Question: Alright, I want to know how to delay a portion of a program without pausing
the entire program. I'm not necessarily good at python so if you could give me
a relatively simple answer if possible, that would be great.
I want to have a turtle draw a circle on screen every time this function is... |
Memory consumption of python ESL
Question: I have written a ESL server, which controls call flow on FreeSWITCH server.
The problem is that after the connection closes, the memory consumption does
not decrease to normal. After some hundred connections are made to the server,
its memory consumption goes to GBs and it has... |
Python SyntaxError: invalid syntax elif statement
Question: So I am pretty new to python, I am familiar with Java, C and Ruby.
I tried compiling a script for Kali to fix the RFkill issue for wifi devices
since Kali does not have an RFKill.
#!/usr/bin/python
# replacement for rfkill util, which is mi... |
How to use python script to automate software installation
Question: I am new to Python. I want to automate the software installation process. The
scenario is as follow
> Run the installation file. On first screen it has two buttons next, cancel.
> On click of next it goes to next screen having two buttons, next, ca... |
Checking for particular style using python-docx
Question:
from docx import *
document = Document('ABC.docx')
for paragraph in document.paragraphs:
for run in paragraph.runs:
if run.style == 'Strong':
print run.text
This is the code I am using to open a docx file and to check if... |
Trac - Problems upgrading from 0.12.5 to 1.0.1
Question: I've been trying to upgrade our trac environment from 0.12.5 to 1.0.1 on
debian squeeze. I updated it using wheezy backports.
After I installed the new version using apt-get I ran the following:
trac-admin /var/lib/trac upgrade
trac-admin /var... |
Lock process until subprocess reaches a certain point
Question: I am running multiple subprocesses in parallel, but I need to lock each
process until the subprocess gives an output (via print function). The
subprocesses are running a python script that has been packaged to an
executable.
The code looks like this:
... |
How to make Menu.add_command() work in tkinter on the Mac?
Question: If I create a tkinter menu on OS X and try to add a menu button to it with
`add_comand()`, nothing shows up in the menu.
If the code below is run on Ubuntu, I get a menubar with two commands labeled
"Red" and "Blue" that change the background color o... |
How to create custom elements styled like material design?
Question: I love material design. I love jquery, web forms and elements. It have many
styles. But when i use PyQt i have default button and checkbox...
I love something like this: 
Can I chang... |
Can you specify a command to run after you embed into IPython?
Question: When calling IPython.embed() is it possible to give it a command or magic
function to run after embeding happens.
I would like to run something like this
import IPython
IPython.embed(command='%pylab qt4')
My current worka... |
Appending CSV files, matching unordered columns
Question: Problem: matching columns while appending CSV files
I have 50 .csv files where each column is a word, each row is a time of day
and each file holds all words for one day. They look like this:
Date Time Aword Bword Cword Dword
Date1 t1 0 ... |
How to set the background color of a ttk.Combobox
Question: I have a problem to set background color for Combobox using tkinter ttk with
'vista' theme (I'm using Python 3). I've tried code from here [ttk.Combobox
glitch when state is read-only and out of
focus](http://stackoverflow.com/questions/18610519/ttk-combobox-g... |
pythonic way to customize classes
Question: I am trying to figure out a clean way to use inheritance for custom classes. I
have the following directory structure.
inheritTest.py
Level1
__init__.py
t_Generic.py
Level2
__init__.py
t_Custom.py
**Goal:** I want a... |
How to get the content of a tkinter Text object
Question: I'm trying to use `tkinter.Text` to create a text area in _Python_. With that,
I want to get all the input they put into that text area and display it in the
Entry field above it. It gives an error saying it needs two arguments.
from Tkinter impor... |
Python pandas idxmax for multiple indexes in a dataframe
Question: I have a series that looks like this:
delivery
2007-04-26 706 23
2007-04-27 705 10
706 1089
708 83
710 13
... |
pip install python-novaclient is failing due to netifaces.c
Question: I'm trying to install OpenStack python novaclient using pip install python-
novaclient This task fails: netifaces.c:185:6 #error You need to add code for
your platform
I have no idea what code it wants. Does anyone understand this?
Answer: This ha... |
Creating a normalized histogram
Question: I am working on a research paper published on Hair recognition from human
face, in the research paper I am stuck at the following part:
> We downsample each of Y,Cb and Cr channels into 64 levels.Then we can
> construct a three-dimensional color histogram in which each dimensi... |
No module named '_sqlite3' error
Question: Python 2.6 and Django 1.6 was installed on the server (Suse). I installed
Python 3.4 and Django 1.7.
I can run
> django-admin.py startproject hi
Once I run any command related to manage.py like
> python manage.py syncdb
I will get this error
File "/usr/loc... |
Can't start pyspark (DSE 4.6)
Question: I've installed Datastax enterprise 4.6 in a cluster and I can't figure out why
the pyspark throw this error. The scala interface works nicely but the python
doesn't. Does anyone have a clue how to fix this?
Python 2.6.6 Centos 6.5
Cheers
bash-4.1$ dse pyspark --m... |
getting p2p_device_address from wpa_cli status
Question: Is there any way to get different information from the command "wpa_cli
status", e.g., p2p_device_address, ssid etc. separately, ?
What i am currently using is by calling wpa_cli from a python script:
import subprocess
cmd = "wpa_cli -i wlan... |
What DLL's I have to load for Gobject in cx_freeze
Question: I have a little problem with cx_freeze and hoping one of you can help me. I
have searched trough this wonderfull forum but I can't find the answer. I have
used cx_freeze before with python 3.3 and ktinker and that worked flawless.
Now I made a little tool wit... |
Python can't import my package
Question: I have the following directory structure:
myapp
├── a
│ ├── amodule.py
│ └── __init__.py
├── b
│ ├── bmodule.py
│ ├── __init__.py
└── __init__.py
In `a/amodule.py` I have this snippet which calls a simple function in
`b/bm... |
Taking form button input
Question: So i'm using Flask to build a basic control panel for an IR Automation in my
home. However I'm failing to understand how to take a response from the form
in my HTML. So I basically have a button that changes the state of a device
when pressed. The issue I'm having is taking that respo... |
How can I install pip-accel on Ubuntu 14.10?
Question: I would like to use [pip-accel](https://pypi.python.org/pypi/pip-accel) to
speed up compilation-heavy installations to virtual environments (e.g.
matplotlib, NumPy). It isn't in the 14.10 Ubuntu repos so I must install it
manually. However, my installation attempt ... |
Why does this use of Python's multiprocessing module not seem to process sequentially?
Question: I'm trying to learn to use Python's Multiprocessing module. As a first test, I
thought I would run four 15 second processes at the same time. I wrote this
module, which I called "multiPtest.py"::
import time
... |
Install PyX under python 2.7.6
Question: I am trying to install PyX in yosemite under python 2.7.6
Initially, the setup looks ok
python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /Users/alkaloge/Library/... |
random color text generat
Question: I am trying to make a program in python that will accept an argument of text
input, then randomly change each letter to be a different color
This is what I have:
color = ['red' , 'blue', 'green' , 'purple' , 'yellow' , 'pink' , '#f60' , 'black' , 'white'];
I wan... |
Why is it considered 'powerful' to pass a function as a parameter?
Question: I am reading through _A Concise Introduction to Programming in Python_ by Mark
J.Johnson and I stumbled upon a piece of code that uses darts to estimate the
area under the graph. The code is working perfectly fine but I am getting
confused as ... |
How to make a random text python
Question: I need help to output a random text. I've been given a text with 25k words,
from this `text_file` I've been calculating the probability for the single
letters, and the single words to see which letters/words have been used most.
Now I need to make a other text with 500 letter... |
Serialize python objects along with class definition
Question: I'm trying to understand how to make RPC calls using Python. I have a stupid
server that defines a class and exposes a method that create instances of that
class:
# server.py
class Greeter(object):
def __init__(self, name):
... |
Sphinx autodoc TypeError: 'type' object is not iterable
Question: When trying to build documentation (any type: html, man pages, latexpdf...)
sphinx fails while trying to autodoc a subdirectory of a project. I've tried
many different approaches to try to narrow down what the problem is but I
can't seem to find the culp... |
Permission denied error near end of python module (igraph) install
Question: I'm trying to install igraph 0.7. It's on a cluster, so it must be done in my
home directory. I'm using `pip` and pointing it to a local archive. The
process works well, until then end, when I get a permission denied error.
pequ... |
Python: Creating a new dictionary while switching keys and values
Question: If I am given a dictionary that has student names as keys and the subjects
they're proficient in as a set of strings, how would I go about creating a new
dictionary that would have the subjects as keys and everybody who's proficient
in those su... |
Python subtract first element from each respective row of matrix
Question: I want to subtract the first value of a row from the rest of the elements of
that row, so for
import numpy as np
z = np.array([[1,2,3,4],[4,5,6,7],[7,8,9,9]])
for n in range(0,3):
znew = z[n,:]-z[n,0]
... |
Installing psycopg2 in virtual env on RHEL fails
Question: I have been on this for days now. Everytime I attempt to install psycopg2 into
a virtual environment on my RHEL VPS it fails with the following error. Anyone
with a clue should please help out. Thanks.
(pyenv)[root@10 pyenv]# pip install psycopg2... |
I am using python 3.2 and pip 6.0.6, when I run scrapy startproject tutorial I get the following error
Question: When I run the command scrapy startproject tutorial, i get lots of lines of
errors and at the end AttributeError:'NoneType'object has no attribute
'startswith'. In the previous lines it is pointing to variou... |
python running test: ImproperlyConfigured
Question: I'm trying to run some testes for django (1.7) project.
have created a `test_models.py` directory `/tests/` under project directory.
On running test
>> python tests/test_models.py -v
Error:
django.core.exceptions.ImproperlyConfigu... |
Python flask cannot open an xml file
Question: I try to implement a server-side multilanguage service on my website. This is
the structure on the folders:
data
--locale
static
--css
--images
--js
templates
--index.html
--page1.html
...
main.py
I use Crowdin t... |
How would I write this program in Python 3.3.2?
Question: This is Guess_The_Number program I wrote in Python:
import random
print("Hello! Today we are going to play Guess The Number!")
number = int(input("Guess a number between 0 and 5"))
random_number = random.randint(0, 5)
if number == ... |
What is wrong here with Choice 2?
Question: I have been working on this code (in python) to print a CSV file, sorted. The
first choice works fine and sorts it Alphabetically. However the Choice 2
section is supposed to sort the csv file to the highest score. The text/csv
file (
name, score, out of:
... |
Biopython SeqIO: how to write modified SeqRecord header
Question: I thought I'd try using Biopython to salvage some trivially corrupted fastq
files provided by a collaborator. I simply need to modify header lines
(starting with `@`) which contain a certain substring. However, the new fastq
files created by the followin... |
Tkinter AttributeError: object has no attribute 'tk'
Question: I've looked around a bit, but I can't find an answer to my error. Here is the
code:
import tkinter as tk
root=tk.Tk()
class Page(tk.Frame):
'''Enables switching between pages of a window.'''
def __init__(self... |
ConvergenceWarning: Maximum Likelihood slows kernel-run-time?
Question: I use the very nicht code-object `arma_order_select_ic` in order to finde the
lowest Information Criterion for chor choosing p- and q values.
I am not sure if i do it right or if the code just stumbles upon some
mistakes...
In:
y =... |
Python/Matplotlib -> to_rgba: Invalid rgba arg
Question: I'm trying to plot contours and have previously used a RGB tuple to specify
the color (only one for all contours) - however, now I get a ValueError from
to_rgba:
ValueError: to_rgba: Invalid rgba arg "1"
to_rgb: Invalid rgb arg "1"
cannot c... |
XML Not Parsing in Python 2.7 with ElementTree
Question: I have the following XML file which I get from REST API
>
> <?xml version="1.0" encoding="utf-8"?>
> <boxes>
> <home id="1" name="productname"/>
> <server>111.111.111.111</server>
> <approved>yes</approved>
> <creation>2007 handma... |
Urllib2 using Tor and socks in python
Question: I'm trying to crawl websites in Python using tor. I tried below code, which
gives the IP used by tor, trying this code for 2-3 times gives me different
IP's from different countries. I want IP's from specific country **eg India**.
Can we do it using tor and socks?
... |
Trying to convert to datetime
Question: I am using datetime to convert a time string. I used the
[reference](https://docs.python.org/2/library/time.html#time.strptime) for the
specifying the format. How should I have coded the format?
In [19]:import datetime
In [20]: d
Out[20]: 'Oct. 30, 201... |
How to correctly test RGB values using images(OpenCV & Python)?
Question: I'm currently working on a project which uses color detection (OpenCV). I'm
very new to Python and OpenCV so I'm not getting it work exactly as I want it
to.
I have a class ColourDetection(any suggestions for fine tuning the HSV
values?) which c... |
Connection to MySql server fails - Python
Question: I'm trying to connect to mySql database using Python. The database is situated
on free webhosting server webzdarma.cz.
I use `mysql.connector.connect` and all of my arguments are correct in my
opinion. The information about connecting to the database are:
... |
os.rename() error no such file or folder exists
Question: I have been trying to create a python script that logs my data into a .dat
file called 'log.dat' and every minute, rename log.dat to something else and
just start writing the incoming log data to a new, empty log.dat file.
But however my os.rename line is creat... |
Jython inside IDE ok, outside IDE, "no os specific module found"?
Question: I already had the Jython interpreter working. But when changing from java
1.7u45 to java 8, it only runs inside the IDE.
My project uses Jython2.5.3. All standard python modules are packaged into a
zip file and put on the java classpath.
Now ... |
nosetests framework: how to pass environment variables to my tests?
Question: I have a test suite that gets executed as a part of a larger build framework,
written in Python. Some of the tests require parameters, which I want to pass
using environment variables.
Apparently the nosetests runner has an `env` parameter, ... |
python-requests - user-agent is being overriden
Question: I have
logindata = {
'username': 'me',
'password': 'blbla'
}
payload = {'from':'me', 'lang':'en', 'url':csv_url}
headers = {
'User-Agent': 'Mozilla/5.0'
}
api_url = 'h... |
Python regex to parse semi-fixed width file
Question: I have a data file that is essentially a fixed-width text file. There are a
variable number of spaces and positioning in the text. I'm trying to parse the
file into a list with python and can't figure out the appropriate regex (of
course am open to non-regex options... |
Installing Orange into a virtualenv
Question: Linux Mint 17.1 with native Python 2.7.6.
All pre-reqs listed in the INSTALL.txt: python-numpy libqt4-opengl-dev
libqt4-dev cmake qt4-qmake python-sip-dev python-qt4 python-qt4-dev python-
qwt5-qt4 python-sip graphviz python-networkx python-imaging python-qt4-gl
build-esse... |
Trouble using date from pyodbc query
Question: I am working with an Access 2003 database using python 2.7 connecting with
pyodbc. Windows 7
I am having trouble making sense of a date query.
In the trivial example below, the first query collects the user's date of
birth 'dob' which in the database is a datetime.dateti... |
Converting an unknown data structure to a known data structure in Python
Question: I recently used an API to pull in some data from a platform I use.
But the problem is, the data that I pulled, is not a recognized data
structure.
It's almost a list of dictionaries, with some extra stuff.
I need to know how can I con... |
How can I start to write Unit test in web Scrapy using python?
Question:
class AljazeeraSpider(XMLFeedSpider):
name = "aljazeera"
allowed_domains = ["aljazeera.com"]
start_urls = [
'http://www.aljazeera.com/',
]
def parse(self, response):
hxs = H... |
Multiple requests using urllib2.urlopen() at the same time
Question: My question is this; Is it possible to request two different URLs at the same
time?
What I'm trying to do, is use a Python script to call requests from two
different URLs at the same time. Making two PHP scripts run simultaneously (on
different serve... |
Compare date with current date in python
Question: How do I compare a datetime object of this format
"Thu, 15 Jan 2015 06:35:37 GMT" with the current time ?
Answer: The easiest way is with the `dateutil` package. First install `dateutil` and
then:
from dateutil.parser import parse
parsed_time = pa... |
reading a file, taking file line content, then using content as parameters for class method definitions Python
Question: What I am trying to do here is read a line of a file. If the content in the
file meets the correct criteria execute one of the definitions in my class.
The thing is I have no clue on what kind of cod... |
Python Matplotlib: black squares when saving eps of plot of masked array, why?
Question: When I run the following code:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x_data = np.random.randn(10000)
y_data = np.random.randn(10000)
hist, xbins, ybins = np.his... |
Django Template Does Not Exist
Question: I know this has been covered already but none of the solutions have worked for
me. I have a basic django project and it cannot find the template. Here is my
views.py:
now = datetime.datetime.now()
t = get_template('index.html')
html = t.render(Context({'cu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.