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
42,329,346
I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go. This is what i have in UserData of Instance one ``` "#!/bin/bash\n", "#############################################################################################\n", "s...
2017/02/19
[ "https://Stackoverflow.com/questions/42329346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/907937/" ]
Glad you figured it out! Posting my last comment as an answer below. Thanks for the live example. So, I click on the submit button and I can see the browser sending a POST request. The server responds successfully, but with a redirect. `POST https://win-marketing.sciencesupercrew.com/en/users/login` -> `301 Moved Per...
I am no expert but since your code is working on local just try the following to get an idea where the problem might be: a) Run production environment on your local, see if the problem persists there. b) Try to test run without any javascript enabled or atleast disable custom ones on the production server. c) Try to...
42,329,346
I am trying to learn Cloudformation im stuck with a senario where I need a second EC2 instance started after one EC2 is provisioned and good to go. This is what i have in UserData of Instance one ``` "#!/bin/bash\n", "#############################################################################################\n", "s...
2017/02/19
[ "https://Stackoverflow.com/questions/42329346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/907937/" ]
Glad you figured it out! Posting my last comment as an answer below. Thanks for the live example. So, I click on the submit button and I can see the browser sending a POST request. The server responds successfully, but with a redirect. `POST https://win-marketing.sciencesupercrew.com/en/users/login` -> `301 Moved Per...
This sounds like an SSL issue to me. Your form is definitely POSTing to the route. You can confirm this by adding `data-remote="true"` to your form HTML in the browser, then watching the console as you make the request: ``` XHR finished loading: POST "https://win-marketing.sciencesupercrew.com/en/users/login" ``` W...
16,256,341
I am trying to go back to the top of a function (not restart it, but go to the top) but can not figure out how to do this. Instead of giving you the long code I'm just going to make up an example of what I want: ``` used = [0,0,0] def fun(): score = input("please enter a place to put it: ") if score == "this o...
2013/04/27
[ "https://Stackoverflow.com/questions/16256341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2255589/" ]
What you are looking for is a `while` loop. You want to set up your loop to keep going until a place is found. Something like this: ``` def fun(): found_place = False while not found_place: score = input("please enter a place to put it: ") if score == "here" if used[1] == 0: ...
As Ashwini correctly points out, you should do a `while` loop ``` def fun(): end_condition = False while not end_condition: score = input("please enter a place to put it: ") if score == "here": if used[1] == 0: score[1] = total used[1] = 1 elif used[1] == 1: print("Alrea...
44,628,435
I am making a request to my api.ai chatbot after following the instructions given on their official github website [here](https://github.com/api-ai/apiai-python-client/blob/master/examples/send_text_example.py). The following is the code for which I am getting an error, to which the solution is supposedly to call the f...
2017/06/19
[ "https://Stackoverflow.com/questions/44628435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7872066/" ]
> > I've tried various casting attempts > > > Have you tried this one? ``` .FirstOrDefault(ids => ids.Contains((T)propertyInfo.GetValue(item, null))) ``` Since `ids` is of type `IGrouping<TKey, TElement>` where `TElement` is of type `T` in your case, casting the value of property to `T` will allow for the compa...
Ok, so I cracked it in the end. I needed to add more detail in my generic method header/signature. ``` public static IEnumerable<T> MixObjectsByProperty<T, U>( IEnumerable<T> objects, string propertyName, IEnumerable<IEnumerable<U>> groupsToMergeByProperty = null) where T : class where U : ...
44,628,435
I am making a request to my api.ai chatbot after following the instructions given on their official github website [here](https://github.com/api-ai/apiai-python-client/blob/master/examples/send_text_example.py). The following is the code for which I am getting an error, to which the solution is supposedly to call the f...
2017/06/19
[ "https://Stackoverflow.com/questions/44628435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7872066/" ]
Without seeing the whole method (because your type signatures clearly indicate it's not the whole method), here's an example implementation: ``` public class Ext { public static List<T[]> MixObjectsByProperty<T, TProp, U>( IEnumerable<T> source, Expression<Func<T, TProp>> property, IEnumera...
> > I've tried various casting attempts > > > Have you tried this one? ``` .FirstOrDefault(ids => ids.Contains((T)propertyInfo.GetValue(item, null))) ``` Since `ids` is of type `IGrouping<TKey, TElement>` where `TElement` is of type `T` in your case, casting the value of property to `T` will allow for the compa...
44,628,435
I am making a request to my api.ai chatbot after following the instructions given on their official github website [here](https://github.com/api-ai/apiai-python-client/blob/master/examples/send_text_example.py). The following is the code for which I am getting an error, to which the solution is supposedly to call the f...
2017/06/19
[ "https://Stackoverflow.com/questions/44628435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7872066/" ]
Without seeing the whole method (because your type signatures clearly indicate it's not the whole method), here's an example implementation: ``` public class Ext { public static List<T[]> MixObjectsByProperty<T, TProp, U>( IEnumerable<T> source, Expression<Func<T, TProp>> property, IEnumera...
Ok, so I cracked it in the end. I needed to add more detail in my generic method header/signature. ``` public static IEnumerable<T> MixObjectsByProperty<T, U>( IEnumerable<T> objects, string propertyName, IEnumerable<IEnumerable<U>> groupsToMergeByProperty = null) where T : class where U : ...
53,311,721
This question is killing me softly at the moment. I am trying to learn python, lambda, and Dynamodb. Python looks awesome, I am able to connect to MySQL while using a normal MySQL server like Xampp, the goal is to learn to work with Dynamodb, but somehow I am unable to get\_items from the Dynamodb. This is really ki...
2018/11/15
[ "https://Stackoverflow.com/questions/53311721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9821202/" ]
Thats to @ippi. It was the quotes that I am using. ``` table.get_item(Key={"id": '1'}) ``` needed to be ``` table.get_item(Key={"id": 1}) ``` As I am using a numeric and not a string. Hope this helps for the next person(s) with the same problem.
You're facing this problem because you have created a table with a partition key whose data type is an integer. Now you're performing a read an item operation specifying partition as a string which needs to be an integer that causes this issue. I'm the author of Lucid-Dynamodb, a minimalist wrapper to AWS DynamoDB. It...
61,973,288
currently im learning how to use Apache Airflow and trying to create a simple DAG script like this ``` from datetime import datetime from airflow import DAG from airflow.operators.dummy_operator import DummyOperator from airflow.operators.python_operator import PythonOperator def print_hello(): return 'Hello worl...
2020/05/23
[ "https://Stackoverflow.com/questions/61973288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Put a ROW ID on your tables ``` df_1 <- read_table("A B C 2.3 5 3 12 3 1 0.4 13 2") %>% rowid_to_column("ROW") df_2 <- read_table("A B C 4.3 23 1 1 7 2 0.4 10 2") %>% rowid_to_column("ROW") df_3 <- read_table("A B ...
You can put all the dataframes in a list : ``` list_df <- mget(ls(pattern = 'df_\\d+')) ``` Then calculate the stats for each column separately. ``` data.frame(A = Reduce(`+`, lapply(list_df, `[[`, 1))/length(list_df), B = apply(do.call(rbind, lapply(list_df, `[[`, 2)), 2, median), C = apply...
28,741,772
I am a novice writing a simple script to analyse a game. The data I would like to use describes "Items" and they have statistics associated with them (eg. "Attack Speed"). To clarify: The game is not something I have access to beyond being a player, my script is to compare combinations of the items. I will manually l...
2015/02/26
[ "https://Stackoverflow.com/questions/28741772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4610057/" ]
Without further info, I would say to use JSON, as it's easy to use and human-readable: ``` { "Attack Speed": 5, "Items": ["Dirt", "Flower", "Egg"] } ```
Well, You got many more options. From least to most complicated : * [Pickle](https://wiki.python.org/moin/UsingPickle) * [Shelve](http://pymotw.com/2/shelve/) * [SQLite](http://zetcode.com/db/sqlitepythontutorial/) * [SQLAlchemy](http://www.sqlalchemy.org/) What You should use really depends on what are Your needs ex...
19,228,516
Here is my argparse sample say sample.py ``` import argparse parser = argparse.ArgumentParser() parser.add_argument("-p", nargs="+", help="Stuff") args = parser.parse_args() print args ``` Python - 2.7.3 I expect that the user supplies a list of arguments separated by spaces after the -p option. For example, if yo...
2013/10/07
[ "https://Stackoverflow.com/questions/19228516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44124/" ]
> > Note: python 3.8 adds an `action="extend"` which will create the desired list of ['x','y'] > > > To produce a list of ['x','y'] use `action='append'`. Actually it gives ``` Namespace(p=[['x'], ['y']]) ``` For each `-p` it gives a list `['x']` as dictated by `nargs='+'`, but `append` means, add that value to...
I ran into the same issue. I decided to go with the custom action route as suggested by mgilson. ``` import argparse class ExtendAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): if getattr(namespace, self.dest, None) is None: setattr(namespace, self.dest, []) ...
55,376,876
I would like to setup the local pgadmin in server mode behind the reverse proxy. The reverse proxy and the pgadmin could be on the same machine. I tried to set up but it always fails. Here is mypgadmin conf: ``` Listen 8080 <VirtualHost *:8080> SSLEngine on SSLCertificateFile /etc/pki/tls/certs/pgadmin.crt SSLCe...
2019/03/27
[ "https://Stackoverflow.com/questions/55376876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2886412/" ]
this work for me. I make pgadmin proxy to sub directory (https://localhost/pgadmin) ``` <VirtualHost *:80> ServerName localhost DocumentRoot "/var/www" <Directory "/var/www"> AllowOverride all </Directory ProxyPass /ws/ ws://0.0.0.0:8888/ ProxyPass /phpmyadmin/ http://phpmyadmin/ ...
Have you tried with latest version, I think it is fixed this commit Ref: [LINK](https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=commit;h=f401def044c8b47974d58c71ff9e6f71f34ef41d) Online Docs: <https://www.pgadmin.org/docs/pgadmin4/dev/server_deployment.html>
55,376,876
I would like to setup the local pgadmin in server mode behind the reverse proxy. The reverse proxy and the pgadmin could be on the same machine. I tried to set up but it always fails. Here is mypgadmin conf: ``` Listen 8080 <VirtualHost *:8080> SSLEngine on SSLCertificateFile /etc/pki/tls/certs/pgadmin.crt SSLCe...
2019/03/27
[ "https://Stackoverflow.com/questions/55376876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2886412/" ]
this work for me. I make pgadmin proxy to sub directory (https://localhost/pgadmin) ``` <VirtualHost *:80> ServerName localhost DocumentRoot "/var/www" <Directory "/var/www"> AllowOverride all </Directory ProxyPass /ws/ ws://0.0.0.0:8888/ ProxyPass /phpmyadmin/ http://phpmyadmin/ ...
This config works, use 0.0.0.0 for pgadmin docker, else use your ip change port 5050 with your pgadmin port ``` <VirtualHost *:80> ServerName pgadmin.yourdomain.com RedirectMatch permanent ^/pgadmin4$ /pgadmin4/ ProxyPreserveHost On ProxyPass / http://0.0.0.0:5050/ ProxyPassReverse / http://0.0.0.0:5050/ Heade...
13,336,628
I have very simple web page example read from html file using python. the html called led.html as in bellow: ``` <html> <body> <br> <p> <p> <a href="?switch=1"><img src="images/on.png"></a> </body> </html> ``` and the python code is: ``` import cherrypy import os.path import struct class Server(object): led_swi...
2012/11/11
[ "https://Stackoverflow.com/questions/13336628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1813738/" ]
If you require to swap *all* first (of pair) elements (and not just `(1, 36)` and `(0, 36)`), you can do `fwd_count_sort=sorted(rvs_count.items(), key=lambda x: (x[0][1],-x[0][0]), reverse=True)`
I'm not exactly sure on the definition of your sorting criteria, but this is a method to sort the `pair` list according to the values in `fwd_count` and `rvs_count`. Hopefully you can use this to get to the result you want. ``` def keyFromPair(pair): """Return a tuple (f, r) to be used for sorting the pairs by fre...
63,851,302
I need to execute below function based on user input: > > If `X=0`, then from line `URL ....Print('Success` should be written to a file & get saved as `test.py`. > > > At the backend, the saved file (`Test.py`) would automatically get fetched by Task scheduler from the saved location & would run periodically. An...
2020/09/11
[ "https://Stackoverflow.com/questions/63851302", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13824611/" ]
Given a scalar `x` and a vector `v` the expression `x <=quantile (v, .95)` can be written as `sum( x > v) < Q` where `Q = .95 * numel(v)` \*. Also `A_1` can be splitted before the loop to avoid extra indexing. Moreover the most inner loop can be removed in favor of vectorization. ``` Af_1 = A_1(:,1); Af_2 = A_2(:,1);...
Option 1: Because all numbers are positive, you can do some optimizations. 95 percentile will be only higher if you add `A1` to the mix - if you find the `j` and `k` of greatest 95 percentile of `A2+A3` on the right side compared to the sum of the first 2 elements, you can simply take that for every `i`. ``` maxDif = ...
19,479,644
I saw a python example today and it used -> for example this was what I saw: ``` spam = None bacon = 42 def monty_python(a:spam,b:bacon) -> "different:": pass ``` What is that code doing? I'm not quite sure I've never seen code like that I don't really get what ``` a:spam,b:bacon ``` is doing either, can ...
2013/10/20
[ "https://Stackoverflow.com/questions/19479644", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2805788/" ]
It is function annotation for a return type. [`annotations`](https://stackoverflow.com/questions/3038033/what-are-good-uses-for-python3s-function-annotations) do nothing inside the code, they are there to help a user with code completion (in my experience). Here is the [PEP](http://www.python.org/dev/peps/pep-3107/) f...
They're [function annotations](http://ceronman.com/2013/03/12/a-powerful-unused-feature-of-python-function-annotations/). They don't really do anything by themselves, but they can be used for documentation or in combination with metaprogramming.
13,700,045
I'm trying to build a graph library in python (along with standard graph-algorithms). I've tried to implement DFS and this is what it looks like ``` def DFS(gr, s, path): """ Depth first search Returns a list of nodes "findable" from s """ if s in path: return False path.append(s) for each in gr.n...
2012/12/04
[ "https://Stackoverflow.com/questions/13700045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427069/" ]
Just make a wrapper method that calls the one you already have: ``` def DFS(gr, s): path = [] DFS2(gr, s, path) return path ``` Here `DFS2` is the method you showed above.
Actually why don't you just set `path` to have a default of an empty list? So using your same code but slightly different arguments: ``` # Original def DFS(gr, s, path): # Modified def DFS(gr, s, path=[]): # From here you can do DFS(gr, s) ```
13,700,045
I'm trying to build a graph library in python (along with standard graph-algorithms). I've tried to implement DFS and this is what it looks like ``` def DFS(gr, s, path): """ Depth first search Returns a list of nodes "findable" from s """ if s in path: return False path.append(s) for each in gr.n...
2012/12/04
[ "https://Stackoverflow.com/questions/13700045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427069/" ]
Just make a wrapper method that calls the one you already have: ``` def DFS(gr, s): path = [] DFS2(gr, s, path) return path ``` Here `DFS2` is the method you showed above.
You can use an empty default value for the visited nodes, as suggested by chutsu, but be careful with using [mutable default arguments](https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument/52572954#52572954). Also I would suggest using a set instead of a list for constant look...
12,127,869
I'm trying to build a package from source by executing `python setup.py py2exe` This is the section of code from setup.py, I suppose would be relevant: ``` if sys.platform == "win32": # For py2exe. import matplotlib sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC...
2012/08/26
[ "https://Stackoverflow.com/questions/12127869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193653/" ]
I would recommend ignoring the dependency outright. Add `MSVCP90.dll` to the list of `dll_excludes` given as an option to `py2exe`. Users will have to install the Microsoft Visual C++ 2008 redistributable. An example: ``` setup( options = { "py2exe":{ ... "dll_excludes": ["MSVCP...
(new answer, since the other answer describes an alternate solution) You can take the files from the WinSxS directory and copy them to the `C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT` directory (normally created by Visual Studio, which you don't have). Copy them to get the following ...
12,127,869
I'm trying to build a package from source by executing `python setup.py py2exe` This is the section of code from setup.py, I suppose would be relevant: ``` if sys.platform == "win32": # For py2exe. import matplotlib sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC...
2012/08/26
[ "https://Stackoverflow.com/questions/12127869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193653/" ]
I would recommend ignoring the dependency outright. Add `MSVCP90.dll` to the list of `dll_excludes` given as an option to `py2exe`. Users will have to install the Microsoft Visual C++ 2008 redistributable. An example: ``` setup( options = { "py2exe":{ ... "dll_excludes": ["MSVCP...
I think it has something to do with the spaces in the directory. You should try using `.rstrip()`. For example, put this: ``` directory='C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT' directory=directory.rstrip() ``` You can then use the variable directory like you would have used the...
12,127,869
I'm trying to build a package from source by executing `python setup.py py2exe` This is the section of code from setup.py, I suppose would be relevant: ``` if sys.platform == "win32": # For py2exe. import matplotlib sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC...
2012/08/26
[ "https://Stackoverflow.com/questions/12127869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193653/" ]
I would recommend ignoring the dependency outright. Add `MSVCP90.dll` to the list of `dll_excludes` given as an option to `py2exe`. Users will have to install the Microsoft Visual C++ 2008 redistributable. An example: ``` setup( options = { "py2exe":{ ... "dll_excludes": ["MSVCP...
I used to have a huge number of problems with complication on Windows, like the issue you're facing as well as installing packages like Cython with `pip install cython`. The solution that worked best for me after two weeks of pain was downloading and running the unofficial MinGW GCC binary for Windows provided [here](...
12,127,869
I'm trying to build a package from source by executing `python setup.py py2exe` This is the section of code from setup.py, I suppose would be relevant: ``` if sys.platform == "win32": # For py2exe. import matplotlib sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC...
2012/08/26
[ "https://Stackoverflow.com/questions/12127869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193653/" ]
(new answer, since the other answer describes an alternate solution) You can take the files from the WinSxS directory and copy them to the `C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT` directory (normally created by Visual Studio, which you don't have). Copy them to get the following ...
I think it has something to do with the spaces in the directory. You should try using `.rstrip()`. For example, put this: ``` directory='C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT' directory=directory.rstrip() ``` You can then use the variable directory like you would have used the...
12,127,869
I'm trying to build a package from source by executing `python setup.py py2exe` This is the section of code from setup.py, I suppose would be relevant: ``` if sys.platform == "win32": # For py2exe. import matplotlib sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC...
2012/08/26
[ "https://Stackoverflow.com/questions/12127869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193653/" ]
(new answer, since the other answer describes an alternate solution) You can take the files from the WinSxS directory and copy them to the `C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT` directory (normally created by Visual Studio, which you don't have). Copy them to get the following ...
I used to have a huge number of problems with complication on Windows, like the issue you're facing as well as installing packages like Cython with `pip install cython`. The solution that worked best for me after two weeks of pain was downloading and running the unofficial MinGW GCC binary for Windows provided [here](...
48,716,989
I'm trying to create an infinite loop that will output the Y axis of a sine wave, and want to use variables specifying the amplitude of the wave, frequency, and resolution. Where frequency is the number of full sine waves in a second like electrical AC frequency. I'm trying to do something like this: ``` #!/usr/bin/...
2018/02/10
[ "https://Stackoverflow.com/questions/48716989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6058228/" ]
How about something like this: ``` DELETE FROM inventory WHERE updated NOT IN ( SELECT updated FROM ( SELECT MAX(updated) updated FROM inventory GROUP BY DATE(updated) ) i ) ``` This would work well if you have the `updated` indexed (ordered). Basically the sub query gets all the max...
Get the most recent time in a subquery, join that with the table, and delete. ``` DELETE i1 FROM inventory AS i1 JOIN (SELECT DATE(updated) AS date, MAX(updated) AS latest FROM inventory WHERE itemname = '24T7351' GROUP BY date) AS i2 ON DATE(i1.updated) = i2.date AND i1.updated != i2.latest WHERE i...
48,716,989
I'm trying to create an infinite loop that will output the Y axis of a sine wave, and want to use variables specifying the amplitude of the wave, frequency, and resolution. Where frequency is the number of full sine waves in a second like electrical AC frequency. I'm trying to do something like this: ``` #!/usr/bin/...
2018/02/10
[ "https://Stackoverflow.com/questions/48716989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6058228/" ]
How about something like this: ``` DELETE FROM inventory WHERE updated NOT IN ( SELECT updated FROM ( SELECT MAX(updated) updated FROM inventory GROUP BY DATE(updated) ) i ) ``` This would work well if you have the `updated` indexed (ordered). Basically the sub query gets all the max...
If you want the latest record on each date for each item: ``` SELECT i.* FROM inventory i WHERE i.updated < (select max(i2.updated) from inventory i2 where i2.itemname = i.itemname and date(i2.updated) = date(i.updated) ) ORDER BY updated...
48,716,989
I'm trying to create an infinite loop that will output the Y axis of a sine wave, and want to use variables specifying the amplitude of the wave, frequency, and resolution. Where frequency is the number of full sine waves in a second like electrical AC frequency. I'm trying to do something like this: ``` #!/usr/bin/...
2018/02/10
[ "https://Stackoverflow.com/questions/48716989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6058228/" ]
How about something like this: ``` DELETE FROM inventory WHERE updated NOT IN ( SELECT updated FROM ( SELECT MAX(updated) updated FROM inventory GROUP BY DATE(updated) ) i ) ``` This would work well if you have the `updated` indexed (ordered). Basically the sub query gets all the max...
This solution would help you assign a rank to each of the rows. You can delete based on rank. The latest record has rank of 1. ``` SELECT ItemName, BLOCK_1_PRICE, M, S, B, P, updated, if (ItemName=@curItem,@curRank:= @curRank + 1, @curRank:=@reset) AS rank, @curItem:=ItemName, @...
62,892,652
I have a class that gets the data from the form, makes some changes and save it to the database. I want to have several method inside. * Get * Post * And some other method that will make some changes to the data from the form I want the post method to save the data from the form to the database and pass the instanse...
2020/07/14
[ "https://Stackoverflow.com/questions/62892652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13197641/" ]
``` class AddSiteView(View): form_class = AddSiteForm template_name = 'home.html' def get(self, request, *args, **kwargs): form = self.form_class() return render(request, self.template_name, { 'form': form }) def post(self, request, *args, **kwargs): form = self.form_class(requ...
One must return a response from the `post` method. This code returns a `Site` instance on these lines. Not sure what is the intended behavior, either a `redirect` or `render` should be used. ``` try: site_id = Site.objects.get(url=site_url) except ObjectDoesNotExist: site_instan...
36,682,832
Exactly how should python models be exported for use in c++? I'm trying to do something similar to this tutorial: <https://www.tensorflow.org/versions/r0.8/tutorials/image_recognition/index.html> I'm trying to import my own TF model in the c++ API in stead of the inception one. I adjusted input size and the paths, bu...
2016/04/17
[ "https://Stackoverflow.com/questions/36682832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5452997/" ]
At first, you need to graph definition to file by using following command ``` with tf.Session() as sess: //Build network here tf.train.write_graph(sess.graph.as_graph_def(), "C:\\output\\", "mymodel.pb") ``` Then, save your model by using saver ``` saver = tf.train.Saver(tf.global_variables()) saver.save(sess, "...
You can try this (modify name of output layer): ``` import os import tensorflow as tf from tensorflow.python.framework import graph_util def load_graph_def(model_path, sess=None): sess = sess if sess is not None else tf.get_default_session() saver = tf.train.import_meta_graph(model_path + '.meta') saver.r...
36,682,832
Exactly how should python models be exported for use in c++? I'm trying to do something similar to this tutorial: <https://www.tensorflow.org/versions/r0.8/tutorials/image_recognition/index.html> I'm trying to import my own TF model in the c++ API in stead of the inception one. I adjusted input size and the paths, bu...
2016/04/17
[ "https://Stackoverflow.com/questions/36682832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5452997/" ]
At first, you need to graph definition to file by using following command ``` with tf.Session() as sess: //Build network here tf.train.write_graph(sess.graph.as_graph_def(), "C:\\output\\", "mymodel.pb") ``` Then, save your model by using saver ``` saver = tf.train.Saver(tf.global_variables()) saver.save(sess, "...
You can find very useful the [DNN](https://docs.opencv.org/master/d6/d0f/group__dnn.html) module of OpenCV. It makes it simple to load and use pretrained models developed with Tensorflow (and other frameworks). It can be used in a C++ program. [Here](https://www.pyimagesearch.com/2017/08/21/deep-learning-with-opencv/...
61,578,697
I am trying to wrap my head around python. Basically I am trying to remove a duplicate string (a date to be more precise) in some data. So for example: ``` 2019-03-31 2019-06-30 2019-09-30 2019-12-31 2020-03-31 2020-03-31 ``` notice 2020-03-31 is duplicated. I would like to find the duplicated date and rename it as...
2020/05/03
[ "https://Stackoverflow.com/questions/61578697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13461709/" ]
Use a [`set`](https://docs.python.org/3/library/stdtypes.html#set) to keep track of items you've seen. If any items are already in the set, append the desired string (use `= "last quarter"` if you want a full rename; it's unclear). ``` data = """2019-03-31 2019-06-30 2019-09-30 2019-12-31 2020-03-31 2020-03-31""".spli...
For your function, if you have list of elements then your function will be : ``` def checkForDuplicates(listOfElems): check=[] for i in range(len(listOfElems)): if listofElems[i] in check: #then it is a duplicate and you can rename it listofElems[i]='last quarter' else: ...
61,578,697
I am trying to wrap my head around python. Basically I am trying to remove a duplicate string (a date to be more precise) in some data. So for example: ``` 2019-03-31 2019-06-30 2019-09-30 2019-12-31 2020-03-31 2020-03-31 ``` notice 2020-03-31 is duplicated. I would like to find the duplicated date and rename it as...
2020/05/03
[ "https://Stackoverflow.com/questions/61578697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13461709/" ]
Use a [`set`](https://docs.python.org/3/library/stdtypes.html#set) to keep track of items you've seen. If any items are already in the set, append the desired string (use `= "last quarter"` if you want a full rename; it's unclear). ``` data = """2019-03-31 2019-06-30 2019-09-30 2019-12-31 2020-03-31 2020-03-31""".spli...
If your list is sorted, you can try this. ``` def checkForDuplicates(listOfElems): for i in range(len(listOfElems)-1): if listOfElems[i]==listOfElems[i+1]: listOfElems[i+1] = "last quarter" retrun listOfElems ```
61,578,697
I am trying to wrap my head around python. Basically I am trying to remove a duplicate string (a date to be more precise) in some data. So for example: ``` 2019-03-31 2019-06-30 2019-09-30 2019-12-31 2020-03-31 2020-03-31 ``` notice 2020-03-31 is duplicated. I would like to find the duplicated date and rename it as...
2020/05/03
[ "https://Stackoverflow.com/questions/61578697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13461709/" ]
For your function, if you have list of elements then your function will be : ``` def checkForDuplicates(listOfElems): check=[] for i in range(len(listOfElems)): if listofElems[i] in check: #then it is a duplicate and you can rename it listofElems[i]='last quarter' else: ...
If your list is sorted, you can try this. ``` def checkForDuplicates(listOfElems): for i in range(len(listOfElems)-1): if listOfElems[i]==listOfElems[i+1]: listOfElems[i+1] = "last quarter" retrun listOfElems ```
44,610,150
I downloaded Python 3.6 from Python's website (from the download page for Windows) and it seems only the interpreter is available. I don't see anything else (Standard Library or something) in my system. Is it included in the interpreter and hidden or something? I tried to install ibm\_db 2.0.7 as an extension of Pytho...
2017/06/17
[ "https://Stackoverflow.com/questions/44610150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8176681/" ]
Timeout is for raising a timeout error if an event isn't emitted within a certain time period. You probably want Observable.interval: ``` return Observable.interval(1000).mergeMap(t=> this.http.get(matchUrl)) .toPromise() .then(response => response.json().participants as Match[]); ``` if you want to ...
Use `debounceTime` operator as below ``` getMatch(matchId: number): Promise<Match[]> { let matchUrl: string = 'https://br1.api.riotgames.com/lol/match/v3/matches/'+ matchId +'?api_key='; return this.http.get(matchUrl) .debounceTime(1000) .toPromise() .then(respo...
5,395,782
In a python/google app engine app, I've got a choice between storing some static data (couple KB in size) in a local json/xml file or putting it into the datastore and querying it from there. The data is created by me, so there's no issues with badly formed data. In specific terms such as saving quota, less resource us...
2011/03/22
[ "https://Stackoverflow.com/questions/5395782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/614453/" ]
If your data is small, static and infrequently changed, you'll get the best performance by just writing your data as a `dict` in it's own module and just `import` it where you need it. This would take advantage of the fact that Python will cache your modules on import.
It is faster to keep your data in a static file instead of the datastore. As you said, this saves on datastore quota, and also saves time in round-trips to the datastore. However, any **data you store in static files is static and cannot be changed by your application** (see the ["Sandbox" section here](http://code.go...
5,395,782
In a python/google app engine app, I've got a choice between storing some static data (couple KB in size) in a local json/xml file or putting it into the datastore and querying it from there. The data is created by me, so there's no issues with badly formed data. In specific terms such as saving quota, less resource us...
2011/03/22
[ "https://Stackoverflow.com/questions/5395782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/614453/" ]
For superior app performance, as Chris and others pointed out, python dict is the best. But if you are ok with the minimal performance hit caused by datastore queries, I think that is the way to go purely from a design and maintenance perspective. Simplicity takes precedence over performance if you are not approaching...
It is faster to keep your data in a static file instead of the datastore. As you said, this saves on datastore quota, and also saves time in round-trips to the datastore. However, any **data you store in static files is static and cannot be changed by your application** (see the ["Sandbox" section here](http://code.go...
5,395,782
In a python/google app engine app, I've got a choice between storing some static data (couple KB in size) in a local json/xml file or putting it into the datastore and querying it from there. The data is created by me, so there's no issues with badly formed data. In specific terms such as saving quota, less resource us...
2011/03/22
[ "https://Stackoverflow.com/questions/5395782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/614453/" ]
If your data is small, static and infrequently changed, you'll get the best performance by just writing your data as a `dict` in it's own module and just `import` it where you need it. This would take advantage of the fact that Python will cache your modules on import.
For superior app performance, as Chris and others pointed out, python dict is the best. But if you are ok with the minimal performance hit caused by datastore queries, I think that is the way to go purely from a design and maintenance perspective. Simplicity takes precedence over performance if you are not approaching...
32,977,076
Related: [ImportError: No module named bootstrap3 even while using virtualenv](https://stackoverflow.com/questions/29781872/importerror-no-module-named-bootstrap3-even-while-using-virtualenv) Every time I attempt to use manage.py (startapp, shell, etc) or load my page (using Apache), I get the error below. I'm running...
2015/10/06
[ "https://Stackoverflow.com/questions/32977076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1303827/" ]
As it is said in docs, you need `django-bootstrap3` package to use bootstrap3. Here is the [link](https://github.com/dyve/django-bootstrap3).
I defer to the answer above. Just pointing out that the django-bootstrap-toolkit, which is for v2 of Bootstrap, could be removed. Thanks for using these libraries!
5,880,781
Can anybody tell me what is wrong in this program? I face ``` syntaxerror unexpected character after line continuation character ``` when I run this program: ``` f = open(D\\python\\HW\\2_1 - Copy.cp,"r"); lines = f.readlines(); for i in lines: thisline = i.split(" "); ```
2011/05/04
[ "https://Stackoverflow.com/questions/5880781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/642564/" ]
You need to quote that filename: ``` f = open("D\\python\\HW\\2_1 - Copy.cp", "r") ``` Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability: ``` print "This is a lon...
Replace `f = open(D\\python\\HW\\2_1 - Copy.cp,"r");` by `f = open("D:\\python\\HW\\2_1 - Copy.cp", "r")` 1. File path needs to be a string (constant) 2. need colon in Windows file path 3. space after comma for better style 4. ; after statement is allowed but fugly. What tutorial are you using?
5,880,781
Can anybody tell me what is wrong in this program? I face ``` syntaxerror unexpected character after line continuation character ``` when I run this program: ``` f = open(D\\python\\HW\\2_1 - Copy.cp,"r"); lines = f.readlines(); for i in lines: thisline = i.split(" "); ```
2011/05/04
[ "https://Stackoverflow.com/questions/5880781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/642564/" ]
You need to quote that filename: ``` f = open("D\\python\\HW\\2_1 - Copy.cp", "r") ``` Otherwise the bare backslash after the D is interpreted as a line-continuation character, and should be followed by a newline. This is used to extend long expressions over multiple lines, for readability: ``` print "This is a lon...
The filename should be a string. In other names it should be within quotes. ```py f = open("D\\python\\HW\\2_1 - Copy.cp","r") lines = f.readlines() for i in lines: thisline = i.split(" "); ``` You can also open the file using `with` ```py with open("D\\python\\HW\\2_1 - Copy.cp","r") as f: lines = f.readli...
5,880,781
Can anybody tell me what is wrong in this program? I face ``` syntaxerror unexpected character after line continuation character ``` when I run this program: ``` f = open(D\\python\\HW\\2_1 - Copy.cp,"r"); lines = f.readlines(); for i in lines: thisline = i.split(" "); ```
2011/05/04
[ "https://Stackoverflow.com/questions/5880781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/642564/" ]
Replace `f = open(D\\python\\HW\\2_1 - Copy.cp,"r");` by `f = open("D:\\python\\HW\\2_1 - Copy.cp", "r")` 1. File path needs to be a string (constant) 2. need colon in Windows file path 3. space after comma for better style 4. ; after statement is allowed but fugly. What tutorial are you using?
The filename should be a string. In other names it should be within quotes. ```py f = open("D\\python\\HW\\2_1 - Copy.cp","r") lines = f.readlines() for i in lines: thisline = i.split(" "); ``` You can also open the file using `with` ```py with open("D\\python\\HW\\2_1 - Copy.cp","r") as f: lines = f.readli...
16,297,892
Upgrade to 13.04 has totally messed my system up . I am having this issue when running ``` ./manage.py runserver Traceback (most recent call last): File "./manage.py", line 8, in <module> from django.core.management import execute_from_command_line File "/home/rats/rats/local/lib/python2.7/site-packages/django/...
2013/04/30
[ "https://Stackoverflow.com/questions/16297892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1080407/" ]
If you are using virtualenvwrapper then you can recreate the virtualenv on top of the existing one (with no environment currently active): `mkvirtualenv <existing name>` which should pull in the latest (upgraded) python version from the system and fix any mismatch errors.
I have just solved that problem on my machine. The problem was that Ubuntu 13.04 use python 2.7.4. That makes conflict with the Python version of the `virtualenv`. What I do was to re-create the `virtualenv` with the new version of python. I think it's the simplest way, but you can try to upgrade the python version w...
16,297,892
Upgrade to 13.04 has totally messed my system up . I am having this issue when running ``` ./manage.py runserver Traceback (most recent call last): File "./manage.py", line 8, in <module> from django.core.management import execute_from_command_line File "/home/rats/rats/local/lib/python2.7/site-packages/django/...
2013/04/30
[ "https://Stackoverflow.com/questions/16297892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1080407/" ]
If you are using virtualenvwrapper then you can recreate the virtualenv on top of the existing one (with no environment currently active): `mkvirtualenv <existing name>` which should pull in the latest (upgraded) python version from the system and fix any mismatch errors.
You don't need to recreate the environment. You can upgrade the virtualenv running this command: > > virtualenv /PATH/TO/YOUR\_OLD\_ENV > > > `YOUR_OLD_ENV` folder will be properly upgraded to the version 2.7.4.
16,297,892
Upgrade to 13.04 has totally messed my system up . I am having this issue when running ``` ./manage.py runserver Traceback (most recent call last): File "./manage.py", line 8, in <module> from django.core.management import execute_from_command_line File "/home/rats/rats/local/lib/python2.7/site-packages/django/...
2013/04/30
[ "https://Stackoverflow.com/questions/16297892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1080407/" ]
You don't need to recreate the environment. You can upgrade the virtualenv running this command: > > virtualenv /PATH/TO/YOUR\_OLD\_ENV > > > `YOUR_OLD_ENV` folder will be properly upgraded to the version 2.7.4.
I have just solved that problem on my machine. The problem was that Ubuntu 13.04 use python 2.7.4. That makes conflict with the Python version of the `virtualenv`. What I do was to re-create the `virtualenv` with the new version of python. I think it's the simplest way, but you can try to upgrade the python version w...
51,531,429
I have an ndarray of N 1x3 arrays I'd like to perform dot multiplication with a 3x3 matrix. I can't seem to figure out an efficient way to do this, as all the multi\_dot and tensordot, etc methods seem to recursively sum or multiply the results of each operation. I simply want to apply a dot multiply the same way you c...
2018/07/26
[ "https://Stackoverflow.com/questions/51531429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6587755/" ]
Try This: ``` import numpy as np N = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6]]) m = np.asarray([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) re0 = np.asarray([np.dot(m, a) for a in N]) # original re1 = np.dot(m, N.T).T # efficient print("result0:\n{}".format(re0)) print("result1:\n{}".format(r...
First, regarding your last question. There's a difference between a (3,) `N` and (1,3): ``` In [171]: np.dot(m,[1,2,3]) Out[171]: array([140, 320, 500]) # (3,) result In [172]: np.dot(m,[[1,2,3]]) --------------------------------------------------------------------------- ValueError ...
25,570,507
Still working with LDAP... The problem i submit today is this: i'm creating a posixGroup on a server LDAP using a custom method developed in python using Django framework. I attach the method code below. The main issue is that attribute **gidNumber is compulsory of posixGroup class**, but usually is not required w...
2014/08/29
[ "https://Stackoverflow.com/questions/25570507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3963403/" ]
See paragraph a "Note on Minification" in <https://docs.angularjs.org/tutorial/step_05> It is used to keep a string reference of your injections of dependencies after minifications : > > Since Angular infers the controller's dependencies from the names of > arguments to the controller's constructor function, if you...
Controllers are callables, and their arguments must be injected with existing/valid/registered dependencies. Angular takes three ways: 1. If the passed controller (this also applies to providers) is an array, the last item is the controller, and the former items are expected to be strings with the names of dependencie...
8,127,648
I have two threads in python (2.7). I start them at the beginning of my program. While they execute, my program reaches the end and exits, killing both of my threads before waiting for resolution. I'm trying to figure out how to wait for both threads to finish before exiting. ``` def connect_cam(ip, execute_lock): ...
2011/11/14
[ "https://Stackoverflow.com/questions/8127648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6367/" ]
`Thread` is meant as a lower level primitive interface to Python's threading machinery - use [`threading`](http://docs.python.org/library/threading.html#thread-objects) instead. Then, you can use `threading.join()` to synchronize threads. > > Other threads can call a thread’s join() method. This blocks the > calling...
First, you ought to be using the [threading](http://docs.python.org/library/threading.html#module-threading) module, not the thread module. Next, have your main thread [join()](http://docs.python.org/library/threading.html#threading.Thread.join) the other threads.
8,127,648
I have two threads in python (2.7). I start them at the beginning of my program. While they execute, my program reaches the end and exits, killing both of my threads before waiting for resolution. I'm trying to figure out how to wait for both threads to finish before exiting. ``` def connect_cam(ip, execute_lock): ...
2011/11/14
[ "https://Stackoverflow.com/questions/8127648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6367/" ]
`Thread` is meant as a lower level primitive interface to Python's threading machinery - use [`threading`](http://docs.python.org/library/threading.html#thread-objects) instead. Then, you can use `threading.join()` to synchronize threads. > > Other threads can call a thread’s join() method. This blocks the > calling...
Yoo can do something like that: ``` import threading class connect_cam(threading.Thread): def __init__(self, ip, execute_lock): threading.Thread.__init__(self) self.ip = ip self.execute_lock = execute_lock def run(self): try: conn = TelnetConnection.TelnetClient(s...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
I think your code is ok. You need close resultset, statement and connection in block finally.
Though your code works, I strongly suggest to **refactor it for better maintenance and readability** as shown below. Also, ensure that the resources are closed properly: ``` public void dashboardReports() { handleTotalStocks(); handleTotalSales(); handleTotalPurchages(); //Add others } ``` **hand...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
Since you are only doing `SELECT` operations here, there is no real need for an explicit transaction, because you are not changing the state of the database, and there is nothing to rollback. There is nothing wrong with grouping all `SELECT` statements inside a single `try` block. However, there is a potential drawback...
Though your code works, I strongly suggest to **refactor it for better maintenance and readability** as shown below. Also, ensure that the resources are closed properly: ``` public void dashboardReports() { handleTotalStocks(); handleTotalSales(); handleTotalPurchages(); //Add others } ``` **hand...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
If you are happy with all subsequent `SELECT`s failing if one fails, then I would change the method to throw an exception ``` public void dashboardReports() throws SQLException { .... } ``` and then catch the SQLException from the calling method. **Note** I think it is better to throw/catch a `SQLException` rathe...
Just make sure you close your statements and resultsets: ``` try { String total_stock_value="select sum(price*closingstock)as tsv from purchase_table"; try (Statement ps_tsv=connection.createStatement(); ResultSet set_tsv=ps_tsv.executeQuery(total_stock_value)) { if(set_tsv.next()) { ...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
This violates the [Single Responsbility](https://en.wikipedia.org/wiki/Single_responsibility_principle) and the [Single Layer of Abstraction](http://principles-wiki.net/principles:single_level_of_abstraction) principles. So although this code is technically valid; you should not only focus on its **correctness**, but ...
If you are happy with all subsequent `SELECT`s failing if one fails, then I would change the method to throw an exception ``` public void dashboardReports() throws SQLException { .... } ``` and then catch the SQLException from the calling method. **Note** I think it is better to throw/catch a `SQLException` rathe...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
Since you are only doing `SELECT` operations here, there is no real need for an explicit transaction, because you are not changing the state of the database, and there is nothing to rollback. There is nothing wrong with grouping all `SELECT` statements inside a single `try` block. However, there is a potential drawback...
If you are happy with all subsequent `SELECT`s failing if one fails, then I would change the method to throw an exception ``` public void dashboardReports() throws SQLException { .... } ``` and then catch the SQLException from the calling method. **Note** I think it is better to throw/catch a `SQLException` rathe...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
I think your code is ok. You need close resultset, statement and connection in block finally.
1.You can have a method like , `executeQuery(Connection conn, Statement st, String sql)` to encapsulate and reduce your lines of code. 2.Don't rely on generic `Exception` , catch sql specific exception classes too 3.I don't see a `finally` block there to properly close resources unless you are doing that somewhere e...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
If you are happy with all subsequent `SELECT`s failing if one fails, then I would change the method to throw an exception ``` public void dashboardReports() throws SQLException { .... } ``` and then catch the SQLException from the calling method. **Note** I think it is better to throw/catch a `SQLException` rathe...
1.You can have a method like , `executeQuery(Connection conn, Statement st, String sql)` to encapsulate and reduce your lines of code. 2.Don't rely on generic `Exception` , catch sql specific exception classes too 3.I don't see a `finally` block there to properly close resources unless you are doing that somewhere e...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
Since you are only doing `SELECT` operations here, there is no real need for an explicit transaction, because you are not changing the state of the database, and there is nothing to rollback. There is nothing wrong with grouping all `SELECT` statements inside a single `try` block. However, there is a potential drawback...
1.You can have a method like , `executeQuery(Connection conn, Statement st, String sql)` to encapsulate and reduce your lines of code. 2.Don't rely on generic `Exception` , catch sql specific exception classes too 3.I don't see a `finally` block there to properly close resources unless you are doing that somewhere e...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
This violates the [Single Responsbility](https://en.wikipedia.org/wiki/Single_responsibility_principle) and the [Single Layer of Abstraction](http://principles-wiki.net/principles:single_level_of_abstraction) principles. So although this code is technically valid; you should not only focus on its **correctness**, but ...
Better way is to create method that does common operations: ``` public String execute(String query) throws SQLException { Statement ps_toco=connection.createStatement(); ResultSet set_toco=ps_toco.executeQuery(query); return set_toco.next(); } ``` When you call this method surround it with try catch ...
43,603,199
I am using Docker on a Python Flask webapp, but am getting an error when I try and run it. ``` $ sudo docker run -t imgcomparer6 unable to load configuration from app.py ``` **Python** In my app.py file, my only instance of `app.run()` in the webapp is within the `'__main__':` function (seen [here](https://stackove...
2017/04/25
[ "https://Stackoverflow.com/questions/43603199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1258509/" ]
I think your code is ok. You need close resultset, statement and connection in block finally.
Better way is to create method that does common operations: ``` public String execute(String query) throws SQLException { Statement ps_toco=connection.createStatement(); ResultSet set_toco=ps_toco.executeQuery(query); return set_toco.next(); } ``` When you call this method surround it with try catch ...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
If **spark-shell** doesn't show this line on start: > > Spark context available as 'sc' (master = local[\*], app id = local-XXX). > > > Run ``` val sc = SparkContext.getOrCreate() ```
The issue is that you created `sc` of type `SparkConfig` not `SparkContext` (both have the same initials). --- For using parallelize method in Spark 2.0 version or any other version, `sc` should be `SparkContext` and not `SparkConf`. The correct code should be like this: ``` import org.apache.spark.SparkContext im...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
The issue is that you created `sc` of type `SparkConfig` not `SparkContext` (both have the same initials). --- For using parallelize method in Spark 2.0 version or any other version, `sc` should be `SparkContext` and not `SparkConf`. The correct code should be like this: ``` import org.apache.spark.SparkContext im...
You should prefer to use `SparkSession` as it is the the entry point for Spark from version 2. You could try something like : ``` import org.apache.spark.sql.SparkSession val spark = SparkSession.builder. master("local") .appName("spark session example") .getOrCreate() val sc = spark.sparkContext val data...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
The issue is that you created `sc` of type `SparkConfig` not `SparkContext` (both have the same initials). --- For using parallelize method in Spark 2.0 version or any other version, `sc` should be `SparkContext` and not `SparkConf`. The correct code should be like this: ``` import org.apache.spark.SparkContext im...
There is some problem with `2.2.0 version` of Apache Spark. I replaced it with `2.2.1 version` which is the latest one and i am able to get `sc` and `spark` variables automatically when I start `spark-shell` via `cmd` in `windows 7`. I hope it will help someone. I executed below code which creates rdd and it works p...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
The issue is that you created `sc` of type `SparkConfig` not `SparkContext` (both have the same initials). --- For using parallelize method in Spark 2.0 version or any other version, `sc` should be `SparkContext` and not `SparkConf`. The correct code should be like this: ``` import org.apache.spark.SparkContext im...
Your code shud like this ``` val conf = new SparkConf() conf.setMaster("local[*]") conf.setAppName("myname") val sc = new SparkContext(conf) ``` NOTE: master url should be local[\*]
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
If **spark-shell** doesn't show this line on start: > > Spark context available as 'sc' (master = local[\*], app id = local-XXX). > > > Run ``` val sc = SparkContext.getOrCreate() ```
You should prefer to use `SparkSession` as it is the the entry point for Spark from version 2. You could try something like : ``` import org.apache.spark.sql.SparkSession val spark = SparkSession.builder. master("local") .appName("spark session example") .getOrCreate() val sc = spark.sparkContext val data...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
If **spark-shell** doesn't show this line on start: > > Spark context available as 'sc' (master = local[\*], app id = local-XXX). > > > Run ``` val sc = SparkContext.getOrCreate() ```
There is some problem with `2.2.0 version` of Apache Spark. I replaced it with `2.2.1 version` which is the latest one and i am able to get `sc` and `spark` variables automatically when I start `spark-shell` via `cmd` in `windows 7`. I hope it will help someone. I executed below code which creates rdd and it works p...
47,961,437
I'm using Jupyter Notebook to develop some Python. This is my first stab at logging errors and I'm having an issue where no errors are logged to my error file. I'm using: ``` import logging logger = logging.getLogger('error') logger.propagate = False hdlr = logging.FileHandler("error.log") formatter = logging.Formatt...
2017/12/24
[ "https://Stackoverflow.com/questions/47961437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694657/" ]
If **spark-shell** doesn't show this line on start: > > Spark context available as 'sc' (master = local[\*], app id = local-XXX). > > > Run ``` val sc = SparkContext.getOrCreate() ```
Your code shud like this ``` val conf = new SparkConf() conf.setMaster("local[*]") conf.setAppName("myname") val sc = new SparkContext(conf) ``` NOTE: master url should be local[\*]
16,913,086
I want to run third part tool written in python on my ubuntu machine ([corgy tool](https://github.com/pkerpedjiev/corgy)). However I don't know how to add additional modules to Python path. ``` cat doc/download.rst There is currently no setup.py, so you need to manually add the download directory to your P...
2013/06/04
[ "https://Stackoverflow.com/questions/16913086", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1286528/" ]
Create a `.bash_profile` in your home directory. Then, add the line ``` PYTHONPATH=$PYTHONPATH:new_dir EXPORT $PYTHONPATH ``` Or even better: ``` if [ -d "new_dir" ] ; then PYTHONPATH="$PYTHONPATH:new_dir" fi EXPORT $PYTHONPATH ``` The `.bash_profile` properties are loaded every time you log in. The `source` c...
[@fedorqui](https://stackoverflow.com/users/1983854/fedorqui-so-stop-harming)'s answer above was almost good for me, but there is at least one mistake (I am not sure about the `export` statement in all caps, I am a complete newbie). There should not be a `$` sign preceding PYTHONPATH in the export statement. So the opt...
54,503,298
I have a list of list of lists (all of lists have same size) in python like this: ``` A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] ``` I want to remove some columns (i-th elements of all lists). Is there any way that does this without `for` statements?
2019/02/03
[ "https://Stackoverflow.com/questions/54503298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7789910/" ]
As mentioned, you can't do this without loop. However, using built-in functions here's a functional approach that doesn't explicitly use any loop: ``` In [24]: from operator import itemgetter In [25]: def remove_col(arr, ith): ...: itg = itemgetter(*filter((ith).__ne__, range(len(arr[0])))) ...: retur...
You could easily use [list comprehension](https://www.pythonforbeginners.com/basics/list-comprehensions-in-python) and [slices](https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-python/) : ``` A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] k = 1 B = [l[:k]+l[k+1:] for l in A] print(B) # >> retur...
54,503,298
I have a list of list of lists (all of lists have same size) in python like this: ``` A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] ``` I want to remove some columns (i-th elements of all lists). Is there any way that does this without `for` statements?
2019/02/03
[ "https://Stackoverflow.com/questions/54503298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7789910/" ]
As mentioned, you can't do this without loop. However, using built-in functions here's a functional approach that doesn't explicitly use any loop: ``` In [24]: from operator import itemgetter In [25]: def remove_col(arr, ith): ...: itg = itemgetter(*filter((ith).__ne__, range(len(arr[0])))) ...: retur...
I think you can do this without `for` if you are proficient with `zip` (it's my favorite "hack"): ``` A = [[1, 2, 3, 4], ['a', 'b', 'c', 'd'], [12, 13, 14, 15]] B = list(zip(*A)) B.pop(i) C = list(map(list, zip(*B))) ``` Result (i = 2): ``` [[1, 2, 4], ['a', 'b', 'd'], [12, 13, 15]] ``` --- Of course, `map` is a...
54,503,298
I have a list of list of lists (all of lists have same size) in python like this: ``` A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] ``` I want to remove some columns (i-th elements of all lists). Is there any way that does this without `for` statements?
2019/02/03
[ "https://Stackoverflow.com/questions/54503298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7789910/" ]
As mentioned, you can't do this without loop. However, using built-in functions here's a functional approach that doesn't explicitly use any loop: ``` In [24]: from operator import itemgetter In [25]: def remove_col(arr, ith): ...: itg = itemgetter(*filter((ith).__ne__, range(len(arr[0])))) ...: retur...
`numpy` is able to remove entire columns: ``` import numpy A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] na = numpy.array(A) print(na[:,:-1]) # remove last column print(na[:,1:]) # remove first column print(numpy.concatenate((na[:,:2],na[:,3:]),axis=1)) # build from 2 slices: remove third column ``` res...
54,503,298
I have a list of list of lists (all of lists have same size) in python like this: ``` A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] ``` I want to remove some columns (i-th elements of all lists). Is there any way that does this without `for` statements?
2019/02/03
[ "https://Stackoverflow.com/questions/54503298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7789910/" ]
As mentioned, you can't do this without loop. However, using built-in functions here's a functional approach that doesn't explicitly use any loop: ``` In [24]: from operator import itemgetter In [25]: def remove_col(arr, ith): ...: itg = itemgetter(*filter((ith).__ne__, range(len(arr[0])))) ...: retur...
Another variant using a list-comprehension, with `enumerate`: ``` >>> A = [[1,2,3,4],['a','b','c','d'] , [12,13,14,15]] >>> k = 2 >>> [[x for i, x in enumerate(a) if i != k] for a in A] [[1, 2, 4], ['a', 'b', 'd'], [12, 13, 15]] ``` And, yes, this has the word `for` in it (twice even!), but performance should not be...
60,171,622
I'm working with large data sets. I'm trying to use the NumPy library where I can or python features to process the data sets in an efficient way (e.g. LC). First I find the relevant indexes: ``` dt_temp_idx = np.where(dt_diff > dt_temp_th) ``` Then I want to create a mask containing for each index a sequence start...
2020/02/11
[ "https://Stackoverflow.com/questions/60171622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5080562/" ]
Using masks (boolean arrays) are efficient being memory-efficient and performant too. We will make use of [`SciPy's binary-dilation`](https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.morphology.binary_dilation.html) to extend the thresholded mask. Here's a step-by-step setup and solution run- ...
`dt_temp_idx` is a numpy array, but still a Python iterable so you can use a good old Python list comprehension: ``` lst = [ i for j in dt_temp_idx for i in range(j, j+11)] ``` If you want to cope with sequence overlaps and make it back a np.array, just do: ``` result = np.array({i for j in dt_temp_idx for i in ran...
5,077,625
I'm trying to write a short program that will read in the contents of e-mails within a folder on my exchange/Outlook profile so I can manipulate the data. However I'm having a problem finding much information about python and exchange/Outlook integration. A lot of stuff is either very old/has no docs/not explained. I'v...
2011/02/22
[ "https://Stackoverflow.com/questions/5077625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/559504/" ]
I had the same problem you did - didn't find much that worked. The following code, however, works like a charm. ``` import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case, ...
I have created my own iterator to iterate over Outlook objects via python. The issue is that python tries to iterates starting with Index[0], but outlook expects for first item Index[1]... To make it more Ruby simple, there is below a helper class Oli with following methods: .items() - yields a tuple(index, Item)......
5,077,625
I'm trying to write a short program that will read in the contents of e-mails within a folder on my exchange/Outlook profile so I can manipulate the data. However I'm having a problem finding much information about python and exchange/Outlook integration. A lot of stuff is either very old/has no docs/not explained. I'v...
2011/02/22
[ "https://Stackoverflow.com/questions/5077625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/559504/" ]
I had the same problem you did - didn't find much that worked. The following code, however, works like a charm. ``` import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case, ...
I had the same issue. Combining various approaches from the internet (and above) come up with the following approach (checkEmails.py) ``` class CheckMailer: def __init__(self, filename="LOG1.txt", mailbox="Mailbox - Another User Mailbox", folderindex=3): self.f = FileWriter(filename) s...
5,077,625
I'm trying to write a short program that will read in the contents of e-mails within a folder on my exchange/Outlook profile so I can manipulate the data. However I'm having a problem finding much information about python and exchange/Outlook integration. A lot of stuff is either very old/has no docs/not explained. I'v...
2011/02/22
[ "https://Stackoverflow.com/questions/5077625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/559504/" ]
I had the same problem you did - didn't find much that worked. The following code, however, works like a charm. ``` import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case, ...
Sorry for my bad English. Checking Mails using Python with **MAPI** is easier, ``` outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") folder = outlook.Folders[5] Subfldr = folder.Folders[5] messages_REACH = Subfldr.Items message = messages_REACH.GetFirst() ``` Here we can get the most fi...
5,077,625
I'm trying to write a short program that will read in the contents of e-mails within a folder on my exchange/Outlook profile so I can manipulate the data. However I'm having a problem finding much information about python and exchange/Outlook integration. A lot of stuff is either very old/has no docs/not explained. I'v...
2011/02/22
[ "https://Stackoverflow.com/questions/5077625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/559504/" ]
I have created my own iterator to iterate over Outlook objects via python. The issue is that python tries to iterates starting with Index[0], but outlook expects for first item Index[1]... To make it more Ruby simple, there is below a helper class Oli with following methods: .items() - yields a tuple(index, Item)......
I had the same issue. Combining various approaches from the internet (and above) come up with the following approach (checkEmails.py) ``` class CheckMailer: def __init__(self, filename="LOG1.txt", mailbox="Mailbox - Another User Mailbox", folderindex=3): self.f = FileWriter(filename) s...
5,077,625
I'm trying to write a short program that will read in the contents of e-mails within a folder on my exchange/Outlook profile so I can manipulate the data. However I'm having a problem finding much information about python and exchange/Outlook integration. A lot of stuff is either very old/has no docs/not explained. I'v...
2011/02/22
[ "https://Stackoverflow.com/questions/5077625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/559504/" ]
I have created my own iterator to iterate over Outlook objects via python. The issue is that python tries to iterates starting with Index[0], but outlook expects for first item Index[1]... To make it more Ruby simple, there is below a helper class Oli with following methods: .items() - yields a tuple(index, Item)......
Sorry for my bad English. Checking Mails using Python with **MAPI** is easier, ``` outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") folder = outlook.Folders[5] Subfldr = folder.Folders[5] messages_REACH = Subfldr.Items message = messages_REACH.GetFirst() ``` Here we can get the most fi...
32,150,849
I'm writing a simple Flask app, with the sole purpose to learn Python and MongoDB. I've managed to reach to the point where all the collections are defined, and CRUD operations work in general. Now, one thing that I really want to understand, is how to refresh the collection, after updating its structure. For example,...
2015/08/21
[ "https://Stackoverflow.com/questions/32150849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/971392/" ]
Solution is easier then I expected: ``` db.getCollection('user').update( // query {}, // update { $rename: { 'companies': 'company' } }, // options { "multi" : true, // update all documents "upsert" : false // insert a new document, if no e...
> > I have updated my `user.py` to match my new requests, but anytime I interact with the db its self, since the table's structure was not refreshed, I get the following error > > > MongoDB does not have a "table structure" like relational databases do. After a document has been inserted, you can't change it's sch...
66,684,265
The case is if I want to reverse select a python list to `n` like: ``` n = 3 l = [1,2,3,4,5,6] s = l[5:n:-1] # s is [6, 5] ``` OK, it works, but how can I set `n`'s value to select the whole list? let's see this example, what I expect the first line is `[5, 4, 3, 2, 1]` ``` [40]: for i in range(-1, 5): ...: ...
2021/03/18
[ "https://Stackoverflow.com/questions/66684265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2955827/" ]
I was led to answer from <https://github.com/JeffreyWay/laravel-mix/issues/2896;> they seemed to upgrade the syntax the documentation can be found here: <https://github.com/JeffreyWay/laravel-mix/blob/467f0c9b01b7da71c519619ba8b310422321e0d6/UPGRADE.md#vue-configuration>
When I tried your solution it did not work. Here is how I managed to fix this issue, using this new/changed property additionalData, in previous versions this property was data or prependData. ``` mix.webpackConfig({ module: { rules: [ { test: /\.scss$/, use: [ ...
67,792,538
i'm writing a python script which reads emails from Outlook then extract the body The problem is that when it reads an email answer, the body contains the previous emails. Is there away to avoid that and just extract the body of the email. This is a part of my code : ``` import requests import json import base64 utl...
2021/06/01
[ "https://Stackoverflow.com/questions/67792538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15268168/" ]
Try this solution that uses `zoo` (and `dplyr`, which I'm inferring you're already using): ```r library(dplyr) eg <- expand.grid(Sample.Type = unique(dat$Sample.Type), date = seq(min(dat$date), max(dat$date), by = "day"), stringsAsFactors = FALSE) dat %>% mutate(a=TRUE) %>% full...
You just need to `lag()` while grouping by `Sample.Type`. 1. Toy dataset. I just added a third Sample.Type ```r library(dplyr) library(lubridate) typeday <- tibble( Sample.Type = c("A", "B", "A", "B", "A", "A","B", "C", "C"), date = as.Date(c("2020-10-05", "2020-10-05", "2020-10-06", "20...
65,888,118
I deployed a flask app to IIS using FastCGI and WSGI Handler. The steps that I have followed are 1. Created a virtual environment for Python and installed all packages including wfastCGI. 2. Set the Handler mappings and included the FastCGI settings. 3. Assigned the necessary permissions for the folders by adding IIS\...
2021/01/25
[ "https://Stackoverflow.com/questions/65888118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6831630/" ]
You use the wrong css. The `translateX` is the state, not the animation. Use `animation` instead. ```css @keyframes menu-open { from {width: 0px;} to {width: 220px;} } .open { animation-name: menu-open; animation-duration: 1s; animation-fill-mode: forwards; } @keyframes menu-close { from {width: 220px;}...
You should specify both transform properties in style attribute like so: style={{transform: this.showMenu ? "translateX(0%)" : "translateX(100%)"}}
63,899,935
I'm writing a code to take a rain time-series and save hourly files for each day in order to feed a hydrological model, so, basically, I need to save each file with the hour of the day with tho digits, like this: ``` rain_20200101_0000.txt rain_20200101_0100.txt ... rain_20200101_0900.txt rain_20200101_1000.txt .. rai...
2020/09/15
[ "https://Stackoverflow.com/questions/63899935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7335001/" ]
I experienced the same case, for me, what worked was what has been commented before: Change the value of 'cwd' property in launch.json to the value of the project directory. { ... "cwd": "${workspaceFolder}" } to { ... "cwd": "${workspaceFolder}/SATestUtils.API" } All the credits to Bemm... [![enter image descrip...
Did you try to specify the asp net environment at the launch.json? Something like this: [![enter image description here](https://i.stack.imgur.com/gwMzt.png)](https://i.stack.imgur.com/gwMzt.png)
60,836,709
So after doing some web scraping and turning data frames into lists, I want to compare one list to another that I have created myself. But, if one list doesn’t have a value from another, I want it added in the exact order of the list I’m comparing it to. For example, if I’m comparing one list of snacks with another ...
2020/03/24
[ "https://Stackoverflow.com/questions/60836709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11583556/" ]
Assuming that prices in `ListPrices` are consistent, i.e. if `List1` has two bananas, both have the same price, you can create a `dict` by `zip`ing `List1` and `ListPrices` and then look up the price for the items in `List2` in that dict, or use `nan` as a default. ``` prices = dict(zip(List2, ListPrices)) # {'apples'...
You can convert it to a dictionary for a simple look up ``` d = dict(zip(List2,ListPrices)) [d.get(i,None) for i in List1] ```
60,836,709
So after doing some web scraping and turning data frames into lists, I want to compare one list to another that I have created myself. But, if one list doesn’t have a value from another, I want it added in the exact order of the list I’m comparing it to. For example, if I’m comparing one list of snacks with another ...
2020/03/24
[ "https://Stackoverflow.com/questions/60836709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11583556/" ]
You can convert it to a dictionary for a simple look up ``` d = dict(zip(List2,ListPrices)) [d.get(i,None) for i in List1] ```
so if I understand correctly, `ListPrices` is the list of prices for `List2`. ``` List1 = ['apples', 'bananas', 'cookies', 'soda'] List2 = ['apples', 'cookies', 'soda'] ListPrices = [1, 3, 1] ``` If so, you can make sure to bind prices to each item of `List2` using a dict: ``` MapPrices = dict(zip(List2, ListPrice...
60,836,709
So after doing some web scraping and turning data frames into lists, I want to compare one list to another that I have created myself. But, if one list doesn’t have a value from another, I want it added in the exact order of the list I’m comparing it to. For example, if I’m comparing one list of snacks with another ...
2020/03/24
[ "https://Stackoverflow.com/questions/60836709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11583556/" ]
Assuming that prices in `ListPrices` are consistent, i.e. if `List1` has two bananas, both have the same price, you can create a `dict` by `zip`ing `List1` and `ListPrices` and then look up the price for the items in `List2` in that dict, or use `nan` as a default. ``` prices = dict(zip(List2, ListPrices)) # {'apples'...
so if I understand correctly, `ListPrices` is the list of prices for `List2`. ``` List1 = ['apples', 'bananas', 'cookies', 'soda'] List2 = ['apples', 'cookies', 'soda'] ListPrices = [1, 3, 1] ``` If so, you can make sure to bind prices to each item of `List2` using a dict: ``` MapPrices = dict(zip(List2, ListPrice...
17,980,691
I'm having difficulty getting my sizers to work properly in wxpython. I am trying to do a simple one horizontal bar at top (with text in it) and two vertical boxes below (with gridsizers \* the left one should only be 2 columns!! \* inside each). I want the everything in the image to stretch and fit my panel as well (w...
2013/07/31
[ "https://Stackoverflow.com/questions/17980691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/936911/" ]
Is this what you're after? ![enter image description here](https://i.stack.imgur.com/dodoe.png) ``` import wx class Frame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent) self.panel = wx.Panel(self) main_sizer = wx.BoxSizer(wx.VERTICAL) # Title sel...
something like this?? ``` import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,"Test Stretching!!") p1 = wx.Panel(self,-1,size=(500,100)) p1.SetMinSize((500,100)) p1.SetBackgroundColour(wx.GREEN) hsz = wx.BoxSizer(wx.HORIZONTAL) p2...
17,980,691
I'm having difficulty getting my sizers to work properly in wxpython. I am trying to do a simple one horizontal bar at top (with text in it) and two vertical boxes below (with gridsizers \* the left one should only be 2 columns!! \* inside each). I want the everything in the image to stretch and fit my panel as well (w...
2013/07/31
[ "https://Stackoverflow.com/questions/17980691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/936911/" ]
Is this what you're after? ![enter image description here](https://i.stack.imgur.com/dodoe.png) ``` import wx class Frame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent) self.panel = wx.Panel(self) main_sizer = wx.BoxSizer(wx.VERTICAL) # Title sel...
Here's one way to do it: ``` import wx ######################################################################## class MyPanel(wx.Panel): """""" #---------------------------------------------------------------------- def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, par...
45,876,059
I have this server <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_tls/server.py> And I want to connect to the server with this code: ``` ws = create_connection("wss://127.0.0.1:9000") ``` What options do I need to add to `create_connection`? Adding `sslopt={"cert_reqs": ...
2017/08/25
[ "https://Stackoverflow.com/questions/45876059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1238675/" ]
This works ``` import asyncio import websockets import ssl async def hello(): async with websockets.connect('wss://127.0.0.1:9000',ssl=ssl.SSLContext(protocol=ssl.PROTOCOL_TLS)) as websocket: data = 'hi' await websocket.send(data) print("> {}".format(data)) response = await websoc...
For me the option from the question seems to work: ``` from websocket import create_connection import ssl ws = create_connection("wss://echo.websocket.org", sslopt={"cert_reqs": ssl.CERT_NONE}) ws.send("python hello!") print (ws.recv()) ws.close() ``` See also here: <https://github.com/websocket-client/websocket-c...
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
Using [defaultdict](http://docs.python.org/2/library/collections.html#collections.defaultdict): ``` import itertools from collections import defaultdict a1 = {u'SFP_1': [u'cat', u'3'], u'SFP_0': [u'cat', u'5', u'bat', u'1']} b1 = itertools.chain.from_iterable(a1.itervalues()) c1 = defaultdict(int) for animal, count ...
``` In [8]: a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } In [9]: answer = collections.defaultdict(int) In [10]: for L in a1.values(): for k,v in itertools.izip(itertools.islice(L, 0, len(L), 2), ...
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
``` In [8]: a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } In [9]: answer = collections.defaultdict(int) In [10]: for L in a1.values(): for k,v in itertools.izip(itertools.islice(L, 0, len(L), 2), ...
Try `collections.defaultdict(int):` From the manual - ``` >>> s = 'mississippi' >>> d = defaultdict(int) >>> for k in s: ... d[k] += 1 ... >>> d.items() [('i', 4), ('p', 2), ('s', 4), ('m', 1)] ``` This should let you get to where you need to be.
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
``` In [8]: a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } In [9]: answer = collections.defaultdict(int) In [10]: for L in a1.values(): for k,v in itertools.izip(itertools.islice(L, 0, len(L), 2), ...
For whatever a pure Python solution is worth, here's one. ``` a1 = {'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1']} def count(what): sums = {} for items in what.itervalues(): for k, v in zip(items[::2], items[1::2]): if k in sums: sums[k] = str(int(sums[k]) + int(...
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
``` In [8]: a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } In [9]: answer = collections.defaultdict(int) In [10]: for L in a1.values(): for k,v in itertools.izip(itertools.islice(L, 0, len(L), 2), ...
You can use [collections.Counter](http://docs.python.org/2/library/collections.html#collections.Counter) class, which is basically a specialized version of collections.defaultdict(int) with nice extra methods and nice name: ``` from collections import Counter def count(dct): # Counter is specialized version of de...
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
Using [defaultdict](http://docs.python.org/2/library/collections.html#collections.defaultdict): ``` import itertools from collections import defaultdict a1 = {u'SFP_1': [u'cat', u'3'], u'SFP_0': [u'cat', u'5', u'bat', u'1']} b1 = itertools.chain.from_iterable(a1.itervalues()) c1 = defaultdict(int) for animal, count ...
Try `collections.defaultdict(int):` From the manual - ``` >>> s = 'mississippi' >>> d = defaultdict(int) >>> for k in s: ... d[k] += 1 ... >>> d.items() [('i', 4), ('p', 2), ('s', 4), ('m', 1)] ``` This should let you get to where you need to be.
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
Using [defaultdict](http://docs.python.org/2/library/collections.html#collections.defaultdict): ``` import itertools from collections import defaultdict a1 = {u'SFP_1': [u'cat', u'3'], u'SFP_0': [u'cat', u'5', u'bat', u'1']} b1 = itertools.chain.from_iterable(a1.itervalues()) c1 = defaultdict(int) for animal, count ...
For whatever a pure Python solution is worth, here's one. ``` a1 = {'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1']} def count(what): sums = {} for items in what.itervalues(): for k, v in zip(items[::2], items[1::2]): if k in sums: sums[k] = str(int(sums[k]) + int(...
17,986,923
I have a python dictionary of the form : ``` a1 = { 'SFP_1': ['cat', '3'], 'SFP_0': ['cat', '5', 'bat', '1'] } ``` The end result I need is a dictionary of the form : ``` {'bat': '1', 'cat': '8'} ``` I am currently doing this: ``` b1 = list(itertools.chain(*a1.values())) c1 = dict(itertools...
2013/08/01
[ "https://Stackoverflow.com/questions/17986923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2054020/" ]
Using [defaultdict](http://docs.python.org/2/library/collections.html#collections.defaultdict): ``` import itertools from collections import defaultdict a1 = {u'SFP_1': [u'cat', u'3'], u'SFP_0': [u'cat', u'5', u'bat', u'1']} b1 = itertools.chain.from_iterable(a1.itervalues()) c1 = defaultdict(int) for animal, count ...
You can use [collections.Counter](http://docs.python.org/2/library/collections.html#collections.Counter) class, which is basically a specialized version of collections.defaultdict(int) with nice extra methods and nice name: ``` from collections import Counter def count(dct): # Counter is specialized version of de...
45,045,147
I'm trying to migrate a table with SQLAlchemy Migrate, but I'm getting this error: ``` sqlalchemy.exc.UnboundExecutionError: Table object 'responsibles' is not bound to an Engine or Connection. Execution can not proceed without a database to execute against. ``` When I run: ``` python manage.py test ``` This is ...
2017/07/11
[ "https://Stackoverflow.com/questions/45045147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1934510/" ]
did you create your engine? like this `engine = create_engine('sqlite:///:memory:')` and then do `meta.bind = engine meta.create_all(engine)`
You need to supply `engine` or `connection` [`sqlalchemy.schema.MetaData.bind`](http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.MetaData.bind) For e.g.: ``` engine = create_engine("someurl://") metadata.bind = engine ```
70,596,608
In the office we have a fileWatcher that converts pointclouds to .laz files. We just started working with Revit but came to the conclusion that it is not possible to import .laz in Revit. So I googled and found a solution execept it is written in python and our watcher is in c#. Below the python script. `<location>/dec...
2022/01/05
[ "https://Stackoverflow.com/questions/70596608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10411687/" ]
Convert the columns to `Date` class and use `difftime` ``` df1$Difference <- with(df1, as.numeric(difftime(as.Date(DeliveryDate), as.Date(ExpectedDate), units = "days"))) ``` --- Or using `tidyverse` ``` library(dplyr) library(lubridate) df1 %>% mutate(Difference = as.numeric(difftime(ymd(DeliveryD...
First change your date to lubridate date: 2022-01-05 would be ``` date1 <- ymd("2022-01-05") date2 <- ymd("2022-01-07") diff_days <- difftime(date2, date1, units="days") ```
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I got the same issue and found a [GitHub issue](https://github.com/conda/conda/issues/6073#issuecomment-356981567) related to this. In the comments, @kalefranz posted an ideal solution by using the `--no-builds` flag with conda env export. ``` conda env export --no-builds > environment.yml ``` However, even remove b...
I had a similar issue and was able to work around it. My issue wasn't related to pip but rather because the export platform wasn't the same as the import platform (Ref: nehaljwani's November 2018 answer on <https://github.com/conda/conda/issues/7311>). @Shixiang Wang's answer point towards a part of the solution. The ...
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I got the same issue and found a [GitHub issue](https://github.com/conda/conda/issues/6073#issuecomment-356981567) related to this. In the comments, @kalefranz posted an ideal solution by using the `--no-builds` flag with conda env export. ``` conda env export --no-builds > environment.yml ``` However, even remove b...
tl;dr `conda env export --from-history -n name_of_your_env -f environment.yml` --- `conda env export` command pins your dependencies to the exact version along with OS specific details. Looks like this for Pandas on macOS for example, `- pandas=1.0.5=py38h959d312_0`. `conda env create` cannot use this to create the ...
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I had same problem and found your question googling for it. `ResolvePackageNotFound` error describes all packages not installed yet, but required. To solve the problem, move them under `pip` section: ``` name: ex3 channels: - menpo - defaults dependencies: - cairo=1.14.8=0 - *** - another dependencies, except ...
tl;dr `conda env export --from-history -n name_of_your_env -f environment.yml` --- `conda env export` command pins your dependencies to the exact version along with OS specific details. Looks like this for Pandas on macOS for example, `- pandas=1.0.5=py38h959d312_0`. `conda env create` cannot use this to create the ...
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I had same problem and found your question googling for it. `ResolvePackageNotFound` error describes all packages not installed yet, but required. To solve the problem, move them under `pip` section: ``` name: ex3 channels: - menpo - defaults dependencies: - cairo=1.14.8=0 - *** - another dependencies, except ...
I had a similar issue and was able to work around it. My issue wasn't related to pip but rather because the export platform wasn't the same as the import platform (Ref: nehaljwani's November 2018 answer on <https://github.com/conda/conda/issues/7311>). @Shixiang Wang's answer point towards a part of the solution. The ...
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I got the same issue and found a [GitHub issue](https://github.com/conda/conda/issues/6073#issuecomment-356981567) related to this. In the comments, @kalefranz posted an ideal solution by using the `--no-builds` flag with conda env export. ``` conda env export --no-builds > environment.yml ``` However, even remove b...
There can be another reason for the '**ResolvePackageNotFound**' error -- the version of the packages you require might be in an old version of the repository that is not searched by default. The different paths to locations in the Anaconda repositories can be found at: <https://repo.continuum.io/pkgs/> My yml fil...
49,154,899
I want to create a virtual environment using conda and yml file. Command: ``` conda env create -n ex3 -f env.yml ``` Type ENTER it gives following message: ``` ResolvePackageNotFound: - gst-plugins-base==1.8.0=0 - dbus==1.10.20=0 - opencv3==3.2.0=np111py35_0 - qt==5.6.2=5 - libxcb==1.12=1 - libgcc==5.2.0=0 ...
2018/03/07
[ "https://Stackoverflow.com/questions/49154899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7722305/" ]
I got the same issue and found a [GitHub issue](https://github.com/conda/conda/issues/6073#issuecomment-356981567) related to this. In the comments, @kalefranz posted an ideal solution by using the `--no-builds` flag with conda env export. ``` conda env export --no-builds > environment.yml ``` However, even remove b...
If you are looking at this and feel too much chore to change Conda version `packge=ver=py.*` to pip style `package==ver`, I wrote this small script that delete the `=py.*` part from Conda style. Note below code work on the presume that you already changed `package=ver` to `package==ver`. ``` #!/bin/bash COUNT=0 fi...