question_id
int64
502
42.8M
parent_answer_post_id
int64
595
42.8M
prob
float64
0
0.87
snippet
stringlengths
0
12.1k
intent
stringlengths
11
198
id
stringlengths
9
20
1,870,871
3,987,901
0.000619
import tables as t hdf5_file = t.openFile('outfile.hdf5')
efficient way to compress a numpy array (python)
1870871_3987901_2
10,741,922
10,741,976
0.000619
expr
Dive into python and-or fail
10741922_10741976_4
40,257,152
40,538,541
0.000619
from googleapiclient import discovery projectID = 'projects/<your_project_id>'
Is there anyway Google App Engine apps can communicate or control Machine Learning models or tasks?
40257152_40538541_17
17,720,926
17,756,418
0.000618
uri = 'mongodb://user:pass@example.com/my_database/?w=2' from pymongo.uri_parser import parse_uri
pymongo default database connection
17720926_17756418_5
20,297,858
20,297,892
0.000618
run_every = crontab(month_of_year=starttime.month, day_of_month=starttime. day, hour=starttime.hour, minute=starttime.minute)
Django celery task run at once on startup of celery server
20297858_20297892_10
7,514,093
7,514,513
0.000618
from pprint import pprint li = [] for i in range(5): li.append((lambda x: lambda : pprint(x))(i))
lambda function don't closure the parameter in Python?
7514093_7514513_16
9,070,081
9,070,173
0.000618
python from filters import air
store each class in a separate file python
9070081_9070173_5
1,258,712
1,378,134
0.000617
tomorrow
fuzzy timestamp parsing with Python
1258712_1378134_6
34,899,733
34,900,927
0.000617
tree = ast.parse('import a; from b import c') tree.body tree.body[0].names[0].name
List all third party packages and theirselves functions used in a Python file
34899733_34900927_19
9,497,370
9,497,409
0.000616
foo bar
making exe file from python that uses command line arguments
9497370_9497409_19
29,349,607
29,350,541
0.000616
import clr clr.AddReference('System.Data') from System.Data.SqlClient import * Conn_string = ( 'data source=Server_Name; initial catalog=Database_Name; trusted_connection=True' ) ScheduleConn = SqlConnection(Conn_string) ScheduleConn.Open()
pymssql windows authentication
29349607_29350541_9
4,729,832
9,471,374
0.000616
import csv as csv_mod import codecs file = request.FILES['file'] dialect = csv_mod.Sniffer().sniff(codecs.EncodedFile(file, 'utf-8').read(1024))
Proccessing a Django UploadedFile as UTF-8 with universal newlines
4729832_9471374_17
1,071,110
18,106,223
0.000615
import requests def translate_es_to_en(text): url = 'https://www.googleapis.com/language/translate/v2'
Call Google Translate from Python
1071110_18106223_10
26,265,430
26,265,705
0.000615
import warnings import exceptions
Django: Naive datetime while time zone support is active (sqlite)
26265430_26265705_5
442,442
442,525
0.000614
pwd pwd - P
How to know when you are in a symbolic link
442442_442525_2
3,819,449
11,196,943
0.000614
org.python.Python.PythonApplications - 2.7 org.python.Python.PythonDocumentation - 2.7 org.python.Python.PythonFramework - 2.7 org.python.Python.PythonProfileChanges - 2.7
How to uninstall Python 2.7 on a Mac OS X 10.6.4?
3819449_11196943_15
16,055,403
16,055,603
0.000614
import platform setup_requires = ['foo', 'bar'] if platform.system() == 'Windows': pass
Setuptools platform specific dependencies
16055403_16055603_12
2,549,939
35,996,948
0.000613
import signal signal.SIGINT.name signal.SIGINT.value
Get signal names from numbers in Python
2549939_35996948_13
1,629,687
1,630,614
0.000612
from xml.dom.minidom import parseString dom = parseString("""<message> <text> Hello! </text> </message>""") dom.childNodes[0].childNodes text = dom.getElementsByTagName('text')[0].childNodes[0] text.data = text.data.replace('Hello', 'Hello world')
Alter XML while preserving layout
1629687_1630614_18
17,791,481
41,110,107
0.000612
import re def get_property(prop, project): result = re.search('{}\\s*=\\s*[\\\'"]([^\\\'"]*)[\\\'"]'.format(prop), open(project + '/__init__.py').read())
Creating a __version__ attribute for python packages without getting into trouble
17791481_41110107_17
25,104,154
40,746,017
0.000612
import requests from pkg_resources import parse_version def versions(name): pass
pypi see older versions of package
25104154_40746017_11
22,588,316
22,591,024
0.000611
P
pandas applying regex to replace values
22588316_22591024_14
4,994,638
7,303,734
0.000611
from pyftpdlib.handlers import FTPHandler address = '0.0.0.0', 21
One line ftp server in python
4994638_7303734_11
16,328,801
24,818,556
0.000611
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap) cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true) cap.setCapability(ChromeOptions.CAPABILITY, options)
Define download directory for chromedriver selenium with python
16328801_24818556_12
1,762,306
1,770,581
0.000611
def get_help_url(self): from pkg_resources import resource_filename
force unpacking of certain egg directories
1762306_1770581_16
3,868,722
3,869,492
0.00061
from lxml import html page = html.fromstring( """<html> <body>yuck, a newline! bandwidth wasted!</body> </html>""")
Strip whitespace from Mako template output (Pylons)
3868722_3869492_6
14,009,148
14,046,303
0.00061
from PythonMagick import Image img = Image('image.jpg')
Exif reading library
14009148_14046303_13
26,762,015
26,889,541
0.000609
from psychopy import core from ctypes import windll windll.inpout32.Out32(portaddress, triggerCode)
PsychoPy sending triggers on 64bit OS
26762015_26889541_12
10,874,719
32,600,280
0.000609
from lxml.builder import ElementMaker, E M = ElementMaker(namespace=None, nsmap={None: 'http://www.w3.org/1999/xhtml'}) html = M.html(E.head(E.title('Test page')), E.body(E.p('Hello world'))) result = etree.tostring(html, xml_declaration=True, doctype= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' , encoding='utf-8', standalone=False, with_tail=False, method='xml', pretty_print=True)
Recommended way to generate XHTML documents with lxml
10874719_32600280_19
20,340,815
20,340,970
0.000608
dir(type) import sys
Built-in magic variable names/attributes
20340815_20340970_5
29,603,056
29,614,388
0.000608
import StanfordDependencies sd = StanfordDependencies.get_instance(jar_filename= 'point to Stanford Parser JAR file')
Using StanfordParser to get typed dependencies from a parsed sentence
29603056_29614388_5
9,956,741
9,956,804
0.000608
Django == 1.4
How to install multiple python packages at once using pip
9956741_9956804_0
8,069,975
8,070,008
0.000607
from csv import reader infile = ['A,B,C,"D12121",E,F,G,H,"I9,I8",J,K'] for line in reader(infile): pass
Split string on commas but ignore commas within double-quotes?
8069975_8070008_9
1,174,984
1,175,491
0.000607
from numpy import array nums = array(((0.01, 0.01, 0.02, 0.04, 0.03), (0.0, 0.02, 0.02, 0.03, 0.02), (0.01, 0.02, 0.02, 0.03, 0.02), (0.01, 0.0, 0.01, 0.05, 0.03)))
How to efficiently calculate a running standard deviation?
1174984_1175491_8
2,494,468
2,540,589
0.000606
directoryWhereMyOwnPythonScriptsReside
How to create an application which embeds and runs Python code without local Python installation?
2494468_2540589_19
8,727,486
8,728,045
0.000605
AUTH_LDAP_SERVER_URI = 'ldap://ldap.example.com' import ldap from django_auth_ldap.config import LDAPSearch AUTH_LDAP_BIND_DN = '' AUTH_LDAP_BIND_PASSWORD = ''
LDAP in Django default admin
8727486_8728045_18
42,683,518
42,712,569
0.000605
import sys from pprint import pprint as p remove = ['/usr/lib/python2.7'] sys.path = [path for path in sys.path if path not in remove]
pip in virtualenv cannot find ctypes
42683518_42712569_11
15,570,099
15,570,546
0.000603
import io
Pandas Pivot tables row subtotals
15570099_15570546_17
29,647,326
29,649,072
0.000602
from multiprocessing import Pool def f(row_id): pass
Sparse matrix dot product keeping only N-max values per result row
29647326_29649072_16
6,821,677
6,821,958
0.000602
import itertools as it fields = {'a': ('col1', 'col2'), 'b': ('col1', 'col3')} fields_sql = ', '.join("{t}.{f} as '{t}.{f}'".format(f=f, t=t) for t in fields for f in fields[t]) sql = """SELECT {f} FROM a JOIN b ON ... WHERE ...""".format(f =fields_sql)
force mysqldb dict cursor to return prefix all column names with table name
6821677_6821958_17
13,024,416
13,024,551
0.0006
import dis def unpack_or_index(t=(0, 1)): pass
How come unpacking is faster than accessing by index?
13024416_13024551_19
2,549,939
35,996,948
0.0006
import signal signal.SIGINT.name signal.SIGINT.value signal.Signals(2).name
Get signal names from numbers in Python
2549939_35996948_14
29,645,153
29,645,179
0.0006
gender
remove name, dtype from pandas output
29645153_29645179_14
32,095,935
32,105,181
0.000599
from crontab import CronTab cron = CronTab() job = cron.new(command='/usr/bin/echo')
Python script to send mail at specific time and day every month
32095935_32105181_9
15,670,505
15,761,249
0.000599
py - execute - clause - python3 py - execute - clause - ipython
Comparison of Python modes for Emacs
15670505_15761249_9
1,037,406
1,037,423
0.000599
from urlgrabber.keepalive import HTTPHandler keepalive_handler = HTTPHandler() opener = urllib.request.build_opener(keepalive_handler)
Python urllib2 with keep alive
1037406_1037423_19
21,975,666
22,055,820
0.000598
if node() in ['dev1', 'dev2']: from local import * elif node() in ['prod1', 'prod2']: pass
Active Django settings file from Celery worker
21975666_22055820_18
235,435
242,175
0.000598
from ctypes import CDLL, c_char_p getenv = CDLL('libc.so.6').getenv
Environment Variables in Python on Linux
235435_242175_8
18,194,374
26,541,647
0.000598
python import io io.DEFAULT_BUFFER_SIZE
Default buffer size for a file on Linux
18194374_26541647_8
23,740,880
23,745,571
0.000597
from djcelery.models import PeriodicTask, CrontabSchedule every_hours_crontab = CrontabSchedule(minute=0)
Add, modify, remove celery.schedules at run time
23740880_23745571_13
10,900,852
38,482,056
0.000597
import random myrandom = random.SystemRandom
Near seeds in random number generation may give similar random numbers?
10900852_38482056_10
31,956,506
31,957,784
0.000597
import git repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha short_sha = repo.git.rev_parse(sha, short=1)
get short sha of commit with gitpython
31956506_31957784_14
22,011,481
26,852,052
0.000597
latDiv.id = 'extractedLat' latDiv.innerHtml = lat document.body.appendChild(latDiv)
Get the parameters of a JavaScript function with Scrapy
22011481_26852052_8
1,465,146
14,739,514
0.000596
import timeit tic = timeit.default_timer() toc = timeit.default_timer()
How do you determine a processing time in Python?
1465146_14739514_9
41,020,239
41,020,266
0.000594
Open
Replace a NaN index value in dataframe
41020239_41020266_3
2,814,609
2,815,796
0.000594
import imp sm.MyClass.kind imp.reload(sm)
reloading module, need to re-compile sub modules?
2814609_2815796_16
6,821,677
6,821,958
0.000594
import itertools as it fields = {'a': ('col1', 'col2'), 'b': ('col1', 'col3')} fields_sql = ', '.join("{t}.{f} as '{t}.{f}'".format(f=f, t=t) for t in fields for f in fields[t]) sql = """SELECT {f} FROM a JOIN b ON ... WHERE ..."""
force mysqldb dict cursor to return prefix all column names with table name
6821677_6821958_16
12,329,807
12,330,005
0.000593
import multiprocessing daemon = False bind = 'unix:/tmp/gunicorn.sock' workers = multiprocessing.cpu_count() * 2 + 1 timeout = 60
Django app deployment on nGINX
12329807_12330005_12
7,822,101
7,822,691
0.000593
obj = SomeObject() p = Proxy(obj) a = p.a b = p.b
String construction using OOP and Proxy pattern
7822101_7822691_13
20,617,600
20,621,143
0.000592
-2.7 -3.2 -3.3
Travis special requirements for each python version
20617600_20621143_10
9,353,822
42,587,012
0.000592
import psycopg2 conn_string = ( "host='localhost' dbname='my_database' user='postgres' password='secret'")
Connecting postgresql with sqlalchemy
9353822_42587012_8
13,773,862
13,774,565
0.000592
import traceback
API in Flask--returns JSON but HTML exceptions break my JSON client
13773862_13774565_11
12,172,791
12,173,406
0.000592
from math import * def sin_degrees(x): pass
Changes in import statement python3
12172791_12173406_11
34,553,622
34,822,733
0.000591
from bs4 import BeautifulSoup html = """ <div style="display:flex"> <div class="half" style="font-size: 0.8em;width: 33%;"> apple </div> <div class="half" style="font-size: 0.8em;text-align: center;width: 28%;"> peach </div> <div class="half" style="font-size: 0.8em;text-align: right;width: 33%;" title="nofruit"> cucumber </div> </div> """
Dealing with a colon in BeautifulSoup CSS selectors
34553622_34822733_14
7,822,101
7,822,691
0.000591
obj = SomeObject() p = Proxy(obj) a = p.a
String construction using OOP and Proxy pattern
7822101_7822691_14
6,408,886
6,409,798
0.00059
print(constant.GET_SERVER_QUEUE) print(constant.GET_SERVER_QUEUE)
Python constants declaration
6408886_6409798_19
41,531,689
41,531,702
0.00059
Country
Pandas: transform column's values in independent columns
41531689_41531702_5
11,472,810
14,405,269
0.00059
from verlib import NormalizedVersion as V assert V('0.7.9') < V('0.8a0') < V('0.8a1') < V('0.8b0') < V('0.8b1') < V( '0.8b2') < V('0.8.0') < V('0.8.1a0') < V('0.8.1') < V('0.9') < V('1.0a3' ) < V('1.0b2') < V('1.0b20') < V('1.0c0') < V('1.0') < V('1.0.1') assert V('0.7.9') < V('0.8.0a0') < V('0.8.0a1') < V('0.8.0b0') < V('0.8.0b1' ) < V('0.8.0b2') < V('0.8.0') < V('0.8.1a0') < V('0.8.1') < V('0.9') < V( '1.0a3') < V('1.0b2') < V('1.0b20') < V('1.0c0') < V('1.0') < V('1.0.1')
How to specify version ranges in install_requires (setuptools, distribute)
11472810_14405269_9
3,285,443
5,647,140
0.000589
root <<= 1 rem = (rem << 2) + (a >> 30)
Improving pure Python prime sieve by recurrence formula
3285443_5647140_12
19,569,701
19,707,600
0.000589
d.addCallback(context.succeeded) from pprint import pprint d.addCallback(pprint)
Benefits of twisted-suds - Async way of using python suds soap lib
19569701_19707600_17
5,120,302
18,360,428
0.000589
from unidecode import unidecode m = 'My fianc\xe9 David' print(m)
Avoiding Python UnicodeDecodeError in Jinja's nl2br filter
5120302_18360428_9
2,087,492
2,150,202
0.000588
APScheduler == 1.01
Can a Python package depend on a specific version control revision of another Python package?
2087492_2150202_0
5,953,205
22,567,430
0.000588
from sortedcontainers import SortedSet ss = SortedSet([3, 7, 2, 2])
Why are there no containers sorted by insertion order in Python's standard libraries?
5953205_22567430_11
1,285,911
1,552,005
0.000588
from timeit import Timer setup = ( """from random import randint as R;d=dict((str(R(0,1000000)),R(0,1000000)) for i in range(D));q=dict((str(R(0,1000000)),R(0,1000000)) for i in range(Q));print("looking for %s items in %s"%(len(q),len(d)))""" ) Timer('set(q) <= set(d)', 'D=1000000;Q=100;' + setup).timeit(1) Timer('set(q) <= d.keys()', 'D=1000000;Q=100;' + setup).timeit(1)
python: How do I check that multiple keys are in a dict in one go?
1285911_1552005_14
3,400,525
3,400,578
0.000588
import file2 print(file2.foo)
Global Variable from a different file Python
3400525_3400578_5
4,711,179
4,711,886
0.000588
import dis def test(): pass
Auto expanding blocks of comments in emacs
4711179_4711886_15
11,021,130
29,618,322
0.000587
bottle
Parallel Pip install
11021130_29618322_9
7,514,093
7,514,513
0.000587
from pprint import pprint li = []
lambda function don't closure the parameter in Python?
7514093_7514513_17
39,644,514
39,694,727
0.000586
from cryptography.hazmat.primitives.asymmetric import ec backend = default_backend() key = ec.generate_private_key(ec.SECP256R1(), backend)
How to find ASN.1 components of EC key python-cryptography
39644514_39694727_18
1,285,911
1,552,005
0.000586
from timeit import Timer setup = ( """from random import randint as R;d=dict((str(R(0,1000000)),R(0,1000000)) for i in range(D));q=dict((str(R(0,1000000)),R(0,1000000)) for i in range(Q));print("looking for %s items in %s"%(len(q),len(d)))""" ) Timer('set(q) <= set(d)', 'D=1000000;Q=100;' + setup).timeit(1)
python: How do I check that multiple keys are in a dict in one go?
1285911_1552005_13
5,537,592
29,628,236
0.000586
import requests import browser_cookie cj = browser_cookie.firefox()
How to extract Firefox session cookie (python language preferred)
5537592_29628236_9
27,486,589
27,487,021
0.000586
imp_spam = 'spam' try: import spam except: imp_spam = 'pyspam'
Python any of many dependencies
27486589_27487021_13
15,691,740
15,691,929
0.000585
a2
Does assignment with advanced indexing copy array data?
15691740_15691929_13
20,753,782
20,768,282
0.000585
import matplotlib as mpl font_paths = mpl.font_manager.findSystemFonts() font_objects = mpl.font_manager.createFontList(font_paths) font_names = [f.name for f in font_objects]
Default fonts in Seaborn statistical data visualization in iPython
20753782_20768282_15
31,533,496
31,667,372
0.000585
END
To convert from Python arrays to PostgreSQL quickly?
31533496_31667372_3
27,901,211
27,901,437
0.000585
python << _EOF_ import vim print('arg is ' + vim.eval('a:arg')) _EOF_ endfunction
How to pass arguments from vimscript functions to python interface?
27901211_27901437_11
2,409,472
2,409,523
0.000585
b = 'oof', 'rab', 'toz' return import dis
Python: How expensive is to create a small list many times?
2409472_2409523_15
17,791,481
41,110,107
0.000584
import re def get_property(prop, project): result = re.search('{}\\s*=\\s*[\\\'"]([^\\\'"]*)[\\\'"]'.format(prop), open(project + '/__init__.py').read()) return result.group(1)
Creating a __version__ attribute for python packages without getting into trouble
17791481_41110107_18
29,631,504
29,631,641
0.000582
s1 = """ import numpy as np a=np.random.randint(0,200,100) b1=np.random.randint(0,100,50) np.intersect1d(b1,a) """ s2 = """ import numpy as np a=np.random.randint(0,200,100) b1=np.random.randint(0,100,50) a[np.in1d(a, b1)] """ print(' first: ', timeit(stmt=s1, number=100000))
Return values from array based on indices of common values in two other arrays
29631504_29631641_17
8,893,209
8,893,965
0.000582
http = types.ModuleType('http') from .http import client http.client = client
Relative import of submodule
8893209_8893965_16
5,949,181
5,949,730
0.000581
from optparse import OptionParser parser = OptionParser()
How to unittest command line arguments?
5949181_5949730_5
41,463,763
41,463,788
0.000581
object
Merge 2 dataframes with same values in a column
41463763_41463788_14
20,734,875
20,734,938
0.000581
import optparse
python optparse, default values for optional options
20734875_20734938_14
19,181,767
19,184,557
0.00058
import Control.Monad import Control.Monad.State
Translating a simple imperative algorithm to functional style
19181767_19184557_2
22,011,481
26,852,052
0.000578
latDiv.innerHtml = lat document.body.appendChild(latDiv)
Get the parameters of a JavaScript function with Scrapy
22011481_26852052_7
21,975,666
22,055,820
0.000577
from common_settings import * from platform import node
Active Django settings file from Celery worker
21975666_22055820_19
134,387
784,421
0.000577
from paste.deploy import appconfig from pylons import config from YOURPROJ.config.environment import load_environment conf = appconfig('config:development.ini', relative_to='.')
Run Pylons controller as separate app?
134387_784421_14
36,663,600
36,663,673
0.000576
280
Multiple inputs from one input
36663600_36663673_6
466,684
467,291
0.000575
import win32_sysinfo as sysinfo
How can I return system information in Python?
466684_467291_18
5,544,629
19,465,670
0.000574
from amqplib import client_0_8 as amqp conn = amqp.Connection(host='localhost:5672 ', userid='guest', password= 'guest', virtual_host='/', insist=False) chan = conn.channel()
Retrieve list of tasks in a queue in Celery
5544629_19465670_9