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 |
|---|---|---|---|---|---|
20,383,924 | What I am trying to do is access the traffic meter data on my local netgear router. It's easy enough to login to it and click on the link, but ideally I would like a little app that sits down in the system tray (windows) that I can check whenever I want to see what my network traffic is.
I'm using python to try to acc... | 2013/12/04 | [
"https://Stackoverflow.com/questions/20383924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1777330/"
] | Okay, I found the solution and it was way easier than I thought. I did try John1024's suggestion and was able to download the proper webpage from the router using wget. However I didn't like the fact that wget saved the result to a file, which I would then have to open and parse.
I ended up going back to the original ... | The web interface for my Netgear router (WNDR3700) is also filled with javascript. Yours may differ but I have found that my scripts can get all the info they need without javascript.
The first step is finding the correct URL. Using FireFox, I went to the traffic page and then used "This Frame -> Show only this frame"... |
29,516,084 | Getting the following error when trying to install Pandas (0.16.0), which is in my requirements.txt file, on AWS Elastic Beanstalk EC2 instance:
```
building 'pandas.msgpack' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-si... | 2015/04/08 | [
"https://Stackoverflow.com/questions/29516084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1177562/"
] | For pandas being compiled on Elastic Beanstalk, make sure to have both packages: `gcc-c++` *and* `python-devel`
```
packages:
yum:
gcc-c++: []
python-devel: []
``` | Install `python-dev`
```
sudo apt-get install python-dev
```
For `python3`
```
sudo apt-get install python3-dev
``` |
29,516,084 | Getting the following error when trying to install Pandas (0.16.0), which is in my requirements.txt file, on AWS Elastic Beanstalk EC2 instance:
```
building 'pandas.msgpack' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-si... | 2015/04/08 | [
"https://Stackoverflow.com/questions/29516084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1177562/"
] | For pandas being compiled on Elastic Beanstalk, make sure to have both packages: `gcc-c++` *and* `python-devel`
```
packages:
yum:
gcc-c++: []
python-devel: []
``` | on ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install |
29,516,084 | Getting the following error when trying to install Pandas (0.16.0), which is in my requirements.txt file, on AWS Elastic Beanstalk EC2 instance:
```
building 'pandas.msgpack' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-si... | 2015/04/08 | [
"https://Stackoverflow.com/questions/29516084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1177562/"
] | For pandas being compiled on Elastic Beanstalk, make sure to have both packages: `gcc-c++` *and* `python-devel`
```
packages:
yum:
gcc-c++: []
python-devel: []
``` | I had to upgrade amazon's EC2 pip. You can do this by editing the .config file in .ebextensions:
`sh
commands:
00_update_pip:
command: "/opt/python/run/venv/bin/pip install --upgrade pip"` |
29,516,084 | Getting the following error when trying to install Pandas (0.16.0), which is in my requirements.txt file, on AWS Elastic Beanstalk EC2 instance:
```
building 'pandas.msgpack' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-si... | 2015/04/08 | [
"https://Stackoverflow.com/questions/29516084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1177562/"
] | For pandas being compiled on Elastic Beanstalk, make sure to have both packages: `gcc-c++` *and* `python-devel`
```
packages:
yum:
gcc-c++: []
python-devel: []
``` | I solved this issue by ssh'ing in to the EBS machine and updating pip
```
pip install -U pip
``` |
68,341,995 | I have a python file that basically runs a main() function which scrapes data given a given keyword.
I am trying to do multiprocessing so my main function in my Jupyter Notebook looks like
```
p1 = multiprocessing.Process(target=main, args=['cosmetics'])
p2 = multiprocessing.Process(target=main, args=['airpod pro case... | 2021/07/12 | [
"https://Stackoverflow.com/questions/68341995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16404222/"
] | No, it's not that running the module using a terminal won't save files, that's actually the way you run python modules. Check your main() whether it is actually writing the CSV file or not. | the only question i saw in here was `Does running python file on termina/cmd not allow saving csv files?` the answer is no... its fine to save csv files in the command line typically
```
open("output.csv","w") as f:
f.write("this,is\na,csv")
``` |
68,341,995 | I have a python file that basically runs a main() function which scrapes data given a given keyword.
I am trying to do multiprocessing so my main function in my Jupyter Notebook looks like
```
p1 = multiprocessing.Process(target=main, args=['cosmetics'])
p2 = multiprocessing.Process(target=main, args=['airpod pro case... | 2021/07/12 | [
"https://Stackoverflow.com/questions/68341995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16404222/"
] | My bad guys, it was a stupid mistake on my part. I didn't actually do cd Desktop/DE to go to the DE folder on my terminal/cmd line and ran the code when I just opened the terminal/cmd, making the files automatically save somewhere else. | the only question i saw in here was `Does running python file on termina/cmd not allow saving csv files?` the answer is no... its fine to save csv files in the command line typically
```
open("output.csv","w") as f:
f.write("this,is\na,csv")
``` |
5,436,227 | I have a sandbox PAYPAL area,
My language is python - Django and I use django-paypal
ipn tes on my server works but
when someone try to buy something, after paypal process in sandbox I don't receive signal and in my paypal\_ipn I don't see the transaction.
So the problem is that I don't receive the signal.
This is my s... | 2011/03/25 | [
"https://Stackoverflow.com/questions/5436227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/677220/"
] | I think you can use the Paypal Test Tools to send fake notifactions to your notify url. That might make it easier to debug.
<http://www.friendly-stranger.com/pictures/paypal.jpg>
What you can also do is run the tests that come with django-paypal. It should be something like
```
python manage.py test paypal
```
Yo... | I had a similar problem. In my case, I could see from access logs that PayPal *is* accessing my payment notification URL, and the requests are 200 OK, but no signals triggered on Django side.
Turned out that payments had "Pending" status instead of "Completed" (and I wasn't listening on `paypal.standard.ipn.signals.pa... |
5,436,227 | I have a sandbox PAYPAL area,
My language is python - Django and I use django-paypal
ipn tes on my server works but
when someone try to buy something, after paypal process in sandbox I don't receive signal and in my paypal\_ipn I don't see the transaction.
So the problem is that I don't receive the signal.
This is my s... | 2011/03/25 | [
"https://Stackoverflow.com/questions/5436227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/677220/"
] | I think you can use the Paypal Test Tools to send fake notifactions to your notify url. That might make it easier to debug.
<http://www.friendly-stranger.com/pictures/paypal.jpg>
What you can also do is run the tests that come with django-paypal. It should be something like
```
python manage.py test paypal
```
Yo... | In my case the reason was trivial - I've added the signal handler code to `views.py` which is not loaded automatically so the handler was never really used and connected to the signal. The simplest but ugly solution is to move them to `models.py`, recommended is to use Django's [ready()](https://docs.djangoproject.com/... |
5,436,227 | I have a sandbox PAYPAL area,
My language is python - Django and I use django-paypal
ipn tes on my server works but
when someone try to buy something, after paypal process in sandbox I don't receive signal and in my paypal\_ipn I don't see the transaction.
So the problem is that I don't receive the signal.
This is my s... | 2011/03/25 | [
"https://Stackoverflow.com/questions/5436227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/677220/"
] | I had a similar problem. In my case, I could see from access logs that PayPal *is* accessing my payment notification URL, and the requests are 200 OK, but no signals triggered on Django side.
Turned out that payments had "Pending" status instead of "Completed" (and I wasn't listening on `paypal.standard.ipn.signals.pa... | In my case the reason was trivial - I've added the signal handler code to `views.py` which is not loaded automatically so the handler was never really used and connected to the signal. The simplest but ugly solution is to move them to `models.py`, recommended is to use Django's [ready()](https://docs.djangoproject.com/... |
12,138,298 | I am trying to use "With open()" with python 2.6 and it is giving error(Syntax error) while it works fine with python 2.7.3
Am I missing something or some import to make my program work!
Any help would be appreciated.
Br
My code is here:
```
def compare_some_text_of_a_file(self, exportfileTransferFolder, exportfile... | 2012/08/27 | [
"https://Stackoverflow.com/questions/12138298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864924/"
] | The `with open()` statement is supported in Python 2.6, you must have a different error.
See [PEP 343](http://www.python.org/dev/peps/pep-0343/) and the python [File Objects documentation](http://docs.python.org/library/stdtypes.html#file-objects) for the details.
Quick demo:
```
Python 2.6.8 (unknown, Apr 19 2012, ... | The `with open()` syntax is supported by Python 2.6. On Python 2.4 it is not supported and gives a syntax error. If you need to support PYthon 2.4, I would suggest something like:
```
def readfile(filename, mode='r'):
f = open(filename, mode)
try:
for line in f:
yield f
except e:
... |
12,138,298 | I am trying to use "With open()" with python 2.6 and it is giving error(Syntax error) while it works fine with python 2.7.3
Am I missing something or some import to make my program work!
Any help would be appreciated.
Br
My code is here:
```
def compare_some_text_of_a_file(self, exportfileTransferFolder, exportfile... | 2012/08/27 | [
"https://Stackoverflow.com/questions/12138298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864924/"
] | The `with open()` statement is supported in Python 2.6, you must have a different error.
See [PEP 343](http://www.python.org/dev/peps/pep-0343/) and the python [File Objects documentation](http://docs.python.org/library/stdtypes.html#file-objects) for the details.
Quick demo:
```
Python 2.6.8 (unknown, Apr 19 2012, ... | It is the "extended" `with` statement with multiple context expressions which causes your trouble.
In 2.6, instead of
```
with open(...) as f1, open(...) as f2:
do_stuff()
```
you should add a nesting level and write
```
with open(...) as f1:
with open(...) as f2:
do.stuff()
```
[The docu](http:... |
12,138,298 | I am trying to use "With open()" with python 2.6 and it is giving error(Syntax error) while it works fine with python 2.7.3
Am I missing something or some import to make my program work!
Any help would be appreciated.
Br
My code is here:
```
def compare_some_text_of_a_file(self, exportfileTransferFolder, exportfile... | 2012/08/27 | [
"https://Stackoverflow.com/questions/12138298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/864924/"
] | It is the "extended" `with` statement with multiple context expressions which causes your trouble.
In 2.6, instead of
```
with open(...) as f1, open(...) as f2:
do_stuff()
```
you should add a nesting level and write
```
with open(...) as f1:
with open(...) as f2:
do.stuff()
```
[The docu](http:... | The `with open()` syntax is supported by Python 2.6. On Python 2.4 it is not supported and gives a syntax error. If you need to support PYthon 2.4, I would suggest something like:
```
def readfile(filename, mode='r'):
f = open(filename, mode)
try:
for line in f:
yield f
except e:
... |
63,805,737 | i am trying to implement the following code but it is throwing an error
TypeError
```
Traceback (most recent call last)
<ipython-input-29-6ed67c712ed4> in <module>()
28 return model
29
---> 30 model = nvidia_model()
31 print(model.summary())
32 # dead relu problem: when a node i... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63805737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14206313/"
] | I was stuck on the same error. Here's what I found:
`Convolution2D` is a Keras v1 API (docs: <https://faroit.com/keras-docs/1.2.2/layers/convolutional/>)
`Conv2D` is the newer v2 API (docs: <https://faroit.com/keras-docs/2.0.5/layers/convolutional/>).
I got it working with the following changes:
1. Changed `import ... | Try using pooling instead of subsample. Usually that will work. |
63,805,737 | i am trying to implement the following code but it is throwing an error
TypeError
```
Traceback (most recent call last)
<ipython-input-29-6ed67c712ed4> in <module>()
28 return model
29
---> 30 model = nvidia_model()
31 print(model.summary())
32 # dead relu problem: when a node i... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63805737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14206313/"
] | ```py
def nvidia_model():
model= Sequential()
model.add(Convolution2D(24, 5, 5, subsample=(2, 2), input_shape=(66, 200, 3), activation='relu'))
model.add(Convolution2D(36, 5, 5, subsample=(2, 2), activation='relu'))
model.add(Convolution2D(48, 5, 5, subsample=(2, 2), activation='relu'))
model.a... | Try using pooling instead of subsample. Usually that will work. |
63,805,737 | i am trying to implement the following code but it is throwing an error
TypeError
```
Traceback (most recent call last)
<ipython-input-29-6ed67c712ed4> in <module>()
28 return model
29
---> 30 model = nvidia_model()
31 print(model.summary())
32 # dead relu problem: when a node i... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63805737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14206313/"
] | I was stuck on the same error. Here's what I found:
`Convolution2D` is a Keras v1 API (docs: <https://faroit.com/keras-docs/1.2.2/layers/convolutional/>)
`Conv2D` is the newer v2 API (docs: <https://faroit.com/keras-docs/2.0.5/layers/convolutional/>).
I got it working with the following changes:
1. Changed `import ... | Found the solution!!
It is because use the argument for Kernel as a tuple. So yah doing (5,5) for it worked for me.
p.s. this marks the first answer I ever gave, yay |
63,805,737 | i am trying to implement the following code but it is throwing an error
TypeError
```
Traceback (most recent call last)
<ipython-input-29-6ed67c712ed4> in <module>()
28 return model
29
---> 30 model = nvidia_model()
31 print(model.summary())
32 # dead relu problem: when a node i... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63805737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14206313/"
] | ```py
def nvidia_model():
model= Sequential()
model.add(Convolution2D(24, 5, 5, subsample=(2, 2), input_shape=(66, 200, 3), activation='relu'))
model.add(Convolution2D(36, 5, 5, subsample=(2, 2), activation='relu'))
model.add(Convolution2D(48, 5, 5, subsample=(2, 2), activation='relu'))
model.a... | I was stuck on the same error. Here's what I found:
`Convolution2D` is a Keras v1 API (docs: <https://faroit.com/keras-docs/1.2.2/layers/convolutional/>)
`Conv2D` is the newer v2 API (docs: <https://faroit.com/keras-docs/2.0.5/layers/convolutional/>).
I got it working with the following changes:
1. Changed `import ... |
63,805,737 | i am trying to implement the following code but it is throwing an error
TypeError
```
Traceback (most recent call last)
<ipython-input-29-6ed67c712ed4> in <module>()
28 return model
29
---> 30 model = nvidia_model()
31 print(model.summary())
32 # dead relu problem: when a node i... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63805737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14206313/"
] | ```py
def nvidia_model():
model= Sequential()
model.add(Convolution2D(24, 5, 5, subsample=(2, 2), input_shape=(66, 200, 3), activation='relu'))
model.add(Convolution2D(36, 5, 5, subsample=(2, 2), activation='relu'))
model.add(Convolution2D(48, 5, 5, subsample=(2, 2), activation='relu'))
model.a... | Found the solution!!
It is because use the argument for Kernel as a tuple. So yah doing (5,5) for it worked for me.
p.s. this marks the first answer I ever gave, yay |
12,521,189 | I'm familiar with programming but new to python:
>
> mem = [0] \* memloadsize
>
>
>
what does the '[0]' represent?
Is it a built-in array? | 2012/09/20 | [
"https://Stackoverflow.com/questions/12521189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493578/"
] | The `[` and `]` characters, in this context, are used to construct array literals:
```
>>> []
[]
>>> [0]
[0]
>>> ['a', 'b', 'c']
['a', 'b', 'c']
```
Multiplying arrays is idiomatic, and generates an array gotten by repeating the elements in the array by the given factor:
```
>>> ['a'] * 4
['a', 'a', 'a', 'a']
>>> [... | It just means a one element `list` containing just a 0. Multiplying by `memloadsize` gives you a `list` of `memloadsize` zeros. |
12,521,189 | I'm familiar with programming but new to python:
>
> mem = [0] \* memloadsize
>
>
>
what does the '[0]' represent?
Is it a built-in array? | 2012/09/20 | [
"https://Stackoverflow.com/questions/12521189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493578/"
] | It just means a one element `list` containing just a 0. Multiplying by `memloadsize` gives you a `list` of `memloadsize` zeros. | This command is conceptually equivalent to this:
```
mem = []
for i in xrange(memloadsize):
mem.append(0)
``` |
12,521,189 | I'm familiar with programming but new to python:
>
> mem = [0] \* memloadsize
>
>
>
what does the '[0]' represent?
Is it a built-in array? | 2012/09/20 | [
"https://Stackoverflow.com/questions/12521189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493578/"
] | The `[` and `]` characters, in this context, are used to construct array literals:
```
>>> []
[]
>>> [0]
[0]
>>> ['a', 'b', 'c']
['a', 'b', 'c']
```
Multiplying arrays is idiomatic, and generates an array gotten by repeating the elements in the array by the given factor:
```
>>> ['a'] * 4
['a', 'a', 'a', 'a']
>>> [... | This command is conceptually equivalent to this:
```
mem = []
for i in xrange(memloadsize):
mem.append(0)
``` |
6,522,281 | I've got a program that downloads part01, then part02 etc of a rar file split across the internet.
My program downloads part01 first, then part02 and so on.
After some tests, I found out that using, on example, UnRAR2 for python I can extract the first part of the file (an .avi file) contained in the archive and I'm ab... | 2011/06/29 | [
"https://Stackoverflow.com/questions/6522281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/774236/"
] | You are talking about an .avi file inside the rar archives. Are you sure the archives are actually compressed? [Video files released by the warez scene do not use compression:](http://en.wikipedia.org/wiki/Standard_%28warez%29#Packaging)
>
> Ripped movies are still packaged due to the large filesize, but compression ... | I highly doubt it. By nature of compression (from my understanding), every bit is needed to uncompress it. It seems that the source of where you are downloading from has intentionally broken the avi into pieces before compression, but by the time you apply compression, whatever you compressed is now one atomic unit. So... |
6,522,281 | I've got a program that downloads part01, then part02 etc of a rar file split across the internet.
My program downloads part01 first, then part02 and so on.
After some tests, I found out that using, on example, UnRAR2 for python I can extract the first part of the file (an .avi file) contained in the archive and I'm ab... | 2011/06/29 | [
"https://Stackoverflow.com/questions/6522281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/774236/"
] | I highly doubt it. By nature of compression (from my understanding), every bit is needed to uncompress it. It seems that the source of where you are downloading from has intentionally broken the avi into pieces before compression, but by the time you apply compression, whatever you compressed is now one atomic unit. So... | I don't know if this was asked with a specific language in mind, but it is possible to stream a compressed RAR directly from the internet and have it decompressed on the fly. I can do this with my C# library <http://sharpcompress.codeplex.com/>
The RAR format is actually kind of nice. It has headers preceding each ent... |
6,522,281 | I've got a program that downloads part01, then part02 etc of a rar file split across the internet.
My program downloads part01 first, then part02 and so on.
After some tests, I found out that using, on example, UnRAR2 for python I can extract the first part of the file (an .avi file) contained in the archive and I'm ab... | 2011/06/29 | [
"https://Stackoverflow.com/questions/6522281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/774236/"
] | You are talking about an .avi file inside the rar archives. Are you sure the archives are actually compressed? [Video files released by the warez scene do not use compression:](http://en.wikipedia.org/wiki/Standard_%28warez%29#Packaging)
>
> Ripped movies are still packaged due to the large filesize, but compression ... | I don't know if this was asked with a specific language in mind, but it is possible to stream a compressed RAR directly from the internet and have it decompressed on the fly. I can do this with my C# library <http://sharpcompress.codeplex.com/>
The RAR format is actually kind of nice. It has headers preceding each ent... |
57,604,719 | I was trying to install thrift(0.11.0) over my system(macOs 10.14.5).For which I downloaded and extracted tar file. Then I ran following commands :
```
./bootstrap.sh
./configure
make
make install
```
But **make install** throwed the following error :
```
error: could not create '/usr/lib/python2.7/site-packages': ... | 2019/08/22 | [
"https://Stackoverflow.com/questions/57604719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6729549/"
] | 1.open thrift's subfolder lib/py/ and modify the Makefile as follow:
PY\_PREFIX=/usr
change to
PY\_PREFIX = /Users/amy/python
2.sudo make install | I faced the same problem trying to install thrift on Mac OS.
I found a separate guide for installing thrift on Mac OS, I tried it and it finally worked successfully:
1- Download the boost library from [boost.org](http://www.boost.org/) untar compile with
```
./bootstrap.sh
sudo ./b2 threading=multi address-model=64... |
17,577,403 | I am trying to write an HTML parser in Python that takes as its input a URL or list of URLs and outputs specific data about each of those URLs in the format:
URL: data1: data2
The data points can be found at the exact same HTML node in each of the URLs. They are consistently between the same starting tags and ending ... | 2013/07/10 | [
"https://Stackoverflow.com/questions/17577403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2479631/"
] | ```
import urllib2
from bs4 import BeautifulSoup
url = 'http://www.youtube.com/watch?v=QOdW1OuZ1U0'
f = urllib2.urlopen(url)
data = f.read()
soup = BeautifulSoup(data)
span = soup.find('span', attrs={'class':'watch-view-count'})
print '{}:{}'.format(url, span.text)
```
If you do not want to use `BeautifulSoup`, you... | I prefer `HTMLParser` over `re` for this type of task. However, `HTMLParser` can be a bit tricky. I use immutable objects to store data... I'm sure this this the wrong way of doing it. But its worked with several projects for me in the past.
```
import urllib2
from HTMLParser import HTMLParser
import csv
position =... |
55,700,995 | I have. directory with ~250 .txt files in it. Each of these files has a title like this:
`Abraham Lincoln [December 01, 1862].txt`
`George Washington [October 25, 1790].txt`
etc...
However, these are terrible file names for reading into python and I want to iterate over all of them to change them to a more suitable... | 2019/04/16 | [
"https://Stackoverflow.com/questions/55700995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | Please try the straightforward (tedious) bash script:
```
#!/bin/bash
declare -A map=(["January"]="01" ["February"]="02" ["March"]="03" ["April"]="04" ["May"]="05" ["June"]="06" ["July"]="07" ["August"]="08" ["September"]="09" ["October"]="10" ["November"]="11" ["December"]="12")
pat='^([^[]+) \[([A-Za-z]+) ([0-9]+)... | I like to pull the filename apart, then put it back together.
Also GNU date can parse-out the time, which is simpler than using `sed` or a big `case` statement to convert "October" to "10".
```
#! /usr/bin/bash
if [ "$1" == "" ] || [ "$1" == "--help" ]; then
echo "Give a filename like \"Abraham Lincoln [December... |
55,700,995 | I have. directory with ~250 .txt files in it. Each of these files has a title like this:
`Abraham Lincoln [December 01, 1862].txt`
`George Washington [October 25, 1790].txt`
etc...
However, these are terrible file names for reading into python and I want to iterate over all of them to change them to a more suitable... | 2019/04/16 | [
"https://Stackoverflow.com/questions/55700995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | ```
for file in *.txt; do
# extract parts of the filename to be differently formatted with a regex match
[[ $file =~ (.*)\[(.*)\] ]] || { echo "invalid file $file"; exit; }
# format extracted strings and generate the new filename
formatted_date=$(date -d "${BASH_REMATCH[2]}" +"%Y_%m_%d")
name="${BA... | I like to pull the filename apart, then put it back together.
Also GNU date can parse-out the time, which is simpler than using `sed` or a big `case` statement to convert "October" to "10".
```
#! /usr/bin/bash
if [ "$1" == "" ] || [ "$1" == "--help" ]; then
echo "Give a filename like \"Abraham Lincoln [December... |
70,627,862 | How can i build a nested python dictionary, based on **number** of levels, like this?
How can be the recursive function passing int of levels?
```
{
"aggs": {
"cat_level_1": {
"terms": {
"field": "cat_level_1"
},
"aggs": {
"cat_level_2": {... | 2022/01/07 | [
"https://Stackoverflow.com/questions/70627862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8881622/"
] | We can build the dictionary from the deepest level, wrapping the previously built dictionary on each level.
```py
def dict_with_depth_of(n):
return {
"aggs": {
f"cat_level_{n}": {
"terms": {
"field": f"cat_level_{n}"
}
}
}
... | This is the right answer
```
def dict_with_depth_of(n):
return {
"aggs": {
f"cat_level_{n}": {
"terms": {
"field": f"cat_level_{n}"
}
}
}
}
def nested_dict(n):
d = None
for i in reversed(range(1, n + 1)):
... |
32,194,643 | So I am trying to use jinja2 for a simple html template but I keep getting this error when I call `render()`:
```
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\jinja2\jinja2\loaders.py", line 125, in load
Fil... | 2015/08/25 | [
"https://Stackoverflow.com/questions/32194643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3263488/"
] | Button should be of custom type to set an image. Verify your code once again. Set the button to custom type in Storyboard. | I can see you are using IBOutlet of a button this means you are using button from nib, then you should change background image from Attributes Inspector on right side of your xcode
otherwise if you still need it to be changed programmatically
then try this
```
[self.color1 setBackgroundImage:[UIImage imageNamed:@"57_... |
32,194,643 | So I am trying to use jinja2 for a simple html template but I keep getting this error when I call `render()`:
```
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\jinja2\jinja2\loaders.py", line 125, in load
Fil... | 2015/08/25 | [
"https://Stackoverflow.com/questions/32194643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3263488/"
] | Button should be of custom type to set an image. Verify your code once again. Set the button to custom type in Storyboard. | >
> I have a button and this button has a back color.
>
>
>
Are you trying to set the background color as well as background image of the button. You can only apply one thing at a time.
1. Verify if your button's type is System or Custom.
[](htt... |
72,596,436 | I've read about and understand [floating point round-off issues](https://docs.python.org/3/tutorial/floatingpoint.html) such as:
```
>>> sum([0.1] * 10) == 1.0
False
>>> 1.1 + 2.2 == 3.3
False
>>> sin(radians(45)) == sqrt(2) / 2
False
```
I also know how to work around these issues with [math.isclose()](https://do... | 2022/06/12 | [
"https://Stackoverflow.com/questions/72596436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/424499/"
] | The key to the solution is to build a wrapper that overrides the `__eq__` method and replaces it with an approximate match:
```
import cmath
class Approximately(complex):
def __new__(cls, x, /, **kwargs):
result = complex.__new__(cls, x)
result.kwargs = kwargs
return result
def __eq_... | Raymond's answer is very fancy and ergonomic, but seems like a lot of magic for something that could be much simpler. A more minimal version would just be to capture the calculated value and just explicitly check whether the things are "close", e.g.:
```
import math
match 1.1 + 2.2:
case x if math.isclose(x, 3.3)... |
5,684,010 | I want to change this string
`<p><b> hello world </b></p>. I am playing <b> python </b>`
to:
`<bold><bold>hello world </bold></bold>, I am playing <bold> python </bold>`
I used:
```
import re
pattern = re.compile(r'\<p>(.*?)\</p>|\<b>(.*?)\</b>')
print re.sub(pattern, r'<bold>\1</bold>', "<p><b>hello world</b>... | 2011/04/16 | [
"https://Stackoverflow.com/questions/5684010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/293487/"
] | If you choose not to use regex, then it simple as this:
```
d = {'<p>':'<bold>','</p>':'</bold>','<b>':'<bold>','</b>':'</bold>'}
s = '<p><b> hello world </b></p>. I am playing <b> python </b>'
for k,v in d.items():
s = s.replace(k,v)
``` | The problem is because the first group is the one within `<p></p>` and the second group is within `<b></b>` in the regexp. However, in your substitution you are referring to the first group when, if it matched to `<b></b>`, there wasn't one. I offer a couple of solutions.
First,
```
>>> pattern = re.compile(r'<(p|b... |
5,684,010 | I want to change this string
`<p><b> hello world </b></p>. I am playing <b> python </b>`
to:
`<bold><bold>hello world </bold></bold>, I am playing <bold> python </bold>`
I used:
```
import re
pattern = re.compile(r'\<p>(.*?)\</p>|\<b>(.*?)\</b>')
print re.sub(pattern, r'<bold>\1</bold>', "<p><b>hello world</b>... | 2011/04/16 | [
"https://Stackoverflow.com/questions/5684010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/293487/"
] | Although I don't recommend using Regex for parsing HTML (there are libraries for that purpose in almost every language), this should work:
```
text = "<p><b> hello world </b></p>. I am playing <b> python </b>"
import re
pattern1 = re.compile(r'\<p>(.*?)\</p>')
pattern2 = re.compile(r'\<b>(.*?)\</b>')
replaced = re... | The problem is because the first group is the one within `<p></p>` and the second group is within `<b></b>` in the regexp. However, in your substitution you are referring to the first group when, if it matched to `<b></b>`, there wasn't one. I offer a couple of solutions.
First,
```
>>> pattern = re.compile(r'<(p|b... |
5,931,386 | I help to maintain a package for python called nxt-python. It uses metaclasses to define the methods of a control object. Here's the method that defines the available functions:
```
class _Meta(type):
'Metaclass which adds one method for each telegram opcode'
def __init__(cls, name, bases, dict):
supe... | 2011/05/09 | [
"https://Stackoverflow.com/questions/5931386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/495504/"
] | For plain functions:
```
def f(): # for demonstration
pass
f.__doc__ = "Docstring!"
help(f)
```
This works in both python2 and python3, on functions with and without docstrings defined. You can also do `+=`. Note that it is `__doc__` and not `__docs__`.
For methods, you need to use the `__func__` attribute of... | You may also use [setattr](http://docs.python.org/library/functions.html#setattr) on the class/function object and set the docstring.
```
setattr(foo,'__doc__',"""My Doc string""")
``` |
41,252,289 | What's the syntax for *exclusive* `min` and `max` arguments for redis `zcount` command in python (redis-py)? It's not alluded to in the [documentation](https://redis-py.readthedocs.io/en/latest/).
Would it be:
```
minimum = time.time() - 2000
maximum = time.time()
my_server.zadd(sorted_set, '('+str(minimum), maximum... | 2016/12/20 | [
"https://Stackoverflow.com/questions/41252289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4936905/"
] | The [unit tests](https://github.com/andymccurdy/redis-py/blob/eae07e76b6524e6772be60169549766e7826419a/tests/test_commands.py) gives some examples:
```
def test_zcount(self, r):
r.zadd('a', a1=1, a2=2, a3=3)
assert r.zcount('a', '-inf', '+inf') == 3
assert r.zcount('a', 1, 2) == 2
assert r.zcount('a', ... | What about using `sys.float_info.epsilon`? This is the smallest comparable difference between two numbers:
```
minimum = time.time() - 2000
maximum = time.time()
my_server.zadd(sorted_set, minimum + sys.float_info.epsilon, maximum)
```
Or, with `-` for maximum:
```
minimum = time.time() - 2000
maximum = time.time()... |
35,422,156 | This is the code that I am working with:
```
import pandas as pd
z = pd.Series(data = [1,2,3,4,5,6,7], index = xrange(1,8))
array = []
for i in range(1,8):
array.append(z[i]*2)
print array
```
It does exactly what I tell it to because I can't figure out how to do a simple iteration. This is the printed outp... | 2016/02/16 | [
"https://Stackoverflow.com/questions/35422156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5020060/"
] | You want to use the last value of the accumulation list in the expression.
For example:
```
data = [ -3.2 , 30.66, 7.71, 9.87] # the input list for `sample`
In [686]: test=[100000]
In [687]: for i in range(4):
test.append(test[-1]*(1+data[i]/100))
In [688]: test
Out[688]: [100000, 96800.0, 126478.88, 1... | I think that what you're trying to do is to compute powers of two, instead of multiplications of two:
```
array.append(2**z[i])
``` |
20,993,084 | I am new to python and been stuck with an issue, any one please help me to solve this issue. Requirement is I have created a sqlite database and created a table and also inserted values to it but the problem is I am not getting how to display that data from database in table view in python so please help me out from th... | 2014/01/08 | [
"https://Stackoverflow.com/questions/20993084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2440020/"
] | This is a short, albeit complete example on how to achieve the expected result.
The trick is to define a [QSqlQueryModel](http://srinikom.github.io/pyside-docs/PySide/QtSql/QSqlQueryModel.html?highlight=qsqlquerymodel#PySide.QtSql.QSqlQueryModel) and pass it to a [QTableView](http://srinikom.github.io/pyside-docs/PySid... | I know this question has been a long time ago and the accepted one is for PyQt4. Because the API has been changed a bit on PyQt5, hope my answer can help someone using PyQt5.
```
from PyQt5 import QtWidgets, QtSql
# connect to postgresql
db = QtSql.QSqlDatabase.addDatabase("QPSQL")
db.setHostName(**)
db.setDatabaseNam... |
62,713,159 | I have a csv file with names (last\_name, name, age) and I want to convert all age attributes into integers. This is a way but I guess there is a more pythonic way to do so? I tried to do it with list comprehension but it didn't quite worked as I wanted.
```
import csv
with open("names.csv") as names_file:
head ,... | 2020/07/03 | [
"https://Stackoverflow.com/questions/62713159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13607895/"
] | Best way to handle this:
```
import pandas as pd
df = pd.read_csv('names.csv')
df["age"] = pd.to_numeric(df["age"])
```
If you want a list just do this:
```py
list_ = df['age'].to_list()
print(list_)
``` | I would do:
```
names = [['A', 'B', '20'], ['C', 'D', '30'], ['E', 'F', '40']] # sample data
for i in names:
i[2] = int(i[2])
print(names)
```
Which is more succint than:
```
for i in range(len(names)):
names[i][2] = int(names[i][2])
```
If you have to use list-comprehension then you might do:
```
names... |
62,713,159 | I have a csv file with names (last\_name, name, age) and I want to convert all age attributes into integers. This is a way but I guess there is a more pythonic way to do so? I tried to do it with list comprehension but it didn't quite worked as I wanted.
```
import csv
with open("names.csv") as names_file:
head ,... | 2020/07/03 | [
"https://Stackoverflow.com/questions/62713159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13607895/"
] | ```
import csv
with open("names.csv") as names_file:
head, *names = csv.reader(names_file)
names = [[f, l, int(a)] for f, l, a in names]
``` | I would do:
```
names = [['A', 'B', '20'], ['C', 'D', '30'], ['E', 'F', '40']] # sample data
for i in names:
i[2] = int(i[2])
print(names)
```
Which is more succint than:
```
for i in range(len(names)):
names[i][2] = int(names[i][2])
```
If you have to use list-comprehension then you might do:
```
names... |
33,982,834 | I have been trying to convert some code into a try statement but I can't seem to get anything working.
Here is my code in pseudo code:
```
start
run function
check for user input ('Would you like to test another variable? (y/n) ')
if: yes ('y') restart from top
elif: no ('n') exit program (loop is at end of progra... | 2015/11/29 | [
"https://Stackoverflow.com/questions/33982834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5552713/"
] | If you want to make your code neater, you should consider having
`while run:`
instead of
`while run == True:`
and also remove the last two lines, because setting `run` and `cont` to `True` again isn't necessary (their value didn't change).
Furthermore, I think that a `try - except` block would be useful in the ca... | >
> Ok so as a general case I will try to avoid try...except blocks
>
>
>
Don't do this. Use the right tool for the job.
Use `raise` to signal that your code can't (or shouldn't) deal with the scenario.
Use `try-except` to process that *signal*.
>
> Now what is the proper way for me to convert this into a tr... |
14,286,480 | I tagged python and perl in this only because that's what I've used thus far. If anyone knows a better way to go about this I'd certainly be willing to try it out. Anyway, my problem:
I need to create an input file for a gene prediction program that follows the following format:
```
seq1 5 15
seq1 20 34
seq2 50 48
s... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14286480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1784467/"
] | In Unix:
```
grep <file.gff3 " exon " |
sed "s/^\([^ ]+\) +[.] +exon +\([0-9]+\) \([0-9]+\).*$/\1 \2 \3/"
``` | For pedestrians:
(this is Python)
```
with open(data_file) as f:
for line in f:
tokens = line.split()
if len(tokens) > 3 and tokens[2] == 'exon':
print tokens[0], tokens[3], tokens[4]
```
which prints
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
``` |
14,286,480 | I tagged python and perl in this only because that's what I've used thus far. If anyone knows a better way to go about this I'd certainly be willing to try it out. Anyway, my problem:
I need to create an input file for a gene prediction program that follows the following format:
```
seq1 5 15
seq1 20 34
seq2 50 48
s... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14286480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1784467/"
] | For pedestrians:
(this is Python)
```
with open(data_file) as f:
for line in f:
tokens = line.split()
if len(tokens) > 3 and tokens[2] == 'exon':
print tokens[0], tokens[3], tokens[4]
```
which prints
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
``` | Here's a Perl script option `perl scriptName.pl file.gff3`:
```
use strict;
use warnings;
while (<>) {
print "@{ [ (split)[ 0, 3, 4 ] ] }\n" if /exon/;
}
```
Output:
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
```
Or you could just do the following:
```
perl -n -e 'print "@{ [ (split)[ 0, 3,... |
14,286,480 | I tagged python and perl in this only because that's what I've used thus far. If anyone knows a better way to go about this I'd certainly be willing to try it out. Anyway, my problem:
I need to create an input file for a gene prediction program that follows the following format:
```
seq1 5 15
seq1 20 34
seq2 50 48
s... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14286480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1784467/"
] | It looks like your data is tab-separated.
This Perl program will print columns 1, 4 and 5 from all records that have `exon` in the third column. You need to change the file name in the `open` statement to your actual file name.
```
use strict;
use warnings;
open my $fh, '<', 'genes.gff3' or die $!;
while (<$fh>) {
... | For pedestrians:
(this is Python)
```
with open(data_file) as f:
for line in f:
tokens = line.split()
if len(tokens) > 3 and tokens[2] == 'exon':
print tokens[0], tokens[3], tokens[4]
```
which prints
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
``` |
14,286,480 | I tagged python and perl in this only because that's what I've used thus far. If anyone knows a better way to go about this I'd certainly be willing to try it out. Anyway, my problem:
I need to create an input file for a gene prediction program that follows the following format:
```
seq1 5 15
seq1 20 34
seq2 50 48
s... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14286480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1784467/"
] | In Unix:
```
grep <file.gff3 " exon " |
sed "s/^\([^ ]+\) +[.] +exon +\([0-9]+\) \([0-9]+\).*$/\1 \2 \3/"
``` | Here's a Perl script option `perl scriptName.pl file.gff3`:
```
use strict;
use warnings;
while (<>) {
print "@{ [ (split)[ 0, 3, 4 ] ] }\n" if /exon/;
}
```
Output:
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
```
Or you could just do the following:
```
perl -n -e 'print "@{ [ (split)[ 0, 3,... |
14,286,480 | I tagged python and perl in this only because that's what I've used thus far. If anyone knows a better way to go about this I'd certainly be willing to try it out. Anyway, my problem:
I need to create an input file for a gene prediction program that follows the following format:
```
seq1 5 15
seq1 20 34
seq2 50 48
s... | 2013/01/11 | [
"https://Stackoverflow.com/questions/14286480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1784467/"
] | It looks like your data is tab-separated.
This Perl program will print columns 1, 4 and 5 from all records that have `exon` in the third column. You need to change the file name in the `open` statement to your actual file name.
```
use strict;
use warnings;
open my $fh, '<', 'genes.gff3' or die $!;
while (<$fh>) {
... | Here's a Perl script option `perl scriptName.pl file.gff3`:
```
use strict;
use warnings;
while (<>) {
print "@{ [ (split)[ 0, 3, 4 ] ] }\n" if /exon/;
}
```
Output:
```
PITG_00002 2 397
PITG_00004 1 1275
PITG_00004 1397 1969
```
Or you could just do the following:
```
perl -n -e 'print "@{ [ (split)[ 0, 3,... |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | Here's one way to do that:
```
>>> indices = numpy.indices((5, 5))
>>> a = indices[0] * indices[1]
>>> a
array([[ 0, 0, 0, 0, 0],
[ 0, 1, 2, 3, 4],
[ 0, 2, 4, 6, 8],
[ 0, 3, 6, 9, 12],
[ 0, 4, 8, 12, 16]])
```
To further explain, `numpy.indices((5, 5))` generates two arra... | I'm away from my python at the moment, but does this one work?
```
array( [ [ i*j for j in xrange(5)] for i in xrange(5)] )
``` |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | Here's one way to do that:
```
>>> indices = numpy.indices((5, 5))
>>> a = indices[0] * indices[1]
>>> a
array([[ 0, 0, 0, 0, 0],
[ 0, 1, 2, 3, 4],
[ 0, 2, 4, 6, 8],
[ 0, 3, 6, 9, 12],
[ 0, 4, 8, 12, 16]])
```
To further explain, `numpy.indices((5, 5))` generates two arra... | Just wanted to add that @Senderle's response can be generalized for any function and dimension:
```
dims = (3,3,3) #i,j,k
ii = np.indices(dims)
```
You could then calculate `a[i,j,k] = i*j*k` as
```
a = np.prod(ii,axis=0)
```
or `a[i,j,k] = (i-1)*j*k`:
```
a = (ii[0,...]-1)*ii[1,...]*ii[2,...]
```
etc |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | Here's one way to do that:
```
>>> indices = numpy.indices((5, 5))
>>> a = indices[0] * indices[1]
>>> a
array([[ 0, 0, 0, 0, 0],
[ 0, 1, 2, 3, 4],
[ 0, 2, 4, 6, 8],
[ 0, 3, 6, 9, 12],
[ 0, 4, 8, 12, 16]])
```
To further explain, `numpy.indices((5, 5))` generates two arra... | For the multiplication
```
np.multiply.outer(np.arange(5), np.arange(5)) # a_ij = i * j
```
and in general
```
np.frompyfunc(
lambda i, j: f(i, j), 2, 1
).outer(
np.arange(5),
np.arange(5),
).astype(np.float64) # a_ij = f(i, j)
```
basically you create an `np.ufunc` via `np.frompyfunc` and then `out... |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | A generic solution would be to use [np.fromfunction()](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html)
From the doc:
>
> `numpy.fromfunction(function, shape, **kwargs)`
>
>
> Construct an array by executing a function over each coordinate. The
> resulting array therefore has a value f... | Here's one way to do that:
```
>>> indices = numpy.indices((5, 5))
>>> a = indices[0] * indices[1]
>>> a
array([[ 0, 0, 0, 0, 0],
[ 0, 1, 2, 3, 4],
[ 0, 2, 4, 6, 8],
[ 0, 3, 6, 9, 12],
[ 0, 4, 8, 12, 16]])
```
To further explain, `numpy.indices((5, 5))` generates two arra... |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | A generic solution would be to use [np.fromfunction()](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html)
From the doc:
>
> `numpy.fromfunction(function, shape, **kwargs)`
>
>
> Construct an array by executing a function over each coordinate. The
> resulting array therefore has a value f... | I'm away from my python at the moment, but does this one work?
```
array( [ [ i*j for j in xrange(5)] for i in xrange(5)] )
``` |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | A generic solution would be to use [np.fromfunction()](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html)
From the doc:
>
> `numpy.fromfunction(function, shape, **kwargs)`
>
>
> Construct an array by executing a function over each coordinate. The
> resulting array therefore has a value f... | Just wanted to add that @Senderle's response can be generalized for any function and dimension:
```
dims = (3,3,3) #i,j,k
ii = np.indices(dims)
```
You could then calculate `a[i,j,k] = i*j*k` as
```
a = np.prod(ii,axis=0)
```
or `a[i,j,k] = (i-1)*j*k`:
```
a = (ii[0,...]-1)*ii[1,...]*ii[2,...]
```
etc |
6,254,713 | How can I create a numpy matrix with its elements being a function of its indices?
For example, a multiplication table: `a[i,j] = i*j`
An Un-numpy and un-pythonic would be to create an array of zeros and then loop through.
There is no doubt that there is a better way to do this, without a loop.
However, even better ... | 2011/06/06 | [
"https://Stackoverflow.com/questions/6254713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/349043/"
] | A generic solution would be to use [np.fromfunction()](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html)
From the doc:
>
> `numpy.fromfunction(function, shape, **kwargs)`
>
>
> Construct an array by executing a function over each coordinate. The
> resulting array therefore has a value f... | For the multiplication
```
np.multiply.outer(np.arange(5), np.arange(5)) # a_ij = i * j
```
and in general
```
np.frompyfunc(
lambda i, j: f(i, j), 2, 1
).outer(
np.arange(5),
np.arange(5),
).astype(np.float64) # a_ij = f(i, j)
```
basically you create an `np.ufunc` via `np.frompyfunc` and then `out... |
6,975,808 | I like to store my data after a longish python program as dictionaries in a new script. This then allows me to import the program (and hence data) easily for further manipulation.
I write something like this (an old example):
```
file = open(p['results']+'asa_contacts.py','w')
print>>file, \
'''
\'''
This file stores... | 2011/08/07 | [
"https://Stackoverflow.com/questions/6975808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299000/"
] | Unless there's a specific reason that you need source code -- and I suspect there isn't, you just want to serialize and deserialize data from disk -- a better option would be Python's [`pickle` module](http://docs.python.org/library/pickle.html). | [Lossy's suggestion](https://stackoverflow.com/questions/6975808/outputting-data-as-dictionaries-in-a-new-python-file/6975843#6975843) of `repr` happens to work, but `repr` isn't *specifically* designed for serialization. I think it would be slightly more robust to use a tool designed for that purpose; and since you wa... |
6,975,808 | I like to store my data after a longish python program as dictionaries in a new script. This then allows me to import the program (and hence data) easily for further manipulation.
I write something like this (an old example):
```
file = open(p['results']+'asa_contacts.py','w')
print>>file, \
'''
\'''
This file stores... | 2011/08/07 | [
"https://Stackoverflow.com/questions/6975808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299000/"
] | I am not sure if this is what you are looking for but try the inbuilt function repr.
```
repr(a)
``` | [Lossy's suggestion](https://stackoverflow.com/questions/6975808/outputting-data-as-dictionaries-in-a-new-python-file/6975843#6975843) of `repr` happens to work, but `repr` isn't *specifically* designed for serialization. I think it would be slightly more robust to use a tool designed for that purpose; and since you wa... |
48,765,260 | Object oriented python, I want to create a static method to convert hours, minutes and seconds into seconds.
I create a class called Duration:
```
class Duration:
def __init__(self, hours, minutes, seconds):
self.hours = hours
self.minutes = minutes
self.seconds = secon... | 2018/02/13 | [
"https://Stackoverflow.com/questions/48765260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6715237/"
] | You're almost there.
Instead of passing the result of `duration1.info()` to `duration1.static_method()`, you simply pass the whole object:
```
duration1 = Duration(29, 7, 10)
print(duration1.info()) # 29-07-10
print(duration1.static_method(duration1)) # 104830
```
And since it's a static method, you could just as w... | A static method is *explicitly* a function which is tied to a class rather than an instance. `self` in Python represents an instance of a class in Python.
These are not simpatico.
You can make your code work by passing `duration1` to your static method and changing the name of its accepted parameter from `self` to ... |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | `import queue` is **lowercase** `q` in Python 3.
Change `Q` to `q` and it will be fine.
(See code in <https://stackoverflow.com/a/29688081/632951> for smart switching.) | It's because of the Python version. In Python 2.x it's `import Queue as queue`; on the contrary in Python 3 it's `import queue`. If you want it for both environments you may use something below as mentioned [here](https://stackoverflow.com/questions/46363871/no-module-named-queue?noredirect=1&lq=1)
```
try:
import ... |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | I solve the problem my issue was I had file named queue.py in the same directory | It's because of the Python version. In Python 2.x it's `import Queue as queue`; on the contrary in Python 3 it's `import queue`. If you want it for both environments you may use something below as mentioned [here](https://stackoverflow.com/questions/46363871/no-module-named-queue?noredirect=1&lq=1)
```
try:
import ... |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | Queue is in the multiprocessing module so:
```
from multiprocessing import Queue
``` | In my case it should be:
`from multiprocessing import JoinableQueue`
Since in python2, Queue has methods like `.task_done()`, but in python3 `multiprocessing.Queue` doesn't have this method, and `multiprocessing.JoinableQueue` does. |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | It's because of the Python version. In Python 2.x it's `import Queue as queue`; on the contrary in Python 3 it's `import queue`. If you want it for both environments you may use something below as mentioned [here](https://stackoverflow.com/questions/46363871/no-module-named-queue?noredirect=1&lq=1)
```
try:
import ... | I run into the same problem and learn that queue module defines classes and exceptions, that defines the public methods (Queue Objects).
Ex.
```
workQueue = queue.Queue(10)
``` |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | I solve the problem my issue was I had file named queue.py in the same directory | I just copy the file name Queue.py in the `*/lib/python2.7/` to queue.py and that solved my problem. |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | It's because of the Python version. In Python 2.x it's `import Queue as queue`; on the contrary in Python 3 it's `import queue`. If you want it for both environments you may use something below as mentioned [here](https://stackoverflow.com/questions/46363871/no-module-named-queue?noredirect=1&lq=1)
```
try:
import ... | In my case it should be:
`from multiprocessing import JoinableQueue`
Since in python2, Queue has methods like `.task_done()`, but in python3 `multiprocessing.Queue` doesn't have this method, and `multiprocessing.JoinableQueue` does. |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | Queue is in the multiprocessing module so:
```
from multiprocessing import Queue
``` | It's because of the Python version. In Python 2.x it's `import Queue as queue`; on the contrary in Python 3 it's `import queue`. If you want it for both environments you may use something below as mentioned [here](https://stackoverflow.com/questions/46363871/no-module-named-queue?noredirect=1&lq=1)
```
try:
import ... |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | `import queue` is **lowercase** `q` in Python 3.
Change `Q` to `q` and it will be fine.
(See code in <https://stackoverflow.com/a/29688081/632951> for smart switching.) | I just copy the file name Queue.py in the `*/lib/python2.7/` to queue.py and that solved my problem. |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | I solve the problem my issue was I had file named queue.py in the same directory | In my case it should be:
`from multiprocessing import JoinableQueue`
Since in python2, Queue has methods like `.task_done()`, but in python3 `multiprocessing.Queue` doesn't have this method, and `multiprocessing.JoinableQueue` does. |
33,432,426 | I am trying to import `requests` module, but I got this error
my python version is 3.4 running on ubuntu 14.04
```
>>> import requests
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Em... | 2015/10/30 | [
"https://Stackoverflow.com/questions/33432426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5104452/"
] | Queue is in the multiprocessing module so:
```
from multiprocessing import Queue
``` | I just copy the file name Queue.py in the `*/lib/python2.7/` to queue.py and that solved my problem. |
57,229,074 | I am trying to import an existing database into my **Django** project, so I run `python manage.py migrate --fake-initial`, but I get this error:
```
operations to perform:
Apply all migrations: ExcursionsManagerApp, GeneralApp, InvoicesManagerApp, OperationsManagerApp, PaymentsManagerApp, RatesMan
agerApp, ReportsMa... | 2019/07/27 | [
"https://Stackoverflow.com/questions/57229074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6843153/"
] | Just by running the following [command](https://docs.djangoproject.com/en/3.1/ref/django-admin/#cmdoption-migrate-fake) would solve the problem:
```
python manage.py migrate --fake
``` | Steps you can follow to make migrations from an existing database. Firstly empty the django migration table from the database.
```sql
delete from django_migrations
```
1. Remove migrations from your migrations folder for the app
```sh
rm -rf <app>/migrations/
```
2. Reset the migration for builtin apps(like admin... |
57,229,074 | I am trying to import an existing database into my **Django** project, so I run `python manage.py migrate --fake-initial`, but I get this error:
```
operations to perform:
Apply all migrations: ExcursionsManagerApp, GeneralApp, InvoicesManagerApp, OperationsManagerApp, PaymentsManagerApp, RatesMan
agerApp, ReportsMa... | 2019/07/27 | [
"https://Stackoverflow.com/questions/57229074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6843153/"
] | `--fake-initial` can't deal with any situation where some of the tables listed in the initial migration exist and some do not. So, if tables exist for some, but not all, of the `CreateModel()`s in the `operations` list in your `0001_initial.py`, `--fake-initial` does not apply and it tries to create tables for ALL of t... | Steps you can follow to make migrations from an existing database. Firstly empty the django migration table from the database.
```sql
delete from django_migrations
```
1. Remove migrations from your migrations folder for the app
```sh
rm -rf <app>/migrations/
```
2. Reset the migration for builtin apps(like admin... |
26,327,497 | **WHAT IS WORKING**
I'm following [wsgi documentation to run django](http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#test-your-django-project). I'm testing that it's all working before start to use nginx. I succeeded running manage.py and loading the webpage in my browser:
```
python manag... | 2014/10/12 | [
"https://Stackoverflow.com/questions/26327497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2010764/"
] | **SOLUTION:**
An incorrect configuration in wsgi.py was making uWSGI unable to call the application. I solved it using this wsgi.py:
```
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "metrics.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
```
And runnin... | 1):
Highly recommend run uwsgi in emperor mode.
```
/usr/bin/uwsgi --emperor /etc/uwsgi --pidfile /var/run/uwsgi.pid --daemonize /var/log/uwsgi.log
```
2) Example wsgi.py for your project:
```
import os
import sys
ADD_PATH = ['/home/ubuntu/web/metrics.com/app/',]
for item in ADD_PATH:
sys.path.insert (0, item)
... |
46,895,876 | I have a script `wordcount.py`
I used setuptools to create an entry point, named `wordcount`, so now I can call the command from anywhere in the system.
I am trying to execute it via spark-submit (command: `spark-submit wordcount`) but it is failing with the following error:
`Error: Cannot load main class from J... | 2017/10/23 | [
"https://Stackoverflow.com/questions/46895876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7963251/"
] | This is pretty similar to Jaap's comment, but a little more spelled out and uses the row names explicitly:
```
mat = as.matrix(dat[, 2:5])
row.names(mat) = dat$MUN
mat = rbind(mat, colSums(mat[c("Angra dos Reis (RJ)", "Areal (RJ)"), ], na.rm = T))
row.names(mat)[nrow(mat)] = "X"
mat
# X1990 X19... | A solution can be using sqldf package. If the name of the data frame is `df`, you can do it likes the following:
```
library(sqldf)
result <- sqldf("SELECT * FROM df UNION
SELECT 'X', SUM(X1990), SUM(X1991), SUM(X1992), SUM(X1993) FROM df
WHERE MUN IN ('Angra dos Reis (RJ)', 'Areal (RJ)')")
``` |
46,895,876 | I have a script `wordcount.py`
I used setuptools to create an entry point, named `wordcount`, so now I can call the command from anywhere in the system.
I am trying to execute it via spark-submit (command: `spark-submit wordcount`) but it is failing with the following error:
`Error: Cannot load main class from J... | 2017/10/23 | [
"https://Stackoverflow.com/questions/46895876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7963251/"
] | This is pretty similar to Jaap's comment, but a little more spelled out and uses the row names explicitly:
```
mat = as.matrix(dat[, 2:5])
row.names(mat) = dat$MUN
mat = rbind(mat, colSums(mat[c("Angra dos Reis (RJ)", "Areal (RJ)"), ], na.rm = T))
row.names(mat)[nrow(mat)] = "X"
mat
# X1990 X19... | I have assumed that you would like to sum data of two municipalites whose names you know/specify and then add their sum at the end of the table. I was not sure if this understanding is correct. You might need to specify your question again in case below code is not what you need (e.g., concerning if you need to sum mul... |
46,895,876 | I have a script `wordcount.py`
I used setuptools to create an entry point, named `wordcount`, so now I can call the command from anywhere in the system.
I am trying to execute it via spark-submit (command: `spark-submit wordcount`) but it is failing with the following error:
`Error: Cannot load main class from J... | 2017/10/23 | [
"https://Stackoverflow.com/questions/46895876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7963251/"
] | This is pretty similar to Jaap's comment, but a little more spelled out and uses the row names explicitly:
```
mat = as.matrix(dat[, 2:5])
row.names(mat) = dat$MUN
mat = rbind(mat, colSums(mat[c("Angra dos Reis (RJ)", "Areal (RJ)"), ], na.rm = T))
row.names(mat)[nrow(mat)] = "X"
mat
# X1990 X19... | Here is a `dplyr` solution:
```
library(dplyr)
df %>%
filter(MUN %in% c("Angra dos Reis (RJ)", "Areal (RJ)")) %>%
summarize_if(is.numeric, sum, na.rm = TRUE) %>%
as.list(.) %>%
c(MUN = "X") %>%
bind_rows(df, .)
```
**Result:**
```
MUN X1990 X1991 X1992 X1993
1 Angra dos Reis (RJ)... |
46,895,876 | I have a script `wordcount.py`
I used setuptools to create an entry point, named `wordcount`, so now I can call the command from anywhere in the system.
I am trying to execute it via spark-submit (command: `spark-submit wordcount`) but it is failing with the following error:
`Error: Cannot load main class from J... | 2017/10/23 | [
"https://Stackoverflow.com/questions/46895876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7963251/"
] | A solution can be using sqldf package. If the name of the data frame is `df`, you can do it likes the following:
```
library(sqldf)
result <- sqldf("SELECT * FROM df UNION
SELECT 'X', SUM(X1990), SUM(X1991), SUM(X1992), SUM(X1993) FROM df
WHERE MUN IN ('Angra dos Reis (RJ)', 'Areal (RJ)')")
``` | I have assumed that you would like to sum data of two municipalites whose names you know/specify and then add their sum at the end of the table. I was not sure if this understanding is correct. You might need to specify your question again in case below code is not what you need (e.g., concerning if you need to sum mul... |
46,895,876 | I have a script `wordcount.py`
I used setuptools to create an entry point, named `wordcount`, so now I can call the command from anywhere in the system.
I am trying to execute it via spark-submit (command: `spark-submit wordcount`) but it is failing with the following error:
`Error: Cannot load main class from J... | 2017/10/23 | [
"https://Stackoverflow.com/questions/46895876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7963251/"
] | Here is a `dplyr` solution:
```
library(dplyr)
df %>%
filter(MUN %in% c("Angra dos Reis (RJ)", "Areal (RJ)")) %>%
summarize_if(is.numeric, sum, na.rm = TRUE) %>%
as.list(.) %>%
c(MUN = "X") %>%
bind_rows(df, .)
```
**Result:**
```
MUN X1990 X1991 X1992 X1993
1 Angra dos Reis (RJ)... | I have assumed that you would like to sum data of two municipalites whose names you know/specify and then add their sum at the end of the table. I was not sure if this understanding is correct. You might need to specify your question again in case below code is not what you need (e.g., concerning if you need to sum mul... |
4,119,054 | I'm looking for a finance library in python which offers a method similar to the MATLAB's [portalloc](http://www.mathworks.com/help/toolbox/finance/portalloc.html) . It is used to optimize a portfolio. | 2010/11/07 | [
"https://Stackoverflow.com/questions/4119054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409701/"
] | If you know linear algebra, there is a simple function for solving the optimization problem which any library should support. Unfortunately, it's been so long since I researched it I can't tell you the formula nor a library that supports it, but a little research should reveal it. The main point is that any linear alge... | Maybe you could use this [library](http://www.downv.com/Mac/download-Python-statlib-10009752.htm) (statlib) or this [one](http://www.downv.com/Mac/download-Mystic-10004716.htm) (Mystic) to help you. |
4,119,054 | I'm looking for a finance library in python which offers a method similar to the MATLAB's [portalloc](http://www.mathworks.com/help/toolbox/finance/portalloc.html) . It is used to optimize a portfolio. | 2010/11/07 | [
"https://Stackoverflow.com/questions/4119054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409701/"
] | If you know linear algebra, there is a simple function for solving the optimization problem which any library should support. Unfortunately, it's been so long since I researched it I can't tell you the formula nor a library that supports it, but a little research should reveal it. The main point is that any linear alge... | If you know how to define your objective function. You can use [Numpy](http://docs.scipy.org/doc/scipy-0.14.0/reference/optimize.html) to solve almost any portfolio optimization problem. |
4,119,054 | I'm looking for a finance library in python which offers a method similar to the MATLAB's [portalloc](http://www.mathworks.com/help/toolbox/finance/portalloc.html) . It is used to optimize a portfolio. | 2010/11/07 | [
"https://Stackoverflow.com/questions/4119054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409701/"
] | If you know linear algebra, there is a simple function for solving the optimization problem which any library should support. Unfortunately, it's been so long since I researched it I can't tell you the formula nor a library that supports it, but a little research should reveal it. The main point is that any linear alge... | Python implementations of some typical portfolio optimizations can be found at <https://github.com/czielinski/portfolioopt>. The corresponding quadratic programs are being solved using the `CVXOPT` library. *(Disclaimer: this is my own GitHub repository.)* |
4,119,054 | I'm looking for a finance library in python which offers a method similar to the MATLAB's [portalloc](http://www.mathworks.com/help/toolbox/finance/portalloc.html) . It is used to optimize a portfolio. | 2010/11/07 | [
"https://Stackoverflow.com/questions/4119054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409701/"
] | If you know linear algebra, there is a simple function for solving the optimization problem which any library should support. Unfortunately, it's been so long since I researched it I can't tell you the formula nor a library that supports it, but a little research should reveal it. The main point is that any linear alge... | I am new but I believe gradient descent is what you are looking for. Michael Chu, who is author of optopsy 2.0 python library (<https://github.com/michaelchu/optopsy>), has great insights into implementation. Works great with v3.7. |
71,929,367 | Please don't delete this. this is so simple but I'm banging my head making this work for last two hours.
As displayed. I want to import python file module\_dir into module\_sub\_dir.py, but its giving erros. all **init**.py are empty.[](https://i.stac... | 2022/04/19 | [
"https://Stackoverflow.com/questions/71929367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11268322/"
] | Add `sys.path.append("..")` to the very beginning then importlib will be able to reach the file in parent directories of CWD. But I recommend you not to use such ugly solution in your projects. | Update as I have figured out the issue myslef.
So the issue is how VS Code runs .py file individually as oppose to running entire package like Pycharm. It works in Pycharm. To make it work in VS Code sys.import.path('..') works. |
58,455,061 | Suppose python dictionary is like
D = {'a':1,'a':2}
Can I get those 2 values with same key
Because I want write a function so I can get dictionary like above? | 2019/10/18 | [
"https://Stackoverflow.com/questions/58455061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5961544/"
] | Dictionary keys in Python are unique. Python will resolve `D = {'a':1,'a':2}` as `D = {'a': 2}`
You can effectively store multiple values under the same key by storing a list under that key. In your case,
```
D = {'a': [1, 2]}
```
This would allow you to access the elements of 'a' by using
```
D['a'][elementIdx]... | You cannot. I set up an identical dictionary, and when attempting to print the key `'a'`, I received the secondary value, i.e., `2`. Keys are meant to be unique.
You could try something like:
```
x = {}
for i in range(2):
x[f"a{i}"] = i
```
Which would output key values like `a0, a1, etc.` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | at the very least use a list comprehension:
```
[x for x in a + b if (a + b).count(x) == 1]
```
otherwise use the [set](http://docs.python.org/library/stdtypes.html#set-types-set-frozenset) class:
```
list(set(a).symmetric_difference(set(b)))
```
there is also a more compact form:
```
list(set(a) ^ set(b))
``` | Items in b that aren't in a, if you need to preserve order or duplicates in b:
```
>>> a = [1, 2, 3]
>>> b = [1, 2, 3, 4, 4, 5]
>>> a_set = set(a)
>>> [x for x in b if x not in a_set]
[4, 4, 5]
```
Items in b that aren't in a, not preserving order, and not preserving duplicates in b:
```
>>> list(set(b) - set(a))
[... |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | If the order is not important and you can ignore repetitions within `a` and `b`, I would simply use sets:
```
>>> set(b) - set(a)
set([4, 5])
```
Sets are iterable, so most of the times you do not need to explicitly convert them back to list. If you have to, this does it:
```
>>> list(set(b) - set(a))
[4, 5]
``` | I'd say go for the set variant, where
```
set(b) ^ set(a) (set.symmetric_difference())
```
only applies if you can be certain that a is always a subset of b, but in that case has the advantage of being commutative, ie. you don't have to worry about calculating set(b) ^ set(a) or set(a) ^ set(b); or
```
set(b)... |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | Here are some different possibilities with the sets
```
>>> a = [1, 2, 3, 4, 5, 1, 2]
>>> b = [1, 2, 5, 6]
>>> print list(set(a)^set(b))
[3, 4, 6]
>>> print list(set(a)-set(b))
[3, 4]
>>> print list(set(b)-set(a))
[6]
>>> print list(set(a)-set(b))+list(set(b)-set(a))
[3, 4, 6]
>>>
``` | Another solution using only lists:
```
a = [1, 2, 3]
b = [1, 2, 3, 4, 5]
c = [n for n in a + b if n not in a or n not in b]
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | at the very least use a list comprehension:
```
[x for x in a + b if (a + b).count(x) == 1]
```
otherwise use the [set](http://docs.python.org/library/stdtypes.html#set-types-set-frozenset) class:
```
list(set(a).symmetric_difference(set(b)))
```
there is also a more compact form:
```
list(set(a) ^ set(b))
``` | ```
a = [1, 2 ,3]
b = [1, 2, 3, 4, 5]
c=[]
for x in a:
if x not in b:
c.append(x)
print(c)
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | at the very least use a list comprehension:
```
[x for x in a + b if (a + b).count(x) == 1]
```
otherwise use the [set](http://docs.python.org/library/stdtypes.html#set-types-set-frozenset) class:
```
list(set(a).symmetric_difference(set(b)))
```
there is also a more compact form:
```
list(set(a) ^ set(b))
``` | Here are some different possibilities with the sets
```
>>> a = [1, 2, 3, 4, 5, 1, 2]
>>> b = [1, 2, 5, 6]
>>> print list(set(a)^set(b))
[3, 4, 6]
>>> print list(set(a)-set(b))
[3, 4]
>>> print list(set(b)-set(a))
[6]
>>> print list(set(a)-set(b))+list(set(b)-set(a))
[3, 4, 6]
>>>
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | I'd say go for the set variant, where
```
set(b) ^ set(a) (set.symmetric_difference())
```
only applies if you can be certain that a is always a subset of b, but in that case has the advantage of being commutative, ie. you don't have to worry about calculating set(b) ^ set(a) or set(a) ^ set(b); or
```
set(b)... | Another solution using only lists:
```
a = [1, 2, 3]
b = [1, 2, 3, 4, 5]
c = [n for n in a + b if n not in a or n not in b]
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | Items in b that aren't in a, if you need to preserve order or duplicates in b:
```
>>> a = [1, 2, 3]
>>> b = [1, 2, 3, 4, 4, 5]
>>> a_set = set(a)
>>> [x for x in b if x not in a_set]
[4, 4, 5]
```
Items in b that aren't in a, not preserving order, and not preserving duplicates in b:
```
>>> list(set(b) - set(a))
[... | Another solution using only lists:
```
a = [1, 2, 3]
b = [1, 2, 3, 4, 5]
c = [n for n in a + b if n not in a or n not in b]
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | at the very least use a list comprehension:
```
[x for x in a + b if (a + b).count(x) == 1]
```
otherwise use the [set](http://docs.python.org/library/stdtypes.html#set-types-set-frozenset) class:
```
list(set(a).symmetric_difference(set(b)))
```
there is also a more compact form:
```
list(set(a) ^ set(b))
``` | If the order is not important and you can ignore repetitions within `a` and `b`, I would simply use sets:
```
>>> set(b) - set(a)
set([4, 5])
```
Sets are iterable, so most of the times you do not need to explicitly convert them back to list. If you have to, this does it:
```
>>> list(set(b) - set(a))
[4, 5]
``` |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | at the very least use a list comprehension:
```
[x for x in a + b if (a + b).count(x) == 1]
```
otherwise use the [set](http://docs.python.org/library/stdtypes.html#set-types-set-frozenset) class:
```
list(set(a).symmetric_difference(set(b)))
```
there is also a more compact form:
```
list(set(a) ^ set(b))
``` | I'd say go for the set variant, where
```
set(b) ^ set(a) (set.symmetric_difference())
```
only applies if you can be certain that a is always a subset of b, but in that case has the advantage of being commutative, ie. you don't have to worry about calculating set(b) ^ set(a) or set(a) ^ set(b); or
```
set(b)... |
1,062,803 | Take two lists, second with same items than first plus some more:
```
a = [1,2,3]
b = [1,2,3,4,5]
```
I want to get a third one, containing only the new items (the ones not repeated):
```
c = [4,5]
```
The solution I have right now is:
```
>>> c = []
>>> for i in ab:
... if ab.count(i) == 1:
... c.append(i... | 2009/06/30 | [
"https://Stackoverflow.com/questions/1062803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65459/"
] | Items in b that aren't in a, if you need to preserve order or duplicates in b:
```
>>> a = [1, 2, 3]
>>> b = [1, 2, 3, 4, 4, 5]
>>> a_set = set(a)
>>> [x for x in b if x not in a_set]
[4, 4, 5]
```
Items in b that aren't in a, not preserving order, and not preserving duplicates in b:
```
>>> list(set(b) - set(a))
[... | Here are some different possibilities with the sets
```
>>> a = [1, 2, 3, 4, 5, 1, 2]
>>> b = [1, 2, 5, 6]
>>> print list(set(a)^set(b))
[3, 4, 6]
>>> print list(set(a)-set(b))
[3, 4]
>>> print list(set(b)-set(a))
[6]
>>> print list(set(a)-set(b))+list(set(b)-set(a))
[3, 4, 6]
>>>
``` |
70,992,422 | When running xlwings 0.26.1 (latest for Anaconda 3.83) or 0.10.0 (using for compatibility reasons) with the latest version of `Office 365 Excel`, I get an error after moving a sheet when running `app.quit()`:
```
import xlwings as xw
import pythoncom
pythoncom.CoInitialize()
app = xw.apps.add()
app.display_alerts = F... | 2022/02/04 | [
"https://Stackoverflow.com/questions/70992422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7952542/"
] | I found the problem
If `mcr.microsoft.com/windows/nanoserver:1809` image is used then arguments should be used in %arg% format.
If `mcr.microsoft.com/dotnet/framework/sdk:4.8` image is used then arguments should be used in $env:arg format.
It is confusing and I haven't found where it is documented. | This looks like it might be a bug.
When you have a build arg with the same name as an already existing environment variable, Docker will use the already set environment variable instead of the build arg.
The framework image you use already has an environment variable called DOTNET\_VERSION, so you can't access the bu... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | You can use dict comprehension and enumerate the `csv` object,
```
import csv
reader = csv.reader(open("filename.csv"))
x = {num+1:name[0].split(" ",1)[-1].rstrip() for (num, name) in enumerate(reader)}
print(x)
# output,
{1: 'Bob West', 2: 'Hannah South', 3: 'Bruce North'}
```
Or you can do it without using `csv... | This should work for the given input:
data.csv:
=========
```
1.male Bob West,
2.female Hannah South,
3.male Bruce North,
```
Code:
=====
```
import csv
reader = csv.reader(open("data.csv"))
d = {}
for row in reader:
splitted = row[0].split('.')
# print splitted[0]
# print ' '.join(splitted[1].split(' ')[... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | This should work for the given input:
data.csv:
=========
```
1.male Bob West,
2.female Hannah South,
3.male Bruce North,
```
Code:
=====
```
import csv
reader = csv.reader(open("data.csv"))
d = {}
for row in reader:
splitted = row[0].split('.')
# print splitted[0]
# print ' '.join(splitted[1].split(' ')[... | ```
import cv with open('Employee_address.txt', mode='r') as CSV_file:
csv_reader= csv.DirectReader(csv_file)
life_count=0
for row in csv_reader:
if line_count==0:
print(f'columns names are {",".join()}')
line += 1
print(f'\t{row["name"]} works in the {row["depart... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | You can use dict comprehension and enumerate the `csv` object,
```
import csv
reader = csv.reader(open("filename.csv"))
x = {num+1:name[0].split(" ",1)[-1].rstrip() for (num, name) in enumerate(reader)}
print(x)
# output,
{1: 'Bob West', 2: 'Hannah South', 3: 'Bruce North'}
```
Or you can do it without using `csv... | as per Simit, but using regular expressions and realising that your `1.` and `A` and `B` are you just trying to explain Excel cell and column identifiers
```
import re, csv
reader = csv.reader(open("data.csv"))
out = {}
for i, line in enumerate(reader, 1):
m = re.match(r'^(male|female) (.*)$', line)
if not m... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | as per Simit, but using regular expressions and realising that your `1.` and `A` and `B` are you just trying to explain Excel cell and column identifiers
```
import re, csv
reader = csv.reader(open("data.csv"))
out = {}
for i, line in enumerate(reader, 1):
m = re.match(r'^(male|female) (.*)$', line)
if not m... | ```
import cv with open('Employee_address.txt', mode='r') as CSV_file:
csv_reader= csv.DirectReader(csv_file)
life_count=0
for row in csv_reader:
if line_count==0:
print(f'columns names are {",".join()}')
line += 1
print(f'\t{row["name"]} works in the {row["depart... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | You can use dict comprehension and enumerate the `csv` object,
```
import csv
reader = csv.reader(open("filename.csv"))
x = {num+1:name[0].split(" ",1)[-1].rstrip() for (num, name) in enumerate(reader)}
print(x)
# output,
{1: 'Bob West', 2: 'Hannah South', 3: 'Bruce North'}
```
Or you can do it without using `csv... | ```
import cv with open('Employee_address.txt', mode='r') as CSV_file:
csv_reader= csv.DirectReader(csv_file)
life_count=0
for row in csv_reader:
if line_count==0:
print(f'columns names are {",".join()}')
line += 1
print(f'\t{row["name"]} works in the {row["depart... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | You can use dict comprehension and enumerate the `csv` object,
```
import csv
reader = csv.reader(open("filename.csv"))
x = {num+1:name[0].split(" ",1)[-1].rstrip() for (num, name) in enumerate(reader)}
print(x)
# output,
{1: 'Bob West', 2: 'Hannah South', 3: 'Bruce North'}
```
Or you can do it without using `csv... | I like to use Pandas for stuff like this. You can use Pandas to import it and then export it to a dict.
```
import pandas as pd
df = pd.read_csv('test.csv',header=-1)
# Creates new columns in the dataframe based on the rules of the question
df['Name']=df[0].str.split(' ',1).str.get(1)
df['ID'] = df[0].str.split('.',1... |
53,092,936 | I need some help with a assignment for python.
The task is to convert a .csv file to a dictionary, and do some changes. The problem is that the .csv file only got 1 column, but 3 rows.
The .csv file looks like this in excel
```
A B
1.male Bob West
2.female Hannah South
3.male B... | 2018/10/31 | [
"https://Stackoverflow.com/questions/53092936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10470153/"
] | I like to use Pandas for stuff like this. You can use Pandas to import it and then export it to a dict.
```
import pandas as pd
df = pd.read_csv('test.csv',header=-1)
# Creates new columns in the dataframe based on the rules of the question
df['Name']=df[0].str.split(' ',1).str.get(1)
df['ID'] = df[0].str.split('.',1... | ```
import cv with open('Employee_address.txt', mode='r') as CSV_file:
csv_reader= csv.DirectReader(csv_file)
life_count=0
for row in csv_reader:
if line_count==0:
print(f'columns names are {",".join()}')
line += 1
print(f'\t{row["name"]} works in the {row["depart... |
13,788,688 | I'm using a python code to get data from my server. However, I keep getting a "u" as a prefix to each key in the JSON
as follows:
```
"{u'BD': 271, u'PS': 48, u'00': 177, u'CA': 5, u'DE': 15, u'FR': 18, u'UM': 45, u'KR': 6, u'IL': 22181, u'GB': 15}"
```
My python code is as follows:
```
from json import dumps
ans ... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1432779/"
] | The `u''` means the value is a unicode literal. Everything is working as intended, you don't need to get rid of those.
JSON is a standard that supports Unicode values natively, and thus the `json` module accepts unicode strings when converting a Python value to JSON:
```
>>> import json
>>> ans={u'BD': 271, u'PS': 48... | I think something got mixed up here. The result you've posted looks like a Python representation of a dict. To be precise: json.dumps returns a string, so its result should be enclosed in quotes, like this:
```
>>> import json
>>> json.dumps({'foo': 'bar'})
'{"foo": "bar"}'
``` |
32,540,092 | I have a jinja2 template designed to print out the IP addresses of ec2 instances (tagged region: au) :
```
{% for host in groups['tag_region_au'] %}
```
My problem is I can't for the life of me work out how to include only hosts that exist in one group and NOT another (however each host may be in two or more groups)... | 2015/09/12 | [
"https://Stackoverflow.com/questions/32540092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/264897/"
] | You can use built-in `group_names` variable in this case. `group_names` variable is a list of all groups that the current host is a member of.
My `hosts` file:
```
[tag_region_au]
host1
host2
host3
[tag_state_live]
host2
host3
host4
```
My template file `test.j2`:
```
{% for host in groups['tag_region_au'] %}
{... | A really clean way to do it if you don't mind starting a new play for the templating stuff is to use a group expression in the play target (which is exactly what they're for). For example:
```
- hosts: tag_region_au:!tag_state_live
tasks:
- template: (bla)
```
Then in your template, you'd reference the `play_host... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.