qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
7,538,628
So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the `mkvirtualenv` function of virtualenvwrapper. The project has a requirements.txt file with a few required libraries (requests too :D) and the program won't r...
2011/09/24
[ "https://Stackoverflow.com/questions/7538628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151048/" ]
Just source the `virtualenvwrapper.sh` script in your script to import the virtualenvwrapper's functions. You should then be able to use the `workon` function in your script. And maybe better, you could create a shell script (you could name it `venv-run.sh` for example) to run any Python script into a given virtualenv...
I can't find the way to trigger the commands of `virtualenvwrapper` in shell. But this trick can help: assume your env. name is `myenv`, then put following lines at the beginning of scripts: ``` ENV=myenv source $WORKON_HOME/$ENV/bin/activate ```
7,538,628
So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the `mkvirtualenv` function of virtualenvwrapper. The project has a requirements.txt file with a few required libraries (requests too :D) and the program won't r...
2011/09/24
[ "https://Stackoverflow.com/questions/7538628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151048/" ]
I can't find the way to trigger the commands of `virtualenvwrapper` in shell. But this trick can help: assume your env. name is `myenv`, then put following lines at the beginning of scripts: ``` ENV=myenv source $WORKON_HOME/$ENV/bin/activate ```
This is a super old thread and I had a similar issue. I started digging for a simpler solution out of curiousity. ``` gnome-terminal --working-directory='/home/exact/path/here' --tab --title="API" -- bash -ci "workon aaapi && python manage.py runserver 8001; exec bash;" ``` The --workingdirectory forces the tab to ...
7,538,628
So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the `mkvirtualenv` function of virtualenvwrapper. The project has a requirements.txt file with a few required libraries (requests too :D) and the program won't r...
2011/09/24
[ "https://Stackoverflow.com/questions/7538628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151048/" ]
This is a super old thread and I had a similar issue. I started digging for a simpler solution out of curiousity. ``` gnome-terminal --working-directory='/home/exact/path/here' --tab --title="API" -- bash -ci "workon aaapi && python manage.py runserver 8001; exec bash;" ``` The --workingdirectory forces the tab to ...
Apparently, I was doing this the wrong way. Instead of saving the virtualenv's name in the .venv file, I should be putting the virtualenv's directory path. ``` (cdvirtualenv && pwd) > .venv ``` and in the `bin/run-app`, I put ``` source "$(cat .venv)/bin/activate" python main.py ``` And yay!
7,538,628
So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the `mkvirtualenv` function of virtualenvwrapper. The project has a requirements.txt file with a few required libraries (requests too :D) and the program won't r...
2011/09/24
[ "https://Stackoverflow.com/questions/7538628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151048/" ]
Just source the `virtualenvwrapper.sh` script in your script to import the virtualenvwrapper's functions. You should then be able to use the `workon` function in your script. And maybe better, you could create a shell script (you could name it `venv-run.sh` for example) to run any Python script into a given virtualenv...
Apparently, I was doing this the wrong way. Instead of saving the virtualenv's name in the .venv file, I should be putting the virtualenv's directory path. ``` (cdvirtualenv && pwd) > .venv ``` and in the `bin/run-app`, I put ``` source "$(cat .venv)/bin/activate" python main.py ``` And yay!
7,538,628
So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the `mkvirtualenv` function of virtualenvwrapper. The project has a requirements.txt file with a few required libraries (requests too :D) and the program won't r...
2011/09/24
[ "https://Stackoverflow.com/questions/7538628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151048/" ]
It's a [known issue](https://bitbucket.org/dhellmann/virtualenvwrapper/issue/219/cant-deactivate-active-virtualenv-from). As a workaround, you can make the content of the script a function and place it in either `~/.bashrc` or `~/.profile` ``` function run-app() { workon "$(cat .venv)" python main.py } ```
Apparently, I was doing this the wrong way. Instead of saving the virtualenv's name in the .venv file, I should be putting the virtualenv's directory path. ``` (cdvirtualenv && pwd) > .venv ``` and in the `bin/run-app`, I put ``` source "$(cat .venv)/bin/activate" python main.py ``` And yay!
69,624,176
I need to make a letter "C" print using python the code I currently have is down below but I'm not sure how to add 2 stars to the end of the letter. Needed in python. **Here is my current output:** ``` Enter an odd number 5 or greater: 5 *** * * * * *** ``` **Here is my needed Output:** ``` Enter an odd number ...
2021/10/19
[ "https://Stackoverflow.com/questions/69624176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17187287/" ]
You can decouple authentication with authorization to allow more flexible connections between all three entities: Browser, HTTP server, and DB. To make your second example work you could do: * The HTTP server (US) submits asynchroneously the query to the DB (Asia) and requests a auth token for it. * The HTTP server (...
Building on @TheImpalers answer: How about add another table to your remote DB that is just for retrieving query result? When client asks the backend service for database query, the backend service will generate a UUID or other secure token and tell the DB to run the query and store it under the given UUID. The backe...
69,624,176
I need to make a letter "C" print using python the code I currently have is down below but I'm not sure how to add 2 stars to the end of the letter. Needed in python. **Here is my current output:** ``` Enter an odd number 5 or greater: 5 *** * * * * *** ``` **Here is my needed Output:** ``` Enter an odd number ...
2021/10/19
[ "https://Stackoverflow.com/questions/69624176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17187287/" ]
You can decouple authentication with authorization to allow more flexible connections between all three entities: Browser, HTTP server, and DB. To make your second example work you could do: * The HTTP server (US) submits asynchroneously the query to the DB (Asia) and requests a auth token for it. * The HTTP server (...
TLDR: ``` Europe (Client) -> US (Server) -> Asia (Server) -> Asia (DB) ``` Open a HTTP server in Asia (if not don't have access to same DC/server - rent a different one), then re-direct request from HTTP US -> HTTP Asia, which will connect to local DB & stream the response. Redirect can either be a public one (302)...
43,556,353
I have started learning python and using online interpreter for python 2.9-pythontutor ``` x=5,6 if x==5: print "5" else: print "not" ``` It goes in else loop and print not. why is that? what exactly x=5,6 means?
2017/04/22
[ "https://Stackoverflow.com/questions/43556353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7747088/" ]
`,` is tuple expr, where `x,y` will return a tuple `(x,y)` so expression `5,6` will return a tuple `(5,6)` `x` is nether `5` nor `6` but a tuple
When you declared `x = 5, 6` you made it a tuple. Then later when you do `x == 5` this translates to `(5, 6) == 5` which is not true, so the else branch is run. If instead you did `x[0] == 5` that would be true, and print 5. Because we are accessing the 0 index of the tuple, which is equal to 5. Check out [some tutori...
43,556,353
I have started learning python and using online interpreter for python 2.9-pythontutor ``` x=5,6 if x==5: print "5" else: print "not" ``` It goes in else loop and print not. why is that? what exactly x=5,6 means?
2017/04/22
[ "https://Stackoverflow.com/questions/43556353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7747088/" ]
`,` is tuple expr, where `x,y` will return a tuple `(x,y)` so expression `5,6` will return a tuple `(5,6)` `x` is nether `5` nor `6` but a tuple
In Python when you write `x = 4, 5`, it is same as declaring a tuple as `x = (4, 5)`. In interpreter, if you write: ``` >>> x = 4, 5 >>> x (4, 5) ``` Hence, it is similar to comparing a `tuple` with an `int`.
43,556,353
I have started learning python and using online interpreter for python 2.9-pythontutor ``` x=5,6 if x==5: print "5" else: print "not" ``` It goes in else loop and print not. why is that? what exactly x=5,6 means?
2017/04/22
[ "https://Stackoverflow.com/questions/43556353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7747088/" ]
`,` is tuple expr, where `x,y` will return a tuple `(x,y)` so expression `5,6` will return a tuple `(5,6)` `x` is nether `5` nor `6` but a tuple
X here acts as an array, where x is pointed to the first element of the array as x [0] = 5 and x [1] = 6 Execute this code, and the display will be 5 ``` x=5,6 if x[0]==5: print "5" else: print "not" ``` and try to See this link "<http://www.pythontutor.com/visualize.html#mode=edit> " you...
8,572,830
I am building a django application which depends on a python module where a SIGINT signal handler has been implemented. Assuming I cannot change the module I am dependent from, how can I workaround the "signal only works in main thread" error I get integrating it in Django ? Can I run it on the Django main thread? Is...
2011/12/20
[ "https://Stackoverflow.com/questions/8572830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/898179/" ]
Django's built-in development server has auto-reload feature enabled by default which spawns a new thread as a means of reloading code. To work around this you can simply do the following, although you'd obviously lose the convenience of auto-reloading: ``` python manage.py runserver --noreload ``` You'll also need ...
Although the question does not describe exactly the situation you are in, here is some more generic advice: The signal is only sent to the main thread. For this reason, the signal handler should be in the main thread. From that point on, the action that the signal triggers, needs to be communicated to the other thread...
8,572,830
I am building a django application which depends on a python module where a SIGINT signal handler has been implemented. Assuming I cannot change the module I am dependent from, how can I workaround the "signal only works in main thread" error I get integrating it in Django ? Can I run it on the Django main thread? Is...
2011/12/20
[ "https://Stackoverflow.com/questions/8572830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/898179/" ]
I use Python 3.5 and Django 1.8.5 with my project, and I met a similar problem recently. I can easily run my `xxx.py` code with **SIGNAL** directly, but it can't be executed on Django as a package just because of the error "**signal only works in main thread**". Firstly, runserver with `--noreload --nothreading` is us...
Although the question does not describe exactly the situation you are in, here is some more generic advice: The signal is only sent to the main thread. For this reason, the signal handler should be in the main thread. From that point on, the action that the signal triggers, needs to be communicated to the other thread...
8,572,830
I am building a django application which depends on a python module where a SIGINT signal handler has been implemented. Assuming I cannot change the module I am dependent from, how can I workaround the "signal only works in main thread" error I get integrating it in Django ? Can I run it on the Django main thread? Is...
2011/12/20
[ "https://Stackoverflow.com/questions/8572830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/898179/" ]
There is a cleaner way, that doesn't break your ability to use threads and processes. Put your registration calls in manage.py: ``` def handleKill(signum, frame): print "Killing Thread." # Or whatever code you want here ForceTerminate.FORCE_TERMINATE = True print threading.active_count() exit(0)...
Although the question does not describe exactly the situation you are in, here is some more generic advice: The signal is only sent to the main thread. For this reason, the signal handler should be in the main thread. From that point on, the action that the signal triggers, needs to be communicated to the other thread...
8,572,830
I am building a django application which depends on a python module where a SIGINT signal handler has been implemented. Assuming I cannot change the module I am dependent from, how can I workaround the "signal only works in main thread" error I get integrating it in Django ? Can I run it on the Django main thread? Is...
2011/12/20
[ "https://Stackoverflow.com/questions/8572830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/898179/" ]
Django's built-in development server has auto-reload feature enabled by default which spawns a new thread as a means of reloading code. To work around this you can simply do the following, although you'd obviously lose the convenience of auto-reloading: ``` python manage.py runserver --noreload ``` You'll also need ...
I use Python 3.5 and Django 1.8.5 with my project, and I met a similar problem recently. I can easily run my `xxx.py` code with **SIGNAL** directly, but it can't be executed on Django as a package just because of the error "**signal only works in main thread**". Firstly, runserver with `--noreload --nothreading` is us...
8,572,830
I am building a django application which depends on a python module where a SIGINT signal handler has been implemented. Assuming I cannot change the module I am dependent from, how can I workaround the "signal only works in main thread" error I get integrating it in Django ? Can I run it on the Django main thread? Is...
2011/12/20
[ "https://Stackoverflow.com/questions/8572830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/898179/" ]
Django's built-in development server has auto-reload feature enabled by default which spawns a new thread as a means of reloading code. To work around this you can simply do the following, although you'd obviously lose the convenience of auto-reloading: ``` python manage.py runserver --noreload ``` You'll also need ...
There is a cleaner way, that doesn't break your ability to use threads and processes. Put your registration calls in manage.py: ``` def handleKill(signum, frame): print "Killing Thread." # Or whatever code you want here ForceTerminate.FORCE_TERMINATE = True print threading.active_count() exit(0)...
40,390,705
I would like to make an intention list like python does. ``` list = [1,2,3,4] newList = [ i * 2 for i in list ]  ``` Using std,iterator and lambda function, it should be possible to do the same things in one line. ``` std::vector<int> list = {1,2,3,4} ; std::vector<int> newList = ``` Could you complete it ?
2016/11/02
[ "https://Stackoverflow.com/questions/40390705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2708072/" ]
[`std::transform`](http://en.cppreference.com/w/cpp/algorithm/transform) lets you transform values and put them somewhere else: ``` std::vector<int> list = {1,2,3,4}; std::vector<int> newList; std::transform( list.cbegin(), list.cend(), back_inserter(newList), [](int x) { return x * 2; }); ``` But r...
I found this solution. But it's not very nice . ``` std::vector<int> list = {1,2,3,4}; std::vector<int> newList; std::for_each(list.begin(), list.end(),[&newList](int val){newList.push_back(val*2);}); ```
11,333,261
my views.py file code: ``` #!/usr/bin/python from django.template import loader, RequestContext from django.http import HttpResponse #from skey import find_root_tags, count, sorting_list from search.models import Keywords from django.shortcuts import render_to_response as rr def front_page(request): if request...
2012/07/04
[ "https://Stackoverflow.com/questions/11333261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1493850/" ]
``` { % for l in list1 %} ``` should be ``` {% for l in list1 %} ``` and ``` { % endfor %} ``` should be ``` {% endfor %} ```
never put a space between '{' and '%'
13,515,471
I'm generating a bar-chart with matplotlib. It all works well but I can't figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: ![enter image description here](https://i.stack.imgur.com/BCm0v.png) Here is some sample SQL for a postgres 9.1 database: ``` drop table if exi...
2012/11/22
[ "https://Stackoverflow.com/questions/13515471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1808868/" ]
I think you're confused on a few points about how matplotlib handles dates. You're not actually plotting dates, at the moment. You're plotting things on the x-axis with `[0,1,2,...]` and then manually labeling every point with a string representation of the date. Matplotlib will automatically position ticks. However,...
As for your question on how to show only every 4th tick (for example) on the xaxis, you can do this: ``` import matplotlib.ticker as mticker myLocator = mticker.MultipleLocator(4) ax.xaxis.set_major_locator(myLocator) ```
13,515,471
I'm generating a bar-chart with matplotlib. It all works well but I can't figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: ![enter image description here](https://i.stack.imgur.com/BCm0v.png) Here is some sample SQL for a postgres 9.1 database: ``` drop table if exi...
2012/11/22
[ "https://Stackoverflow.com/questions/13515471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1808868/" ]
I think you're confused on a few points about how matplotlib handles dates. You're not actually plotting dates, at the moment. You're plotting things on the x-axis with `[0,1,2,...]` and then manually labeling every point with a string representation of the date. Matplotlib will automatically position ticks. However,...
``` import numpy as np import pandas as pd import matplotlib.pyplot as plt # create a random dataframe with datetimeindex date_range = pd.date_range('1/1/2011', '4/10/2011', freq='D') df = pd.DataFrame(np.random.randint(0,10,size=(100, 1)), columns=['value'], index=date_range) ``` Date ticklabels often overlap: ``` ...
13,515,471
I'm generating a bar-chart with matplotlib. It all works well but I can't figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: ![enter image description here](https://i.stack.imgur.com/BCm0v.png) Here is some sample SQL for a postgres 9.1 database: ``` drop table if exi...
2012/11/22
[ "https://Stackoverflow.com/questions/13515471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1808868/" ]
* The issue in the OP is the dates are formatted as `string` type. `matplotlib` plots every value as a tick label with the tick location being a 0 indexed number based on the number of values. * The resolution to this issue is to convert all values to the correct `type`, `datetime` in this case. + Once the `axes` have...
As for your question on how to show only every 4th tick (for example) on the xaxis, you can do this: ``` import matplotlib.ticker as mticker myLocator = mticker.MultipleLocator(4) ax.xaxis.set_major_locator(myLocator) ```
13,515,471
I'm generating a bar-chart with matplotlib. It all works well but I can't figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: ![enter image description here](https://i.stack.imgur.com/BCm0v.png) Here is some sample SQL for a postgres 9.1 database: ``` drop table if exi...
2012/11/22
[ "https://Stackoverflow.com/questions/13515471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1808868/" ]
* The issue in the OP is the dates are formatted as `string` type. `matplotlib` plots every value as a tick label with the tick location being a 0 indexed number based on the number of values. * The resolution to this issue is to convert all values to the correct `type`, `datetime` in this case. + Once the `axes` have...
``` import numpy as np import pandas as pd import matplotlib.pyplot as plt # create a random dataframe with datetimeindex date_range = pd.date_range('1/1/2011', '4/10/2011', freq='D') df = pd.DataFrame(np.random.randint(0,10,size=(100, 1)), columns=['value'], index=date_range) ``` Date ticklabels often overlap: ``` ...
13,515,471
I'm generating a bar-chart with matplotlib. It all works well but I can't figure out how to prevent the labels of the x-axis from overlapping each other. Here an example: ![enter image description here](https://i.stack.imgur.com/BCm0v.png) Here is some sample SQL for a postgres 9.1 database: ``` drop table if exi...
2012/11/22
[ "https://Stackoverflow.com/questions/13515471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1808868/" ]
As for your question on how to show only every 4th tick (for example) on the xaxis, you can do this: ``` import matplotlib.ticker as mticker myLocator = mticker.MultipleLocator(4) ax.xaxis.set_major_locator(myLocator) ```
``` import numpy as np import pandas as pd import matplotlib.pyplot as plt # create a random dataframe with datetimeindex date_range = pd.date_range('1/1/2011', '4/10/2011', freq='D') df = pd.DataFrame(np.random.randint(0,10,size=(100, 1)), columns=['value'], index=date_range) ``` Date ticklabels often overlap: ``` ...
37,827,920
I followed [this](http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/#comment-72178) to install opencv. When I tested the C and Java samples, they worked fine. But the python samples resulted in a ``` import cv2 ImportError: No module named cv2 ``` How can I fix this? I am using pyth...
2016/06/15
[ "https://Stackoverflow.com/questions/37827920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6417704/" ]
This is a [well known bug](https://connect.microsoft.com/SQLServer/feedback/details/499608/ssms-can-not-paste-more-than-43679-characters-from-a-column-in-grid-mode) in SSMS, You can't paste more than 43679 char from a grid view column and unfortunately this limit can't be increased, You can get around this by displayin...
The datatypes like NCHAR, NVARCHAR, NVARCHAR(MAX) stores half of CHAR, VARCHAR & NVARCHAR(MAX). Because these datatype used to store UNICODE characters. Use these datatypes when you need to store data other then default language (Collation). UNICODE characters take 2 bytes for each character. That's why lenth of NCHAR,...
37,827,920
I followed [this](http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/#comment-72178) to install opencv. When I tested the C and Java samples, they worked fine. But the python samples resulted in a ``` import cv2 ImportError: No module named cv2 ``` How can I fix this? I am using pyth...
2016/06/15
[ "https://Stackoverflow.com/questions/37827920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6417704/" ]
This is a [well known bug](https://connect.microsoft.com/SQLServer/feedback/details/499608/ssms-can-not-paste-more-than-43679-characters-from-a-column-in-grid-mode) in SSMS, You can't paste more than 43679 char from a grid view column and unfortunately this limit can't be increased, You can get around this by displayin...
SQL Server Management Studio has a character limit when printing to the messages pane. There is a workaround to achieve what you need. Using FOR XML to select your data using TYPE you can specify [processing-instruction] and give it a name. Your text will be presented as a link which you can open. This text will have ...
65,716,401
I am trying to install numpy on a macOS Big Sur but got this error. I've tried update pip and setuptool, also update xcode, but the error still appears ``` ERROR: Command errored out with exit status 1: command: /Users/mac/opt/miniconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private...
2021/01/14
[ "https://Stackoverflow.com/questions/65716401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15004197/" ]
Looks like `gcc` compiler or some system library dependencies problem. Here is mine `gcc` version (MacOS Catalina) ``` $ which gcc ``` ``` /usr/bin/gcc ``` ``` $ gcc --version ``` ``` Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDK...
According to similar problem in this link (<https://github.com/numpy/numpy/issues/12026>). You installation tries to compile numpy on your system, which is not necessary. Try to install concrete version of numpy, e.g. `pip3 install numpy==1.19.5`
41,769,507
I have a set of strings that's JSONish, but totally JSON uncompliant. It's also kind of CSV, but values themselves sometimes have commas. The strings look like this: ATTRIBUTE: Value of this attribute, ATTRIBUTE2: Another value, but this one has a comma in it, ATTRIBUTE3:, another value... The only two patterns I ca...
2017/01/20
[ "https://Stackoverflow.com/questions/41769507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3430943/" ]
**Mistake # 1** ``` if (a=0) // condition will be always FALSE ``` must be ``` if (a==0) ``` or better ``` if (0 == a) ``` **Mistake # 2** ``` scanf("%d", &b); // when b is float ``` instead of ``` scanf("%f", &b); ``` **UPDATE:** Actually, for case of checking results of `scanf` I personally prefer t...
Code with corrections and comments - also available here - <http://ideone.com/eqzRQe> ``` #include <stdio.h> #include <math.h> int main(void) { float b; // printf("Eneter a float number"); printf("Enter a float number"); // Corrected typo fflush(stdout); // Send the buffer to the console so the user ca...
39,540,128
I was playing around with the `dis` library to gather information about a function (like what other functions it called). The documentation for [`dis.findlabels`](https://docs.python.org/2/library/dis.html#dis.findlabels) sounds like it would return other function calls, but I've tried it with a handful of functions an...
2016/09/16
[ "https://Stackoverflow.com/questions/39540128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1547004/" ]
No, do not explicitly assign a default value to `Freight`. The warning is legitimate, because you never really assign a value to the field. You do not assign a value, because the field gets populated by magic. (Incidentally, that's why I do not like magic; but that's a different story altogether.) So, the best appr...
You essentially have two choices and which way to go really depends on the intent (to suggest one or the other is subjective). First, you could eliminate the warning if the design requirement of your `Orders` type dictates that it should have a null default value. ``` public string Freight = null; ``` The above mere...
39,540,128
I was playing around with the `dis` library to gather information about a function (like what other functions it called). The documentation for [`dis.findlabels`](https://docs.python.org/2/library/dis.html#dis.findlabels) sounds like it would return other function calls, but I've tried it with a handful of functions an...
2016/09/16
[ "https://Stackoverflow.com/questions/39540128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1547004/" ]
For the sake of completeness, I'm just going to combine blins' answer and Mike's answer - nothing original, just trying to help the next person who runs across this page. Per blins: You may set the value equal to null and the first warning "Field XYZ is assigned to but never used" ``` public string Freight = null; //...
You essentially have two choices and which way to go really depends on the intent (to suggest one or the other is subjective). First, you could eliminate the warning if the design requirement of your `Orders` type dictates that it should have a null default value. ``` public string Freight = null; ``` The above mere...
39,540,128
I was playing around with the `dis` library to gather information about a function (like what other functions it called). The documentation for [`dis.findlabels`](https://docs.python.org/2/library/dis.html#dis.findlabels) sounds like it would return other function calls, but I've tried it with a handful of functions an...
2016/09/16
[ "https://Stackoverflow.com/questions/39540128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1547004/" ]
No, do not explicitly assign a default value to `Freight`. The warning is legitimate, because you never really assign a value to the field. You do not assign a value, because the field gets populated by magic. (Incidentally, that's why I do not like magic; but that's a different story altogether.) So, the best appr...
For the sake of completeness, I'm just going to combine blins' answer and Mike's answer - nothing original, just trying to help the next person who runs across this page. Per blins: You may set the value equal to null and the first warning "Field XYZ is assigned to but never used" ``` public string Freight = null; //...
27,872,305
I have a table with 12 columns and want to select the items in the first column (`qseqid`) based on the second column (`sseqid`). Meaning that the second column (`sseqid`) is repeating with different values in the 11th and 12th columns, which are`evalue`and`bitscore`, respectively. The ones that I would like to get are...
2015/01/10
[ "https://Stackoverflow.com/questions/27872305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1918515/" ]
``` #!usr/bin/python import csv DATA = "data.txt" class Sequence: def __init__(self, row): self.qseqid = row[0] self.sseqid = row[1] self.pident = float(row[2]) self.length = int(row[3]) self.mismatch = int(row[4]) self.gapopen = int(row[5...
``` filename = 'data.txt' readfile = open(filename,'r') d = dict() sseqid=[] lines=[] for i in readfile.readlines(): sseqid.append(i.rsplit()[1]) lines.append(i.rsplit()) sorted_sseqid = sorted(set(sseqid)) sdqDict={} key =None for sorted_ssqd in sorted_sseqid: key=sorted_ssqd evalue=[] bitsco...
27,872,305
I have a table with 12 columns and want to select the items in the first column (`qseqid`) based on the second column (`sseqid`). Meaning that the second column (`sseqid`) is repeating with different values in the 11th and 12th columns, which are`evalue`and`bitscore`, respectively. The ones that I would like to get are...
2015/01/10
[ "https://Stackoverflow.com/questions/27872305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1918515/" ]
``` #!usr/bin/python import csv DATA = "data.txt" class Sequence: def __init__(self, row): self.qseqid = row[0] self.sseqid = row[1] self.pident = float(row[2]) self.length = int(row[3]) self.mismatch = int(row[4]) self.gapopen = int(row[5...
Since you're a Python newbie I'm glad that there are several examples of how to this manually, but for comparison I'll show how it can be done using the [`pandas`](http://pandas.pydata.org) library which makes working with tabular data much simpler. Since you didn't provide example output, I'm assuming that by "with t...
27,872,305
I have a table with 12 columns and want to select the items in the first column (`qseqid`) based on the second column (`sseqid`). Meaning that the second column (`sseqid`) is repeating with different values in the 11th and 12th columns, which are`evalue`and`bitscore`, respectively. The ones that I would like to get are...
2015/01/10
[ "https://Stackoverflow.com/questions/27872305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1918515/" ]
``` #!usr/bin/python import csv DATA = "data.txt" class Sequence: def __init__(self, row): self.qseqid = row[0] self.sseqid = row[1] self.pident = float(row[2]) self.length = int(row[3]) self.mismatch = int(row[4]) self.gapopen = int(row[5...
While not nearly as elegant and concise as using the`pandas`library, it's quite possible to do what you want without resorting to third-party modules. The following uses the`collections.defaultdict`class to facilitate creation of dictionaries of variable-length lists of records. The use of the`AttrDict`class is optiona...
27,872,305
I have a table with 12 columns and want to select the items in the first column (`qseqid`) based on the second column (`sseqid`). Meaning that the second column (`sseqid`) is repeating with different values in the 11th and 12th columns, which are`evalue`and`bitscore`, respectively. The ones that I would like to get are...
2015/01/10
[ "https://Stackoverflow.com/questions/27872305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1918515/" ]
Since you're a Python newbie I'm glad that there are several examples of how to this manually, but for comparison I'll show how it can be done using the [`pandas`](http://pandas.pydata.org) library which makes working with tabular data much simpler. Since you didn't provide example output, I'm assuming that by "with t...
``` filename = 'data.txt' readfile = open(filename,'r') d = dict() sseqid=[] lines=[] for i in readfile.readlines(): sseqid.append(i.rsplit()[1]) lines.append(i.rsplit()) sorted_sseqid = sorted(set(sseqid)) sdqDict={} key =None for sorted_ssqd in sorted_sseqid: key=sorted_ssqd evalue=[] bitsco...
27,872,305
I have a table with 12 columns and want to select the items in the first column (`qseqid`) based on the second column (`sseqid`). Meaning that the second column (`sseqid`) is repeating with different values in the 11th and 12th columns, which are`evalue`and`bitscore`, respectively. The ones that I would like to get are...
2015/01/10
[ "https://Stackoverflow.com/questions/27872305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1918515/" ]
While not nearly as elegant and concise as using the`pandas`library, it's quite possible to do what you want without resorting to third-party modules. The following uses the`collections.defaultdict`class to facilitate creation of dictionaries of variable-length lists of records. The use of the`AttrDict`class is optiona...
``` filename = 'data.txt' readfile = open(filename,'r') d = dict() sseqid=[] lines=[] for i in readfile.readlines(): sseqid.append(i.rsplit()[1]) lines.append(i.rsplit()) sorted_sseqid = sorted(set(sseqid)) sdqDict={} key =None for sorted_ssqd in sorted_sseqid: key=sorted_ssqd evalue=[] bitsco...
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
``` html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split("©") print(html[0][-4:]) print(html[1][:4]) ``` Output : ``` ight Bro ```
Try doing it this way : ``` if "©" in html: pos_c = html.find("©") symbol = html[pos_c-4:pos_c] print symbol ```
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
Here's a **regex only** solution to get the 4 characters before and after the © ``` import re text = "This is all test and try things that's going on bro Copyright© Bro Code Bro" print(re.findall(".{4}©.{4}", text)) ``` Output: ``` ['ight© Bro'] ```
Try doing it this way : ``` if "©" in html: pos_c = html.find("©") symbol = html[pos_c-4:pos_c] print symbol ```
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
``` html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split("©") print(html[0][-4:]) print(html[1][:4]) ``` Output : ``` ight Bro ```
You are almost there! Use search to get index and then slice/dice the string as you like ``` symbol=re.search(r"(?<=©).+$",html).start() ``` The above line give you the index of the match , in this case 63 Use ``` html[symbol:symbol+4] for post and html[symbol-4:symbol] for pre. ```
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
Here's a **regex only** solution to get the 4 characters before and after the © ``` import re text = "This is all test and try things that's going on bro Copyright© Bro Code Bro" print(re.findall(".{4}©.{4}", text)) ``` Output: ``` ['ight© Bro'] ```
You are almost there! Use search to get index and then slice/dice the string as you like ``` symbol=re.search(r"(?<=©).+$",html).start() ``` The above line give you the index of the match , in this case 63 Use ``` html[symbol:symbol+4] for post and html[symbol-4:symbol] for pre. ```
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
``` html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split("©") print(html[0][-4:]) print(html[1][:4]) ``` Output : ``` ight Bro ```
Please use python built in function split() to solve the problem. `html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split('©')`
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
Here's a **regex only** solution to get the 4 characters before and after the © ``` import re text = "This is all test and try things that's going on bro Copyright© Bro Code Bro" print(re.findall(".{4}©.{4}", text)) ``` Output: ``` ['ight© Bro'] ```
``` html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split("©") print(html[0][-4:]) print(html[1][:4]) ``` Output : ``` ight Bro ```
44,063,297
In python, I'm trying to extract 4 charterers before and after '©' symbol,this code extracts the characters after ©,can anyone help printing the characters before © (I don't want the entire string to get print,only few characters) ``` import re html = "This is all test and try things that's going on bro Copyright©...
2017/05/19
[ "https://Stackoverflow.com/questions/44063297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6228540/" ]
Here's a **regex only** solution to get the 4 characters before and after the © ``` import re text = "This is all test and try things that's going on bro Copyright© Bro Code Bro" print(re.findall(".{4}©.{4}", text)) ``` Output: ``` ['ight© Bro'] ```
Please use python built in function split() to solve the problem. `html = "This is all test and try things that's going on bro Copyright© Bro Code Bro" html = html.split('©')`
65,635,575
I get the following error when I attempt to load a saved `sklearn.preprocessing.MinMaxScaler` ``` /shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use a...
2021/01/08
[ "https://Stackoverflow.com/questions/65635575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7253453/" ]
The issue is you are training the scaler on a machine with an older verion of sklearn than the machine you're using to load the scaler. Noitce the `UserWarning` `UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. U...
I solved this issue with `pip install scikit-learn==0.23.2` in my conda or cmd. Essentially downgrading the scikit module helped.
65,635,575
I get the following error when I attempt to load a saved `sklearn.preprocessing.MinMaxScaler` ``` /shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use a...
2021/01/08
[ "https://Stackoverflow.com/questions/65635575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7253453/" ]
The issue is you are training the scaler on a machine with an older verion of sklearn than the machine you're using to load the scaler. Noitce the `UserWarning` `UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. U...
New property `clip` was added to `MinMaxScaler` in later version (since 0.24). ``` # loading and transforming import joblib from sklearn.preprocessing import MinMaxScaler scaler = joblib.load('scaler') assert isinstance(scaler, MinMaxScaler) scaler.clip = False # add this line data = scaler.transform(data) # throws...
65,635,575
I get the following error when I attempt to load a saved `sklearn.preprocessing.MinMaxScaler` ``` /shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use a...
2021/01/08
[ "https://Stackoverflow.com/questions/65635575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7253453/" ]
The issue is you are training the scaler on a machine with an older verion of sklearn than the machine you're using to load the scaler. Noitce the `UserWarning` `UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. U...
version issue of **sklearn** You need to install in windows `pip install scikit-learn==0.24.0` I solve my Problem using this command
65,635,575
I get the following error when I attempt to load a saved `sklearn.preprocessing.MinMaxScaler` ``` /shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use a...
2021/01/08
[ "https://Stackoverflow.com/questions/65635575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7253453/" ]
I solved this issue with `pip install scikit-learn==0.23.2` in my conda or cmd. Essentially downgrading the scikit module helped.
version issue of **sklearn** You need to install in windows `pip install scikit-learn==0.24.0` I solve my Problem using this command
65,635,575
I get the following error when I attempt to load a saved `sklearn.preprocessing.MinMaxScaler` ``` /shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use a...
2021/01/08
[ "https://Stackoverflow.com/questions/65635575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7253453/" ]
New property `clip` was added to `MinMaxScaler` in later version (since 0.24). ``` # loading and transforming import joblib from sklearn.preprocessing import MinMaxScaler scaler = joblib.load('scaler') assert isinstance(scaler, MinMaxScaler) scaler.clip = False # add this line data = scaler.transform(data) # throws...
version issue of **sklearn** You need to install in windows `pip install scikit-learn==0.24.0` I solve my Problem using this command
40,511,177
I am actually new to python. While learning it I came across this piece of code. Python official document says when encounter with continue statement, control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? C...
2016/11/09
[ "https://Stackoverflow.com/questions/40511177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6250108/" ]
The `finally` code is always executed in a `try/except` block. The `continue` doesn't skip it (or it would be a bug in python).
The `finally` clause **must be executed** no matter what happens, and so it is. This is why it's called `finally`: it doesn't matter whether what you have *tried* succeeded or raised an *except*ion, it is *always* executed.
40,511,177
I am actually new to python. While learning it I came across this piece of code. Python official document says when encounter with continue statement, control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? C...
2016/11/09
[ "https://Stackoverflow.com/questions/40511177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6250108/" ]
The `finally` code is always executed in a `try/except` block. The `continue` doesn't skip it (or it would be a bug in python).
finally will be executed always in a try/exept no matter what is the exception.I think this material will help you <https://docs.python.org/2.5/whatsnew/pep-341.html>
40,511,177
I am actually new to python. While learning it I came across this piece of code. Python official document says when encounter with continue statement, control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? C...
2016/11/09
[ "https://Stackoverflow.com/questions/40511177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6250108/" ]
This is stated in the [documentation for the `continue` statement](https://docs.python.org/3/reference/simple_stmts.html#the-continue-statement): > > When continue passes control out of a try statement with a finally clause, *that finally clause is executed before really starting the next loop cycle*. > > > (Emph...
The `finally` clause **must be executed** no matter what happens, and so it is. This is why it's called `finally`: it doesn't matter whether what you have *tried* succeeded or raised an *except*ion, it is *always* executed.
40,511,177
I am actually new to python. While learning it I came across this piece of code. Python official document says when encounter with continue statement, control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? C...
2016/11/09
[ "https://Stackoverflow.com/questions/40511177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6250108/" ]
The `finally` clause **must be executed** no matter what happens, and so it is. This is why it's called `finally`: it doesn't matter whether what you have *tried* succeeded or raised an *except*ion, it is *always* executed.
finally will be executed always in a try/exept no matter what is the exception.I think this material will help you <https://docs.python.org/2.5/whatsnew/pep-341.html>
40,511,177
I am actually new to python. While learning it I came across this piece of code. Python official document says when encounter with continue statement, control will shift to the beginning of the loop, but in this case it is shifting to final statement and executing from there onward. Is this a bug in python or what? C...
2016/11/09
[ "https://Stackoverflow.com/questions/40511177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6250108/" ]
This is stated in the [documentation for the `continue` statement](https://docs.python.org/3/reference/simple_stmts.html#the-continue-statement): > > When continue passes control out of a try statement with a finally clause, *that finally clause is executed before really starting the next loop cycle*. > > > (Emph...
finally will be executed always in a try/exept no matter what is the exception.I think this material will help you <https://docs.python.org/2.5/whatsnew/pep-341.html>
30,080,491
I am trying to reproduce the algorithm described in the Isolation Forest paper in python. <http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf?q=isolation> This is my current code: ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd from sklearn.decomposition i...
2015/05/06
[ "https://Stackoverflow.com/questions/30080491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2411173/" ]
``` self.anomaly_score_ = _anomaly_score(self.all_anomaly_score_, n_samples) ``` You're calculating \_anomaly\_score with n\_samples which is total number of samples. However, you are building trees with subsamples. Therefore, when you're calculating the average search length '\_c(n)' you should use sample\_size inst...
There is a pull-request in scikit-learn: <https://github.com/scikit-learn/scikit-learn/pull/4163>
30,080,491
I am trying to reproduce the algorithm described in the Isolation Forest paper in python. <http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf?q=isolation> This is my current code: ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd from sklearn.decomposition i...
2015/05/06
[ "https://Stackoverflow.com/questions/30080491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2411173/" ]
I have finally been able to solve the problem. The code is still slow due to the continuous copy operation performed in each split on the data. This is the working version of the algorithm. ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd def _h(i): return np.log(...
There is a pull-request in scikit-learn: <https://github.com/scikit-learn/scikit-learn/pull/4163>
30,080,491
I am trying to reproduce the algorithm described in the Isolation Forest paper in python. <http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf?q=isolation> This is my current code: ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd from sklearn.decomposition i...
2015/05/06
[ "https://Stackoverflow.com/questions/30080491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2411173/" ]
I have finally been able to solve the problem. The code is still slow due to the continuous copy operation performed in each split on the data. This is the working version of the algorithm. ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd def _h(i): return np.log(...
``` self.anomaly_score_ = _anomaly_score(self.all_anomaly_score_, n_samples) ``` You're calculating \_anomaly\_score with n\_samples which is total number of samples. However, you are building trees with subsamples. Therefore, when you're calculating the average search length '\_c(n)' you should use sample\_size inst...
30,080,491
I am trying to reproduce the algorithm described in the Isolation Forest paper in python. <http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf?q=isolation> This is my current code: ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd from sklearn.decomposition i...
2015/05/06
[ "https://Stackoverflow.com/questions/30080491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2411173/" ]
``` self.anomaly_score_ = _anomaly_score(self.all_anomaly_score_, n_samples) ``` You're calculating \_anomaly\_score with n\_samples which is total number of samples. However, you are building trees with subsamples. Therefore, when you're calculating the average search length '\_c(n)' you should use sample\_size inst...
Donbeo, your code works pretty well with just a few minor adjustments, the main problem it had is that you missed one of the base cases (end condition) of the recursive algorithm, so it hangs in loop when that condition comes up. You need something to this effect in the \_split\_data function (shown in code below) and ...
30,080,491
I am trying to reproduce the algorithm described in the Isolation Forest paper in python. <http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf?q=isolation> This is my current code: ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd from sklearn.decomposition i...
2015/05/06
[ "https://Stackoverflow.com/questions/30080491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2411173/" ]
I have finally been able to solve the problem. The code is still slow due to the continuous copy operation performed in each split on the data. This is the working version of the algorithm. ``` import numpy as np import sklearn as sk import matplotlib.pyplot as plt import pandas as pd def _h(i): return np.log(...
Donbeo, your code works pretty well with just a few minor adjustments, the main problem it had is that you missed one of the base cases (end condition) of the recursive algorithm, so it hangs in loop when that condition comes up. You need something to this effect in the \_split\_data function (shown in code below) and ...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
**1)** To the best of my knowledge as of early Nov, 2017 you are correct: there is no commonly available way to compile Swift to WebAssembly. Maybe some enterprising hacker somewhere has made it happen but if so she hasn't shared her code with us yet. **2)** In order to enable Wasm support you will probably need to ha...
WebAssembly target would be like a generic unix target for llvm, so I think someone needs develop that port. Please note that Swift -> Wasm in browser would be pretty much useless because Wasm has no DOM or DOM API access so you still need JavaScript to do anything meaningful, thus the question: why would anyone bothe...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
It looks like there is a commercial offering that supports compilation of Swift to WebAssembly. RemObjects, the developer tooling company, has [just announced support for WebAssembly with their Elements compiler](https://blogs.remobjects.com/2018/01/12/webassembly-swift-c-java-and-oxygene-in-the-browser/), which can co...
WebAssembly target would be like a generic unix target for llvm, so I think someone needs develop that port. Please note that Swift -> Wasm in browser would be pretty much useless because Wasm has no DOM or DOM API access so you still need JavaScript to do anything meaningful, thus the question: why would anyone bothe...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
As of May 2019 there's an open-source project available called [SwiftWasm](https://swiftwasm.org/) that allows you to compile Swift code to WebAssembly targeting [WASI SDK](https://wasi.dev). This means that binaries produced by SwiftWasm can be executed either in browsers with [WASI polyfill](https://wasi.dev/polyfill...
WebAssembly target would be like a generic unix target for llvm, so I think someone needs develop that port. Please note that Swift -> Wasm in browser would be pretty much useless because Wasm has no DOM or DOM API access so you still need JavaScript to do anything meaningful, thus the question: why would anyone bothe...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
I was looking for a way to convert Swift code to web assembly, and I found this. <https://swiftwasm.org/> I do not know how mature this platform is (October 2022) and if it can flourish, but having the capability is exciting. Also, it provides means for writing JavaScript in Swift directly.
WebAssembly target would be like a generic unix target for llvm, so I think someone needs develop that port. Please note that Swift -> Wasm in browser would be pretty much useless because Wasm has no DOM or DOM API access so you still need JavaScript to do anything meaningful, thus the question: why would anyone bothe...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
**1)** To the best of my knowledge as of early Nov, 2017 you are correct: there is no commonly available way to compile Swift to WebAssembly. Maybe some enterprising hacker somewhere has made it happen but if so she hasn't shared her code with us yet. **2)** In order to enable Wasm support you will probably need to ha...
It looks like there is a commercial offering that supports compilation of Swift to WebAssembly. RemObjects, the developer tooling company, has [just announced support for WebAssembly with their Elements compiler](https://blogs.remobjects.com/2018/01/12/webassembly-swift-c-java-and-oxygene-in-the-browser/), which can co...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
**1)** To the best of my knowledge as of early Nov, 2017 you are correct: there is no commonly available way to compile Swift to WebAssembly. Maybe some enterprising hacker somewhere has made it happen but if so she hasn't shared her code with us yet. **2)** In order to enable Wasm support you will probably need to ha...
As of May 2019 there's an open-source project available called [SwiftWasm](https://swiftwasm.org/) that allows you to compile Swift code to WebAssembly targeting [WASI SDK](https://wasi.dev). This means that binaries produced by SwiftWasm can be executed either in browsers with [WASI polyfill](https://wasi.dev/polyfill...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
**1)** To the best of my knowledge as of early Nov, 2017 you are correct: there is no commonly available way to compile Swift to WebAssembly. Maybe some enterprising hacker somewhere has made it happen but if so she hasn't shared her code with us yet. **2)** In order to enable Wasm support you will probably need to ha...
I was looking for a way to convert Swift code to web assembly, and I found this. <https://swiftwasm.org/> I do not know how mature this platform is (October 2022) and if it can flourish, but having the capability is exciting. Also, it provides means for writing JavaScript in Swift directly.
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
It looks like there is a commercial offering that supports compilation of Swift to WebAssembly. RemObjects, the developer tooling company, has [just announced support for WebAssembly with their Elements compiler](https://blogs.remobjects.com/2018/01/12/webassembly-swift-c-java-and-oxygene-in-the-browser/), which can co...
As of May 2019 there's an open-source project available called [SwiftWasm](https://swiftwasm.org/) that allows you to compile Swift code to WebAssembly targeting [WASI SDK](https://wasi.dev). This means that binaries produced by SwiftWasm can be executed either in browsers with [WASI polyfill](https://wasi.dev/polyfill...
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
It looks like there is a commercial offering that supports compilation of Swift to WebAssembly. RemObjects, the developer tooling company, has [just announced support for WebAssembly with their Elements compiler](https://blogs.remobjects.com/2018/01/12/webassembly-swift-c-java-and-oxygene-in-the-browser/), which can co...
I was looking for a way to convert Swift code to web assembly, and I found this. <https://swiftwasm.org/> I do not know how mature this platform is (October 2022) and if it can flourish, but having the capability is exciting. Also, it provides means for writing JavaScript in Swift directly.
46,572,148
I am receiving the following error message in spyder. Warning: You are using requests version , which is older than requests-oauthlib expects, please upgrade to 2.0.0 or later. I am not sure how i upgrade requests. I am using python 2.7 as part of an anaconda installation
2017/10/04
[ "https://Stackoverflow.com/questions/46572148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7426556/" ]
As of May 2019 there's an open-source project available called [SwiftWasm](https://swiftwasm.org/) that allows you to compile Swift code to WebAssembly targeting [WASI SDK](https://wasi.dev). This means that binaries produced by SwiftWasm can be executed either in browsers with [WASI polyfill](https://wasi.dev/polyfill...
I was looking for a way to convert Swift code to web assembly, and I found this. <https://swiftwasm.org/> I do not know how mature this platform is (October 2022) and if it can flourish, but having the capability is exciting. Also, it provides means for writing JavaScript in Swift directly.
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
It is the simplest way to download and save the image from internet using **urlib.request** package. Here, you can simply pass the image URL(from where you want to download and save the image) and directory(where you want to save the download image locally, and give the image name with .jpg or .png) Here I given "loc...
download and save image to directory ==================================== ``` import requests headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en...
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
``` import requests img_data = requests.get(image_url).content with open('image_name.jpg', 'wb') as handler: handler.write(img_data) ```
Python code snippet to download a file from an url and save with its name ``` import requests url = 'http://google.com/favicon.ico' filename = url.split('/')[-1] r = requests.get(url, allow_redirects=True) open(filename, 'wb').write(r.content) ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
``` import requests img_data = requests.get(image_url).content with open('image_name.jpg', 'wb') as handler: handler.write(img_data) ```
For linux in case; you can use wget command ``` import os url1 = 'YOUR_URL_WHATEVER' os.system('wget {}'.format(url1)) ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
``` import requests img_data = requests.get(image_url).content with open('image_name.jpg', 'wb') as handler: handler.write(img_data) ```
```py import random import urllib.request def download_image(url): name = random.randrange(1,100) fullname = str(name)+".jpg" urllib.request.urlretrieve(url,fullname) download_image("http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg") ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
A sample code that works for me on Windows: ``` import requests with open('pic1.jpg', 'wb') as handle: response = requests.get(pic_url, stream=True) if not response.ok: print(response) for block in response.iter_content(1024): if not block: break handle.write(block) ...
For linux in case; you can use wget command ``` import os url1 = 'YOUR_URL_WHATEVER' os.system('wget {}'.format(url1)) ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
A sample code that works for me on Windows: ``` import requests with open('pic1.jpg', 'wb') as handle: response = requests.get(pic_url, stream=True) if not response.ok: print(response) for block in response.iter_content(1024): if not block: break handle.write(block) ...
download and save image to directory ==================================== ``` import requests headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en...
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
```py import random import urllib.request def download_image(url): name = random.randrange(1,100) fullname = str(name)+".jpg" urllib.request.urlretrieve(url,fullname) download_image("http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg") ```
For linux in case; you can use wget command ``` import os url1 = 'YOUR_URL_WHATEVER' os.system('wget {}'.format(url1)) ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
For linux in case; you can use wget command ``` import os url1 = 'YOUR_URL_WHATEVER' os.system('wget {}'.format(url1)) ```
download and save image to directory ==================================== ``` import requests headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en...
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
You can pick any arbitrary image from Google Images, copy the url, and use the following approach to download the image. Note that the extension isn't always included in the url, as some of the other answers seem to assume. You can automatically detect the correct extension using imghdr, which is included with Python 3...
if you want to stick to 2 lines? : ``` with open(os.path.join(dir_path, url[0]), 'wb') as f: f.write(requests.get(new_url).content) ```
30,229,231
I got a problem when I am using python to save an image from url either by urllib2 request or urllib.urlretrieve. That is the url of the image is valid. I could download it manually using the explorer. However, when I use python to download the image, the file cannot be opened. I use Mac OS preview to view the image. T...
2015/05/14
[ "https://Stackoverflow.com/questions/30229231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4898319/" ]
It is the simplest way to download and save the image from internet using **urlib.request** package. Here, you can simply pass the image URL(from where you want to download and save the image) and directory(where you want to save the download image locally, and give the image name with .jpg or .png) Here I given "loc...
For linux in case; you can use wget command ``` import os url1 = 'YOUR_URL_WHATEVER' os.system('wget {}'.format(url1)) ```
31,550,622
I can call MATLAB from my system python: ``` >>> import matlab.engine >>> ``` but when I load a virtual environment, I now get a segfault: ``` >>> import matlab.engine Segmentation fault: 11 ``` I've run the [setup.py install instructions](http://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-e...
2015/07/21
[ "https://Stackoverflow.com/questions/31550622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/362703/" ]
I did this: ``` cd "matlabroot\extern\engines\python" python setup.py install --prefix="installdir" ``` Where the `installdir` is my virtualenv, `matlabroot` the directory for the MatLab install. Seems to work with my windows server, so far, so good. Reference here: <https://www.mathworks.com/help/matlab/matlab_e...
I ran the "`python setup.py install`" from `matlabroot\extern\engines\python` with my virtual environment active. Note that I did use `venv`.
31,550,622
I can call MATLAB from my system python: ``` >>> import matlab.engine >>> ``` but when I load a virtual environment, I now get a segfault: ``` >>> import matlab.engine Segmentation fault: 11 ``` I've run the [setup.py install instructions](http://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-e...
2015/07/21
[ "https://Stackoverflow.com/questions/31550622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/362703/" ]
I did this: ``` cd "matlabroot\extern\engines\python" python setup.py install --prefix="installdir" ``` Where the `installdir` is my virtualenv, `matlabroot` the directory for the MatLab install. Seems to work with my windows server, so far, so good. Reference here: <https://www.mathworks.com/help/matlab/matlab_e...
I have successfully run Matlab 2019b through venv. The command that I used: `sudo python3.7 setup.py install --prefix="/home/ubuntu/alexandros/vitrualEnv/py37` You have to give the path to the full environment. In my case, it is `/home/ubuntu/alexandros/vitrualEnv/py37/`. Inside the virtual environment, you will see ...
37,465,816
The Getting Started docs for aiohttp give the following client example: ``` import asyncio import aiohttp async def fetch_page(session, url): with aiohttp.Timeout(10): async with session.get(url) as response: assert response.status == 200 return await response.read() loop = asynci...
2016/05/26
[ "https://Stackoverflow.com/questions/37465816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58866/" ]
Just don't use the result of `session.get()` as a context manager; use it as a coroutine directly instead. The request context manager that `session.get()` produces would normally [*release* the request](http://pythonhosted.org/aiohttp/client_reference.html#aiohttp.ClientResponse.release) on exit, but [so does using `r...
`aiohttp`'s [examples](https://github.com/KeepSafe/aiohttp/tree/master/examples) implemented using 3.4 syntax. Based on [json client example](https://github.com/KeepSafe/aiohttp/blob/master/examples/client_json.py) your function would be: ``` @asyncio.coroutine def fetch(session, url): with aiohttp.Timeout(10): ...
52,211,917
Trying to create a batch script for windows that runs a program with python3 if available else python2. I know the script can be executed with `$py -2 script.py` and py3 with `$py -3 script.py`. and if I run `py -0`, it returns all the python versions. How do I build this script? I do not want to check if the pytho...
2018/09/06
[ "https://Stackoverflow.com/questions/52211917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5252492/" ]
Not a full solution, but a method to detect which version of Python is installed: You can check if Python 3 is installed by running `py -3 --version` and then checking the `%ERRORLEVEL%` variable in the batch script. If it is 0, then `py -3 --version` was successful, i.e. Python 3 is installed on the system. If it is ...
You can do it without temporary file ``` set PYTHON_MAJOR_VERSION=0 for /f %%i in ('python -c "import sys; print(sys.version_info[0])"') do set PYTHON_MAJOR_VERSION=%%i ```
52,211,917
Trying to create a batch script for windows that runs a program with python3 if available else python2. I know the script can be executed with `$py -2 script.py` and py3 with `$py -3 script.py`. and if I run `py -0`, it returns all the python versions. How do I build this script? I do not want to check if the pytho...
2018/09/06
[ "https://Stackoverflow.com/questions/52211917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5252492/" ]
Piping directly `python.exe --version` to `find` or `findstr` is not working (with python 2.7). Building dinamicaly and running a python script that return the version, will enable this piping ! The solution : ``` @echo off set "$py=0" call:construct for /f "delims=" %%a in ('python #.py ^| findstr "2"') do set "$...
You can do it without temporary file ``` set PYTHON_MAJOR_VERSION=0 for /f %%i in ('python -c "import sys; print(sys.version_info[0])"') do set PYTHON_MAJOR_VERSION=%%i ```
67,644,959
Since the code was cryptic I decided to reformulate it. This code is trying to remove the second element from a linked list (the node with number 2 on "int data"). The first parameter of remove\_node is the address of the first pointer of the list, so if I have to remove the first pointer of the list I am able to star...
2021/05/22
[ "https://Stackoverflow.com/questions/67644959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15996314/" ]
First of all, if the first `while` loop stops due to `*address_of_ptr == NULL`, then the line `address_of_ptr = &((*address_of_ptr)->next);` will cause undefined behavior, due to deferencing a `NULL` pointer. However, this will not happen with the sample input provided by the function `main`, so it is not the cause o...
This line: ``` begin_list = &previous->next; ``` You might be mis-thinking how pointers to pointers work. Since `begin_list` is a `t_list **`, you generally want to assign to `*begin_list`. Also, since `previous->next` is already an address, you don't want to assign the address to `*begin_list`, just the value, so t...
67,644,959
Since the code was cryptic I decided to reformulate it. This code is trying to remove the second element from a linked list (the node with number 2 on "int data"). The first parameter of remove\_node is the address of the first pointer of the list, so if I have to remove the first pointer of the list I am able to star...
2021/05/22
[ "https://Stackoverflow.com/questions/67644959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15996314/" ]
First of all, if the first `while` loop stops due to `*address_of_ptr == NULL`, then the line `address_of_ptr = &((*address_of_ptr)->next);` will cause undefined behavior, due to deferencing a `NULL` pointer. However, this will not happen with the sample input provided by the function `main`, so it is not the cause o...
I prepared an answer last night several minutes after you asked the question at first, and put a lot of thought into it, but didn't come back until just now. I'd let my version go, but it's a more detailed look into the problem anyway, so I thought I'd include it for posterity. --- The problem lay on line 36: ``` ...
67,644,959
Since the code was cryptic I decided to reformulate it. This code is trying to remove the second element from a linked list (the node with number 2 on "int data"). The first parameter of remove\_node is the address of the first pointer of the list, so if I have to remove the first pointer of the list I am able to star...
2021/05/22
[ "https://Stackoverflow.com/questions/67644959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15996314/" ]
I would like to thank everyone who helped me sorting this issue, I truly appreciate your effort in making the explanation clear as possible. After a lot of thinking a solution that I believe is much simpler than my first code come up. @David C. Rankin mentioned ["Linus on Understanding Pointers"](https://grisha.org/blo...
This line: ``` begin_list = &previous->next; ``` You might be mis-thinking how pointers to pointers work. Since `begin_list` is a `t_list **`, you generally want to assign to `*begin_list`. Also, since `previous->next` is already an address, you don't want to assign the address to `*begin_list`, just the value, so t...
67,644,959
Since the code was cryptic I decided to reformulate it. This code is trying to remove the second element from a linked list (the node with number 2 on "int data"). The first parameter of remove\_node is the address of the first pointer of the list, so if I have to remove the first pointer of the list I am able to star...
2021/05/22
[ "https://Stackoverflow.com/questions/67644959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15996314/" ]
I would like to thank everyone who helped me sorting this issue, I truly appreciate your effort in making the explanation clear as possible. After a lot of thinking a solution that I believe is much simpler than my first code come up. @David C. Rankin mentioned ["Linus on Understanding Pointers"](https://grisha.org/blo...
I prepared an answer last night several minutes after you asked the question at first, and put a lot of thought into it, but didn't come back until just now. I'd let my version go, but it's a more detailed look into the problem anyway, so I thought I'd include it for posterity. --- The problem lay on line 36: ``` ...
50,187,041
I need help with my python program. I'm doing a calculator. The numbers must be formed, but for some reason they do not add up. It seems that I did everything right, but the program does not work. Please help me. [Picture](https://i.stack.imgur.com/777SB.png) Code: ``` a = input('Enter number A \n'); d = input('En...
2018/05/05
[ "https://Stackoverflow.com/questions/50187041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9744650/" ]
Please don't post screenshots. Copy and paste text and use the {} CODE markdown. What data type is returned by input()? It's always a string. It doesn't matter what you type. Where is the variable c actually calculated in this program? Line 4. What types of data are used to compute c? Two strings. What happens when...
`a` and `b` are strings. `a + b` concatenates strings `a` and `b`. You need to convert the strings to int: `c = int(a) + int(b)` And remove the lines: ``` if str(d) == "+": int(c) == "a + b" ```
50,187,041
I need help with my python program. I'm doing a calculator. The numbers must be formed, but for some reason they do not add up. It seems that I did everything right, but the program does not work. Please help me. [Picture](https://i.stack.imgur.com/777SB.png) Code: ``` a = input('Enter number A \n'); d = input('En...
2018/05/05
[ "https://Stackoverflow.com/questions/50187041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9744650/" ]
Please don't post screenshots. Copy and paste text and use the {} CODE markdown. What data type is returned by input()? It's always a string. It doesn't matter what you type. Where is the variable c actually calculated in this program? Line 4. What types of data are used to compute c? Two strings. What happens when...
Here is the complete code, that should to what you want: ``` a = input('Enter number A \n'); operation = input('Enter sign operations \n') b = input('Enter number B \n') c = a + b if operation == "+": c= int(a) + int(b) print('Answer:', c) ```
50,187,041
I need help with my python program. I'm doing a calculator. The numbers must be formed, but for some reason they do not add up. It seems that I did everything right, but the program does not work. Please help me. [Picture](https://i.stack.imgur.com/777SB.png) Code: ``` a = input('Enter number A \n'); d = input('En...
2018/05/05
[ "https://Stackoverflow.com/questions/50187041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9744650/" ]
Please don't post screenshots. Copy and paste text and use the {} CODE markdown. What data type is returned by input()? It's always a string. It doesn't matter what you type. Where is the variable c actually calculated in this program? Line 4. What types of data are used to compute c? Two strings. What happens when...
Since it looks like you also want to enter an operation sign you might also try `eval` ``` a = input('Enter number A \n'); d = raw_input('Enter sign operations \n') b = input('Enter number B \n') eval_string = str(a) + d + str(b) print ( eval(eval_string) ) ``` You should know `input` accepts only integers and...
9,776,332
I wrote a python program that needs to call aircrack program to some tasks, but I run into trouble with the privilege. Initially the aircrack program is called in command line, it requires "sudo" at the beginning. After that I checked the location of the executable and found that it locates under `/usr/sbin/`. Right no...
2012/03/19
[ "https://Stackoverflow.com/questions/9776332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/636625/" ]
first, none of us can replace the chmod man page (so i'll start by quoting it): ``` A numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2)...
You have to set the suid flag for all users. ``` sudo chmod ogu+sxr /usr/sbing/airodump-ng ```
7,377,494
I'm trying to scrape a page using python The problem is, I keep getting Errno54 Connection reset by peer. The error comes when I run this code - ``` urllib2.urlopen("http://www.bkstr.com/webapp/wcs/stores/servlet/CourseMaterialsResultsView?catalogId=10001&categoryId=9604&storeId=10161&langId=-1&programId=562&term...
2011/09/11
[ "https://Stackoverflow.com/questions/7377494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/915672/" ]
``` $> telnet www.bkstr.com 80 Trying 64.37.224.85... Connected to www.bkstr.com. Escape character is '^]'. GET /webapp/wcs/stores/servlet/CourseMaterialsResultsView?catalogId=10001&categoryId=9604&storeId=10161&langId=-1&programId=562&termId=100020629&divisionDisplayName=Stanford&departmentDisplayName=ILAC&courseDispl...
I came across a similar error just recently. The connection was dropping out and being reset. I tried cookiejars, extended delays and different headers/useragents, but nothing worked. In the end the fix was simple. I went from urllib2 to requests. The old; ``` import urllib2 opener = urllib2.build_opener() buf = opene...
50,983,646
I have a dataframe like this: ``` df = pd.DataFrame({'timestamp':pd.date_range('2018-01-01', '2018-01-02', freq='2h', closed='right'),'col1':[np.nan, np.nan, np.nan, 1,2,3,4,5,6,7,8,np.nan], 'col2':[np.nan, np.nan, 0, 1,2,3,4,5,np.nan,np.nan,np.nan,np.nan], 'col3':[np.nan, -1, 0, 1,2,3,4,5,6,7,8,9], 'col4':[-2, -1, 0,...
2018/06/22
[ "https://Stackoverflow.com/questions/50983646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6435921/" ]
Since it's a response header i assume you mean this: ``` ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") ```
Another option if you are not using `Context`: ``` func setResponseHeader(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") h.ServeHTTP(w, r) } } ``` `setResponseHeader` is essentially a decorator of...
50,983,646
I have a dataframe like this: ``` df = pd.DataFrame({'timestamp':pd.date_range('2018-01-01', '2018-01-02', freq='2h', closed='right'),'col1':[np.nan, np.nan, np.nan, 1,2,3,4,5,6,7,8,np.nan], 'col2':[np.nan, np.nan, 0, 1,2,3,4,5,np.nan,np.nan,np.nan,np.nan], 'col3':[np.nan, -1, 0, 1,2,3,4,5,6,7,8,9], 'col4':[-2, -1, 0,...
2018/06/22
[ "https://Stackoverflow.com/questions/50983646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6435921/" ]
Since it's a response header i assume you mean this: ``` ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") ```
To enable CORS support on fasthttp, better use [fasthttpcors](https://github.com/AdhityaRamadhanus/fasthttpcors) package. ``` import ( ... cors "github.com/AdhityaRamadhanus/fasthttpcors" ... ) func main() { ... withCors := cors.NewCorsHandler(cors.Options{ AllowMaxAge: math.MaxInt32, ...
41,846,085
I am doing this python programming and stuck with an issue. The program cannot call the value of the n\_zero when I put it in the conditional statement. Here's the program ``` import numpy as np n_zero=int(input('Insert the amount of 0: ')) n_one =int(input('Insert the amount of 1: ')) n_two =int(input('Insert the...
2017/01/25
[ "https://Stackoverflow.com/questions/41846085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7456346/" ]
In python you don't cast the left value variable as you don't specify the left value type. ``` n_zero=int(input('Insert the amount of 0: ')) ``` **Regarding your edit:** What exactly are you trying to reach? if multiply than use the operator \* ``` if len(data)==(2*(n_zero)-1): ... ```
``` if len(data) == (2(n_zero) - 1): ``` should become: ``` if len(data) == (2 * (n_zero) - 1): ``` Note `*` in second example. You must explicitly provide operator, Python will not assume that You want to multiply those 2 numbers if You don't tell it.
62,191,477
somebody can explain why docker does not wanna run Django server Thats my structure of project: ``` app bankproject env docker-compose.yml Dockerfile manage.py requirements.txt ``` There is my file Docker: ``` # pull official base image FROM python:3.8.0-alpine # set work dir...
2020/06/04
[ "https://Stackoverflow.com/questions/62191477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13678793/" ]
You haven't declared a `ref` and passed it to `HeaderComponent`, see [`useRef` hook](https://reactjs.org/docs/hooks-reference.html#useref). ``` const App = () => { const calendarRef = useRef(); React.useEffect(() => { console.log(calendarRef.current); }, []); return ( <div className="App"> <Hea...
You should define a ref in the App component and pass it on to the HeaderComponent ``` const App = () => { let calendarRef = useRef(); return ( <div className="App"> <HeaderComponent calendarRef={calendarRef} /> <Calendar ref={calendarRef} height="100vh" /> </div> ); }; export default App; ...
32,080,635
I am looking into Python's **Least Recently Used (LRU) cache** implementation [here](http://code.activestate.com/recipes/578078-py26-and-py30-backport-of-python-33s-lru-cache/). Can someone please explain what the `_make_key` function is doing? ``` def _make_key(args, kwds, typed, kwd_mark = (object(),),...
2015/08/18
[ "https://Stackoverflow.com/questions/32080635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4677617/" ]
The function is converting a set of function arguments to a sequence that (a) can be hashed and (b) returns the same hash value for the same arguments, if a function is invoked multiple times with the same arguments. Obviously, `args` and `kwargs` are intended to be the positional and keyword arguments of a generic fu...
Summary ------- The *\_make\_key()* function flattens the arguments into a compact tuple that can be used to determine whether the arguments for two calls are the same. Generated keys -------------- The call `f(10, 20, x=30, y=40)` and `f(10, 20, y=40, x=30)` both have the same key: ``` (10, 20, <object object at 0...
51,361,441
I want to rewrite a `python` code for calculating accumulated result of `max`. I refered to numpy [documentation](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.accumulate.html) Input: `[7200,7050,7300,7500,7440,7200,7300,7280,7400]` Output: `[7200, 7200, 7300, 7500, 7500, 7500, 7500, 7500, 7500]` ...
2018/07/16
[ "https://Stackoverflow.com/questions/51361441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3911211/" ]
Something like this is inline, more or less: ```js var max = 0; var input = [7200, 7050, 7300, 7500, 7440, 7200, 7300, 7280, 7400]; var output = input.map(function(e) { return max > e ? max : max = e; }); console.log(output); ``` Inspired by [Pierre's answer](https://stackoverflow.com/a/51361720/2959522), here...
One line solution with `Array.from()` : ```js var arr = [7200, 7050, 7300, 7500, 7440, 7200, 7300, 7280, 7400]; var output = Array.from({length:arr.length}, (el,i) => Math.max(...arr.slice(0,i+1))) console.log(output); ```
51,361,441
I want to rewrite a `python` code for calculating accumulated result of `max`. I refered to numpy [documentation](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.accumulate.html) Input: `[7200,7050,7300,7500,7440,7200,7300,7280,7400]` Output: `[7200, 7200, 7300, 7500, 7500, 7500, 7500, 7500, 7500]` ...
2018/07/16
[ "https://Stackoverflow.com/questions/51361441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3911211/" ]
Something like this is inline, more or less: ```js var max = 0; var input = [7200, 7050, 7300, 7500, 7440, 7200, 7300, 7280, 7400]; var output = input.map(function(e) { return max > e ? max : max = e; }); console.log(output); ``` Inspired by [Pierre's answer](https://stackoverflow.com/a/51361720/2959522), here...
Here is a one-liner alternative: ``` a = [7200,7050,7300,7500,7440,7200,7300,7280,7400] b = [max(a[0:i]) if i > 0 else a[i] for i in range(len(a))] ```
53,057,646
Here is my code for upload a file to S3 bucket sing boto3 in python. ``` import boto3 def upload_to_s3(backupFile, s3Bucket, bucket_directory, file_format): s3 = boto3.resource('s3') s3.meta.client.upload_file(backupFile, s3Bucket, bucket_directory.format(file_format)) upload_to_s3('/tmp/backup.py', 'bsfbac...
2018/10/30
[ "https://Stackoverflow.com/questions/53057646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3440631/" ]
A CAN transceiver is just a high speed step down converter. (on a basic level) CAN protocol works in a variant of voltage ranges. MCP2551 is a set CAN transceiver suitable for 12V and 24V systems. With added features to help with the physical layer like `externally-controlled slope` for reduced RFI emissions, `detecti...
For software, look for the CANtact open source project on Github. It is an implementation for the STM32F042. I had to adapt the project to build it under Atollic but it was not too hard and it works. It provides a SLCAN type of interface over a virtual COM port over USB, which is very fast and convenient. There is als...
59,433,681
I have the following data in terms of dataframe ``` data = pd.DataFrame({'colA': ['a', 'c', 'a', 'e', 'c', 'c'], 'colB': ['b', 'd', 'b', 'f', 'd', 'd'], 'colC':['SD100', 'SD200', 'SD300', 'SD400', 'SD500', 'SD600']}) ``` I want the output as attached [enter image description here][2] I want to achieve this using pa...
2019/12/21
[ "https://Stackoverflow.com/questions/59433681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12054665/" ]
You can try: ``` Column A Column B Column C 0 a b SD100 1 c d SD200 2 a b SD300 3 e f SD400 4 c d SD500 5 c d SD600 ``` --- ``` >>> df.groupby(['Column A', 'Column B']).agg(list) C...
I don't know why you want to make multindex, but you can simply `sort_values` or use `groupby`. ```py import pandas as pd df = pd.DataFrame({"ColumnA":['a','c','a','e','c','c'], "ColumnB":['b','d','b','f','d','d'], "ColumnC":['SD100','SD200','SD300','SD400','SD500','SD600']}) print(df...
59,433,681
I have the following data in terms of dataframe ``` data = pd.DataFrame({'colA': ['a', 'c', 'a', 'e', 'c', 'c'], 'colB': ['b', 'd', 'b', 'f', 'd', 'd'], 'colC':['SD100', 'SD200', 'SD300', 'SD400', 'SD500', 'SD600']}) ``` I want the output as attached [enter image description here][2] I want to achieve this using pa...
2019/12/21
[ "https://Stackoverflow.com/questions/59433681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12054665/" ]
You can try: ``` Column A Column B Column C 0 a b SD100 1 c d SD200 2 a b SD300 3 e f SD400 4 c d SD500 5 c d SD600 ``` --- ``` >>> df.groupby(['Column A', 'Column B']).agg(list) C...
This will update your data into what you wished `data=data.groupby(['colA','colB']).agg(list)`