qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
1,584,864 | Say that we have a multilayered iterable with some strings at the "final" level, yes strings are iterable, but I think that you get my meaning:
```
['something',
('Diff',
('diff', 'udiff'),
('*.diff', '*.patch'),
('text/x-diff', 'text/x-patch')),
('Delphi',
('delphi', 'pas', 'pascal', 'objectpascal'),
('*.pas',),
('... | 2009/10/18 | [
"https://Stackoverflow.com/questions/1584864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/177293/"
] | Here is a grep that uses recursion to search the data structure.
Note that good data structures lead the way to elegant solutions.
Bad data structures make you bend over backwards to accomodate.
This feels to me like one of those cases where a bad data structure is obstructing
rather than helping you.
Having a si... | To get the position use `enumerate()`
```
>>> data = [('foo', 'bar', 'frrr', 'baz'), ('foo/bar', 'baz/foo')]
>>>
>>> for l1, v1 in enumerate(data):
... for l2, v2 in enumerate(v1):
... if 'f' in v2:
... print l1, l2, v2
...
0 0 foo
1 0 foo/bar
1 1 baz/foo
```
In this example I a... |
1,584,864 | Say that we have a multilayered iterable with some strings at the "final" level, yes strings are iterable, but I think that you get my meaning:
```
['something',
('Diff',
('diff', 'udiff'),
('*.diff', '*.patch'),
('text/x-diff', 'text/x-patch')),
('Delphi',
('delphi', 'pas', 'pascal', 'objectpascal'),
('*.pas',),
('... | 2009/10/18 | [
"https://Stackoverflow.com/questions/1584864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/177293/"
] | I'd split recursive enumeration from grepping:
```
def enumerate_recursive(iter, base=()):
for index, item in enumerate(iter):
if isinstance(item, basestring):
yield (base + (index,)), item
else:
for pair in enumerate_recursive(item, (base + (index,))):
yield... | To get the position use `enumerate()`
```
>>> data = [('foo', 'bar', 'frrr', 'baz'), ('foo/bar', 'baz/foo')]
>>>
>>> for l1, v1 in enumerate(data):
... for l2, v2 in enumerate(v1):
... if 'f' in v2:
... print l1, l2, v2
...
0 0 foo
1 0 foo/bar
1 1 baz/foo
```
In this example I a... |
1,584,864 | Say that we have a multilayered iterable with some strings at the "final" level, yes strings are iterable, but I think that you get my meaning:
```
['something',
('Diff',
('diff', 'udiff'),
('*.diff', '*.patch'),
('text/x-diff', 'text/x-patch')),
('Delphi',
('delphi', 'pas', 'pascal', 'objectpascal'),
('*.pas',),
('... | 2009/10/18 | [
"https://Stackoverflow.com/questions/1584864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/177293/"
] | I'd split recursive enumeration from grepping:
```
def enumerate_recursive(iter, base=()):
for index, item in enumerate(iter):
if isinstance(item, basestring):
yield (base + (index,)), item
else:
for pair in enumerate_recursive(item, (base + (index,))):
yield... | Here is a grep that uses recursion to search the data structure.
Note that good data structures lead the way to elegant solutions.
Bad data structures make you bend over backwards to accomodate.
This feels to me like one of those cases where a bad data structure is obstructing
rather than helping you.
Having a si... |
36,831,274 | I want to connect my Django web app database to my postgresql database I have on my Pythonanywhere paid account. Before coding anything, I just wanted to get everything talking to each other. This is the settings.py DATABASE section from my django app. I'm running Python 3.5 and Django 1.9.
```
DATABASES = {
'default'... | 2016/04/25 | [
"https://Stackoverflow.com/questions/36831274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3314523/"
] | You need to setup django first if you are using it as a standalone script. Would have been easier to try with `./manage.py shell`. but if you want to test with a standalone script, here goes:
```
import sys,os
if __name__ == '__main__': # pragma nocover
# Setup environ
sys.path.append(os.getcwd())
os.en... | The error you are getting is because you need to properly initialize the django environment before you can write custom scripts against it.
The easiest way to solve this is to run a python shell that already has the django configuration loaded, you can do this with `python manage.py shell`.
Once this shell has loaded... |
56,652,022 | I am working with an Altera DE1-SoC board where I am reading data from a sensor using a C program. The data is being read continually, in a while loop and written to a text file. I want to read this data using a python program and display the data.
The problem is that I am not sure how to avoid collision during the re... | 2019/06/18 | [
"https://Stackoverflow.com/questions/56652022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6649616/"
] | Loop the *TableDefs* collection.
For each *TableDef*, loop the *Fields* collection.
For each *Field*, check the property *Type* (= 101, as I recall) or *IsComplex* = True.
IsComplex is also True for *Multi-Value* fields, but if you don't use these, you should be fine. | Here is an example on VBA. It prints in immediate (open VBA editor by `Alt` + `F11`, then press `Ctrl` + `G`) messages about tables with Attachment type field.
```vb
Public Sub subTest()
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fld As DAO.Field
Dim boolIsAttachmentFieldPresent ... |
56,652,022 | I am working with an Altera DE1-SoC board where I am reading data from a sensor using a C program. The data is being read continually, in a while loop and written to a text file. I want to read this data using a python program and display the data.
The problem is that I am not sure how to avoid collision during the re... | 2019/06/18 | [
"https://Stackoverflow.com/questions/56652022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6649616/"
] | Loop the *TableDefs* collection.
For each *TableDef*, loop the *Fields* collection.
For each *Field*, check the property *Type* (= 101, as I recall) or *IsComplex* = True.
IsComplex is also True for *Multi-Value* fields, but if you don't use these, you should be fine. | This is what I came up with:
```vb
Public Function ListAttachmentTables()
Dim tdf As TableDef
Dim fld As Field
Dim FldsCnt As Long
Dim lngCountLoop As Long
CurrentDb.TableDefs.Refresh
For Each tdf In CurrentDb.TableDefs
If Not tdf.Name Like "MSys*" Then
For Each fld In tdf.Fields
... |
60,494,341 | I have a large csv data file, sample of the data as below.
```
name year value
China 1997 481970
Japan 1997 8491480
Germany 1997 4678022
China 1998 589759
Japan 1998 ... | 2020/03/02 | [
"https://Stackoverflow.com/questions/60494341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12807398/"
] | Assuming the input shown reproducibly in the Note at the end convert it to a zoo object `z` which, by specifying `split=`, will also convert it to wide form at the same time. Then expand it using `merge` and use linear interpolation with `na.approx`. Alternately replace `na.approx` with `na.spline`. Finally convert the... | An option using `data.table`:
```
DT[, date := as.IDate(paste0(year, "-12-31"))][,
c("y0", "y1") := .(value, shift(value, -1L, fill=value[.N])), name]
longDT <- DT[, {
eom <- seq(min(date)+1L, max(date)+1L, by="1 month") - 1L
v <- unlist(mapply(function(a, d) a + (0:11) * d, y0, (y1 - y0)/12, SIMPLIFY=FAL... |
49,687,860 | After upgrade pycharm to 2018.1, and upgrade python to 3.6.5, pycharm reports "unresolved reference 'join'". The last version of pycharm doesn't show any warning for the line below:
```
from os.path import join, expanduser
```
May I know why?
(I used python 3.6.? before)
I tried almost everything I can find, such ... | 2018/04/06 | [
"https://Stackoverflow.com/questions/49687860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8335451/"
] | Sadly, it seems that PyCharm will try to evaluate the path to an existing file/folder, which in some cases will not exist and thus create this warning.
It's not very useful when you are building a path for something that's supposed to be created, because obviously it will not exist yet, but PyCharm will still complain... | Check that pycharms is using the correct interpreter. |
63,404,899 | I'm trying to write a highly modular Python logging system (using the logging module) and include information from the trace module in the log message.
For example, I want to be able to write a line of code like:
```
my_logger.log_message(MyLogFilter, "this is a message")
```
and have it include the trace of where ... | 2020/08/14 | [
"https://Stackoverflow.com/questions/63404899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3014653/"
] | >
> or if I'm completely off on the wrong track and if that's the case, what I should be doing instead.
>
>
>
My strong suggestion is that you view logging as a solved problem and avoid reinventing the wheel.
If you need more than the standard library's `logging` module provides, it's probably something like [str... | It turns out the missing piece to the puzzle is using the "traceback" module rather than the "trace" one. It's simple enough to parse the output of traceback to pull out the source filename and line number of the ".log\_message()" call.
If my logging needs become any more complicated then I'll definitely look into str... |
51,074,335 | Want to find the delimiter in the text file.
The text looks:
```
ID; Name
1; John Mak
2; David H
4; Herry
```
The file consists of tabs with the delimiter.
I tried with following: [by referring](https://stackoverflow.com/questions/21407993/find-delimiter-in-txt-to-convert-to-csv-using-python)
```... | 2018/06/28 | [
"https://Stackoverflow.com/questions/51074335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4268241/"
] | `sniff` can conclude with only one single character as the delimiter. Since your CSV file contains two characters as the delimiter, `sniff` will simply pick one of them. But since you also pass in the optional second argument to `sniff`, it will only pick what's contained in that value as a possible delimiter, which in... | Sniffing is not guaranteed to work.
Here is one approach that will work with any kind of delimiter.
You start with what you assume is the most common delimiter `;` if that fails, then you try others until you manage to parse the row.
```
import csv
with open('sample.csv') as f:
reader = csv.reader(f, delimiter=';... |
40,523,328 | I have code below for a simple test of `sympy.solve`:
```
#!/usr/bin/python
from sympy import *
x = Symbol('x', real=True)
#expr = sympify('exp(1 - 10*x) - 15')
expr = exp(1 - x) - 15
print "Expressiong:", expr
out = solve(expr)
for item in out:
print "Answer:", item
expr = exp(1 - 10*x) - 15
print expr
out = ... | 2016/11/10 | [
"https://Stackoverflow.com/questions/40523328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2298014/"
] | I can also confirm that the `solve` output for the equation `exp(1 - 10*x) - 15 == 0` appears unecessarily complicated. I would suggest for univariate equations to first consider `sympy.solveset`. For this example, it gives the following nicely formatted solutions.
```
import sympy as sp
sp.init_printing(pretty_print=... | `solve` gives real and complex roots if symbols allow. An equation like `exp(2*x)-4` can be though of as `y**2 - 4` with `y = exp(x)` and `y` (thus `x`) will have two solutions. There are 10 solutions if the 2 is replaced with 10. (But there are actually many more solutions besides as `solveset` indicates.)
You based ... |
53,289,402 | I have a windows setup file (.exe), which is used to install a software. This is a third party executable. During installation, it expects certain values and has a UI.
I want to run this setup .exe silently without any manual intervention (even for providing the parameter values).
After spending some time googling abou... | 2018/11/13 | [
"https://Stackoverflow.com/questions/53289402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1773169/"
] | ***Deployment***: Note that it is not always possible to run a setup.exe silently with full control of parameters and with reliable silent running. It depends on how the installer was designed. In these cases I normally resort to repackaging - some more detail below on this.
Some general tips for dealing with deployme... | You can also try creating a shortcut to the exe and adding (one at a time) common help parameters in the shortcut target and see if one gives you a help dialog. Some common parameters are
/?
/help
-help
--help
This also depends on the developer implementing a help parameter, but most installer builders default to imp... |
62,515,497 | I have a directory with quite some files. I have `n` search patterns and would like to list all files that match `m` of those.
Example: From the files below, list the ones that contain at least *two* of `str1`, `str2`, `str3` and `str4`.
```sh
$ ls -l dir/
total 16
-rw-r--r--. 1 me me 10 Jun 22 14:22 a
-rw-r--r--. 1 ... | 2020/06/22 | [
"https://Stackoverflow.com/questions/62515497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2656118/"
] | ```
$ cat reg.txt
str1
str2
str3
str4
```
```
$ cat prog.awk
# reads regexps from the first input file
# parameterized by `m'
# requires gawk or mawk for `nextfile'
FNR == NR {
reg[NR] = $0
next
}
FNR == 1 {
for (i in reg)
tst[i]
cnt = 0
}
{
for (i in tst) {
if ($0 ~ reg[i]) {
if (++cnt == m) ... | Here's an option using `awk` since you tagged it with that too:
```
find dir -type f -exec \
awk '/str1|str2|str3|str4/{c++} END{if(c>=2) print FILENAME;}' {} \;
```
It will however count duplicates, so a file containing
```
str1
str1
```
will be listed. |
62,515,497 | I have a directory with quite some files. I have `n` search patterns and would like to list all files that match `m` of those.
Example: From the files below, list the ones that contain at least *two* of `str1`, `str2`, `str3` and `str4`.
```sh
$ ls -l dir/
total 16
-rw-r--r--. 1 me me 10 Jun 22 14:22 a
-rw-r--r--. 1 ... | 2020/06/22 | [
"https://Stackoverflow.com/questions/62515497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2656118/"
] | Since the programming language doesn't matter as much as the performance, here's a version in C++. I haven't compared it with `awk` myself though.
```
#include <cstddef>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace... | ```
$ cat reg.txt
str1
str2
str3
str4
```
```
$ cat prog.awk
# reads regexps from the first input file
# parameterized by `m'
# requires gawk or mawk for `nextfile'
FNR == NR {
reg[NR] = $0
next
}
FNR == 1 {
for (i in reg)
tst[i]
cnt = 0
}
{
for (i in tst) {
if ($0 ~ reg[i]) {
if (++cnt == m) ... |
62,515,497 | I have a directory with quite some files. I have `n` search patterns and would like to list all files that match `m` of those.
Example: From the files below, list the ones that contain at least *two* of `str1`, `str2`, `str3` and `str4`.
```sh
$ ls -l dir/
total 16
-rw-r--r--. 1 me me 10 Jun 22 14:22 a
-rw-r--r--. 1 ... | 2020/06/22 | [
"https://Stackoverflow.com/questions/62515497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2656118/"
] | Since the programming language doesn't matter as much as the performance, here's a version in C++. I haven't compared it with `awk` myself though.
```
#include <cstddef>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace... | Here's an option using `awk` since you tagged it with that too:
```
find dir -type f -exec \
awk '/str1|str2|str3|str4/{c++} END{if(c>=2) print FILENAME;}' {} \;
```
It will however count duplicates, so a file containing
```
str1
str1
```
will be listed. |
44,282,257 | I am new in python.
I have a scrapy project. I am using conda virtual environment where I have written a pipeline class like this:
```
from cassandra.cqlengine import connection
from cassandra.cqlengine.management import sync_table, create_keyspace_network_topology
from recentnews.cassandra.model.NewsPaperDataModel im... | 2017/05/31 | [
"https://Stackoverflow.com/questions/44282257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1427144/"
] | So it appeared that [there was a folder named `recentnews/cassandra/`](https://stackoverflow.com/questions/44282257/importerror-no-module-named-cqlengine-but-worked-on-python-command?noredirect=1#comment75573040_44282257) in the OP's scrapy project (namespace `recentnews.cassandra`).
When scrapy imports the item pipel... | When you create a virtual environment, by default the user-installed packages are not copied. You would therefore have to run `pip install casandra` (or whatever the package is called) in your virtual environment. That will probably fix this problem. |
50,877,817 | The first column corresponds to a single process and the second column are the components that go into the process. I want to have a loop that can examine all the processes and evaluate what other processes have the same individual components. Ultimately, I want a loop to find what processes have 50% or more of their c... | 2018/06/15 | [
"https://Stackoverflow.com/questions/50877817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9946677/"
] | Here is what I ended up doing:
```
// Get the tile's cartesian center.
var cartesian = new Cesium.Cartesian3(1525116.05769, -4463608.36127, 4278734.88048);
// Get the tile's cartographic center.
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
// Rotate the model.
model.rotation.x = -cartographic.lat... | Just convert "gltfUpAxis" to "Z" would work fine. Or you can try "Y" too.
```
"asset": {
"gltfUpAxis": "Z",
"version": "1.0"
},
``` |
67,022,905 | I have a simple text file that has groups of key:value pairs with a blank row between each group of key:values. The number of key:value pairs can vary from group to group. Sample data and my code so far.
```
key1: value1
key2: value2
key3: value3
key1: value4
key2: value5
key3: value6
```
The code is close to what ... | 2021/04/09 | [
"https://Stackoverflow.com/questions/67022905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3123307/"
] | Using [`Array.from()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) and [`Array.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce), this could be done as follows:
```
Array.from(map.entries()).reduce((a, b) => a[1] <... | Here is one approach
* Convert it to an array of key/value pairs
* Sort the array by the value
* Extract the second item of the first pair
Like so
```
let map: Map<string, number> = new Map();
map.set("a", 12);
map.set("b", 124);
map.set("c", 14);
map.set("d", 155);
const key = Array.from(map).sort((a, b) => (a[1]... |
2,319,495 | I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the n... | 2010/02/23 | [
"https://Stackoverflow.com/questions/2319495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18308/"
] | On every machine you have to basically run following `pywin32_postinstall.py -install` once. Assuming your python installation on the network is `N:\Python26`, run following command on every client:
```
N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install
```
Another important thing is `Good Lu... | You could use [batch files running at boot](http://isg.ee.ethz.ch/tools/realmen/index.en.html) to
* Mount the network share (`net use \\server\share`)
* Copy the Python and packages installers from the network share to a local folder
* Check version of the msi installer against the installed version
* If different, un... |
2,319,495 | I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the n... | 2010/02/23 | [
"https://Stackoverflow.com/questions/2319495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18308/"
] | Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.
So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 t... | You could use [batch files running at boot](http://isg.ee.ethz.ch/tools/realmen/index.en.html) to
* Mount the network share (`net use \\server\share`)
* Copy the Python and packages installers from the network share to a local folder
* Check version of the msi installer against the installed version
* If different, un... |
2,319,495 | I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the n... | 2010/02/23 | [
"https://Stackoverflow.com/questions/2319495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18308/"
] | On every machine you have to basically run following `pywin32_postinstall.py -install` once. Assuming your python installation on the network is `N:\Python26`, run following command on every client:
```
N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install
```
Another important thing is `Good Lu... | Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.
So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 t... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Any reason you haven't considered Selenium with the Chrome Driver?
<http://code.google.com/p/selenium/wiki/ChromeDriver>
<http://code.google.com/p/selenium/wiki/PythonBindings> | [casperjs](http://casperjs.org/) is a headless webkit, but it wouldn't give you python bindings that I know of; it seems command-line oriented, but that doesn't mean you couldn't run it from python in such a way that satisfies what you are after. When you run casperjs, you provide a path to the javascript you want to e... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Any reason you haven't considered Selenium with the Chrome Driver?
<http://code.google.com/p/selenium/wiki/ChromeDriver>
<http://code.google.com/p/selenium/wiki/PythonBindings> | While I'm the author of [CasperJS](http://casperjs.org/), I invite you to check out [Ghost.py](http://jeanphix.me/Ghost.py/), *a webkit web client written in Python*.
While it's heavily inspired by CasperJS, it's not based on [PhantomJS](http://phantomjs.org/) — it still uses [PyQt](http://www.riverbankcomputing.co.uk... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Any reason you haven't considered Selenium with the Chrome Driver?
<http://code.google.com/p/selenium/wiki/ChromeDriver>
<http://code.google.com/p/selenium/wiki/PythonBindings> | I use this to get the driver:
```
def get_browser(storage_dir, headless=False):
"""
Get the browser (a "driver").
Parameters
----------
storage_dir : str
headless : bool
Results
-------
browser : selenium webdriver object
"""
# find the path with 'which chromedriver'
p... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Any reason you haven't considered Selenium with the Chrome Driver?
<http://code.google.com/p/selenium/wiki/ChromeDriver>
<http://code.google.com/p/selenium/wiki/PythonBindings> | This question is 5 years old now and at the time it was a big challenge to run a headless chrome using python, but the good news is:
**Starting from version 59, released in June 2017, Chrome comes with a headless driver**, meaning we can use it in a non-graphical server environment and run tests without having pages v... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | While I'm the author of [CasperJS](http://casperjs.org/), I invite you to check out [Ghost.py](http://jeanphix.me/Ghost.py/), *a webkit web client written in Python*.
While it's heavily inspired by CasperJS, it's not based on [PhantomJS](http://phantomjs.org/) — it still uses [PyQt](http://www.riverbankcomputing.co.uk... | [casperjs](http://casperjs.org/) is a headless webkit, but it wouldn't give you python bindings that I know of; it seems command-line oriented, but that doesn't mean you couldn't run it from python in such a way that satisfies what you are after. When you run casperjs, you provide a path to the javascript you want to e... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | I use this to get the driver:
```
def get_browser(storage_dir, headless=False):
"""
Get the browser (a "driver").
Parameters
----------
storage_dir : str
headless : bool
Results
-------
browser : selenium webdriver object
"""
# find the path with 'which chromedriver'
p... | [casperjs](http://casperjs.org/) is a headless webkit, but it wouldn't give you python bindings that I know of; it seems command-line oriented, but that doesn't mean you couldn't run it from python in such a way that satisfies what you are after. When you run casperjs, you provide a path to the javascript you want to e... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | This question is 5 years old now and at the time it was a big challenge to run a headless chrome using python, but the good news is:
**Starting from version 59, released in June 2017, Chrome comes with a headless driver**, meaning we can use it in a non-graphical server environment and run tests without having pages v... | [casperjs](http://casperjs.org/) is a headless webkit, but it wouldn't give you python bindings that I know of; it seems command-line oriented, but that doesn't mean you couldn't run it from python in such a way that satisfies what you are after. When you run casperjs, you provide a path to the javascript you want to e... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | While I'm the author of [CasperJS](http://casperjs.org/), I invite you to check out [Ghost.py](http://jeanphix.me/Ghost.py/), *a webkit web client written in Python*.
While it's heavily inspired by CasperJS, it's not based on [PhantomJS](http://phantomjs.org/) — it still uses [PyQt](http://www.riverbankcomputing.co.uk... | I use this to get the driver:
```
def get_browser(storage_dir, headless=False):
"""
Get the browser (a "driver").
Parameters
----------
storage_dir : str
headless : bool
Results
-------
browser : selenium webdriver object
"""
# find the path with 'which chromedriver'
p... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | This question is 5 years old now and at the time it was a big challenge to run a headless chrome using python, but the good news is:
**Starting from version 59, released in June 2017, Chrome comes with a headless driver**, meaning we can use it in a non-graphical server environment and run tests without having pages v... | While I'm the author of [CasperJS](http://casperjs.org/), I invite you to check out [Ghost.py](http://jeanphix.me/Ghost.py/), *a webkit web client written in Python*.
While it's heavily inspired by CasperJS, it's not based on [PhantomJS](http://phantomjs.org/) — it still uses [PyQt](http://www.riverbankcomputing.co.uk... |
9,776,351 | This question describes my conclusion after researching available options for creating a headless Chrome instance in Python and asks for confirmation or resources that describe a 'better way'.
From what I've seen it seems that the quickest way to get started with a headless instance of Chrome in a Python application i... | 2012/03/19 | [
"https://Stackoverflow.com/questions/9776351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | This question is 5 years old now and at the time it was a big challenge to run a headless chrome using python, but the good news is:
**Starting from version 59, released in June 2017, Chrome comes with a headless driver**, meaning we can use it in a non-graphical server environment and run tests without having pages v... | I use this to get the driver:
```
def get_browser(storage_dir, headless=False):
"""
Get the browser (a "driver").
Parameters
----------
storage_dir : str
headless : bool
Results
-------
browser : selenium webdriver object
"""
# find the path with 'which chromedriver'
p... |
27,916,891 | I wrote some python code like:
```
if platform == 'ios':
do_something()
elif platform == 'android':
do_something_else()
```
And this piece of code was strongly criticized by one of my colleague. He accused me why I don't have an else block to handle the rest part.
In my opinion, all I need to do is to deal ... | 2015/01/13 | [
"https://Stackoverflow.com/questions/27916891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3480199/"
] | `else` is not required from the syntax point of view and is not enforced by `PEP8`. If you intended do nothing if `platform` is not `ios` or `android` then this is perfectly ok.
Alternatively, you can have a mapping "platform > function", something along these lines:
```
mapping = {'ios': do_something, 'android': do_... | It depends on your code but in this case either way would've been fine. There was a logical reason that your code needed to be that way and that's fine. You do not have to follow the rules all the time, you have to be able to try different stuff all the time. |
27,955,947 | We are trying to write an automated test for our iOS app using the Appium python client.
We want to imitate Swipe event on an element but none of the APIs from appium.webdriver.common.touch\_action seem to be behaving the way we want.
Basically we want to break down swipe in three events (KEYDOWN, MOVE, KEYUP).
The f... | 2015/01/15 | [
"https://Stackoverflow.com/questions/27955947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/631679/"
] | Your 'data' contains 4 contours. Each contour has one point that was drawn on image. What you need is 1 contour with 4 points. Push all your points to data[0].
On side note, you don't need to call drawContours() in loop. If you provide negative index of contour (third parameter), then all contours will be drawn.
```
... | If you have only 4 points, I suggest you to use cv::Rectangle. If you can have a lot of points, you have to write a function using [cv::Line](http://docs.opencv.org/2.4.2/modules/core/doc/drawing_functions.html#line). |
49,981,741 | I am writing a python application and trying to manage the code in a structure.
The directory structure that I have is something like the following:-
```
package/
A/
__init__.py
base.py
B/
__init__.py
base.py
app.py
__init__.py
```
so I have a line in A/**init**.py that says
```
from .bas... | 2018/04/23 | [
"https://Stackoverflow.com/questions/49981741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7877397/"
] | This is occurred because you have two packages: *A* and *B*. Package *B* can't get access to content of package *A* via relative import because it cant move outside top-level package. In you case both packages are top-level.
You need reorganize you project, for example like that
```
.
├── TL
│ ├── A
│ │ ├── __... | My problem was forgetting `__init__.py` in my top level directory. This allowed me to use relative imports for folders in that directory. |
62,209,746 | Still fairly new to python.
I was wondering what would be a good way of detecting what output response a python program were to choose.
As an example, if you were to make a speed/distance/time calculator, if only 2 input were ever given, how would you detect which was the missing input and therefore the output? I can... | 2020/06/05 | [
"https://Stackoverflow.com/questions/62209746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11098113/"
] | Python allows you to change types of variables on the fly. Since you are working with integers and `0` could be a useful value in your calculations, your default 'not present' value should be `None`:
```
def sdf(speed=None, time=None, distance=None):
if speed is None:
return calculate_speed(time, distance... | You should use multiple functions and call the one needed.
```
def CalculateTravelTime(distance, speed)
def CalculateTravelSpeed(distance, time)
def CalculateTravelDistance(speed, time)
``` |
62,209,746 | Still fairly new to python.
I was wondering what would be a good way of detecting what output response a python program were to choose.
As an example, if you were to make a speed/distance/time calculator, if only 2 input were ever given, how would you detect which was the missing input and therefore the output? I can... | 2020/06/05 | [
"https://Stackoverflow.com/questions/62209746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11098113/"
] | This is what I would do :
```
def sdf(distance=None, speed=None, time=None):
"""Calculate the missing speed, distance time value
returns a 3-tuple (speed, distance, time)
raises ValueError if more than one or no unknowns are given"""
if (distance, speed,time).count(None) > 1:
... | You should use multiple functions and call the one needed.
```
def CalculateTravelTime(distance, speed)
def CalculateTravelSpeed(distance, time)
def CalculateTravelDistance(speed, time)
``` |
62,209,746 | Still fairly new to python.
I was wondering what would be a good way of detecting what output response a python program were to choose.
As an example, if you were to make a speed/distance/time calculator, if only 2 input were ever given, how would you detect which was the missing input and therefore the output? I can... | 2020/06/05 | [
"https://Stackoverflow.com/questions/62209746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11098113/"
] | Python allows you to change types of variables on the fly. Since you are working with integers and `0` could be a useful value in your calculations, your default 'not present' value should be `None`:
```
def sdf(speed=None, time=None, distance=None):
if speed is None:
return calculate_speed(time, distance... | This is what I would do :
```
def sdf(distance=None, speed=None, time=None):
"""Calculate the missing speed, distance time value
returns a 3-tuple (speed, distance, time)
raises ValueError if more than one or no unknowns are given"""
if (distance, speed,time).count(None) > 1:
... |
48,788,169 | I was doing cs231n assignment 2 and encountered this problem.
I'm using tensorflow-gpu 1.5.0
Code as following
```
# define our input (e.g. the data that changes every batch)
# The first dim is None, and gets sets automatically based on batch size fed in
X = tf.placeholder(tf.float32, [None, 32, 32, 3])
y = tf.place... | 2018/02/14 | [
"https://Stackoverflow.com/questions/48788169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5856554/"
] | The problem is that the `y_out` argument to `sess.run()` is `None`, whereas it must be a `tf.Tensor` (or tensor-like object, such as a `tf.Variable`) or a `tf.Operation`.
In your example, `y_out` is defined by the following code:
```
# define model
def complex_model(X,y,is_training):
pass
y_out = complex_model(X... | I believe that **mrry** is right.
If you give a second look the the notebook [Assignment 2 - Tensorflow.ipynb](https://github.com/BedirYilmaz/cs231-stanford/blob/master/assignment2/TensorFlow.ipynb), you will notice the description cell as follows :
>
> Training a specific model
>
>
> In this section, we're going... |
11,100,380 | I've been studying tkinter in python3 and find it very hard to find good documentation and answers online. To help others struggling with the same problems I decided to post a solution for a simple problem that there seems to be no documentation for online.
Problem: Create a wizard-like program, that presents the user... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11100380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1466253/"
] | As you've taken the liberty to post an answer as a question. I'd like to post a comment as an answer and suggest that perhaps you should contribute this to TkDocs (click their [About tab](http://www.tkdocs.com/about.html) and they talk about contributing to the site).
I think it'd be better if that site were to improv... | Thanks for your work- I used it as inspiration for this example that, while extremely light in terms of the content, is a cool way to make an arbitrary number of windows that you can switch between. You could move the location of the next and back buttons, turn them into arrows, whatever you want.
```
from tkinter im... |
3,974,211 | i saw a javascript implementation of sha-256.
i waana ask if it is safe (pros/cons wathever) to use sha-256 (using javascript implementation or maybe python standard modules) alogrithm as a password generator:
i remember one password, put it in followed(etc) by the website address and use the generated text as the pas... | 2010/10/20 | [
"https://Stackoverflow.com/questions/3974211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/481170/"
] | I think you are describing the approach used by [SuperGenPass](http://supergenpass.com/):
Take a master password (same for every site), concatenate it with the site's domain name, and then hash the thing.
Yes, SHA-256 would be secure for that, likely more secure than when SuperGenPass uses. However, you will end up w... | SHA-256 generates *very* long strings. You're better off using `random.choice()` with a string a fixed number of times. |
52,236,797 | Built Python 3.7 on my Raspberry pi zero in a attempt to upgrade from Python 3.5.3
The build was successful, ran into the module not found for smbus and switched that to smbus2, now when I import gpiozero I get Module not found. my DungeonCube.py program was working fine under Python 3.5.3, but now Python 3.7 seems to ... | 2018/09/08 | [
"https://Stackoverflow.com/questions/52236797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10333299/"
] | I had same problem, realized that i used `pip3` to install the package, but I was trying to use it with `python` which invokes python2. I tried with `python3` it works just fine. | did you download the gpiozero module onto the raspberry pi? it does not come preinstalled with python.
you could try to do "sudo python3 pip install gpiozero". if that doesnt work replace python3 with python @GarryOsborne . |
15,976,639 | First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with consonant+"o"+consonant. For example "b" would be replaced with "bob" and "d" would be replaced with "dod" (so the word "python" would be chan... | 2013/04/12 | [
"https://Stackoverflow.com/questions/15976639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2275161/"
] | `lexicon` is a dictionary with integers as keys and tuples as values. when you iterate over it's items, you're getting tuples of the form `(integer,tuple)`. You're then passing that integer and tuple to `text.replace` as `i` and `j` which is why it's complaining. Perhaps you meant:
```
for i,j in lexicon.values():
... | no ... your keys in the handmade version are strings ... your kets in the other version are ints ... ints have no replace method |
15,976,639 | First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with consonant+"o"+consonant. For example "b" would be replaced with "bob" and "d" would be replaced with "dod" (so the word "python" would be chan... | 2013/04/12 | [
"https://Stackoverflow.com/questions/15976639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2275161/"
] | `lexicon` is a dictionary with integers as keys and tuples as values. when you iterate over it's items, you're getting tuples of the form `(integer,tuple)`. You're then passing that integer and tuple to `text.replace` as `i` and `j` which is why it's complaining. Perhaps you meant:
```
for i,j in lexicon.values():
... | No need for dictionaries this time, just iterate over characters of text, add vovels or consonant+o+consonant to an result array and join it to a string at the end:
```
def replacer(text):
consonants = set('bcdfghjklmnpqrstvwxz')
result = []
for c in text:
if c in consonants:
result.app... |
15,976,639 | First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with consonant+"o"+consonant. For example "b" would be replaced with "bob" and "d" would be replaced with "dod" (so the word "python" would be chan... | 2013/04/12 | [
"https://Stackoverflow.com/questions/15976639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2275161/"
] | `lexicon` is a dictionary with integers as keys and tuples as values. when you iterate over it's items, you're getting tuples of the form `(integer,tuple)`. You're then passing that integer and tuple to `text.replace` as `i` and `j` which is why it's complaining. Perhaps you meant:
```
for i,j in lexicon.values():
... | I guess what you wanted to achieve is lexicon mapping consonant to replacement. It may be done this way:
```
lexicon = { c: c+'o'+c for c in consonant }
```
which is equivalent of:
```
for c in consonant:
lexicon[c] = c+'o'+c
``` |
15,976,639 | First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with consonant+"o"+consonant. For example "b" would be replaced with "bob" and "d" would be replaced with "dod" (so the word "python" would be chan... | 2013/04/12 | [
"https://Stackoverflow.com/questions/15976639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2275161/"
] | No need for dictionaries this time, just iterate over characters of text, add vovels or consonant+o+consonant to an result array and join it to a string at the end:
```
def replacer(text):
consonants = set('bcdfghjklmnpqrstvwxz')
result = []
for c in text:
if c in consonants:
result.app... | no ... your keys in the handmade version are strings ... your kets in the other version are ints ... ints have no replace method |
15,976,639 | First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with consonant+"o"+consonant. For example "b" would be replaced with "bob" and "d" would be replaced with "dod" (so the word "python" would be chan... | 2013/04/12 | [
"https://Stackoverflow.com/questions/15976639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2275161/"
] | I guess what you wanted to achieve is lexicon mapping consonant to replacement. It may be done this way:
```
lexicon = { c: c+'o'+c for c in consonant }
```
which is equivalent of:
```
for c in consonant:
lexicon[c] = c+'o'+c
``` | no ... your keys in the handmade version are strings ... your kets in the other version are ints ... ints have no replace method |
59,457,595 | I am taking the data science course from Udemy. After running the code to show the iris data set, it does not show. Instead, it downloads a data file.
I am running the following code:
```py
from IPython.display import HTML
HTML('<iframe src=http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data></if... | 2019/12/23 | [
"https://Stackoverflow.com/questions/59457595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4998064/"
] | If plot is not in the first line in the file, you could do this:
```
sed '1,/plot/!s/plot//'
```
If it can be on the first line, I see no other way but to loop it:
```
sed ':a;/plot/!{n;ba;};:b;n;s///;bb'
``` | In case you are ok with an `awk` solution, could you please try following.
```
awk '/plot/ && ++count==1{print;next} !/plot/' Input_file
```
***Explanation:*** Adding explanation for above code.
```
awk ' ##Starting awk program from here.
/plot/ && ++count==1{ ##Checking condition if... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | To install the latest version of pyaudio using conda:
```
source activate -your environment name-
pip install pyaudio
```
You may run into the following error when installing from pip:
```
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
compilation termin... | I was able to get it install with [anaconda](https://www.continuum.io/downloads), using [this package](https://anaconda.org/bokeh/pyaudio).
Follow install instructions for linux [here](https://www.continuum.io/downloads#_unix), then do:
```
conda install -c bokeh pyaudio=0.2.7
``` |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | To install the latest version of pyaudio using conda:
```
source activate -your environment name-
pip install pyaudio
```
You may run into the following error when installing from pip:
```
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
compilation termin... | try to install using the the below command
```
pip install pyaudio
```
after that install the required Microsoft Visual C++ 14.0
refer the below image for the same.
[](https://i.stack.imgur.com/FFtJ5.jpg)
and restart the system and run the same co... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | To install the latest version of pyaudio using conda:
```
source activate -your environment name-
pip install pyaudio
```
You may run into the following error when installing from pip:
```
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
compilation termin... | I have found the work arround for mac.
please refer the below steps to install pyaudio on python 3.5
Follow these steps :
* export HOMEBREW\_NO\_ENV\_FILTERING=1
* xcode-select --install
* brew update
* brew upgrade
* brew install portaudio
* pip install pyaudio |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | I have found the work arround for mac.
please refer the below steps to install pyaudio on python 3.5
Follow these steps :
* export HOMEBREW\_NO\_ENV\_FILTERING=1
* xcode-select --install
* brew update
* brew upgrade
* brew install portaudio
* pip install pyaudio | try to install using the the below command
```
pip install pyaudio
```
after that install the required Microsoft Visual C++ 14.0
refer the below image for the same.
[](https://i.stack.imgur.com/FFtJ5.jpg)
and restart the system and run the same co... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | You don't need to compile pyaudio. To [install PyAudio](https://people.csail.mit.edu/hubert/pyaudio/#downloads), run:
```
$ sudo add-apt-repository universe
$ sudo apt-get install python-pyaudio python3-pyaudio
```
The first command [enables Universe Ubuntu repository](https://askubuntu.com/q/148638/3712).
If you w... | I have found the work arround for mac.
please refer the below steps to install pyaudio on python 3.5
Follow these steps :
* export HOMEBREW\_NO\_ENV\_FILTERING=1
* xcode-select --install
* brew update
* brew upgrade
* brew install portaudio
* pip install pyaudio |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | To install the latest version of pyaudio using conda:
```
source activate -your environment name-
pip install pyaudio
```
You may run into the following error when installing from pip:
```
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
compilation termin... | You don't need to compile pyaudio. To [install PyAudio](https://people.csail.mit.edu/hubert/pyaudio/#downloads), run:
```
$ sudo add-apt-repository universe
$ sudo apt-get install python-pyaudio python3-pyaudio
```
The first command [enables Universe Ubuntu repository](https://askubuntu.com/q/148638/3712).
If you w... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | I have found the work arround for mac.
please refer the below steps to install pyaudio on python 3.5
Follow these steps :
* export HOMEBREW\_NO\_ENV\_FILTERING=1
* xcode-select --install
* brew update
* brew upgrade
* brew install portaudio
* pip install pyaudio | Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. To install this p... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | I have found the work arround for mac.
please refer the below steps to install pyaudio on python 3.5
Follow these steps :
* export HOMEBREW\_NO\_ENV\_FILTERING=1
* xcode-select --install
* brew update
* brew upgrade
* brew install portaudio
* pip install pyaudio | I was able to get it install with [anaconda](https://www.continuum.io/downloads), using [this package](https://anaconda.org/bokeh/pyaudio).
Follow install instructions for linux [here](https://www.continuum.io/downloads#_unix), then do:
```
conda install -c bokeh pyaudio=0.2.7
``` |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | You don't need to compile pyaudio. To [install PyAudio](https://people.csail.mit.edu/hubert/pyaudio/#downloads), run:
```
$ sudo add-apt-repository universe
$ sudo apt-get install python-pyaudio python3-pyaudio
```
The first command [enables Universe Ubuntu repository](https://askubuntu.com/q/148638/3712).
If you w... | Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. To install this p... |
32,879,614 | I was following the instructions [here](https://people.csail.mit.edu/hubert/pyaudio/compilation.html) and I'm having trouble getting the installation to work. Basically, the first part works fine. I downloaded portaudio, followed the instructions, and it all seemed to work.
However, when I tried`python3 setup.py insta... | 2015/10/01 | [
"https://Stackoverflow.com/questions/32879614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047641/"
] | To install the latest version of pyaudio using conda:
```
source activate -your environment name-
pip install pyaudio
```
You may run into the following error when installing from pip:
```
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
compilation termin... | Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. To install this p... |
23,507,902 | I use gsutil to transfer files from a Windows machine to Google Cloud Storage.
I have not used it for more than 6 months and now when I try it I get:
Failure: invalid\_grant
From researching this I suspect the access token is no longer valid as it has not been used for 6 months, and I need a refresh token?
I cannot... | 2014/05/07 | [
"https://Stackoverflow.com/questions/23507902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3610488/"
] | You can ask gsutil to configure itself. Go to the directory with gsutil and run this:
```
c:\gsutil> python gsutil config
```
Gsutil will lead you through the steps to setting up your credentials.
That said, access tokens only normally last about a half hour. It's more likely that the previously-configured refresh ... | Brandon Yarbrough gave me suggestions which solved this problem. He suspected that the .boto file was corrupted and suggested I delete it and run gsutil config again. I did this and it solved the problem. |
23,507,902 | I use gsutil to transfer files from a Windows machine to Google Cloud Storage.
I have not used it for more than 6 months and now when I try it I get:
Failure: invalid\_grant
From researching this I suspect the access token is no longer valid as it has not been used for 6 months, and I need a refresh token?
I cannot... | 2014/05/07 | [
"https://Stackoverflow.com/questions/23507902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3610488/"
] | The command to authenticate is now
```
$ gcloud auth login
```
That should refresh your grant and get you going again.
You may also want to run
```
$ gcloud components update
```
to update your installation. | Brandon Yarbrough gave me suggestions which solved this problem. He suspected that the .boto file was corrupted and suggested I delete it and run gsutil config again. I did this and it solved the problem. |
32,775,258 | Trying to write `to_csv` with the following code:
```
file_name = time.strftime("Box_Office_Data_%Y/%m/%d_%H:%M.csv")
allFilms.to_csv(file_name)
```
But am getting the following error:
```
FileNotFoundError Traceback (most recent call last)
<ipython-input-36-aa2d6e13e9af> in <module>()
... | 2015/09/25 | [
"https://Stackoverflow.com/questions/32775258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5314975/"
] | The error is clear -
```
FileNotFoundError: [Errno 2] No such file or directory: 'Box_Office_Data_2015/09/24_22:11.csv'
```
If you get this error when trying to do `.to_csv()` , it means that the directory in which you are trying to save the file does not exist. So in your case, the directory - `Box_Office_Data_2015... | In your code `file_name = time.strftime("Box_Office_Data_%Y/%m/%d_%H:%M.csv")`.
File name was like this `Box_Office_Data_2015/09/24_22:11.csv`, which means a path to a file.
Try to replace the `/` with something like `_`.
Try this:
`file_name = time.strftime("Box_Office_Data_%Y_%m_%d_%H:%M.csv")` |
56,507,997 | I did `!pip install tree` on google colab notebook. It showed that `Pillow in /usr/local/lib/python3.6/dist-packages (from tree) (4.3.0)`. But when I use `!tree`. The notebook reminded me that `bin/bash: tree: command not found`. How to solve it?
I tried several times but all failed.
It showed:
```
Collecting tree
... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56507997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11618792/"
] | You seem to have confused pip with the local package manager?
`!apt-get install tree` does what you want:
```
.
└── sample_data
├── anscombe.json
├── california_housing_test.csv
├── california_housing_train.csv
├── mnist_test.csv
├── mnist_train_small.csv
└── README.md
1 directory, 6 files
`... | I think you have installed wrong tree with pip <https://pypi.org/project/Tree/>
Right code for install on Mac `brew install tree`
```
sudo apt-get install tree
```
the command for Debian / Ubuntu Linux / Mint `sudo apt install tree` |
56,507,997 | I did `!pip install tree` on google colab notebook. It showed that `Pillow in /usr/local/lib/python3.6/dist-packages (from tree) (4.3.0)`. But when I use `!tree`. The notebook reminded me that `bin/bash: tree: command not found`. How to solve it?
I tried several times but all failed.
It showed:
```
Collecting tree
... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56507997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11618792/"
] | You seem to have confused pip with the local package manager?
`!apt-get install tree` does what you want:
```
.
└── sample_data
├── anscombe.json
├── california_housing_test.csv
├── california_housing_train.csv
├── mnist_test.csv
├── mnist_train_small.csv
└── README.md
1 directory, 6 files
`... | also, it's doesn't work for me but here is an alternative code for the tree dictionary
```
import os
for path, dirs, files in os.walk('/content/sample_data'):
print (path)
for f in files:
print (f)
```
[](https://i.stack.imgur.com/dq1eB.png) |
56,507,997 | I did `!pip install tree` on google colab notebook. It showed that `Pillow in /usr/local/lib/python3.6/dist-packages (from tree) (4.3.0)`. But when I use `!tree`. The notebook reminded me that `bin/bash: tree: command not found`. How to solve it?
I tried several times but all failed.
It showed:
```
Collecting tree
... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56507997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11618792/"
] | I think you have installed wrong tree with pip <https://pypi.org/project/Tree/>
Right code for install on Mac `brew install tree`
```
sudo apt-get install tree
```
the command for Debian / Ubuntu Linux / Mint `sudo apt install tree` | also, it's doesn't work for me but here is an alternative code for the tree dictionary
```
import os
for path, dirs, files in os.walk('/content/sample_data'):
print (path)
for f in files:
print (f)
```
[](https://i.stack.imgur.com/dq1eB.png) |
68,160,205 | Before I describe the problem, here is a basic run-down of the overall process to give you a clearer picture. Additionally, I am a novice at PHP:
1. I have a WordPress website that uses CPanel as its web hosting software
2. The WordPress website has a form (made by UFB) that has the user upload an image
3. The image g... | 2021/06/28 | [
"https://Stackoverflow.com/questions/68160205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16332203/"
] | Set the [Request.URL](https://pkg.go.dev/net/http#Request.URL) to an [opaque URL](https://pkg.go.dev/net/url#URL.Opaque). The opaque URL is written to the request line as is.
```
request := &http.Request{
URL: &url.URL{Opaque: "http://127.0.0.1:10019/system?action=add_servers"}
Body: ... | what value of the URL variable?
I think you can define the URL variable use a specific host
```
var url = "http://127.0.0.1:10019/system?action=add_servers"
```
In case your path is dynamic from another variable, you can use `fmt.Sprintf`, like below
```
// assume url value
var path = "/system?action=add_servers"
... |
45,948,854 | I have this situation :
* *File1* named **source.txt**
* *File2* named **destination.txt**
**source.txt** contains these strings:
```
MSISDN=213471001120
MSISDN=213471001121
MSISDN=213471001122
```
I want to see **destination.txt** contains these cases:
MSISDN=213471001120 **only** for First execution of python c... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45948854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6056999/"
] | You have to read the whole file, before writing again, because mode `w` empties the file:
```
with open('source.txt') as lines:
lines = list(lines)
with open('destination.txt', 'w') as first:
first.write(lines[0])
with open('source.txt', 'w') as other:
other.writelines(lines[1:])
``` | You're gonna need an external file to store the state of "how many times have I run before"
```
with open('source.txt', 'r') as source, open('counter.txt', 'r') as counter, open('destination.txt', 'w') as destination:
num_to_read = int(counter.readline().strip())
for _ in range(num_to_read):
line_to_wr... |
45,948,854 | I have this situation :
* *File1* named **source.txt**
* *File2* named **destination.txt**
**source.txt** contains these strings:
```
MSISDN=213471001120
MSISDN=213471001121
MSISDN=213471001122
```
I want to see **destination.txt** contains these cases:
MSISDN=213471001120 **only** for First execution of python c... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45948854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6056999/"
] | You need to compare the current content of `destination.txt` before deciding what to write next.
This code worked for me:
```
#!/usr/bin/env python
file_src = open('source.txt', 'r')
data_src = file_src.readlines()
file_des = open('destination.txt', 'r+') # 'r+' opens file for RW
data_des = file_des.read()
if data... | You're gonna need an external file to store the state of "how many times have I run before"
```
with open('source.txt', 'r') as source, open('counter.txt', 'r') as counter, open('destination.txt', 'w') as destination:
num_to_read = int(counter.readline().strip())
for _ in range(num_to_read):
line_to_wr... |
61,877,065 | I am trying to implement Okapi BM25 in python. While I have seen some tutorials how to do it, it seems I am stuck in the process.
So I have collection of documents (and has as columns 'id' and 'text') and queries (and has as columns 'id' and 'text'). I have done the pre-processing steps and I have my documents and qu... | 2020/05/18 | [
"https://Stackoverflow.com/questions/61877065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13498967/"
] | `**kwargs` expects arguments to be passed by keyword, not by position. Once you do that, you can access the individual kwargs like you would in any other dictionary:
```
class Student:
def __init__(self, **kwargs):
self.name = kwargs.get('name')
self.age = kwargs.get('age')
self.salary = k... | **kwargs** is created as a dictionary inside the scope of the function. You need to pass a keyword which uses them as keys in the dictionary. (Try running the print statement below)
```
class Student:
def __init__(self, **kwargs):
#print(kwargs)
self.name = kwargs["name"]
self.age = kwargs[... |
61,877,065 | I am trying to implement Okapi BM25 in python. While I have seen some tutorials how to do it, it seems I am stuck in the process.
So I have collection of documents (and has as columns 'id' and 'text') and queries (and has as columns 'id' and 'text'). I have done the pre-processing steps and I have my documents and qu... | 2020/05/18 | [
"https://Stackoverflow.com/questions/61877065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13498967/"
] | `**kwargs` expects arguments to be passed by keyword, not by position. Once you do that, you can access the individual kwargs like you would in any other dictionary:
```
class Student:
def __init__(self, **kwargs):
self.name = kwargs.get('name')
self.age = kwargs.get('age')
self.salary = k... | Though you can do this as some of the answers here have shown, this is not really a great idea (at least not for the code you are showing here). So I am not going to answer the subject line question you have asked, but show you what the code you seem to be trying to write should be doing (and that is not using `kwargs`... |
59,596,957 | First, let me say: I know I shouldn't be iterating over a dataframe per:
[How to iterate over rows - Don't!](https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas/55557758#55557758)
[How to iterate over rows...](https://stackoverflow.com/questions/16476924/how-to-iterate-over-... | 2020/01/05 | [
"https://Stackoverflow.com/questions/59596957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/554517/"
] | In short, the answer is the performance benefit of using iterrows. This [post](https://engineering.upside.com/a-beginners-guide-to-optimizing-pandas-code-for-speed-c09ef2c6a4d6) could better explain the differences between the various options. | My problem is that I wanted to create a new column which was the difference of a value in the current row and a value in a prior row without using iteration.
I think the more "panda-esque" way of doing this (without iteration) would be to use dataframe.shift() to create a new column which contains the prior rows data ... |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | I had the same problem, probably you have installed numpy without Anaconda, so there is a conflict because of this, which numpy to use: that one installed with pip or with conda. When I removed non-Anaconda numpy, error gone.
```
pip uninstall numpy
``` | First remove `numpy` from `/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-x86_64.egg`
and then use the following command
`sudo pip install numpy scipy`
I had solve this error in my case. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | For cython users:
[This](https://github.com/numpy/numpy/issues/8415) post was helpful. The post explains, that there is some flag (--with-fpectl), which is either set during the compilation of cpython or not. When a library has been compiled using a cpython without that flag, it is incompatible to a version with that... | First remove `numpy` from `/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-x86_64.egg`
and then use the following command
`sudo pip install numpy scipy`
I had solve this error in my case. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | For cython users:
[This](https://github.com/numpy/numpy/issues/8415) post was helpful. The post explains, that there is some flag (--with-fpectl), which is either set during the compilation of cpython or not. When a library has been compiled using a cpython without that flag, it is incompatible to a version with that... | I agree with previous posts that this seems to be caused by having multiple versions of numpy installed. For me, it wasn't enough to just use pip, as I also had multiple versions of pip installed.
Specifying the specific pip solved the problem:
```
/usr/bin/pip3 uninstall numpy
``` |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | I had the same problem, probably you have installed numpy without Anaconda, so there is a conflict because of this, which numpy to use: that one installed with pip or with conda. When I removed non-Anaconda numpy, error gone.
```
pip uninstall numpy
``` | Initially, I installed cython using system /usr/bin/pip and anconda pip. I uninstalled system cython using system pip and reinstalled using
`conda install cython`. Works now. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | I agree with previous posts that this seems to be caused by having multiple versions of numpy installed. For me, it wasn't enough to just use pip, as I also had multiple versions of pip installed.
Specifying the specific pip solved the problem:
```
/usr/bin/pip3 uninstall numpy
``` | First remove `numpy` from `/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-x86_64.egg`
and then use the following command
`sudo pip install numpy scipy`
I had solve this error in my case. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | For cython users:
[This](https://github.com/numpy/numpy/issues/8415) post was helpful. The post explains, that there is some flag (--with-fpectl), which is either set during the compilation of cpython or not. When a library has been compiled using a cpython without that flag, it is incompatible to a version with that... | Initially, I installed cython using system /usr/bin/pip and anconda pip. I uninstalled system cython using system pip and reinstalled using
`conda install cython`. Works now. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | irony at it's best, i restarted my laptop without doing nothing, and it worked. Can't understand why. | I ran into this problem in a particular situation. Using **Anaconda** (3 I think) I was creating a new environment. Previously I had created a py3 env with numpy, Not sure if related. But when creating my new py2.7 environment I went to install a particular package Ta-lib via pip, but then had this same Question's impo... |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | irony at it's best, i restarted my laptop without doing nothing, and it worked. Can't understand why. | Initially, I installed cython using system /usr/bin/pip and anconda pip. I uninstalled system cython using system pip and reinstalled using
`conda install cython`. Works now. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | I had the same problem, probably you have installed numpy without Anaconda, so there is a conflict because of this, which numpy to use: that one installed with pip or with conda. When I removed non-Anaconda numpy, error gone.
```
pip uninstall numpy
``` | irony at it's best, i restarted my laptop without doing nothing, and it worked. Can't understand why. |
36,190,757 | I am trying to use the One Million Song Dataset, for this i had to install python tables, numpy, cython, hdf5, numexpr, and so.
Yesterday i managed to install all i needed, and after having some troubles with hdf5, i downloaded the precompiled binary packages and saved them in my /bin folder, and the respective libra... | 2016/03/23 | [
"https://Stackoverflow.com/questions/36190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2869143/"
] | irony at it's best, i restarted my laptop without doing nothing, and it worked. Can't understand why. | First remove `numpy` from `/usr/local/lib/python2.7/dist-packages/numpy-1.11.0-py2.7-linux-x86_64.egg`
and then use the following command
`sudo pip install numpy scipy`
I had solve this error in my case. |
59,227,170 | i run a python program using `beautifulsoup` and `requests` to scrape embedded videos URL , but to download theses videos i need to bypass a ads popups and `javascript` reload only then the `m3u8` files start to appear in the network traffic;
so i need to simulate the clicks to get to the `javascript` reload (if there... | 2019/12/07 | [
"https://Stackoverflow.com/questions/59227170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12496538/"
] | There is no rule against using selenium side by side with beautifulsoup and requests. You can use the selenium to bypass the clicks, popups and ads and use beautifulsoup and requests to download the videos after the urls have appeared. You can redirect selenium to different urls using the results you get from running a... | >
> Blockquote
> `i run a python program using beautifulsoup and requests to scrape embedded videos URL , but to download theses videos i need to bypass a ads popups and javascript reload only then the m3u8 files start to appear in the network traffic;
>
>
>
so i need to simulate the clicks to get to the javascri... |
24,853,027 | I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran `django-admin.py startproject test123`, switched to `test123` directory, and ran the command `python manage.py runserver`, then i get this:
```
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_... | 2014/07/20 | [
"https://Stackoverflow.com/questions/24853027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637619/"
] | Followed this SO answer:
[Uninstall python.org version of python2.7 in favor of default OS X python2.7](https://stackoverflow.com/questions/13538586/uninstall-python-org-version-of-python2-7-in-favor-of-default-os-x-python2-7)
Then changed my `.bash_profile` Python path to `/usr/lib/python` for the default OSX python... | You most likely have another file named `operator.py` on your `PYTHONPATH` (probably in the current working directory), which shadows the standard library `operator` module..
Remove or rename the file. |
24,853,027 | I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran `django-admin.py startproject test123`, switched to `test123` directory, and ran the command `python manage.py runserver`, then i get this:
```
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_... | 2014/07/20 | [
"https://Stackoverflow.com/questions/24853027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637619/"
] | I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
```
virtualenv -p /usr/bin/python2.7 venv
```
startproject was working again. | You most likely have another file named `operator.py` on your `PYTHONPATH` (probably in the current working directory), which shadows the standard library `operator` module..
Remove or rename the file. |
24,853,027 | I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran `django-admin.py startproject test123`, switched to `test123` directory, and ran the command `python manage.py runserver`, then i get this:
```
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_... | 2014/07/20 | [
"https://Stackoverflow.com/questions/24853027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637619/"
] | Followed this SO answer:
[Uninstall python.org version of python2.7 in favor of default OS X python2.7](https://stackoverflow.com/questions/13538586/uninstall-python-org-version-of-python2-7-in-favor-of-default-os-x-python2-7)
Then changed my `.bash_profile` Python path to `/usr/lib/python` for the default OSX python... | For those not wanting to switch to Apple's python, simply [deleting the virtualenv and rebuilding it](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=749491#10) worked fine for me.
Tip: Don't forget to `pip freeze > requirements.txt` first if you aren't already tracking your package requirements. That way you can `... |
24,853,027 | I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran `django-admin.py startproject test123`, switched to `test123` directory, and ran the command `python manage.py runserver`, then i get this:
```
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_... | 2014/07/20 | [
"https://Stackoverflow.com/questions/24853027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637619/"
] | Followed this SO answer:
[Uninstall python.org version of python2.7 in favor of default OS X python2.7](https://stackoverflow.com/questions/13538586/uninstall-python-org-version-of-python2-7-in-favor-of-default-os-x-python2-7)
Then changed my `.bash_profile` Python path to `/usr/lib/python` for the default OSX python... | I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
```
virtualenv -p /usr/bin/python2.7 venv
```
startproject was working again. |
24,853,027 | I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran `django-admin.py startproject test123`, switched to `test123` directory, and ran the command `python manage.py runserver`, then i get this:
```
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_... | 2014/07/20 | [
"https://Stackoverflow.com/questions/24853027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637619/"
] | I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
```
virtualenv -p /usr/bin/python2.7 venv
```
startproject was working again. | For those not wanting to switch to Apple's python, simply [deleting the virtualenv and rebuilding it](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=749491#10) worked fine for me.
Tip: Don't forget to `pip freeze > requirements.txt` first if you aren't already tracking your package requirements. That way you can `... |
45,718,546 | In python 3, you can now open a file safely using the `with` clause like this:
```
with open("stuff.txt") as f:
data = f.read()
```
Using this method, I don't need to worry about closing the connection
I was wondering if I could do the same for the multiprocessing. For example, my current code looks like:
```... | 2017/08/16 | [
"https://Stackoverflow.com/questions/45718546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2208112/"
] | ```
with multiprocessing.Pool( ... ) as pool:
pool.starmap( ... )
```
<https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool>
>
> New in version 3.3: Pool objects now support the context management protocol – see Context Manager Types. **enter**() returns the pool object, and **exit**... | Although its more than what the OP asked, if you want something that will work for both Python 2 and Python 3, you can use:
```py
# For python 2/3 compatibility, define pool context manager
# to support the 'with' statement in Python 2
if sys.version_info[0] == 2:
from contextlib import contextmanager
@context... |
48,512,269 | Hi guys I am trying to read from subprocess.PIPE without blocking the main process. I have found this code:
```
import sys
from subprocess import PIPE, Popen
from threading import Thread
try:
from Queue import Queue, Empty
except ImportError:
from queue import Queue, Empty # python 3.x
ON_POSIX = 'posix' i... | 2018/01/30 | [
"https://Stackoverflow.com/questions/48512269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7395188/"
] | I was away from my project for a long time but finally I manged to solve the issue.
```
from subprocess import PIPE, Popen
from threading import Thread
p = Popen(['myprogram.exe'], stdout=PIPE)
t = Thread(target=results)
t.daemon = True
t.start()
def results():
a = p.stdout.readline()
```
Maybe this is not ex... | On a unix environment you can simply make the stdout/stderr/stdin file descriptors nonblocking like so:
```
import os, fcntl
from subprocess import Popen, PIPE
def nonblock(stream):
fcntl.fcntl(stream, fcntl.F_SETFL, fcntl.fcntl(stream, fcntl.F_GETFL) | os.O_NONBLOCK)
proc = Popen("for ((;;)) { date; sleep 1; }"... |
28,371,555 | I have written this script to test a single ip address for probing specific user names on smtp servers for a pentest. I am trying now to port this script to run the same tests, but to a range of ip addresses instead of a single one. Can anyone shed some light as to how that can be achieved?
```
#!/usr/bin/python
impo... | 2015/02/06 | [
"https://Stackoverflow.com/questions/28371555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4283164/"
] | I would implement this by turning your code as it stands into a function to probe a single host, taking the host name/ip as an argument. Then, loop over your list of hosts (either from the command line, a file, interactive querying of a user, or wherever) and make a call to your single host probe for each host in the l... | Ok, so here is what I have done to get this going.
The solution is not elegant at all but it does the trick, and also, I could not spend more time trying to find a solution on this purely in Python, so I have decided, after reading the answer from bmhkim above(thanks for the tips) to write a bash script to have it ite... |
28,371,555 | I have written this script to test a single ip address for probing specific user names on smtp servers for a pentest. I am trying now to port this script to run the same tests, but to a range of ip addresses instead of a single one. Can anyone shed some light as to how that can be achieved?
```
#!/usr/bin/python
impo... | 2015/02/06 | [
"https://Stackoverflow.com/questions/28371555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4283164/"
] | If you're using Python3.3+, this is mostly simple
```
import ipaddress # new in Python3.3
start_ip, end_ip = however_you_get_these_as_strings()
ip_networks = ipaddress.summarize_address_range(
ipaddress.IPv4Address(start_ip),
ipaddress.IPv4Address(end_ip))
# list of networks between... | Ok, so here is what I have done to get this going.
The solution is not elegant at all but it does the trick, and also, I could not spend more time trying to find a solution on this purely in Python, so I have decided, after reading the answer from bmhkim above(thanks for the tips) to write a bash script to have it ite... |
57,331,667 | I'm using `poetry` library to manage project dependencies, so when I use
`docker build --tag=helloworld .`
I got this error
```
[AttributeError]
'NoneType' object has no attribute 'group'
```
Installing breaks on `umongo (2.1.0)` package
Here is my `pyproject.toml` file
```
[tool.poetry.dependen... | 2019/08/02 | [
"https://Stackoverflow.com/questions/57331667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6804296/"
] | The following works for me:
```
FROM python:3.7.1-alpine
WORKDIR /opt/project
RUN pip install --upgrade pip && pip --no-cache-dir install poetry
COPY ./pyproject.toml .
RUN poetry install --no-dev
```
with pyproject.toml:
```
[tool.poetry]
name = "57331667"
version = "0.0.1"
authors = ["skufler <[email protected]... | If you want to install it with pip3 in production, here's how the latest version of Poetry (late 2021) can export a requirements.txt file:
```sh
# Production with no development dependencies
poetry export --no-interaction --no-ansi --without-hashes --format requirements.txt --output ./requirements.prod.txt
# For deve... |
57,331,667 | I'm using `poetry` library to manage project dependencies, so when I use
`docker build --tag=helloworld .`
I got this error
```
[AttributeError]
'NoneType' object has no attribute 'group'
```
Installing breaks on `umongo (2.1.0)` package
Here is my `pyproject.toml` file
```
[tool.poetry.dependen... | 2019/08/02 | [
"https://Stackoverflow.com/questions/57331667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6804296/"
] | Alternative approach
--------------------
Don't install `poetry` into your deployment environment. It's a package management tool, which aims to improve development of and collaboration on libraries. If you want to deploy an application, you only need a package installer (read: `pip`) - and the opinionated stance of `... | If you want to install it with pip3 in production, here's how the latest version of Poetry (late 2021) can export a requirements.txt file:
```sh
# Production with no development dependencies
poetry export --no-interaction --no-ansi --without-hashes --format requirements.txt --output ./requirements.prod.txt
# For deve... |
48,301,318 | I have a Python script where I import `datadog` module. When I run `python datadog.py`, it fails with `ImportError: cannot import name statsd`. The script starts with following lines:
```
import os
import mysql.connector
from time import time
from datadog import statsd
```
Actual error messages are following:
```
... | 2018/01/17 | [
"https://Stackoverflow.com/questions/48301318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8495751/"
] | The problem is that your script is named `datadog.py`. So when it imports the module `datadog`, it imports itself. | First install statsd by
```
pip install statsd
```
then do
```
import statsd
``` |
69,970,902 | s =[(1, 2), (2, 3), (3, 4), (1, 3)]
Output should be:
1 2
2 3
3 4
1 3
#in python only
**"WITHOUT USING FOR LOOP"**
In below code
```
ns=[[4, 4], [5, 4], [3, 3]]
for x in ns:
n=x[0]
m=x[1]
f=list(range(1,n+1))
l=list(range(2,n+1))
permut = itertools.permutations(f, 2)
permut=list(permut)... | 2021/11/15 | [
"https://Stackoverflow.com/questions/69970902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17415916/"
] | I had this issue last night, tried with php 7.3 and 7.4 in the end i just used the latest php 8.1 and this issue went away. | You could try going to `illuminate/log/Logger.php` and adding `use Monolog\Logger as Monolog;` at the beginning of the file. After that, change the constructor from this:
```
/**
* Create a new log writer instance.
*
* @param \Psr\Log\LoggerInterface $logger
* @param \Illuminate\Contracts\Ev... |
14,142,144 | I have a custom field located in my `/app/models.py` . My question is...
What is the best practice here. Should I have a separate file i.e. `customField.py` and import to the `models.py`, or should it be all in the same `models.py` file?
best practice
```
class HibernateBooleanField(models.BooleanField):
__meta... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14142144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/578822/"
] | If you're on Oracle 11g you can use the DBMS\_PARALLEL\_EXECUTE package to run your procedure in multiple threads. [Find out more](http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_parallel_ex.htm#CHDIJACH).
If you're on an earlier version you can implement DIY parallelism using a technique from Tom Kyte. The H... | Sounds like you need a set of queries using the MySql `LIMIT` clause to implement paging (e.g. a query would get the first 1000, another would get the second 1000 etc..).
You could form these queries and submit as `Callables` to an [Executor service](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Ex... |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code -
```
from email import Encoders
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def sendmail(to, subject, text, att... | below formate worked for me
>
> EMAIL\_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>
>
> EMAIL\_USE\_TLS = True EMAIL\_HOST = 'mail.xxxxxxx.xxx'
>
>
> EMAIL\_PORT = 465
>
>
> EMAIL\_HOST\_USER = '[email protected]'
>
>
> EMAIL\_HOST\_PASSWORD = 'xxxxxxx'
>
>
> |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | I use Gmail as my SMTP server for Django. Much easier than dealing with postfix or whatever other server. I'm not in the business of managing email servers.
In settings.py:
```
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
```
*... | You could use **"Test Mail Server Tool"** to test email sending on your machine or localhost. Google and Download "Test Mail Server Tool" and set it up.
Then in your settings.py:
```
EMAIL_BACKEND= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
```
From shell:
```
from djang... |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | I found using SendGrid to be the easiest way to set up sending email with Django. Here's how it works:
1. [Create a SendGrid account](https://app.sendgrid.com/signup) (and verify your email)
2. Add the following to your `settings.py`:
`EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = '<your sendgrid username>'
EMAIL... | below formate worked for me
>
> EMAIL\_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
>
>
> EMAIL\_USE\_TLS = True EMAIL\_HOST = 'mail.xxxxxxx.xxx'
>
>
> EMAIL\_PORT = 465
>
>
> EMAIL\_HOST\_USER = '[email protected]'
>
>
> EMAIL\_HOST\_PASSWORD = 'xxxxxxx'
>
>
> |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | 1. Create a project: `django-admin.py startproject gmail`
2. Edit settings.py with code below:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'email_password'
EMAIL_PORT = 587
```
3. Run... | You could use **"Test Mail Server Tool"** to test email sending on your machine or localhost. Google and Download "Test Mail Server Tool" and set it up.
Then in your settings.py:
```
EMAIL_BACKEND= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
```
From shell:
```
from djang... |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | For Django version 1.7, if above solutions dont work then try the following
in **settings.py** add
```
#For email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
#Must generate specific password for your app in [... | You could use **"Test Mail Server Tool"** to test email sending on your machine or localhost. Google and Download "Test Mail Server Tool" and set it up.
Then in your settings.py:
```
EMAIL_BACKEND= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
```
From shell:
```
from djang... |
6,367,014 | In my `settings.py`, I have the following:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'localhost'
# Port for sending e-mail.
EMAIL_PORT = 1025
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAI... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6367014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/749477/"
] | 1. Create a project: `django-admin.py startproject gmail`
2. Edit settings.py with code below:
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'email_password'
EMAIL_PORT = 587
```
3. Run... | I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code -
```
from email import Encoders
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def sendmail(to, subject, text, att... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.