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 |
|---|---|---|---|---|---|
61,035,989 | i am trying to run this simple flask app and I keep getting this error in the terminal when trying to run the flask app
`FLASK_APP=app.py flask run`
i keep getting this error :
`sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied`
here is my app:
```
from flask import Flask... | 2020/04/04 | [
"https://Stackoverflow.com/questions/61035989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10600856/"
] | Other than just setting a password, you can log in without a password by:
1. Enable trust authentication, eg `echo "local all all trust" | sudo tee -a /etc/postgresql/10/main/pg_hba.conf`
2. Create a role with login access with the same username as your local username, eg if `whoami` returns `myname`, then `sudo -u po... | so apparently you need a password to connect to database from SQLAlchemy, I was able to work around this by simply creating a password or adding new user with password.
let me know if there is a different work around/solution |
61,469,948 | I am a beginner in the field of Data Science and I am working with Data Preprocessing in python. However, I am working with the Fingers Dataset so I want to move the pictures so every pic fits in its own directory to be able to use **ImageDataGenerator** and **flowfromdirectory** to import the pictures and apply rescal... | 2020/04/27 | [
"https://Stackoverflow.com/questions/61469948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11381138/"
] | Firstly instead of doing a for each and push promises you can map them and do a Promise all. You need no push. Your function can return directly your promise all call. The caller can await it or use then...
Something like this (I didn't test it)
```js
// serverlist declaration
function getList(serverlist) {
const oper... | For more consistency and for resolving this question i/we(other people which can help you) need *all* code this all variables definition (because for now i can't find where is the `promises` variable is defined). Thanks |
73,805,667 | i am a beginner with python. I need to calculate a binairy number. I used a for loop for this because I need to print those same numbers with the len(). Can someone tell me what i am doing wrong?
```
for binairy in ["101011101"]:
binairy = binairy ** 2
print(binairy)
print(len(binairy))
```
>
> TypeErro... | 2022/09/21 | [
"https://Stackoverflow.com/questions/73805667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14861522/"
] | you used a list but you could use a string directly
```
def binary_to_decimal(binary):
decimal = 0
for digit in binary:
decimal = decimal*2 + int(digit)
return decimal
print(binary_to_decimal("1010"))
``` | ["101011101"] is a list with a single string. "101011101" is a list of characters. Look at this:
```py
for let_me_find_out in ["101011101"]:
print(let_me_find_out)
for let_me_find_out in "101011101":
print(let_me_find_out)
```
With this knowledge, you can now start your binary conversion:
```py
for binairy... |
73,805,667 | i am a beginner with python. I need to calculate a binairy number. I used a for loop for this because I need to print those same numbers with the len(). Can someone tell me what i am doing wrong?
```
for binairy in ["101011101"]:
binairy = binairy ** 2
print(binairy)
print(len(binairy))
```
>
> TypeErro... | 2022/09/21 | [
"https://Stackoverflow.com/questions/73805667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14861522/"
] | you used a list but you could use a string directly
```
def binary_to_decimal(binary):
decimal = 0
for digit in binary:
decimal = decimal*2 + int(digit)
return decimal
print(binary_to_decimal("1010"))
``` | I think I understand what you mean:
You are willing to make the weight of every single number and than summing it all like "110" = "0x20+1x21+1x22" = 62dec
So I will suggest to write the code like this:
```
weight, result = 0, 0
for binary in "101011101"[::-1]:
result += int(binary)*2**weight
print(result)
``` |
73,805,667 | i am a beginner with python. I need to calculate a binairy number. I used a for loop for this because I need to print those same numbers with the len(). Can someone tell me what i am doing wrong?
```
for binairy in ["101011101"]:
binairy = binairy ** 2
print(binairy)
print(len(binairy))
```
>
> TypeErro... | 2022/09/21 | [
"https://Stackoverflow.com/questions/73805667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14861522/"
] | ["101011101"] is a list with a single string. "101011101" is a list of characters. Look at this:
```py
for let_me_find_out in ["101011101"]:
print(let_me_find_out)
for let_me_find_out in "101011101":
print(let_me_find_out)
```
With this knowledge, you can now start your binary conversion:
```py
for binairy... | I think I understand what you mean:
You are willing to make the weight of every single number and than summing it all like "110" = "0x20+1x21+1x22" = 62dec
So I will suggest to write the code like this:
```
weight, result = 0, 0
for binary in "101011101"[::-1]:
result += int(binary)*2**weight
print(result)
``` |
51,793,379 | In my file, I have a large number of images in **jpg** format and they are named **[fruit type].[index].jpg**.
Instead of manually making three new sub folders to copy and paste the images into each sub folder, is there some python code that can parse through the name of the images and choose where to redirect the i... | 2018/08/10 | [
"https://Stackoverflow.com/questions/51793379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8238011/"
] | Here’s the code to do just that, if you need help merging this into your codebase let me know:
```
import os, os.path, shutil
folder_path = "test"
images = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
for image in images:
folder_name = image.split('.')[0]
new_path = ... | If they are all formatted similarly to the three fruit example you gave, you can simply do a string.split(".")[0] on each filename you encounter:
```
import os
for image in images:
fruit = image.split(".")[0]
if not os.path.isdir(fruit):
os.mkdir(fruit)
os.rename(os.path.join(fruit, image))
``` |
51,793,379 | In my file, I have a large number of images in **jpg** format and they are named **[fruit type].[index].jpg**.
Instead of manually making three new sub folders to copy and paste the images into each sub folder, is there some python code that can parse through the name of the images and choose where to redirect the i... | 2018/08/10 | [
"https://Stackoverflow.com/questions/51793379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8238011/"
] | Here’s the code to do just that, if you need help merging this into your codebase let me know:
```
import os, os.path, shutil
folder_path = "test"
images = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
for image in images:
folder_name = image.split('.')[0]
new_path = ... | As an idea, hope it helps
```
import os
from pathlib import Path
import shutil
folder_path = "images/"
nameList=[]
for image in os.listdir(folder_paths):
folder_name = image.split('.')[0]
nameList.append(folder_name)
for f in os.listdir(folder_paths):
Path(folder_name).mkdir(paren... |
71,480,638 | Atttempted to implement jit decorator to increase the speed of execution of my code. Not getting proper results. It is throughing all sorts of errors.. Key error, type errors, etc..
The actual code without numba is working without any issues.
```
# The Code without numba is:
df = pd.DataFrame()
df['Serial'] = [865,866... | 2022/03/15 | [
"https://Stackoverflow.com/questions/71480638",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15922454/"
] | You can only use `df['A'].values[:]` if the column `A` exists in the dataframe. Otherwise you need to create a new one, possibly with `df['A'] = ...`.
Moreover, the trick with `astype(object)` applies for string but not for numbers. Indeed, string-based dataframe columns do apparently not use Numpy string-based array ... | This Code is giving list to list convertion typeerror.
```
from numba import njit
df = pd.DataFrame()
df['Serial'] = [865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880]
df['Value'] = [586,586.45,585.95,585.85,585.45,585.5,586,585.7,585.7,585.5,585.5,585.45,585.3,584,584,585]
df['Ref'] = [586.35,586.1,586... |
48,757,747 | Let's consider a file called `test1.py` and containing the following code:
```
def init_foo():
global foo
foo=10
```
Let's consider another file called `test2.py` and containing the following:
```
import test1
test1.init_foo()
print(foo)
```
Provided that `test1` is on the pythonpath (and gets imported ... | 2018/02/13 | [
"https://Stackoverflow.com/questions/48757747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4961888/"
] | For this you need to use [`selModel`](https://docs.sencha.com/extjs/5.1.4/api/Ext.grid.Panel.html#cfg-selModel) config for [`grid`](https://docs.sencha.com/extjs/5.1.4/api/Ext.grid.Panel.html) using [`CheckboxModel`](https://docs.sencha.com/extjs/5.1.4/api/Ext.selection.CheckboxModel.html).
* A **selModel** Ext.select... | I achieved by adding keyup,keydown listeners. Please find the fiddle where i updated the code.
<https://fiddle.sencha.com/#view/editor&fiddle/2d98> |
56,314,194 | I want to get random item from a list, also I don't want some items to be consider while `random.choice()`. Below is my data structure
```
x=[
{ 'id': 1, 'version':0.1, 'ready': True }
{ 'id': 6, 'version':0.2, 'ready': True }
{ 'id': 4, 'version':0.1, 'ready': False }
{ 'id': 35, 'version':0.1, 'ready': Fals... | 2019/05/26 | [
"https://Stackoverflow.com/questions/56314194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2200798/"
] | Have a look at Dotplant2 which uses Yii2 and currency conversion tables in the backend. Specifically these files.
1. components/payment/[PaypalPayment.php](https://github.com/DevGroup-ru/dotplant2/blob/master/application/components/payment/PayPalPayment.php) and 2. their [CurrencyHelper.php](https://github.com/DevGro... | I got this from PayPal support:
>
> Unfortunately domestic transaction is not possible to receive in USD and similarly international transaction should be in USD. There is no way to have single currency for both the transactions. Thanks and regards,
>
>
> |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | First off [set\_time\_limit(0);](http://php.net/set_time_limit) will make your script run for ever so timeout shouldn't be an issue. Second any \*exec call in PHP does NOT use the PATH by default (might depend on configuration), so your script will exit without giving any info on the problem, and it quite often ends up... | I found that the issue when I tried this was the simple fact that I did not compile the source on the server I was running it on. By compiling on your local machine and then uploading to your server, it will be corrupted in some way. shell\_exec() should work by compiling the source you are trying to run on the same se... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | shell\_exec returns a string, if you run it alone it won't produce any output, so you can write:
```
$output = shell_exec(...);
print $output;
``` | Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.
I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes th... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | shell\_exec returns a string, if you run it alone it won't produce any output, so you can write:
```
$output = shell_exec(...);
print $output;
``` | Found this before and helped me solve my background execution problem:
```
function background_exec($command)
{
if(substr(php_uname(), 0, 7) == 'Windows')
{
pclose(popen('start "background_exec" ' . $command, 'r'));
}
else
{
exec($command . ' > /dev/null &');
}
}
```
Source:
... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.
I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes th... | I found that the issue when I tried this was the simple fact that I did not compile the source on the server I was running it on. By compiling on your local machine and then uploading to your server, it will be corrupted in some way. shell\_exec() should work by compiling the source you are trying to run on the same se... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | shell\_exec returns a string, if you run it alone it won't produce any output, so you can write:
```
$output = shell_exec(...);
print $output;
``` | A proplem could be that your script takes longer than the server waiting time definied for a request (can be set in the php.ini or httpd.conf).
Another issue could be that the servers account does not have the right to execute or access code or files needed for your script to run. |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.
I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes th... | A proplem could be that your script takes longer than the server waiting time definied for a request (can be set in the php.ini or httpd.conf).
Another issue could be that the servers account does not have the right to execute or access code or files needed for your script to run. |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | shell\_exec returns a string, if you run it alone it won't produce any output, so you can write:
```
$output = shell_exec(...);
print $output;
``` | I found that the issue when I tried this was the simple fact that I did not compile the source on the server I was running it on. By compiling on your local machine and then uploading to your server, it will be corrupted in some way. shell\_exec() should work by compiling the source you are trying to run on the same se... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.
I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes th... | Found this before and helped me solve my background execution problem:
```
function background_exec($command)
{
if(substr(php_uname(), 0, 7) == 'Windows')
{
pclose(popen('start "background_exec" ' . $command, 'r'));
}
else
{
exec($command . ' > /dev/null &');
}
}
```
Source:
... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | First off [set\_time\_limit(0);](http://php.net/set_time_limit) will make your script run for ever so timeout shouldn't be an issue. Second any \*exec call in PHP does NOT use the PATH by default (might depend on configuration), so your script will exit without giving any info on the problem, and it quite often ends up... | Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.
I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes th... |
4,214,031 | I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when the Python script finishes its job, it updates a field in database and then the website renders some graphics, based on the results of the Python... | 2010/11/18 | [
"https://Stackoverflow.com/questions/4214031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2203413/"
] | First off [set\_time\_limit(0);](http://php.net/set_time_limit) will make your script run for ever so timeout shouldn't be an issue. Second any \*exec call in PHP does NOT use the PATH by default (might depend on configuration), so your script will exit without giving any info on the problem, and it quite often ends up... | A proplem could be that your script takes longer than the server waiting time definied for a request (can be set in the php.ini or httpd.conf).
Another issue could be that the servers account does not have the right to execute or access code or files needed for your script to run. |
11,533,939 | If I have more than one class in a python script, how do I call a function from the first class in the second class?
Here is an Example:
```
Class class1():
def function1():
blah blah blah
Class class2():
*How do I call function1 to here from class1*
``` | 2012/07/18 | [
"https://Stackoverflow.com/questions/11533939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1481620/"
] | Functions in classes are also known as methods, and they are invoked on objects. The way to call a method in class1 from class2 is to have an instance of class1:
```
class Class2(object):
def __init__(self):
self.c1 = Class1()
self.c1.function1()
``` | The cleanest way is probably through inheritance:
```
class Base(object):
def function1(self):
# blah blah blah
class Class1(Base):
def a_method(self):
self.function1() # works
class Class2(Base):
def some_method(self):
self.function1() # works
c1 = Class1()
c1.function1() # w... |
27,296,373 | I'm importing data with XLRD. The overall project involves pulling data from existing Excel files, but there are merged cells. Essentially, an operator is accounting for time on one of 3 shifts. As such, for each date on the grid they're working with, there are 3 columns (one for each shift). I want to change the UI as... | 2014/12/04 | [
"https://Stackoverflow.com/questions/27296373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2711535/"
] | I dont think this is a good application for a comprehension, and an explicit loop would be better:
```
lst = [41665.0, '', '', 41666.0, '', '', 41667.0, '', '', 41668.0, '', '', 41669.0, '', '', 41670.0, '', >>> lst = [41665.0, '', '', 41666.0, '', '', 41667.0, '', '', 41668.0, '', '', 41669.0, '', '', 41670.0, '', ''... | Another solution,
```
>>> l = [41665.0, '', '', 41666.0, '', '', 41667.0, '', '', 41668.0, '', '', 41669.0, '', '', 41670.0, '', '', 41671.0, '', '']
>>> lst = [ item for item in l if item is not '']
>>> [ v for item in zip(lst,lst,lst) for v in item ]
[41665.0, 41665.0, 41665.0, 41666.0, 41666.0, 41666.0, 41667.0, 41... |
38,971,465 | I want to use the stack method to get reverse string in this revers question.
"Write a function revstring(mystr) that uses a stack to reverse the characters in a string."
This is my code.
```
from pythonds.basic.stack import Stack
def revstring(mystr):
myStack = Stack() //this is how i have myStack
... | 2016/08/16 | [
"https://Stackoverflow.com/questions/38971465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6712244/"
] | Here's 3 solutions to the same problem, just pick one:
**1ST SOLUTION**
Fixing your solution, you almost got it, you just need to indent properly
your blocks like this:
```
from pythonds.basic.stack import Stack
def revstring(mystr):
myStack = Stack() # this is how i have myStack
for ch in mystr: # loopin... | * the `while` should not be in the `for`
* the `return` should be outside, not in the `while`
**code:**
```
from pythonds.basic.stack import Stack
def revstring(mystr):
myStack = Stack() # this is how i have myStack
for ch in mystr: # looping through characters in my string
myStack.push(... |
69,897,646 | I'm using seaborn.displot to display a distribution of scores for a group of participants.
Is it possible to have the y axis show an actual percentage (example below)?
This is required by the audience for the data.
Currently it is done in excel but It would be more useful in python.
```py
import seaborn as sns
data... | 2021/11/09 | [
"https://Stackoverflow.com/questions/69897646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2015461/"
] | As mentioned by @JohanC, the y axis for a KDE is a [density](https://en.wikipedia.org/wiki/Probability_density_function), not a proportion, so it does not make sense to convert it to a percentage.
You'd have two options. One would be to plot a KDE curve over a histogram with histogram counts expressed as percentages:
... | * [`seaborn.displot`](https://seaborn.pydata.org/generated/seaborn.displot.html) is a figure-level plot providing access to several approaches for visualizing the univariate or bivariate distribution of data ([histplot](https://seaborn.pydata.org/generated/seaborn.histplot.html), [kdeplot](https://seaborn.pydata.org/ge... |
73,098,560 | Try to use pytorch, when I do
import torch
```
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-2-eb42ca6e4af3> in <module>
----> 1 import torch
C:\Big_Data_app\Anaconda3\lib\site-packages\torch\__in... | 2022/07/24 | [
"https://Stackoverflow.com/questions/73098560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14733291/"
] | I solved the problem.
Just reinstall your Anaconda.
**!!Warning!!: you will lose your lib.**
Referring solution:
[Problem with Torch 1.11](https://discuss.pytorch.org/t/problem-with-torch-1-11/146885) | The version may not be exactly as same as yours, but maybe [this question](https://stackoverflow.com/questions/63187161/error-while-import-pytorch-module-the-specified-module-could-not-be-found) asked on 2020-09-04 helps. |
73,098,560 | Try to use pytorch, when I do
import torch
```
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-2-eb42ca6e4af3> in <module>
----> 1 import torch
C:\Big_Data_app\Anaconda3\lib\site-packages\torch\__in... | 2022/07/24 | [
"https://Stackoverflow.com/questions/73098560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14733291/"
] | I solved the problem.
Just reinstall your Anaconda.
**!!Warning!!: you will lose your lib.**
Referring solution:
[Problem with Torch 1.11](https://discuss.pytorch.org/t/problem-with-torch-1-11/146885) | My problem was solved by creating a new conda environment and installing PyTorch there. Everything worked perfectly on the first try in the new environment. Reinstalling Anaconda will work too, but this solution is less costly. |
73,098,560 | Try to use pytorch, when I do
import torch
```
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-2-eb42ca6e4af3> in <module>
----> 1 import torch
C:\Big_Data_app\Anaconda3\lib\site-packages\torch\__in... | 2022/07/24 | [
"https://Stackoverflow.com/questions/73098560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14733291/"
] | I solved the problem.
Just reinstall your Anaconda.
**!!Warning!!: you will lose your lib.**
Referring solution:
[Problem with Torch 1.11](https://discuss.pytorch.org/t/problem-with-torch-1-11/146885) | In my case PyTorch broke after playing around with TensorFlow (installing different CPU and CUDA versions). I've just run Anaconda Prompt (with administrative privileges) and ordered Anaconda to update all possible packages by running following command:
```
conda update --all
```
After that the problem with PyTorch ... |
56,303,279 | when i run this code:
```
#!/usr/bin/env python
import scapy.all as scapy
from scapy_http import http
def sniff(interface):
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
def process_sniffed_packet(packet):
if packet.haslayer(http.HTTPRequest):
print(packet)
sniff("eth0")
``... | 2019/05/25 | [
"https://Stackoverflow.com/questions/56303279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11533009/"
] | You can fix this problem by using `python2` instead of `python3`. If you don't want to change your python version then you'd need to make some changes to `scapy-http`'s library codes. From your traceback I can see that file is located at: `/usr/local/lib/python3.7/dist-packages/scapy_http/http.py`. Now open that file w... | You're using `scapy_http` in addition to `scapy`.
`scapy_http` hasn't been update in a while, and has poor compatibility with Python 3+
Feel free to have a look at <https://github.com/secdev/scapy/pull/1925> : it's not merged in Scapy yet (should be sometimes soon I guess) but it's an updated & improved port of `scapy... |
65,977,278 | I have a image:
It has some time in it.
But I need to convert it to this using python:
this:
[](https://i.stack.imgur.com/j3iIp.png)
to this
[](https://i.stack.imgur.com/d61GK.png)
... | 2021/01/31 | [
"https://Stackoverflow.com/questions/65977278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13994535/"
] | Try this out.
```py
sampleList = [
'CustomerA', 'Yes', 'No', 'No',
'CustomerB', 'No', 'No', 'No',
'CustomerC', 'Yes', 'Yes', 'No'
]
preferredOutput = [
tuple(sampleList[n : n + 4])
for n in range(0, len(sampleList), 4)
]
print(preferredOutput)
# OUTPUT (IN PRETTY FORM)
#
# [
# ('CustomerA'... | You can use list comprehension `output=[tuple(sampleList[4*i:4*i+4]) for i in range(3)]` |
49,220,569 | a=[('<https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.4766j0j7&sourceid=chrome&ie=UTF-8>', 1), ('<https://kite.zerodha.com/>', 1), ('<https://kite.trade/connect/login?api_key=xyz>', 1)]
how to get value of api\_key which is xyz from above mentioned `a`.
please help me to write code in... | 2018/03/11 | [
"https://Stackoverflow.com/questions/49220569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9337404/"
] | Just looping over all elements and parsing url to get the api\_key, have a look into below code:
```
from urlparse import urlparse, parse_qs
a=[('https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.4766j0j7&sourceid=chrome&ie=UTF-8', 1), ('https://kite.zerodha.com/', 1), ('https://kite.t... | This will work too. Hope this helps.
>
> * Find all items that has the keyword 'api\_key' (in url[0]),
> * Split it into columns, delimited by '=' (split by '=')
> * The last entry ([-1]) will be the answer (xyz).
>
>
>
```
a=[('https://www.google.co.in/search?q=kite+zerodha&oq=kite%2Cz&aqs=chrome.1.69i57j0l5.476... |
55,905,144 | Here is an image showing Python scope activity (version 3.6 and target x64):
Python Scope
[](https://i.stack.imgur.com/QqZbP.png)
The main problem is the relation between both invoke python methods, the first one is used to start the class object, and the second one to access ... | 2019/04/29 | [
"https://Stackoverflow.com/questions/55905144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11425716/"
] | I believe that this activity was designed with simple scripts in mind, not with entire classes. [Here's](https://forum.uipath.com/t/python-script-with-class-and-object/111110/3) an article on their Community Forum where user Sergiu.Wittenberger goes into more details.
Let's start with the Load Python Script activity:
... | I would like to add to what the above user said that you have to make sure that the imports you use are in the global site-packages, and not in a venv as Studio doesn't have access to that.
Moreoever, always add this:
```
import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
```
to the ... |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | This seems like a bogus message. I get the same warning message after upgrading to TensorFlow 2.1, but I do not use any class weights or sample weights at all. I do use a generator that returns a tuple like this:
```
return inputs, targets
```
And now I just changed it to the following to make the warning go away:
... | I have taken your Gist and installed Tensorflow 2.0, instead of TFA and it worked without any such Warning.
Here is the [Gist](https://colab.sandbox.google.com/gist/rmothukuru/e9d65d1119d90c1ec0d435249f3f5d01/untitled2.ipynb) of the complete code. Code for installing the Tensorflow is shown below:
```
!pip install t... |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | I believe this is a bug with tensorflow that will happen when you call `model.compile()` with default parameter `sample_weight_mode=None` and then call `model.fit()` with specified `sample_weight` or `class_weight`.
From the tensorflow repos:
* `fit()` eventually calls `_process_training_inputs()`
* `_process_trainin... | I have taken your Gist and installed Tensorflow 2.0, instead of TFA and it worked without any such Warning.
Here is the [Gist](https://colab.sandbox.google.com/gist/rmothukuru/e9d65d1119d90c1ec0d435249f3f5d01/untitled2.ipynb) of the complete code. Code for installing the Tensorflow is shown below:
```
!pip install t... |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | I have taken your Gist and installed Tensorflow 2.0, instead of TFA and it worked without any such Warning.
Here is the [Gist](https://colab.sandbox.google.com/gist/rmothukuru/e9d65d1119d90c1ec0d435249f3f5d01/untitled2.ipynb) of the complete code. Code for installing the Tensorflow is shown below:
```
!pip install t... | instead of providing a dictionary
```
weights = {'0': 42.0, '1': 1.0}
```
i tried a list
```
weights = [42.0, 1.0]
```
and the warning disappeared. |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | This seems like a bogus message. I get the same warning message after upgrading to TensorFlow 2.1, but I do not use any class weights or sample weights at all. I do use a generator that returns a tuple like this:
```
return inputs, targets
```
And now I just changed it to the following to make the warning go away:
... | I believe this is a bug with tensorflow that will happen when you call `model.compile()` with default parameter `sample_weight_mode=None` and then call `model.fit()` with specified `sample_weight` or `class_weight`.
From the tensorflow repos:
* `fit()` eventually calls `_process_training_inputs()`
* `_process_trainin... |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | This seems like a bogus message. I get the same warning message after upgrading to TensorFlow 2.1, but I do not use any class weights or sample weights at all. I do use a generator that returns a tuple like this:
```
return inputs, targets
```
And now I just changed it to the following to make the warning go away:
... | instead of providing a dictionary
```
weights = {'0': 42.0, '1': 1.0}
```
i tried a list
```
weights = [42.0, 1.0]
```
and the warning disappeared. |
59,317,919 | Training an image classifier using `.fit_generator()` or `.fit()` and passing a dictionary to `class_weight=` as an argument.
I never got errors in TF1.x but in 2.1 I get the following output when starting training:
```none
WARNING:tensorflow:sample_weight modes were coerced from
...
to
['...']
```
What d... | 2019/12/13 | [
"https://Stackoverflow.com/questions/59317919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1838257/"
] | I believe this is a bug with tensorflow that will happen when you call `model.compile()` with default parameter `sample_weight_mode=None` and then call `model.fit()` with specified `sample_weight` or `class_weight`.
From the tensorflow repos:
* `fit()` eventually calls `_process_training_inputs()`
* `_process_trainin... | instead of providing a dictionary
```
weights = {'0': 42.0, '1': 1.0}
```
i tried a list
```
weights = [42.0, 1.0]
```
and the warning disappeared. |
21,083,760 | I have two files that are tab delimited.I need to compare file 1 column 3 to file 2 column 1 .If there is a match I need to write column 2 of file 2 next to the matching line in file 1.here is a sample of my file:
file 1:
```
a rao rocky1 beta
b rao buzzy2 beta
c Rachel rocky2 alpha
```
file 2:
```
rocky1 highli... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21083760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2464553/"
] | ```
import sys
# Usage: python SCRIPT.py FILE1 FILE2 > OUTPUT
file1, file2 = sys.argv[1:3]
# Store info from the smaller file in a dict.
d = {}
with open(file2) as fh:
for line in fh:
k, v = line.split()
d[k] = v
# Process the bigger file line-by-line, printing to standard output.
with open(f... | ```
with open('outfile.txt', 'w') as outfile:
with open('file1.txt', 'r') as f1:
with open('file2.txt', 'r') as f2:
for f1line in f1:
for f2line in f2:
## remove new line character at end of each line
f1line = f1line.rs... |
21,083,760 | I have two files that are tab delimited.I need to compare file 1 column 3 to file 2 column 1 .If there is a match I need to write column 2 of file 2 next to the matching line in file 1.here is a sample of my file:
file 1:
```
a rao rocky1 beta
b rao buzzy2 beta
c Rachel rocky2 alpha
```
file 2:
```
rocky1 highli... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21083760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2464553/"
] | ```
import sys
# Usage: python SCRIPT.py FILE1 FILE2 > OUTPUT
file1, file2 = sys.argv[1:3]
# Store info from the smaller file in a dict.
d = {}
with open(file2) as fh:
for line in fh:
k, v = line.split()
d[k] = v
# Process the bigger file line-by-line, printing to standard output.
with open(f... | `file2` is set up to be the associative array and it's the smaller of the two files, so I re-arranged the awk a bit to get:
```
awk 'NR==FNR { if( length($1) > 0) a[$1]=$2; next} { if( $3 in a ) {print $0,a[$3] } else { print $0 } }' file2 file1 > newfile
```
1. For some reason, my machine wouldn't create `a[]` unti... |
21,083,760 | I have two files that are tab delimited.I need to compare file 1 column 3 to file 2 column 1 .If there is a match I need to write column 2 of file 2 next to the matching line in file 1.here is a sample of my file:
file 1:
```
a rao rocky1 beta
b rao buzzy2 beta
c Rachel rocky2 alpha
```
file 2:
```
rocky1 highli... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21083760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2464553/"
] | ```
import sys
# Usage: python SCRIPT.py FILE1 FILE2 > OUTPUT
file1, file2 = sys.argv[1:3]
# Store info from the smaller file in a dict.
d = {}
with open(file2) as fh:
for line in fh:
k, v = line.split()
d[k] = v
# Process the bigger file line-by-line, printing to standard output.
with open(f... | Here is a more short `awk`
```
awk 'NR==FNR {a[$1]=$2;next} {print $0,$3 in a?a[$3]:""}' file2 file1
a rao rocky1 beta highlightpath
b rao buzzy2 beta
c Rachel rocky2 alpha greenpath
``` |
21,083,760 | I have two files that are tab delimited.I need to compare file 1 column 3 to file 2 column 1 .If there is a match I need to write column 2 of file 2 next to the matching line in file 1.here is a sample of my file:
file 1:
```
a rao rocky1 beta
b rao buzzy2 beta
c Rachel rocky2 alpha
```
file 2:
```
rocky1 highli... | 2014/01/13 | [
"https://Stackoverflow.com/questions/21083760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2464553/"
] | ```
import sys
# Usage: python SCRIPT.py FILE1 FILE2 > OUTPUT
file1, file2 = sys.argv[1:3]
# Store info from the smaller file in a dict.
d = {}
with open(file2) as fh:
for line in fh:
k, v = line.split()
d[k] = v
# Process the bigger file line-by-line, printing to standard output.
with open(f... | Addressing all the suggestions together:
I am getting none of these to work ! Maybe because of empty lines in my file 2? Well the lines are not completely empty. for example:
rocky1 highlightpath
rimper2 darkenpath
rocky2 greenpath
lacy2
lucy1 pembrooke
now when I ran the python codes given above I used a corre... |
56,504,180 | I have set up a Raspberry Pi connected to an LED strip which is controllable from my phone via a Node server I have running on the RasPi. It triggers a simple python script that sets a colour.
I'm looking to expand the functionality such that I have a python script continuously running and I can send colours to it tha... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56504180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635908/"
] | Just delete keys that must be exclude for invalid user:
```
myReportsHeader = () => {
const { valid_user } = this.props;
const { tableHeaders } = this.props.tableHeaders
const { labels: tableLabels } = tableHeaders
if (!valid_user) {
delete tableLabels['tb4']
}
return tableLabels
}
```
[Delete operat... | You can first construct an object with default values. Then add additional property if the condition is true and finally return it e.g:
```
const obj = {
tb1: tableLabels.tb1,
tb2: tableLabels.tb2,
tb3: tableLabels.tb3,
tb5: tableLabels.tb5,
tb6: tableLabels.tb6,
tb7: tableLabels.tb7,
tb8: ... |
56,504,180 | I have set up a Raspberry Pi connected to an LED strip which is controllable from my phone via a Node server I have running on the RasPi. It triggers a simple python script that sets a colour.
I'm looking to expand the functionality such that I have a python script continuously running and I can send colours to it tha... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56504180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635908/"
] | Just delete keys that must be exclude for invalid user:
```
myReportsHeader = () => {
const { valid_user } = this.props;
const { tableHeaders } = this.props.tableHeaders
const { labels: tableLabels } = tableHeaders
if (!valid_user) {
delete tableLabels['tb4']
}
return tableLabels
}
```
[Delete operat... | What [Maheer Ali commented](https://stackoverflow.com/questions/56504157/add-a-key-to-an-object-at-a-particular-position-in-javascript#comment99596414_56504157) should be an answer:
Objects don't guarantee the order of their keys.
For that use arrays.
So, you will probably have
```js
const columns = [tableLabels.t... |
56,504,180 | I have set up a Raspberry Pi connected to an LED strip which is controllable from my phone via a Node server I have running on the RasPi. It triggers a simple python script that sets a colour.
I'm looking to expand the functionality such that I have a python script continuously running and I can send colours to it tha... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56504180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635908/"
] | Just delete keys that must be exclude for invalid user:
```
myReportsHeader = () => {
const { valid_user } = this.props;
const { tableHeaders } = this.props.tableHeaders
const { labels: tableLabels } = tableHeaders
if (!valid_user) {
delete tableLabels['tb4']
}
return tableLabels
}
```
[Delete operat... | You can use spread syntax to avoid duplicate code.
```
const obj = { ...tableLabels }
if (!valid_user) {
// Delete tb4 if user is invalid
delete obj.tb4;
}
return obj;
``` |
56,504,180 | I have set up a Raspberry Pi connected to an LED strip which is controllable from my phone via a Node server I have running on the RasPi. It triggers a simple python script that sets a colour.
I'm looking to expand the functionality such that I have a python script continuously running and I can send colours to it tha... | 2019/06/08 | [
"https://Stackoverflow.com/questions/56504180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635908/"
] | Just delete keys that must be exclude for invalid user:
```
myReportsHeader = () => {
const { valid_user } = this.props;
const { tableHeaders } = this.props.tableHeaders
const { labels: tableLabels } = tableHeaders
if (!valid_user) {
delete tableLabels['tb4']
}
return tableLabels
}
```
[Delete operat... | I would do like this, a combination of [spread](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) and [destructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)
```
myReportsHeader = () => {
const { valid_user } = this... |
67,899,519 | I have a json file with size in 500 MB with structure like
```
{"user": "[email protected]","contact":[{"name":"Jack "John","number":"+1 23456789"},{"name":"Jack Jill","number":"+1 232324789"}]}
```
Issue is when i parse this string with pandas read\_json, I get error
`Unexpected character found when decoding object valu... | 2021/06/09 | [
"https://Stackoverflow.com/questions/67899519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9025131/"
] | In general here is no robust way to fix this, nor to ignore any part of the row nor even to ignore the whole row because if a quoted string can contain quotes and can also contain `:`s and `,`s then a messed up string can look exactly like a valid set of fields.
Having said that, if we target only the "name" field and... | You can try removing that extra " using regex `("[\s\w]*)(")([\s\w]*")`.
The regex try to match any string with spaces/alphabets followed by a quote and then followed again by spaces/alphabets and removing that additional quote.
This will work for the given problem but for more complex patterns, you may have to tweak... |
50,848,226 | Currently I am trying to run Stardew Valley from python by doing this:
```
import subprocess
subprocess.call(['cmd', 'D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe'])
```
However, this fails and only opens a CMD window. I have a basic understanding of how to launch programs from python, but I do not u... | 2018/06/14 | [
"https://Stackoverflow.com/questions/50848226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4848801/"
] | Can you try using the steam commandline using the appid of the game:
```
subprocess.call(r"C:\Program Files (x86)\Steam\Steam.exe -applaunch 413150")
```
you can find the app id in the "web document tab" from the desktop shortcut properties
(which can be generated by right click and select create desktop shortcut... | You don't have to use `cmd`, you can start the `.exe` directly.
Additionally you should be aware that `\` is used to escape characters in Python strings, but should not be interpreted specially in Windows paths. Better use raw strings prefixed with `r` for Windows paths, which disable such escapes:
```
import subproc... |
50,848,226 | Currently I am trying to run Stardew Valley from python by doing this:
```
import subprocess
subprocess.call(['cmd', 'D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe'])
```
However, this fails and only opens a CMD window. I have a basic understanding of how to launch programs from python, but I do not u... | 2018/06/14 | [
"https://Stackoverflow.com/questions/50848226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4848801/"
] | You don't have to use `cmd`, you can start the `.exe` directly.
Additionally you should be aware that `\` is used to escape characters in Python strings, but should not be interpreted specially in Windows paths. Better use raw strings prefixed with `r` for Windows paths, which disable such escapes:
```
import subproc... | You can use the following way:
```
import os
os.startfile("D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe")
```
What this piece of code does is, **it simply opens the file using its windows assigned default program**.
A disadvantage of this way of starting is that it won't return any process object. S... |
50,848,226 | Currently I am trying to run Stardew Valley from python by doing this:
```
import subprocess
subprocess.call(['cmd', 'D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe'])
```
However, this fails and only opens a CMD window. I have a basic understanding of how to launch programs from python, but I do not u... | 2018/06/14 | [
"https://Stackoverflow.com/questions/50848226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4848801/"
] | Can you try using the steam commandline using the appid of the game:
```
subprocess.call(r"C:\Program Files (x86)\Steam\Steam.exe -applaunch 413150")
```
you can find the app id in the "web document tab" from the desktop shortcut properties
(which can be generated by right click and select create desktop shortcut... | You can use the following way:
```
import os
os.startfile("D:\SteamR\steamapps\common\Stardew Valley\Stardew Valley.exe")
```
What this piece of code does is, **it simply opens the file using its windows assigned default program**.
A disadvantage of this way of starting is that it won't return any process object. S... |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Install Cython:
```
pip install cython
``` | In the CLI-python, import sys and look what's inside sys.path
Then try to use `export PYTHONPATH=whatyougot` |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | I only got one advice for you : Create a virtualenv. This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).
Should be one of the solutions. | That is easy.
You could try `install cython` package first.
It will upgrade your **easy\_install** built in python. |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this [question](https://stackoverflow.com/questions/257616/sudo-changes-path-why) for more info. You need to make sure that sudo calls the right python, either by using the full path:
```
sudo /usr/local/epd/bin/python setup.py... | For python3 use
```
sudo apt-get install cython3
```
For python2 use
```
sudo apt-get install cython
```
Details can be read at [this](https://superuser.com/questions/388750/install-cython-on-python-3-x) |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | I only got one advice for you : Create a virtualenv. This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).
Should be one of the solutions. | Ran into this again in modern times. The solution was simple:
```
pip uninstall cython && pip install cython
``` |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | I only got one advice for you : Create a virtualenv. This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).
Should be one of the solutions. | I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError. In case someone needs it - before installing requirements.txt run this command:
>
> pip install Cython --install-option="--no-cython-compile"
>
>
>
Installing GCC also might help. |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this [question](https://stackoverflow.com/questions/257616/sudo-changes-path-why) for more info. You need to make sure that sudo calls the right python, either by using the full path:
```
sudo /usr/local/epd/bin/python setup.py... | I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError. In case someone needs it - before installing requirements.txt run this command:
>
> pip install Cython --install-option="--no-cython-compile"
>
>
>
Installing GCC also might help. |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Run
>
> `which python`
>
>
>
Thats the path to the python that your system has defaulted too
then go to @tiago's method of:
>
> `sudo <output of which python> setup.py install`
>
>
> | I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError. In case someone needs it - before installing requirements.txt run this command:
>
> pip install Cython --install-option="--no-cython-compile"
>
>
>
Installing GCC also might help. |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Your sudo is not getting the right python. This is a known behaviour of sudo in Ubuntu. See this [question](https://stackoverflow.com/questions/257616/sudo-changes-path-why) for more info. You need to make sure that sudo calls the right python, either by using the full path:
```
sudo /usr/local/epd/bin/python setup.py... | Read like a thousand of these threads and finally got it for Python 3. (replace pip with pip3 if you have that kind of installation, and run `pip uninstall cython` if you have tried other solutions before running any of these)
Mac:
```
brew install cython
pip install --upgrade cython
```
Ubuntu
```
sudo apt-get in... |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Run
>
> `which python`
>
>
>
Thats the path to the python that your system has defaulted too
then go to @tiago's method of:
>
> `sudo <output of which python> setup.py install`
>
>
> | That is easy.
You could try `install cython` package first.
It will upgrade your **easy\_install** built in python. |
11,108,461 | I'm having a strange problem while trying to install the Python library `zenlib`, using its `setup.py` file. When I run the `setup.py` file, I get an import error, saying
>
> ImportError: No module named Cython.Distutils`
>
>
>
but I do have such a module, and I can import it on the python command line without a... | 2012/06/19 | [
"https://Stackoverflow.com/questions/11108461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1467306/"
] | Read like a thousand of these threads and finally got it for Python 3. (replace pip with pip3 if you have that kind of installation, and run `pip uninstall cython` if you have tried other solutions before running any of these)
Mac:
```
brew install cython
pip install --upgrade cython
```
Ubuntu
```
sudo apt-get in... | Just install Cython from
<http://cython.org/#download>
and install it using this command
```
sudo python setup.py install
```
Then run the command
```
sudo python -c 'import Cython.Distutils'
```
and it will be installed and the error message will disappear. |
38,557,849 | A peak finding program in a 1-D python list which returns a peak with its index if for an index 'x' in the list 'arr' if (arr[x] > arr[x+1] and arr[x] > arr[x-1]).
Special case
Case 1 : In case of the first element. Only compare it to the second element. If arr[x] > arr[x+1], peak found.
Case 2 : Last element. Compare ... | 2016/07/24 | [
"https://Stackoverflow.com/questions/38557849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4254959/"
] | for example, let us create a middleware function that will handle CORS using:
*[github.com/buaazp/fasthttprouter](https://github.com/buaazp/fasthttprouter)* and *[github.com/valyala/fasthttp](https://github.com/valyala/fasthttp)*
```
var (
corsAllowHeaders = "authorization"
corsAllowMethods = "HEAD,GE... | Example of auth middleware for fasthttp & fasthttprouter (new versions)
```
type Middleware func(h fasthttp.RequestHandler) fasthttp.RequestHandler
type AuthFunc func(ctx *fasthttp.RequestCtx) bool
func NewAuthMiddleware(authFunc AuthFunc) Middleware {
return func(h fasthttp.RequestHandler) fasthttp.RequestHandler... |
12,902,178 | >
> **Possible Duplicate:**
>
> [Compare two different files line by line and write the difference in third file - Python](https://stackoverflow.com/questions/7757626/compare-two-different-files-line-by-line-and-write-the-difference-in-third-file)
>
>
>
The logic in my head works something like this...
for lin... | 2012/10/15 | [
"https://Stackoverflow.com/questions/12902178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1747993/"
] | assuming I understand what you want to do .... use set intersection :)
```
for line in newlines:
if set(line.split()) & set(xlines): #set intersection
print "overlap between xlines and current line"
break
else:
fileresult.write(item)
``` | I presume this is what you want to do:
```
outfile = file("outfile.txt", "w")
lines_to_check_for = [ line for line in file("list.txt", "r") ]
for line in file("testing.txt", "r"):
if not line in lines_to_check_for:
outfile.write(line)
```
This will read all the lines in `list.txt` into an array, and then... |
12,902,178 | >
> **Possible Duplicate:**
>
> [Compare two different files line by line and write the difference in third file - Python](https://stackoverflow.com/questions/7757626/compare-two-different-files-line-by-line-and-write-the-difference-in-third-file)
>
>
>
The logic in my head works something like this...
for lin... | 2012/10/15 | [
"https://Stackoverflow.com/questions/12902178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1747993/"
] | assuming I understand what you want to do .... use set intersection :)
```
for line in newlines:
if set(line.split()) & set(xlines): #set intersection
print "overlap between xlines and current line"
break
else:
fileresult.write(item)
``` | If the input files format is that you have one item per line (so that the check for existing element in readlines lists is ok), you are looking for list membership test:
```
if item in xlines:
break
```
To point some some more python stuff: make a set from the list you test for membership (because the tests will... |
11,452,887 | Based on this example of a line from a file
```
1:alpha:beta
```
I'm trying to get python to read the file in and then line by line print whats after the 2nd `':'`
```
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
```
... | 2012/07/12 | [
"https://Stackoverflow.com/questions/11452887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | For the data format given this will work:
```
with open('data.txt') as inf:
for line in inf:
line = line.strip()
line = line.split(':')
print ':'.join(line[2:])
```
For `'1:alpha:beta'` the output would be `'beta'`
For `'1:alpha:beta:gamma'` the output would be `'beta:gamma'` (Thanks fo... | Values returned by functions aren't automatically sent to stdout in non-interactive mode, you have to explicitly print them.
So, for Python 2, use `print line.split(strip_char, 2)[2]`. If you ever use Python 3, it'll be `print(line.split(strip_char, 2)[2])`.
(Props to Jon Clements, I forgot you could limit how many t... |
11,452,887 | Based on this example of a line from a file
```
1:alpha:beta
```
I'm trying to get python to read the file in and then line by line print whats after the 2nd `':'`
```
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
```
... | 2012/07/12 | [
"https://Stackoverflow.com/questions/11452887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Values returned by functions aren't automatically sent to stdout in non-interactive mode, you have to explicitly print them.
So, for Python 2, use `print line.split(strip_char, 2)[2]`. If you ever use Python 3, it'll be `print(line.split(strip_char, 2)[2])`.
(Props to Jon Clements, I forgot you could limit how many t... | You get just 'beta' because join gives you a string:
```
data = '1:alpha:beta'
strip_char = ":"
strip_char.join(data.split(strip_char)[2:])
'beta'
```
Try this:
```
lines=[]
with open('filePath', 'r') as f:
for line in f.readlines():
lines.append(line.strip())
for line in lines: print line.split(':')[1... |
11,452,887 | Based on this example of a line from a file
```
1:alpha:beta
```
I'm trying to get python to read the file in and then line by line print whats after the 2nd `':'`
```
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
```
... | 2012/07/12 | [
"https://Stackoverflow.com/questions/11452887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | For the data format given this will work:
```
with open('data.txt') as inf:
for line in inf:
line = line.strip()
line = line.split(':')
print ':'.join(line[2:])
```
For `'1:alpha:beta'` the output would be `'beta'`
For `'1:alpha:beta:gamma'` the output would be `'beta:gamma'` (Thanks fo... | If it's everything after the 2nd ':' as a string (which can include ':') then use the maxsplit option, eg:
```
line.split(':', 2)[2]
```
eg:
```
>>> d = '1:alpha:beta:charlie:delta'
>>> d.split(':', 2)
['1', 'alpha', 'beta:charlie:delta']
```
**This saves joining afterwards** |
11,452,887 | Based on this example of a line from a file
```
1:alpha:beta
```
I'm trying to get python to read the file in and then line by line print whats after the 2nd `':'`
```
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
```
... | 2012/07/12 | [
"https://Stackoverflow.com/questions/11452887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | For the data format given this will work:
```
with open('data.txt') as inf:
for line in inf:
line = line.strip()
line = line.split(':')
print ':'.join(line[2:])
```
For `'1:alpha:beta'` the output would be `'beta'`
For `'1:alpha:beta:gamma'` the output would be `'beta:gamma'` (Thanks fo... | You get just 'beta' because join gives you a string:
```
data = '1:alpha:beta'
strip_char = ":"
strip_char.join(data.split(strip_char)[2:])
'beta'
```
Try this:
```
lines=[]
with open('filePath', 'r') as f:
for line in f.readlines():
lines.append(line.strip())
for line in lines: print line.split(':')[1... |
11,452,887 | Based on this example of a line from a file
```
1:alpha:beta
```
I'm trying to get python to read the file in and then line by line print whats after the 2nd `':'`
```
import fileinput
#input file
x = fileinput.input('ids.txt')
strip_char = ":"
for line in x:
strip_char.join(line.split(strip_char)[2:])
```
... | 2012/07/12 | [
"https://Stackoverflow.com/questions/11452887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If it's everything after the 2nd ':' as a string (which can include ':') then use the maxsplit option, eg:
```
line.split(':', 2)[2]
```
eg:
```
>>> d = '1:alpha:beta:charlie:delta'
>>> d.split(':', 2)
['1', 'alpha', 'beta:charlie:delta']
```
**This saves joining afterwards** | You get just 'beta' because join gives you a string:
```
data = '1:alpha:beta'
strip_char = ":"
strip_char.join(data.split(strip_char)[2:])
'beta'
```
Try this:
```
lines=[]
with open('filePath', 'r') as f:
for line in f.readlines():
lines.append(line.strip())
for line in lines: print line.split(':')[1... |
48,753,297 | I am trying to evaluate istio and trying to deploy the bookinfo example app provided with the istio installation. While doing that, I am facing the following issue.
```
Environment: Non production
1. Server Node - red hat enterprise linux 7 64 bit VM [3.10.0-693.11.6.el7.x86_64]
Server in customer secure vpn with n... | 2018/02/12 | [
"https://Stackoverflow.com/questions/48753297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3675410/"
] | For your example string, you could remove the `^` like:
[`(?<=FN=).+?(?=&.+?$)`](https://regex101.com/r/33BiQU/1)
`^` means assert the position at start of the string.
For this example, you could also write this as:
[`(?<=FN=)[^&]+`](https://regex101.com/r/uIORIF/1)
**Explanation**
* `(?<=` Positive lookbehind th... | Instead of a regex, you could use the "proper" way of parsing the URI and the query string:
```
Imports System.Web
Module Module1
Sub Main()
Dim u = New Uri("https://portal-gamma.myColgate.com/sites/ENG/Pages/r.aspx?RT=Modify Support&Element=Business Direct&SE=Chain Supply&FN=Freight Forwarder Standard O... |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | You can refer the below sample code:
```
class SampleAdapter(private var list: List<String>,
private val viewmodel: SampleViewModel,
private val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewT... | If i understand correctly from [this page](https://medium.com/@stephen.brewer/an-adventure-with-recyclerview-databinding-livedata-and-room-beaae4fc8116) it is not best to pass the `lifeCycleOwner` to a `RecyclerView.Adapter` binding item, since:
>
> When a ViewHolder has been
> detached, meaning it is not currently v... |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | You can refer the below sample code:
```
class SampleAdapter(private var list: List<String>,
private val viewmodel: SampleViewModel,
private val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewT... | Instead of passing LifeCycleOwner to RecyclerView. Try to use `observeForever(Observer)` in case of observing data from the RecyclerView. And remove observer after the work has been done using `removeObserver(Observer)`.
Refer Documentation: <https://developer.android.com/reference/androidx/lifecycle/LiveData#observeF... |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | You can refer the below sample code:
```
class SampleAdapter(private var list: List<String>,
private val viewmodel: SampleViewModel,
private val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewT... | You can pass lifecycleOwner to binding in onCreateViewHolder method.
```
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
...
binding.lifecycleOwner = parent.findViewTreeLifecycleOwner()
return ViewHolder(binding)
}
``` |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | You can refer the below sample code:
```
class SampleAdapter(private var list: List<String>,
private val viewmodel: SampleViewModel,
private val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewT... | As you can get lifecycle owner from Binding in the following;
```
inner class ViewHolder(binding: List....): RecyclerView.ViewHolder(binding.root) {
private val lifecycleOwner by lazy{
binding.root.context as? LifecycleOwner
}
}
``` |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | If i understand correctly from [this page](https://medium.com/@stephen.brewer/an-adventure-with-recyclerview-databinding-livedata-and-room-beaae4fc8116) it is not best to pass the `lifeCycleOwner` to a `RecyclerView.Adapter` binding item, since:
>
> When a ViewHolder has been
> detached, meaning it is not currently v... | Instead of passing LifeCycleOwner to RecyclerView. Try to use `observeForever(Observer)` in case of observing data from the RecyclerView. And remove observer after the work has been done using `removeObserver(Observer)`.
Refer Documentation: <https://developer.android.com/reference/androidx/lifecycle/LiveData#observeF... |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | If i understand correctly from [this page](https://medium.com/@stephen.brewer/an-adventure-with-recyclerview-databinding-livedata-and-room-beaae4fc8116) it is not best to pass the `lifeCycleOwner` to a `RecyclerView.Adapter` binding item, since:
>
> When a ViewHolder has been
> detached, meaning it is not currently v... | You can pass lifecycleOwner to binding in onCreateViewHolder method.
```
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
...
binding.lifecycleOwner = parent.findViewTreeLifecycleOwner()
return ViewHolder(binding)
}
``` |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | If i understand correctly from [this page](https://medium.com/@stephen.brewer/an-adventure-with-recyclerview-databinding-livedata-and-room-beaae4fc8116) it is not best to pass the `lifeCycleOwner` to a `RecyclerView.Adapter` binding item, since:
>
> When a ViewHolder has been
> detached, meaning it is not currently v... | As you can get lifecycle owner from Binding in the following;
```
inner class ViewHolder(binding: List....): RecyclerView.ViewHolder(binding.root) {
private val lifecycleOwner by lazy{
binding.root.context as? LifecycleOwner
}
}
``` |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | Instead of passing LifeCycleOwner to RecyclerView. Try to use `observeForever(Observer)` in case of observing data from the RecyclerView. And remove observer after the work has been done using `removeObserver(Observer)`.
Refer Documentation: <https://developer.android.com/reference/androidx/lifecycle/LiveData#observeF... | You can pass lifecycleOwner to binding in onCreateViewHolder method.
```
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
...
binding.lifecycleOwner = parent.findViewTreeLifecycleOwner()
return ViewHolder(binding)
}
``` |
63,461,566 | Currently using selenium in python and was trying to for loop after locating element by "img" tags in whole webpage. I am trying to save all the urls and img names to my 2 arrays.
```
imgurl = []
imgname = []
allimgtags = browser.find_element_by_tag_name("img")
for a in len(allimgtags):
imgurl.append(wholeimgtags... | 2020/08/18 | [
"https://Stackoverflow.com/questions/63461566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14082479/"
] | Instead of passing LifeCycleOwner to RecyclerView. Try to use `observeForever(Observer)` in case of observing data from the RecyclerView. And remove observer after the work has been done using `removeObserver(Observer)`.
Refer Documentation: <https://developer.android.com/reference/androidx/lifecycle/LiveData#observeF... | As you can get lifecycle owner from Binding in the following;
```
inner class ViewHolder(binding: List....): RecyclerView.ViewHolder(binding.root) {
private val lifecycleOwner by lazy{
binding.root.context as? LifecycleOwner
}
}
``` |
32,177,869 | I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?
Maybe what I want ask is what's the best way to setup multi... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32177869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853876/"
] | How did you set up Kubernetes? I'm not aware of any installation scripts that put pod IPs into a 172 subnet.
But in general, assuming Kubernetes has been set up properly (ideally using one of the provided scripts), using a [service object](https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/servi... | I realize maybe the question was a bit vague:
if what you want is for your app to talk to the redis service, then set a service for redis (with a name of 'redis' for example) and then the redis service will be accessible simply by calling it by its hostname 'redis'
check the guestbook example that sets up a Redis mas... |
32,177,869 | I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?
Maybe what I want ask is what's the best way to setup multi... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32177869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853876/"
] | How did you set up Kubernetes? I'm not aware of any installation scripts that put pod IPs into a 172 subnet.
But in general, assuming Kubernetes has been set up properly (ideally using one of the provided scripts), using a [service object](https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/servi... | Kubernetes provides a basic service discovery mechanism by providing DNS names to the kubernetes services (which are associated with pods). When a pod wants to talk to another pod, it should use the DNS name (e.g. svc1.namespace1.svc.cluster.local) |
32,177,869 | I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?
Maybe what I want ask is what's the best way to setup multi... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32177869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853876/"
] | When you create a service, the service will proxy the connection to the different pods.
A service therefore maintains the list of IPs of the pods' containers.
You can then look those up in the API
they will be at
```
http(s)://${KUBERNETES_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/${SERVICE_NAME}
```... | I realize maybe the question was a bit vague:
if what you want is for your app to talk to the redis service, then set a service for redis (with a name of 'redis' for example) and then the redis service will be accessible simply by calling it by its hostname 'redis'
check the guestbook example that sets up a Redis mas... |
32,177,869 | I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?
Maybe what I want ask is what's the best way to setup multi... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32177869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853876/"
] | When you create a service, the service will proxy the connection to the different pods.
A service therefore maintains the list of IPs of the pods' containers.
You can then look those up in the API
they will be at
```
http(s)://${KUBERNETES_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/${SERVICE_NAME}
```... | Kubernetes provides a basic service discovery mechanism by providing DNS names to the kubernetes services (which are associated with pods). When a pod wants to talk to another pod, it should use the DNS name (e.g. svc1.namespace1.svc.cluster.local) |
32,177,869 | I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?
Maybe what I want ask is what's the best way to setup multi... | 2015/08/24 | [
"https://Stackoverflow.com/questions/32177869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853876/"
] | I realize maybe the question was a bit vague:
if what you want is for your app to talk to the redis service, then set a service for redis (with a name of 'redis' for example) and then the redis service will be accessible simply by calling it by its hostname 'redis'
check the guestbook example that sets up a Redis mas... | Kubernetes provides a basic service discovery mechanism by providing DNS names to the kubernetes services (which are associated with pods). When a pod wants to talk to another pod, it should use the DNS name (e.g. svc1.namespace1.svc.cluster.local) |
69,602,778 | I have installed the library in Base conda environment (the only one I have):
```
(base) C:\Users\44444>conda install graphviz
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
```
Set the path in System -> Environment Variables : to both... | 2021/10/17 | [
"https://Stackoverflow.com/questions/69602778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16339433/"
] | You have only installed the `graphiz` software, not the python interface to it. For that you will need [this package](https://anaconda.org/conda-forge/python-graphviz) which you can install with
```
conda install -c conda-forge python-graphviz
``` | Don't add conda's folders to the system PATH manually. What you need to do to work with Anaconda is activating the environment via
```
conda activate
```
This will add all the following folders temporarily to the PATH:
```
C:\Users\44444\anaconda3
C:\Users\44444\anaconda3\Library\mingw-w64\bin
C:\Users\44444\anacon... |
52,089,002 | I was trying to install a plugin for tmux called powerline. I was installing some thing on brew like PyPy and python.
Now when I try to open a vim file I get:
```
dyld: Library not loaded: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/Python
Referenced from: /usr/local/bin/vim
Reason: image not foun... | 2018/08/30 | [
"https://Stackoverflow.com/questions/52089002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9470570/"
] | `=AVERAGE.WEIGHTED(FILTER(A:A,ISNUMBER(A:A)),FILTER(B:B,ISNUMBER(A:A)))`
`=SUM(FILTER(A:A*B:B / sum(FILTER(B:B,ISNUMBER(A:A))),ISNUMBER(A:A)))`
`=SUM(FILTER(A:A*B:B / (sum(B:B) - SUMIF(A:A,"><", B:B)),ISNUMBER(A:A)))`
case both columns contain strings, add 1 more condition for each formula:
`=AVERAGE.WEIGHTED(FILTE... | So let us suppose our numbers (we hope) sit in A2:A4 and the weights are in B2:B4. In C2, place
```
=if(and(ISNUMBER(A2),isnumber(B2)),A2,"")
```
and drag that down to C4 to keep only actual numbers for which we have weights.
Similarly in D2 (and drag to D4), use
```
=if(and(ISNUMBER(A2),isnumber(B2)),B2,"")
```... |
18,560,993 | This may be a well-known question stored in some FAQ but i can't google the solution. I'm trying to write a scalar function of scalar argument but allowing for ndarray argument. The function should check its argument for domain correctness because domain violation may cause an exception. This example demonstrates what ... | 2013/09/01 | [
"https://Stackoverflow.com/questions/18560993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1038377/"
] | This will work fine in NumPy >= 1.9 (not released as of writing this). On previous versions you can work around by an extra `np.asarray` call:
```
x[np.asarray(x > 0)] = 0
``` | Could you call `f([1.0])` instead?
Otherwise you can do:
```
x = np.asarray(x)
if x.ndim == 0:
x = x[..., None]
``` |
32,395,635 | I'm very new to odoo and python and was wondering if I could get some help getting my module to load. I've been following the odoo 8 documentation very closely and can't get anything to appear in the local modules part. (Yes, I have clicked refresh/update module list).
I have also made sure that I put the correct path... | 2015/09/04 | [
"https://Stackoverflow.com/questions/32395635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5300262/"
] | I think you might have missed to include the addon directory which includes the custom module.
It can be accomplished via two methods.
1. You can add to, the addons\_path directive in openerp-server.conf, (separate paths with a comma)
```
eg: addons_path = /opt/openerp/server/openerp/addons,custom_path_here
```
2.... | You need to restart your service (odoo-service). |
58,506,732 | **Objective**: to extract the first email from an email thread
**Description**: Based on manual inspection of the emails, I realized that the next email in the email thread always starts with a set of From, Sent, To and Subject
**Test Input**:
```
Hello World from: the other side of the first email
from: this
sen... | 2019/10/22 | [
"https://Stackoverflow.com/questions/58506732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4457330/"
] | To only get the first match, you could use a capturing group and match exactly what should follow.
```
^(.*)\r?\n\s*\r?\nfrom:.*\r?\nsent:.*\r?\nto:.*\r?\nsubject:
```
* `^` Start of string
* `(.*)` Match any char except a newline 0+ times
* `\r?\n\s*` Match a newline followed by 0+ times a whitespace char using `\s... | Maybe I am misunderstanding, but why don't you just do this:
```
re.compile(r"^.*from:\s(\w+@\w+\.\w+)")
```
This will find the first string in "email-form" (group 1) after the first "from: " at beginning of the string. |
58,506,732 | **Objective**: to extract the first email from an email thread
**Description**: Based on manual inspection of the emails, I realized that the next email in the email thread always starts with a set of From, Sent, To and Subject
**Test Input**:
```
Hello World from: the other side of the first email
from: this
sen... | 2019/10/22 | [
"https://Stackoverflow.com/questions/58506732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4457330/"
] | To only get the first match, you could use a capturing group and match exactly what should follow.
```
^(.*)\r?\n\s*\r?\nfrom:.*\r?\nsent:.*\r?\nto:.*\r?\nsubject:
```
* `^` Start of string
* `(.*)` Match any char except a newline 0+ times
* `\r?\n\s*` Match a newline followed by 0+ times a whitespace char using `\s... | ```
import re
text = """Hello World from: the other side of the first email
from: this
sent: at
to: that
subject: what
second email
from: this
sent: at
to: that
subject: what
third email
from: this
date: at
to: that
subject: what
fourth email"""
m = re.match(r'.*?(?=^from:[^\n]*\nsent:[^\n]*\nto:[^\n]*\nsubject... |
58,506,732 | **Objective**: to extract the first email from an email thread
**Description**: Based on manual inspection of the emails, I realized that the next email in the email thread always starts with a set of From, Sent, To and Subject
**Test Input**:
```
Hello World from: the other side of the first email
from: this
sen... | 2019/10/22 | [
"https://Stackoverflow.com/questions/58506732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4457330/"
] | To only get the first match, you could use a capturing group and match exactly what should follow.
```
^(.*)\r?\n\s*\r?\nfrom:.*\r?\nsent:.*\r?\nto:.*\r?\nsubject:
```
* `^` Start of string
* `(.*)` Match any char except a newline 0+ times
* `\r?\n\s*` Match a newline followed by 0+ times a whitespace char using `\s... | Normally, each email message has a `Message-id:` header that uniquely identifies that message. Messages grouped in a thread make a tree of messages, al based on the header `In-response-to:` header, that links children (responses) with parents.
Your assumption can be used to link messages that lack the `Message-id:` he... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
<https://github.com/clips/pattern/tree/development>
The portin... | Additionally, I was facing :
```
"BadZipFile: File is not a zip file" error while importing from pattern.
```
This is because `sentiwordnet` which is out of date in nltk. So comment it in :
```
C:\Anaconda3\Lib\site-packages\Pattern-2.6-py3.5.egg\pattern\text\en\wordnet\_init.py
```
Make sure the necessary corpo... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | As of writing, Python 3.6 support is still not merged with master. However, it is available in the python3 branch.
To install via pip:
```
pip install https://github.com/clips/pattern/archive/python3.zip
```
Note that ThReSholD's answer for Python 3 (pattern3) is for a:
[deprecated pattern3 repository which contai... | Additionally, I was facing :
```
"BadZipFile: File is not a zip file" error while importing from pattern.
```
This is because `sentiwordnet` which is out of date in nltk. So comment it in :
```
C:\Anaconda3\Lib\site-packages\Pattern-2.6-py3.5.egg\pattern\text\en\wordnet\_init.py
```
Make sure the necessary corpo... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | **pip install pattern3** - Python 3.x
**pip install pattern** - Python 2.7.x | In the upgrade from python 2.x to 3.x, the print statement was made into a function call rather than a keyword. What used to be the line `print "Hello world!"` is now the line `print("Hello world!")`. So now all code written for 2.x that prints to the console does not work in version 3.x, as the compiler hits a runtime... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | **pip install pattern3** - Python 3.x
**pip install pattern** - Python 2.7.x | Additionally, I was facing :
```
"BadZipFile: File is not a zip file" error while importing from pattern.
```
This is because `sentiwordnet` which is out of date in nltk. So comment it in :
```
C:\Anaconda3\Lib\site-packages\Pattern-2.6-py3.5.egg\pattern\text\en\wordnet\_init.py
```
Make sure the necessary corpo... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
<https://github.com/clips/pattern/tree/development>
The portin... | In the upgrade from python 2.x to 3.x, the print statement was made into a function call rather than a keyword. What used to be the line `print "Hello world!"` is now the line `print("Hello world!")`. So now all code written for 2.x that prints to the console does not work in version 3.x, as the compiler hits a runtime... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | **pip install pattern3** - Python 3.x
**pip install pattern** - Python 2.7.x | The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
<https://github.com/clips/pattern/tree/development>
The portin... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | **pip install pattern3** - Python 3.x
**pip install pattern** - Python 2.7.x | Using Windows Subsystem for Linux, I made pattern to work using conda from (miniconda) in
Python 3.6:
-----------
```sh
conda create -n test -c conda-forge python=3.7 pattern
conda activate test
```
works without issues
Python 3.7:
-----------
```sh
conda create -n test -c conda-forge python=3.7 pattern
conda ac... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
<https://github.com/clips/pattern/tree/development>
The portin... | Using Windows Subsystem for Linux, I made pattern to work using conda from (miniconda) in
Python 3.6:
-----------
```sh
conda create -n test -c conda-forge python=3.7 pattern
conda activate test
```
works without issues
Python 3.7:
-----------
```sh
conda create -n test -c conda-forge python=3.7 pattern
conda ac... |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | The short answer at the moment is - you can't. They haven't quite finished the port to python3 yet.
There is alleged compatibility in the development branch but the recommended manual setup didn't work for me (in virtualenv) - it fails in a different way.
<https://github.com/clips/pattern/tree/development>
The portin... | For Mac OS:
```
brew install mysql
export PATH=$PATH:/usr/local/mysql/bin
pip3 install mysql-connector
pip3 install https://github.com/clips/pattern/archive/python3.zip
``` |
34,998,210 | How do I pip install pattern packages in python 3.5?
While in CMD:
```
pip install pattern
syntaxerror: missing parentheses in call to 'print'
```
Shows error:
```
messageCommand "python setup.py egg_info" failed with error
code 1 in temp\pip-build-3uegov4d\pattern
```
`seaborn` and `tweepy` were all suc... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34998210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5818150/"
] | For Mac OS:
```
brew install mysql
export PATH=$PATH:/usr/local/mysql/bin
pip3 install mysql-connector
pip3 install https://github.com/clips/pattern/archive/python3.zip
``` | Additionally, I was facing :
```
"BadZipFile: File is not a zip file" error while importing from pattern.
```
This is because `sentiwordnet` which is out of date in nltk. So comment it in :
```
C:\Anaconda3\Lib\site-packages\Pattern-2.6-py3.5.egg\pattern\text\en\wordnet\_init.py
```
Make sure the necessary corpo... |
8,891,099 | I seem to have stumbled across a quirk in Django custom model fields. I have the following custom modelfield:
```
class PriceField(models.DecimalField):
__metaclass__ = models.SubfieldBase
def to_python(self, value):
try:
return Price(super(PriceField, self).to_python(value))
excep... | 2012/01/17 | [
"https://Stackoverflow.com/questions/8891099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/836049/"
] | Answered my own question: This apparently is a Django bug. values\_list does not deserialize the database data.
It's being tracked here: <https://code.djangoproject.com/ticket/9619> and is pending a design decision. | Just to note that this was resolved in Django 1.8 with the addition of the `from_db_value` method on custom fields.
See <https://docs.djangoproject.com/en/1.8/howto/custom-model-fields/#converting-values-to-python-objects> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.