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 |
|---|---|---|---|---|---|
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | Have you tried [Pyglet](http://www.pyglet.org/) with [PyOpenGL](http://pyopengl.sourceforge.net/)? The two goes very well together. Wheaties' suggest is quite good as well, although [PyOgre](http://www.ogre3d.org/wiki/index.php/PyOgre) also has a steep learning curve, as it is indeed higher-level. On another thought, t... | I have no personal experience with this, but I have heard some decent things about [Pyglet](http://www.pyglet.org/index.html) |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | You could try mlab / Mayavi (a wrapper for VTK). There's some examples here: <http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html> | I have no personal experience with this, but I have heard some decent things about [Pyglet](http://www.pyglet.org/index.html) |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | [Panda3D](http://www.panda3d.org/) seems to be a nice 3D graphics library designed to be used in Python, although it's mostly game oriented. I've browsed the manuals a few times and it's very polished and of a high quality, it has even been used in some big studio's games (like Disney's Pirates of the Caribbean online,... | I have no personal experience with this, but I have heard some decent things about [Pyglet](http://www.pyglet.org/index.html) |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | Have you tried [Pyglet](http://www.pyglet.org/) with [PyOpenGL](http://pyopengl.sourceforge.net/)? The two goes very well together. Wheaties' suggest is quite good as well, although [PyOgre](http://www.ogre3d.org/wiki/index.php/PyOgre) also has a steep learning curve, as it is indeed higher-level. On another thought, t... | You could try mlab / Mayavi (a wrapper for VTK). There's some examples here: <http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html> |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | Have you tried [Pyglet](http://www.pyglet.org/) with [PyOpenGL](http://pyopengl.sourceforge.net/)? The two goes very well together. Wheaties' suggest is quite good as well, although [PyOgre](http://www.ogre3d.org/wiki/index.php/PyOgre) also has a steep learning curve, as it is indeed higher-level. On another thought, t... | I used openGL with C++ a few years back - found it quite low level. I also have used Java3D which seemed to be a bit higher level. If you are not stuck on using python - try Java3D - very simple to get up and running. |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | You could try mlab / Mayavi (a wrapper for VTK). There's some examples here: <http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html> | I used openGL with C++ a few years back - found it quite low level. I also have used Java3D which seemed to be a bit higher level. If you are not stuck on using python - try Java3D - very simple to get up and running. |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | [Panda3D](http://www.panda3d.org/) seems to be a nice 3D graphics library designed to be used in Python, although it's mostly game oriented. I've browsed the manuals a few times and it's very polished and of a high quality, it has even been used in some big studio's games (like Disney's Pirates of the Caribbean online,... | You could try mlab / Mayavi (a wrapper for VTK). There's some examples here: <http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html> |
2,823,907 | I am looking for a graphics library for 3D reconstruction research to develop my specific viewer based on some library. OpenGL seems in a low level and I have to remake the wheel everywhere. And I also tried VTK(visualization toolkit). However, it seems too abstract that I need to master many conceptions before I start... | 2010/05/13 | [
"https://Stackoverflow.com/questions/2823907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166482/"
] | [Panda3D](http://www.panda3d.org/) seems to be a nice 3D graphics library designed to be used in Python, although it's mostly game oriented. I've browsed the manuals a few times and it's very polished and of a high quality, it has even been used in some big studio's games (like Disney's Pirates of the Caribbean online,... | I used openGL with C++ a few years back - found it quite low level. I also have used Java3D which seemed to be a bit higher level. If you are not stuck on using python - try Java3D - very simple to get up and running. |
21,327,768 | Note: I was using the wrong source file for my data - once that was fixed, my issue was resolved. It turns out, there is no simple way to use `int(..)` on a string that is not an integer literal.
This is an example from the book "Machine Learning In Action", and I cannot quite figure out what is wrong. Here's some bac... | 2014/01/24 | [
"https://Stackoverflow.com/questions/21327768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1884158/"
] | strings like "largeDoses" could not be converted to integers. In folder `Ch02` of [that code project](https://github.com/pbharrin/machinelearninginaction), you have two data files, use the second one `datingTestSet2.txt` instead of loading the first | You can use [ast.literal\_eval](http://docs.python.org/2/library/ast.html#ast.literal_eval) and catch the exception ValueError the malformed string (by the way int('9.4') will raise an exception) |
60,490,195 | I am trying to write a small program using the AzureML Python SDK (v1.0.85) to register an Environment in AMLS and use that definition to construct a local Conda environment when experiments are being run (for a pre-trained model). The code works fine for simple scenarios where all dependencies are loaded from Conda/ p... | 2020/03/02 | [
"https://Stackoverflow.com/questions/60490195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9821873/"
] | The issue was with out firewall blocking the required requests between AMLS and the storage container (I presume to get the environment definitions/ private wheels).
We resolved this by updating the firewall with appropriate ALLOW rules for the AMLS service to contact and read from the attached storage container. | Assuming that you'd like to run in the script on a remote compute, then my suggestion would be to pass the environment you just "got". to a `RunConfiguration`, then pass that to an `ScriptRunConfig`, `Estimator`, or a `PythonScriptStep`
```py
from azureml.core import ScriptRunConfig
from azureml.core.runconfig import ... |
1,419,416 | please, could someone explain to me a few basic things about working with languages like C? Especially on Windows?
1. If I want to use some other library, what do I need from the library? Header files .h and ..?
2. What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?
3. Does it ... | 2009/09/14 | [
"https://Stackoverflow.com/questions/1419416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166939/"
] | >
> 1: If I want to use some other library, what do I need from the library? Header files .h and ..?
>
>
>
... and, usually a `*.lib` file which you pass as an argument to your linker.
>
> 2: What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?
>
>
>
This might be usef... | In all seriousness, the place to go to learn how to run your local environment is the documentation for your local environment. After all we on not even know exactly what your environment *is*, much less have it in front of us.
But here are some answers:
`1.` You need the headers, and a linkable object of some kind. ... |
1,419,416 | please, could someone explain to me a few basic things about working with languages like C? Especially on Windows?
1. If I want to use some other library, what do I need from the library? Header files .h and ..?
2. What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?
3. Does it ... | 2009/09/14 | [
"https://Stackoverflow.com/questions/1419416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166939/"
] | *If I want to use some other library, what do I need from the library? Header files .h and ..?*
You need header .h or .hpp for C,C++ although some languages don't require header files. You'll also need .a, .so, .dll, .lib, .jar etc files. These files contain the machine code that you linker can link into your program.... | In all seriousness, the place to go to learn how to run your local environment is the documentation for your local environment. After all we on not even know exactly what your environment *is*, much less have it in front of us.
But here are some answers:
`1.` You need the headers, and a linkable object of some kind. ... |
1,419,416 | please, could someone explain to me a few basic things about working with languages like C? Especially on Windows?
1. If I want to use some other library, what do I need from the library? Header files .h and ..?
2. What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?
3. Does it ... | 2009/09/14 | [
"https://Stackoverflow.com/questions/1419416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/166939/"
] | >
> 1: If I want to use some other library, what do I need from the library? Header files .h and ..?
>
>
>
... and, usually a `*.lib` file which you pass as an argument to your linker.
>
> 2: What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?
>
>
>
This might be usef... | *If I want to use some other library, what do I need from the library? Header files .h and ..?*
You need header .h or .hpp for C,C++ although some languages don't require header files. You'll also need .a, .so, .dll, .lib, .jar etc files. These files contain the machine code that you linker can link into your program.... |
20,303,558 | Coming from this link: [Splitlines in Python a table with empty spaces](https://stackoverflow.com/questions/20252728/splitlines-in-python-a-table-with-empty-spaces)
It works well but there is a problem when the size of the columns change:
```
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init... | 2013/11/30 | [
"https://Stackoverflow.com/questions/20303558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2898827/"
] | I did a bit of reading on `lsof -F` after checking out the other thread and found that it does produce easily parsed output. Here's a quick demonstration of the general idea. It parses that and prints a small subset of the parsed output to show format. Are you able to use `-F` for your use case?
```
import subprocess
... | As [@Tim Wilder said](https://stackoverflow.com/a/20304501/4279), you could use `lsof -F` to get machine-readable output. Here's a script that converts `lsof` output into json. One json object per line. It produces output as soon as pipe buffers are full without waiting for the whole `lsof` process to end (it takes a w... |
35,196,449 | I am writing script supporting my Django project development. First I thought of using bash for this purpose but due to lack of enough knowledge and total lack of time I decided to write something using argparse and running system commands using subprocess.
Everything went ok until I had to run
```
./manage.py migrat... | 2016/02/04 | [
"https://Stackoverflow.com/questions/35196449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1844201/"
] | This is not impossible, but it is a bad idea - it's very tricky to get right.
Instead, you want to separate the business logic from the UI, so that you can do the logic in the background, while the UI is still on the UI thread. The key is that you must not modify the UI controls from the background thread - instead, y... | WPF does not allow you to change UI from the background thread. Only ONE SINGLE thread can handle UI thread. Instead, you should calculate your data in the background thread, and then call `Application.Current.Dispatcher.Invoke(...)` method to update the UI. For example:
```
Application.Current.Dispatcher.Invoke(() =>... |
36,811,332 | I'm having some trouble create a table using values from a text file. My text file looks like this:
```
e432,6/5/3,6962,c8429,A,4324
e340,2/3/5,566623,c1210,A,3201
e4202,6/5/3,4232,c8419,E,4232
e3230,2/3/5,66632,c1120,A,53204
e4202,6/5/3,61962,c8429,A,4322
```
I would like to generate a table containing arrays where... | 2016/04/23 | [
"https://Stackoverflow.com/questions/36811332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5854201/"
] | AFAIK, neither JavaScript nor TypeScript provide a generic hashing function.
You have to import a third-party lib, like [ts-md5](https://www.npmjs.com/package/ts-md5) for instance, and give it a string representation of your object: `Md5.hashStr(JSON.stringify(yourObject))`.
Obviously, depending on your precise use ... | If you want to compare the objects and not the data, then the @Valery solution is not for you, as it will compare the data and not the two objects.
If you want to compare the data and not the objects, then JSON.stringify(obj1) === JSON.stringify(obj2) is enough, which is simple string comparison. |
36,811,332 | I'm having some trouble create a table using values from a text file. My text file looks like this:
```
e432,6/5/3,6962,c8429,A,4324
e340,2/3/5,566623,c1210,A,3201
e4202,6/5/3,4232,c8419,E,4232
e3230,2/3/5,66632,c1120,A,53204
e4202,6/5/3,61962,c8429,A,4322
```
I would like to generate a table containing arrays where... | 2016/04/23 | [
"https://Stackoverflow.com/questions/36811332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5854201/"
] | AFAIK, neither JavaScript nor TypeScript provide a generic hashing function.
You have to import a third-party lib, like [ts-md5](https://www.npmjs.com/package/ts-md5) for instance, and give it a string representation of your object: `Md5.hashStr(JSON.stringify(yourObject))`.
Obviously, depending on your precise use ... | For non-crypto uses, like implementing a hash table, here is is the typescript of the venerable java hashCode of a string:
```
export function hashCode(str: string): number {
var h: number = 0;
for (var i = 0; i < str.length; i++) {
h = 31 * h + str.charCodeAt(i);
}
return h & 0xFFFFFFFF
}
``` |
25,960,754 | ```
ImportError at /
cannot import name views
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7
Exception Type: ImportError
Exception Value:
cannot import name views
Exception Location: /Users/adam/Desktop/qblog/qblog/urls.py in <module>, line 1
Python Executable: /... | 2014/09/21 | [
"https://Stackoverflow.com/questions/25960754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1779600/"
] | There is no need to import the views in your project-level file. You are not using them there, so no reason to import them.
If you *did* need to, you would just to `from blog import views`, because the views are in the blog directory and manage.py puts the top-level directory into the Python path. | You can just use `import views`.This works for me |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | In order to use the python package you need the dependencies first. For mac you can just use `brew install ta-lib` and then `pip install TA-Lib` will work just fine. | I faced the same problems trying with Anaconda 5.1.0 and Python 3.6 via Visual Studio.
The solution was to get a wheel from <https://www.lfd.uci.edu/~gohlke/pythonlibs>, then install it via pip. You need to make sure the wheel matches your python version (in my case, 3.6).
In Anaconda, I just opened a prompt, naviga... |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | I faced the same problems trying with Anaconda 5.1.0 and Python 3.6 via Visual Studio.
The solution was to get a wheel from <https://www.lfd.uci.edu/~gohlke/pythonlibs>, then install it via pip. You need to make sure the wheel matches your python version (in my case, 3.6).
In Anaconda, I just opened a prompt, naviga... | Install an updated **Microsoft visual c++ Redistributable for Visual Studio 2015, 2017 and 2019**:
<https://support.microsoft.com/he-il/help/2977003/the-latest-supported-visual-c-downloads>
worked for me.. |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | Download `ta-lib-0.4.0-msvc.zip` from <http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-msvc.zip> and unzip to `C:\ta-lib`
This is a 32-bit release. If you want to use 64-bit Python, you will need to build a 64-bit version of the library.
Some unofficial (and unsupported) instructions for building on 64-bit Win... | Download related package from
<https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib>
```
TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl (Since I have python 3.6, cp36)
```
and use
```
pip install TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl
``` |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | Download related package from
<https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib>
```
TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl (Since I have python 3.6, cp36)
```
and use
```
pip install TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl
``` | Install an updated **Microsoft visual c++ Redistributable for Visual Studio 2015, 2017 and 2019**:
<https://support.microsoft.com/he-il/help/2977003/the-latest-supported-visual-c-downloads>
worked for me.. |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | Download related package from
<https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib>
```
TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl (Since I have python 3.6, cp36)
```
and use
```
pip install TA_Lib‑0.4.17‑cp36‑cp36m‑win_amd64.whl
``` | Had to spend good amount of time even with so many people facing the same issue. Long story short WINDOWS \*\*\*T. I am on Windows 10 running python3.7
Enough of ranting here are the steps that worked for me
1. Install Visual C++ Build tools (<https://www.youtube.com/watch?v=P4_R34Lb-PE>)
<https://visualstudio.micros... |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | you can proceed as follows:
1. Go to the following page: [https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib](https://www.lfd.uci.edu/%7Egohlke/pythonlibs/#ta-lib)
Choose your version of python: `cp35` means Python 3.5 (64 bit for example)
2. Download the package and unzip in `...\Python\Python35\Scripts`
3. Go on `c... | Had to spend good amount of time even with so many people facing the same issue. Long story short WINDOWS \*\*\*T. I am on Windows 10 running python3.7
Enough of ranting here are the steps that worked for me
1. Install Visual C++ Build tools (<https://www.youtube.com/watch?v=P4_R34Lb-PE>)
<https://visualstudio.micros... |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | The following solved the issue I had installing ta-lib for Python:
1. OS: Windows 10
Python: 2.7, embedded in [miniconda](https://conda.io/miniconda).
Miniconda: 64 bits.
[PyCharm](https://www.jetbrains.com/pycharm/) 2018.1.4 Community Edition.
2. You need to convert ta-lib to 64 bits. You can find it already converte... | From everything that I have tried, the simplest way to solve this was more obvious than it looked based on previous answers. Run the following command on your conda terminal:
```
conda install -c conda-forge ta-lib
```
Make sure you are running this command on the desired environment. |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | Download `ta-lib-0.4.0-msvc.zip` from <http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-msvc.zip> and unzip to `C:\ta-lib`
This is a 32-bit release. If you want to use 64-bit Python, you will need to build a 64-bit version of the library.
Some unofficial (and unsupported) instructions for building on 64-bit Win... | From everything that I have tried, the simplest way to solve this was more obvious than it looked based on previous answers. Run the following command on your conda terminal:
```
conda install -c conda-forge ta-lib
```
Make sure you are running this command on the desired environment. |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | In order to use the python package you need the dependencies first. For mac you can just use `brew install ta-lib` and then `pip install TA-Lib` will work just fine. | From everything that I have tried, the simplest way to solve this was more obvious than it looked based on previous answers. Run the following command on your conda terminal:
```
conda install -c conda-forge ta-lib
```
Make sure you are running this command on the desired environment. |
41,155,985 | Frustratingly having a lot of difficult installing the TA-Lib package in python.
<https://pypi.python.org/pypi/TA-Lib>
I have read through all the forum posts I can find on this but no such luck for my particular problem..
Windows 10
Python 3.5.2
Anaconda 4.2.0
Cython 0.24.1
Microsoft Visual Studio 14.0
I have d... | 2016/12/15 | [
"https://Stackoverflow.com/questions/41155985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273219/"
] | From <https://github.com/mrjbq7/ta-lib>:
'This typically means that it can't find the underlying TA-Lib library, a dependency which needs to be installed.'
Install the underlying TA-Lib library first from here:
<https://www.ta-lib.org/hdr_dw.html>
I used the 'ta-lib-0.4.0-msvc.zip' one.
Then download a whl file fr... | Install an updated **Microsoft visual c++ Redistributable for Visual Studio 2015, 2017 and 2019**:
<https://support.microsoft.com/he-il/help/2977003/the-latest-supported-visual-c-downloads>
worked for me.. |
31,091,104 | I am using a PHP server at the back end and a basic web page which asks the user to upload an image. This image is used as an input to a MATLAB script to be executed on the server side.
What I need is something like a MATLAB session(not clear on that word) that is already running on the server side which runs the MATL... | 2015/06/27 | [
"https://Stackoverflow.com/questions/31091104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3159395/"
] | There exist multiple interfaces to control matlab. Probably best choice for this case is [matlabcontrol](https://code.google.com/p/matlabcontrol/) or the matlab engine for python (which you can't use for some reason). On windows a third alternative would be com.
Besides controlling the matlab process, you could implem... | There is an API for C++ where you call the Matlab engine using engOpen. This will open Matlab and leave it running until you close it. Then your C++ program can wait and listen for the image to process.
<http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html>
Another option is t... |
31,091,104 | I am using a PHP server at the back end and a basic web page which asks the user to upload an image. This image is used as an input to a MATLAB script to be executed on the server side.
What I need is something like a MATLAB session(not clear on that word) that is already running on the server side which runs the MATL... | 2015/06/27 | [
"https://Stackoverflow.com/questions/31091104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3159395/"
] | You could write Matlab code to check the upload folder for new images regularly. Process new images and then move the processed images to an archive folder.
To check for new files use `dir` command
```
FILES = dir(['path/to/upload/folder/*.PNG']);
```
Replace PNG extension with that of your image files.
To move fi... | There is an API for C++ where you call the Matlab engine using engOpen. This will open Matlab and leave it running until you close it. Then your C++ program can wait and listen for the image to process.
<http://www.mathworks.com/help/matlab/calling-matlab-engine-from-c-c-and-fortran-programs.html>
Another option is t... |
24,518,868 | I am looking at the bencode specification and I am writing a C++ port of the deluge bit-torrent client's bencode implementation (written in python).
The Python implementation includes a dictionary of { data\_types : callback\_functions } by which a function wrapper easily selects which encoding function to use by a dic... | 2014/07/01 | [
"https://Stackoverflow.com/questions/24518868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3795241/"
] | A primer on templates
---------------------
C++, in contrast to the dynamic Python, is a **statically typed language**. What this means is that the types of objects are known at compile time (more on the differences [here](https://stackoverflow.com/a/1517670/2567683)).
A way to generalize code in C++ is templates, w... | What you're seeing here is not a parent-child relationship as in normal inheritance, it's a [specialization](http://en.cppreference.com/w/cpp/language/template_specialization). The template defines the default implementation, and the specializations replace that implementation for parameters that match the specific typ... |
49,342,652 | I have a Django Web-Application that uses celery in the background for periodic tasks.
Right now I have three docker images
* one for the django application
* one for celery workers
* one for the celery scheduler
whose `Dockerfile`s all look like this:
```
FROM alpine:3.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
W... | 2018/03/17 | [
"https://Stackoverflow.com/questions/49342652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/376172/"
] | I will suggest to use one Dockerfile and just update your CMD during runtime. Litle bit modification will work for both local and Heroku as well.
As far Heroku is concern they provide environment variable to start container with the environment variable.
[heroku set-up-your-local-environment-variables](https://devcent... | I would recommend looking at [docker-compose](https://docs.docker.com/compose/) to simplify management of multiple containers.
Use a single Dockerfile like the one you posted above, then create a `docker-compose.yml` that might look something like this:
```
version: '3'
services:
# a django service serving an appli... |
61,882,562 | I'm trying to access to my Api rest that I released in Heroku with docker and see that Dynos is running the gunicorn command that I put in the Dockerfile.
The Dockerfile that I used is:
```
FROM ubuntu:18.04
RUN apt update
RUN apt install -y python3 python3-pip
RUN mkdir /opt/app
ENV PYTHONUNBUFFERED 1
ENV LANG C.UT... | 2020/05/19 | [
"https://Stackoverflow.com/questions/61882562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13039952/"
] | @jhaos mentioned gunicorn was running in the root path
Change the following in `Dockerfile`
```
RUN mkdir /opt/app to WORKDIR /opt/app
COPY Ski4All/ /opt/app/ to COPY Ski4All .
``` | The problem was that the gunicorn command was running in the / root path and not in the correct workdir. In the comments @HariHaraSuhan solved the error. |
12,183,763 | I am following the tutorial for deploying a django project on AWS elastic beanstalk here:
<http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html>
My app works when I test locally but when I deploy, I'm getting a 404 error. Looking at the event logs, I see this message:
`Error r... | 2012/08/29 | [
"https://Stackoverflow.com/questions/12183763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/656707/"
] | I believe you don't need to put container\_commands in .config because there is no database or table at this moment. | I followed the same tutorial recently and had a similar result.
At step 6, upon seeing the default django 'congrats' page render locally, I deployed to EB as instructed and got a 404 instead of the default 'congrats' page.
I decided to use the code up to that point as a foundation for following the '[getting starte... |
12,183,763 | I am following the tutorial for deploying a django project on AWS elastic beanstalk here:
<http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html>
My app works when I test locally but when I deploy, I'm getting a 404 error. Looking at the event logs, I see this message:
`Error r... | 2012/08/29 | [
"https://Stackoverflow.com/questions/12183763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/656707/"
] | Did you made the step?: Freeze the requirements.txt file.
```
(djangodev)# pip freeze > requirements.txt
```
Note
Make sure your requirements.txt file contains the following:
```
Django==1.4.1
MySQL-python==1.2.3
```
I had the same problem because I skipped it. Once I did it, add, commit and push. It works! | I followed the same tutorial recently and had a similar result.
At step 6, upon seeing the default django 'congrats' page render locally, I deployed to EB as instructed and got a 404 instead of the default 'congrats' page.
I decided to use the code up to that point as a foundation for following the '[getting starte... |
12,183,763 | I am following the tutorial for deploying a django project on AWS elastic beanstalk here:
<http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html>
My app works when I test locally but when I deploy, I'm getting a 404 error. Looking at the event logs, I see this message:
`Error r... | 2012/08/29 | [
"https://Stackoverflow.com/questions/12183763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/656707/"
] | I believe you don't need to put container\_commands in .config because there is no database or table at this moment. | If you can, you should try to access the log file; it might give you a better idea of what's going on. Here's a link that might help:
<http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html> |
12,183,763 | I am following the tutorial for deploying a django project on AWS elastic beanstalk here:
<http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html>
My app works when I test locally but when I deploy, I'm getting a 404 error. Looking at the event logs, I see this message:
`Error r... | 2012/08/29 | [
"https://Stackoverflow.com/questions/12183763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/656707/"
] | Did you made the step?: Freeze the requirements.txt file.
```
(djangodev)# pip freeze > requirements.txt
```
Note
Make sure your requirements.txt file contains the following:
```
Django==1.4.1
MySQL-python==1.2.3
```
I had the same problem because I skipped it. Once I did it, add, commit and push. It works! | If you can, you should try to access the log file; it might give you a better idea of what's going on. Here's a link that might help:
<http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html> |
730,573 | I have gotten quite familiar with django's email sending abilities, but I havn't seen anything about it receiving and processing emails from users. Is this functionality available?
A few google searches have not turned up very promising results. Though I did find this: [Receive and send emails in python](https://stac... | 2009/04/08 | [
"https://Stackoverflow.com/questions/730573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2908/"
] | There's an app called [jutda-helpdesk](http://code.google.com/p/jutda-helpdesk/) that uses Python's `poplib` and `imaplib` to process incoming emails. You just have to have an account somewhere with POP3 or IMAP access.
This is adapted from their [get\_email.py](http://code.google.com/p/jutda-helpdesk/source/browse/tr... | Django is really intended as a web server (well, as a framework that fits into a web server), not as an email server. I suppose you could put some code into a Django web application that starts up an email server, using the kind of code shown in that question you linked to, but I really wouldn't recommend it; it's an a... |
730,573 | I have gotten quite familiar with django's email sending abilities, but I havn't seen anything about it receiving and processing emails from users. Is this functionality available?
A few google searches have not turned up very promising results. Though I did find this: [Receive and send emails in python](https://stac... | 2009/04/08 | [
"https://Stackoverflow.com/questions/730573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2908/"
] | I know this question is pretty old now but just thought I'd add for future reference that you might want to give <http://cloudmailin.com> a go. We have quite a few django users using the system and it should be a little simpler than the proposed solution. | Django is really intended as a web server (well, as a framework that fits into a web server), not as an email server. I suppose you could put some code into a Django web application that starts up an email server, using the kind of code shown in that question you linked to, but I really wouldn't recommend it; it's an a... |
730,573 | I have gotten quite familiar with django's email sending abilities, but I havn't seen anything about it receiving and processing emails from users. Is this functionality available?
A few google searches have not turned up very promising results. Though I did find this: [Receive and send emails in python](https://stac... | 2009/04/08 | [
"https://Stackoverflow.com/questions/730573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2908/"
] | There's an app called [jutda-helpdesk](http://code.google.com/p/jutda-helpdesk/) that uses Python's `poplib` and `imaplib` to process incoming emails. You just have to have an account somewhere with POP3 or IMAP access.
This is adapted from their [get\_email.py](http://code.google.com/p/jutda-helpdesk/source/browse/tr... | I know this question is pretty old now but just thought I'd add for future reference that you might want to give <http://cloudmailin.com> a go. We have quite a few django users using the system and it should be a little simpler than the proposed solution. |
39,840,323 | I'm using tensorflow 0.10 and I was benchmarking the examples found in the [official HowTo on reading data](https://www.tensorflow.org/versions/r0.10/how_tos/reading_data/index.html#reading-data). This HowTo illustrates different methods to move data to tensorflow, using the same MNIST example.
I was surprised by the ... | 2016/10/03 | [
"https://Stackoverflow.com/questions/39840323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/765009/"
] | **Update Oct 9** the slowness comes because the computation runs too fast for Python to pre-empt the computation thread and to schedule the pre-fetching threads. Computation in main thread takes 2ms and apparently that's too little for the pre-fetching thread to grab the GIL. Pre-fetching thread has larger delay and he... | Yaroslav nails the problem well. With small models you'll need to speed up the data import. One way to do this is with the Tensorflow function, [tf.TFRecordReader.read\_up\_to](https://www.tensorflow.org/api_docs/python/io_ops/readers#TFRecordReader.read_up_to), that reads multiple records in each `session.run()` call,... |
39,840,323 | I'm using tensorflow 0.10 and I was benchmarking the examples found in the [official HowTo on reading data](https://www.tensorflow.org/versions/r0.10/how_tos/reading_data/index.html#reading-data). This HowTo illustrates different methods to move data to tensorflow, using the same MNIST example.
I was surprised by the ... | 2016/10/03 | [
"https://Stackoverflow.com/questions/39840323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/765009/"
] | **Update Oct 9** the slowness comes because the computation runs too fast for Python to pre-empt the computation thread and to schedule the pre-fetching threads. Computation in main thread takes 2ms and apparently that's too little for the pre-fetching thread to grab the GIL. Pre-fetching thread has larger delay and he... | The main question is that why **the example with the preloaded data (constant)**
[examples/how\_tos/reading\_data/fully\_connected\_preloaded.py](https://github.com/tensorflow/tensorflow/blob/r0.10/tensorflow/examples/how_tos/reading_data/fully_connected_preloaded.py) is significantly slower than other data loading exa... |
39,840,323 | I'm using tensorflow 0.10 and I was benchmarking the examples found in the [official HowTo on reading data](https://www.tensorflow.org/versions/r0.10/how_tos/reading_data/index.html#reading-data). This HowTo illustrates different methods to move data to tensorflow, using the same MNIST example.
I was surprised by the ... | 2016/10/03 | [
"https://Stackoverflow.com/questions/39840323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/765009/"
] | Yaroslav nails the problem well. With small models you'll need to speed up the data import. One way to do this is with the Tensorflow function, [tf.TFRecordReader.read\_up\_to](https://www.tensorflow.org/api_docs/python/io_ops/readers#TFRecordReader.read_up_to), that reads multiple records in each `session.run()` call,... | The main question is that why **the example with the preloaded data (constant)**
[examples/how\_tos/reading\_data/fully\_connected\_preloaded.py](https://github.com/tensorflow/tensorflow/blob/r0.10/tensorflow/examples/how_tos/reading_data/fully_connected_preloaded.py) is significantly slower than other data loading exa... |
52,407,452 | When I run the following piece of code, only the print statements in the method, which I have dynamically assigned to the class "Test" only return "my\_unique\_method\_name".
**How to print the method name I have given it?** (Which is "wizardry" in the method—see "Expected Output" below.)
```
#!/usr/bin/python3
impo... | 2018/09/19 | [
"https://Stackoverflow.com/questions/52407452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5039582/"
] | As you have already made the step to use template matching with the `template match="Class/Student"` I would suggest to stick with that approach and simply write two templates, one for the `Class` elements, the other for the `Student` elements
```
<xsl:template match="Class">
<ul>
<xsl:apply-template... | You want one `ul` per `Class`, not per `Student`, so change
```
<xsl:template match="Class/Student">
```
to
```
<xsl:template match="Class">
```
Then change
```
<xsl:for-each select="../Student">
```
to
```
<xsl:for-each select="Student">
```
to get one `li` per `Student` child element of the `Class... |
39,745,460 | I am working on some piece of python code that calls various linux tools (like ssh) for automation purposes. Right now I am looking into "return code" handling.
Thus: I am looking for a simple way to run *some* command that gives me a specific non-zero return code; something like
```
echo "this is a testcommand, tha... | 2016/09/28 | [
"https://Stackoverflow.com/questions/39745460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1531124/"
] | Run `exit` in a subshell.
```
$ (exit 5) ; echo $?
5
``` | This is not exactly what you are asking but custom `rc` can be achieved through exit command.
```
echo "this is a test command, that should return with " ;exit 5
echo $?
5
``` |
39,745,460 | I am working on some piece of python code that calls various linux tools (like ssh) for automation purposes. Right now I am looking into "return code" handling.
Thus: I am looking for a simple way to run *some* command that gives me a specific non-zero return code; something like
```
echo "this is a testcommand, tha... | 2016/09/28 | [
"https://Stackoverflow.com/questions/39745460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1531124/"
] | Run `exit` in a subshell.
```
$ (exit 5) ; echo $?
5
``` | I have this function defined in `.bashrc`:
```
return_errorcode ()
{
return $1
}
```
So, I can directly use something like
```
$ return_errorcode 5
$ echo $?
5
```
Compared to `(exit 5); echo $?` option, this mechanism saves you a subshell. |
4,377,260 | As an exercise I built a little script that query Google Suggest JSON API. The code is quite simple:
```
query = 'a'
url = "http://clients1.google.co.jp/complete/search?hl=ja&q=%s&json=t" %query
response = urllib.urlopen(url)
result = json.load(response)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x83 in posit... | 2010/12/07 | [
"https://Stackoverflow.com/questions/4377260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/246242/"
] | The response header (`print response.header`) contains the following information:
```
Content-Type: text/javascript; charset=Shift_JIS
```
Note the charset.
If you specify this encoding in `json.load` it will work:
```
result = json.load(response, encoding='shift_jis')
``` | Regardless of what the spec says, the string "\x83A\x83}\x83]\x83\x93" is not UTF-8.
At a guess, it is one of [ "cp932", "shift\_jis", "shift\_jis\_2004", "shift\_jisx0213" ]; try decoding as one of these. |
32,566,625 | Say I generated a `dots = psychopy.visual.DotStim`. Is it possible to change the number of dots later? `dots.nDots = 5` leads to an error on the next `dots.draw()` because the underlying matrices don't match:
```
Traceback (most recent call last):
File "/home/jonas/Documents/projects/work pggcs/experiment/dots.py", ... | 2015/09/14 | [
"https://Stackoverflow.com/questions/32566625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1297830/"
] | It can be fixed for the `DotStim`:
```
dots.nDots = 5
dots._dotsDir = [0]*dots.nDots
dots. _verticesBase = dots._newDotsXY(dots.nDots)
```
This set movement of all dots to 0 but you can change that value to whatever you like or specify for individual dots. This is a hack which will likely break if you modify other a... | Yes, it would be nice to be able to do this but I haven't gotten around to it. The code that has to be run when the nDots/nElements changes is pretty close to starting from scratch with a new stimulus.**init** so adding this in 'correctly' probably means some refactoring (move a lot of the **init** code into setNDots()... |
48,279,419 | How does the quality of my code gets affected if I don't use `__init__` method in python? A simple example would be appreciated. | 2018/01/16 | [
"https://Stackoverflow.com/questions/48279419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7735772/"
] | *Short answer*; nothing happens.
*Long answer*; if you have a class `B`, which inherits from a class `A`, and if `B` has no `__init__` method defined, then the parent's (in this case, `A`) `__init__` is invoked.
```
In [137]: class A:
...: def __init__(self):
...: print("In A")
...: ... | Its not a matter of quality here, in `Object-oriented-design` which python supports, `__init__` is way to supply data when an object is created first. In `OOPS`, this is called a `constructor`. In other words **A constructor is a method which prepares a valid object**.
There are design patters on large projects are bu... |
11,577,619 | I got two files each containing a column with "time" and one with "id" like this:
File 1:
```
time id
11.24 1
11.26 2
11.27 3
11.29 5
11.30 6
```
File 2:
```
time id
11.25 1
11.26 3
11.27 4
11.31 6
11.32 7
11.33 8
```
Im trying to do a python script which can subtract the... | 2012/07/20 | [
"https://Stackoverflow.com/questions/11577619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1540477/"
] | Python Set do not support ordering for the elements. I would store the data as a dictionary
```
file1 = {1:'11:24', 2:'11:26', ... etc}
file2 = {1:'11:25', 3:'11:26', ... etc}
```
The loop over the intersection of the keys (or union based on your needs) to do the subtraction (time based or math based). | This is a bit old school. Look at using a default dict from the `collections` module for a more elegant approach.
This will work for any number of files, I've named mine `f1`, `f2` etc. The general idea is to process each file and build up a list of time values for each id. After file processing, iterate over the dict... |
11,577,619 | I got two files each containing a column with "time" and one with "id" like this:
File 1:
```
time id
11.24 1
11.26 2
11.27 3
11.29 5
11.30 6
```
File 2:
```
time id
11.25 1
11.26 3
11.27 4
11.31 6
11.32 7
11.33 8
```
Im trying to do a python script which can subtract the... | 2012/07/20 | [
"https://Stackoverflow.com/questions/11577619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1540477/"
] | Python Set do not support ordering for the elements. I would store the data as a dictionary
```
file1 = {1:'11:24', 2:'11:26', ... etc}
file2 = {1:'11:25', 3:'11:26', ... etc}
```
The loop over the intersection of the keys (or union based on your needs) to do the subtraction (time based or math based). | You can use this as a base (instead of treating '11.24' as a float, I guess you want to adapt for hours/minutes or minutes/seconds)... you can effectively union and subtract matching keys using a `defaultdict`.
As long as you can get your data into a format like this:
```
f1 = [
[11.24, 1],
[11.26, 2],
[1... |
11,577,619 | I got two files each containing a column with "time" and one with "id" like this:
File 1:
```
time id
11.24 1
11.26 2
11.27 3
11.29 5
11.30 6
```
File 2:
```
time id
11.25 1
11.26 3
11.27 4
11.31 6
11.32 7
11.33 8
```
Im trying to do a python script which can subtract the... | 2012/07/20 | [
"https://Stackoverflow.com/questions/11577619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1540477/"
] | List comprehensions can do the trick very easily:
```
#read these from file if you want to, included in this form for brevity
F1 = {1: 11.24, 2: 11.26, 3:11.27, 5:11.29, 6:11.30}
F2 = {1:11.25, 3:11.26, 4:11.27, 6:11.31, 7:11.32, 8:11.33}
K1 = set(F1.keys())
K2 = set(F2.keys())
result = dict([ (k, F1[k] - F2[k]) for... | This is a bit old school. Look at using a default dict from the `collections` module for a more elegant approach.
This will work for any number of files, I've named mine `f1`, `f2` etc. The general idea is to process each file and build up a list of time values for each id. After file processing, iterate over the dict... |
11,577,619 | I got two files each containing a column with "time" and one with "id" like this:
File 1:
```
time id
11.24 1
11.26 2
11.27 3
11.29 5
11.30 6
```
File 2:
```
time id
11.25 1
11.26 3
11.27 4
11.31 6
11.32 7
11.33 8
```
Im trying to do a python script which can subtract the... | 2012/07/20 | [
"https://Stackoverflow.com/questions/11577619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1540477/"
] | List comprehensions can do the trick very easily:
```
#read these from file if you want to, included in this form for brevity
F1 = {1: 11.24, 2: 11.26, 3:11.27, 5:11.29, 6:11.30}
F2 = {1:11.25, 3:11.26, 4:11.27, 6:11.31, 7:11.32, 8:11.33}
K1 = set(F1.keys())
K2 = set(F2.keys())
result = dict([ (k, F1[k] - F2[k]) for... | You can use this as a base (instead of treating '11.24' as a float, I guess you want to adapt for hours/minutes or minutes/seconds)... you can effectively union and subtract matching keys using a `defaultdict`.
As long as you can get your data into a format like this:
```
f1 = [
[11.24, 1],
[11.26, 2],
[1... |
23,221,577 | I'm following [this tutorial on Embedding Python on C](https://docs.python.org/2.7/extending/embedding.html), but their [Pure Embedding](https://docs.python.org/2.7/extending/embedding.html#pure-embedding) example is not working for me.
I have on the same folder (taken from the example):
**call.c**
```
#include <Pyt... | 2014/04/22 | [
"https://Stackoverflow.com/questions/23221577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1970845/"
] | Try setting `PYTHONPATH`:
```
export PYTHONPATH=`pwd`
``` | Really, the example should have `PySys_SetPath(".");` after initialization. |
71,363,142 | how do you call a php function with html
I have this:
```
<input class="myButton" type="button" name="woonkameruit" value="UIT" onclick="kameroff('woonkamer');<?php woonkameruit()?>">
```
and
```
function woonkameruit() {
exec("sudo pkill python");
exec("sudo python3/home/pi/Documents/Programmas/WOONKAMERUit... | 2022/03/05 | [
"https://Stackoverflow.com/questions/71363142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17288855/"
] | You have to send the function name via Javascript, and create some controller like logic. It is a similar to what Laravel Livewire does. For Example:
frontend.php:
```
<!-- Frontend Logic -->
<input id="myButton" class="myButton" type="button" name="woonkameruit" value="UIT">
<!-- Put Before </body> -->
<script typ... | You cannot directly call PHP functions with HTML as it is in the backend.
However you can send a request to the backend with JS or HTML and make the PHP handle it so it executes a function.
To do this there are multiple ways:
HTML: Form
JS: Ajax
If you do not know how to implement this I suggest going to websites ... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | ```
>>> # Printable
>>> s = 'test'
>>> len(s)+2 == len(repr(s))
True
>>> # Unprintable
>>> s = 'test\x00'
>>> len(s)+2 == len(repr(s))
False
``` | ```
ctrlchar = "\n\r| "
# ------------------------------------------------------------------------
# This will let you control what you deem 'printable'
# Clean enough to display any binary
def isprint(chh):
if ord(chh) > 127:
return False
if ord(chh) < 32:
return False
if chh in ctrlchar... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | In Python 3, strings have an `isprintable()` method:
```
>>> 'a, '.isprintable()
True
```
For Python 2.7, see Dave Webb's answer. | ```
# Here is the full routine to display an arbitrary binary string
# Python 2
ctrlchar = "\n\r| "
# ------------------------------------------------------------------------
def isprint(chh):
if ord(chh) > 127:
return False
if ord(chh) < 32:
return False
if chh in ctrlchar:
retur... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | As you've said the [`string` module has `printable`](http://docs.python.org/library/string.html#string.printable) so it's just a case of checking if all the characters in your string are in `printable`:
```
>>> hello = 'Hello World!'
>>> bell = chr(7)
>>> import string
>>> all(c in string.printable for c in hello)
Tru... | ```
ctrlchar = "\n\r| "
# ------------------------------------------------------------------------
# This will let you control what you deem 'printable'
# Clean enough to display any binary
def isprint(chh):
if ord(chh) > 127:
return False
if ord(chh) < 32:
return False
if chh in ctrlchar... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | As you've said the [`string` module has `printable`](http://docs.python.org/library/string.html#string.printable) so it's just a case of checking if all the characters in your string are in `printable`:
```
>>> hello = 'Hello World!'
>>> bell = chr(7)
>>> import string
>>> all(c in string.printable for c in hello)
Tru... | ```
>>> # Printable
>>> s = 'test'
>>> len(s)+2 == len(repr(s))
True
>>> # Unprintable
>>> s = 'test\x00'
>>> len(s)+2 == len(repr(s))
False
``` |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | In Python 3, strings have an `isprintable()` method:
```
>>> 'a, '.isprintable()
True
```
For Python 2.7, see Dave Webb's answer. | The `category` function from the `unicodedata` [module](https://docs.python.org/2/library/unicodedata.html#unicodedata.category) might suit your needs. For instance, you can use this to check whether there are any control characters in a string while still allowing non-ASCII characters.
```
>>> import unicodedata
>>>... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | In the ASCII table, [\x20-\x7e] are printable characters.
Use regular expressions to check whether characters other than these characters are included in the string.
You can make sure whether this is a printable string.
```
>>> import re
>>> # Printable
>>> print re.search(r'[^\x20-\x7e]', 'test')
None
>>> # U... | Mine is a solution to get rid of any known set of characters. it might help.
```
non_printable_chars = set("\n\t\r ") # Space included intensionally
is_printable = lambda string:bool(set(string) - set(non_printable_chars))
...
...
if is_printable(string):
print("""do something""")
...
``` |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | In Python 3, strings have an `isprintable()` method:
```
>>> 'a, '.isprintable()
True
```
For Python 2.7, see Dave Webb's answer. | Mine is a solution to get rid of any known set of characters. it might help.
```
non_printable_chars = set("\n\t\r ") # Space included intensionally
is_printable = lambda string:bool(set(string) - set(non_printable_chars))
...
...
if is_printable(string):
print("""do something""")
...
``` |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | As you've said the [`string` module has `printable`](http://docs.python.org/library/string.html#string.printable) so it's just a case of checking if all the characters in your string are in `printable`:
```
>>> hello = 'Hello World!'
>>> bell = chr(7)
>>> import string
>>> all(c in string.printable for c in hello)
Tru... | ```
# Here is the full routine to display an arbitrary binary string
# Python 2
ctrlchar = "\n\r| "
# ------------------------------------------------------------------------
def isprint(chh):
if ord(chh) > 127:
return False
if ord(chh) < 32:
return False
if chh in ctrlchar:
retur... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | As you've said the [`string` module has `printable`](http://docs.python.org/library/string.html#string.printable) so it's just a case of checking if all the characters in your string are in `printable`:
```
>>> hello = 'Hello World!'
>>> bell = chr(7)
>>> import string
>>> all(c in string.printable for c in hello)
Tru... | In the ASCII table, [\x20-\x7e] are printable characters.
Use regular expressions to check whether characters other than these characters are included in the string.
You can make sure whether this is a printable string.
```
>>> import re
>>> # Printable
>>> print re.search(r'[^\x20-\x7e]', 'test')
None
>>> # U... |
3,636,928 | I have some code that pulls data from a com-port and I want to make sure that what I got really is a printable string (i.e. ASCII, maybe UTF-8) before printing it. Is there a function for doing this? The first half dozen places I looked, didn't have anything that looks like what I want. ([string has printable](http://d... | 2010/09/03 | [
"https://Stackoverflow.com/questions/3636928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | This Python 3 string contains all kinds of special characters:
```
s = 'abcd\x65\x66 äüöë\xf1 \u00a0\u00a1\u00a2 漢字 \a\b\r\t\n\v\\ \231\x9a \u2640\u2642\uffff'
```
If you try to show it in the console (or use `repr`), it makes a pretty good job of escaping all non-printable characters from that string:
```
>>> s
'a... | The `category` function from the `unicodedata` [module](https://docs.python.org/2/library/unicodedata.html#unicodedata.category) might suit your needs. For instance, you can use this to check whether there are any control characters in a string while still allowing non-ASCII characters.
```
>>> import unicodedata
>>>... |
53,727,275 | I am trying to ammend a group of files in a folder, by adding F to the 4th line (which is number 3 in python, if I'm correct). With the following code below, the code is just continuously running and not making the amendments, anyone got any ideas?
```
import os
from glob import glob
list_of_files = glob('*.gjf') ... | 2018/12/11 | [
"https://Stackoverflow.com/questions/53727275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10750169/"
] | The error is expected. Function runtime is based on C#, when the response tries to add the `Allow` header, underlying C# code checks its name. It's by design that `Allow` is a read-only header in [HttpContentHeaders](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.headers.httpcontentheaders?view=netframewo... | Have you tried adding the allowed methods to the **function.json** files as noted in the [documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook#trigger---configuration)?
Example below:
```
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
... |
53,727,275 | I am trying to ammend a group of files in a folder, by adding F to the 4th line (which is number 3 in python, if I'm correct). With the following code below, the code is just continuously running and not making the amendments, anyone got any ideas?
```
import os
from glob import glob
list_of_files = glob('*.gjf') ... | 2018/12/11 | [
"https://Stackoverflow.com/questions/53727275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10750169/"
] | The error is expected. Function runtime is based on C#, when the response tries to add the `Allow` header, underlying C# code checks its name. It's by design that `Allow` is a read-only header in [HttpContentHeaders](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.headers.httpcontentheaders?view=netframewo... | If you are editing this through the portal, navigate to the `integrate` section of the function and select POST and OPTIONS methods. |
53,727,275 | I am trying to ammend a group of files in a folder, by adding F to the 4th line (which is number 3 in python, if I'm correct). With the following code below, the code is just continuously running and not making the amendments, anyone got any ideas?
```
import os
from glob import glob
list_of_files = glob('*.gjf') ... | 2018/12/11 | [
"https://Stackoverflow.com/questions/53727275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10750169/"
] | The error is expected. Function runtime is based on C#, when the response tries to add the `Allow` header, underlying C# code checks its name. It's by design that `Allow` is a read-only header in [HttpContentHeaders](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.headers.httpcontentheaders?view=netframewo... | Solved it through putting an APIM in front of teh logic app. This APIM just returns a 200 in case of the OPTIONS request, and calls the logic app for the subsequent HTTP post requests |
71,044,523 | For Example I have enabled the mTLS in my istio service in STRICT mode. and I have authorization policy that have kind of source.principals rule check.
Now I want to access these rules details like source.principals and source.namespace after request is authenticated and authorized so that I can do more business login... | 2022/02/09 | [
"https://Stackoverflow.com/questions/71044523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2090808/"
] | Have a look at the [AuthConfig class](https://github.com/manfredsteyer/angular-oauth2-oidc/blob/master/projects/lib/src/auth.config.ts) and try setting `loginUrl` to the authorize endpoint and also set the token endpoint explicitly. See if this gives you a different error.
A good library should allow you to set endpoi... | Extending **auth.config** about additional loginUrl and tokenUrl solved the issue.
This is finall version of my config file:
```
export const OAUTH_CONFIG: AuthConfig = {
issuer: environment.identityProviderBaseUrl,
loginUrl: environment.identityProviderLoginUrl,
logoutUrl: environment.identityProviderLogoutUrl... |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | **UPDATE** (with solution below)
I've been digging into the Django model code and it seems like there is a bug that creates a race condition when using "app.model"-based identifiers for the related field in a ForeignKey. When the application is running in production mode as opposed to DEBUG, the ForeignKey.get\_defaul... | Another cause:
Make sure that all Foreign Keys are in the same reference models in the same application (app label). I was banging my head against the wall for a while on this one.
```
class Meta:
db_table = 'reservation'
app_label = 'admin'
``` |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | **UPDATE** (with solution below)
I've been digging into the Django model code and it seems like there is a bug that creates a race condition when using "app.model"-based identifiers for the related field in a ForeignKey. When the application is running in production mode as opposed to DEBUG, the ForeignKey.get\_defaul... | In my case i had a model 'Entity' and a 'User' which inherited 'AbstractBaseUser'. A 'User' model had a entity field with ForeignKey to Entity configured that way:
```
entity = m.ForeignKey('core.Entity', on_delete=m.SET_NULL, null=True)
```
in the end the workaround was to change it to
```
from core.models import ... |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | **UPDATE** (with solution below)
I've been digging into the Django model code and it seems like there is a bug that creates a race condition when using "app.model"-based identifiers for the related field in a ForeignKey. When the application is running in production mode as opposed to DEBUG, the ForeignKey.get\_defaul... | In my case, I made a mistake with the class call by surrounding the class name with quotes. Removing them solved the error for me. See the wrong code below:
```
from django.db import models
from django.contrib.auth.models import AbstractUser
from account.models import Profile
class User(AbstractUser):
first_name ... |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | **UPDATE** (with solution below)
I've been digging into the Django model code and it seems like there is a bug that creates a race condition when using "app.model"-based identifiers for the related field in a ForeignKey. When the application is running in production mode as opposed to DEBUG, the ForeignKey.get\_defaul... | As it has already been highlighted in other answers, the most common cause seems to be referring to a model using the `'app.Model'` syntax.
However, it might still be quite a big challenge to figure out which model exactly is causing the trouble.
I found that a quick solution to that question is to go directly to the... |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | In my case i had a model 'Entity' and a 'User' which inherited 'AbstractBaseUser'. A 'User' model had a entity field with ForeignKey to Entity configured that way:
```
entity = m.ForeignKey('core.Entity', on_delete=m.SET_NULL, null=True)
```
in the end the workaround was to change it to
```
from core.models import ... | Another cause:
Make sure that all Foreign Keys are in the same reference models in the same application (app label). I was banging my head against the wall for a while on this one.
```
class Meta:
db_table = 'reservation'
app_label = 'admin'
``` |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | In my case i had a model 'Entity' and a 'User' which inherited 'AbstractBaseUser'. A 'User' model had a entity field with ForeignKey to Entity configured that way:
```
entity = m.ForeignKey('core.Entity', on_delete=m.SET_NULL, null=True)
```
in the end the workaround was to change it to
```
from core.models import ... | In my case, I made a mistake with the class call by surrounding the class name with quotes. Removing them solved the error for me. See the wrong code below:
```
from django.db import models
from django.contrib.auth.models import AbstractUser
from account.models import Profile
class User(AbstractUser):
first_name ... |
14,386,536 | I have an existing, functional Django application that has been running in DEBUG mode for the last several months. When I change the site to run in production mode, I begin getting the following Exception emails sent to me when I hit a specific view that tries to create a new Referral model object.
```
Traceback (most... | 2013/01/17 | [
"https://Stackoverflow.com/questions/14386536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1988262/"
] | In my case i had a model 'Entity' and a 'User' which inherited 'AbstractBaseUser'. A 'User' model had a entity field with ForeignKey to Entity configured that way:
```
entity = m.ForeignKey('core.Entity', on_delete=m.SET_NULL, null=True)
```
in the end the workaround was to change it to
```
from core.models import ... | As it has already been highlighted in other answers, the most common cause seems to be referring to a model using the `'app.Model'` syntax.
However, it might still be quite a big challenge to figure out which model exactly is causing the trouble.
I found that a quick solution to that question is to go directly to the... |
50,866,111 | I'm working with retrain.python file from this demo.
I'm getting different types of files:
[](https://i.stack.imgur.com/WLY0Y.png)
[](https://i.stack.imgur.com/htD6r.png)
[![enter i... | 2018/06/14 | [
"https://Stackoverflow.com/questions/50866111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4024038/"
] | Here is a nice script to freeze a graph
```
import os
import argparse
import tensorflow as tf
from tensorflow.python.framework import graph_util
from tensorflow.python.platform import gfile
def load_graph_def(model_path, sess=None):
if os.path.isfile(model_path):
with gfile.FastGFile(model_path, 'rb') as ... | Given that you have a `meta graph` saved, try using the `input_meta_graph` argument:
```
python freeze_graph.py \
--input_meta_graph=/home/automator/Desktop/retrain/code/tmp/model.meta \
--input_checkpoint=/home/automator/Desktop/retrain/code/tmp/model.ckpt \
--input_binary=true \
--output_graph=/home/automator/Des... |
60,763,948 | These are my two models, when I try to open City page on Django I get an error: "column city.country\_id\_id does not exist". I don't know why python adds extra `_id` there.
```
class Country(models.Model):
country_id = models.CharField(primary_key=True,max_length=3)
country_name = models.CharField(max_length=... | 2020/03/19 | [
"https://Stackoverflow.com/questions/60763948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13090788/"
] | as the comments have begun to mention, and in reference to your final statement, this code absolutely *should not* work, for multiple reasons.
1) you open the file three times, for no apparent reason.
2) `outfile` isn't declared, doesn't do anything.
3) when you open a file with `w` it clears the contents of afforme... | This will work.
```
f_name = input("Input file name: ")
with open(f_name, "r+") as f:
lines = f.read().splitlines() # get string, split lines
lines = [l.capitalize() for l in lines] # capitalize each line
f.seek(0) # move the cursor to the beginning
f.write('\n'.join(lines)) # join the lines and w... |
3,939,482 | I have a stats app written in python that on a timer refreshes the ssh screen with stats. Right now it uses os.system('clear') to clear the screen and then outputs a multi line data with the stats.
I'd like to do just do a \r instead of executing the clear but that only works with one line, is it possible to do this w... | 2010/10/15 | [
"https://Stackoverflow.com/questions/3939482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/388538/"
] | It doesn't really answer your question, but there isn't really anything wrong with calling os.system to clear out the terminal (other than the system running on different operating systems) in which case you could use:
`os.system('cls' if os.name=='nt' else 'clear')` | For simple applications you can use:
```
print('\n' * number_of_lines)
```
For more advanced there is [curses](http://docs.python.org/library/curses.html) module in standard library. |
3,939,482 | I have a stats app written in python that on a timer refreshes the ssh screen with stats. Right now it uses os.system('clear') to clear the screen and then outputs a multi line data with the stats.
I'd like to do just do a \r instead of executing the clear but that only works with one line, is it possible to do this w... | 2010/10/15 | [
"https://Stackoverflow.com/questions/3939482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/388538/"
] | solved the issue with:
```
import curses
window = curses.initscr()
window.addstr(1, 0, "my text")
window.refresh()
curses.endwin()
``` | For simple applications you can use:
```
print('\n' * number_of_lines)
```
For more advanced there is [curses](http://docs.python.org/library/curses.html) module in standard library. |
40,119,361 | I have a dictionary which has the following structure in a python program
`{'John':{'age': '12', 'height':'152', 'weight':'45}}`, this is the result returned from a function.
My question is how may I extract the sub-dictionary please? so that I can have the data in this form only `{'age': '12', 'height':'152', 'weight... | 2016/10/18 | [
"https://Stackoverflow.com/questions/40119361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6797800/"
] | To get a value from a dictionary, use dict[key]:
```
>>> d = {'John':{'age': '12', 'height':'152', 'weight':'45'}}
>>> d['John']
{'age': '12', 'height': '152', 'weight': '45'}
>>>
``` | ```
>>> d = {'John':{'age': '12', 'height':'152', 'weight':'45'}, 'Kim':{'age': '13', 'height': '113', 'weight': '30'}}
>>> for key in d:
... print(key, d[key])
...
John {'height': '152', 'weight': '45', 'age': '12'}
Kim {'height': '113', 'weight': '30', 'age': '13'}
```
Just access the subdictionary with `d[key... |
45,103,348 | I try to make to load the content from mysqldb using an animation and a limit of content taken and it takes content is displaying when it gets at the end of content the animation of loading is continue loading a I get this error
My script:
```
<script>
$(document).ready(function(){
var limit = 7;
var... | 2017/07/14 | [
"https://Stackoverflow.com/questions/45103348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7906290/"
] | You are returning an empty string from your python code:
```
if json_fetch=="<Response 3 bytes [200 OK]>":
return ""
```
When you use `JSON.parse("")`, you are returned with the `Uncaught SyntaxError: Unexpected end of JSON input` | i change but now is returning an empty array "[]" and the animation did't stop to place on the screen the text("did't stop")
script:
```
<script>
$(document).ready(function(){
var limit = 7;
var start = 0;
var action = 'inactive';
function load_country_data(limit, start)
{
$.ajax({
url:"/select_index",
... |
29,037,501 | I created an SSH-Agent to provide my key to the ssh/scp cmd when connecting to my server.
I also scripted a SSH-Add with the command 'expect' to write my paraphrase when it's needed.
This works perfectly with my user "user".
But I'm executing a python script that uses /dev/mem that need to be run as root through sudo... | 2015/03/13 | [
"https://Stackoverflow.com/questions/29037501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4542774/"
] | There's no general way to get this behavior.
You can create an ImmutablePerson class with a constructor that would accept a Person and construct an immutable version of that Person . | Sure, just have a boolean flag in the Person object which says if the object is locked for modifications. If it is locked just have all setters do nothing or have them throw exceptions.
When invoking `immutableObject(person)` just set the flag to true. Setting the flag will also lock/deny the ability to set/change th... |
29,037,501 | I created an SSH-Agent to provide my key to the ssh/scp cmd when connecting to my server.
I also scripted a SSH-Add with the command 'expect' to write my paraphrase when it's needed.
This works perfectly with my user "user".
But I'm executing a python script that uses /dev/mem that need to be run as root through sudo... | 2015/03/13 | [
"https://Stackoverflow.com/questions/29037501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4542774/"
] | There is no way to do it without doing some work.
You need to either get a compile time check by creating a new immutable object from the mutable one as Eran suggests, add some code for a runtime check, or get a weaker compiler time check by using a split interface
e.g
```
interface ReadOnlyPerson {
int getX();
}
... | Sure, just have a boolean flag in the Person object which says if the object is locked for modifications. If it is locked just have all setters do nothing or have them throw exceptions.
When invoking `immutableObject(person)` just set the flag to true. Setting the flag will also lock/deny the ability to set/change th... |
29,037,501 | I created an SSH-Agent to provide my key to the ssh/scp cmd when connecting to my server.
I also scripted a SSH-Add with the command 'expect' to write my paraphrase when it's needed.
This works perfectly with my user "user".
But I'm executing a python script that uses /dev/mem that need to be run as root through sudo... | 2015/03/13 | [
"https://Stackoverflow.com/questions/29037501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4542774/"
] | There's no general way to get this behavior.
You can create an ImmutablePerson class with a constructor that would accept a Person and construct an immutable version of that Person . | There is no way to do it without doing some work.
You need to either get a compile time check by creating a new immutable object from the mutable one as Eran suggests, add some code for a runtime check, or get a weaker compiler time check by using a split interface
e.g
```
interface ReadOnlyPerson {
int getX();
}
... |
45,309,118 | Trying to create a game called `hangman` in Python.
I've come a long way, but the 'core' functionality is failing me.
I've edited out all the parts which are irrelevant for this question.
Here it comes:
```
picked = ['yaaayyy']
length = len(picked)
dashed = "-" * length
guessed = picked.replace(pick... | 2017/07/25 | [
"https://Stackoverflow.com/questions/45309118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4834431/"
] | This code seems to be slightly wrong:
```
found = [i for i, x in enumerate(picked) if x == input]
for item in found:
guessed = guessed[:item] + input + guessed[i+1:]
```
That last line should probably be:
```
guessed = guessed[:item] + input + guessed[item+1:]
```
**EDIT**
This seems simpler to me:
```
for ... | Assuming you're using python3 you can solve it by simply doing:
```
user_input = input()
guessed = ''.join(letter if user_input == letter else guessed[i] for i, letter in enumerate(picked))
``` |
51,954,369 | ```
[{"answerInfo":{"extraData":{"am_answer_type":"NN"}},"content":"MP3:not support.","messageId":"c4d6a2f4649d483a811fcce4b26ae9a1"}]
```
How to extract "MP3: not support" from this String using regular expression or python code?
But an error was generated per the suggestion:
```
Traceback (most recent call last):... | 2018/08/21 | [
"https://Stackoverflow.com/questions/51954369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/697911/"
] | In my code below, I create a dataframe then output it to a .csv file using `pandas.DataFrame.to_csv()` ([link to docs](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html)). In this example, I also add try and except clauses to raise an exception if the user enters an invalid Series ID (... | ```
import requests
import json
import csv
headers = {'Content-type': 'application/json'}
data = json.dumps({"seriesid": ['LAUMT421090000000005'],"startyear":"2011", "endyear":"2014"})
p = requests.post('https://api.bls.gov/publicAPI/v2/timeseries/data/', data=data, headers=headers)
json_data = json.loads(p.text)
```
... |
30,532,431 | My program consists in mouse drawing: Simultaneous reproduction of the drawn curves are done on a toplevel window. My aim is to set the vertical and horizontal scroll bars to the toplevel window.
The drawing works as I expected except I am not seeing the scrollbars as well as I am getting this error (which does not st... | 2015/05/29 | [
"https://Stackoverflow.com/questions/30532431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4949239/"
] | These lines are incorrect:
```
self.canvas.config(yscrollcommand=self.canvas.yview)
self.canvas.config(xscrollcommand=self.canvas.xview)
```
You're telling the canvas to scroll the canvas when the canvas scrolls. The `yscrollcommand` and `xscrollcommand` options typically need to call the `set` method of a scrollbar... | I want to share the solution I found in case someone in the future encounters this problem:
I only had encrust the two scrollbars into the same parent widget as the canvas itself. I mean:
```
self.sbarv=Scrollbar(self.top,orient=VERTICAL)
self.sbarh=Scrollbar(self.top,orient=HORIZONTAL)
``` |
29,583,102 | I've been working locally on an AngularJS front-end, Django REST backend project and I want to deploy it to Heroku. It keeps giving me errors when I try to push, however,
I've followed the steps on [here](https://devcenter.heroku.com/articles/getting-started-with-django), which has helped me deploy Django-only apps be... | 2015/04/11 | [
"https://Stackoverflow.com/questions/29583102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2883245/"
] | I don't understand why you need Node at all in a Django project - it's not required for Angular or DRF - but the instructions in the linked project mention setting the buildpack to a custom "multi" one:
```
heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
``` | it seems like you have not installed Django in you virtualenv
Have you forgot to run `pip install django-toolbelt` |
8,949,454 | I have a pygtk Table with 16 squares, each of them containing a label. Label names are: label1, label2, label3, ..., label16.
I also have a timer that fires every *n* seconds. When the timer is fired one of the squares is highlighted (just set the font size of it to 18 and the font size of the rest to 12).
If there w... | 2012/01/21 | [
"https://Stackoverflow.com/questions/8949454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090788/"
] | You *could* use the built-in function, [`getattr()`](http://docs.python.org/library/functions.html#getattr) as others have suggested:
```
label = getattr(self, 'label%d' % i)
label.modify_font(self.__font_small)
```
But in reality, you'd be better off storing your 16 `label`s in a [`list`](http://docs.python.org/tut... | You should look into the `getattr` function. |
8,949,454 | I have a pygtk Table with 16 squares, each of them containing a label. Label names are: label1, label2, label3, ..., label16.
I also have a timer that fires every *n* seconds. When the timer is fired one of the squares is highlighted (just set the font size of it to 18 and the font size of the rest to 12).
If there w... | 2012/01/21 | [
"https://Stackoverflow.com/questions/8949454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090788/"
] | You should look into the `getattr` function. | Why in the world would you write that as a bunch of `if` statements?
```
modify_fonts = [getattr(self, "label%s" % i).modify_font for i in xrange(1, 17)]
```
You now have a list of the methods you can call for each label. That is, `modify_fonts[0]` is `self.label1.modify_font` and so on. Then you call them in a loop... |
8,949,454 | I have a pygtk Table with 16 squares, each of them containing a label. Label names are: label1, label2, label3, ..., label16.
I also have a timer that fires every *n* seconds. When the timer is fired one of the squares is highlighted (just set the font size of it to 18 and the font size of the rest to 12).
If there w... | 2012/01/21 | [
"https://Stackoverflow.com/questions/8949454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090788/"
] | You *could* use the built-in function, [`getattr()`](http://docs.python.org/library/functions.html#getattr) as others have suggested:
```
label = getattr(self, 'label%d' % i)
label.modify_font(self.__font_small)
```
But in reality, you'd be better off storing your 16 `label`s in a [`list`](http://docs.python.org/tut... | Use [`getattr`](http://docs.python.org/library/functions.html#getattr):
```
self.__actual_choice = (self.__actual_choice % 16)+1
for i in range(1, 17):
if i == self.__actual_choice:
getattr(self, 'label' + str(i)).modify_font(self.__font_big)
else:
getattr(self, 'label' + str(i)).modify_font(se... |
8,949,454 | I have a pygtk Table with 16 squares, each of them containing a label. Label names are: label1, label2, label3, ..., label16.
I also have a timer that fires every *n* seconds. When the timer is fired one of the squares is highlighted (just set the font size of it to 18 and the font size of the rest to 12).
If there w... | 2012/01/21 | [
"https://Stackoverflow.com/questions/8949454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090788/"
] | Use [`getattr`](http://docs.python.org/library/functions.html#getattr):
```
self.__actual_choice = (self.__actual_choice % 16)+1
for i in range(1, 17):
if i == self.__actual_choice:
getattr(self, 'label' + str(i)).modify_font(self.__font_big)
else:
getattr(self, 'label' + str(i)).modify_font(se... | Why in the world would you write that as a bunch of `if` statements?
```
modify_fonts = [getattr(self, "label%s" % i).modify_font for i in xrange(1, 17)]
```
You now have a list of the methods you can call for each label. That is, `modify_fonts[0]` is `self.label1.modify_font` and so on. Then you call them in a loop... |
8,949,454 | I have a pygtk Table with 16 squares, each of them containing a label. Label names are: label1, label2, label3, ..., label16.
I also have a timer that fires every *n* seconds. When the timer is fired one of the squares is highlighted (just set the font size of it to 18 and the font size of the rest to 12).
If there w... | 2012/01/21 | [
"https://Stackoverflow.com/questions/8949454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090788/"
] | You *could* use the built-in function, [`getattr()`](http://docs.python.org/library/functions.html#getattr) as others have suggested:
```
label = getattr(self, 'label%d' % i)
label.modify_font(self.__font_small)
```
But in reality, you'd be better off storing your 16 `label`s in a [`list`](http://docs.python.org/tut... | Why in the world would you write that as a bunch of `if` statements?
```
modify_fonts = [getattr(self, "label%s" % i).modify_font for i in xrange(1, 17)]
```
You now have a list of the methods you can call for each label. That is, `modify_fonts[0]` is `self.label1.modify_font` and so on. Then you call them in a loop... |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | Numpy indexing arrays provide concise notation for application of bit reversal permutations.
```
import numpy as np
def bitrev_map(nbits):
"""create bit reversal mapping
>>> bitrev_map(3)
array([0, 4, 2, 6, 1, 5, 3, 7], dtype=uint16)
>>> import numpy as np
>>> np.arange(8)[bitrev_map(3)]
array([0, 4, 2, ... | You can do something like this where you can define how many bits in the argument l.
```
def reverse(x, l):
r = x & 1
for i in range (1, l):
r = r << 1 | (x >> i) & 1
print(bin(r))
return r
``` |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | This is a fast way to do it:
I got it from [here](https://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c)
```
BitReverseTable256 = [0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0... | You can do something like this where you can define how many bits in the argument l.
```
def reverse(x, l):
r = x & 1
for i in range (1, l):
r = r << 1 | (x >> i) & 1
print(bin(r))
return r
``` |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | This is a fast way to do it:
I got it from [here](https://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c)
```
BitReverseTable256 = [0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0... | [This](http://wiki.python.org/moin/BitwiseOperators) is the first link I found googling for "python bitwise" and it has a pretty good summary of how to do bit-twiddling in Python.
If you don't care too much about speed, the most straightforward solution is to go through each bit-place of the original number and, if it... |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | If you truly want 32 bits rather than 4, then here is a function to do what you want:
```
def revbits(x):
return int(bin(x)[2:].zfill(32)[::-1], 2)
```
Basically I'm converting to binary, stripping off the '0b' in front, filling with zeros up to 32 chars, reversing, and converting back to an integer.
It might ... | You can do something like this where you can define how many bits in the argument l.
```
def reverse(x, l):
r = x & 1
for i in range (1, l):
r = r << 1 | (x >> i) & 1
print(bin(r))
return r
``` |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | This is a fast way to do it:
I got it from [here](https://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c)
```
BitReverseTable256 = [0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0... | Numpy indexing arrays provide concise notation for application of bit reversal permutations.
```
import numpy as np
def bitrev_map(nbits):
"""create bit reversal mapping
>>> bitrev_map(3)
array([0, 4, 2, 6, 1, 5, 3, 7], dtype=uint16)
>>> import numpy as np
>>> np.arange(8)[bitrev_map(3)]
array([0, 4, 2, ... |
5,333,509 | What is the best way to reverse the significant bits of an integer in python and then get the resulting integer out of it?
For example I have the numbers 1,2,5,15 and I want to reverse the bits like so:
```
original reversed
1 - 0001 - 1000 - 8
2 - 0010 - 0100 - 4
5 - 0101 - 1010 - 10
15 - 1111 - 1111... | 2011/03/17 | [
"https://Stackoverflow.com/questions/5333509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330013/"
] | ```
reversed_ = sum(1<<(numbits-1-i) for i in range(numbits) if original>>i&1)
``` | [This](http://wiki.python.org/moin/BitwiseOperators) is the first link I found googling for "python bitwise" and it has a pretty good summary of how to do bit-twiddling in Python.
If you don't care too much about speed, the most straightforward solution is to go through each bit-place of the original number and, if it... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.