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 |
|---|---|---|---|---|---|
7,459,766 | I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found`
Could someone advice me on what to do?
```
rmicro@ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.3.tar.g... | 2011/09/18 | [
"https://Stackoverflow.com/questions/7459766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/618677/"
] | Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries.
```
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-mysql.connector
sudo ... | In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:
```
sudo apt install build-essential python-dev libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient
``` |
7,459,766 | I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found`
Could someone advice me on what to do?
```
rmicro@ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.3.tar.g... | 2011/09/18 | [
"https://Stackoverflow.com/questions/7459766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/618677/"
] | Reread the error message. It says:
>
> sh: mysql\_config: not found
>
>
>
If you are on Ubuntu Natty, `mysql_config` belongs to package [libmysqlclient-dev](http://packages.ubuntu.com/search?searchon=contents&keywords=mysql_config&mode=exactfilename&suite=natty&arch=any) | this worked for me on python 3
pip install mysqlclient
----------------------- |
7,459,766 | I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found`
Could someone advice me on what to do?
```
rmicro@ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
Downloading MySQL-python-1.2.3.tar.g... | 2011/09/18 | [
"https://Stackoverflow.com/questions/7459766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/618677/"
] | On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:
```
sudo apt-get install python-mysqldb
```
If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked q... | 1. find the folder: `sudo find / -name "mysql_config"` (assume it's `"/opt/local/lib/mysql5/bin"`)
2. add it into PATH:`export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH`
3. install it again |
21,979,134 | If I do `print(1 >> 2)` I get 0.
If I do `print(2 << 1)` I get 4.
If I do `print(9 << 3)` I get 72
If I do `print(3 >> 9)` I get 0
What do `>>` and `<<` do in python? | 2014/02/24 | [
"https://Stackoverflow.com/questions/21979134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2840324/"
] | They are bitwise shift operators. For example, 2 has the binary equivalent 00000010, so 2 << 1 is 00000010 shifted left 1 time. This yields 00000100, which is 4.
1 >> 2 is 00000001 shifted right 2 times which is 00000000 (the 1 falls off the end after the first shift though, so 1>>1 is also 0), obviously that is 0. | Bitwise shift left and bitwise shift right. They're roughly equivalent to doubling (`<<`) or halving (`>>`) just like decimal shift left is roughly equivalent to multiplying by 10 and decimal shift right is roughly equivalent to dividing by 10. |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | To support arbitrary attribute assignment, an object needs a `__dict__`: a dict associated with the object, where arbitrary attributes can be stored. Otherwise, there's nowhere to *put* new attributes.
An instance of `object` does **not** carry around a `__dict__` -- if it did, before the horrible circular dependence ... | It is simply due to optimization.
Dicts are relatively large.
```
>>> import sys
>>> sys.getsizeof((lambda:1).__dict__)
140
```
Most (maybe all) classes that are defined in C do not have a dict for optimization.
If you look at the [source code](http://svn.python.org/view/python/trunk/Objects/object.c?revision=7445... |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | To support arbitrary attribute assignment, an object needs a `__dict__`: a dict associated with the object, where arbitrary attributes can be stored. Otherwise, there's nowhere to *put* new attributes.
An instance of `object` does **not** carry around a `__dict__` -- if it did, before the horrible circular dependence ... | As other answerers have said, an `object` does not have a `__dict__`. `object` is the base class of **all** types, including `int` or `str`. Thus whatever is provided by `object` will be a burden to them as well. Even something as simple as an *optional* `__dict__` would need an extra pointer for each value; this would... |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | As other answerers have said, an `object` does not have a `__dict__`. `object` is the base class of **all** types, including `int` or `str`. Thus whatever is provided by `object` will be a burden to them as well. Even something as simple as an *optional* `__dict__` would need an extra pointer for each value; this would... | This is (IMO) one of the fundamental limitations with Python - you can't re-open classes. I believe the actual problem, though, is caused by the fact that classes implemented in C can't be modified at runtime... subclasses can, but not the base classes. |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | It is simply due to optimization.
Dicts are relatively large.
```
>>> import sys
>>> sys.getsizeof((lambda:1).__dict__)
140
```
Most (maybe all) classes that are defined in C do not have a dict for optimization.
If you look at the [source code](http://svn.python.org/view/python/trunk/Objects/object.c?revision=7445... | This is (IMO) one of the fundamental limitations with Python - you can't re-open classes. I believe the actual problem, though, is caused by the fact that classes implemented in C can't be modified at runtime... subclasses can, but not the base classes. |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | So, investigating my own question, I discovered this about the Python language: you can inherit from things like int, and you see the same behaviour:
```
>>> class MyInt(int):
pass
>>> x = MyInt()
>>> print x
0
>>> x.hello = 4
>>> print x.hello
4
>>> x = x + 1
>>> print x
1
>>> print x.hello
Traceback (most re... | <https://docs.python.org/3/library/functions.html#object> :
>
> **Note**: [`object`](https://docs.python.org/3/library/functions.html#object) does *not* have a [`__dict__`](https://docs.python.org/3/library/stdtypes.html#object.__dict__), so you can’t assign arbitrary attributes to an instance of the [`object`](https... |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | It is simply due to optimization.
Dicts are relatively large.
```
>>> import sys
>>> sys.getsizeof((lambda:1).__dict__)
140
```
Most (maybe all) classes that are defined in C do not have a dict for optimization.
If you look at the [source code](http://svn.python.org/view/python/trunk/Objects/object.c?revision=7445... | It's because object is a "type", not a class. In general, all classes that are defined in C extensions (like all the built in datatypes, and stuff like numpy arrays) do not allow addition of arbitrary attributes. |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | To support arbitrary attribute assignment, an object needs a `__dict__`: a dict associated with the object, where arbitrary attributes can be stored. Otherwise, there's nowhere to *put* new attributes.
An instance of `object` does **not** carry around a `__dict__` -- if it did, before the horrible circular dependence ... | <https://docs.python.org/3/library/functions.html#object> :
>
> **Note**: [`object`](https://docs.python.org/3/library/functions.html#object) does *not* have a [`__dict__`](https://docs.python.org/3/library/stdtypes.html#object.__dict__), so you can’t assign arbitrary attributes to an instance of the [`object`](https... |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | As other answerers have said, an `object` does not have a `__dict__`. `object` is the base class of **all** types, including `int` or `str`. Thus whatever is provided by `object` will be a burden to them as well. Even something as simple as an *optional* `__dict__` would need an extra pointer for each value; this would... | So, investigating my own question, I discovered this about the Python language: you can inherit from things like int, and you see the same behaviour:
```
>>> class MyInt(int):
pass
>>> x = MyInt()
>>> print x
0
>>> x.hello = 4
>>> print x.hello
4
>>> x = x + 1
>>> print x
1
>>> print x.hello
Traceback (most re... |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | So, investigating my own question, I discovered this about the Python language: you can inherit from things like int, and you see the same behaviour:
```
>>> class MyInt(int):
pass
>>> x = MyInt()
>>> print x
0
>>> x.hello = 4
>>> print x.hello
4
>>> x = x + 1
>>> print x
1
>>> print x.hello
Traceback (most re... | It's because object is a "type", not a class. In general, all classes that are defined in C extensions (like all the built in datatypes, and stuff like numpy arrays) do not allow addition of arbitrary attributes. |
1,529,002 | So, I was playing around with Python while answering [this question](https://stackoverflow.com/questions/1528932/how-to-create-inline-objects-with-properties-in-python/), and I discovered that this is not valid:
```
o = object()
o.attr = 'hello'
```
due to an `AttributeError: 'object' object has no attribute 'attr'`... | 2009/10/07 | [
"https://Stackoverflow.com/questions/1529002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] | It is simply due to optimization.
Dicts are relatively large.
```
>>> import sys
>>> sys.getsizeof((lambda:1).__dict__)
140
```
Most (maybe all) classes that are defined in C do not have a dict for optimization.
If you look at the [source code](http://svn.python.org/view/python/trunk/Objects/object.c?revision=7445... | <https://docs.python.org/3/library/functions.html#object> :
>
> **Note**: [`object`](https://docs.python.org/3/library/functions.html#object) does *not* have a [`__dict__`](https://docs.python.org/3/library/stdtypes.html#object.__dict__), so you can’t assign arbitrary attributes to an instance of the [`object`](https... |
68,968,534 | In Python 2, there is a comparison function.
>
> A comparison function is any callable that accept two arguments, compares them, and returns a negative number for less-than, zero for equality, or a positive number for greater-than.
>
>
>
In Python 3, the comparison function is replaced with a key function.
>
> ... | 2021/08/28 | [
"https://Stackoverflow.com/questions/68968534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/839733/"
] | Consider how tuples *normally* compare: element by element, going to the next element when the current values are equal (sometimes called *lexicographic order*).
Our required comparison algorithm, rewritten in steps that match that general approach, is:
* First, we want to compare the `x` values, putting them in asce... | Since the original version of this was rec'd for deletion as supposedly not actually answering the question due to it... being too long, I guess?, here's a shorter version of the exact same answer that gives less insight but uses fewer words. (Yes, it was too long. It also answered the question. "omg tl;dr" shouldn't b... |
68,968,534 | In Python 2, there is a comparison function.
>
> A comparison function is any callable that accept two arguments, compares them, and returns a negative number for less-than, zero for equality, or a positive number for greater-than.
>
>
>
In Python 3, the comparison function is replaced with a key function.
>
> ... | 2021/08/28 | [
"https://Stackoverflow.com/questions/68968534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/839733/"
] | Consider how tuples *normally* compare: element by element, going to the next element when the current values are equal (sometimes called *lexicographic order*).
Our required comparison algorithm, rewritten in steps that match that general approach, is:
* First, we want to compare the `x` values, putting them in asce... | Alternately, one can replicate the work that the built-in `cmp_to_key` does, but hard-wiring the comparison logic from the original `cmp` function. I don't recommend this, obviously; but it is still in some sense "direct", and it highlights a few important things about Python internals.
The idea is, we create a wrappe... |
68,968,534 | In Python 2, there is a comparison function.
>
> A comparison function is any callable that accept two arguments, compares them, and returns a negative number for less-than, zero for equality, or a positive number for greater-than.
>
>
>
In Python 3, the comparison function is replaced with a key function.
>
> ... | 2021/08/28 | [
"https://Stackoverflow.com/questions/68968534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/839733/"
] | Alternately, one can replicate the work that the built-in `cmp_to_key` does, but hard-wiring the comparison logic from the original `cmp` function. I don't recommend this, obviously; but it is still in some sense "direct", and it highlights a few important things about Python internals.
The idea is, we create a wrappe... | Since the original version of this was rec'd for deletion as supposedly not actually answering the question due to it... being too long, I guess?, here's a shorter version of the exact same answer that gives less insight but uses fewer words. (Yes, it was too long. It also answered the question. "omg tl;dr" shouldn't b... |
62,633,601 | I want to re-implement a certain API client, which is written in Python, in JavaScript. I fail to replicate the HMAC SHA256 signing function. For some keys the output is identical, but for some it is different. It appears that the output is the same when the key consists of printable characters after decoding its Base6... | 2020/06/29 | [
"https://Stackoverflow.com/questions/62633601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447243/"
] | The base64 encoded secret you are trying to give to CryptoJs does not represent a valid UTF-8 string, which CryptoJS requires. You can use [this tool](https://onlineutf8tools.com/convert-hexadecimal-to-utf8) to check for validity. `atob()` is encoding agnostic and just converts byte by byte, and does not check if it's ... | In the third example you are using different parameters in the python and JavaScript versions.
In python:
sign\_string('xTsHZGfWUmnIpSu+TaVraECU88O3j9qVjlwTWGb/C8k=', "my message")
In JavaScript:
sign\_string('pkmNNJw3alrpIBi5t5Pxuym00M211oN86IhLZVT8', "my message") |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | I have found a fairly simple way to do this.
Initially, through your Anaconda Prompt, you can follow the steps in this official Tensorflow site - [here](https://www.tensorflow.org/install/install_windows). You have to follow the steps as is, no deviation.
Later, you open the Anaconda Navigator. In Anaconda Navigator,... | It is better to create new environment with new name ($newenv):`conda create -n $newenv tensorflow`
Then by using anaconda navigator under environment tab you can find newenv in the middle column.
By clicking on the play button open terminal and type: `activate tensorflow`
Then install tensorflow inside the newenv b... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | I came up with your case. This is how I sort it out
1. Install Anaconda
2. Create a virtual environment - `conda create -n tensorflow`
3. Go inside your virtual environment - (on macOS/Linux:) `source activate tensorflow` (on Windows: `activate tensorflow`)
4. Inside that install tensorflow. You can install it using `... | For Anaconda users in Windows 10 and those who recently updated Anaconda environment, TensorFlow may cause some issues to activate or initiate.
Here is the solution which I explored and which worked for me:
* Uninstall current Anaconda environment and delete all the existing files associated with Anaconda from your C... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | 1. install tensorflow by running these commands in anoconda shell or in console:
```
conda create -n tensorflow python=3.5
activate tensorflow
conda install pandas matplotlib jupyter notebook scipy scikit-learn
pip install tensorflow
```
2. close the console and reopen it and type these commands:
```
activate tenso... | I have to install it using condo's pip3. Just start jupyter-notebook and execute following
```
import sys
sys.executable
```
This will give you something like this
```
/home/<user>/anaconda3/bin/python
```
Now in a terminal execute the following (using pip3 from the above path where we found our python)
```
/hom... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | I have found a fairly simple way to do this.
Initially, through your Anaconda Prompt, you can follow the steps in this official Tensorflow site - [here](https://www.tensorflow.org/install/install_windows). You have to follow the steps as is, no deviation.
Later, you open the Anaconda Navigator. In Anaconda Navigator,... | Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating t... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | 1. install tensorflow by running these commands in anoconda shell or in console:
```
conda create -n tensorflow python=3.5
activate tensorflow
conda install pandas matplotlib jupyter notebook scipy scikit-learn
pip install tensorflow
```
2. close the console and reopen it and type these commands:
```
activate tenso... | I have found a fairly simple way to do this.
Initially, through your Anaconda Prompt, you can follow the steps in this official Tensorflow site - [here](https://www.tensorflow.org/install/install_windows). You have to follow the steps as is, no deviation.
Later, you open the Anaconda Navigator. In Anaconda Navigator,... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating t... | I have to install it using condo's pip3. Just start jupyter-notebook and execute following
```
import sys
sys.executable
```
This will give you something like this
```
/home/<user>/anaconda3/bin/python
```
Now in a terminal execute the following (using pip3 from the above path where we found our python)
```
/hom... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | 1. install tensorflow by running these commands in anoconda shell or in console:
```
conda create -n tensorflow python=3.5
activate tensorflow
conda install pandas matplotlib jupyter notebook scipy scikit-learn
pip install tensorflow
```
2. close the console and reopen it and type these commands:
```
activate tenso... | Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating t... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | 1. Install Anaconda
2. Run Anaconda command prompt
3. write "activate tensorflow" for windows
4. pip install tensorflow
5. pip install jupyter notebook
6. jupyter notebook.
Only this solution worked for me. Tried 7 8 solutions.
Using Windows platform. | I would suggest launching Jupyter lab/notebook from your base environment and selecting the right kernel.
[How to add conda environment to jupyter lab](https://stackoverflow.com/questions/53004311/how-to-add-conda-environment-to-jupyter-lab) should contains the info needed to add the kernel to your base environment.
... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | I believe a short video showing all the details if you have Anaconda is the following for mac (it is very similar to windows users as well) just open Anaconda navigator and everything is just the same (almost!)
<https://www.youtube.com/watch?v=gDzAm25CORk>
Then go to jupyter notebook and code
```
!pip install tensor... | I have to install it using condo's pip3. Just start jupyter-notebook and execute following
```
import sys
sys.executable
```
This will give you something like this
```
/home/<user>/anaconda3/bin/python
```
Now in a terminal execute the following (using pip3 from the above path where we found our python)
```
/hom... |
43,216,256 | I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called `tensorflow` as follows
```
conda create -n tensorflow
```
Then installed the data science Python packages, like Pan... | 2017/04/04 | [
"https://Stackoverflow.com/questions/43216256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2769240/"
] | 1. Install Anaconda
2. Run Anaconda command prompt
3. write "activate tensorflow" for windows
4. pip install tensorflow
5. pip install jupyter notebook
6. jupyter notebook.
Only this solution worked for me. Tried 7 8 solutions.
Using Windows platform. | Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating t... |
19,151,734 | I have data in the following format:
```
user,item,rating
1,1,3
1,2,2
2,1,2
2,4,1
```
and so on
I want to convert this in matrix form
So, the out put is like this
```
Item--> 1,2,3,4....
user
1 3,2,0,0....
2 2,0,0,1
```
....and so on..
How do I do this in python?
THanks | 2013/10/03 | [
"https://Stackoverflow.com/questions/19151734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/902885/"
] | ```
data = [
(1,1,3),
(1,2,2),
(2,1,2),
(2,4,1),
]
#import csv
#with open('data.csv') as f:
# next(f) # Skip header
# data = [map(int, row) for row in csv.reader(f)]
# # Python 3.x: map(int, row) -> tuple(map(int, row))
n = max(max(user, item) for user, item, rating in data) # Get size of mat... | a different approach from @falsetru,
do you read from file in write to file?
may be work with dictionary
```
from collections import defaultdict
valdict=defaultdict(int)
nuser=0
nitem=0
for line in infile:
eachline=line.strip().split(",")
valdict[tuple(eachline[0:2])]=eachline[2]
nuser=max(nuser,eachlin... |
74,165,151 | Let's say I have following python code:
```
import numpy as np
import matplotlib.pyplot as plt
fig=plt.figure()
ax=plt.axes(projection='3d')
x=y=np.linspace(1,10,100)
X,Y=np.meshgrid(x,y)
Z=np.sin(X)**3+np.cos(Y)**3
ax.plot_surface(X,Y,Z)
plt.show()
```
How do I calculate from this code the gradient and plot it? I ... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74165151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12548284/"
] | gradient is a vector. It has 2 components (in this case, since we are dealing with function ℝ²→ℝ, X,Y↦Z(X,Y)), one which is ∂Z/∂X, (also a function of X and Y), another which is ∂Z/∂Y.
So, np.gradients returns both. `np.gradient(Z)`, called with a 100×100 array of Z, returns a list [∂Z/∂X, ∂Z/∂Y], both being also 100×... | Here is the practical way to achieve it with Python:
```
import numpy as np
import matplotlib.pyplot as plt
# Some scalar function of interest:
def z(x, y):
return np.power(np.sin(x), 3) + np.power(np.cos(y), 3)
# Grid for gradient:
xmin, xmax = -7, 7
x = y = np.linspace(xmin, xmax, 100)
X, Y = np.meshgrid(x, y)... |
60,473,135 | I am using python 3.7 on Spyder. Here is my simple code to store string elements ['a','b'] in a list L as sympy symbols. As output, I have new list L with two Symbols [a,b] in it. But when I try to use these symbols in my calculation I get an error saying a & b are not defined. Any suggestions on how can I fix this?
B... | 2020/03/01 | [
"https://Stackoverflow.com/questions/60473135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11039234/"
] | Not knowing the second template argument to `std::array<>` means your `test` class should be templated as well.
```
template <std::size_t N>
class test
{
void function(const std::array<int, N> & myarr)
{
// ...
}
};
```
By the way, it's better to pass `myarr` as `const &`. | You could use an approach like:
```
#include<array>
using namespace std;
template <size_t N>
class test
{
void function(const array<int, N> & myarr)
{
/* My code */
}
};
```
But keep in mind that `std::array` is not a dynamic array. You have to know the sizes at compile time.
If you get to know... |
59,410,455 | I have an application with python, flask, and flask\_mysqldb. When I execute the first query, everything works fine, but the second query always throws an error (2006, server has gone away). Everything I found on the web says this error is a timeout issue, which doesn't seem to be my case because:
1 - I run the second... | 2019/12/19 | [
"https://Stackoverflow.com/questions/59410455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5844134/"
] | >
> I've noticed that the same data stored inside integer had reversed byte order than when stored as char
>
>
>
This implies that the file was stored with different byte endianness than what the CPU uses. In the example output, you can see that the CPU uses little-endian (least significant byte first). Given that... | As @Mat briefly explained, you're running into something called "endianness". There's "Big Endian", where the most significant bits are at the beginning?! (yes, it's a bit counter-intuitive), and "Little Endian", where the least significant bits are at the beginning.
>
> For example: Arabic numerals are big endian. "... |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | There should be a binary called "pip2.7" installed at some location included within your $PATH variable.
You can find that out by typing
```
which pip2.7
```
This should print something like '/usr/local/bin/pip2.7' to your stdout. If it does not print anything like this, it is not installed. In that case, install i... | An alternative is to call the `pip` module by using python2.7, as below:
```
python2.7 -m pip <commands>
```
For example, you could run `python2.7 -m pip install <package>` to install your favorite python modules. Here is a reference: <https://stackoverflow.com/a/50017310/4256346>.
In case the pip module has not ye... |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | There should be a binary called "pip2.7" installed at some location included within your $PATH variable.
You can find that out by typing
```
which pip2.7
```
This should print something like '/usr/local/bin/pip2.7' to your stdout. If it does not print anything like this, it is not installed. In that case, install i... | as noted [here](https://stackoverflow.com/questions/61699983/upgrade-to-ubuntu-20-04-killed-pip/61974430#61974430), this is what worked best for me:
```
sudo apt-get install python3 python3-pip python3-setuptools
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
``` |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | There should be a binary called "pip2.7" installed at some location included within your $PATH variable.
You can find that out by typing
```
which pip2.7
```
This should print something like '/usr/local/bin/pip2.7' to your stdout. If it does not print anything like this, it is not installed. In that case, install i... | `pip` has now dropped support for python2, therefore you can't use python2 pip
You can't find `python2-pip` in `apt-get` anymore, and you won't get `pip` when installing python2 from source
You can still install python modules using `apt-get`. To install a python prepend ‘python-’ to the module name
```
apt-get inst... |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | An alternative is to call the `pip` module by using python2.7, as below:
```
python2.7 -m pip <commands>
```
For example, you could run `python2.7 -m pip install <package>` to install your favorite python modules. Here is a reference: <https://stackoverflow.com/a/50017310/4256346>.
In case the pip module has not ye... | as noted [here](https://stackoverflow.com/questions/61699983/upgrade-to-ubuntu-20-04-killed-pip/61974430#61974430), this is what worked best for me:
```
sudo apt-get install python3 python3-pip python3-setuptools
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
``` |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | An alternative is to call the `pip` module by using python2.7, as below:
```
python2.7 -m pip <commands>
```
For example, you could run `python2.7 -m pip install <package>` to install your favorite python modules. Here is a reference: <https://stackoverflow.com/a/50017310/4256346>.
In case the pip module has not ye... | `pip` has now dropped support for python2, therefore you can't use python2 pip
You can't find `python2-pip` in `apt-get` anymore, and you won't get `pip` when installing python2 from source
You can still install python modules using `apt-get`. To install a python prepend ‘python-’ to the module name
```
apt-get inst... |
26,266,437 | I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
```
pip -V
```
It shows:
```
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
```
How do I use the 2.7 version of pip located at:
```
/usr/local/lib/python2.7/site-packages
``` | 2014/10/08 | [
"https://Stackoverflow.com/questions/26266437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84885/"
] | as noted [here](https://stackoverflow.com/questions/61699983/upgrade-to-ubuntu-20-04-killed-pip/61974430#61974430), this is what worked best for me:
```
sudo apt-get install python3 python3-pip python3-setuptools
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
``` | `pip` has now dropped support for python2, therefore you can't use python2 pip
You can't find `python2-pip` in `apt-get` anymore, and you won't get `pip` when installing python2 from source
You can still install python modules using `apt-get`. To install a python prepend ‘python-’ to the module name
```
apt-get inst... |
64,882,005 | I have a python list shown below. I want to remove all the elements after a specific character `''`
Note1: The number of elements before `''` can vary. I am developing a generic code.
Note2: There can be multiple `''` I want to remove after the first `''`
Note3: Slice is not applicable because it supports only integ... | 2020/11/17 | [
"https://Stackoverflow.com/questions/64882005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14606112/"
] | ```
list = ['a', 'b', 'c', '', 'd', 'e']
list = list[:list.index('')]
#list is now ['a', 'b', 'c']
```
Explanation: `list.index('')` finds the first instance of `''` in the list. `list[:x]` gives the first `x` elements of the list. This code will throw an exception if `''` is not in the list. | You have a list and want to delete everything after a value that meets some sort of criteria. You can enumerate the list, searching for that value and delete the remaining slice. `list.index` will tell you the index of value that exactly matches some object like `""`.
```
test = ["foo", "bar", "" "baz", "", "quux"]
tr... |
64,882,005 | I have a python list shown below. I want to remove all the elements after a specific character `''`
Note1: The number of elements before `''` can vary. I am developing a generic code.
Note2: There can be multiple `''` I want to remove after the first `''`
Note3: Slice is not applicable because it supports only integ... | 2020/11/17 | [
"https://Stackoverflow.com/questions/64882005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14606112/"
] | ```
list = ['a', 'b', 'c', '', 'd', 'e']
list = list[:list.index('')]
#list is now ['a', 'b', 'c']
```
Explanation: `list.index('')` finds the first instance of `''` in the list. `list[:x]` gives the first `x` elements of the list. This code will throw an exception if `''` is not in the list. | First, you should find the first time `''` shows, by using `mylist.index('')`. This will indeed find the first show of it, as in `index()`'s documentation:
>
> Return first index of value.
>
>
>
Also, note the rest of the documentation:
>
> Raises ValueError if the value is not present.
>
>
>
Make sure to c... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I would recommend installing Ubuntu (as a Ubuntu user), you can dual-boot. However, that isn't an answer.
MySQLClient (the fork for Python3) is available a precompiled binary from here:
<http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient>
Try to find precompiled binaries for simplicity sake. As far as troubleshoo... | I grew frustrated with trying to get python and other packages to compile/play nicely on Windows as well. Switching over to Ubuntu was a breath of fresh air, for sure.
The win32com package is made specifically for Windows hosts, so that could not longer be used, but there are other ways to achieve the same thing in Ub... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I would recommend installing Ubuntu (as a Ubuntu user), you can dual-boot. However, that isn't an answer.
MySQLClient (the fork for Python3) is available a precompiled binary from here:
<http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient>
Try to find precompiled binaries for simplicity sake. As far as troubleshoo... | You could try <http://www.activestate.com/activepython/downloads> for Windows. I t includes compiled binaries, avoiding the need for a C complier. |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I would recommend installing Ubuntu (as a Ubuntu user), you can dual-boot. However, that isn't an answer.
MySQLClient (the fork for Python3) is available a precompiled binary from here:
<http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient>
Try to find precompiled binaries for simplicity sake. As far as troubleshoo... | Looks like you're missing MySQL dev package. Another [StackOverflow question](https://stackoverflow.com/questions/1972259/cannot-open-include-file-config-win-h-no-such-file-or-directory-while-inst) has the details. But if I were you, I'd go the route [Alexander Huszagh](https://stackoverflow.com/users/4131059/alexander... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | You could try <http://www.activestate.com/activepython/downloads> for Windows. I t includes compiled binaries, avoiding the need for a C complier. | I grew frustrated with trying to get python and other packages to compile/play nicely on Windows as well. Switching over to Ubuntu was a breath of fresh air, for sure.
The win32com package is made specifically for Windows hosts, so that could not longer be used, but there are other ways to achieve the same thing in Ub... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I have faced the exact same issues for Python 2.7 on 64 bit Windows trying to install pycld2.
Tried many methods like installing VS express 2008, MingW, etc and it just doesnt work.
What saved me is this link:
<https://github.com/aboSamoor/polyglot/issues/11>
The proposed solution is to download the binaries from <h... | I grew frustrated with trying to get python and other packages to compile/play nicely on Windows as well. Switching over to Ubuntu was a breath of fresh air, for sure.
The win32com package is made specifically for Windows hosts, so that could not longer be used, but there are other ways to achieve the same thing in Ub... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | You could try <http://www.activestate.com/activepython/downloads> for Windows. I t includes compiled binaries, avoiding the need for a C complier. | Looks like you're missing MySQL dev package. Another [StackOverflow question](https://stackoverflow.com/questions/1972259/cannot-open-include-file-config-win-h-no-such-file-or-directory-while-inst) has the details. But if I were you, I'd go the route [Alexander Huszagh](https://stackoverflow.com/users/4131059/alexander... |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I have faced the exact same issues for Python 2.7 on 64 bit Windows trying to install pycld2.
Tried many methods like installing VS express 2008, MingW, etc and it just doesnt work.
What saved me is this link:
<https://github.com/aboSamoor/polyglot/issues/11>
The proposed solution is to download the binaries from <h... | You could try <http://www.activestate.com/activepython/downloads> for Windows. I t includes compiled binaries, avoiding the need for a C complier. |
30,744,415 | Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did... | 2015/06/09 | [
"https://Stackoverflow.com/questions/30744415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2069136/"
] | I have faced the exact same issues for Python 2.7 on 64 bit Windows trying to install pycld2.
Tried many methods like installing VS express 2008, MingW, etc and it just doesnt work.
What saved me is this link:
<https://github.com/aboSamoor/polyglot/issues/11>
The proposed solution is to download the binaries from <h... | Looks like you're missing MySQL dev package. Another [StackOverflow question](https://stackoverflow.com/questions/1972259/cannot-open-include-file-config-win-h-no-such-file-or-directory-while-inst) has the details. But if I were you, I'd go the route [Alexander Huszagh](https://stackoverflow.com/users/4131059/alexander... |
32,330,838 | I am new to Python. I have a code both in python 3.x & python 2.x (Actually, it is a library which has been written in 2.x). I am calling a function in python 2.x from python 3.x. The library return a HTTPResponse (from python 2.x). I am not able to parse the HTTPResponse in my code (In Python 3.x).
**My request is :... | 2015/09/01 | [
"https://Stackoverflow.com/questions/32330838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5268513/"
] | This should work:
```
beans = {
myBean(MyBeanImpl) { bean ->
bean.scope = 'prototype'
someProperty = 42
otherProperty = "blue"
bookService = ref("bookService")
}
}
``` | I agree with Jeff Scott Brown.
How do you know it doesn't work? We're using Grails 2.3.9.
I have this in my resources.groovy:
```
httpBuilderPool(HTTPBuilder) { bean ->
bean.scope = 'prototype' // A new service is created every time it is injected into another class
client = ref('httpClientPool')
}
...... |
30,364,874 | I'm trying to teach myself python and I'm quite new to parsing concepts. I'm trying to parse the output from my fire service pager, it seems to follow a consistent pattern as follows:
```
(UNIT1, UNIT2, UNIT3) 911-STRU (Box# 12345) aBusiness 12345 Street aTown (Xstr CrossStreet1/CrossStreet2) building fire, persons re... | 2015/05/21 | [
"https://Stackoverflow.com/questions/30364874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4889516/"
] | I think your best/easiest option is to use [regular expressions](https://docs.python.org/2/library/re.html), defining a pattern that will match all or parts of your input string and extract the pieces that you're interested in.
[PyParsing](http://pyparsing.wikispaces.com/) will probably work fine too. I have not used... | If you know pyparsing, then it might be easier to go with it. The `()` can always be treated as optional. Pyparsing will make certain things easier out of the box.
If you are not so familiar with pyparsing, and your main goal is learning python, then hand craft your own parser in pure python. Nothing better at learni... |
21,331,730 | I want to install PHP on the server. and I want to install it with Python script. Can I include PHP (some version number) in the reqirements.txt file and install it on the server?
If not, then how can I install PHP on the server using a python script? | 2014/01/24 | [
"https://Stackoverflow.com/questions/21331730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1162512/"
] | You can get the counts by using
```
df.groupby([df.index.date, 'action']).count()
```
or you can plot directly using this method
```
df.groupby([df.index.date, 'action']).count().plot(kind='bar')
```
You could also just store the results to `count` and then plot it separately. This is assuming that your index i... | Starting from
```
mydate col_name
0 2000-12-29 00:10:00 action1
1 2000-12-29 00:20:00 action2
2 2000-12-29 00:30:00 action2
3 2000-12-29 00:40:00 action1
4 2000-12-29 00:50:00 action1
5 2000-12-31 00:10:00 action1
6 2000-12-31 00:20:00 action2
7 2000-12-31 00:30:00 action2
```
You can... |
21,331,730 | I want to install PHP on the server. and I want to install it with Python script. Can I include PHP (some version number) in the reqirements.txt file and install it on the server?
If not, then how can I install PHP on the server using a python script? | 2014/01/24 | [
"https://Stackoverflow.com/questions/21331730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1162512/"
] | Starting from
```
mydate col_name
0 2000-12-29 00:10:00 action1
1 2000-12-29 00:20:00 action2
2 2000-12-29 00:30:00 action2
3 2000-12-29 00:40:00 action1
4 2000-12-29 00:50:00 action1
5 2000-12-31 00:10:00 action1
6 2000-12-31 00:20:00 action2
7 2000-12-31 00:30:00 action2
```
You can... | I find the combo `.count_values().plot.bar()` very intuitive to do histogram plot. It also puts categories in the right order for you and, in many cases where there are too many categories, you can simply do `.count_values().iloc[:k].plot.bar()`.
So, what I would do in your case is to compute a new Pandas Series of da... |
21,331,730 | I want to install PHP on the server. and I want to install it with Python script. Can I include PHP (some version number) in the reqirements.txt file and install it on the server?
If not, then how can I install PHP on the server using a python script? | 2014/01/24 | [
"https://Stackoverflow.com/questions/21331730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1162512/"
] | You can get the counts by using
```
df.groupby([df.index.date, 'action']).count()
```
or you can plot directly using this method
```
df.groupby([df.index.date, 'action']).count().plot(kind='bar')
```
You could also just store the results to `count` and then plot it separately. This is assuming that your index i... | I find the combo `.count_values().plot.bar()` very intuitive to do histogram plot. It also puts categories in the right order for you and, in many cases where there are too many categories, you can simply do `.count_values().iloc[:k].plot.bar()`.
So, what I would do in your case is to compute a new Pandas Series of da... |
40,821,733 | I'm currently using vagrant and set it up to connect to my local computer's port 5000 and when I move to localhost:5000, the default ubuntu webpage appears to confirm that I'm connected.
However, it tells me to manipulate the app using the index.html in there but I already have a whole Python flask app stored somewhe... | 2016/11/26 | [
"https://Stackoverflow.com/questions/40821733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4297337/"
] | Create a static field inside class, and increment it in constructor.
something like this:
```
class A {
public:
A() : itemnumber(nextNum) { ++nextNum; }
private:
int itemnumber;
static int nextNum;
}
// in CPP file initialize it
int A::nextNum = 1;
```
Also, don't forget to increment static field in co... | with a static variable like
```
class rect{
public:
static int num;
rect(){num++;}
};
int rect::num =0;
int main(){
rect a();
cout << rect::num;
}
``` |
49,469,409 | I am relatively new to programming.
I'm trying to run the following:
```
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawc... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49469409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9545845/"
] | The matplotlib deprecated the get\_axis\_bgcolor. You'll need to update basemap to version 1.1.0 to fix this error. It's installable via conda-forge, via:
```
conda install -c conda-forge basemap
```
In case you'll get error like, "Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets... | In addition to [@user45237841](https://stackoverflow.com/users/8861059/user45237841)'s answer, you can also change the `resolution` to `c` or `l` to resolve this error `Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default.`
```
my_map = Basemap(projection = 'or... |
49,469,409 | I am relatively new to programming.
I'm trying to run the following:
```
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawc... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49469409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9545845/"
] | The matplotlib deprecated the get\_axis\_bgcolor. You'll need to update basemap to version 1.1.0 to fix this error. It's installable via conda-forge, via:
```
conda install -c conda-forge basemap
```
In case you'll get error like, "Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets... | if you are using Jupyter-notebook make sure that using --yes to processing package installing on platform. `conda install -c conda-forge basemap-data-hires --yes` |
49,469,409 | I am relatively new to programming.
I'm trying to run the following:
```
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawc... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49469409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9545845/"
] | The matplotlib deprecated the get\_axis\_bgcolor. You'll need to update basemap to version 1.1.0 to fix this error. It's installable via conda-forge, via:
```
conda install -c conda-forge basemap
```
In case you'll get error like, "Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets... | If you don't want to update just replace `get_axis_bgcolor` with `get_facecolor` in `\site-packages\mpl_toolkits\basemap\__init__.py` file.
```
Line 1623: fill_color = ax.get_facecolor()
Line 1767: axisbgc = ax.get_facecolor()
``` |
49,469,409 | I am relatively new to programming.
I'm trying to run the following:
```
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawc... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49469409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9545845/"
] | In addition to [@user45237841](https://stackoverflow.com/users/8861059/user45237841)'s answer, you can also change the `resolution` to `c` or `l` to resolve this error `Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default.`
```
my_map = Basemap(projection = 'or... | if you are using Jupyter-notebook make sure that using --yes to processing package installing on platform. `conda install -c conda-forge basemap-data-hires --yes` |
49,469,409 | I am relatively new to programming.
I'm trying to run the following:
```
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawc... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49469409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9545845/"
] | In addition to [@user45237841](https://stackoverflow.com/users/8861059/user45237841)'s answer, you can also change the `resolution` to `c` or `l` to resolve this error `Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default.`
```
my_map = Basemap(projection = 'or... | If you don't want to update just replace `get_axis_bgcolor` with `get_facecolor` in `\site-packages\mpl_toolkits\basemap\__init__.py` file.
```
Line 1623: fill_color = ax.get_facecolor()
Line 1767: axisbgc = ax.get_facecolor()
``` |
64,641,472 | Accidentally my python script has made a table with name as "ext\_data\_content\_modec --replace" which we want to delete.
However BQ doesn't seem to recognize the table with spaces and keywords(--replace).
We have tried many variants of bq rm , as well as tried deleting the from BQ console but it doesn't work
For e... | 2020/11/02 | [
"https://Stackoverflow.com/questions/64641472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13078109/"
] | You would do something like this:
```
Map<String, B> bById = ...
Map<String, B> bByName = ...
for (A a : listA) {
B b = bById.getOrDefault(a.id, bByName.get(a.name));
if (b != null) {
a.setPersonalDetails(b.getPersonalDetails);
}
}
``` | you can use comparator to achieve this.Just a example psudo code is given below
```java
Collections.sort(listA, Comparator.comparing(A::getId)
.thenComparing(A::getName)
.thenComparing(A::getAge));
``` |
50,863,799 | I'm pretty new to Python, but have Python 3.6 installed, and running a few other programs perfectly. I'm trying to pull data using the pandas\_datareader module but keep running into this issue. Operating system: OSX.I've visited the other threads on similar errors and tried their methods to no avail.
Additional conc... | 2018/06/14 | [
"https://Stackoverflow.com/questions/50863799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7075311/"
] | As has been noted, `is_list_like` has been moved from `pandas.core.common` to `pandas.api.types`.
There are several paths forward for you.
1. My (highly) recommended solution: download Conda and set up an environment with a version of Pandas prior to v0.23.0.
2. You can install the development version of Pandas, with... | Small workaround is to define it like this:
```
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader
``` |
4,645,822 | I've been struggling with the [cutting stock problem](http://en.wikipedia.org/wiki/Cutting_stock_problem) for a while, and I need to do a funcion that given an array of values, gives me an array of array for all the possible combinations.
I trying to do this function, but (as everything in python), I think someone mus... | 2011/01/10 | [
"https://Stackoverflow.com/questions/4645822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
>>> from itertools import permutations
>>> x = range(3)
>>> list(permutations(x))
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>>
``` | Do you mean [itertools.combinations](http://docs.python.org/library/itertools.html#itertools.combinations)? |
4,645,822 | I've been struggling with the [cutting stock problem](http://en.wikipedia.org/wiki/Cutting_stock_problem) for a while, and I need to do a funcion that given an array of values, gives me an array of array for all the possible combinations.
I trying to do this function, but (as everything in python), I think someone mus... | 2011/01/10 | [
"https://Stackoverflow.com/questions/4645822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
>>> from itertools import permutations
>>> x = range(3)
>>> list(permutations(x))
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>>
``` | ```
>>> from itertools import combinations
>>> list(combinations('abcd', 2))
``` |
22,476,489 | We can convert a `datetime` value in to decimal using following function.
```
import time
from datetime import datetime
t = datetime.now()
t1 = t.timetuple()
print time.mktime(t1)
```
Output :
```
Out[9]: 1395136322.0
```
Similarly is there a way to convert strings in to a `decimal` using python?.
Example str... | 2014/03/18 | [
"https://Stackoverflow.com/questions/22476489",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/461436/"
] | If you want an integer to uniquely identify a string, I'd go for hashing functions, like SHA. They return the same value for the same input.
```
import hashlib
def sha256_hash_as_int(s):
return int(hashlib.sha256(s).hexdigest(), 16)
```
If you use Python 3, you first have to encode `s` to some concrete encoding,... | You can use [hash](http://docs.python.org/2.7/library/functions.html#hash) function:
```
>>> hash("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0")
1892010093
``` |
37,737,098 | I have a string time coming from a third party (external to my python program), and I need to compare that time to right now. How long ago was that time?
How can I do this?
I've looked at the `datetime` and `time` libraries, as well as `pytz`, and can't find an obvious way to do this. It should automatically incorpor... | 2016/06/09 | [
"https://Stackoverflow.com/questions/37737098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6365333/"
] | Signing a commit will change the commit metadata, and thus change the underlying SHA1 commit ID. As you probably know, for Git, this has the same consequence of trying to change the contents of your history.
If you want to just re-sign your last commit you could run:
`git commit -S --amend`
If you want to re-sign a ... | If you want to sign all the existing commits on the branch without do any changes to them:
```
git rebase --exec 'git commit --amend --no-edit -n -S' -i origin/HEAD
``` |
37,737,098 | I have a string time coming from a third party (external to my python program), and I need to compare that time to right now. How long ago was that time?
How can I do this?
I've looked at the `datetime` and `time` libraries, as well as `pytz`, and can't find an obvious way to do this. It should automatically incorpor... | 2016/06/09 | [
"https://Stackoverflow.com/questions/37737098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6365333/"
] | Signing a commit will change the commit metadata, and thus change the underlying SHA1 commit ID. As you probably know, for Git, this has the same consequence of trying to change the contents of your history.
If you want to just re-sign your last commit you could run:
`git commit -S --amend`
If you want to re-sign a ... | If I had my branch created from master, I would use the following:
>
>
> ```
> git rebase --exec 'git commit --amend --no-edit -n -S' -i master
>
> ```
>
>
This command will detect all my commits on my branch and reapply them as signed commits on top of master. |
37,737,098 | I have a string time coming from a third party (external to my python program), and I need to compare that time to right now. How long ago was that time?
How can I do this?
I've looked at the `datetime` and `time` libraries, as well as `pytz`, and can't find an obvious way to do this. It should automatically incorpor... | 2016/06/09 | [
"https://Stackoverflow.com/questions/37737098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6365333/"
] | If you want to sign all the existing commits on the branch without do any changes to them:
```
git rebase --exec 'git commit --amend --no-edit -n -S' -i origin/HEAD
``` | If I had my branch created from master, I would use the following:
>
>
> ```
> git rebase --exec 'git commit --amend --no-edit -n -S' -i master
>
> ```
>
>
This command will detect all my commits on my branch and reapply them as signed commits on top of master. |
22,486,519 | I am trying to create a fabric script that will install the erlang solutions R15B02 package and am having some difficulty. I have the following code in my fabric script:
```
sudo("apt-get update")
sudo("apt-get -qy install python-software-properties")
sudo('add-apt-repository "deb http://packages.erlang-soluti... | 2014/03/18 | [
"https://Stackoverflow.com/questions/22486519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/232337/"
] | You can also use one of these projects for installing and managing different versions of Erlang on the same computer:
* <https://github.com/spawngrid/kerl>
* <https://github.com/metadave/erln8> | If you can find the file 'esl-erlang\_15.b.2-1~ubuntu~precise\_i386.deb' or the 64 bit version, those could be installed with dpkg. If you find these, to install both at once, extract the .deb with `dpkg -x esl-erlang_15.b.2-1~ubuntu~precise_i386.deb` and move the binaries inside somewhere else. If you can't find that ... |
68,076,036 | In my main directory I have two programs: `main.py` and a myfolder (which is a directory).
The `main.py` file has these 2 lines:
```
from myfolder import Adding
print(Adding.execute())
```
Inside the myfolder directory, I have 3 python files only: `__init__.py`, `abstract_math_ops.py`, and `adding.py`.
The `__ini... | 2021/06/22 | [
"https://Stackoverflow.com/questions/68076036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7705108/"
] | Your folder is a package, and you can't import sibling-submodules of a package in the way you're trying to do in `adding.py`. You either need to use an absolute import (`from myfolder.abstract_math_ops import AbstractMathOps`, which works the same anywhere), or use an explicit relative import (`from .abstract_math_ops ... | Try with:
```
from .abstract_math_ops import AbstractMathOps
```
You need to add the relative location of the file for the import to work in this case. |
51,156,919 | I'm currently reading a dummy.txt, the content showing as below:
```
8t1080 0.077500 0.092123 -0.079937
63mh9j 0.327872 -0.074191 -0.014623
63l2o3 0.504010 0.356935 -0.275896
64c97u 0.107409 0.021140 -0.000909
```
Now, I am reading it using python like below:
```
lines = open("dummy.txt", "r").readlines()
```
I w... | 2018/07/03 | [
"https://Stackoverflow.com/questions/51156919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8221657/"
] | You would greatly benefit from [`pandas`](https://pandas.pydata.org/) in this case:
```
import pandas as pd
df = pd.read_csv('dummy.txt', sep=' ', header=None)
>>> df.values
array([['8t1080', 0.0775, 0.092123, -0.079937],
['63mh9j', 0.327872, -0.074191, -0.014622999999999999],
['63l2o3', 0.50401000000... | In your first case it IS working, however each time the for loops the line variable is reset to the next value, and its current value is lost to recieve the next one.
```
aux=[]
for line in lines: #here the program changes the value of line
line = line.split() # here you change the value of line
for x in range... |
51,156,919 | I'm currently reading a dummy.txt, the content showing as below:
```
8t1080 0.077500 0.092123 -0.079937
63mh9j 0.327872 -0.074191 -0.014623
63l2o3 0.504010 0.356935 -0.275896
64c97u 0.107409 0.021140 -0.000909
```
Now, I am reading it using python like below:
```
lines = open("dummy.txt", "r").readlines()
```
I w... | 2018/07/03 | [
"https://Stackoverflow.com/questions/51156919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8221657/"
] | You just need a data structure to output to for the first example i.e.
```
data = []
lines = open("dummy.txt", "r").readlines()
for line in lines:
line = line.split()
for x in range(1, len(line)):
line[x] = float(line[x])
data.append(line)
```
The data list will contain what you want. | In your first case it IS working, however each time the for loops the line variable is reset to the next value, and its current value is lost to recieve the next one.
```
aux=[]
for line in lines: #here the program changes the value of line
line = line.split() # here you change the value of line
for x in range... |
43,113,717 | I have the text file like this
```
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : example.com
IPv6 Address. . . . . . . . . . . : xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
Temporary IPv6 Address. . . . . . : xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
Link-local IPv6 Address . . . . . : xxxx:xxxx:xxxx:xxx... | 2017/03/30 | [
"https://Stackoverflow.com/questions/43113717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3636467/"
] | yes, using @IdClass annotation.
```
@Entity
@IdClass(EmployeeKey.class)
public class Employee {
@Id
private int id;
@Id
private int departmendId;
}
public class EmployeeKey implements Serializable {
private int id;
private int departmendId;
}
public interface EmployeeRepository extends JpaReposit... | Even if the underlying table does not have an explicit primary key specified, I am sure there is at least one column that is defined as unique (or has a unique index specified for it).
You can add the @Id annotation to the entity field relevant to that column and that will the sufficient for the persistence provider.... |
30,625,787 | This might seem simple but it has flummoxed me for a day, so I'm turning to ya'll.
I have a valid Python dictionary:
```
{'numeric_int2': {'(113.7, 211.4]': 3,
'(15.023, 113.7]': 4,
'(211.4, 309.1]': 5,
'(309.1, 406.8]': 4,
'(406.8, 504.5]': 5,
'(504.5, 602.2]': 7,
'(602.2, 699.9]': 4,
'(699.9, 797.6]':... | 2015/06/03 | [
"https://Stackoverflow.com/questions/30625787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2935984/"
] | **it appears both simplejson and json work as expected to me**, however
simplejson is faster than json(by quite a bit) and it seems to work fine with your data
```
import simplejson,json
print simplejson.dumps({'numeric_int2': {'(113.7, 211.4]': 3,
'(15.023, 113.7]': 4,
'(211.4, 309.1]': 5,
'(309.1, 406.8]': 4,
'(406.... | Found the answer. Here is the function that works:
```
# Count the frequency of each value
def count_by_value(df,columns):
# Selects appropriate columns for the action
numeric = [c[0] for c in columns if c[1] == 'numeric']
# Returns 0 if none of the appropriate columns exists
if len(numeric) == 0:
... |
59,146,674 | I have a batch file which is running a python script and in the python script, I have a subprocess function which is being ran.
I have tried `subprocess.check_output`, `subprocess.run`, `subprocess.Popen`, all of them returns me an empty string only when running it using a batch file.
If I run it manually or using an... | 2019/12/02 | [
"https://Stackoverflow.com/questions/59146674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2865368/"
] | Updated
-------
First of all, if there is a need to run `anaconda-prompt` by calling `activate.bat` file, you can simply do as follows:
```
import subprocess
def call_anaconda_venv():
subprocess.call('python -m venv virtual.env')
subprocess.call('cmd.exe /k /path/venv/Scripts/activate.bat')
if __name__ == "... | This is happening because your ide is not running in a shell that works in the way that open subprocess is expecting.
If you set SHELL=False and specify the absolute path to the batch file it will run.
you might still need the cwd if the batch file requires it. |
34,339,867 | I am trying to match the following strings:
```
2 match virtual-address 172.29.210.119 tcp eq www
4 match virtual-address 172.29.210.147 tcp any
```
The expected output:
```
172.29.210.119
tcp
www
172.29.210.147
tcp
any
```
I am using pattern:
```
match virtual-address (\d+\.\d+\.\d+\.\d+)\s?(\w+)?... | 2015/12/17 | [
"https://Stackoverflow.com/questions/34339867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4611991/"
] | You can use this regex in Python:
```
\bmatch virtual-address (\d+\.\d+\.\d+\.\d+)\s?(\w+) (?:eq\s+)?(\w+)
```
[RegEx Demo](https://regex101.com/r/tX8mB2/1)
Python regex doesn't support *Atomic Group* syntax `(?>..)` like PCRE. | If you modify the flavor of regex101 for "python", you will see that you can not use `(?>eq)?`
An alternative to what you want is to use `$`, to assert position at end of a line. Using `(\w+)$` will catch the last of the string sentence.
```
import re
text = [
'2 match virtual-address 172.29.210.119 tcp eq www',... |
22,976,523 | I'm working on a small app that pulls data out of a list stored in a list, passes it through a class init, and then displays/allows user to work. Everything was going fine until i tried to format the original 'list' in the IDLE so it was easier to read (for me). so I'd change 9 to 09, 8 to 08. etc It was a simple forma... | 2014/04/10 | [
"https://Stackoverflow.com/questions/22976523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2584933/"
] | It's nothing to do with lists or strings. When you prefix a number with `0`, it's interpreted as [octal](http://en.wikipedia.org/wiki/Octal). And 9 is not a valid octal digit!
```
Python 2.7.6
Type "help", "copyright", "credits" or "license" for more information.
>>> 09
File "<stdin>", line 1
09
^
SyntaxEr... | It's not just Python, it's most programming languages. Starting a number with a zero signifies that the number is in octal, which means only digits `0-7` are valid. Thus,
```
5 == 05
6 == 06
7 == 07
8 == 010
9 == 011
...
15 == 017
16 == 020
...
255 == 0377
```
Similarly, prefix `0x` means the number is hexadecimal (... |
22,976,523 | I'm working on a small app that pulls data out of a list stored in a list, passes it through a class init, and then displays/allows user to work. Everything was going fine until i tried to format the original 'list' in the IDLE so it was easier to read (for me). so I'd change 9 to 09, 8 to 08. etc It was a simple forma... | 2014/04/10 | [
"https://Stackoverflow.com/questions/22976523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2584933/"
] | It's nothing to do with lists or strings. When you prefix a number with `0`, it's interpreted as [octal](http://en.wikipedia.org/wiki/Octal). And 9 is not a valid octal digit!
```
Python 2.7.6
Type "help", "copyright", "credits" or "license" for more information.
>>> 09
File "<stdin>", line 1
09
^
SyntaxEr... | This is because python interprets numbers with a `0` in front of them as octal, so saying `09` doesn't make much sense.
If you changed it for instance to the following:
```
a = ["ge", 07]
```
everything works fine. |
22,976,523 | I'm working on a small app that pulls data out of a list stored in a list, passes it through a class init, and then displays/allows user to work. Everything was going fine until i tried to format the original 'list' in the IDLE so it was easier to read (for me). so I'd change 9 to 09, 8 to 08. etc It was a simple forma... | 2014/04/10 | [
"https://Stackoverflow.com/questions/22976523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2584933/"
] | It's nothing to do with lists or strings. When you prefix a number with `0`, it's interpreted as [octal](http://en.wikipedia.org/wiki/Octal). And 9 is not a valid octal digit!
```
Python 2.7.6
Type "help", "copyright", "credits" or "license" for more information.
>>> 09
File "<stdin>", line 1
09
^
SyntaxEr... | This is because if the digit starts with a `0` it is considered an octal digit and octal digits are only from`0-7`
### Example
```
>>> 015 - 02 #which is obviously not what you'd expect for base10 integers
11
``` |
23,120,865 | Apologies if this is a basic question, but let us say I have a tab delimited file named `file.txt` formatted as follows:
```
Label-A [tab] Value-1
Label-B [tab] Value-2
Label-C [tab] Value-3
[...]
Label-i [tab] Value-n
```
I want [xlrd](https://pypi.python.org/pypi/xlrd) or [openpyxl](htt... | 2014/04/16 | [
"https://Stackoverflow.com/questions/23120865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3543052/"
] | Since you said you are used to working in Bash, I'm assuming you're using some kind of Unix/Linux, so here's something that will work on Linux.
Before pasting the code, I'd like to point a few things:
Working with Excel in Unix (and Python) is not that straightforward. For instance, you can't open an Excel sheet for ... | That's a job for VBA, but if I had to do it in Python I would do something like this:
```
import Excel
xl = Excel.ExcelApp(False)
wb = xl.app.Workbooks("MyWorkBook.xlsx")
wb.Sheets("Ass'y").Cells(1, 1).Value2 = "something"
wb.Save()
```
With an helper `Excel.py` class like this:
```
import win32com.client
class Ex... |
23,120,865 | Apologies if this is a basic question, but let us say I have a tab delimited file named `file.txt` formatted as follows:
```
Label-A [tab] Value-1
Label-B [tab] Value-2
Label-C [tab] Value-3
[...]
Label-i [tab] Value-n
```
I want [xlrd](https://pypi.python.org/pypi/xlrd) or [openpyxl](htt... | 2014/04/16 | [
"https://Stackoverflow.com/questions/23120865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3543052/"
] | Since you said you are used to working in Bash, I'm assuming you're using some kind of Unix/Linux, so here's something that will work on Linux.
Before pasting the code, I'd like to point a few things:
Working with Excel in Unix (and Python) is not that straightforward. For instance, you can't open an Excel sheet for ... | You should use the CSV module in the standard library to read the file.
In openpyxl you can have something like this:
```
from openpyxl import load_workbook
wb = load_workbook('workbook.xlsx')
ws = wb[sheetname]
for idx, line in enumerate(csvfile):
ws.cell(row=idx, column=0) = line[0]
ws.cell(row=idx, column=... |
2,830,953 | I have a script which contains two classes. (I'm obviously deleting a lot of stuff that I don't believe is relevant to the error I'm dealing with.) The eventual task is to create a decision tree, as I mentioned in [this](https://stackoverflow.com/questions/2726167/parse-a-csv-file-using-python-to-make-a-decision-tree-l... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2830953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27290/"
] | This is fairly easy.
```
var timerID;
$("#left").hover(function() {
timerID = setInterval(slideLeft, 1000);
}, function() {
clearInterval(timerID);
});
function slideLeft() {
$("#slider").animate({left: -30});
}
```
and similar for right.
You only need to use `hover()` if there's something you need to stop w... | You don't have to check where the mouse is, as the `mouseout` event will be triggered when the mouse leaves the element.
To make the movement repeat while the mouse is hovering the element, start an interval that you stop when the mouse leaves the element:
```
$(function(){
var moveInterval;
$('#moveLeft').hove... |
69,512,596 | I've recently started learning how to code in python. I wanted to know if there is a norm or specific rule for the position of statements while using functions.
eg:
```
def example(x):
y = 7
print("Default value is", y)
print("Value entered is", x)
a = int(input("Enter a value: "))
example(a)
```
Would... | 2021/10/10 | [
"https://Stackoverflow.com/questions/69512596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17117924/"
] | In larger programs, pretty much everything will be in functions (or methods, which are a kind of function). The only code at the top level will be a couple of lines to call the first function (often called `main`).
The question then is whether to put the `input` into the same function, or into separate functions. That... | If the result of input statement will only be used inside one function, then moving the statement into that function might be better in the future when your code becomes more complex |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | I would try to replicate the Django application functionality with the [PyQt toolkit](http://www.riverbankcomputing.co.uk/software/pyqt/intro).
You can in fact embed web content in PyQt applications, with the help of QtWebKit. I would post some potentially useful links, but apparently I have too low a reputation to po... | I have `django manage.py runserver` in .bat file and a localhost bookmark bar in a browser and whola a django-desktop-app. Or make your own browser that opens localhost. [Creating a web-browser with Python and PyQT](https://pythonspot.com/creating-a-webbrowser-with-python-and-pyqt-tutorial/) |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | I think you should just create an application that connects to the webserver. There is a good answer to getting RESTful API calls into your django application. This means you'd basically just be creating a new front-end for your server.
[Using django-rest-interface](https://stackoverflow.com/questions/212941/using-dja... | I am thinking about a similar Problem.
Would it be enough to habe a minimal PyQt Gui that enables you to present the djando-website from localhost (get rid of TCP/HTTPS on loop interface somehow) via QtWebkit?
All you seem to need is to have a minimal Python-Broser, that surfs the build in Webserver (and i guess you ... |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | I would try to replicate the Django application functionality with the [PyQt toolkit](http://www.riverbankcomputing.co.uk/software/pyqt/intro).
You can in fact embed web content in PyQt applications, with the help of QtWebKit. I would post some potentially useful links, but apparently I have too low a reputation to po... | I am thinking about a similar Problem.
Would it be enough to habe a minimal PyQt Gui that enables you to present the djando-website from localhost (get rid of TCP/HTTPS on loop interface somehow) via QtWebkit?
All you seem to need is to have a minimal Python-Broser, that surfs the build in Webserver (and i guess you ... |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | There are two places you can go to try to decouple the view and put it into a new desktop app. First you can use the existing controller and model and adapt a new view to that. Second, you can use only the existing model and build a new view and controller.
If you haven't adhered closely enough to the MVC principles ... | There's a project called [Camelot](http://www.python-camelot.com/) which seems to try to combine Django-like features on the desktop using PyQt. Haven't tried it though. |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | For starters, you'll have to replace the web UI with a desktop technology like Tk/Tcl.
If you do that, you may not want to use HTTP as the protocol between the client and the services.
Django is a web framework. If you're switching to a desktop, you'll have to forego Django. | It is possible to convert a django application to a desktop app with pywebview with some line of codes. Frist create a python file gui.py in directory where manage.py exists. install pywebview through pip, the write the code in gui.py
```
import os
import sys
import time
from threading import Thread
import webview
de... |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | For starters, you'll have to replace the web UI with a desktop technology like Tk/Tcl.
If you do that, you may not want to use HTTP as the protocol between the client and the services.
Django is a web framework. If you're switching to a desktop, you'll have to forego Django. | There's a project called [Camelot](http://www.python-camelot.com/) which seems to try to combine Django-like features on the desktop using PyQt. Haven't tried it though. |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | I would try to replicate the Django application functionality with the [PyQt toolkit](http://www.riverbankcomputing.co.uk/software/pyqt/intro).
You can in fact embed web content in PyQt applications, with the help of QtWebKit. I would post some potentially useful links, but apparently I have too low a reputation to po... | There are two places you can go to try to decouple the view and put it into a new desktop app. First you can use the existing controller and model and adapt a new view to that. Second, you can use only the existing model and build a new view and controller.
If you haven't adhered closely enough to the MVC principles ... |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | I think you should just create an application that connects to the webserver. There is a good answer to getting RESTful API calls into your django application. This means you'd basically just be creating a new front-end for your server.
[Using django-rest-interface](https://stackoverflow.com/questions/212941/using-dja... | I have `django manage.py runserver` in .bat file and a localhost bookmark bar in a browser and whola a django-desktop-app. Or make your own browser that opens localhost. [Creating a web-browser with Python and PyQT](https://pythonspot.com/creating-a-webbrowser-with-python-and-pyqt-tutorial/) |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | It is possible to convert a django application to a desktop app with pywebview with some line of codes. Frist create a python file gui.py in directory where manage.py exists. install pywebview through pip, the write the code in gui.py
```
import os
import sys
import time
from threading import Thread
import webview
de... | I have `django manage.py runserver` in .bat file and a localhost bookmark bar in a browser and whola a django-desktop-app. Or make your own browser that opens localhost. [Creating a web-browser with Python and PyQT](https://pythonspot.com/creating-a-webbrowser-with-python-and-pyqt-tutorial/) |
4,646,659 | How to convert the web site develpoed in django, python into desktop application.
I am new to python and django can you please help me out
Thanks in Advance | 2011/01/10 | [
"https://Stackoverflow.com/questions/4646659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/569806/"
] | For starters, you'll have to replace the web UI with a desktop technology like Tk/Tcl.
If you do that, you may not want to use HTTP as the protocol between the client and the services.
Django is a web framework. If you're switching to a desktop, you'll have to forego Django. | I have `django manage.py runserver` in .bat file and a localhost bookmark bar in a browser and whola a django-desktop-app. Or make your own browser that opens localhost. [Creating a web-browser with Python and PyQT](https://pythonspot.com/creating-a-webbrowser-with-python-and-pyqt-tutorial/) |
11,170,478 | I have a command line program developed in c. Lets say, i have a parser written in C. Now i am developing a project with gui in python and i need that parser for python project. In c we can invoke a system call and redirect the output to system.out or a file. Is there are any way to do this python? I have both code and... | 2012/06/23 | [
"https://Stackoverflow.com/questions/11170478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1135245/"
] | I would not expect MySQL to give that error message, but many other databases do. In other databases you can work around it by repeating the column definition:
```
SELECT amount1 + amount2 as totalamount
FROM Donation
WHERE amount1 + amount2 > 1000
```
Or you can use a subquery to avoid the repitition:
```
S... | No way.
**WHERE** filters column while **HAVING** filters on aggregates.
See [SQL Having](http://www.w3schools.com/sql/sql_having.asp) |
11,170,478 | I have a command line program developed in c. Lets say, i have a parser written in C. Now i am developing a project with gui in python and i need that parser for python project. In c we can invoke a system call and redirect the output to system.out or a file. Is there are any way to do this python? I have both code and... | 2012/06/23 | [
"https://Stackoverflow.com/questions/11170478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1135245/"
] | I would not expect MySQL to give that error message, but many other databases do. In other databases you can work around it by repeating the column definition:
```
SELECT amount1 + amount2 as totalamount
FROM Donation
WHERE amount1 + amount2 > 1000
```
Or you can use a subquery to avoid the repitition:
```
S... | Depending on the SQL dialect you can't put a derived column in the where clause.
Instead use this where clause.
```
WHERE (amount1 + amount2) > 1000
``` |
11,170,478 | I have a command line program developed in c. Lets say, i have a parser written in C. Now i am developing a project with gui in python and i need that parser for python project. In c we can invoke a system call and redirect the output to system.out or a file. Is there are any way to do this python? I have both code and... | 2012/06/23 | [
"https://Stackoverflow.com/questions/11170478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1135245/"
] | I would not expect MySQL to give that error message, but many other databases do. In other databases you can work around it by repeating the column definition:
```
SELECT amount1 + amount2 as totalamount
FROM Donation
WHERE amount1 + amount2 > 1000
```
Or you can use a subquery to avoid the repitition:
```
S... | I suggest you use one of the variations in Andomar's answer.
What MySQL allows is this (don't use it, it's not standard and almost any other DBMS does NOT allow it):
```
SELECT (amount1 + amount2) AS totalamount
FROM Donation
HAVING totalamount > 1000 ;
``` |
6,418,199 | I was looking up the pypy project (Python in Python), and started pondering the issue of what is running the outer layer of python? Surely, I conjectured, it can't be as the old saying goes "turtles all the way down"! Afterall, python is not valid x86 assembly!
Soon I remembered the concept of bootstrapping, and look... | 2011/06/20 | [
"https://Stackoverflow.com/questions/6418199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/322900/"
] | >
> In the interest of performance, I'm sure C compilers are just built up from assembly.
>
>
>
C compilers are, nowadays, (almost?) completely written in C (or higher-level languages - Clang is C++, for instance). Compilers gain little to nothing from including hand-written assembly code. The things that take mo... | If you buy a new machine with a pre-installed OS, it doesn't even need to include a compiler anywhere, because all the executable code has been compiled on some other machine, by whoever provides the OS - your machine doesn't need to compile anything itself.
How do you get to this point if you have a completely new CP... |
6,418,199 | I was looking up the pypy project (Python in Python), and started pondering the issue of what is running the outer layer of python? Surely, I conjectured, it can't be as the old saying goes "turtles all the way down"! Afterall, python is not valid x86 assembly!
Soon I remembered the concept of bootstrapping, and look... | 2011/06/20 | [
"https://Stackoverflow.com/questions/6418199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/322900/"
] | >
> Say I buy a new cpu with nothing on it. During the first operation I wish to install an OS, which runs C. What runs the C compiler? Is there a miniature C compiler in the BIOS?
>
>
>
I understand what you're asking... what would happen if we had no C compiler and had to start from scratch?
The answer is you'... | If you buy a new machine with a pre-installed OS, it doesn't even need to include a compiler anywhere, because all the executable code has been compiled on some other machine, by whoever provides the OS - your machine doesn't need to compile anything itself.
How do you get to this point if you have a completely new CP... |
6,418,199 | I was looking up the pypy project (Python in Python), and started pondering the issue of what is running the outer layer of python? Surely, I conjectured, it can't be as the old saying goes "turtles all the way down"! Afterall, python is not valid x86 assembly!
Soon I remembered the concept of bootstrapping, and look... | 2011/06/20 | [
"https://Stackoverflow.com/questions/6418199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/322900/"
] | >
> Say I buy a new cpu with nothing on it. During the first operation I wish to install an OS, which runs C. What runs the C compiler? Is there a miniature C compiler in the BIOS?
>
>
>
I understand what you're asking... what would happen if we had no C compiler and had to start from scratch?
The answer is you'... | >
> In the interest of performance, I'm sure C compilers are just built up from assembly.
>
>
>
C compilers are, nowadays, (almost?) completely written in C (or higher-level languages - Clang is C++, for instance). Compilers gain little to nothing from including hand-written assembly code. The things that take mo... |
37,959,217 | I'm using PM2 to run a Python program in the background like so
`pm2 start helloworld.py`
and it works perfectly fine. However, within `helloworld.py` I have several print statements that act as logs. For example, when a network request comes in or if a database value is updated. When I run `helloworld.py` like so:
... | 2016/06/22 | [
"https://Stackoverflow.com/questions/37959217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/896112/"
] | This question is a few months old, so maybe you figured this out a while ago, but it was one of the top google hits when I was having the same problem so I thought I'd add what I found.
Seems like it's an issue with how python buffers sys.stdout. In some platforms/instances, when called by say pm2 or nohup, the sys.st... | Check the folder #HOME/.pm2/logs
See for example the folder structure section here: <http://pm2.keymetrics.io/docs/usage/quick-start/>
Also consider using a configuration file with an explicit logs folder that is relative to your scripts. (Note this folder must exist before pm2 can use it.) See <http://pm2.keymetrics... |
41,247,600 | For the following two dataframes:
```
df1 = pd.DataFrame({'name': pd.Series(["A", "B", "C"]), 'value': pd.Series([1., 2., 3.])})
name value
0 A 1.0
1 B 2.0
2 C 3.0
df2 = pd.DataFrame({'name': pd.Series(["A", "C", "D"]), 'value': pd.Series([1., 3., 5.])})
name value
0 A 1.0
1 C... | 2016/12/20 | [
"https://Stackoverflow.com/questions/41247600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4424484/"
] | You can use [`isin`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html):
```
print (df2[df2["name"].isin(df1["name"])])
name value
0 A 1.0
1 C 3.0
```
Another faster solution with [`numpy.intersect1d`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.intersect1d.h... | Slightly different method that might be useful on your actual data, you could use an "inner join" (the intersection) a la SQL. More useful if your columns aren't duplicated in both data frames (e.g. merging two different data sets with some common key)
```
df1 = pd.DataFrame({'name': pd.Series(["A", "B", "C"]), 'value... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.