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 |
|---|---|---|---|---|---|
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | Well it's shorter to just present the code than to explain:
```
#include <iostream> // std::wcout, std::endl
#include <string> // std::string
#include <utility> // std::begin, std::end
#include <vector>
using namespace std;
string sum( char const a, char const b ) { return string() + a + b;... | You could certainly make this generic:
```
template <class InIt1, class InIt2, class OutIt>
void cross_product(InIt1 b1, InIt1 e1, InIt2 b2, InIt2 e2, OutIt out) {
for (auto i=b1; i != e1; ++i)
for (auto j=b2; j != e2; ++j)
*out++ = std::make_pair(*i, *j);
}
```
Note that you don't genera... |
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | Weirdly enough, `cross_product` is missing from the C++ algorithms library. It can easily be added but as Jerry’s and Alf’s answers show, opinions differ on how to do it best. In fact, I’d do it different still. Jerry’s interface conforms to that of the other C++ algorithms but he didn’t abstract away the cross product... | Well it's shorter to just present the code than to explain:
```
#include <iostream> // std::wcout, std::endl
#include <string> // std::string
#include <utility> // std::begin, std::end
#include <vector>
using namespace std;
string sum( char const a, char const b ) { return string() + a + b;... |
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | Weirdly enough, `cross_product` is missing from the C++ algorithms library. It can easily be added but as Jerry’s and Alf’s answers show, opinions differ on how to do it best. In fact, I’d do it different still. Jerry’s interface conforms to that of the other C++ algorithms but he didn’t abstract away the cross product... | You could certainly make this generic:
```
template <class InIt1, class InIt2, class OutIt>
void cross_product(InIt1 b1, InIt1 e1, InIt2 b2, InIt2 e2, OutIt out) {
for (auto i=b1; i != e1; ++i)
for (auto j=b2; j != e2; ++j)
*out++ = std::make_pair(*i, *j);
}
```
Note that you don't genera... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Your selection list in the first condition of your `if` statement is the problem.
If `opt` happens to be `es`, for example, then
```
if opt == 'es':
opt = "ESP:"
```
will change that to `ESP:`.
```
if opt in ["es","la","en","ar","fr"] and extent == "begin":
```
can then never be `True` (when you're using `an... | **AND**
To become condition True by **AND Operator**, required **True** result from the **all conditions**.
**OR**
To become condition True by **OR Operator**, required **True** result from the any **one condition**.
**E.g.**
```
In [1]: True and True
Out[1]: True
In [2]: True and False
Out[2]: False
In [3]: Tru... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Unless the output from the first line of code is `"ar"` or `"fr"` (or something else not in the `if-elif` conditions), you are over-writing the `opt` variable. Consider re-naming the 'new' `opt` to something else, like follows:
```
opt = child.get('desc')
extent = child.get('extent')
if opt == 'es':
opt2 = "ESP:... | **AND**
To become condition True by **AND Operator**, required **True** result from the **all conditions**.
**OR**
To become condition True by **OR Operator**, required **True** result from the any **one condition**.
**E.g.**
```
In [1]: True and True
Out[1]: True
In [2]: True and False
Out[2]: False
In [3]: Tru... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | **AND**
To become condition True by **AND Operator**, required **True** result from the **all conditions**.
**OR**
To become condition True by **OR Operator**, required **True** result from the any **one condition**.
**E.g.**
```
In [1]: True and True
Out[1]: True
In [2]: True and False
Out[2]: False
In [3]: Tru... | This is an operator precedence problem. You expect the code to work as:
```
if (opt in ["es","la","en","ar","fr"]) and (extent == "begin"):
print time, opt+(" " + opt).join([c.encode('latin-1') for c in child.tail.split(' ')])
```
But it works as
```
if opt in (["es","la","en","ar","fr"] and extent == "begin"):... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Unless the output from the first line of code is `"ar"` or `"fr"` (or something else not in the `if-elif` conditions), you are over-writing the `opt` variable. Consider re-naming the 'new' `opt` to something else, like follows:
```
opt = child.get('desc')
extent = child.get('extent')
if opt == 'es':
opt2 = "ESP:... | Your selection list in the first condition of your `if` statement is the problem.
If `opt` happens to be `es`, for example, then
```
if opt == 'es':
opt = "ESP:"
```
will change that to `ESP:`.
```
if opt in ["es","la","en","ar","fr"] and extent == "begin":
```
can then never be `True` (when you're using `an... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Your selection list in the first condition of your `if` statement is the problem.
If `opt` happens to be `es`, for example, then
```
if opt == 'es':
opt = "ESP:"
```
will change that to `ESP:`.
```
if opt in ["es","la","en","ar","fr"] and extent == "begin":
```
can then never be `True` (when you're using `an... | When `opt` is one of these: `"es", "la", "en"`
then the value of `opt` is changed, and this:
`if opt in ["es","la","en","ar","fr"] and extent == "begin":`
won't pass, because `opt` is wrong.
I guess `extent` is equal `"begin"`, so if u swap `and` with `or` it will pass, as one of the statements is correct. ... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Your selection list in the first condition of your `if` statement is the problem.
If `opt` happens to be `es`, for example, then
```
if opt == 'es':
opt = "ESP:"
```
will change that to `ESP:`.
```
if opt in ["es","la","en","ar","fr"] and extent == "begin":
```
can then never be `True` (when you're using `an... | This is an operator precedence problem. You expect the code to work as:
```
if (opt in ["es","la","en","ar","fr"]) and (extent == "begin"):
print time, opt+(" " + opt).join([c.encode('latin-1') for c in child.tail.split(' ')])
```
But it works as
```
if opt in (["es","la","en","ar","fr"] and extent == "begin"):... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Unless the output from the first line of code is `"ar"` or `"fr"` (or something else not in the `if-elif` conditions), you are over-writing the `opt` variable. Consider re-naming the 'new' `opt` to something else, like follows:
```
opt = child.get('desc')
extent = child.get('extent')
if opt == 'es':
opt2 = "ESP:... | When `opt` is one of these: `"es", "la", "en"`
then the value of `opt` is changed, and this:
`if opt in ["es","la","en","ar","fr"] and extent == "begin":`
won't pass, because `opt` is wrong.
I guess `extent` is equal `"begin"`, so if u swap `and` with `or` it will pass, as one of the statements is correct. ... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | Unless the output from the first line of code is `"ar"` or `"fr"` (or something else not in the `if-elif` conditions), you are over-writing the `opt` variable. Consider re-naming the 'new' `opt` to something else, like follows:
```
opt = child.get('desc')
extent = child.get('extent')
if opt == 'es':
opt2 = "ESP:... | This is an operator precedence problem. You expect the code to work as:
```
if (opt in ["es","la","en","ar","fr"]) and (extent == "begin"):
print time, opt+(" " + opt).join([c.encode('latin-1') for c in child.tail.split(' ')])
```
But it works as
```
if opt in (["es","la","en","ar","fr"] and extent == "begin"):... |
30,884,008 | I have files with code that is formatted for windows. when I try to run them on linux machine i have problem with file encodings. Can anybody suggest a solution for this
on Windows when I run I get -
```
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python... | 2015/06/17 | [
"https://Stackoverflow.com/questions/30884008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943862/"
] | When `opt` is one of these: `"es", "la", "en"`
then the value of `opt` is changed, and this:
`if opt in ["es","la","en","ar","fr"] and extent == "begin":`
won't pass, because `opt` is wrong.
I guess `extent` is equal `"begin"`, so if u swap `and` with `or` it will pass, as one of the statements is correct. ... | This is an operator precedence problem. You expect the code to work as:
```
if (opt in ["es","la","en","ar","fr"]) and (extent == "begin"):
print time, opt+(" " + opt).join([c.encode('latin-1') for c in child.tail.split(' ')])
```
But it works as
```
if opt in (["es","la","en","ar","fr"] and extent == "begin"):... |
17,559,257 | I am using the following code to send email from unix.
Code
```
#!/usr/bin/python
import os
def sendMail():
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s\n" % "[email protected]")
p.write("To: %s\n" % "[email protected]... | 2013/07/09 | [
"https://Stackoverflow.com/questions/17559257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392233/"
] | Sendmail is an extremely simplistic program. It knows how to send a blob of text over smtp. If you want to have attachments, you're going to have to do the work of converting them into a blob of text and using (in your example) p.write() to add them into the message.
That's hard - but you can use the `email` module (p... | I normally use the following to send a file "file\_name.dat" as attachment:
```
uuencode file_name.dat file_name.dat | mail -s "Subject line" [email protected]
``` |
17,559,257 | I am using the following code to send email from unix.
Code
```
#!/usr/bin/python
import os
def sendMail():
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s\n" % "[email protected]")
p.write("To: %s\n" % "[email protected]... | 2013/07/09 | [
"https://Stackoverflow.com/questions/17559257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392233/"
] | Use the `email.mime` package to create your mail instead of trying to generate it manually, it will save you a lot of trouble.
For example, sending a text message with an attachment could be as simple as:
```
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.applicati... | I normally use the following to send a file "file\_name.dat" as attachment:
```
uuencode file_name.dat file_name.dat | mail -s "Subject line" [email protected]
``` |
58,880,450 | How might I remove duplicate lines from a file and also the unique related to this duplicate?
**Example:**
Input file:
```
line 1 : Messi , 1
line 2 : Messi , 2
line 3 : CR7 , 2
```
I want the output file to be:
```
line 1 : CR7 , 2
```
Just ( " CR7 , 2 " I want to delete duplicate lines and also... | 2019/11/15 | [
"https://Stackoverflow.com/questions/58880450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12379359/"
] | Have you tried `Counter`?
This works for example:
```
import collections
a = [1, 1, 2]
out = [k for k, v in collections.Counter(a).items() if v == 1]
print(out)
```
Output: `[2]`
Or with a longer example:
```
import collections
a = [1, 1, 1, 2, 4, 4, 4, 5, 3]
out = [k for k, v in collections.Counter(a).items() ... | Given your input you can do something like this:
```
seen = {} # key maps to index
double_seen = set()
with open('input.txt') as f:
for line in f:
_, key = line.split(':')
key = key.strip()
if key not in seen: # Have not seen this yet?
seen[key] = line # Then add it to the dict... |
67,194,174 | I want to write a python code were the output will be something like this
[[1],[1,2],[1,2,3], … [1,2,3, … ]]
I have this code and has the similar output but the only difference is that it prints all the cases
for example
if I say that the range is 3 it prints
[[1], [1, 2], [1, 3], [1, 2, 3]]
and not
[[1], [1, 2], [1, 2... | 2021/04/21 | [
"https://Stackoverflow.com/questions/67194174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13300391/"
] | How about using `list comprehension`?
For example:
```
num = 3
print([[*range(1, i + 1)] for i in range(1, num + 1)])
```
Output:
```
[[1], [1, 2], [1, 2, 3]]
``` | You should not use a loop inside loops if you intend to add a single number at the end of it only.
```
def copyBase(lst):
return lst[:]
def sub_lists(l):
base = [1]
lists = []
for i in range(1, l+1):
lists += [copyBase(base),]
base += [i+1]
return lists
num=int(input("Please give... |
67,194,174 | I want to write a python code were the output will be something like this
[[1],[1,2],[1,2,3], … [1,2,3, … ]]
I have this code and has the similar output but the only difference is that it prints all the cases
for example
if I say that the range is 3 it prints
[[1], [1, 2], [1, 3], [1, 2, 3]]
and not
[[1], [1, 2], [1, 2... | 2021/04/21 | [
"https://Stackoverflow.com/questions/67194174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13300391/"
] | *output will be something like this [[1],[1,2],[1,2,3], … [1,2,3, … ]]*
You might combine `range` with `list` comprehension to get desired result, for example for 5:
```
n = 5
sublists = [list(range(1,i+1)) for i in range(1,n+1)]
print(sublists)
```
output
```
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]... | You should not use a loop inside loops if you intend to add a single number at the end of it only.
```
def copyBase(lst):
return lst[:]
def sub_lists(l):
base = [1]
lists = []
for i in range(1, l+1):
lists += [copyBase(base),]
base += [i+1]
return lists
num=int(input("Please give... |
67,194,174 | I want to write a python code were the output will be something like this
[[1],[1,2],[1,2,3], … [1,2,3, … ]]
I have this code and has the similar output but the only difference is that it prints all the cases
for example
if I say that the range is 3 it prints
[[1], [1, 2], [1, 3], [1, 2, 3]]
and not
[[1], [1, 2], [1, 2... | 2021/04/21 | [
"https://Stackoverflow.com/questions/67194174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13300391/"
] | How about using `list comprehension`?
For example:
```
num = 3
print([[*range(1, i + 1)] for i in range(1, num + 1)])
```
Output:
```
[[1], [1, 2], [1, 2, 3]]
``` | Try this
```
def sub_lists(l):
lists = []
for i in range(l):
sublist = [1]
for i2 in range(i):
sublist.append(i2+2)
lists.append(sublist)
return lists
```
**Implementation With User Input**
```
def sub_lists(l):
lists = []
for i in range(l):
sublist = ... |
67,194,174 | I want to write a python code were the output will be something like this
[[1],[1,2],[1,2,3], … [1,2,3, … ]]
I have this code and has the similar output but the only difference is that it prints all the cases
for example
if I say that the range is 3 it prints
[[1], [1, 2], [1, 3], [1, 2, 3]]
and not
[[1], [1, 2], [1, 2... | 2021/04/21 | [
"https://Stackoverflow.com/questions/67194174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13300391/"
] | *output will be something like this [[1],[1,2],[1,2,3], … [1,2,3, … ]]*
You might combine `range` with `list` comprehension to get desired result, for example for 5:
```
n = 5
sublists = [list(range(1,i+1)) for i in range(1,n+1)]
print(sublists)
```
output
```
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]... | Try this
```
def sub_lists(l):
lists = []
for i in range(l):
sublist = [1]
for i2 in range(i):
sublist.append(i2+2)
lists.append(sublist)
return lists
```
**Implementation With User Input**
```
def sub_lists(l):
lists = []
for i in range(l):
sublist = ... |
58,105,181 | I'm using databricks-connect on mac using pycharm but after I finished the configuration and tried to run `databricks-connect test`, I got the following error and have no idea what the problem is. I followed this documentation: <https://docs.databricks.com/user-guide/dev-tools/db-connect.html>
The error message is as ... | 2019/09/25 | [
"https://Stackoverflow.com/questions/58105181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6279751/"
] | Maybe your Java/Python version does not comply. Check your cluster, which Python version does it use (in my case it was 3.5).
And what's most important: check which JDK version do you have on your computer.
In my case, I've had the latest one, which was not supported by `databricks-connect`. It needs to run on JDK 8. | To ignore the RUNTIME version, export an environment variable that resolves:
export DEBUG\_IGNORE\_VERSION\_MISMATCH=1 |
58,105,181 | I'm using databricks-connect on mac using pycharm but after I finished the configuration and tried to run `databricks-connect test`, I got the following error and have no idea what the problem is. I followed this documentation: <https://docs.databricks.com/user-guide/dev-tools/db-connect.html>
The error message is as ... | 2019/09/25 | [
"https://Stackoverflow.com/questions/58105181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6279751/"
] | I would make sure you are using the right version of the Databricks Runtime (DB Connect only currently supports 5.1-5.5). Since these is a limit on the DBR that works with DB connect, you'll have to make sure you match the python version as well (for the base Databricks runtime, I believe it is 3.5.x). | To ignore the RUNTIME version, export an environment variable that resolves:
export DEBUG\_IGNORE\_VERSION\_MISMATCH=1 |
25,331,758 | I am writing a script to start and background a process inside a vagrant machine. It seems like every time the script ends and the ssh session ends, the background process also ends.
Here's the command I am running:
`vagrant ssh -c "cd /vagrant/src; nohup python hello.py > hello.out > 2>&1 &"`
`hello.py` is actually... | 2014/08/15 | [
"https://Stackoverflow.com/questions/25331758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3667561/"
] | I faced the same problem when trying to run Django application as a daemon. I don't know why, but adding a "sleep 1" behind works for me.
```
vagrant ssh -c "nohup python manage.py runserver & sleep 1"
``` | Running nohup inside the ssh command did not work for me when running wireshark. This did:
```
nohup vagrant ssh -c "wireshark" &
``` |
46,901,975 | I am new to this whole python and the data mining.
Let's say I have a list of string called data
```
data[0] = ['I want to make everything lowercase']
data[1] = ['How Do I Do It']
data[2] = ['With A Large DataSet']
```
and so on. My len(data) gives 50000.
I have tried
```
{k.lower(): v for k, v in data.items()}
`... | 2017/10/24 | [
"https://Stackoverflow.com/questions/46901975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4160544/"
] | if your list *data* like this:
```
data = ['I want to make everything lowercase', '', '']
data = [k.lower() for k in data]
```
if your list *data* is a list of string list:
```
data = [['I want to make everything lowercase'], ['']]
data = [[k.lower()] for l in data for k in l]
```
the fact is that list don't has ... | You need a list comprehension, not a dict comprehension:
```
lowercase_data = [v.lower() for v in data]
``` |
65,332,466 | I get a [circular dependency error](https://stackoverflow.com/questions/40705237/django-db-migrations-exceptions-circulardependencyerror) that makes me have to comment out a field. Here is how my models are set up:
```
class Intake(models.Model):
# This field causes a bug on makemigrations. It must be commented wh... | 2020/12/16 | [
"https://Stackoverflow.com/questions/65332466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Ok OP let me do this again, you want to find all the rows which are "A" (base condition) and all the rows which are following a "A" row at some point, right ?
Then,
```
is_A = df["ID"] == "A"
not_A_follows_from_A = (df["ID"] != "A") &( df["ID"].shift() == "A")
candidates = df["ID"].loc[is_A | not_A_follows_from_A].un... | Let us try `drop_duplicates`, then `groupby` select the number of unique ID we would like to keep by `head`, and `merge`
```
out = df.merge(df[['Time','ID']].drop_duplicates().groupby('Time').head(2))
Time ID Val
0 1 A 2.0
1 1 A 5.0
2 1 B 2.5
3 1 B 2.0
4 2 A 1.0
5 2 A 6.0
6 ... |
18,451,694 | e.g. I defined an function which needs several input arguments, if some keyword arguments not being assigned, typically there be an TypeError message, but I want to change it, to output an NaN as the result, could it be done?
```
def myfunc( S0, K ,r....):
if S0 = NaN or .....:
```
How to do it?
Much appreciate... | 2013/08/26 | [
"https://Stackoverflow.com/questions/18451694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2525479/"
] | You can capture the TypeError and do whatever you want with it:
```
def myfunc(a):
try:
return a / 2.5 + 5
except TypeError:
return float('nan')
print myfunc('whatever')
```
[The Python Tutorial](http://docs.python.org/2/tutorial/errors.html) has an excellent chapter on this subject. | ```
def myfunc(S0 = None, K = None, r = None, ....):
if S0 is None or K is None or r is None:
return NaN
``` |
18,451,694 | e.g. I defined an function which needs several input arguments, if some keyword arguments not being assigned, typically there be an TypeError message, but I want to change it, to output an NaN as the result, could it be done?
```
def myfunc( S0, K ,r....):
if S0 = NaN or .....:
```
How to do it?
Much appreciate... | 2013/08/26 | [
"https://Stackoverflow.com/questions/18451694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2525479/"
] | You can capture the TypeError and do whatever you want with it:
```
def myfunc(a):
try:
return a / 2.5 + 5
except TypeError:
return float('nan')
print myfunc('whatever')
```
[The Python Tutorial](http://docs.python.org/2/tutorial/errors.html) has an excellent chapter on this subject. | Yes, to generate a NaN you do `float('nan')`:
```
>>> import math
>> float('nan')
nan
>>> math.isnan(float('nan'))
True
```
So you can `return float('nan')` wherever you want to return the `nan`. I recommend you just raise the exception, though. |
18,451,694 | e.g. I defined an function which needs several input arguments, if some keyword arguments not being assigned, typically there be an TypeError message, but I want to change it, to output an NaN as the result, could it be done?
```
def myfunc( S0, K ,r....):
if S0 = NaN or .....:
```
How to do it?
Much appreciate... | 2013/08/26 | [
"https://Stackoverflow.com/questions/18451694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2525479/"
] | You can capture the TypeError and do whatever you want with it:
```
def myfunc(a):
try:
return a / 2.5 + 5
except TypeError:
return float('nan')
print myfunc('whatever')
```
[The Python Tutorial](http://docs.python.org/2/tutorial/errors.html) has an excellent chapter on this subject. | If you don't want to use TypeError, then how about using AttributeError?
```
def myfunc(a):
try:
return a / 2.5 + 5
except AttributeError:
return float('nan')
print myfunc('whatever')
``` |
68,030,577 | I have obtained 3 lists/arrays in my python script and I am wondering why I am not able to multiply them to values successfully.
```
Array 1: [-0.01896408 -0.0191784 -0.01939271 ... 0.97766441 0.97745009
0.97723578]
Array 2: [ 1.21527999 1.21302709 1.21077419 ... -0.69821075 -0.70046365
-0.70271655]
Array 3: [... | 2021/06/18 | [
"https://Stackoverflow.com/questions/68030577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15233108/"
] | I can't comment so I have to post my comment like this:
As I understand it you try to multiply elements of the "pointsArray" with a scalar.
Have you tried printing
```
array1[i]
```
to see what it looks like? From the error I would guess that this is somehow not just a number, but the entire array. You could for ex... | dot is used for matrix multiplication.
Try this:
```
matrix1.dot(matrix2)
```
A bit more clarity:
If you want to use \*, convert both to numpy.matrix and then try. |
68,030,577 | I have obtained 3 lists/arrays in my python script and I am wondering why I am not able to multiply them to values successfully.
```
Array 1: [-0.01896408 -0.0191784 -0.01939271 ... 0.97766441 0.97745009
0.97723578]
Array 2: [ 1.21527999 1.21302709 1.21077419 ... -0.69821075 -0.70046365
-0.70271655]
Array 3: [... | 2021/06/18 | [
"https://Stackoverflow.com/questions/68030577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15233108/"
] | I guess, what you want to do is as follows:
```
import numpy as np
array1 = np.array([-0.01896408, -0.0191784, -0.01939271, 0.97766441, 0.97745009, 0.97723578])
array2 = np.array([ 1.21527999, 1.21302709, 1.21077419, -0.69821075, -0.70046365, -0.70271655])
array3 = np.array([-0.19631591, -0.1938487, -0.19138148, 0.72... | dot is used for matrix multiplication.
Try this:
```
matrix1.dot(matrix2)
```
A bit more clarity:
If you want to use \*, convert both to numpy.matrix and then try. |
68,030,577 | I have obtained 3 lists/arrays in my python script and I am wondering why I am not able to multiply them to values successfully.
```
Array 1: [-0.01896408 -0.0191784 -0.01939271 ... 0.97766441 0.97745009
0.97723578]
Array 2: [ 1.21527999 1.21302709 1.21077419 ... -0.69821075 -0.70046365
-0.70271655]
Array 3: [... | 2021/06/18 | [
"https://Stackoverflow.com/questions/68030577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15233108/"
] | I guess, what you want to do is as follows:
```
import numpy as np
array1 = np.array([-0.01896408, -0.0191784, -0.01939271, 0.97766441, 0.97745009, 0.97723578])
array2 = np.array([ 1.21527999, 1.21302709, 1.21077419, -0.69821075, -0.70046365, -0.70271655])
array3 = np.array([-0.19631591, -0.1938487, -0.19138148, 0.72... | I can't comment so I have to post my comment like this:
As I understand it you try to multiply elements of the "pointsArray" with a scalar.
Have you tried printing
```
array1[i]
```
to see what it looks like? From the error I would guess that this is somehow not just a number, but the entire array. You could for ex... |
57,487,274 | I have a below API response. This is a very small subset which I am pasting here for reference. there can be 80+ columns on this.
```
[["name","age","children","city", "info"], ["Richard Walter", "35", ["Simon", "Grace"], {"mobile":"yes","house_owner":"no"}],
["Mary", "43", ["Phil", "Marshall", "Emily"], {"mobile":"y... | 2019/08/14 | [
"https://Stackoverflow.com/questions/57487274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11924956/"
] | There are times when using Python seems to be very effective, this might be one of those.
```
df['scores'].apply(lambda x: sum(float(i) if len(x) > 0 else np.nan for i in x.split(',')))
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
``` | You can just do `str.split`
```
df.scores.str.split(',',expand=True).astype(float).sum(1).mask(df.scores.isnull())
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
dtype: float64
``` |
57,487,274 | I have a below API response. This is a very small subset which I am pasting here for reference. there can be 80+ columns on this.
```
[["name","age","children","city", "info"], ["Richard Walter", "35", ["Simon", "Grace"], {"mobile":"yes","house_owner":"no"}],
["Mary", "43", ["Phil", "Marshall", "Emily"], {"mobile":"y... | 2019/08/14 | [
"https://Stackoverflow.com/questions/57487274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11924956/"
] | You can just do `str.split`
```
df.scores.str.split(',',expand=True).astype(float).sum(1).mask(df.scores.isnull())
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
dtype: float64
``` | Another solution using explode, groupby and sum functions:
```
df.scores.str.split(',').explode().astype(float).groupby(level=0).sum(min_count=1)
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
Name: scores, dtype: float64
```
Or to make @WeNYoBen's answer slightly s... |
57,487,274 | I have a below API response. This is a very small subset which I am pasting here for reference. there can be 80+ columns on this.
```
[["name","age","children","city", "info"], ["Richard Walter", "35", ["Simon", "Grace"], {"mobile":"yes","house_owner":"no"}],
["Mary", "43", ["Phil", "Marshall", "Emily"], {"mobile":"y... | 2019/08/14 | [
"https://Stackoverflow.com/questions/57487274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11924956/"
] | There are times when using Python seems to be very effective, this might be one of those.
```
df['scores'].apply(lambda x: sum(float(i) if len(x) > 0 else np.nan for i in x.split(',')))
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
``` | Another solution using explode, groupby and sum functions:
```
df.scores.str.split(',').explode().astype(float).groupby(level=0).sum(min_count=1)
0 NaN
1 NaN
2 0.359982
3 0.359982
4 -0.000646
5 0.003793
6 0.856057
Name: scores, dtype: float64
```
Or to make @WeNYoBen's answer slightly s... |
48,176,802 | I'm very new to work with `xlsxwriter` in python. I have created a scraper in python and it is working flawlessly. However, when I try to write these data in an excel file using `xlsxwriter` I get stuck. What I have written so far can create an excel file and write the last populated data derived from the for loop. How... | 2018/01/09 | [
"https://Stackoverflow.com/questions/48176802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9189799/"
] | 1. Each time through the first `for` loop, you overwrite `data`, so only the last thing assigned survives. This could be addressed by moving your second `for` loop to be inside the first, so it gets called for each value of `data`.
2. If you want things to be in different columns, you need to use different values for `... | As Scott Hunter noted, your overwriting your data, which is stored just fine as a tuple in your data variable. However, it seems like your issue is in your for loop, where you're only adding to row within each block, which explains why your code is traveling only vertically in your spread sheet. Perhaps rearranging thi... |
61,715,377 | So I have a docker project, which is some kind of Python pytest that runs subprocess on an executable file as a blackbox test. I would like to build the container, and then run it each time by copying the executable file to a dedicated folder inside the container WORKDIR (e.g. exec/). But I am not sure how to do it.
... | 2020/05/10 | [
"https://Stackoverflow.com/questions/61715377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4930109/"
] | 'Week' in mysql has 2 inputs: date and week type. By default it's equal 0. That means week starts from sunday. Try this code:
```
SELECT IFNULL(SUM(rendeles_dbszam),0) as eladott_pizzak_szama FROM rendeles WHERE WEEK(rendeles_idopont) = WEEK(CURRENT_DATE(),1)
``` | You can use this little formula to get the Monday starting the week of any given DATE, DATETIME, or TIMESTAMP object.
```
FROM_DAYS(TO_DAYS(datestamp) -MOD(TO_DAYS(datestamp) -2, 7))
```
I like to use it in a stored function named `TRUNC_MONDAY(datestamp)` defined like this.
```
DELIMITER $$
DROP FUNCTION IF EXIST... |
40,920,564 | I am using two different `HTTP POST` utilities ([poster](https://addons.mozilla.org/en-US/firefox/addon/poster/) out of Firefox as well as `Python` [requests](http://docs.python-requests.org/en/master/) API) to post a simple `SPARQL` insert to `Virtuoso`.
My URL is: `http://localhost:8890/sparql`
My request parameter... | 2016/12/01 | [
"https://Stackoverflow.com/questions/40920564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1312080/"
] | I stopped by this question days ago trying to achieve the same with `curl`. Since it is a powerful (and far more convenient) alternative to browser extensions, here is the formulation that eventually proved successful:
```
curl -X POST \
-H "Content-Type:application/sparql-update" \
-H "Accept:text/html" \
... | There are many aspects to this "question" making it difficult to provide a simple answer, suitable to this site. This is one of the reasons I suggested the mailing list, which is better suited to conversational and/or multi-facet assistance.
* Have you tried using `curl` as most of our examples do?
* Looking at the [P... |
40,920,564 | I am using two different `HTTP POST` utilities ([poster](https://addons.mozilla.org/en-US/firefox/addon/poster/) out of Firefox as well as `Python` [requests](http://docs.python-requests.org/en/master/) API) to post a simple `SPARQL` insert to `Virtuoso`.
My URL is: `http://localhost:8890/sparql`
My request parameter... | 2016/12/01 | [
"https://Stackoverflow.com/questions/40920564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1312080/"
] | If you are using python, I would avoid using the `requests` library. There are some dedicated libraries for RDF which abstract the process and make your life easier.
Try:
* [SPARQLWrapper](https://sparqlwrapper.readthedocs.io/en/latest/#)
* [RDFLib](https://rdflib.readthedocs.io/en/stable/#)
[They are both form the ... | There are many aspects to this "question" making it difficult to provide a simple answer, suitable to this site. This is one of the reasons I suggested the mailing list, which is better suited to conversational and/or multi-facet assistance.
* Have you tried using `curl` as most of our examples do?
* Looking at the [P... |
40,920,564 | I am using two different `HTTP POST` utilities ([poster](https://addons.mozilla.org/en-US/firefox/addon/poster/) out of Firefox as well as `Python` [requests](http://docs.python-requests.org/en/master/) API) to post a simple `SPARQL` insert to `Virtuoso`.
My URL is: `http://localhost:8890/sparql`
My request parameter... | 2016/12/01 | [
"https://Stackoverflow.com/questions/40920564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1312080/"
] | I stopped by this question days ago trying to achieve the same with `curl`. Since it is a powerful (and far more convenient) alternative to browser extensions, here is the formulation that eventually proved successful:
```
curl -X POST \
-H "Content-Type:application/sparql-update" \
-H "Accept:text/html" \
... | This seems to be a Virtuoso specific issue. You can only post a query by using content type "application/sparql-update" instead of "application/sparql-query" which is common.
The request is done as follows with Python:
```
headers = {
'Content-Type': 'application/sparql-update',
'Accept': 'app... |
40,920,564 | I am using two different `HTTP POST` utilities ([poster](https://addons.mozilla.org/en-US/firefox/addon/poster/) out of Firefox as well as `Python` [requests](http://docs.python-requests.org/en/master/) API) to post a simple `SPARQL` insert to `Virtuoso`.
My URL is: `http://localhost:8890/sparql`
My request parameter... | 2016/12/01 | [
"https://Stackoverflow.com/questions/40920564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1312080/"
] | I stopped by this question days ago trying to achieve the same with `curl`. Since it is a powerful (and far more convenient) alternative to browser extensions, here is the formulation that eventually proved successful:
```
curl -X POST \
-H "Content-Type:application/sparql-update" \
-H "Accept:text/html" \
... | If you are using python, I would avoid using the `requests` library. There are some dedicated libraries for RDF which abstract the process and make your life easier.
Try:
* [SPARQLWrapper](https://sparqlwrapper.readthedocs.io/en/latest/#)
* [RDFLib](https://rdflib.readthedocs.io/en/stable/#)
[They are both form the ... |
40,920,564 | I am using two different `HTTP POST` utilities ([poster](https://addons.mozilla.org/en-US/firefox/addon/poster/) out of Firefox as well as `Python` [requests](http://docs.python-requests.org/en/master/) API) to post a simple `SPARQL` insert to `Virtuoso`.
My URL is: `http://localhost:8890/sparql`
My request parameter... | 2016/12/01 | [
"https://Stackoverflow.com/questions/40920564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1312080/"
] | If you are using python, I would avoid using the `requests` library. There are some dedicated libraries for RDF which abstract the process and make your life easier.
Try:
* [SPARQLWrapper](https://sparqlwrapper.readthedocs.io/en/latest/#)
* [RDFLib](https://rdflib.readthedocs.io/en/stable/#)
[They are both form the ... | This seems to be a Virtuoso specific issue. You can only post a query by using content type "application/sparql-update" instead of "application/sparql-query" which is common.
The request is done as follows with Python:
```
headers = {
'Content-Type': 'application/sparql-update',
'Accept': 'app... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | Another symptom of this problem for me was if I went into the python console of my virtualenv and did `import ssl` it would error out. Turns out my virtualenv wasn't using the `brew` version of python, just the default install on my machine. No clue why the default install suddenly stopped working, but here's how I fix... | In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): <https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8>
Simply copy it to a file (downloadable link above) and execute it like this: `zsh -e recreate_virtualenvs.sh <project_name>`
```
#!/bin/zsh -e
if [ ! -d "$... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | I'm using Redhat and have met the same problem.
My solution is :
1. install openssl and openssl-devel ---- yum install openssl openssl-devel -y
2. install krb5-devel ---- yum install krb5-devel
3. change to your python's directory and recompile it ---- make
If I didn't do the 2nd step, when I recompiled my python2.7... | For Ubuntu
==========
First check wheather install openssl-develop
```
sudo apt-get install libssl-dev
```
Try another way to reinstall `pip`
```
sudo apt-get install python-setuptools
sudo easy_install pip
```
use `setuptools` to install pip rather than install with source code may can solve the problem of depe... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstall... | In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): <https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8>
Simply copy it to a file (downloadable link above) and execute it like this: `zsh -e recreate_virtualenvs.sh <project_name>`
```
#!/bin/zsh -e
if [ ! -d "$... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | You need to install the OpenSSL header files before building Python if you need SSL support. On Debian and Ubuntu, they are in a package called `libssl-dev`. You might need some more dependencies, [as noted here](https://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu). | For Ubuntu
==========
First check wheather install openssl-develop
```
sudo apt-get install libssl-dev
```
Try another way to reinstall `pip`
```
sudo apt-get install python-setuptools
sudo easy_install pip
```
use `setuptools` to install pip rather than install with source code may can solve the problem of depe... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | OSX + homebrew users:
=====================
You can get the latest updates to the recipe:
```
brew reinstall python
```
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
```
openssl version... | Another symptom of this problem for me was if I went into the python console of my virtualenv and did `import ssl` it would error out. Turns out my virtualenv wasn't using the `brew` version of python, just the default install on my machine. No clue why the default install suddenly stopped working, but here's how I fix... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | You need to install OpenSSl before make and install Python to solve the problem.
On Centos:
```
yum install openssl openssl-devel -y
```
[source](http://www.leonli.co.uk/blog/723/solve-python-importerror-cannot-import-name-httpshandler) | On OSX, brew kept refusing to link against its openssl with this error:
```
15:27 $ brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full ... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstall... | It seems your `pip` requires `HTTPSHandler` which is part of `SSL` library.
**OSX**
On OS X you should link OpenSSL during Python installation (See: [#14497](https://github.com/Homebrew/homebrew/issues/14497)).
For Python 2:
```
brew reinstall python --with-brewed-openssl
pip install --upgrade pip
```
For Python ... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstall... | I'm using Redhat and have met the same problem.
My solution is :
1. install openssl and openssl-devel ---- yum install openssl openssl-devel -y
2. install krb5-devel ---- yum install krb5-devel
3. change to your python's directory and recompile it ---- make
If I didn't do the 2nd step, when I recompiled my python2.7... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | OSX + homebrew users:
=====================
You can get the latest updates to the recipe:
```
brew reinstall python
```
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
```
openssl version... | It seems your `pip` requires `HTTPSHandler` which is part of `SSL` library.
**OSX**
On OS X you should link OpenSSL during Python installation (See: [#14497](https://github.com/Homebrew/homebrew/issues/14497)).
For Python 2:
```
brew reinstall python --with-brewed-openssl
pip install --upgrade pip
```
For Python ... |
20,688,034 | Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
```
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env... | 2013/12/19 | [
"https://Stackoverflow.com/questions/20688034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3016020/"
] | I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstall... | For Ubuntu
==========
First check wheather install openssl-develop
```
sudo apt-get install libssl-dev
```
Try another way to reinstall `pip`
```
sudo apt-get install python-setuptools
sudo easy_install pip
```
use `setuptools` to install pip rather than install with source code may can solve the problem of depe... |
1,045,906 | I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6.
I have had no problems installing any other modules so far, but am getting errors installing pyCurl.
The error:
```
Sea... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/124485/"
] | I couldn't find a curl-config to add to the path, which makes sense as it's not a module that can be called (as far as I can tell)
The answer ended up being a bit of a hack, but it works.
As I had pyCurl working in my native python2.6 install, I simply copied the curl and pycurl items from the native install into th... | It looks like `curl-config` isn't in your path. Try running it from the command line and adjust the `PATH` environment variable as needed so that Python can find it. |
1,045,906 | I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6.
I have had no problems installing any other modules so far, but am getting errors installing pyCurl.
The error:
```
Sea... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/124485/"
] | ```
$ apt-cache depends python-pycurl
python-pycurl
Depends: libc6
Depends: libcurl3-gnutls
Depends: libgnutls26
Depends: libidn11
Depends: libkrb53
Depends: libldap-2.4-2
Depends: zlib1g
Depends: python
Depends: python
Depends: python-central
[...]
```
So first install the dependencies via `sudo ... | It looks like `curl-config` isn't in your path. Try running it from the command line and adjust the `PATH` environment variable as needed so that Python can find it. |
1,045,906 | I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6.
I have had no problems installing any other modules so far, but am getting errors installing pyCurl.
The error:
```
Sea... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/124485/"
] | Following dependencies are needed for installing pycurl:
```
apt-cache depends python-pycurl
python-pycurl
Depends: libc6
Depends: libcurl3-gnutls
Depends: libgcrypt11
Depends: python2.7
Depends: python
Depends: python
Suggests: libcurl4-gnutls-dev
Suggests: python-pycurl-dbg
Conflicts: <python2.3-pycurl>
Conflicts: ... | It looks like `curl-config` isn't in your path. Try running it from the command line and adjust the `PATH` environment variable as needed so that Python can find it. |
1,045,906 | I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6.
I have had no problems installing any other modules so far, but am getting errors installing pyCurl.
The error:
```
Sea... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/124485/"
] | Following dependencies are needed for installing pycurl:
```
apt-cache depends python-pycurl
python-pycurl
Depends: libc6
Depends: libcurl3-gnutls
Depends: libgcrypt11
Depends: python2.7
Depends: python
Depends: python
Suggests: libcurl4-gnutls-dev
Suggests: python-pycurl-dbg
Conflicts: <python2.3-pycurl>
Conflicts: ... | I couldn't find a curl-config to add to the path, which makes sense as it's not a module that can be called (as far as I can tell)
The answer ended up being a bit of a hack, but it works.
As I had pyCurl working in my native python2.6 install, I simply copied the curl and pycurl items from the native install into th... |
1,045,906 | I have worked with pyCurl in the past and have it working with my system default python install. However, I have a project that requires python to be more portable and I am using ActivePython-2.6.
I have had no problems installing any other modules so far, but am getting errors installing pyCurl.
The error:
```
Sea... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/124485/"
] | Following dependencies are needed for installing pycurl:
```
apt-cache depends python-pycurl
python-pycurl
Depends: libc6
Depends: libcurl3-gnutls
Depends: libgcrypt11
Depends: python2.7
Depends: python
Depends: python
Suggests: libcurl4-gnutls-dev
Suggests: python-pycurl-dbg
Conflicts: <python2.3-pycurl>
Conflicts: ... | ```
$ apt-cache depends python-pycurl
python-pycurl
Depends: libc6
Depends: libcurl3-gnutls
Depends: libgnutls26
Depends: libidn11
Depends: libkrb53
Depends: libldap-2.4-2
Depends: zlib1g
Depends: python
Depends: python
Depends: python-central
[...]
```
So first install the dependencies via `sudo ... |
11,696,691 | I have a Bash script (Bash 3.2, Mac OS X 10.8) that invokes multiple Python scripts in parallel in order to better utilize multiple cores. Each Python script takes a really long time to complete.
The problem is that if I hit Ctrl+C in the middle of the Bash script, the Python scripts do not actually get killed. How ca... | 2012/07/27 | [
"https://Stackoverflow.com/questions/11696691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1424877/"
] | You can't use this structure:
```
do
{
window.setTimeout(fadeIn,1000);
} while(done == false);
```
Because the code in the `setTimeout()` runs sometime LATER, your value of done will NEVER be changed and this loop will run forever. And, as long as it runs, the `setTimeout()` never gets to fire either (because ja... | Remember that javascript is single-threaded, so your setTimeout'et functions will not be called until it is finished running the current script. Which will never happen since you're in a loop that's never gonna end (untill you're out of memory from all those setTimeout's). Just call setTimeout once and let the function... |
19,489,132 | What is the proper way to pass values of string variables to Popen function in Python? I tried the below piece of code
```
var1 = 'hello'
var2 = 'universe'
p=Popen('/usr/bin/python /apps/sample.py ' + '"' + str(eval('var1')) + ' ' + '"' + str(eval('var2')), shell=True)
```
and in sample.py, below is the code
```
pr... | 2013/10/21 | [
"https://Stackoverflow.com/questions/19489132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2663585/"
] | This should work:
```
p = Popen('/usr/bin/python /apps/sample.py {} {}'.format(var1, var2), shell=True)
```
Learn about [string formatting](http://docs.python.org/2/library/string.html#format-examples) .
Second, passing arguments to scripts has its quirks: <http://docs.python.org/2/library/subprocess.html#subproces... | ```
var1 = 'hello'
var2 = 'universe'
p=Popen("/usr/bin/python /apps/sample.py %s %s"%(str(eval('var1')), str(eval('var2'))), shell=True)
```
Passing format specifier is nice way to do it. |
48,234,112 | I want to print all elements in this list in reversed order and every element in this list must be on a new line.
For example if the list is ['i', 'am', 'programming', 'with', 'python'] it should print out:
python
with
programming
am
i
What is the best way to do this?
```
def list():
words = []
while True:
... | 2018/01/12 | [
"https://Stackoverflow.com/questions/48234112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9160869/"
] | You don't need to convert to a data table for every step, it would be easier to query if you moved away from that.
```
var query =
from row in dt.AsEnumerable()
group new
{
premA = row.Field<decimal>("PREM_A"),
premB = row.Field<decimal>("PREM_B"),
} by row.Field<string>("ID").Trim() in... | Also:
```
var resultsDt = dt.AsEnumerable()
.GroupBy(row => row.Field<string>("ID"))
.Select(grp =>new {Id= grp.Key,
PREM_A= grp.Sum(r => r.Field<decimal>("PREM_A")),
PREM_B=grp.Sum(r... |
64,802,573 | I am trying to get the most basic of OpenAPI server to work as expected. It works as expected with auto-generated python-flask but not with aspnet where exceptions being raised on queries occurs.
What extra steps are required to get the aspnet server to respond correctly to queries?
The YAML is as below:
```
openapi... | 2020/11/12 | [
"https://Stackoverflow.com/questions/64802573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/133232/"
] | You can set a **cookie** for detection users; for example, for the first, I visit your store, you set a cookie with **GUID** value for me, now when I order something, you use my GUID as an identifier to track my order. | add AllowAnonymous attribute to actions or controllers. Then user don't need to do log in.
```
[
[AllowAnonymous]
public class Orders: Controller
{
[AllowAnonymous]
public ActionResult PlaceOrder()
{
}
public ActionResult Get()
{
}
... |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | >
> subprocess: The `subprocess` module
> allows you to spawn new processes,
> connect to their input/output/error
> pipes, and obtain their return codes.
>
>
>
<http://docs.python.org/library/subprocess.html>
Usage:
```
import subprocess
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)... | use spawn
```
import os
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
``` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | >
> subprocess: The `subprocess` module
> allows you to spawn new processes,
> connect to their input/output/error
> pipes, and obtain their return codes.
>
>
>
<http://docs.python.org/library/subprocess.html>
Usage:
```
import subprocess
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)... | You can use [`subprocess.Popen`](http://docs.python.org/library/subprocess.html). There's a few ways to do it:
```
import subprocess
cmd = ['/run/myscript', '--arg', 'value']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print line
p.wait()
print p.returncode
```
Or, if you don't care w... |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | use spawn
```
import os
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
``` | this worked for me fine!
`shell_command = "ls -l"
subprocess.call(shell_command.split())` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | You can use [`subprocess.Popen`](http://docs.python.org/library/subprocess.html). There's a few ways to do it:
```
import subprocess
cmd = ['/run/myscript', '--arg', 'value']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print line
p.wait()
print p.returncode
```
Or, if you don't care w... | use spawn
```
import os
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
``` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | >
> subprocess: The `subprocess` module
> allows you to spawn new processes,
> connect to their input/output/error
> pipes, and obtain their return codes.
>
>
>
<http://docs.python.org/library/subprocess.html>
Usage:
```
import subprocess
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)... | The subprocess module has come along way since 2008. In particular [`check_call`](http://docs.python.org/library/subprocess.html#subprocess.check_call) and [`check_output`](http://docs.python.org/library/subprocess.html#subprocess.check_output) make simple subprocess stuff even easier. The `check_*` family of functions... |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | >
> subprocess: The `subprocess` module
> allows you to spawn new processes,
> connect to their input/output/error
> pipes, and obtain their return codes.
>
>
>
<http://docs.python.org/library/subprocess.html>
Usage:
```
import subprocess
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)... | this worked for me fine!
`shell_command = "ls -l"
subprocess.call(shell_command.split())` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | >
> subprocess: The `subprocess` module
> allows you to spawn new processes,
> connect to their input/output/error
> pipes, and obtain their return codes.
>
>
>
<http://docs.python.org/library/subprocess.html>
Usage:
```
import subprocess
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)... | I use os.system
```
import os
os.system("pdftoppm -png {} {}".format(path2pdf, os.path.join(tmpdirname, "temp")))
``` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | You can use [`subprocess.Popen`](http://docs.python.org/library/subprocess.html). There's a few ways to do it:
```
import subprocess
cmd = ['/run/myscript', '--arg', 'value']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print line
p.wait()
print p.returncode
```
Or, if you don't care w... | I use os.system
```
import os
os.system("pdftoppm -png {} {}".format(path2pdf, os.path.join(tmpdirname, "temp")))
``` |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | You can use [`subprocess.Popen`](http://docs.python.org/library/subprocess.html). There's a few ways to do it:
```
import subprocess
cmd = ['/run/myscript', '--arg', 'value']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print line
p.wait()
print p.returncode
```
Or, if you don't care w... | The `os.exec*()` functions *replace* the current programm with the new one. When this programm ends so does your process. You probably want `os.system()`. |
325,463 | I've a python script that has to launch a shell command for every file in a dir:
```
import os
files = os.listdir(".")
for f in files:
os.execlp("myscript", "myscript", f)
```
This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python... | 2008/11/28 | [
"https://Stackoverflow.com/questions/325463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28582/"
] | You can use [`subprocess.Popen`](http://docs.python.org/library/subprocess.html). There's a few ways to do it:
```
import subprocess
cmd = ['/run/myscript', '--arg', 'value']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in p.stdout:
print line
p.wait()
print p.returncode
```
Or, if you don't care w... | this worked for me fine!
`shell_command = "ls -l"
subprocess.call(shell_command.split())` |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | After reading this [tutorial](https://cloud.google.com/python/setup), I found the workaround for my case:
```
virtualenv --python "C:\\Anaconda3\\python.exe" env
``` | If `python --V` is showing a version greater than 3, then why not try:
```
virtualenv -p python env
```
instead? The value of the `p` flag is simply referring to the version of python you're wanting to create the virtual environment with. In this case, `python` is greater than version 3. |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | If `python --V` is showing a version greater than 3, then why not try:
```
virtualenv -p python env
```
instead? The value of the `p` flag is simply referring to the version of python you're wanting to create the virtual environment with. In this case, `python` is greater than version 3. | Use something like this: **virtualenv --python "*Your python.exe path*" '*Name of your virtual folder*'**. You can take your python.exe path from your environment variables which is in properties of your '*This PC*' or '*My Computer*'.
Then get into the folder and run the command: ***.\Scripts\activate***
Enter the c... |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | If `python --V` is showing a version greater than 3, then why not try:
```
virtualenv -p python env
```
instead? The value of the `p` flag is simply referring to the version of python you're wanting to create the virtual environment with. In this case, `python` is greater than version 3. | Just a comment: On my Win10, for python3 scripts, I run py c:\path\to\script.
For example:
```
py -m pip --version
```
So to make the above command work, I used:
```
py -m venv env
```
and:
```
virtualenv -p py env
```
So that could be a possible solution as well. |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | After reading this [tutorial](https://cloud.google.com/python/setup), I found the workaround for my case:
```
virtualenv --python "C:\\Anaconda3\\python.exe" env
``` | Use something like this: **virtualenv --python "*Your python.exe path*" '*Name of your virtual folder*'**. You can take your python.exe path from your environment variables which is in properties of your '*This PC*' or '*My Computer*'.
Then get into the folder and run the command: ***.\Scripts\activate***
Enter the c... |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | After reading this [tutorial](https://cloud.google.com/python/setup), I found the workaround for my case:
```
virtualenv --python "C:\\Anaconda3\\python.exe" env
``` | Just a comment: On my Win10, for python3 scripts, I run py c:\path\to\script.
For example:
```
py -m pip --version
```
So to make the above command work, I used:
```
py -m venv env
```
and:
```
virtualenv -p py env
```
So that could be a possible solution as well. |
46,138,803 | I'm trying the tutorial [Using Cloud Datastore with Python](https://cloud.google.com/python/getting-started/using-cloud-datastore), but when I run:
```
virtualenv -p python3 env
```
I got an error:
```
The path python3 (from --python=python3) does not exist
```
I checked the python version by running:
```
python... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46138803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/646732/"
] | Use something like this: **virtualenv --python "*Your python.exe path*" '*Name of your virtual folder*'**. You can take your python.exe path from your environment variables which is in properties of your '*This PC*' or '*My Computer*'.
Then get into the folder and run the command: ***.\Scripts\activate***
Enter the c... | Just a comment: On my Win10, for python3 scripts, I run py c:\path\to\script.
For example:
```
py -m pip --version
```
So to make the above command work, I used:
```
py -m venv env
```
and:
```
virtualenv -p py env
```
So that could be a possible solution as well. |
53,495,570 | I need to install `graph-tool` from source, so I add in my Dockerfile this:
```
FROM ubuntu:18.04
RUN git clone https://git.skewed.de/count0/graph-tool.git
RUN cd graph-tool && ./configure && make && make install
```
as it written [here](https://git.skewed.de/count0/graph-tool/wikis/Installation-instructions#manual... | 2018/11/27 | [
"https://Stackoverflow.com/questions/53495570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9098575/"
] | You need to run **autogen.sh** first, it will generate **configure** file
P.S. Make sure you install libtool
```
apt-get install libtool
``` | You have to install the prerequisites first.
```
RUN apt update && apt install -y --no-install-recommends \
make \
build-essential \
g++ \
....
```
Don't forget to clean up and remove temp/unnecessary files! |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Why don't you use JNA API `http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm` to load native library? Once you putted into your project classpath, you add this code
`NativeLibrary.addSearchPath("libtesseract302", "your native lib path");` make sure you have this libtesseract302.dll file, normally it is located at... | A few days ago I ran into the same error message when trying to load a C++ DLL with JNA. It turned out that the cause was a missing DLL that my DLL depended on.
In my case it was the MS Visual Studio 2012 redistributable, which I then downloaded and installed on the machine and the problem was gone. Try using **Depend... |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | The error stems from your trying to load 32-bit DLLs in 64-bit JVM. The possible solution is switch to 32-bit JVM; alternatively, use [64-bit Tesseract and Leptonica DLLs](https://github.com/charlesw/tesseract/tree/master/src/lib/TesseractOcr/x64). | A few days ago I ran into the same error message when trying to load a C++ DLL with JNA. It turned out that the cause was a missing DLL that my DLL depended on.
In my case it was the MS Visual Studio 2012 redistributable, which I then downloaded and installed on the machine and the problem was gone. Try using **Depend... |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | The error stems from your trying to load 32-bit DLLs in 64-bit JVM. The possible solution is switch to 32-bit JVM; alternatively, use [64-bit Tesseract and Leptonica DLLs](https://github.com/charlesw/tesseract/tree/master/src/lib/TesseractOcr/x64). | I had the same problem and found that this "resource path" is not set by "native directory path" .
You can however add new folders to it by using "Add External Class Folder" in the Library tab, even if this folder does not contain any class file but native library files(like DLL on Windows) |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | The error stems from your trying to load 32-bit DLLs in 64-bit JVM. The possible solution is switch to 32-bit JVM; alternatively, use [64-bit Tesseract and Leptonica DLLs](https://github.com/charlesw/tesseract/tree/master/src/lib/TesseractOcr/x64). | Had the same issue, sorted with the following lines
```
System.load("/usr/local/lib/liblept.so.5")
System.loadLibrary("tesseract")
```
For your case, it might be different libraries but in the end is pretty much the same: just load the libraries that you need manually. |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Had the same issue, sorted with the following lines
```
System.load("/usr/local/lib/liblept.so.5")
System.loadLibrary("tesseract")
```
For your case, it might be different libraries but in the end is pretty much the same: just load the libraries that you need manually. | I think an easier way to get around this error would be to revert to an earlier version where you were not getting this error. Right click on the project folder and navigate to local history to revert to an earlier version. I verified this workaround on the android studio installed on Mac OS Big sur. |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Like the error says, it's looking for `win32-x86-64/libtesseract302.dll` in `java.class.path`. Part of your classpath apparently includes `myproject/target/classes`.
The prefix represents the platform and architecture of the shared library to be loaded, which allows shared libraries for different targets to be include... | I think an easier way to get around this error would be to revert to an earlier version where you were not getting this error. Right click on the project folder and navigate to local history to revert to an earlier version. I verified this workaround on the android studio installed on Mac OS Big sur. |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Like the error says, it's looking for `win32-x86-64/libtesseract302.dll` in `java.class.path`. Part of your classpath apparently includes `myproject/target/classes`.
The prefix represents the platform and architecture of the shared library to be loaded, which allows shared libraries for different targets to be include... | I had the same problem and found that this "resource path" is not set by "native directory path" .
You can however add new folders to it by using "Add External Class Folder" in the Library tab, even if this folder does not contain any class file but native library files(like DLL on Windows) |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | The error stems from your trying to load 32-bit DLLs in 64-bit JVM. The possible solution is switch to 32-bit JVM; alternatively, use [64-bit Tesseract and Leptonica DLLs](https://github.com/charlesw/tesseract/tree/master/src/lib/TesseractOcr/x64). | Why don't you use JNA API `http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm` to load native library? Once you putted into your project classpath, you add this code
`NativeLibrary.addSearchPath("libtesseract302", "your native lib path");` make sure you have this libtesseract302.dll file, normally it is located at... |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Like the error says, it's looking for `win32-x86-64/libtesseract302.dll` in `java.class.path`. Part of your classpath apparently includes `myproject/target/classes`.
The prefix represents the platform and architecture of the shared library to be loaded, which allows shared libraries for different targets to be include... | A few days ago I ran into the same error message when trying to load a C++ DLL with JNA. It turned out that the cause was a missing DLL that my DLL depended on.
In my case it was the MS Visual Studio 2012 redistributable, which I then downloaded and installed on the machine and the problem was gone. Try using **Depend... |
19,768,456 | I stumbled upon a behaviour in python that I have a hard time understanding. This is the proof-of-concept code:
```
from functools import partial
if __name__ == '__main__':
sequence = ['foo', 'bar', 'spam']
loop_one = lambda seq: [lambda: el for el in seq]
no_op = lambda x: x
loop_two = lambda seq: [p... | 2013/11/04 | [
"https://Stackoverflow.com/questions/19768456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146792/"
] | Like the error says, it's looking for `win32-x86-64/libtesseract302.dll` in `java.class.path`. Part of your classpath apparently includes `myproject/target/classes`.
The prefix represents the platform and architecture of the shared library to be loaded, which allows shared libraries for different targets to be include... | Why don't you use JNA API `http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm` to load native library? Once you putted into your project classpath, you add this code
`NativeLibrary.addSearchPath("libtesseract302", "your native lib path");` make sure you have this libtesseract302.dll file, normally it is located at... |
49,203,174 | i am trying to install Home Automatization (<https://home-assistant.io>) on my Synology. I've installed python via the synology packaging system, i've done basic setup (<https://home-assistant.io/docs/installation/synology/>) but when i try to run the daemon i see this in console:
*homeassistant requires Python '>=3.5... | 2018/03/09 | [
"https://Stackoverflow.com/questions/49203174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9469908/"
] | I faced exactly the same issue where I needed to keep previous user answers for a conversation. Take a look at [Handler](https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.handler.html]) documentation which is a base class for all handlers. It has parameter called pass\_user\_data. When set to True it pa... | I think the accepted solution is deprecated -
<https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.handler.html>
>
> pass\_user\_data and pass\_chat\_data determine whether a dict you can use to keep any data in will be sent to the callback function. Related to either the user or the chat that the upda... |
48,971,320 | This may be a very easy question but I'm new to python and I've searched the net however I couldn't solve the problem. I have a csv file which I need to search for a specific word in the columns of its first row. How can I do that? | 2018/02/25 | [
"https://Stackoverflow.com/questions/48971320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9201115/"
] | I used the default csv module of python to read a csv file line by line. Since you specified that we have to search only in the first row, that's why I used break-to stop execution after searching the first row of the csv. You can remove the break, to search throughout the csv. Hope this works.
```
import csv
a='abc' ... | ```
import csv
a='abc' #String that you want to search
with open("testing.csv") as f_obj:
reader = csv.reader(f_obj, delimiter=',')
for line in reader: #Iterates through the rows of your csv
print(line) #line here refers to a row in the csv
if a in str(line): #If the strin... |
819,396 | I have a collection of files encoded in ANSI or UTF-16LE. I would like python to open the files using the correct encoding. The problem is that the ANSI files do not raise any sort of exception when encoded using UTF-16le and vice versa.
Is there a straightforward way to open up the files using the correct file encodi... | 2009/05/04 | [
"https://Stackoverflow.com/questions/819396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/100758/"
] | Use the [chardet](http://chardet.feedparser.org/) library to detect the encoding. | You can check for the [BOM](http://en.wikipedia.org/wiki/Byte-order_mark "BOM") at the beginning of the file to check whether it's UTF.
Then [unicode.decode](http://docs.python.org/library/stdtypes.html#str.decode) accordingly (using one of the [standard encodings](http://docs.python.org/library/codecs.html#standard-e... |
819,396 | I have a collection of files encoded in ANSI or UTF-16LE. I would like python to open the files using the correct encoding. The problem is that the ANSI files do not raise any sort of exception when encoded using UTF-16le and vice versa.
Is there a straightforward way to open up the files using the correct file encodi... | 2009/05/04 | [
"https://Stackoverflow.com/questions/819396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/100758/"
] | Use the [chardet](http://chardet.feedparser.org/) library to detect the encoding. | What's in the files? If it's plain text in a Latin-based alphabet, almost every other byte the UTF-16LE files will be zero. In the windows-1252 files, on the other hand, I wouldn't expect to see any zeros at all. For example, here's `“Hello”` in windows-1252:
```
93 48 65 6C 6C 6F 94
```
...and in UTF-16LE:
```
1C ... |
63,141,133 | I'm new to python and webscraping.
I'm trying to extract the text from a list that starts with `"a href"`.
The whole list is in a variable named `team"`.
If I write `team[0].a.text` I get the first text.
But when I do `team[0:14].a.text` I get this response:
```
AttributeError: 'list' object has no attribute 'a'`
`... | 2020/07/28 | [
"https://Stackoverflow.com/questions/63141133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14011583/"
] | I hope this simple example helps you udnerstand on your errors more.
**If I say `qjogos = (int(qtjog_entry.get()))` at the main block, like:**
```
from tkinter import *
root = Tk()
def click():
pass
qtjog_entry = Entry(root)
qtjog_entry.pack()
qjogos = (int(qtjog_entry.get()))
b = Button(root,text='Click me'... | It looks like `self.qtjog_entry.get()` returns an empty string; you can't use `int()` on an empty string. Without having more context, it's hard to tell exactly what's wrong here. |
11,254,769 | Here is the story.
I have a bunch of stored procedures and all have their own argument types.
What I am looking to do is to create a bit of a type safety layer in python so I can make sure all values are of the correct type before hitting the database.
Of course I don't want to write up the whole schema again in ... | 2012/06/29 | [
"https://Stackoverflow.com/questions/11254769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/537925/"
] | If you want the Python type classes, like you might get from a `SQLALchemy` column object, you'll need to build and maintain your own mapping. `psycopg2` doesn't have one, even internally.
But if what you want is a way to get from an `oid` to a function that will convert raw values into Python instances, `psycopg2.ext... | The mapping of postgres types and python types is given [here](http://packages.python.org/psycopg2/usage.html). Does that help?
Edit:
When you read a record from a table, the postgres (or any database) driver will automatically map the record column types to Python types.
```
cur = con.cursor()
cur.execute("SELECT * ... |
34,538,890 | I have a question which is not really clear in python documentation (<https://docs.python.org/2/library/stdtypes.html#set.intersection>).
When using set.intersection the resulting set contains the objects from current set or from other? In the case that both objects have same value but are different objects in memory.... | 2015/12/30 | [
"https://Stackoverflow.com/questions/34538890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1936538/"
] | What objects are used varies, if the sets are the same size the intersecting elements from b, if b has more elements then the objects from a are returned:
```
i = "$foobar" * 100
j = "$foob" * 100
l = "$foobar" * 100
k = "$foob" * 100
print(id(i), id(j))
print(id(l), id(k))
a = {i, j}
b = {k, l, 3}
inter = a.intersec... | One thing you could do is instead use python dictionaries. Access is still O(1), elements are easy to access, and a simple loop such as follows can get the intersection feature:
```
res=[]
for item in dict1.keys():
if dict2.has_key(item):
res.append(item)
```
The advantage here is you have full control of wha... |
64,839,088 | I'm trying to use the OpenCV Stitcher class for putting two images together. I ran the simple example provided in the answer to this [question](https://stackoverflow.com/questions/34362922/how-to-use-opencv-stitcher-class-with-python) with the same koala images, but it returns `(1, None)` every time. I've tried this on... | 2020/11/14 | [
"https://Stackoverflow.com/questions/64839088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7129536/"
] | Try changing the default pano confidence threshold using `setPanoConfidenceThresh()`. By default it's 1.0, and apparently it results in the stitcher thinking that it has failed.
Here is the full example that works for me. I used that pair of koala images as well, and I am on opencv 4.2.0:
```
stitcher = cv2.Stitcher.... | Try rescaling the images to 0.6 and 0.6 , by using the resize. For some reason I got the result only at those values. |
64,938,027 | Can I indicate a specific dictionary shape/form for an argument to a function in python?
Like in typescript I'd indicate that the `info` argument should be an object with a string `name` and a number `age`:
```js
function parseInfo(info: {name: string, age: number}) { /* ... */ }
```
Is there a way to do this with ... | 2020/11/20 | [
"https://Stackoverflow.com/questions/64938027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6826164/"
] | In Python 3.8+ you could use the [alternative syntax](https://www.python.org/dev/peps/pep-0589/#alternative-syntax) to create a [TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict):
```
from typing import TypedDict
Info = TypedDict('Info', {'name': str, 'age': int})
def parse_info(info: Info):... | Perhaps you could do the following:
```
def assertTypes(obj, type_obj):
for t in type_obj:
if not(t in obj and type(obj[t]) == type_obj[t]):
return False
return True
def parseInfo(info):
if not assertTypes(info, {"name": str, "age": int}):
print("INVALID OBJECT FORMAT")
... |
22,328,160 | I am converting many obscure date formats from an old system. The dates are unpacked/processed as strings and converted into ISO 8601 format.
This particular function attempts to convert YYMMDD0F to YYYYMMDD -- function name says it all. Dates from the year 2000 make this messy and clearly this is not the most python... | 2014/03/11 | [
"https://Stackoverflow.com/questions/22328160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1645914/"
] | How about this one:
```
SELECT ID, Team, DPV, DPT, DPV-DPT AS Difference FROM e2teams
``` | Something like this?
```
SELECT
ID,
Team,
DPV,
DPT,
(DPV - DPT) as Difference
FROM
e2teams
```
You can find more information **[here](https://dev.mysql.com/doc/refman/5.0/en/arithmetic-functions.html)** |
22,328,160 | I am converting many obscure date formats from an old system. The dates are unpacked/processed as strings and converted into ISO 8601 format.
This particular function attempts to convert YYMMDD0F to YYYYMMDD -- function name says it all. Dates from the year 2000 make this messy and clearly this is not the most python... | 2014/03/11 | [
"https://Stackoverflow.com/questions/22328160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1645914/"
] | How about this one:
```
SELECT ID, Team, DPV, DPT, DPV-DPT AS Difference FROM e2teams
``` | ```
SELECT * FROM e2teams GROUP by Difference HAVING (DPV-DPT) = Difference ;
``` |
22,328,160 | I am converting many obscure date formats from an old system. The dates are unpacked/processed as strings and converted into ISO 8601 format.
This particular function attempts to convert YYMMDD0F to YYYYMMDD -- function name says it all. Dates from the year 2000 make this messy and clearly this is not the most python... | 2014/03/11 | [
"https://Stackoverflow.com/questions/22328160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1645914/"
] | How about this one:
```
SELECT ID, Team, DPV, DPT, DPV-DPT AS Difference FROM e2teams
``` | In order to avoid errors and database corruption, you should never have a calculable value on you database.
So the best way to do this is, as answered before :
```
SELECT ID, Team, DPV, DPT, (DPV-DPT) as Difference FROM e2teams
``` |
12,444,942 | I'm doing an evolution experiment using python and pygame, however that is unimportant, it is one function that is not working and id like you to have a look at.
The error message I'm getting is float object is not callable. It says the problem is in line 205 which is calling the function from line 51.
I will post a... | 2012/09/16 | [
"https://Stackoverflow.com/questions/12444942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1339482/"
] | Line 51:
```
def distance(self,listx,listy):
```
Line 55:
```
self.distance=(((self.x-self.tcentrex)**2) + ((self.y-self.tcentrey)**2))**0.5
```
You can't have `self.distance` be both a method and a variable and expect things to work properly.
When line 55 is executed (during the first time the `distance()` meth... | In line 55, within the `distance` method, you assign a float value to `self.distance`. So after you call `distance` once, the attribute `distance` on that object refers to a float, which is not callable. |
55,174,991 | Attempting to convert this EGCD equation into python.
```
egcd(a, b) = (1, 0), if b = 0
= (t, s - q * t), otherwise, where
q = a / b (note: integer division)
r = a mod b
(s, t) = egcd(b, r)
```
The test I used was egcd(5, 37) which should return (15,-2) but is returning (19.5, -5.135135135135135)
My code is:
```
... | 2019/03/15 | [
"https://Stackoverflow.com/questions/55174991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10687320/"
] | `a / b` in Python 3 is "true division" the result is non-truncating floating point division even when both operands are `int`s.
To fix, either use `//` instead (which is floor division):
```
q = a // b
```
or [use `divmod`](https://docs.python.org/3/library/functions.html#divmod) to perform both division and remain... | Change `q = a / b` for `q = a // b` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.