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 |
|---|---|---|---|---|---|
28,031,210 | I have a code who looks like this :
```
# step 1 remove from switch
for server in server_list:
remove_server_from_switch(server)
logger.info("OK : Removed %s", server)
# step 2 remove port
for port in port_list:
remove_ports_from_switch(port)
logger.info("OK : Removed port %s", port)
# step 3 exe... | 2015/01/19 | [
"https://Stackoverflow.com/questions/28031210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4471200/"
] | This is what context managers are for. Read up on the [with statement](https://docs.python.org/2/reference/compound_stmts.html#with) for details, but the general idea is you need to write context manager classes where the `__enter__` and `__exit__` functions do the removal/re-addition of your servers/ports. Then your c... | Maybe something like this will work:
```
undo_dict = {remove_server_from_switch: add_server_to_switch,
remove_ports_from_switch: add_ports_to_switch,
add_server_to_switch: remove_server_from_switch,
add_ports_to_switch: remove_ports_from_switch}
def undo_action(action):
arg... |
28,031,210 | I have a code who looks like this :
```
# step 1 remove from switch
for server in server_list:
remove_server_from_switch(server)
logger.info("OK : Removed %s", server)
# step 2 remove port
for port in port_list:
remove_ports_from_switch(port)
logger.info("OK : Removed port %s", port)
# step 3 exe... | 2015/01/19 | [
"https://Stackoverflow.com/questions/28031210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4471200/"
] | You should use a [with](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement) construct.
As [this link](https://realpython.com/python-with-statement/#the-with-statement-approach) explains:
```
with expression as target_var:
do_something(target_var)
```
>
> The context manager object resul... | Maybe something like this will work:
```
undo_dict = {remove_server_from_switch: add_server_to_switch,
remove_ports_from_switch: add_ports_to_switch,
add_server_to_switch: remove_server_from_switch,
add_ports_to_switch: remove_ports_from_switch}
def undo_action(action):
arg... |
28,031,210 | I have a code who looks like this :
```
# step 1 remove from switch
for server in server_list:
remove_server_from_switch(server)
logger.info("OK : Removed %s", server)
# step 2 remove port
for port in port_list:
remove_ports_from_switch(port)
logger.info("OK : Removed port %s", port)
# step 3 exe... | 2015/01/19 | [
"https://Stackoverflow.com/questions/28031210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4471200/"
] | This is what context managers are for. Read up on the [with statement](https://docs.python.org/2/reference/compound_stmts.html#with) for details, but the general idea is you need to write context manager classes where the `__enter__` and `__exit__` functions do the removal/re-addition of your servers/ports. Then your c... | You should use a [with](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement) construct.
As [this link](https://realpython.com/python-with-statement/#the-with-statement-approach) explains:
```
with expression as target_var:
do_something(target_var)
```
>
> The context manager object resul... |
2,157,665 | I have created a templatetag that loads a yaml document into a python list. In my template I have `{% get_content_set %}`, this dumps the raw list data. What I want to be able to do is something like
```
{% for items in get_content_list %}
<h2>{{items.title}}</h2>
{% endfor %}`
``` | 2010/01/28 | [
"https://Stackoverflow.com/questions/2157665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/245889/"
] | If the list is in a python variable X, then add it to the template context `context['X'] = X` and then you can do
```
{% for items in X %}
{{ items.title }}
{% endfor %}
```
A template tag is designed to render output, so won't provide an iterable list for you to use. But you don't need that as the normal con... | Since writing complex templatetags is not an easy task (well documented though) i would take {% with %} tag source and adapt it for my needs, so it looks like
```
{% get_content_list as content %
{% for items in content %}
<h2>{{items.title}}</h2>
{% endfor %}`
``` |
58,578,181 | I'm try to create python package in **3.6** But I also want backward compatibility to **2.7** How can I write a code for **3.6** and **2.7**
For example I have method called `geo_point()`.
```
def geo_point(lat: float, lng: float):
pass
```
This function work fine in **3.6** but not in **2.7** it show syntax e... | 2019/10/27 | [
"https://Stackoverflow.com/questions/58578181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12280920/"
] | If type hinting is the only issue you have with your code, then look at SO question [Type hinting in Python 2](https://stackoverflow.com/questions/35230635/type-hinting-in-python-2)
It says, that python3 respects also type hinting in comment lines.
Python2 will ignore it and python3 respects this alternative syntax. I... | I doubt it's worth the trouble, but as a proof of concept: You could use a combination of a decorator and the built-in `exec()` function. Using `exec()` is a way to avoid syntax errors due to language differences.
Here's what I mean:
```
import sys
sys_vers_major, sys_vers_minor, sys_vers_micro = sys.version_info[:3... |
58,578,181 | I'm try to create python package in **3.6** But I also want backward compatibility to **2.7** How can I write a code for **3.6** and **2.7**
For example I have method called `geo_point()`.
```
def geo_point(lat: float, lng: float):
pass
```
This function work fine in **3.6** but not in **2.7** it show syntax e... | 2019/10/27 | [
"https://Stackoverflow.com/questions/58578181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12280920/"
] | If type hinting is the only issue you have with your code, then look at SO question [Type hinting in Python 2](https://stackoverflow.com/questions/35230635/type-hinting-in-python-2)
It says, that python3 respects also type hinting in comment lines.
Python2 will ignore it and python3 respects this alternative syntax. I... | >
> I think 2.7 not support type hinting
>
>
>
Actually, Python 2 supports type hinting, and you can write backwards-compatible code. See [the answer about Python 2 type hinting on StackOverflow](https://stackoverflow.com/a/35230792/3694363). |
58,578,181 | I'm try to create python package in **3.6** But I also want backward compatibility to **2.7** How can I write a code for **3.6** and **2.7**
For example I have method called `geo_point()`.
```
def geo_point(lat: float, lng: float):
pass
```
This function work fine in **3.6** but not in **2.7** it show syntax e... | 2019/10/27 | [
"https://Stackoverflow.com/questions/58578181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12280920/"
] | If type hinting is the only issue you have with your code, then look at SO question [Type hinting in Python 2](https://stackoverflow.com/questions/35230635/type-hinting-in-python-2)
It says, that python3 respects also type hinting in comment lines.
Python2 will ignore it and python3 respects this alternative syntax. I... | While the other answers emphasize type hinting, I'm thinking that the
**Six** package
may be of help. The project base and link to documentation is at <https://pypi.org/project/six/>.
>
> Six is a Python 2 and 3 compatibility library. It provides utility functions for smoothing over the differences between the Py... |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | There is a [`Queue`](http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue) class within the `multiprocessing` module specifically for this purpose.
Edit: If you are looking for a complete framework for parallel computing which features a `map()` function using a task queue, have a look at the para... | About queue implementations. There are some.
Look at the Celery project. <http://celeryproject.org/>
So, in your case, you can run 12 conversions (one on each CPU) as Celery tasks, add a callback function (to the conversion or to the task) and in that callback function add a new conversion task running when one of th... |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | This is trivial to do with [jug](http://luispedro.org/software/jug):
```
def process_image(img):
....
images = glob('*.jpg')
for im in images:
Task(process_image, im)
```
Now, just run `jug execute` a few times to spawn worker processes. | About queue implementations. There are some.
Look at the Celery project. <http://celeryproject.org/>
So, in your case, you can run 12 conversions (one on each CPU) as Celery tasks, add a callback function (to the conversion or to the task) and in that callback function add a new conversion task running when one of th... |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | About queue implementations. There are some.
Look at the Celery project. <http://celeryproject.org/>
So, in your case, you can run 12 conversions (one on each CPU) as Celery tasks, add a callback function (to the conversion or to the task) and in that callback function add a new conversion task running when one of th... | This is not the case if you use [`Pool.imap_unordered`](http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.imap_unordered). |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | There is a [`Queue`](http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue) class within the `multiprocessing` module specifically for this purpose.
Edit: If you are looking for a complete framework for parallel computing which features a `map()` function using a task queue, have a look at the para... | The Python threading library that has brought me most joy is [Parallel Python (PP)](http://www.parallelpython.com/). It is trivial with PP to use a thread pool approach with a single queue to achieve what you need. |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | There is a [`Queue`](http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue) class within the `multiprocessing` module specifically for this purpose.
Edit: If you are looking for a complete framework for parallel computing which features a `map()` function using a task queue, have a look at the para... | This is trivial to do with [jug](http://luispedro.org/software/jug):
```
def process_image(img):
....
images = glob('*.jpg')
for im in images:
Task(process_image, im)
```
Now, just run `jug execute` a few times to spawn worker processes. |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | There is a [`Queue`](http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue) class within the `multiprocessing` module specifically for this purpose.
Edit: If you are looking for a complete framework for parallel computing which features a `map()` function using a task queue, have a look at the para... | This is not the case if you use [`Pool.imap_unordered`](http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.imap_unordered). |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | This is trivial to do with [jug](http://luispedro.org/software/jug):
```
def process_image(img):
....
images = glob('*.jpg')
for im in images:
Task(process_image, im)
```
Now, just run `jug execute` a few times to spawn worker processes. | The Python threading library that has brought me most joy is [Parallel Python (PP)](http://www.parallelpython.com/). It is trivial with PP to use a thread pool approach with a single queue to achieve what you need. |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | The Python threading library that has brought me most joy is [Parallel Python (PP)](http://www.parallelpython.com/). It is trivial with PP to use a thread pool approach with a single queue to achieve what you need. | This is not the case if you use [`Pool.imap_unordered`](http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.imap_unordered). |
4,838,740 | Imagine that I have a model that describes the printers that an office has. They could be ready to work or not (maybe in the storage area or it has been bought but not still in th office ...). The model must have a field that represents the phisicaly location of the printer ("Secretary's office", "Reception", ... ). Th... | 2011/01/29 | [
"https://Stackoverflow.com/questions/4838740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/454760/"
] | This is trivial to do with [jug](http://luispedro.org/software/jug):
```
def process_image(img):
....
images = glob('*.jpg')
for im in images:
Task(process_image, im)
```
Now, just run `jug execute` a few times to spawn worker processes. | This is not the case if you use [`Pool.imap_unordered`](http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.imap_unordered). |
4,240,266 | I have a little module that creates a window (program1). I've imported this into another python program of mine (program2).
How do I make program 2 get self.x and x that's in program1?
This is program1.
```
import Tkinter
class Class(Tkinter.Tk):
def __init__(self, parent):
Tkinter.Tk.__init__(self, p... | 2010/11/21 | [
"https://Stackoverflow.com/questions/4240266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/433417/"
] | You can access the variable `self.x` as a member of an instance of `Class`:
```
c = Class(parent)
print(c.x)
```
You cannot access the local variable - it goes out of scope when the method call ends. | I'm not sure exactly what the purpose of 'self.x' and 'x' are but one thing to note in the 'Main' method of class Class
```
def Main(self):
self.button= Tkinter.Button(self,text='hello')
self.button.pack()
self.x = 34
x = 62
```
is that 'x' and 'self.x' are two different variables. T... |
6,372,159 | Can anyone suggest me what is the most pythonic way to import modules in python?
Let me explain - i have read a lot of python code and found several different ways of how to import modules or if to be more precise - when to import:
1. Use one module/several modules which include all the imports(third party modules) w... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6372159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781150/"
] | It *really* doesn't matter, so long as you don't `from ... import *`. The rest is all taste and getting around cyclic import issues. [PEP 8](http://www.python.org/dev/peps/pep-0008/) states that you should import at the top of the script, but even that isn't set in stone. | Python's "import" loads a Python module into its own namespace, so that you have to add the module name followed by a dot in front of references to any names from the imported module
```
import animals
animals.Elephant()
```
"from" loads a Python module into the current namespace, so that you can refer to it without... |
6,372,159 | Can anyone suggest me what is the most pythonic way to import modules in python?
Let me explain - i have read a lot of python code and found several different ways of how to import modules or if to be more precise - when to import:
1. Use one module/several modules which include all the imports(third party modules) w... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6372159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781150/"
] | It *really* doesn't matter, so long as you don't `from ... import *`. The rest is all taste and getting around cyclic import issues. [PEP 8](http://www.python.org/dev/peps/pep-0008/) states that you should import at the top of the script, but even that isn't set in stone. | People have already commented on the major style issues (at the top of the script, etc), so I'll skip that.
For my imports, I usually have them ordered alphabetically by module name (regardless of whether it's 'import' or 'from ... import ...'. I split it into groups of: standard lib; third party modules (from pypi or... |
6,372,159 | Can anyone suggest me what is the most pythonic way to import modules in python?
Let me explain - i have read a lot of python code and found several different ways of how to import modules or if to be more precise - when to import:
1. Use one module/several modules which include all the imports(third party modules) w... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6372159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781150/"
] | It *really* doesn't matter, so long as you don't `from ... import *`. The rest is all taste and getting around cyclic import issues. [PEP 8](http://www.python.org/dev/peps/pep-0008/) states that you should import at the top of the script, but even that isn't set in stone. | Do not use `from module import *`. This will pollute the namespace and is highly frowned upon. However, you can import specific things using from; `from module import something`. This keeps the namespace clean. On larger projects if you use a wildcard you could be importing 2 foo or 2 bar into the same namespace.
[PEP... |
6,372,159 | Can anyone suggest me what is the most pythonic way to import modules in python?
Let me explain - i have read a lot of python code and found several different ways of how to import modules or if to be more precise - when to import:
1. Use one module/several modules which include all the imports(third party modules) w... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6372159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781150/"
] | People have already commented on the major style issues (at the top of the script, etc), so I'll skip that.
For my imports, I usually have them ordered alphabetically by module name (regardless of whether it's 'import' or 'from ... import ...'. I split it into groups of: standard lib; third party modules (from pypi or... | Python's "import" loads a Python module into its own namespace, so that you have to add the module name followed by a dot in front of references to any names from the imported module
```
import animals
animals.Elephant()
```
"from" loads a Python module into the current namespace, so that you can refer to it without... |
6,372,159 | Can anyone suggest me what is the most pythonic way to import modules in python?
Let me explain - i have read a lot of python code and found several different ways of how to import modules or if to be more precise - when to import:
1. Use one module/several modules which include all the imports(third party modules) w... | 2011/06/16 | [
"https://Stackoverflow.com/questions/6372159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781150/"
] | People have already commented on the major style issues (at the top of the script, etc), so I'll skip that.
For my imports, I usually have them ordered alphabetically by module name (regardless of whether it's 'import' or 'from ... import ...'. I split it into groups of: standard lib; third party modules (from pypi or... | Do not use `from module import *`. This will pollute the namespace and is highly frowned upon. However, you can import specific things using from; `from module import something`. This keeps the namespace clean. On larger projects if you use a wildcard you could be importing 2 foo or 2 bar into the same namespace.
[PEP... |
50,105,459 | Hello i have been playing around with python recently and have been trying to learn how to control external peripherals and i/o ports on my laptop.
I have been trying to disable USB ports and disable my network adapter. However when i run my program it does not work. The code does not have a specific syntax error but ... | 2018/04/30 | [
"https://Stackoverflow.com/questions/50105459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7802263/"
] | I think you should try to run such commands as admin in windows. This might help: <https://social.technet.microsoft.com/Forums/windows/en-US/05cce5f6-3c3a-4bb8-8b72-8c1ce4b5eff1/how-to-run-a-program-as-adminitrator-via-the-command-line?forum=w7itproappcompat>
You can also modify your command to print the output in std... | I found the issue with the code. to start with i was using the `subprocess.call` function however trying to run the program with Administrator through python do it through command prompt and use this line of code instead
```
subprocess.run(["powershell","Disable-NetAdapter -Name '*'"])
```
Note\* Yes i changed from ... |
67,915,722 | I am fighiting with some listing all possibilities of command with optional and mandatory parameters in python. I need it to generate some autocomplete script in bash based on help output from some script.
E.g. fictional command:
```
add disk -pool <name> { -diskid <diskid> | -diskid auto [-fx | -tdr] } [-fx] [-statu... | 2021/06/10 | [
"https://Stackoverflow.com/questions/67915722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11387742/"
] | The question is pretty lacking on what exactly wants to be retrieved from Kubernetes but I think I can provide a good baseline.
When you use Kubernetes, you are most probably using `kubectl` to interact with `kubeapi-server`.
Some of the commands you can use to retrieve the information from the cluster:
* `$ kubectl... | If you want to extract just single values, perhaps as part of scripts, then what you are searching for is `-ojsonpath` such as this example:
```
kubectl get svc service-name -ojsonpath='{.spec.ports[0].port}'
```
which will extract jus the value of the first port listed into the service **specs**.
docs - <https://k... |
35,934,735 | I'd like to bind a class method to the object instance so that when the method is invoke as callback it can still access the object instance. I am using an event emitter to generate and fire events.
This is my code:
```
#!/usr/bin/env python3
from pyee import EventEmitter
class Component(object):
_emiter = Event... | 2016/03/11 | [
"https://Stackoverflow.com/questions/35934735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1022525/"
] | Get start day && end day:
```
$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");
echo $startDate->format('Y-m-d H:i:s');
return dd($endDate);
``` | change your output to:
```
echo $StartDate->format('Y-m-d H:i:s');
```
Here's a list of all the formatting characters that can be used to customize your output [Link](http://www.w3schools.com/php/func_date_date.asp) |
63,345,326 | I am new to OPC-UA and Eclipse Milo and I am trying to construct a client that can connect to the OPC-UA server of a machine we have just acquired.
I have been able to set up a simple OPC-UA server on my laptop by using this python tutorial series: <https://www.youtube.com/watch?v=NbKeBfK3pfk>. Additionally, I have be... | 2020/08/10 | [
"https://Stackoverflow.com/questions/63345326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8381207/"
] | I see a couple things to try.
First, make sure to set your custom js file to have 'slick-js' as a dependancy. This way it loads *after* slick slider does.
Also, jquery is already part of wordpress, so you **do not** need to enque it again. However, it should be a dependancy for both your custom script and slick:
```... | Thank you very much, now it finally works. One other thing that I that I was not aware of, was that I was to replace the $ with jQuery, so my custom.js looks like this:
```
`jQuery('.slider').slick({
arrows: false,
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
... |
43,037,588 | I have a CSV file in the same directory as my Python script, and I would like to take that data and turn it into a list that I can use later. I would prefer to use Python's CSV module. After reading the the module's documentation and questions regarding it, I have still not found any help.
### Code
```
#!/usr/bin/env... | 2017/03/27 | [
"https://Stackoverflow.com/questions/43037588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6417530/"
] | You need to open the file in read mode, read the contents!
That is,
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
inputfile = 'inputfile.csv'
inputm = []
with open(inputfile, "rb") as f:
reader = csv.reader(f, delimiter="\t")
for row in reader:
inputm.append(row)
```
Output:
```
[['... | You actually need to `open()` the file:
```
inputfile = open('inputfile.csv')
```
You may want to look at the `with` statement:
```
with open('inputfile.csv') as inputfile:
reader = csv.reader(inputfile)
inputm = list(reader)
``` |
11,306,641 | Here on SO people sometimes say something like "you cannot parse X with regular expressions, because X is not a regular language". From my understanding however, modern regular expressions engines can match more than just regular languages in [Chomsky's sense](http://en.wikipedia.org/wiki/Chomsky_hierarchy). My questio... | 2012/07/03 | [
"https://Stackoverflow.com/questions/11306641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/989121/"
] | Modern regex engines can certainly parse a bigger set of languages than the regular languages set. So said, none of the four classic Chomsky sets are exactly recognized by regexes. All regular languages are clearly recognized by regexes. There are some classic context-free languages that cannot be recognized by regexes... | You can read about regexes in *[An Introduction to Language And Linguistics
By Ralph W. Fasold, Jeff Connor-Linton P.477](http://books.google.com/books?id=dlzthEZGkmsC&pg=PA477#v=onepage&q&f=false)*
**Chomsky Hierarchy**:
Type0 >= Type1 >= Type2 >= Type3
Computational Linguistics mainly features Type 2 & 3 Grammars... |
11,306,641 | Here on SO people sometimes say something like "you cannot parse X with regular expressions, because X is not a regular language". From my understanding however, modern regular expressions engines can match more than just regular languages in [Chomsky's sense](http://en.wikipedia.org/wiki/Chomsky_hierarchy). My questio... | 2012/07/03 | [
"https://Stackoverflow.com/questions/11306641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/989121/"
] | I recently wrote a rather long article on this topic: [The true power of regular expressions](http://nikic.github.com/2012/06/15/The-true-power-of-regular-expressions.html).
To summarize:
* Regular expressions with support for recursive subpattern references can match *all* context-free languages (e.g `a^n b^n`).
* R... | Modern regex engines can certainly parse a bigger set of languages than the regular languages set. So said, none of the four classic Chomsky sets are exactly recognized by regexes. All regular languages are clearly recognized by regexes. There are some classic context-free languages that cannot be recognized by regexes... |
11,306,641 | Here on SO people sometimes say something like "you cannot parse X with regular expressions, because X is not a regular language". From my understanding however, modern regular expressions engines can match more than just regular languages in [Chomsky's sense](http://en.wikipedia.org/wiki/Chomsky_hierarchy). My questio... | 2012/07/03 | [
"https://Stackoverflow.com/questions/11306641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/989121/"
] | I recently wrote a rather long article on this topic: [The true power of regular expressions](http://nikic.github.com/2012/06/15/The-true-power-of-regular-expressions.html).
To summarize:
* Regular expressions with support for recursive subpattern references can match *all* context-free languages (e.g `a^n b^n`).
* R... | You can read about regexes in *[An Introduction to Language And Linguistics
By Ralph W. Fasold, Jeff Connor-Linton P.477](http://books.google.com/books?id=dlzthEZGkmsC&pg=PA477#v=onepage&q&f=false)*
**Chomsky Hierarchy**:
Type0 >= Type1 >= Type2 >= Type3
Computational Linguistics mainly features Type 2 & 3 Grammars... |
34,722,459 | Is there a way to generate a file on HDFS directly?
I want to avoid generating a local file and then over hdfs command line like:
`hdfs dfs -put - "file_name.csv"` to copy to HDFS.
Or is there any python library? | 2016/01/11 | [
"https://Stackoverflow.com/questions/34722459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5773478/"
] | Have you tried with [HdfsCli](http://hdfscli.readthedocs.org/en/latest/quickstart.html)?
To quote the paragraph [Reading and Writing files](http://hdfscli.readthedocs.org/en/latest/quickstart.html#reading-and-writing-files):
```
# Loading a file in memory.
with client.read('features') as reader:
features = reader.r... | Is extremly slow when I use hdfscli the write method?
Is there an any way to speedup with using hdfscli?
```
with client.write(conf.hdfs_location+'/'+ conf.filename, encoding='utf-8', buffersize=10000000) as f:
writer = csv.writer(f, delimiter=conf.separator)
for i in tqdm(10000000000):
row = [column.get_value() f... |
34,722,459 | Is there a way to generate a file on HDFS directly?
I want to avoid generating a local file and then over hdfs command line like:
`hdfs dfs -put - "file_name.csv"` to copy to HDFS.
Or is there any python library? | 2016/01/11 | [
"https://Stackoverflow.com/questions/34722459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5773478/"
] | Have you tried with [HdfsCli](http://hdfscli.readthedocs.org/en/latest/quickstart.html)?
To quote the paragraph [Reading and Writing files](http://hdfscli.readthedocs.org/en/latest/quickstart.html#reading-and-writing-files):
```
# Loading a file in memory.
with client.read('features') as reader:
features = reader.r... | `hdfs dfs -put` does not require yo to create a file on local. Also, no need of creating a zero byte file on hdfs (`touchz`) and append to it (`appendToFile`). You can directly write a file on hdfs as:
```
hadoop fs -put - /user/myuser/testfile
```
Hit enter. On the command prompt, enter the text you want to put in ... |
34,722,459 | Is there a way to generate a file on HDFS directly?
I want to avoid generating a local file and then over hdfs command line like:
`hdfs dfs -put - "file_name.csv"` to copy to HDFS.
Or is there any python library? | 2016/01/11 | [
"https://Stackoverflow.com/questions/34722459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5773478/"
] | Have you tried with [HdfsCli](http://hdfscli.readthedocs.org/en/latest/quickstart.html)?
To quote the paragraph [Reading and Writing files](http://hdfscli.readthedocs.org/en/latest/quickstart.html#reading-and-writing-files):
```
# Loading a file in memory.
with client.read('features') as reader:
features = reader.r... | Two ways of write local files to hdfs using python:
One way is using hdfs python package:
**Code snippet:**
```
from hdfs import InsecureClient
hdfsclient = InsecureClient('http://localhost:50070', user='madhuc')
hdfspath="/user/madhuc/hdfswritedata/"
localpath="/home/madhuc/sample.csv"
hdfsclient.upload(hdfspath, l... |
63,170,922 | Is there a way to **try to** decode a bytearray without raising an error if the encoding fails?
**EDIT**: The solution needn't use bytearray.decode(...). Anything library (preferably standard) that does the job would be great.
**Note**: I don't want to ignore errors, (which I could do using `bytearray.decode(errors='... | 2020/07/30 | [
"https://Stackoverflow.com/questions/63170922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4093278/"
] | You could use the [suppress](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) context manager to suppress the exception and have slightly prettier code than with try/except/pass:
```py
import contextlib
...
return_val = None
with contextlib.suppress(UnicodeDecodeError):
return_val = my_bytear... | The `chardet` module can be used to detect the encoding of a bytearray before calling `bytearray.decode(...)`.
**The Code:**
```py
import chardet
identity = chardet.detect(my_bytearray)
```
The method `chardet.detect(...)` returns a dictionary with the following format:
```
{
'confidence': 0.99,
'encoding': 'a... |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | It's better to use android latest versions. But you can resolve by replace below code in your `app/build.gradle` file
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
Dependencies as follows:
```
compile ... | I have just used Maven google repository in build.gradle(project) :
```
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.google.com'
}
}
... |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | Update your android studio to the latest version. | Maybe it is because of your minimal SDK version, and you need to migrate to AndroidX as SDK does not support legacy support components |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | Follow these steps:
1. update version of build tools and dependences in buyild.gradle(Module)
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
and dependences
```
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.a... | I have just used Maven google repository in build.gradle(project) :
```
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.google.com'
}
}
... |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | It's better to use android latest versions. But you can resolve by replace below code in your `app/build.gradle` file
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
Dependencies as follows:
```
compile ... | Make sure you have `compile 'com.android.support:appcompat-v7:25.1.0` in your `app/build.gradle`. |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | It's better to use android latest versions. But you can resolve by replace below code in your `app/build.gradle` file
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
Dependencies as follows:
```
compile ... | Maybe it is because of your minimal SDK version, and you need to migrate to AndroidX as SDK does not support legacy support components |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | It's better to use android latest versions. But you can resolve by replace below code in your `app/build.gradle` file
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
Dependencies as follows:
```
compile ... | Update your Android Studio to the latest version to resolve |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | I have just used Maven google repository in build.gradle(project) :
```
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.google.com'
}
}
... | Make sure you have `compile 'com.android.support:appcompat-v7:25.1.0` in your `app/build.gradle`. |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | Follow these steps:
1. update version of build tools and dependences in buyild.gradle(Module)
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
and dependences
```
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.a... | Update your Android Studio to the latest version to resolve |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | I have just used Maven google repository in build.gradle(project) :
```
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.google.com'
}
}
... | Maybe it is because of your minimal SDK version, and you need to migrate to AndroidX as SDK does not support legacy support components |
41,801,225 | I'm very new to python. I am writing code to generate an array of number but the output is not as I want.
The code is as follows
```
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3:... | 2017/01/23 | [
"https://Stackoverflow.com/questions/41801225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7456346/"
] | Update your android studio to the latest version. | It's better to use android latest versions. But you can resolve by replace below code in your `app/build.gradle` file
```
android {
compileSdkVersion 24
buildToolsVersion "24.2.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 24
...
}
```
Dependencies as follows:
```
compile ... |
70,771,156 | I've converted my python script with tkinter module to a standalone executable file with PyInstaller but it doesn't work without image.png file in the same patch. How I can add this .png file to my app. And why .exe file have an enormous weight of ~350 Mb? | 2022/01/19 | [
"https://Stackoverflow.com/questions/70771156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17971397/"
] | I had the exact same situation with Tkinter and a single image needed in the GUI.
I combined Aleksandr Tyshkevich answer here and Jonathon Reinhart's answer here [Pyinstaller adding data files](https://stackoverflow.com/questions/41870727/pyinstaller-adding-data-files) as I need to send just the exe file to others, so... | It works:
```py
import os
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
path = resource_path("image.png")
photo = tk.PhotoImage(file=path)
``` |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | Okay. Let start from simple.
First you need get unique user\_id/dev id combinations
```
select distinct dev_id,user_id from reports
```
Result will be
```
dev_id user_id
------------------
111 1
222 2
111 2
333 3
```
After that you should get number of diffe... | I think following sql query should solve you problem:
```
SELECT t1.user_id, t1.dev_id, count(t2.user_id) as qu
FROM (Select Distinct * from reports) t1
Left Join (Select Distinct * from reports) t2
on t1.user_id != t2.user_id and t2.dev_id = t1.dev_id
group by t1.user_Id, t1.dev_id
```
[SQL Fiddle Link](http://sql... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | I think following sql query should solve you problem:
```
SELECT t1.user_id, t1.dev_id, count(t2.user_id) as qu
FROM (Select Distinct * from reports) t1
Left Join (Select Distinct * from reports) t2
on t1.user_id != t2.user_id and t2.dev_id = t1.dev_id
group by t1.user_Id, t1.dev_id
```
[SQL Fiddle Link](http://sql... | Try
```
SELECT
user_id,
SUM(qu) AS qu
FROM (
SELECT
user_id,
count(*)-1 AS qu
FROM
reports
GROUP BY user_id, dev_id
) AS r
GROUP BY user_id
```
No need to do a join if all the data you need is in one table.
Edit: changed the group by to dev\_id instead of user\_id
Edit... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | You can get results by doing:
```
select r.user_id, count(*) - 1
from reports r
group by r.user_id;
```
Is this the calculation that you want? | I think following sql query should solve you problem:
```
SELECT t1.user_id, t1.dev_id, count(t2.user_id) as qu
FROM (Select Distinct * from reports) t1
Left Join (Select Distinct * from reports) t2
on t1.user_id != t2.user_id and t2.dev_id = t1.dev_id
group by t1.user_Id, t1.dev_id
```
[SQL Fiddle Link](http://sql... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | Your query is broken and would not run on many systems. The problem is that the group with `user_id` of 2 has two different `dev_id`s. If you run the "broken query" below you can see that the `min()` and `max()` are distinct but the subquery only sees one of those values which is randomly chosen. The last query is corr... | Try
```
SELECT
user_id,
SUM(qu) AS qu
FROM (
SELECT
user_id,
count(*)-1 AS qu
FROM
reports
GROUP BY user_id, dev_id
) AS r
GROUP BY user_id
```
No need to do a join if all the data you need is in one table.
Edit: changed the group by to dev\_id instead of user\_id
Edit... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | Okay. Let start from simple.
First you need get unique user\_id/dev id combinations
```
select distinct dev_id,user_id from reports
```
Result will be
```
dev_id user_id
------------------
111 1
222 2
111 2
333 3
```
After that you should get number of diffe... | Your query is broken and would not run on many systems. The problem is that the group with `user_id` of 2 has two different `dev_id`s. If you run the "broken query" below you can see that the `min()` and `max()` are distinct but the subquery only sees one of those values which is randomly chosen. The last query is corr... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | Okay. Let start from simple.
First you need get unique user\_id/dev id combinations
```
select distinct dev_id,user_id from reports
```
Result will be
```
dev_id user_id
------------------
111 1
222 2
111 2
333 3
```
After that you should get number of diffe... | ```
SELECT user_id, (COUNT(user_id) -1) as qu
FROM reports
GROUP BY user_id
```
This would give desired result in your case, however you can improve it a lot more.
Cheers,, |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | Okay. Let start from simple.
First you need get unique user\_id/dev id combinations
```
select distinct dev_id,user_id from reports
```
Result will be
```
dev_id user_id
------------------
111 1
222 2
111 2
333 3
```
After that you should get number of diffe... | Try
```
SELECT
user_id,
SUM(qu) AS qu
FROM (
SELECT
user_id,
count(*)-1 AS qu
FROM
reports
GROUP BY user_id, dev_id
) AS r
GROUP BY user_id
```
No need to do a join if all the data you need is in one table.
Edit: changed the group by to dev\_id instead of user\_id
Edit... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | ```
SELECT user_id, (COUNT(user_id) -1) as qu
FROM reports
GROUP BY user_id
```
This would give desired result in your case, however you can improve it a lot more.
Cheers,, | Try
```
SELECT
user_id,
SUM(qu) AS qu
FROM (
SELECT
user_id,
count(*)-1 AS qu
FROM
reports
GROUP BY user_id, dev_id
) AS r
GROUP BY user_id
```
No need to do a join if all the data you need is in one table.
Edit: changed the group by to dev\_id instead of user\_id
Edit... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | You can get results by doing:
```
select r.user_id, count(*) - 1
from reports r
group by r.user_id;
```
Is this the calculation that you want? | Your query is broken and would not run on many systems. The problem is that the group with `user_id` of 2 has two different `dev_id`s. If you run the "broken query" below you can see that the `min()` and `max()` are distinct but the subquery only sees one of those values which is randomly chosen. The last query is corr... |
34,712,248 | Trying to download the website with python, but getting errors. My intention is to download the website, extract relevant information from it using python, save result to another file on my hard disk. Having trouble on step 1. Other steps were working until some strange SSL error. I am using python 2.7
```
import urll... | 2016/01/10 | [
"https://Stackoverflow.com/questions/34712248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5771257/"
] | You can get results by doing:
```
select r.user_id, count(*) - 1
from reports r
group by r.user_id;
```
Is this the calculation that you want? | Try
```
SELECT
user_id,
SUM(qu) AS qu
FROM (
SELECT
user_id,
count(*)-1 AS qu
FROM
reports
GROUP BY user_id, dev_id
) AS r
GROUP BY user_id
```
No need to do a join if all the data you need is in one table.
Edit: changed the group by to dev\_id instead of user\_id
Edit... |
45,510,287 | I want to split long math equation by multipliers.
The expression is given as a string where whitespaces are allowed.
For example:
```
"((a*b>0) * (e>500)) * (abs(j)>2.0) * (n>1)"
```
Should return:
```
['a*b>0', 'e>500', 'abs(j)>2.0', 'n>1']
```
If the division is used things get even more complicated, but let... | 2017/08/04 | [
"https://Stackoverflow.com/questions/45510287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3152072/"
] | ```
import re
string = "((a-b>0) * (e + 10>500)) * (abs(j)>2.0) * (n>1)"
signals = {'+','*','/','-'}
###
##
def splitString(string):
arr_equations = re.split(''([\)]+(\*|\-|\+|\/)+[\(])'',string.replace(" ", ""))
new_array = []
for each_equa in arr_equations:
each_equa = each_equa.strip("()")... | You can simply use the `split()` function:
```
ans_list = your_string.split(" * ")
```
Note the spaces around the multiplier sign. This assumes that your string is exactly as you say. |
45,510,287 | I want to split long math equation by multipliers.
The expression is given as a string where whitespaces are allowed.
For example:
```
"((a*b>0) * (e>500)) * (abs(j)>2.0) * (n>1)"
```
Should return:
```
['a*b>0', 'e>500', 'abs(j)>2.0', 'n>1']
```
If the division is used things get even more complicated, but let... | 2017/08/04 | [
"https://Stackoverflow.com/questions/45510287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3152072/"
] | ```
import re
string = "((a-b>0) * (e + 10>500)) * (abs(j)>2.0) * (n>1)"
signals = {'+','*','/','-'}
###
##
def splitString(string):
arr_equations = re.split(''([\)]+(\*|\-|\+|\/)+[\(])'',string.replace(" ", ""))
new_array = []
for each_equa in arr_equations:
each_equa = each_equa.strip("()")... | you can use regex:
```
s = "((a*b>0) * (e>500)) * (abs(j)>2.0) * (n>1)"
s = ''.join(s.split())
s = re.split(r'([\)]+[\*\+\-/\^]+[\(])', s)
res = []
for x in s:
x = re.sub(r'(^[\(\)\*\+\-\/]+)', '', x)
x = re.sub(r'([\(\)]+$)', '', x)
if len(x) > 0: res.append(x)
print(res)
``` |
57,302,048 | How to Fix this error? I tried visiting all the forums searching for answers to rectify this issue.
Here i am trying to perform multi-label classification using keras
```
from keras.preprocessing.text import Tokenizer
from keras.models import Sequential
from keras.layers import Dense
from keras.preprocessing.sequenc... | 2019/08/01 | [
"https://Stackoverflow.com/questions/57302048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11050535/"
] | Adding an index along the lines of the following might help the performance:
```
CREATE INDEX idx ON table_e (Phone_number, bill_date, col1, col2);
```
Here `col1` and `col2` are the other two columns which might appear in the `SELECT` clause. The strategy of this index, if used, would be to scan the relatively smal... | If you can update then it is better to create `index` on `a.invoice_date` and . Please find the [link](https://dev.mysql.com/doc/refman/8.0/en/index-hints.html) for the same. |
26,535,493 | I wrote a custom python module. It consists of several functions divided thematically between 3 .py files, which are all in the same directory called `microbiome` in my home directory. So the whole path to my custom module directory is:
```
/Users/drosophila/microbiome
```
I'm working on OsX Mavericks. I want to imp... | 2014/10/23 | [
"https://Stackoverflow.com/questions/26535493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1954277/"
] | The *right* way to do this, as explained in the [Python Packaging User Guide](https://packaging.python.org/en/latest/), is to create a `setup.py`-based project.
Then, you can just install your code for any particular Python installation (or virtual environment) by using, e.g., `pip3 install .` from the root directory ... | As you've discovered, `/etc/paths` affects `$PATH`. But `$PATH` does not affect where Python looks for modules. Try `$PYTHONPATH` instead. See `man python` for details. |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | Disclaimer: I'm on the PlaidML team, and we're actively working to improve the setup experience and documentation around it. We're sorry you were stuck on this. For now, here's some instructions to get you back on track.
1. Find out where plaidml-setup was installed. Typically, this is some variant of `/usr/local/bin`... | I'm facing the same problem and answers online are not very helpful. In this case, I'd suggest debugging yourself.
Since this is where the problem is:
```
File "/usr/local/lib/python3.7/site-packages/plaidml/settings.py", line 30, in _setup_config
'Could not find PlaidML configuration file: "{}".'.format(filename))
... |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | Disclaimer: I'm on the PlaidML team, and we're actively working to improve the setup experience and documentation around it. We're sorry you were stuck on this. For now, here's some instructions to get you back on track.
1. Find out where plaidml-setup was installed. Typically, this is some variant of `/usr/local/bin`... | As I wrote here: <https://superuser.com/questions/1404114/traceback-error-during-plaidml-installation/1488059#1488059>
the file `plaidml/settings.py` uses variable `sys.prefix` which for a reason has wrong value for my system: it contains `/usr` instead of `~/.local` so it tries to load `/usr/share/plaidml/experimenta... |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | Disclaimer: I'm on the PlaidML team, and we're actively working to improve the setup experience and documentation around it. We're sorry you were stuck on this. For now, here's some instructions to get you back on track.
1. Find out where plaidml-setup was installed. Typically, this is some variant of `/usr/local/bin`... | **Within the plaidml share directory, there should be a few files: at a minimum, config.json and experimental.json**
usr/local/lib/python3.8/site-packages/plaidml
++
do the followings:
**export PLAIDML\_NATIVE\_PATH=/usr/local/lib/libplaidml.dylib
export RUNFILES\_DIR=/usr/local/share/plaidml.** |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | You need to set **plaidml** and **libplaidml.dylib** path correctly in environment.
Possible paths for **plaidml**
1. `/Library/Frameworks/Python.framework/Versions/3.7/share/plaidml`
2. `/usr/local/share/plaidml`
3. Some other location. Search it.
Possible paths for **libplaidml.dylib**
1. `/Library/Frameworks/Pyt... | I'm facing the same problem and answers online are not very helpful. In this case, I'd suggest debugging yourself.
Since this is where the problem is:
```
File "/usr/local/lib/python3.7/site-packages/plaidml/settings.py", line 30, in _setup_config
'Could not find PlaidML configuration file: "{}".'.format(filename))
... |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | You need to set **plaidml** and **libplaidml.dylib** path correctly in environment.
Possible paths for **plaidml**
1. `/Library/Frameworks/Python.framework/Versions/3.7/share/plaidml`
2. `/usr/local/share/plaidml`
3. Some other location. Search it.
Possible paths for **libplaidml.dylib**
1. `/Library/Frameworks/Pyt... | As I wrote here: <https://superuser.com/questions/1404114/traceback-error-during-plaidml-installation/1488059#1488059>
the file `plaidml/settings.py` uses variable `sys.prefix` which for a reason has wrong value for my system: it contains `/usr` instead of `~/.local` so it tries to load `/usr/share/plaidml/experimenta... |
56,973,032 | So I am trying to install plaidML-keras so I can do tensor-flow stuff on my MacBookPro's gpu (radeon pro 560x). From my research, it can be done using plaidML-Keras ([instalation instrutions](https://github.com/plaidml/plaidml/blob/master/docs/install.rst#macos)). When I run `pip install -U plaidml-keras` it works fine... | 2019/07/10 | [
"https://Stackoverflow.com/questions/56973032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8565630/"
] | You need to set **plaidml** and **libplaidml.dylib** path correctly in environment.
Possible paths for **plaidml**
1. `/Library/Frameworks/Python.framework/Versions/3.7/share/plaidml`
2. `/usr/local/share/plaidml`
3. Some other location. Search it.
Possible paths for **libplaidml.dylib**
1. `/Library/Frameworks/Pyt... | **Within the plaidml share directory, there should be a few files: at a minimum, config.json and experimental.json**
usr/local/lib/python3.8/site-packages/plaidml
++
do the followings:
**export PLAIDML\_NATIVE\_PATH=/usr/local/lib/libplaidml.dylib
export RUNFILES\_DIR=/usr/local/share/plaidml.** |
16,580,285 | I am writing a python script to keep a buggy program open and I need to figure out if the program is not respoding and close it on windows. I can't quite figure out how to do this. | 2013/05/16 | [
"https://Stackoverflow.com/questions/16580285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2125510/"
] | On Windows you can do this:
```
import os
def isresponding(name):
os.system('tasklist /FI "IMAGENAME eq %s" /FI "STATUS eq running" > tmp.txt' % name)
tmp = open('tmp.txt', 'r')
a = tmp.readlines()
tmp.close()
if a[-1].split()[0] == name:
return True
else:
return False
```
It ... | Piling up on the awesome answer from @Saullo GP Castro, this is a version using `subprocess.Popen` instead of `os.system` to avoid creating a temporary file.
```py
import subprocess
def isresponding(name):
"""Check if a program (based on its name) is responding"""
cmd = 'tasklist /FI "IMAGENAME eq %s" /FI "ST... |
5,230,699 | ```
gardai-plan-crackdown-on-troublemakers-at-protest-2438316.html': {'dail': 1, 'focus': 1, 'actions': 1, 'trade': 2, 'protest': 1, 'identify': 1, 'previous': 1, 'detectives': 1, 'republican': 1, 'group': 1, 'monitor': 1, 'clashes': 1, 'civil': 1, 'charge': 1, 'breaches': 1, 'travelling': 1, 'main': 1, 'disrupt': 1, '... | 2011/03/08 | [
"https://Stackoverflow.com/questions/5230699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/515263/"
] | There are details on the [ARFF file format here](http://www.cs.waikato.ac.nz/~ml/weka/arff.html) and it's very simple to generate. For example, using a cut-down version of your Python dictionary, the following script:
```
import re
d = { 'gardai-plan-crackdown-on-troublemakers-at-protest-2438316.html':
{'dail'... | I know it's pretty easy to generate an arff file on your own, but I still wanted to make it simpler so I wrote a python package
<https://github.com/ubershmekel/arff>
It's also on pypi so `easy_install arff` |
5,230,699 | ```
gardai-plan-crackdown-on-troublemakers-at-protest-2438316.html': {'dail': 1, 'focus': 1, 'actions': 1, 'trade': 2, 'protest': 1, 'identify': 1, 'previous': 1, 'detectives': 1, 'republican': 1, 'group': 1, 'monitor': 1, 'clashes': 1, 'civil': 1, 'charge': 1, 'breaches': 1, 'travelling': 1, 'main': 1, 'disrupt': 1, '... | 2011/03/08 | [
"https://Stackoverflow.com/questions/5230699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/515263/"
] | There are details on the [ARFF file format here](http://www.cs.waikato.ac.nz/~ml/weka/arff.html) and it's very simple to generate. For example, using a cut-down version of your Python dictionary, the following script:
```
import re
d = { 'gardai-plan-crackdown-on-troublemakers-at-protest-2438316.html':
{'dail'... | [This project](https://github.com/renatopp/liac-arff) seems to be a bit more up to date. You can install it via
pip:
```
$ pip install liac-arff
```
or easy\_install:
```
$ easy_install liac-arff
``` |
5,230,699 | ```
gardai-plan-crackdown-on-troublemakers-at-protest-2438316.html': {'dail': 1, 'focus': 1, 'actions': 1, 'trade': 2, 'protest': 1, 'identify': 1, 'previous': 1, 'detectives': 1, 'republican': 1, 'group': 1, 'monitor': 1, 'clashes': 1, 'civil': 1, 'charge': 1, 'breaches': 1, 'travelling': 1, 'main': 1, 'disrupt': 1, '... | 2011/03/08 | [
"https://Stackoverflow.com/questions/5230699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/515263/"
] | I know it's pretty easy to generate an arff file on your own, but I still wanted to make it simpler so I wrote a python package
<https://github.com/ubershmekel/arff>
It's also on pypi so `easy_install arff` | [This project](https://github.com/renatopp/liac-arff) seems to be a bit more up to date. You can install it via
pip:
```
$ pip install liac-arff
```
or easy\_install:
```
$ easy_install liac-arff
``` |
18,507,559 | Since I too have also seen this question on SO, so this might be a duplicate for many, but I've not found an answer to this question.
I want select an item from the navigation bar and show the content inside another tag by replacing the current data with AJAX-generated data.
Currently I'm able to post the data into ... | 2013/08/29 | [
"https://Stackoverflow.com/questions/18507559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1162512/"
] | change it id
```
<div id="container-fluid"></div>
```
this is id selector `$("#container-fluid")`
[id-selector](http://api.jquery.com/id-selector/)
if you want to access by class you can use
`$(".container-fluid")`
[class-selector](http://api.jquery.com/class-selector/) | try
```
$("#nav_bar li").click(function(){
var text_input = $(this).text(); // works fine
$.ajax({
type: "POST", //able to post the data behind the scenes
url: "/dashboard/",
data : { 'which_nav_bar' : text_input }
success: function(result){
... |
18,507,559 | Since I too have also seen this question on SO, so this might be a duplicate for many, but I've not found an answer to this question.
I want select an item from the navigation bar and show the content inside another tag by replacing the current data with AJAX-generated data.
Currently I'm able to post the data into ... | 2013/08/29 | [
"https://Stackoverflow.com/questions/18507559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1162512/"
] | Change
```
$("#container-fluid").text(result);
```
to
```
$(".container-fluid").text(result);
```
`#` is used to access by `id` and `.` is used to access by `class` | try
```
$("#nav_bar li").click(function(){
var text_input = $(this).text(); // works fine
$.ajax({
type: "POST", //able to post the data behind the scenes
url: "/dashboard/",
data : { 'which_nav_bar' : text_input }
success: function(result){
... |
44,830,396 | I am parsing a websocket message and due do a bug in a specific socket.io version (Unfortunately I don't have control over the server side), some of the payload is double encoded as utf-8:
The correct value would be **Wrocławskiej** (note the l letter which is LATIN SMALL LETTER L WITH STROKE) but I actually get back ... | 2017/06/29 | [
"https://Stackoverflow.com/questions/44830396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3450689/"
] | You text was encoding to UTF-8, those bytes were then interpreted as ISO-8859-1 and re-encoded to UTF-8.
`Wrocławskiej` is unicode: 0057 0072 006f 0063 **0142** 0061 0077 0073 006b 0069 0065 006a
Encoding to UTF-8 it is: 57 72 6f 63 **c5 82** 61 77 73 6b 69 65 6a
In [ISO-8859-1](https://en.wikipedia.org/wiki/ISO/I... | Well, double encoding may not be the only issue to deal with. Here is a solution that counts for more then one reason
```
String myString = "heartbroken ð";
myString = new String(myString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
String cleanedText = StringEscapeUt... |
44,830,396 | I am parsing a websocket message and due do a bug in a specific socket.io version (Unfortunately I don't have control over the server side), some of the payload is double encoded as utf-8:
The correct value would be **Wrocławskiej** (note the l letter which is LATIN SMALL LETTER L WITH STROKE) but I actually get back ... | 2017/06/29 | [
"https://Stackoverflow.com/questions/44830396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3450689/"
] | You text was encoding to UTF-8, those bytes were then interpreted as ISO-8859-1 and re-encoded to UTF-8.
`Wrocławskiej` is unicode: 0057 0072 006f 0063 **0142** 0061 0077 0073 006b 0069 0065 006a
Encoding to UTF-8 it is: 57 72 6f 63 **c5 82** 61 77 73 6b 69 65 6a
In [ISO-8859-1](https://en.wikipedia.org/wiki/ISO/I... | I had the problem that sometimes I received double encoded strings and sometimes proper encoded strings. The following method fixDoubleUTF8Encoding will handle both properly:
```java
public static void main(String[] args) {
String input = "werewräüèö";
String result = fixDoubleUTF8Encoding(input);
System.out... |
44,830,396 | I am parsing a websocket message and due do a bug in a specific socket.io version (Unfortunately I don't have control over the server side), some of the payload is double encoded as utf-8:
The correct value would be **Wrocławskiej** (note the l letter which is LATIN SMALL LETTER L WITH STROKE) but I actually get back ... | 2017/06/29 | [
"https://Stackoverflow.com/questions/44830396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3450689/"
] | I had the problem that sometimes I received double encoded strings and sometimes proper encoded strings. The following method fixDoubleUTF8Encoding will handle both properly:
```java
public static void main(String[] args) {
String input = "werewräüèö";
String result = fixDoubleUTF8Encoding(input);
System.out... | Well, double encoding may not be the only issue to deal with. Here is a solution that counts for more then one reason
```
String myString = "heartbroken ð";
myString = new String(myString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
String cleanedText = StringEscapeUt... |
63,550,237 | Here z is a list of dict().
```
z = [{'loss': [1, 2, 2] , 'val_loss':[2,4,5], 'accuracy':[3,8,9], 'val_accuracy':[5,9,7]},
{'loss': [1, 2, 2] , 'val_loss':[2,4,5], 'accuracy':[3,8,9], 'val_accuracy':[5,9,7]},
{'loss': [1, 2, 2] , 'val_loss':[2,4,5], 'accuracy':[3,8,9], 'val_accuracy':[5,9,7]},
{'loss': ... | 2020/08/23 | [
"https://Stackoverflow.com/questions/63550237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3168982/"
] | The notation `a = b = c = d = []` assign a new list to `d`, then assign the 3 others variable to `d`, so you have 4 variables pointing to one same list, so you put 4\*10 items in the same list.
Do :
```
a, b, c, d = [], [], [], []
```
Using `map` and `itemgetter` you can do
```
from operator import itemgetter
los... | In python, when you create a variable, you are just creating a pointer to an object, and not a copy of the object. In this case, when you are initializing your list with `a = b = c = d = []`, you are actually making a, b, c, and d point to the same list instead of creating four different lists.
Take the following exam... |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Another alternative, with which I have no experience, is [ProMesh](http://www.codeplex.com/promesh). Personally, I moving to ASP.NET MVC. | One alternative that seems interesting is [MonoRail](http://www.castleproject.org/monorail/index.html) although I haven't tested it out fully. |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Personally I have tried both ASP.NET MVC and MonoRail by CastleProject. Although I really enjoy the other CastleProject libraries, I have found that I enjoy the ASP.NET MVC implementation model better than the CastleProject MonoRail model. Now that ASP.NET MVC has released that they will be including jQuery in with the... | One alternative that seems interesting is [MonoRail](http://www.castleproject.org/monorail/index.html) although I haven't tested it out fully. |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | We have used [MonoRail](http://www.castleproject.org/projects/monorail) RC2 for our small business's online store for the past 18 months. It replaced a 7 year old disaster of classic ASP pages. MonoRail RC2 has worked well for us, serving an average of ~14,000 page requests per day. It enabled me to develop the site ve... | One alternative that seems interesting is [MonoRail](http://www.castleproject.org/monorail/index.html) although I haven't tested it out fully. |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Personally I have tried both ASP.NET MVC and MonoRail by CastleProject. Although I really enjoy the other CastleProject libraries, I have found that I enjoy the ASP.NET MVC implementation model better than the CastleProject MonoRail model. Now that ASP.NET MVC has released that they will be including jQuery in with the... | Another alternative, with which I have no experience, is [ProMesh](http://www.codeplex.com/promesh). Personally, I moving to ASP.NET MVC. |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | We have used [MonoRail](http://www.castleproject.org/projects/monorail) RC2 for our small business's online store for the past 18 months. It replaced a 7 year old disaster of classic ASP pages. MonoRail RC2 has worked well for us, serving an average of ~14,000 page requests per day. It enabled me to develop the site ve... | Another alternative, with which I have no experience, is [ProMesh](http://www.codeplex.com/promesh). Personally, I moving to ASP.NET MVC. |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Another alternative, with which I have no experience, is [ProMesh](http://www.codeplex.com/promesh). Personally, I moving to ASP.NET MVC. | ASP.NET MVC should start to become more accepted as being mature in rapid fashion. Now that it is beta, and supposedly nearly feature complete, the rate at which people adopt it will continue to grow, and likely more sharply. With the RTM/RTW release promised to be in the near future, now is the best time to start to a... |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | We have used [MonoRail](http://www.castleproject.org/projects/monorail) RC2 for our small business's online store for the past 18 months. It replaced a 7 year old disaster of classic ASP pages. MonoRail RC2 has worked well for us, serving an average of ~14,000 page requests per day. It enabled me to develop the site ve... | Personally I have tried both ASP.NET MVC and MonoRail by CastleProject. Although I really enjoy the other CastleProject libraries, I have found that I enjoy the ASP.NET MVC implementation model better than the CastleProject MonoRail model. Now that ASP.NET MVC has released that they will be including jQuery in with the... |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Personally I have tried both ASP.NET MVC and MonoRail by CastleProject. Although I really enjoy the other CastleProject libraries, I have found that I enjoy the ASP.NET MVC implementation model better than the CastleProject MonoRail model. Now that ASP.NET MVC has released that they will be including jQuery in with the... | ASP.NET MVC should start to become more accepted as being mature in rapid fashion. Now that it is beta, and supposedly nearly feature complete, the rate at which people adopt it will continue to grow, and likely more sharply. With the RTM/RTW release promised to be in the near future, now is the best time to start to a... |
300,925 | So, I've spent enough time using ASP.NET webforms to know that I'd almost rather go back to doing classic ASP than use them. But I'm hesitant to move to ASP.NET MVC until it becomes more mature. Are there any open source alternatives?
The main thing I'm looking for is something that's easy to learn and to get a protot... | 2008/11/19 | [
"https://Stackoverflow.com/questions/300925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | We have used [MonoRail](http://www.castleproject.org/projects/monorail) RC2 for our small business's online store for the past 18 months. It replaced a 7 year old disaster of classic ASP pages. MonoRail RC2 has worked well for us, serving an average of ~14,000 page requests per day. It enabled me to develop the site ve... | ASP.NET MVC should start to become more accepted as being mature in rapid fashion. Now that it is beta, and supposedly nearly feature complete, the rate at which people adopt it will continue to grow, and likely more sharply. With the RTM/RTW release promised to be in the near future, now is the best time to start to a... |
44,183,891 | Hello community / developers,
I am currently trying to install SCIP with python and found that there is Windows Support and a pip installer based on <https://github.com/SCIP-Interfaces/PySCIPOpt/blob/master/INSTALL.md>.
Nevertheless I run into a problem "Cannot open include file"
Below is a list of the things I perf... | 2017/05/25 | [
"https://Stackoverflow.com/questions/44183891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7646564/"
] | This looks like a `UNION` of two `INNER JOIN`s. One gets the information from `stock` and has `NULL` values in the columns from `sales_item`, the other gets information from `sales_item` and has `NULL` for the columns from `stock`.
```
SELECT i.item_id, i.name, s.stock_id, s.quantity, NULL AS sales_item_id, NULL AS sa... | All the nulls in your example shows that you are trying to join together two completely different result sets: join the items with the stock and get all that data, then join the items with the sales and return all that data. The trickiness is that you have two different kinds of results in your desired join table. The ... |
17,053,103 | I saw [this question](https://stackoverflow.com/questions/903557/pythons-with-statement-versus-with-as), and I understand when you would want to use `with foo() as bar:`, but I don't understand when you would just want to do:
```
bar = foo()
with bar:
....
```
Doesn't that just remove the tear-down benefits of us... | 2013/06/11 | [
"https://Stackoverflow.com/questions/17053103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1388603/"
] | For example when you want to use `Lock()`:
```
from threading import Lock
myLock = Lock()
with myLock:
...
```
You don't really need the `Lock()` object. You just need to know that it is on. | Using `with` without `as` still gets you the exact same teardown; it just doesn't get you a new local object representing the context.
The reason you want this is that sometimes the context itself isn't directly useful—in other words, you're only using it for the side effects of its context enter and exit.
For exampl... |
17,053,103 | I saw [this question](https://stackoverflow.com/questions/903557/pythons-with-statement-versus-with-as), and I understand when you would want to use `with foo() as bar:`, but I don't understand when you would just want to do:
```
bar = foo()
with bar:
....
```
Doesn't that just remove the tear-down benefits of us... | 2013/06/11 | [
"https://Stackoverflow.com/questions/17053103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1388603/"
] | To expand a bit on @freakish's answer, `with` guarantees entry into and then exit from a "context". What the heck is a context? Well, it's "whatever the thing you're with-ing makes it". Some obvious ones are:
* locks: you take a lock, manipulate some data, and release the lock.
* external files/streams: you open a fil... | For example when you want to use `Lock()`:
```
from threading import Lock
myLock = Lock()
with myLock:
...
```
You don't really need the `Lock()` object. You just need to know that it is on. |
17,053,103 | I saw [this question](https://stackoverflow.com/questions/903557/pythons-with-statement-versus-with-as), and I understand when you would want to use `with foo() as bar:`, but I don't understand when you would just want to do:
```
bar = foo()
with bar:
....
```
Doesn't that just remove the tear-down benefits of us... | 2013/06/11 | [
"https://Stackoverflow.com/questions/17053103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1388603/"
] | To expand a bit on @freakish's answer, `with` guarantees entry into and then exit from a "context". What the heck is a context? Well, it's "whatever the thing you're with-ing makes it". Some obvious ones are:
* locks: you take a lock, manipulate some data, and release the lock.
* external files/streams: you open a fil... | Using `with` without `as` still gets you the exact same teardown; it just doesn't get you a new local object representing the context.
The reason you want this is that sometimes the context itself isn't directly useful—in other words, you're only using it for the side effects of its context enter and exit.
For exampl... |
52,844,036 | I have been trying to create a folder inside a Jenkins pipeline with the following code:
```
pipeline {
agent {
node {
label 'python'
}
}
stages{
stage('Folder'){
steps{
folder 'New Folder'
}
}
}
}
```
But I get the following error message
java.lang.NoSuchMethodErr... | 2018/10/16 | [
"https://Stackoverflow.com/questions/52844036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9131570/"
] | You can pass an updater function to setState. Here's an example of how this might work.
The object returned from the updater function will be merged into the previous state.
```
const updateBubble = ({y, vy, ...props}) => ({y: y + vy, vy: vy + 0.1, ...props})
this.setState(state => ({bubbles: state.bubbles.map(updat... | I would sugest you should change your approach. You should only manage the state as the first you showed, and then, in another component, manage multiple times the component you currently have.
You could use something like this:
```
import React from 'react'
import Box from './box'
export default class Boxes extends... |
52,844,036 | I have been trying to create a folder inside a Jenkins pipeline with the following code:
```
pipeline {
agent {
node {
label 'python'
}
}
stages{
stage('Folder'){
steps{
folder 'New Folder'
}
}
}
}
```
But I get the following error message
java.lang.NoSuchMethodErr... | 2018/10/16 | [
"https://Stackoverflow.com/questions/52844036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9131570/"
] | You can pass an updater function to setState. Here's an example of how this might work.
The object returned from the updater function will be merged into the previous state.
```
const updateBubble = ({y, vy, ...props}) => ({y: y + vy, vy: vy + 0.1, ...props})
this.setState(state => ({bubbles: state.bubbles.map(updat... | You can do this with map indeed. Here's how I would have done it.
One liner
```
this.setState({bubbles: this.state.bubbles.map(x => ({...x, vy: x.vy + 1})})
```
More explicit
```js
this.state = {bubbles: history}
this.setState({ bubbles: this.state.bubbles.map(x => {
// Option 1 - more verbose
let newBu... |
52,844,036 | I have been trying to create a folder inside a Jenkins pipeline with the following code:
```
pipeline {
agent {
node {
label 'python'
}
}
stages{
stage('Folder'){
steps{
folder 'New Folder'
}
}
}
}
```
But I get the following error message
java.lang.NoSuchMethodErr... | 2018/10/16 | [
"https://Stackoverflow.com/questions/52844036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9131570/"
] | You can do this with map indeed. Here's how I would have done it.
One liner
```
this.setState({bubbles: this.state.bubbles.map(x => ({...x, vy: x.vy + 1})})
```
More explicit
```js
this.state = {bubbles: history}
this.setState({ bubbles: this.state.bubbles.map(x => {
// Option 1 - more verbose
let newBu... | I would sugest you should change your approach. You should only manage the state as the first you showed, and then, in another component, manage multiple times the component you currently have.
You could use something like this:
```
import React from 'react'
import Box from './box'
export default class Boxes extends... |
39,427,946 | I'm wondering how I can import the six library to python 2.5.2? It's not possible for me to install using pip, as it's a closed system I'm using.
I have tried to add the six.py file into the lib path. and then use "import six". However, it doesnt seem to be picking up the library from this path. | 2016/09/10 | [
"https://Stackoverflow.com/questions/39427946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/264975/"
] | According to project history, [version 1.9.0](https://bitbucket.org/gutworth/six/src/a9b120c9c49734c1bd7a95e7f371fd3bf308f107?at=1.9.0) supports Python 2.5. Compatibility broke with 1.10.0 release.
>
> Six supports every Python version since 2.5. It is contained in only
> one Python file, so it can be easily copied ... | You can't use `six` on Python 2.5; it requires Python 2.6 or newer.
From the [`six` project homepage](https://bitbucket.org/gutworth/six):
>
> Six supports every Python version since 2.6.
>
>
>
Trying to install `six` on Python 2.5 anyway fails as the included `setup.py` tries to import the `six` module, which t... |
36,610,806 | Here is a [link](https://drive.google.com/folderview?id=0B0bHr4crS9cpaWlockpxcmJxelE&usp=drive_web) to a project and output that you can use to reproduce the problem I describe below.
I'm using **coverage** with **tox** against multiple versions of python. My tox.ini file looks something like this:
```
[tox]
envlist ... | 2016/04/13 | [
"https://Stackoverflow.com/questions/36610806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3188632/"
] | I came upon this problem today, but couldn't find an easy answer. So, for future reference, here is the solution that I came up with.
1. Create an `envlist` that contains each version of Python that will be tested and a custom env for `cov`.
2. For all versions of Python, set `COVERAGE_FILE` environment varible to sto... | I don't understand why tox wouldn't install coverage in each virtualenv properly. You should get two different coverage reports, one for py27 and one for py35. A nicer option might be to produce one combined report. Use `coverage run -p` to record separate data for each run, and then `coverage combine` to combine them ... |
29,419,322 | I am getting the following error while executing the below code snippet exactly at the line `if uID in repo.git.log():`,
the problem is in `repo.git.log()`, I have looked at all the similar questions on Stack Overflow which suggests to use `decode("utf-8")`.
how do I convert `repo.git.log()` into `decode("utf-8")`?
`... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29419322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | 0x92 is a smart quote(’) of Windows-1252. It simply doesn't exist in unicode, therefore it can't be decoded.
Maybe your file was edited by a Windows machine which basically caused this problem? | After good research, I got the solution. In my case, **`datadump.json`** file was having the issue.
* Simply Open the file in notepad format
* Click on save as option
* Go to encoding section below & Click on "UTF-8"
* Save the file.
Now you can try running the command. You are good to go :)
For your reference, I ha... |
29,419,322 | I am getting the following error while executing the below code snippet exactly at the line `if uID in repo.git.log():`,
the problem is in `repo.git.log()`, I have looked at all the similar questions on Stack Overflow which suggests to use `decode("utf-8")`.
how do I convert `repo.git.log()` into `decode("utf-8")`?
`... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29419322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | 0x92 is a smart quote(’) of Windows-1252. It simply doesn't exist in unicode, therefore it can't be decoded.
Maybe your file was edited by a Windows machine which basically caused this problem? | 0x92 does not exist in the encoding UTF-8. As Exceen stated in his answer 0x92 is used in Windows-1252 as a smart quote. The way to resolve this is to use the windows 1252 encoding or to update the smart quote to a normal quote. |
29,419,322 | I am getting the following error while executing the below code snippet exactly at the line `if uID in repo.git.log():`,
the problem is in `repo.git.log()`, I have looked at all the similar questions on Stack Overflow which suggests to use `decode("utf-8")`.
how do I convert `repo.git.log()` into `decode("utf-8")`?
`... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29419322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Use `encoding='cp1252'` will solve the issue. | After good research, I got the solution. In my case, **`datadump.json`** file was having the issue.
* Simply Open the file in notepad format
* Click on save as option
* Go to encoding section below & Click on "UTF-8"
* Save the file.
Now you can try running the command. You are good to go :)
For your reference, I ha... |
29,419,322 | I am getting the following error while executing the below code snippet exactly at the line `if uID in repo.git.log():`,
the problem is in `repo.git.log()`, I have looked at all the similar questions on Stack Overflow which suggests to use `decode("utf-8")`.
how do I convert `repo.git.log()` into `decode("utf-8")`?
`... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29419322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Use `encoding='cp1252'` will solve the issue. | 0x92 does not exist in the encoding UTF-8. As Exceen stated in his answer 0x92 is used in Windows-1252 as a smart quote. The way to resolve this is to use the windows 1252 encoding or to update the smart quote to a normal quote. |
29,419,322 | I am getting the following error while executing the below code snippet exactly at the line `if uID in repo.git.log():`,
the problem is in `repo.git.log()`, I have looked at all the similar questions on Stack Overflow which suggests to use `decode("utf-8")`.
how do I convert `repo.git.log()` into `decode("utf-8")`?
`... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29419322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | After good research, I got the solution. In my case, **`datadump.json`** file was having the issue.
* Simply Open the file in notepad format
* Click on save as option
* Go to encoding section below & Click on "UTF-8"
* Save the file.
Now you can try running the command. You are good to go :)
For your reference, I ha... | 0x92 does not exist in the encoding UTF-8. As Exceen stated in his answer 0x92 is used in Windows-1252 as a smart quote. The way to resolve this is to use the windows 1252 encoding or to update the smart quote to a normal quote. |
32,586,612 | I was getting started with **AWS' Elastic Beanstalk**.
I am following this [tutorial](https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/) to **deploy a Django/PostgreSQL app**.
I did everything before the 'Configuring a Database' section. The deployment was also successful but I am g... | 2015/09/15 | [
"https://Stackoverflow.com/questions/32586612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4201498/"
] | Have you created a `requirements.txt` in the root of your application? [Elastic Beanstalk will automatically install the packages from this file upon deployment.](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-configuration-requirements.html) (Note it might need to be checked into source control to be dep... | The answer (<https://stackoverflow.com/a/47209268/6169225>) by [carl-g](https://stackoverflow.com/users/39396/carl-g) is correct. One thing that got me was that `requirements.txt` was in the wrong directory. Let's say you created a django project called `mysite`. This is the directory in which you run the `eb` command(... |
32,586,612 | I was getting started with **AWS' Elastic Beanstalk**.
I am following this [tutorial](https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/) to **deploy a Django/PostgreSQL app**.
I did everything before the 'Configuring a Database' section. The deployment was also successful but I am g... | 2015/09/15 | [
"https://Stackoverflow.com/questions/32586612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4201498/"
] | Have you created a `requirements.txt` in the root of your application? [Elastic Beanstalk will automatically install the packages from this file upon deployment.](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/python-configuration-requirements.html) (Note it might need to be checked into source control to be dep... | If you forget the **.ebextensions** folder you will get the same error.
I was following along with a good simple (non Elastic Beanstalk) [tutorial](https://scotch.io/tutorials/build-your-first-python-and-django-application) and missed step 3 & 4 of [Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/lates... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.