qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | It seems that you have installed the package in a separate environment in anaconda. I think when you are running jupyter notebook, it is running from the base environment, But actually you need to run it from the library environment. So if the case is this you need to install jupyter notebook in the other environment a... | Recently the fbprophet project renamed to prophet.
If you are referring to it using old name you should install the old version.
```
pip/conda/mamba/whatever install prophet
``` |
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | It seems that you have installed the package in a separate environment in anaconda. I think when you are running jupyter notebook, it is running from the base environment, But actually you need to run it from the library environment. So if the case is this you need to install jupyter notebook in the other environment a... | After spending hours scouring the internet for answers to this question and similar questions like "ERROR: Command errored out with exit status 1: when installing "Facebook" "prophet"" what worked for me was quite simply using a sudo pip install at the terminal prompt:
`$ sudo pip install pystan==2.19.1.1 prophet`
Af... |
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | It seems that you have installed the package in a separate environment in anaconda. I think when you are running jupyter notebook, it is running from the base environment, But actually you need to run it from the library environment. So if the case is this you need to install jupyter notebook in the other environment a... | Window10 + Pycharm.
This works with Python 3.8. and Python 3.9.x:
```
pip install localpip
localpip install fbprophet
``` |
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | Recently the fbprophet project renamed to prophet.
If you are referring to it using old name you should install the old version.
```
pip/conda/mamba/whatever install prophet
``` | After spending hours scouring the internet for answers to this question and similar questions like "ERROR: Command errored out with exit status 1: when installing "Facebook" "prophet"" what worked for me was quite simply using a sudo pip install at the terminal prompt:
`$ sudo pip install pystan==2.19.1.1 prophet`
Af... |
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | Recently the fbprophet project renamed to prophet.
If you are referring to it using old name you should install the old version.
```
pip/conda/mamba/whatever install prophet
``` | Window10 + Pycharm.
This works with Python 3.8. and Python 3.9.x:
```
pip install localpip
localpip install fbprophet
``` |
61,353,951 | I have tried to install Facebook Prophet in Anaconda on Ubuntu following the instructions at:
<https://facebook.github.io/prophet/docs/installation.html#installation-in-python>.
In Anaconda Navigator, when I click on the environment, fbprophet is listed along with the other installed packages. The problem is that whe... | 2020/04/21 | [
"https://Stackoverflow.com/questions/61353951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9415043/"
] | After spending hours scouring the internet for answers to this question and similar questions like "ERROR: Command errored out with exit status 1: when installing "Facebook" "prophet"" what worked for me was quite simply using a sudo pip install at the terminal prompt:
`$ sudo pip install pystan==2.19.1.1 prophet`
Af... | Window10 + Pycharm.
This works with Python 3.8. and Python 3.9.x:
```
pip install localpip
localpip install fbprophet
``` |
21,866,036 | When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?
e.g. this works
```
python -c "import os.path; print os.getcwd()"
```
Shouldn't I explicitly `import os` for `os.getcwd` to be available ? | 2014/02/18 | [
"https://Stackoverflow.com/questions/21866036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/346286/"
] | It works and it is reliable. What happens under the hood is when you do
```
import os.path
```
then `os` gets imported and then `os.path`. | Yes, you can rely on it always working. Python has to include `os` in the namespace for `os.path` to work.
What won't work is using the `from os import path` notation. In that case, the os module is *not* brought into the namespace, only `path`. |
21,866,036 | When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?
e.g. this works
```
python -c "import os.path; print os.getcwd()"
```
Shouldn't I explicitly `import os` for `os.getcwd` to be available ? | 2014/02/18 | [
"https://Stackoverflow.com/questions/21866036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/346286/"
] | This is a good question. If you look at the source code for `os.py` you find this line:
```
sys.modules['os.path'] = path
```
So there's our module. But what's `path`? Well that depends on your OS. For Windows, it's defined in this block:
```
elif 'nt' in _names:
name = 'nt'
linesep = '\r\n'
from nt imp... | It works and it is reliable. What happens under the hood is when you do
```
import os.path
```
then `os` gets imported and then `os.path`. |
21,866,036 | When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?
e.g. this works
```
python -c "import os.path; print os.getcwd()"
```
Shouldn't I explicitly `import os` for `os.getcwd` to be available ? | 2014/02/18 | [
"https://Stackoverflow.com/questions/21866036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/346286/"
] | There's an important thing to know about packages, that is that there is a difference between being loaded and being available.
With `import a` you load module `a` (which can be a package) and make it available under the name `a`.
With `from a import b` you load module `a` (which definitely is a package), then load m... | It works and it is reliable. What happens under the hood is when you do
```
import os.path
```
then `os` gets imported and then `os.path`. |
21,866,036 | When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?
e.g. this works
```
python -c "import os.path; print os.getcwd()"
```
Shouldn't I explicitly `import os` for `os.getcwd` to be available ? | 2014/02/18 | [
"https://Stackoverflow.com/questions/21866036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/346286/"
] | This is a good question. If you look at the source code for `os.py` you find this line:
```
sys.modules['os.path'] = path
```
So there's our module. But what's `path`? Well that depends on your OS. For Windows, it's defined in this block:
```
elif 'nt' in _names:
name = 'nt'
linesep = '\r\n'
from nt imp... | Yes, you can rely on it always working. Python has to include `os` in the namespace for `os.path` to work.
What won't work is using the `from os import path` notation. In that case, the os module is *not* brought into the namespace, only `path`. |
21,866,036 | When I import a subpackage in a package, can I rely on the fact that the parent package is also imported ?
e.g. this works
```
python -c "import os.path; print os.getcwd()"
```
Shouldn't I explicitly `import os` for `os.getcwd` to be available ? | 2014/02/18 | [
"https://Stackoverflow.com/questions/21866036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/346286/"
] | There's an important thing to know about packages, that is that there is a difference between being loaded and being available.
With `import a` you load module `a` (which can be a package) and make it available under the name `a`.
With `from a import b` you load module `a` (which definitely is a package), then load m... | Yes, you can rely on it always working. Python has to include `os` in the namespace for `os.path` to work.
What won't work is using the `from os import path` notation. In that case, the os module is *not* brought into the namespace, only `path`. |
57,076,851 | I want to plot a bode plot of a system with the python control systems library. This is fairly easy. The problem is the plot of the margins. It is no problem to plot the phase margin. But how can I plot the gain margin?
So far, this is a part of my code:
```py
import control as cn
%matplotlib notebook
import matplotl... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57076851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6883478/"
] | Not the most elegant solution but hey it works for me.
```
###Import modules
import numpy as np
import control as ctl
import matplotlib.pyplot as plt
##Functions
def plot_margins(sys):
mag,phase,omega = ctl.bode(sys,dB=True,Plot=False)
magdB = 20*np.log10(mag)
phase_deg = phase*180.0/np.pi
Gm,Pm,Wcg,W... | Starting in version 0.8 of `control`, the [`bode_plot`](https://python-control.readthedocs.io/en/0.8.3/generated/control.bode_plot.html) function (also aliased as `bode`) has an option to plot margins.
```py
import control
sys = control.tf([1], [1, 1]) # example transfer function
control.bode_plot(sys, margins=True)... |
467,602 | Following from this [OS-agnostic question](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python), specifically [this response](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291), similar to data available from the likes of /proc/meminfo o... | 2009/01/22 | [
"https://Stackoverflow.com/questions/467602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | There was a similar question asked:
[How to get current CPU and RAM usage in Python?](https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python)
There are quite a few answers telling you how to accomplish this in windows. | You can try using the systeminfo.exe wrapper I created a while back, it's a bit unorthodox but it seems to do the trick easily enough and without much code.
This should work on 2000/XP/2003 Server, and should work on Vista and Win7 provided they come with systeminfo.exe and it is located on the path.
```
import os, r... |
467,602 | Following from this [OS-agnostic question](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python), specifically [this response](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291), similar to data available from the likes of /proc/meminfo o... | 2009/01/22 | [
"https://Stackoverflow.com/questions/467602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | There was a similar question asked:
[How to get current CPU and RAM usage in Python?](https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python)
There are quite a few answers telling you how to accomplish this in windows. | Some answers given can make trouble if the OS language is not native English. I searched for a way to get a wrapper around the `systeminfo.exe` and found the following solution. To make it more comfortable I pack the result in a dictionary:
```
import os
import tempfile
def get_system_info_dict():
tmp_dir=tempfi... |
467,602 | Following from this [OS-agnostic question](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python), specifically [this response](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291), similar to data available from the likes of /proc/meminfo o... | 2009/01/22 | [
"https://Stackoverflow.com/questions/467602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | In Windows, if you want to get info like from the SYSTEMINFO command, you can use the [WMI module.](https://pypi.python.org/pypi/WMI/)
```
import wmi
c = wmi.WMI()
systeminfo = c.Win32_ComputerSystem()[0]
Manufacturer = systeminfo.Manufacturer
Model = systeminfo.Model
```
...
similarly, the os-related info co... | You can try using the systeminfo.exe wrapper I created a while back, it's a bit unorthodox but it seems to do the trick easily enough and without much code.
This should work on 2000/XP/2003 Server, and should work on Vista and Win7 provided they come with systeminfo.exe and it is located on the path.
```
import os, r... |
467,602 | Following from this [OS-agnostic question](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python), specifically [this response](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291), similar to data available from the likes of /proc/meminfo o... | 2009/01/22 | [
"https://Stackoverflow.com/questions/467602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | You can try using the systeminfo.exe wrapper I created a while back, it's a bit unorthodox but it seems to do the trick easily enough and without much code.
This should work on 2000/XP/2003 Server, and should work on Vista and Win7 provided they come with systeminfo.exe and it is located on the path.
```
import os, r... | Some answers given can make trouble if the OS language is not native English. I searched for a way to get a wrapper around the `systeminfo.exe` and found the following solution. To make it more comfortable I pack the result in a dictionary:
```
import os
import tempfile
def get_system_info_dict():
tmp_dir=tempfi... |
467,602 | Following from this [OS-agnostic question](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python), specifically [this response](https://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291), similar to data available from the likes of /proc/meminfo o... | 2009/01/22 | [
"https://Stackoverflow.com/questions/467602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | In Windows, if you want to get info like from the SYSTEMINFO command, you can use the [WMI module.](https://pypi.python.org/pypi/WMI/)
```
import wmi
c = wmi.WMI()
systeminfo = c.Win32_ComputerSystem()[0]
Manufacturer = systeminfo.Manufacturer
Model = systeminfo.Model
```
...
similarly, the os-related info co... | Some answers given can make trouble if the OS language is not native English. I searched for a way to get a wrapper around the `systeminfo.exe` and found the following solution. To make it more comfortable I pack the result in a dictionary:
```
import os
import tempfile
def get_system_info_dict():
tmp_dir=tempfi... |
19,890,824 | How to store the get Facebook profile picture of a user while logging in through Facebook and saving it in my userprofile model.
I found this link which says how to do so using django-social-auth, <https://gist.github.com/kalamhavij/1662930>. but signals is now deprecated and I have to use pipeline.
Any idea how can ... | 2013/11/10 | [
"https://Stackoverflow.com/questions/19890824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/683634/"
] | This is how it worked with me. (from <https://github.com/omab/python-social-auth/issues/80>)
Add the following code to pipeline.py:
```
from requests import request, HTTPError
from django.core.files.base import ContentFile
def save_profile_picture(strategy, user, response, details,
is_new=F... | Assuming you already configured `SOCIAL_AUTH_PIPELINE`, there aren't many differences with signals approach.
Just create needed pipeline (skipping all imports, they're obvious)
```
def update_avatar(backend, details, response, social_user, uid,\
user, *args, **kwargs):
if backend.__class__ == F... |
19,890,824 | How to store the get Facebook profile picture of a user while logging in through Facebook and saving it in my userprofile model.
I found this link which says how to do so using django-social-auth, <https://gist.github.com/kalamhavij/1662930>. but signals is now deprecated and I have to use pipeline.
Any idea how can ... | 2013/11/10 | [
"https://Stackoverflow.com/questions/19890824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/683634/"
] | Assuming you already configured `SOCIAL_AUTH_PIPELINE`, there aren't many differences with signals approach.
Just create needed pipeline (skipping all imports, they're obvious)
```
def update_avatar(backend, details, response, social_user, uid,\
user, *args, **kwargs):
if backend.__class__ == F... | The above answers may not work (it did not work for me) as the facebook profile URL does not work anymore without accesstoken. The following answer worked for me.
```
def save_profile(backend, user, response, is_new=False, *args, **kwargs):
if is_new and backend.name == "facebook":
#The main part is how to get... |
19,890,824 | How to store the get Facebook profile picture of a user while logging in through Facebook and saving it in my userprofile model.
I found this link which says how to do so using django-social-auth, <https://gist.github.com/kalamhavij/1662930>. but signals is now deprecated and I have to use pipeline.
Any idea how can ... | 2013/11/10 | [
"https://Stackoverflow.com/questions/19890824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/683634/"
] | This is how it worked with me. (from <https://github.com/omab/python-social-auth/issues/80>)
Add the following code to pipeline.py:
```
from requests import request, HTTPError
from django.core.files.base import ContentFile
def save_profile_picture(strategy, user, response, details,
is_new=F... | The above answers may not work (it did not work for me) as the facebook profile URL does not work anymore without accesstoken. The following answer worked for me.
```
def save_profile(backend, user, response, is_new=False, *args, **kwargs):
if is_new and backend.name == "facebook":
#The main part is how to get... |
70,543,710 | I am learning C# and have been taking a lot of online courses.
I am looking for a simpler/neater way to enumerate a list within a list.
In python we can do something like this in just one line:
```
newListofList=[[n,i] for n,i in enumerate([List1,List2,List3])]
```
Does it have to involve lambda and Linq in C#? if ... | 2021/12/31 | [
"https://Stackoverflow.com/questions/70543710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3740222/"
] | Just a *constructor* will be enough:
```
List<List<string>> familyListss = new List<List<string>>() {
new List<string> { "Mary", "Mary_sister", "Mary_father", "Mary_mother", "Mary_brother" },
new List<string> { "Peter", "Peter_sister", "Peter_father", "Peter_mother", "Peter_brother" },
new List<string> { "John",... | Are you taking about something like this?
```
int i = 0;
familyListss.ForEach(f => { familyData.Add(i, f);i++; });
```
This is refactored from
```
int i = 0;
foreach (var f in familyListss)
{
familyData.Add(i, f);
i++;
}
```
With a small extension method, you can build in an index to foreach to make it o... |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | Yes, you can. I started learning Django with very little Python knowledge too. As long as you have another language behind your belt, preferably a web based one (as you do), I don't think you're biting off too much at once.
Python's a pretty easy language to pick up too. Just have to get used to the significant white ... | Sure you can!
Django requires minimal knowledge about using python from the command line, but if you're comfortable with that, then there shouldn't be an issue. Django has excellent documentation and a good tutorial aimed at beginners that does not expect you to be a high-level Python programmer.
Here's the link to th... |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | Yes, you can. I started learning Django with very little Python knowledge too. As long as you have another language behind your belt, preferably a web based one (as you do), I don't think you're biting off too much at once.
Python's a pretty easy language to pick up too. Just have to get used to the significant white ... | Starting from Django it's good way to learn Python in fact. Django allows you to do nice things in a short time, which might be good motivation to dive into that language. |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | Yes, you can. I started learning Django with very little Python knowledge too. As long as you have another language behind your belt, preferably a web based one (as you do), I don't think you're biting off too much at once.
Python's a pretty easy language to pick up too. Just have to get used to the significant white ... | I'm going to disagree with previous answers. You *could* learn Python by learning Django, but I don't think it's a very good idea. You won't really understand why things are the way they are, or how things really work.
My advice would be to follow a Python tutorial first - if you're an experienced programmer already t... |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | Yes, you can. I started learning Django with very little Python knowledge too. As long as you have another language behind your belt, preferably a web based one (as you do), I don't think you're biting off too much at once.
Python's a pretty easy language to pick up too. Just have to get used to the significant white ... | I tried starting just by going through the [Django tutorial](http://docs.djangoproject.com/en/1.2/intro/tutorial01/#intro-tutorial01), which got me going fast, but without enough Python knowledge, I got stuck when starting to write my own first app. Python terms like "tuples", "lists", and "dictionaries" were new to me... |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | Sure you can!
Django requires minimal knowledge about using python from the command line, but if you're comfortable with that, then there shouldn't be an issue. Django has excellent documentation and a good tutorial aimed at beginners that does not expect you to be a high-level Python programmer.
Here's the link to th... | Starting from Django it's good way to learn Python in fact. Django allows you to do nice things in a short time, which might be good motivation to dive into that language. |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | I'm going to disagree with previous answers. You *could* learn Python by learning Django, but I don't think it's a very good idea. You won't really understand why things are the way they are, or how things really work.
My advice would be to follow a Python tutorial first - if you're an experienced programmer already t... | Sure you can!
Django requires minimal knowledge about using python from the command line, but if you're comfortable with that, then there shouldn't be an issue. Django has excellent documentation and a good tutorial aimed at beginners that does not expect you to be a high-level Python programmer.
Here's the link to th... |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | I'm going to disagree with previous answers. You *could* learn Python by learning Django, but I don't think it's a very good idea. You won't really understand why things are the way they are, or how things really work.
My advice would be to follow a Python tutorial first - if you're an experienced programmer already t... | Starting from Django it's good way to learn Python in fact. Django allows you to do nice things in a short time, which might be good motivation to dive into that language. |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | I tried starting just by going through the [Django tutorial](http://docs.djangoproject.com/en/1.2/intro/tutorial01/#intro-tutorial01), which got me going fast, but without enough Python knowledge, I got stuck when starting to write my own first app. Python terms like "tuples", "lists", and "dictionaries" were new to me... | Starting from Django it's good way to learn Python in fact. Django allows you to do nice things in a short time, which might be good motivation to dive into that language. |
3,234,402 | Now, I'm learning python but I'm PHP web developer. I don't interest about terminal and windows programming. I only want to do web development. So, Can I learn Django ? | 2010/07/13 | [
"https://Stackoverflow.com/questions/3234402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/215939/"
] | I'm going to disagree with previous answers. You *could* learn Python by learning Django, but I don't think it's a very good idea. You won't really understand why things are the way they are, or how things really work.
My advice would be to follow a Python tutorial first - if you're an experienced programmer already t... | I tried starting just by going through the [Django tutorial](http://docs.djangoproject.com/en/1.2/intro/tutorial01/#intro-tutorial01), which got me going fast, but without enough Python knowledge, I got stuck when starting to write my own first app. Python terms like "tuples", "lists", and "dictionaries" were new to me... |
33,615,096 | How can I use single quote and double quote same time as string python?
For example:
```
string = "Let's print "Happines" out"
```
result should be Let's print `"Happines"` out
I tried to use backslash but it prints out a `\` before 's that should be. | 2015/11/09 | [
"https://Stackoverflow.com/questions/33615096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5230597/"
] | In python there's lots of ways to write string literals.
For this example you can:
```
print('Let\'s print "Happiness" out')
print("Let's print \"Happiness\" out")
print('''Let's print "Happiness" out''')
print("""Let's print "Happiness" out""")
```
Any of the above will behave as expected. | Taking this string:
```
string = "Let's print "Happines" out"
```
If you want to mix quotes, use the triple single quotes:
```
>>> string = '''Let's print "Happines" out'''
>>> print(string)
Let's print "Happines" out
```
Using triple quotes is acceptable too:
```
>>> string = """Let's print "Happines" out"""... |
61,501,891 | I have an issue with Rsyslog's 'omprog' module when trying to get it to interact with my python (2.7) code. Rsyslog is supposed to send desired messages to python's stdin, yet it does not receive anything. I wonder if anyone else has had better success with this output module?
**Rsyslog.conf**
```
module(load="omprog... | 2020/04/29 | [
"https://Stackoverflow.com/questions/61501891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10192040/"
] | Here is one approach using `tidyverse`. You can `group_by(Species)` and set `Method` to "Both" if both Bottom fishing and Trolling are included in Method within that Species. Then afterwards, you can `group_by` both Species and Method, and use `fill` to replace `NA` with known values. In the end, use `slice` to keep on... | This should get you started. You can add the other columns to the summarize function.
```
library(tidyverse)
fish_catch %>% select(-Bait, -Released, -Kept) %>%
group_by(Species) %>%
summarize(Method = paste0(Method, collapse = "")) %>%
mutate(Method = fct_recode(Method, "both" = "TrollingBottom fishing"))
#... |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | The easiest way seems to be
```
x = 123.0
dist = int(math.log10(abs(x)))
```
I interpreted the second entry in each pair of the list `t` as your desired result, so I chose `int()` to round the logarithm towards zero:
```
>>> [(int(math.log10(abs(x))), y) for x, y in t]
[(2, 2), (1, 1), (0, 0), (0, 0), (-1, -1), (-4... | One way to focus on the digits after the decimal point is to remove the integer part of the number, leaving on the fractional part, with something like `x - int(x)`.
Having isolated the fractional part, you could let python do the counting for you with a `%e` presentation (that also helps take care of rounding issues)... |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | The easiest way seems to be
```
x = 123.0
dist = int(math.log10(abs(x)))
```
I interpreted the second entry in each pair of the list `t` as your desired result, so I chose `int()` to round the logarithm towards zero:
```
>>> [(int(math.log10(abs(x))), y) for x, y in t]
[(2, 2), (1, 1), (0, 0), (0, 0), (-1, -1), (-4... | While this can technically be done with one line (excluding the import statement), I added a few extra things to make it more complete.
```
from re import search
# Assuming number is already defined.
# Floats always have a decimal in its string representation.
if isinstance(float, number):
# This gets the substri... |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | The easiest way seems to be
```
x = 123.0
dist = int(math.log10(abs(x)))
```
I interpreted the second entry in each pair of the list `t` as your desired result, so I chose `int()` to round the logarithm towards zero:
```
>>> [(int(math.log10(abs(x))), y) for x, y in t]
[(2, 2), (1, 1), (0, 0), (0, 0), (-1, -1), (-4... | ```
import math
ZerosCount = math.ceil(-math.log10(abs(value) - abs(math.floor(value)))) - 1
``` |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | One way to focus on the digits after the decimal point is to remove the integer part of the number, leaving on the fractional part, with something like `x - int(x)`.
Having isolated the fractional part, you could let python do the counting for you with a `%e` presentation (that also helps take care of rounding issues)... | While this can technically be done with one line (excluding the import statement), I added a few extra things to make it more complete.
```
from re import search
# Assuming number is already defined.
# Floats always have a decimal in its string representation.
if isinstance(float, number):
# This gets the substri... |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | One way to focus on the digits after the decimal point is to remove the integer part of the number, leaving on the fractional part, with something like `x - int(x)`.
Having isolated the fractional part, you could let python do the counting for you with a `%e` presentation (that also helps take care of rounding issues)... | ```
import math
ZerosCount = math.ceil(-math.log10(abs(value) - abs(math.floor(value)))) - 1
``` |
8,011,017 | Simple problem, how to find the first non-zero digit after decimal point. What I really need is the distance between the decimal point and the first non-zero digit.
I know I could do it with a few lines but I'd like to have some pythonic, nice and clean way to solve this.
So far I have this
```
>>> t = [(123.0, 2), ... | 2011/11/04 | [
"https://Stackoverflow.com/questions/8011017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/181337/"
] | While this can technically be done with one line (excluding the import statement), I added a few extra things to make it more complete.
```
from re import search
# Assuming number is already defined.
# Floats always have a decimal in its string representation.
if isinstance(float, number):
# This gets the substri... | ```
import math
ZerosCount = math.ceil(-math.log10(abs(value) - abs(math.floor(value)))) - 1
``` |
46,215,954 | I get a .csv file with values inside and one of the columns contains durations in the format hh:mm:ss for example 06:42:13 (6 hours, 42 minutes and 13 seconds). Now I want to compare this time with a given time for example 00:00:00 because I have to handle the information in that row different.
time is the value I got... | 2017/09/14 | [
"https://Stackoverflow.com/questions/46215954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8592446/"
] | Do this instead:
```
if time.strip() == "00:00:00":
do something
else:
do something different
``` | Instead of doing string comparisions, using inbuilt `datetime` library to create datetime objects. Use [`datetime.strptime`](https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior) to convert date string. |
46,215,954 | I get a .csv file with values inside and one of the columns contains durations in the format hh:mm:ss for example 06:42:13 (6 hours, 42 minutes and 13 seconds). Now I want to compare this time with a given time for example 00:00:00 because I have to handle the information in that row different.
time is the value I got... | 2017/09/14 | [
"https://Stackoverflow.com/questions/46215954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8592446/"
] | Try it like this:
```
if time == " 00:00:00":
...
```
You have a trailing space at the beginning.
Alternatively you can change your code into this:
```
import csv
import_list = []
with open("input.csv", "r") as csvfile:
inputreader = csv.reader(csvfile, delimiter=';')
for row in inputreader:
imp... | Do this instead:
```
if time.strip() == "00:00:00":
do something
else:
do something different
``` |
46,215,954 | I get a .csv file with values inside and one of the columns contains durations in the format hh:mm:ss for example 06:42:13 (6 hours, 42 minutes and 13 seconds). Now I want to compare this time with a given time for example 00:00:00 because I have to handle the information in that row different.
time is the value I got... | 2017/09/14 | [
"https://Stackoverflow.com/questions/46215954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8592446/"
] | Try it like this:
```
if time == " 00:00:00":
...
```
You have a trailing space at the beginning.
Alternatively you can change your code into this:
```
import csv
import_list = []
with open("input.csv", "r") as csvfile:
inputreader = csv.reader(csvfile, delimiter=';')
for row in inputreader:
imp... | Instead of doing string comparisions, using inbuilt `datetime` library to create datetime objects. Use [`datetime.strptime`](https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior) to convert date string. |
22,599,617 | How do i fix this error, this is the message that i get:
```none
Traceback (most recent call last):
File "C:\Users\Games\Desktop\hendeagon.py", line 28, in <module>
font = pygame.font.SysFont(None, 48)
File "C:\Python33\lib\site-packages\pygame\sysfont.py", line 614, in SysFont
return constructor(fontname, size, set_b... | 2014/03/24 | [
"https://Stackoverflow.com/questions/22599617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3453049/"
] | [`.attr()`](https://api.jquery.com/attr/) is for HTML attributes, not for CSS properties.
You're looking for [`.css()`](http://api.jquery.com/css/):
```
var cssProp = $(this).css('text-decoration'); // Gets the CSS property's value
$(this).css('text-decoration', 'line-through'); // Sets the CSS property's value
``` | Text decoration isn't an attribute it's a CSS value. Attributes are things like href, class and id on an HTML element.
Try this:
```
$(this).css("text-decoration", "line-through");
``` |
68,171,360 | I am trying to create a Neural Network class made up of Neuron objects wired together.
My Neuron class has
1. **Dendrites**
The number of dendrites is specified in the parameters when the class is initialised. The Dendrites are stored in a list whose index stores the voltages of each Dendrite.
eg: `neuron1.dendrit... | 2021/06/29 | [
"https://Stackoverflow.com/questions/68171360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5618307/"
] | Might not be the best solution, but just my 2c. If you want the other neuron's dendrites to be updated as well, you can declare the connections like so:
```
axonConns = [(n1.dendrites, 0), (n2.dendrites, 1), (n3.dendrites, 2)]
```
You need to pass the list of the dendrites itself, and define which of the dendrites a... | You aren't properly reassigning the values of outputDendrites in your class method.
```
def fire(self):
self.outputPotential = self.voltsOut
self.firing = self.on
print("Neuron is firing!")
# Store the axonConnections into a temporary list for parsing since we'll be changing the values WHILE interating... |
68,171,360 | I am trying to create a Neural Network class made up of Neuron objects wired together.
My Neuron class has
1. **Dendrites**
The number of dendrites is specified in the parameters when the class is initialised. The Dendrites are stored in a list whose index stores the voltages of each Dendrite.
eg: `neuron1.dendrit... | 2021/06/29 | [
"https://Stackoverflow.com/questions/68171360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5618307/"
] | By playing around with the following code in python, I thought I had found a solution:
```py
def changeListVars(n):
for i in range(len(n)):
n[i] = n[i]+5
print()
print(n)
x=1
y=2
z=3
m = [x,y,z]
print(len(m))
for i in range(len(m)):
print (m[i])
changeListVars(m)
print()
print(m)
```
The o... | You aren't properly reassigning the values of outputDendrites in your class method.
```
def fire(self):
self.outputPotential = self.voltsOut
self.firing = self.on
print("Neuron is firing!")
# Store the axonConnections into a temporary list for parsing since we'll be changing the values WHILE interating... |
68,171,360 | I am trying to create a Neural Network class made up of Neuron objects wired together.
My Neuron class has
1. **Dendrites**
The number of dendrites is specified in the parameters when the class is initialised. The Dendrites are stored in a list whose index stores the voltages of each Dendrite.
eg: `neuron1.dendrit... | 2021/06/29 | [
"https://Stackoverflow.com/questions/68171360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5618307/"
] | By playing around with the following code in python, I thought I had found a solution:
```py
def changeListVars(n):
for i in range(len(n)):
n[i] = n[i]+5
print()
print(n)
x=1
y=2
z=3
m = [x,y,z]
print(len(m))
for i in range(len(m)):
print (m[i])
changeListVars(m)
print()
print(m)
```
The o... | Might not be the best solution, but just my 2c. If you want the other neuron's dendrites to be updated as well, you can declare the connections like so:
```
axonConns = [(n1.dendrites, 0), (n2.dendrites, 1), (n3.dendrites, 2)]
```
You need to pass the list of the dendrites itself, and define which of the dendrites a... |
56,577,890 | I am trying to run GitLab's job using their shared Runners,
I've created a `.gitlab-ci.yml` and kept it at my project's root,
Configured AWS creds as the environment variables -
```
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
```
under `Settings -> CI / CD -> Variables`
[![enter image descript... | 2019/06/13 | [
"https://Stackoverflow.com/questions/56577890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5433178/"
] | You can use
```
- pip install awscli
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set region $AWS_DEFAULT_REGION
```
instead of
```
- mkdir ~/.aws/
- touch ~/.aws/credentials
- pip install awscli
- printf "[eb-cli]\naws_acc... | In your code, the profile is set to 'eb-cli' for your credentials
```
printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\nregion = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_DEFAULT_REGION" >> ~/.aws/credentials
```
The command you should use is
```
aws s3 ls --profile eb-cli
```
... |
6,074,034 | I wish to execute os.system('ls') in python. the return value of this statement is an error code integer..but I want to get the contents of the present directory as a string. How to accomplish this? | 2011/05/20 | [
"https://Stackoverflow.com/questions/6074034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/748051/"
] | [`os.listdir(".")`](http://docs.python.org/library/os.html#os.listdir)
---
In general, if you want to call a function and get the arguments, you should use [`subprocess.Popen()`](http://docs.python.org/library/subprocess.html#subprocess.Popen). But a lot of the basic directory stuff is in the `os` module so you don't... | Python as build-in functionality like os.listdir() or os.walk() for listing stuff
on the filesystem. Running 'ls' yourself is very bad-style. In general look at the documentation of the subprocess module giving you all flexibility for interacting with external commands. |
69,563,630 | I have a huge python list as the following example:
```
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
```
I would like to join this information in this formatting:
```
ls = ['name: John', 'John has 4 yellow cars.', 'name: Angelina', 'Angelina has 5 ye... | 2021/10/14 | [
"https://Stackoverflow.com/questions/69563630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11601412/"
] | You can use `itertools.groupby`:
```py
import itertools
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
g = itertools.groupby(ls, lambda x: x.startswith('name: '))
output = [''.join(v) for _, v in g]
print(output) # ['name: John', 'John has 4 yellow cars... | Concatenate all the lines that don't begin with `name:` in a variable, then append that to the result when you get to the next `name:` line.
```
ls2 = []
temp_string = ''
for line in lines:
line = line.rstrip('\n')
if line.startswith('name:'):
if temp_string:
ls2.append(temp_string)
... |
69,563,630 | I have a huge python list as the following example:
```
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
```
I would like to join this information in this formatting:
```
ls = ['name: John', 'John has 4 yellow cars.', 'name: Angelina', 'Angelina has 5 ye... | 2021/10/14 | [
"https://Stackoverflow.com/questions/69563630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11601412/"
] | You can use `itertools.groupby`:
```py
import itertools
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
g = itertools.groupby(ls, lambda x: x.startswith('name: '))
output = [''.join(v) for _, v in g]
print(output) # ['name: John', 'John has 4 yellow cars... | I think the logic can be better expressed as "if the current line begins with `name:`, then append it to a new list, and also join the next three lines into one line and append that line too."
```
with open ('names.txt', 'r') as text:
lines = text.readlines()
i = 0
ls2 = []
for i, line in enumerate(lines):
... |
69,563,630 | I have a huge python list as the following example:
```
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
```
I would like to join this information in this formatting:
```
ls = ['name: John', 'John has 4 yellow cars.', 'name: Angelina', 'Angelina has 5 ye... | 2021/10/14 | [
"https://Stackoverflow.com/questions/69563630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11601412/"
] | You can use `itertools.groupby`:
```py
import itertools
ls = ['name: John', 'John has ', '4 yellow ', 'cars.', 'name: Angelina', 'Angelina has ', '5 yellow', 'cars.']
g = itertools.groupby(ls, lambda x: x.startswith('name: '))
output = [''.join(v) for _, v in g]
print(output) # ['name: John', 'John has 4 yellow cars... | Maybe don't split into all lines but just split the whole file by name lines and polish the whitespace afterwards?
```
import re
with open('names.txt') as f:
ls = [re.sub(r'\s+', ' ', s.strip())
for s in re.split('(name:.*)', f.read())
if s]
```
Writing your list back to file and using my abo... |
70,658,581 | I am looking to create accounts on Brownie for deploying contracts but I am not sure how to do this. I have looked online how to do this and I havent found it.
I am running python 3.7 and have brownie installed and working as intended. I have also run brownie using a gnache cli. Any help would be great! | 2022/01/10 | [
"https://Stackoverflow.com/questions/70658581",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17855149/"
] | To create accounts on brownie use
```
brownie accounts new account-name
```
you can then add your private key as well as password encrypt.
You can check to see if this account was made correctly using
```
brownie accounts list
``` | I understand that you are trying to add accounts through the brownie ./scripts folder:
add.py
```
from brownie import accounts
def add_account():
print(len(accounts)
for i in range(10):
accounts.add() #adds a random account with mnemonic & address to the network
print(len(accounts))
def main():
... |
51,666,871 | I have a flask app with a single file (app.py) a large code base size of 6K lines which i want to modularize by making Separate files for each group of route handlers.
Which one is the proper approach
creating Class for similar routes like user and giving member functions like login, register
user.py
```
class User:
... | 2018/08/03 | [
"https://Stackoverflow.com/questions/51666871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2547270/"
] | You should almost never use classes for flask routes as they are inherantly static, and so are not really suited for having instances made of them
The easiest solution is just to separate related routes into modules, as shown in the second part of your question.
If I were you I would also look into Flask's blueprints... | The latter is Pythonic.
Don't use classes when you don't need instance data; use modules. |
66,421,969 | I have a main folder with some .xlsx, .ipynb, .jpeg and some subfolders in it.
Now I want to convert all my .xlsx files in my main folder to PDFs.
It is a routine work that I have to do everyday, I would appreciate if you teach me how to do it in python.
\*all the files have some data in the first sheet of the workbo... | 2021/03/01 | [
"https://Stackoverflow.com/questions/66421969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13403801/"
] | Is there anything you have already tried ?
I suggest testing out pywin32.
1. Download pywin32
```sh
python3 -m pip install pywin32
```
2. Write a script to automate.
```py
import win32com.client
from pywintypes import com_error
# Path to original excel file
WB_PATH = r'~/path/to/file.xlsx'
# PDF path when saving... | try like this :
```
saveFormat = self.SaveFormat
workbook = self.Workbook(self.dataDir + "Book1.xls")
#Save the document in PDF format
workbook.save(self.dataDir + "OutBook1.pdf", saveFormat.PDF)
\# Print message
print "\n Excel to PDF conversion performed successfully."
``` |
48,924,007 | I am trying to compare two `strings` in `python 3.6` and if they are not equal then print a message and exit. My current code is:
```
location = 'United States of America'
if location.lower() != 'united states of america' or location.lower() != 'usa':
print('Location was different = {}'.format(location.lower()))
... | 2018/02/22 | [
"https://Stackoverflow.com/questions/48924007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2966197/"
] | Your condition:
```
if location.lower() != 'united states of america' or location.lower() != 'usa':
```
will never be `False`, since `location.lower()` can't be 2 different strings at the same time.
I suspect you want:
```
if location.lower() != 'united states of america' and location.lower() != 'usa':
``` | You are looking for an AND condition instead of a OR condition in your if statement. If you change that you should be set |
13,348,880 | I am trying to compile the source codes for a simulator which uses C++ and Python. However, it gives me this error:
```
Error: can't find Python.h header in ['path-to-my-python/include/python2.6']
Install Python headers (package python-dev on Ubuntu and RedHat)
```
However, I can see that the header file is there an... | 2012/11/12 | [
"https://Stackoverflow.com/questions/13348880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1762469/"
] | I have written my own AutoCompleteBox control, available at <https://github.com/igorkulman/AutoCompleteBox> | I don't think there is anything built in, but have you checked open source? This was the first thing that showed up when I binged for it on google:
<http://autocompleteboxwinrt.codeplex.com/SourceControl/changeset/view/19567> |
13,348,880 | I am trying to compile the source codes for a simulator which uses C++ and Python. However, it gives me this error:
```
Error: can't find Python.h header in ['path-to-my-python/include/python2.6']
Install Python headers (package python-dev on Ubuntu and RedHat)
```
However, I can see that the header file is there an... | 2012/11/12 | [
"https://Stackoverflow.com/questions/13348880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1762469/"
] | I have written my own AutoCompleteBox control, available at <https://github.com/igorkulman/AutoCompleteBox> | There's no built-in AutoCompleteBox control for Windows Store app.
You may consider a third party control such as:
<http://www.telerik.com/products/windows-8/controls/auto-complete.aspx> |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Assuming you want to print every 5th line starting from a specific line number:
```
$ seq 20 | awk 'NR==4{c=4} c && !((++c) % 5)'
4
9
14
19
$ seq 20 | awk 'NR==2{c=4} c && !((++c) % 5)'
2
7
12
17
$ seq 20 | awk 'NR==6{c=4} c && !((++c) % 5)'
6
11
16
```
`c && !((++c) % 5)` says:
>
> If `c` is set then increment ... | Simply
```
awk 'NR%5 == 4' file
```
will do the job.
Alternatively, if you have GNU `sed`:
```
sed -n 4~5p file
```
---
**Edit:**
A general solution to the problem of printing every *n*th line starting with line *s* using `awk` could be, for example, like that:
```
awk -v s=6 -v n=5 'NR>=s && NR%n == s%n' fi... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Assuming you want to print every 5th line starting from a specific line number:
```
$ seq 20 | awk 'NR==4{c=4} c && !((++c) % 5)'
4
9
14
19
$ seq 20 | awk 'NR==2{c=4} c && !((++c) % 5)'
2
7
12
17
$ seq 20 | awk 'NR==6{c=4} c && !((++c) % 5)'
6
11
16
```
`c && !((++c) % 5)` says:
>
> If `c` is set then increment ... | Your code
```
awk '{if(NR==4 || (NR>4 && NR==NR+7)) print $0}' file
```
contain condition `NR==NR+7` which does never hold, in turn what is right to `||` is always false and therefore your code is in fact acting like it would be
```
awk '{if(NR==4) print $0}' file
```
>
> print row 4 first and then the 9th row a... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Assuming you want to print every 5th line starting from a specific line number:
```
$ seq 20 | awk 'NR==4{c=4} c && !((++c) % 5)'
4
9
14
19
$ seq 20 | awk 'NR==2{c=4} c && !((++c) % 5)'
2
7
12
17
$ seq 20 | awk 'NR==6{c=4} c && !((++c) % 5)'
6
11
16
```
`c && !((++c) % 5)` says:
>
> If `c` is set then increment ... | * doing it in `awk` without ever using `modulo %` :
>
>
> ```
> jot 30 | mawk 'BEGIN { __+=_+=_+=__=_^=FS="^$" } _-(_+=__*(_==NR))'
>
> ```
>
>
```
4
9
14
19
24
29
```
* generic solution without `modulo %` :
-- `"1st print` ***`17th`*** `row then once every` ***`29`*** `rows after that"`
>
>
> ```
> jot 2... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Assuming you want to print every 5th line starting from a specific line number:
```
$ seq 20 | awk 'NR==4{c=4} c && !((++c) % 5)'
4
9
14
19
$ seq 20 | awk 'NR==2{c=4} c && !((++c) % 5)'
2
7
12
17
$ seq 20 | awk 'NR==6{c=4} c && !((++c) % 5)'
6
11
16
```
`c && !((++c) % 5)` says:
>
> If `c` is set then increment ... | Here is another `awk` solution
```
$ seq 30 | awk -v b=14 -v n=5 'NR>=b && !((NR-b)%n)'
14
19
24
29
```
this is just the translation of `sed -n 14~5p`. |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Simply
```
awk 'NR%5 == 4' file
```
will do the job.
Alternatively, if you have GNU `sed`:
```
sed -n 4~5p file
```
---
**Edit:**
A general solution to the problem of printing every *n*th line starting with line *s* using `awk` could be, for example, like that:
```
awk -v s=6 -v n=5 'NR>=s && NR%n == s%n' fi... | Your code
```
awk '{if(NR==4 || (NR>4 && NR==NR+7)) print $0}' file
```
contain condition `NR==NR+7` which does never hold, in turn what is right to `||` is always false and therefore your code is in fact acting like it would be
```
awk '{if(NR==4) print $0}' file
```
>
> print row 4 first and then the 9th row a... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Simply
```
awk 'NR%5 == 4' file
```
will do the job.
Alternatively, if you have GNU `sed`:
```
sed -n 4~5p file
```
---
**Edit:**
A general solution to the problem of printing every *n*th line starting with line *s* using `awk` could be, for example, like that:
```
awk -v s=6 -v n=5 'NR>=s && NR%n == s%n' fi... | * doing it in `awk` without ever using `modulo %` :
>
>
> ```
> jot 30 | mawk 'BEGIN { __+=_+=_+=__=_^=FS="^$" } _-(_+=__*(_==NR))'
>
> ```
>
>
```
4
9
14
19
24
29
```
* generic solution without `modulo %` :
-- `"1st print` ***`17th`*** `row then once every` ***`29`*** `rows after that"`
>
>
> ```
> jot 2... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Simply
```
awk 'NR%5 == 4' file
```
will do the job.
Alternatively, if you have GNU `sed`:
```
sed -n 4~5p file
```
---
**Edit:**
A general solution to the problem of printing every *n*th line starting with line *s* using `awk` could be, for example, like that:
```
awk -v s=6 -v n=5 'NR>=s && NR%n == s%n' fi... | Here is another `awk` solution
```
$ seq 30 | awk -v b=14 -v n=5 'NR>=b && !((NR-b)%n)'
14
19
24
29
```
this is just the translation of `sed -n 14~5p`. |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Your code
```
awk '{if(NR==4 || (NR>4 && NR==NR+7)) print $0}' file
```
contain condition `NR==NR+7` which does never hold, in turn what is right to `||` is always false and therefore your code is in fact acting like it would be
```
awk '{if(NR==4) print $0}' file
```
>
> print row 4 first and then the 9th row a... | * doing it in `awk` without ever using `modulo %` :
>
>
> ```
> jot 30 | mawk 'BEGIN { __+=_+=_+=__=_^=FS="^$" } _-(_+=__*(_==NR))'
>
> ```
>
>
```
4
9
14
19
24
29
```
* generic solution without `modulo %` :
-- `"1st print` ***`17th`*** `row then once every` ***`29`*** `rows after that"`
>
>
> ```
> jot 2... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Here is another `awk` solution
```
$ seq 30 | awk -v b=14 -v n=5 'NR>=b && !((NR-b)%n)'
14
19
24
29
```
this is just the translation of `sed -n 14~5p`. | Your code
```
awk '{if(NR==4 || (NR>4 && NR==NR+7)) print $0}' file
```
contain condition `NR==NR+7` which does never hold, in turn what is right to `||` is always false and therefore your code is in fact acting like it would be
```
awk '{if(NR==4) print $0}' file
```
>
> print row 4 first and then the 9th row a... |
73,829,933 | I have a dataframe
```
import pandas as pd
data_as_dict={'CHROM': {232: 1, 233: 1, 234: 1, 10: 'chr15', 11: 'chr15'}, 'POS_GRCh38': {232: 10506158, 233: 109655507, 234: 113903258, 10: '67165147', 11: '67163292'}, 'REF': {232: 'G', 233: 'CAAA', 234: 'G', 10: 'G', 11: 'C'}, 'Effect_allele': {232: 'A', 233: 'C', 234:... | 2022/09/23 | [
"https://Stackoverflow.com/questions/73829933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4701887/"
] | Here is another `awk` solution
```
$ seq 30 | awk -v b=14 -v n=5 'NR>=b && !((NR-b)%n)'
14
19
24
29
```
this is just the translation of `sed -n 14~5p`. | * doing it in `awk` without ever using `modulo %` :
>
>
> ```
> jot 30 | mawk 'BEGIN { __+=_+=_+=__=_^=FS="^$" } _-(_+=__*(_==NR))'
>
> ```
>
>
```
4
9
14
19
24
29
```
* generic solution without `modulo %` :
-- `"1st print` ***`17th`*** `row then once every` ***`29`*** `rows after that"`
>
>
> ```
> jot 2... |
45,182,153 | I saw at [concurrency is not parallelism](https://blog.golang.org/concurrency-is-not-parallelism) slide that golang can do like this:
```
func main() {
go boring("Boring!")
fmt.Println("I'm listening.")
time.Sleep(2 * time.Second)
fmt.Println("You're boring; I'm leaving.")
}
```
The result look like ... | 2017/07/19 | [
"https://Stackoverflow.com/questions/45182153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8218546/"
] | Instead of sleeping after running run\_until\_complete, you can use [timeouts](https://docs.python.org/3/library/asyncio-task.html#timeouts). This way, it would be something like:
```
async def main():
print('Hello')
try:
await asyncio.wait_for(boring('boring!'), timeout=2.0)
print('Maybe not t... | `loop.run_forever()` if blocking the execution. As your code is running in a single thread, you need to modify your code to something like this:
```
async def boring(msg):
for i in itertools.count(0):
print(msg, i)
await asyncio.sleep(random.random() % 1e3)
async def hello(task):
print('Hello... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I have high hopes for it.
1. This is being worked on by several people from Google. Seeing as how the BDFL is also employed there, this is a positive.
2. Off the bat, they state that this is a branch, and not a fork. As such, it's within the realm of possibility that this will eventually get merged into trunk.
3. Most... | I'm sorry to disappoint you, but when you read [PEP 3146](http://www.python.org/dev/peps/pep-3146/) things look bad.
The improvement is by now minimal and therfore the compiler-code gets more complicated.
Also removing the GIL has many downsides.
Btw. PyPy seems to be faster then Unladen Swallow in [some tests](http:... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I have high hopes for it.
1. This is being worked on by several people from Google. Seeing as how the BDFL is also employed there, this is a positive.
2. Off the bat, they state that this is a branch, and not a fork. As such, it's within the realm of possibility that this will eventually get merged into trunk.
3. Most... | Guido just posted an article to his twitter account that is an update to the Jesse Noller article posted earlier. <http://jessenoller.com/2010/01/06/unladen-swallow-python-3s-best-feature/>. Sounds like they are moving ahead as previously mentioned with python 3. |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | Guido just posted an article to his twitter account that is an update to the Jesse Noller article posted earlier. <http://jessenoller.com/2010/01/06/unladen-swallow-python-3s-best-feature/>. Sounds like they are moving ahead as previously mentioned with python 3. | I think that a 5 times speed improvement is not all that important for me personally.
It is not an order of magnitude change. Although if you consume CPU power at the scale of Google it can be a worth while investment to have some of your staff work on it.
Many of the speed improvements will likely make it into cpyth... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | Guido just posted an article to his twitter account that is an update to the Jesse Noller article posted earlier. <http://jessenoller.com/2010/01/06/unladen-swallow-python-3s-best-feature/>. Sounds like they are moving ahead as previously mentioned with python 3. | They have a quarterly release. So not far away, wait and watch, let them come up with some thing more than just a plan.
If it indeed comes to be true, easy to do away with C and C++ even for performance intensive operations.
Even tho' it is a Google sponsored Open Source project, surprisingly doesn't involve Guido an... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I'm sorry to disappoint you, but when you read [PEP 3146](http://www.python.org/dev/peps/pep-3146/) things look bad.
The improvement is by now minimal and therfore the compiler-code gets more complicated.
Also removing the GIL has many downsides.
Btw. PyPy seems to be faster then Unladen Swallow in [some tests](http:... | They have a quarterly release. So not far away, wait and watch, let them come up with some thing more than just a plan.
If it indeed comes to be true, easy to do away with C and C++ even for performance intensive operations.
Even tho' it is a Google sponsored Open Source project, surprisingly doesn't involve Guido an... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I'm sorry to disappoint you, but when you read [PEP 3146](http://www.python.org/dev/peps/pep-3146/) things look bad.
The improvement is by now minimal and therfore the compiler-code gets more complicated.
Also removing the GIL has many downsides.
Btw. PyPy seems to be faster then Unladen Swallow in [some tests](http:... | [This question](https://stackoverflow.com/questions/695370/what-is-llvm-and-how-is-replacing-python-vm-with-llvm-increasing-speeds-5x) discussed many of the same things. My opinion is that it sounds great, but I'm waiting to see what it looks like, and how long it takes to become stable.
I'm particularly concerned wit... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I have high hopes for it.
1. This is being worked on by several people from Google. Seeing as how the BDFL is also employed there, this is a positive.
2. Off the bat, they state that this is a branch, and not a fork. As such, it's within the realm of possibility that this will eventually get merged into trunk.
3. Most... | They have a quarterly release. So not far away, wait and watch, let them come up with some thing more than just a plan.
If it indeed comes to be true, easy to do away with C and C++ even for performance intensive operations.
Even tho' it is a Google sponsored Open Source project, surprisingly doesn't involve Guido an... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | [This question](https://stackoverflow.com/questions/695370/what-is-llvm-and-how-is-replacing-python-vm-with-llvm-increasing-speeds-5x) discussed many of the same things. My opinion is that it sounds great, but I'm waiting to see what it looks like, and how long it takes to become stable.
I'm particularly concerned wit... | I think that a 5 times speed improvement is not all that important for me personally.
It is not an order of magnitude change. Although if you consume CPU power at the scale of Google it can be a worth while investment to have some of your staff work on it.
Many of the speed improvements will likely make it into cpyth... |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | [This question](https://stackoverflow.com/questions/695370/what-is-llvm-and-how-is-replacing-python-vm-with-llvm-increasing-speeds-5x) discussed many of the same things. My opinion is that it sounds great, but I'm waiting to see what it looks like, and how long it takes to become stable.
I'm particularly concerned wit... | Guido just posted an article to his twitter account that is an update to the Jesse Noller article posted earlier. <http://jessenoller.com/2010/01/06/unladen-swallow-python-3s-best-feature/>. Sounds like they are moving ahead as previously mentioned with python 3. |
714,242 | What are your opinions and expectations on [Google's Unladen Swallow](http://code.google.com/p/unladen-swallow/wiki/ProjectPlan)? From their project plan:
>
> We want to make Python faster, but we
> also want to make it easy for large,
> well-established applications to
> switch to Unladen Swallow.
>
>
> 1. Prod... | 2009/04/03 | [
"https://Stackoverflow.com/questions/714242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60711/"
] | I think the project has noble goals and with enough time (2-3 years), they will probably reach most of them.
They may not be able to merge their branch back into the trunk because Guido's current view is that cpython should be a reference implementation (ie. it shouldn't do things that are impossible for IronPython an... | I think that a 5 times speed improvement is not all that important for me personally.
It is not an order of magnitude change. Although if you consume CPU power at the scale of Google it can be a worth while investment to have some of your staff work on it.
Many of the speed improvements will likely make it into cpyth... |
53,799,912 | Iam trying to pre-process text as a part of NLP.I am new to it.I am not getting why i am unable to replace the digits
```
para = "support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it see... | 2018/12/16 | [
"https://Stackoverflow.com/questions/53799912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10464351/"
] | For replacing all digits from a string, you can the `re` module, for matching and replacing regex patterns. From your last example:
```
import re
processed_words = [re.sub('\d',' ', word) for word in tokenized]
``` | Is this what you want to do? Or am I missing the point?
```
import re
para = """support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it seems true."""
tokenized = para.split(' ')
new_para... |
53,799,912 | Iam trying to pre-process text as a part of NLP.I am new to it.I am not getting why i am unable to replace the digits
```
para = "support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it see... | 2018/12/16 | [
"https://Stackoverflow.com/questions/53799912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10464351/"
] | The error is trying to tell you that you called `re.sub` with something that is not a string (ignore the "or bytes" and the "-like" parts: you have real strings to work with). The culprit is `words`: The function `nltk.word_tokenize()` returns a list, and you cannot pass the whole thing to `re.sub`. You need another fo... | Is this what you want to do? Or am I missing the point?
```
import re
para = """support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it seems true."""
tokenized = para.split(' ')
new_para... |
53,799,912 | Iam trying to pre-process text as a part of NLP.I am new to it.I am not getting why i am unable to replace the digits
```
para = "support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it see... | 2018/12/16 | [
"https://Stackoverflow.com/questions/53799912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10464351/"
] | For replacing all digits from a string, you can the `re` module, for matching and replacing regex patterns. From your last example:
```
import re
processed_words = [re.sub('\d',' ', word) for word in tokenized]
``` | The error is trying to tell you that you called `re.sub` with something that is not a string (ignore the "or bytes" and the "-like" parts: you have real strings to work with). The culprit is `words`: The function `nltk.word_tokenize()` returns a list, and you cannot pass the whole thing to `re.sub`. You need another fo... |
47,740,542 | ```
def lines(file):
for line in file:
yield line
yield '\n'
def blocks(file):
block = []
for line in lines(file):
if line.strip():
block.append(line)
elif block:
yield ''.join(block).strip()
block = []
with open(r'test_input.txt', 'r') as f:... | 2017/12/10 | [
"https://Stackoverflow.com/questions/47740542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9080044/"
] | Your issue is caused by this line:
```
lines = lines(f)
```
With this assignment, you're overwriting the `lines` generator function with its own return value. That means that when `blocks` tries to call `lines` again (which seems a little buggy to me, but not the main issue), it gets the generator object instead of ... | Your problem is not related to Python3. This error exists with Python 2.6.
I do not know exactly what you try to do but your code do not throws error replacing `blocks` function with :
```
def blocks(file):
block = []
for line in file: # here, replace lines(file) with file
if line.strip():
... |
27,224,458 | I'm using Python's Scrapy to do some web scraping, and I'm trying to get the text in the last td of my last tr in the html below.
```
<table class="infobox" style="float: right; width: 225px; text-align: left; -moz-border-radius:10px; font-size: 85%" cellpadding="2">
<tr style="vertical-align: top;">
<td>... | 2014/12/01 | [
"https://Stackoverflow.com/questions/27224458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3892678/"
] | You should create user because tests create test database (not your) everytime.
```
User.objects.create_user(username=<client_username>, password=<client_password>)
```
Now create Client and login
```
self.c = django.test.client.Client()
self.c.login(username=<client_username>, password=<client_password>)
``` | You can override request headers for every client request like this example:
```
def test_report_wrong_password(self):
headers = dict()
headers['HTTP_AUTHORIZATION'] = 'Basic ' + base64.b64encode('user_name:password')
response = self.client.post(
'/report/',
content_type='application/json',... |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | Don't confuse "Twisted" with "`twistd`". When you use "`twistd`", you *are* running the program with Python. "`twistd`" is a Python program that, among other things, can load an application from a `.tac` file (as you're doing here).
The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out p... | Maybe one of `run` or `runApp` in [twisted.scripts.twistd](http://twistedmatrix.com/documents/9.0.0/api/twisted.scripts.twistd.html) modules will work for you. Please let me know if it does, it will be nice to know! |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | I don't know if it's the best way to do this but what I do is instead of:
```
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
```
you can do:
```
from twisted.internet import reactor
reactor.listenTCP(1025, factory)
reactor.run()
```
Sumarized if you... | Don't confuse "Twisted" with "`twistd`". When you use "`twistd`", you *are* running the program with Python. "`twistd`" is a Python program that, among other things, can load an application from a `.tac` file (as you're doing here).
The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out p... |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | On windows you can create .bat file with your command in it, use full paths, then just click on it to start up.
For example I use:
```
runfileserver.bat:
C:\program_files\python26\Scripts\twistd.py -y C:\source\python\twisted\fileserver.tac
``` | I haven't used twisted myself. However, you may try seeing if the twistd is a python file itself. I would take a guess that it is simply managing loading the appropriate twisted libraries from the correct path. |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | Don't confuse "Twisted" with "`twistd`". When you use "`twistd`", you *are* running the program with Python. "`twistd`" is a Python program that, among other things, can load an application from a `.tac` file (as you're doing here).
The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out p... | On windows you can create .bat file with your command in it, use full paths, then just click on it to start up.
For example I use:
```
runfileserver.bat:
C:\program_files\python26\Scripts\twistd.py -y C:\source\python\twisted\fileserver.tac
``` |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | Don't confuse "Twisted" with "`twistd`". When you use "`twistd`", you *are* running the program with Python. "`twistd`" is a Python program that, among other things, can load an application from a `.tac` file (as you're doing here).
The "Twisted Command Prompt" is a Twisted installer-provided convenience to help out p... | I am successfully using the simple Twisted Web server on Windows for Flask web sites.
Are others also successfully using Twisted on Windows, to validate that configuration?
```
new_app.py
if __name__ == "__main__":
reactor_args = {}
def run_twisted_wsgi():
from twisted.internet import reactor
... |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | I haven't used twisted myself. However, you may try seeing if the twistd is a python file itself. I would take a guess that it is simply managing loading the appropriate twisted libraries from the correct path. | I am successfully using the simple Twisted Web server on Windows for Flask web sites.
Are others also successfully using Twisted on Windows, to validate that configuration?
```
new_app.py
if __name__ == "__main__":
reactor_args = {}
def run_twisted_wsgi():
from twisted.internet import reactor
... |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | I don't know if it's the best way to do this but what I do is instead of:
```
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
```
you can do:
```
from twisted.internet import reactor
reactor.listenTCP(1025, factory)
reactor.run()
```
Sumarized if you... | On windows you can create .bat file with your command in it, use full paths, then just click on it to start up.
For example I use:
```
runfileserver.bat:
C:\program_files\python26\Scripts\twistd.py -y C:\source\python\twisted\fileserver.tac
``` |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | I don't know if it's the best way to do this but what I do is instead of:
```
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
```
you can do:
```
from twisted.internet import reactor
reactor.listenTCP(1025, factory)
reactor.run()
```
Sumarized if you... | I am successfully using the simple Twisted Web server on Windows for Flask web sites.
Are others also successfully using Twisted on Windows, to validate that configuration?
```
new_app.py
if __name__ == "__main__":
reactor_args = {}
def run_twisted_wsgi():
from twisted.internet import reactor
... |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | I don't know if it's the best way to do this but what I do is instead of:
```
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
```
you can do:
```
from twisted.internet import reactor
reactor.listenTCP(1025, factory)
reactor.run()
```
Sumarized if you... | Maybe one of `run` or `runApp` in [twisted.scripts.twistd](http://twistedmatrix.com/documents/9.0.0/api/twisted.scripts.twistd.html) modules will work for you. Please let me know if it does, it will be nice to know! |
1,897,939 | I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example:
```
from twisted.protocols import basic
class MyChat(basic.LineReceiver):
... | 2009/12/13 | [
"https://Stackoverflow.com/questions/1897939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117603/"
] | Maybe one of `run` or `runApp` in [twisted.scripts.twistd](http://twistedmatrix.com/documents/9.0.0/api/twisted.scripts.twistd.html) modules will work for you. Please let me know if it does, it will be nice to know! | I haven't used twisted myself. However, you may try seeing if the twistd is a python file itself. I would take a guess that it is simply managing loading the appropriate twisted libraries from the correct path. |
57,652,922 | Say I want to use [black](https://black.readthedocs.io/en/stable/index.html) as an API, and do something like:
```
import black
black.format("some python code")
```
Formatting code by calling the `black` binary with `Popen` is an alternative, but that's not what I'm asking. | 2019/08/26 | [
"https://Stackoverflow.com/questions/57652922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2142577/"
] | You could try using `format_str`:
```
from black import format_str, FileMode
res = format_str("some python code", mode=FileMode())
print(res)
``` | Use `black.format_file_contents`.
*e.g.*
```py
import black
mode = black.FileMode()
fast = False
out = black.format_file_contents("some python code", fast, mode)
```
<https://github.com/psf/black/blob/19.3b0/black.py#L642> |
38,788,816 | I need to install dryscrape for python but I got error, what's the problem?
```
C:\Users\parvij\Anaconda3\Scripts>pip install dryscrape
```
I got this:
```
Collecting dryscrape
Collecting webkit-server>=1.0 (from dryscrape)
Using cached webkit-server-1.0.tar.gz
Collecting xvfbwrapper (from dryscrape)
Requirement ... | 2016/08/05 | [
"https://Stackoverflow.com/questions/38788816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4042278/"
] | Need to install <http://www.qt.io>. Also, The 5.6+ version of Qt removes the Qt WebKit module in favor of the new module Qt WebEngine. So far, webkit-server has not been ported to WebEngine (and likely won't be in the near future), so Qt <= 5.5 is a requirement. | From the [doc](http://dryscrape.readthedocs.io/en/latest/installation.html), you have to installed also [requirements](https://github.com/niklasb/dryscrape/blob/master/requirements.txt).
You can do this as follow
```
pip install -r requirements.txt
```
After this retry to install **dryscrape**. |
38,788,816 | I need to install dryscrape for python but I got error, what's the problem?
```
C:\Users\parvij\Anaconda3\Scripts>pip install dryscrape
```
I got this:
```
Collecting dryscrape
Collecting webkit-server>=1.0 (from dryscrape)
Using cached webkit-server-1.0.tar.gz
Collecting xvfbwrapper (from dryscrape)
Requirement ... | 2016/08/05 | [
"https://Stackoverflow.com/questions/38788816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4042278/"
] | Download webkit-server from github
```
git clone https://github.com/niklasb/webkit-server.git webkit-server
```
Change in webkit-server/setup.py :
```
shutil.copy('src/webkit_server', self.build_purelib)
shutil.copy('src/webkit_server', self.build_platlib)
```
to
```
shutil.copy('src/webkit_server.pro', self.bui... | From the [doc](http://dryscrape.readthedocs.io/en/latest/installation.html), you have to installed also [requirements](https://github.com/niklasb/dryscrape/blob/master/requirements.txt).
You can do this as follow
```
pip install -r requirements.txt
```
After this retry to install **dryscrape**. |
38,788,816 | I need to install dryscrape for python but I got error, what's the problem?
```
C:\Users\parvij\Anaconda3\Scripts>pip install dryscrape
```
I got this:
```
Collecting dryscrape
Collecting webkit-server>=1.0 (from dryscrape)
Using cached webkit-server-1.0.tar.gz
Collecting xvfbwrapper (from dryscrape)
Requirement ... | 2016/08/05 | [
"https://Stackoverflow.com/questions/38788816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4042278/"
] | Download webkit-server from github
```
git clone https://github.com/niklasb/webkit-server.git webkit-server
```
Change in webkit-server/setup.py :
```
shutil.copy('src/webkit_server', self.build_purelib)
shutil.copy('src/webkit_server', self.build_platlib)
```
to
```
shutil.copy('src/webkit_server.pro', self.bui... | Need to install <http://www.qt.io>. Also, The 5.6+ version of Qt removes the Qt WebKit module in favor of the new module Qt WebEngine. So far, webkit-server has not been ported to WebEngine (and likely won't be in the near future), so Qt <= 5.5 is a requirement. |
38,788,816 | I need to install dryscrape for python but I got error, what's the problem?
```
C:\Users\parvij\Anaconda3\Scripts>pip install dryscrape
```
I got this:
```
Collecting dryscrape
Collecting webkit-server>=1.0 (from dryscrape)
Using cached webkit-server-1.0.tar.gz
Collecting xvfbwrapper (from dryscrape)
Requirement ... | 2016/08/05 | [
"https://Stackoverflow.com/questions/38788816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4042278/"
] | Need to install <http://www.qt.io>. Also, The 5.6+ version of Qt removes the Qt WebKit module in favor of the new module Qt WebEngine. So far, webkit-server has not been ported to WebEngine (and likely won't be in the near future), so Qt <= 5.5 is a requirement. | Need do install `qt4` and `libqtwebkit-dev` for compile `webkit-server`, then follow the steps of [@Erwan Clügairtz](https://stackoverflow.com/a/42809856/11831316)
`sudo apt install libqtwebkit-dev qt4` |
38,788,816 | I need to install dryscrape for python but I got error, what's the problem?
```
C:\Users\parvij\Anaconda3\Scripts>pip install dryscrape
```
I got this:
```
Collecting dryscrape
Collecting webkit-server>=1.0 (from dryscrape)
Using cached webkit-server-1.0.tar.gz
Collecting xvfbwrapper (from dryscrape)
Requirement ... | 2016/08/05 | [
"https://Stackoverflow.com/questions/38788816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4042278/"
] | Download webkit-server from github
```
git clone https://github.com/niklasb/webkit-server.git webkit-server
```
Change in webkit-server/setup.py :
```
shutil.copy('src/webkit_server', self.build_purelib)
shutil.copy('src/webkit_server', self.build_platlib)
```
to
```
shutil.copy('src/webkit_server.pro', self.bui... | Need do install `qt4` and `libqtwebkit-dev` for compile `webkit-server`, then follow the steps of [@Erwan Clügairtz](https://stackoverflow.com/a/42809856/11831316)
`sudo apt install libqtwebkit-dev qt4` |
33,464,208 | Is there a pythonic/efficient way to carry out a simple decrement operation on each element (or more accurately a subset of the elements) in a list of objects of an arbitrary class?
I potentially have a large-ish (~ 10K) list of objects, each of which is updated periodically on the basis of a countdown "time to updat... | 2015/11/01 | [
"https://Stackoverflow.com/questions/33464208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1171112/"
] | Perhaps you could replace your flat list with a priority queue using the `heapq` module. The priorities would be the current time, plus the object's `ttu`. When the current time matched the top element's priority, you'd pop it off, do whatever your updating was, and then push it back into the queue with a new priority.... | I think your code is already good; maybe you could add a single method called something like "beat" for performing both things:
* checking if the object is ready to update and in that case handle the update,
* or decrement in the other case;
it would make your loop a little cleaner and simpler. It won't help much for... |
39,029,068 | I want to be able to execute the following code:
```
import numpy
z=numpy.zeros(4)
k="z[i-1]"
for i in range(len(b)):
z[i]=k
```
Which should return the same output as:
```
z=numpy.zeros(4)
for i in range(6):
z[i]=z[i-1]
```
If I execute the first code block, I get an expected error message:
```
File "... | 2016/08/18 | [
"https://Stackoverflow.com/questions/39029068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5510581/"
] | I think you're looking for the [builtin `eval()`](https://docs.python.org/2/library/functions.html#eval)
Consider:
```
>>> z = numpy.zeros(4)
>>> k = "10 + z[i-1]"
>>> for i in range(1, 4):
... z[i] = eval(k)
...
>>> z
array([ 0., 10., 20., 30.])
```
I made the expression a little more complex so you could ... | Do it as following:
```
import numpy
z=numpy.zeros(4)
k="z[i-1]"
for i in range(len(b)):
z[i]=eval(k)
```
But note eval can be a security problem: <http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.