text stringlengths 226 34.5k |
|---|
Network Pinging with Python
Question: Is there a way i can ping requests of a particular website for a particular
no. of times using Python and also is there a way through which i can decide
the no . of packets of data to be send in each request ?
Answer: You can use the os module for this.
5 is the count www.exampl... |
Guess the number game optimization (user creates number, computer guesses)
Question: I am very new to programming so I decided to start with Python about 4 or 5
days ago. I came across a challenge that asked for me to create a "Guess the
number" game. After completion, the "hard challenge" was to create a guess the
num... |
How can a print elements in a list randomly in python?
Question: I've got a list which I want to print in random order. Here is the code I've
written so far:
import random
words=["python","java","constant","immutable"]
for i in words:
print(i, end=" ")
input("") #stops window closing
... |
Continuous loop using threading
Question: I am somewhat new to python. I have been trying to find the answer to this
coding question for some time. I have a function set up to run on a threading
timer. This allows it to execute every second while my other code is running.
I would like this function to simply execute co... |
python numpy and memory efficiency (pass by reference vs. value)
Question: I've recently been using python more and more in place of c/c++ because of it
cuts my coding time by a factor of a few. At the same time, when I'm
processing large amounts of data, the speed at which my python programs run
starts to become a lot... |
Python: Adding an entry?
Question: I'm trying to write a program that asks a user to enter a product name, the
price, and quantity. From there, all the info will be added to a table
(dictionary?) Also, an ID number must be assigned to all new items created.
I'm confused about the ID number segment.
items... |
ASCIIMathMl in ipython notebook
Question: Since ipython notebook renders math using the mathjax library. Mathjax
officially supports the asciimath syntax. But I'm unable to get it rendered
correctly in ipython notebook
from IPython.display import Math
Math(r'x^2 or a_(m n) or a_{m n} or (x+1)/y or sq... |
Python - Django - activate() returns None
Question: Okay, so I'm trying to create a log in with Django.
from views.py:
from django.shortcuts import *
from forms import UserRegistrationForm
from django.contrib.auth import authenticate, login
from django.core.mail import send_mail
from dja... |
python default argument syntax error
Question: I just wrote a small text class in python for a game written using pygame and
for some reason my default arguments aren't working. I tried looking at the
python documentation to see if that might give me an idea what I did wrong,
but I didn't fully get the language in the ... |
How to write to a new line every time in python?
Question: I'm just trying to append new tweets that come in to a new line in a file....
So far nothing i'm trying works on OS X Python.
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print status.t... |
Python Adding Headers to urlparse
Question: There doesn't appear to be a way to add headers to the urlparse command. This
essentially causes Python to use its default user agent, which is blocked by
several web pages. What I am trying to do is essentially do the equivalent of
this:
req = Request(INPUT_UR... |
Show native import attempts in python3
Question: I wrote a Python 3 extension module in C but cannot seem to get Python to
import it.
Is there any way to let Python print out which shared libraries (.so on Linux)
it tries to load and why it fails?
Sadly all the docs I read don't really help since none describes the n... |
crontab with sudo python script
Question: Alright, I've found something. Not sure how to tackle it. I've seen that this
is a common error that comes up in google. The error seems to have something
to do with the environment variables or something. Not sure how to handle
this:
This is the code and it's the part where s... |
What is the main use of the Python built-in 'compile'?
Question: When looking through the list of [Python built-
in](http://docs.python.org/2/library/functions.html#locals) functions, I
struggle with understanding the usefulness the method
[`compile`](http://docs.python.org/2/library/functions.html#compile). All of
the... |
Python NameError in script
Question: I am having issues with this multiprocess script I modeled it after the one I
found here <http://broadcast.oreilly.com/2009/04/pymotw-multiprocessing-
part-2.html>
class test_imports:#Test classes remove
def import_1(self, control_queue, thread_number):
... |
'Assertion Error' while trying to create a console screen using urwid
Question: code below creates a layout and displays some text in the layout. Next the
layout is displayed on the console screen using raw display module from urwid
library. (More info on my complete project can be gleaned from questions at
[widget adv... |
Pandas import error
Question: I tried installing pandas using `easy_install` and it claimed that it
successfully installed the pandas package in my Python Directory.
I switch to IDLE and try `import pandas` and it throws me the following error
-
` Traceback (most recent call last): File "<pyshell#0>", line 1, in <mod... |
Autorun python script from python
Question: I wrote a python script that downloads a random picture from
[APOD](http://apod.nasa.gov/apod/astropix.html). I want to be able to specify
the update frequency in python and have python automatically run the script.
So the program would look something like this:
... |
Problems on installing cvxopt
Question: I am trying to install cvxopt on windows, I use a 2.7 Python Enthought
distribution. I followed the instructions here,
<http://abel.ee.ucla.edu/cvxopt/install/>
The error I run into is the follows,
**./liblapack.a: could not read symbols: Archive has no index; run ranlib to
ad... |
Trouble installing Python package group (STSCI)
Question: I'm trying to install a set of packages called STSCI (Space Telescope Science
Institute). However, I get the following error, and I'm not sure how to fix
it:
error: command 'gcc' failed with exit status 1
Here's the full terminal log:
... |
Selenium (with python) how to modify an element css style
Question: I'm trying to change CSS style of an element (example: from `"visibility:
hidden;"` to `"visibility: visible;"`) using selenium `.execute_script`. (any
other method through selenium+python would be accepted gracefully).
my code:
driver ... |
Fitting data using UnivariateSpline in scipy python
Question: I have a experimental data to which I am trying to fit a curve using
UnivariateSpline function in scipy. The data looks like:
x y
13 2.404070
12 1.588134
11 1.760112
10 1.771360
09 1.860087
08 ... |
PyQt: RuntimeError: wrapped C/C++ object has been deleted
Question: If I run this code:
#!/usr/local/bin/ python3
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QMainWindow):
def __init__(self):
super().__init__... |
What's the right form of python interpreter?
Question: I just began to learn Python for not long and I tried to run a very simple
python CGI script.
The html code is
<form action='cgi-bin/hello_get.py' method = 'post'>
Name: <input type = 'text' name = 'name'> <br/>
<input type = 'submit' value=... |
Python Tkinter save canvas as image using PIL
Question: I have this code which lets the user draw on the canvas and save it as a
`jpeg` file.
As mentioned in [this post](http://stackoverflow.com/questions/9886274/how-
can-i-convert-canvas-content-to-an-image), I tried to draw in parallel on the
canvas and in memory us... |
Raspberry Pi + PocketSphinx
Question: I am attempting to develop a python application on Windows 8 using Eclipse
(Juno) IDE with PyDev plugin.
I have my environment set up, with interpreter. Able to run basics like
"hello, world!"
I would like to start working with CMUSphinx (Namely pocketsphinx &
sphinxbase) to do s... |
null value in JSON is not interpreted by python for openstack API
Question: I am using OpenStack's REST API for programmatic implementation of start or
stop server.
The link for API reference is <http://api.openstack.org/api-ref.html#ext-os-
server-start-stop> This requires a dictionary in python as follows:
... |
AttributeError: '_socketobject' object has no attribute 'bind'
Question: here is my code:
import sae
import socket, sys
host = ''
port = 5005
def app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(stat... |
Python: Playing a music in the background?
Question: I am currently making a game in Python. I am not using PyGame, just the
console (non-GUI) When you start the game, you will get the logo to the game,
and a lot of information about the "journey" you just started. There is a lot
of text, so while the text is scrolling... |
Listening on port being used
Question: Is there any way to listen to traffic on a specific port that another program
is currently using, through the python `socket` module? For example:
|--> my program
external request -> Host ->|--> intended program
I am not looking ... |
Downloaded webpage looks different than the original webpage
Question: I am thinking of downloading [cplusplus.com's C
library](http://www.cplusplus.com/reference/clibrary/) by using Python. I want
to download it completely and then convert it into a linked document such as
Python documentation. This is my initial atte... |
Speeding up Python Imports
Question: I have a large program that is structured using object oriented techniques,
and I have one main driver module that imports a bunch of other classes, which
they in turn import more python built-in modules or other classes. All
together I would say there is well over 250 `from x impor... |
Python list simultaneous update
Question: This seems to be a gotcha for me, I couldnt figure this out
>>> from collections import Counter
>>> tree = [Counter()]*3
>>> tree
[Counter(), Counter(), Counter()]
>>> tree[0][1]+=1
>>> tree
[Counter({1: 1}), Counter({1: 1}), Counter({1: 1... |
How do I import .pyx in python
Question: I have been working with a project that have .pyx files and When I run it on
Ninja Ide it's doesn't recognise them! How can I solve this? I have installed
cython but nothing! Thank you!
Answer: You need to add
[this](http://docs.cython.org/src/userguide/tutorial.html#pyximport... |
Python Memory Error when using random.sample()
Question: OK, so I have a problem that I really need help with.
My program reads values from a pdb file and stores those values in (array =
[]) I then take every combination of 4 from this arrangement of stored values
and store this in a list called maxcoorlist. Because t... |
Which module should contain logging.config.dictConfig(my_dictionary)? What about my_dictionary?
Question: This is all Python. I am still learning...
I have written two modules for my Python application: `Module1` and `Module2`.
I need to send my logging results to three different files. `Module1` sends to
`setup.log` ... |
how to parse through this xml?
Question: Suppose I have the following XML response from mediawiki api. I want to find
out the earliest date that the wiki topic was revised, which in this case is
2005-08-23. How do I parse through the xml to find that out. I'm using python
btw.
<?xml version="1.0"?>
... |
Python 3: Store the contents of a file into one big string
Question: Suppose I have a textfile with this content:
> Hello World My name is Sam
>
> I am 12 years old and a boy
>
> I like Pizza
And I wanted to store it into one big string, no newlines, no spaces or
anything so it would read like this:
> HelloWorldMyna... |
how to grab a web image which has a dynamic src ID in python
Question: it is not a static url but a address like xxx.xxx.com/xxx/run
the image is dynamically built based on daily status, so I can't grab it using
its URL
is it possible to stimulate a browser and get the whole page contains the
image? if then how?
tha... |
Python regex to match all words in {}
Question: I need regex in python to get all words that are in {} for example
a = 'add {new} sentence {with} this word'
Result with re.findall should be [new, with]
Thanks
Answer: Try this:
>>> import re
>>> a = 'add {new} sentence {with} t... |
Some crazy code and crazy data. Insert rows in mysql db (python)
Question: I'm trying to insert some data (stored in a list of tuples) to my local
database. The data is a little inconsistent - some timestamps are
`datetime.datetime` while some can be strings. But I don't think that's where
my problem is.
First of all,... |
How to de-activate command + Q key in pyqt application in Mac OSX?
Question: My PyQt application is closed when I press (command + q) keys in Mac OSX.
(i.e) My App receives close event similar to pressing (Alt +F4) keys in
windows
But How can I disable this type of closing event which is mac native close
keyboard sho... |
calling python script from another script
Question: i'm trying to get simple python script to call another script, just in order
to understand better how it's working. The 'main' code goes like this:
#!/usr/bin/python
import subprocess
subprocess.call('kvadrat.py')
and the script it calls -... |
Simple Python Battleship game
Question: I recently started learning python and decided to try and make my first
project. I'm trying to make a battleship game that randomly places two 3 block
long ships on a board. But it doesn't work quite right. I made a while loop
for ship #2 that's supposed to check and see if two s... |
can python-requests fetch url directly to file handle on disk like curl?
Question: curl has an option to directly save file and header data on disk:
curl_setopt($curl_obj, CURLOPT_WRITEHEADER, $header_handle);
curl_setopt($curl_obj, CURLOPT_FILE, $file_handle);
Is there same ability in python-r... |
compress level of python gzip module not working
Question: I was trying to write data into a compressed file using the python gzip
module. But the module does not seem to accept the level of compression
I followed the syntax specified in the official Python documentation on
[gzip](http://docs.python.org/2/library/gzip... |
Python: Kill (terminate) a process from command prompt using Python
Question: I am not very familiar with the computer software terminology (my apologies).
* I designed a GUI in Python that suppose to execute and/or terminate a script when an appropriate button (on the GUI) is pressed.
* When I press a "Start" but... |
Error while installing numpy in venv
Question: I am getting the following error while trying to install numpy in my venv. I
am running centos. which python points to the python in my venv directory
(venv)bash-3.2$ pip install numpy
Downloading/unpacking numpy
Running setup.py egg_in... |
Python; User Prompts; choose multiple files
Question: I would like to have my code bring up a window where you can select multiple
files within a folder and it assigns these filenames to elements of a list.
Currently, I can only select a single file at a time and it assigns the
filename to a single variable.
... |
How to use grid_forget to eliminate a specific ordering of buttons after they have been instantiated
Question: I am building the GUI for a boardgame for my software engineering class. I am
using the TKinter toolkit on Python 2.7 (windows). I am stuck right now
because I cant seem to find a way to ignore/forget a certai... |
PySide (1.1.2), cx_freeze, WinXP, Python 3.3: ImportError: DLL load failed
Question: I am trying to freeze Python 3.3 code that uses PySide libs using cx_freeze
and all of that on Windows XP (x86, SP2/3).
The `python setup.py build` runs successfully but the executable throws an
`ImportError`:
> ImportError: DLL load... |
how to call a python script inside another python script where both in the same directory?
Question: i have two script--script1.py and script2.py. Now i want to call script1.py
with in script2.py. algo will be like this--
IF condition: run script1.py #through command line ELSE : exit
Answer: In `script1.py` place th... |
Python and Beautiful soup - getting values and saving them in a text file
Question: I have sort of a XML file contains many records of relevant info that looks
like this
<file>
<record>
<type>a</type>
<number>2</number>
</record>
<record>
<type>b</type>
<number>9</number>... |
Pytests import fails after renaming project folder
Question: I've been struggling for a while with renaming a project folder of a Python
project. It was called Foo and I want it to rename it to Bar.
Foo/
/src
__init__.py
x.py
/test
__init__.py
... |
Flask-Admin extending templates
Question: I'm trying to extend my template with 'master.html' template of Flask-Admin
like this:
{% extends 'admin/master.html' %}
{% block body %}
Hello!!!
{% endblock %}
And I get error:
File "/usr/local/Cellar/python/2.7.3/lib/python... |
Typecast from Enthoughts traits to python native objects
Question: This seems to be a trivial task, still I do not find a solution.
When using the API of enthought.traits and working with their data types (e.g.
an integer Int), how can I typecast these values into native python objects
within the `HasTraits` class. Fo... |
How to execute raw SQL in SQLAlchemy-flask app
Question: How do you execute raw SQL in SQLAlchemy?
I have a python web app that runs on flask and interfaces to the database
through SQLAlchemy.
I need a way to run the raw SQL. The query involves multiple table joins along
with Inline views.
I've tried:
... |
RegExp Look for part but exclude If
Question: Right so RegExp is fairly new to me and its still puzzling me. Anyway I
managed to look for almost all the names I want to but now I have to look for
names that have specific part of world in it but exclude if there is another
one next to it.
So basically
Looks for `"Cat"... |
Python: Write dictionary to text file with ordered columns
Question: I have a dictionary D where:
D = {'foo':{'meow':1.23,'mix':2.34}, 'bar':{'meow':4.56, 'mix':None}, 'baz':{'meow':None,'mix':None}}
I wrote this code to write it to a text file:
def dict2txt(D, writefile, column1='-'... |
Porting Django Project to 1&1 Shared Hosting Web-server
Question: As a little background, I've been developing a django application for a 1&1
shared hosting website. When I tried to port the app to the web, I followed
the tutorial from here: <http://robhogg.me.uk/post/2>. The servers have Python
2.6, and I installed dj... |
Python UDP sendto() Ignoring Exception Block and Crashing
Question: I have been trying to get a basic chat application working for months in
python 2.7 (Using Geany IDE), and finally got a basic application working
using UDP. I can connect and broadcast communications, but if a client
connects and then closes later, th... |
Python and Beautiful soup, pick up All elements
Question: I'm getting a text article from one website with help of `python` and
`BeatifulSoup`. Now I have strange problem... I just wana print out the text
inside multiple `p` tags which are located in div with class `dr_article`. Now
the with code looking like this:
... |
Randomly Shuffle Keys and Values in Python DIctionary
Question: Is there a way to randomly shuffle what keys correspond to what values? I have
found random.sample but I was wondering if there was a more pythonic/faster
way of doing this.
Example: `a = {"one":1,"two":2,"three":3}`
Shuffled: `a_shuffled = {"one":2,"two... |
python ast module fails in pydev, succeeds in cmdline python
Question: This is weird. I run this program in PyDev
import ast
import sys
if __name__ == '__main__':
print sys.version
src = '''
print 3*4+5**2
'''
print dir(ast)
n = ast.parse(src)
... |
Python tkinter: Add button to menu bar
Question: I am trying to add a button to the far right of the menubar in my program. But
it isn't working for me. When I connect it to 'root' it appears below it; when
I attach it to 'menubar' or 'filemenu' it doesn't show up at all. Here is my
code:
from tkinter im... |
Calling DLL function in Python
Question: I am having trouble understanding on how to call dll functions from an
existing dll in Python.
OTAClient = cdll.LoadLibrary("C:\PATH\OTAClient.dll")
connect = OTAClientDLL.TDConnection()
* * *
exceptions.AttributeError: function 'TDConnecti... |
Python mysql: how do loop through table and regex-replacing field?
Question: I am trying to iterate a table, fetch the rows in which a field has a pattern,
then update the same row with a match group.
The following code runs without error, the two `print` lines before `update`
clause output correct values. I have foll... |
Having problems reproducing Matlab results in Python for a coupled system of ODE's
Question: I just started to use Python and have a bunch of code I want to transfer over
from Matlab. I started with a simple coupled diff eq and can't seem to figure
out what I'm doing wrong. It appears that the second diff eq is almost ... |
Flask-Admin Blueprint creation during Testing
Question: I'm having trouble with the creation of blueprints by Flask-Admin when I'm
testing my app.
This is my View class (using SQLAlchemy)
##
# All views that only admins are allowed to see should inherit from this class.
#
class AuthView(Mode... |
Organize data sent between client-server
Question: Pardon me if this has been addressed before, but how do I organize data
exchanged between client and server in python application (sockets)?
Let's say I have some elements I have to send - strings, tuples, dicts:
"hello world", (1, 2, 3), {"k": "v"}
... |
Function declaration in Python
Question: I am using Theano in Python. I have the following code:
outtmp = trainfunc(some_parameters)
I cannot find any declaration of the `trainfunc` function, while I can only
find a piece of code before the previous one as:
# Function compilation
... |
having multiples clasess in a module in a package in Python?
Question: I'm having trouble understanding packages in Python. In particular, is it
possible to have multiple classes in a module in a package in Python. For
example:
Kitchen/ Top-level package
__init__.py Initialize the ... |
Parsing an HTML table to a list in python
Question: So I have a few strings that I am pulling from IMDb's award pages:
<table><tr><td><big>Academy Awards, USA</big> </td> </tr> <tr> <th>Year</th><th>Result</th><th>Award</th><th>Category/Recipient(s)</th> </tr> <tr>... |
Will the first source in PYTHONPATH always be searched first?
Question: Will the sources in PYTHONPATH always be searched in the very same order as
they are listed? Or may the order of them change somewhere?
The specific case I'm wondering about is the view of PYTHONPATH before Python
is started and if that differs to... |
Managing a computation onlt with iterators Python
Question: I'm trying to do this very simple thing in a more pythonistic way which would
involve only one iterator:
>>>for i in xrange(10):
... for j in xrange(i+1,10):
... print i,j
0 1
0 2
0 3
0 4
0 5
0 6
0 7... |
Python: How can I access CSV like a matrix?
Question: I don't want to manually do the part of parsing the CSV and I will need to
access the cell in this fashion:
Cells (row, column) = X
or
X = Cells (row, column)
Does anyone know how to do that ?
Answer: numpy is nice but is ... |
Save Matplotlib Animation
Question: I am trying to make an Animation of a wave package and save it as a movie.
Everything except the saving is working. Can you please tell me what I am
doing wrong? When going into the line `ani.save('MovWave.mp4')` he tells me:
writer = writers.list()[0]
IndexErr... |
Is there any way to make this function look nicer?
Question: I need a logic that will extract a url from Apache log file: right now I did
this:
apache_log = {'@source': 'file://xxxxxxxxxxxxxxx//var/log/apache2/access.log', '@source_host': 'xxxxxxxxxxxxxxxxxxx', '@message': 'xxxxxxxxxxxxxxx xxxxxxxxxx - -... |
Django unittest and mocking the requests module
Question: I am new to Mock and am writing a unit test for this function:
# utils.py
import requests
def some_function(user):
payload = {'Email': user.email}
url = 'http://api.example.com'
response = requests.get(url,... |
How to specify which optional parameters to use in a method call?
Question: I want to use optional parameter 4, not optional parameter 3. How do i specify
that my 3rd parameter in my method call is supposed to use optional parameter
4 instead of default to 3?
python code:
from suds.client import Client
... |
recursively build hierarchical JSON tree in python
Question: I have a database of parent-child connections. The data look like the
following but could be presented in whichever way you want (dictionaries, list
of lists, JSON, etc).
links=(("Tom","Dick"),("Dick","Harry"),("Tom","Larry"),("Bob","Leroy"),("... |
multiple numpy version on Mac OS X
Question: I am running Mac OS X 10.8.4.
Python 2.7 is installed by installing command line tools in Xcode.
Apple is managing a version of numpy (1.6.1) located at
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
I use
... |
In Django, is it possible to define a dynamically calculated setting based in another?
Question: (Maybe this question is more about Python but Django is the context, so here
it goes)
Suppose you need a setting `FOO` whose value depends on the value of setting
`BAR` (simplest case is make `CELERY_RESULT_BACKEND` equal ... |
Python setuptools: How can I list a private repository under install_requires?
Question: I am creating a `setup.py` file for a project which depends on private GitHub
repositories. The relevant parts of the file look like this:
from setuptools import setup
setup(name='my_project',
...,
... |
python import names file and sort alphabetically
Question: I can't figure out why my simple names script will not work. It appears to bug
out on the while loop. I might be calling it wrongly, but I figured I might
try to get an answer here while I continue researching.
#!/usr/bin/python
#open th... |
swig numpy multiple matrix and array inputs
Question: I'm trying interface a small C function I made into python using SWIG and the
Numpy typemaps
This function is defined as follows
void nw(int* D, int Dx, int Dy, int* mat, int mx, int my, char *xstr, int xL,char *ystr, int yL);
And my interface ... |
Python Request for Post in Secure website.
Question: I am still learning python and this is my first go at accessing websites and
scraping certain information for myself. I am trying to get my head around the
language. So any input is welcome.
The data below is what I am seeing from the page source. I have to visit a
... |
nameerror:name 'array' is not defined
Question: I copy-pasted this program in pyscripter 2.7. I downloaded numpy and scipy for
python 2.7 too.
import numpy as np
from scipy import linalg
A = np.array([[1,2],[3,4]])
array([[1, 2],
[3, 4]])
linalg.inv(A)
array([[-2. , 1. ],
... |
Trying to write a python app that reads phone numbers from a file
Question: I am quite new to Python. At the moment I am trying to write a script that can
read a `.txt` file that contains a bunch of data, and pull out phone numbers
that are in the format of `(xxx)xxx-xxxx`.
Here is my current attempt, but its not work... |
How to get json using django and jquery ajax? got 500 Intenal server error
Question: I'm trying to show dynamicly details of a certain object, getting them from a
sqlite3 database. I based my code on a tutorial, everything is exactly the
same, but I get a 500 Internal Server Error on my page (but the tutorial runs
perf... |
Is statsmodels lagmatrix function "wrong" ? (adds zeros to lagged array)
Question: **Example:**
Python
lagmatrix([1 2 3])
returns [0 1 2]
This is obviously not correct if I want to regress Y against the lagged values
of Y (i.e. an AR process).
I want to run a regress of Y and the lag values o... |
python3.2 + virtualenv - env create failed
Question: I've got a py2.7 project which I want to test under py3.2. For this purpose, I
want to use virtualenv. I wanted to create an environment that would run 3.2
version internally:
virtualenv 3.2 -p /usr/bin/python3.2
but it failed. My default python ... |
Get a c++ pointer to a Python instance using Boost::Python
Question: I am working on embedding Python inside of a C++ application. When I create a
new object in Python, I want to be able to store a reference to that Object in
my C++ application, so that I can later call methods on that object. What's
the recommended wa... |
python merge two lists (even/odd elements)
Question: Given two lists, I want to merge them so that all elements from the first list
are even-indexed (preserving their order) and all elements from second list
are odd-indexed (also preserving their order). Example below:
x = [0,1,2]
y = [3,4]
... |
LEN error for zipping in python
Question:
def shufflemode():
import random
combined = zip(question, answer)
random.shuffle(combined)
question[:], answer[:] = zip(*combined)
but then i get the error: TypeError: object of type 'zip' has no len()
What do I do im so confused
An... |
generic spider for scrapy project
Question: i am creating generic spider (scrapy spider) for multiple websites. below is
my project directory structure.
myproject <Directory>
--- __init__.py
--- common.py
--- scrapy.cfg
--- myproject <Directory>
---__init__.py
---items.py
... |
How to use youtube-dl from a python program
Question: I would like to access the result of the shell command:
youtube-dl -g "www.youtube.com..."
to print its output `direct url` to file; from within a python program:
import youtube-dl
fromurl="www.youtube.com ...."
geturl=you... |
Nested looping over tuple values in a dictionary with tuple keys python
Question: I have a defaultdict where the key is a 4-tuple (gene_region, species,
ontology, length).
Looping over it is simple:
for gene_region, species, ontology, length in result_dict:
However, I'd like to iterate over it in ... |
Python dict addition
Question: I have two dicts like this,
past =
{
'500188':
{
2: {'S': 16.97011741552128, 'C': 16.97011741552128},
3: {'S': -41.264072314989576, 'C': 'ERROR: reported_eps value not found for the year 2012.'},
4: {'S': -40.454... |
Python attributeError on __del__
Question: I have a python class object and I want to assign the value of one class
variable
class Groupclass(Workerclass):
"""worker class"""
count = 0
def __init__(self):
"""initialize time"""
Groupclass.count += 1
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.