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
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
``` <input type="submit" onclick="this.disabled = true" value="Save"/> ``` or ref [this](https://stackoverflow.com/questions/2545641/how-to-submit-form-only-once-after-multiple-clicking-on-submit)
Using **jQuery**, add onClick handler that returns false: ``` <input type="submit" value="Submit" onClick="$(this).click(function() {return false;});"/> ```
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
i found a alternative online. wat i did is to create a fake disable and hidden button. when the actual button is clicked, i will hide it and show the fake disable button. **actual button:** ``` $onclick = " var boolconfirm = confirm('$strconfirmattempt'); if(boolconfirm==true){ finishattempt.style.display='none'; fin...
Here's a method using onsubmit instead of onlick: This goes at the top: ``` <script type='text/javascript'> function disableButtons() { $('input[type="submit"]').attr('disabled', true); } </script> ``` Then your PHP (note that isset post is NOT for the submit button, because we want to disable the submit button)....
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
I solved it with simple jQuery. The code removes the button on click, then appends the fake button or some like "loading.." text and finally sends the form. **HTML:** ``` <div class="holder"><input type='submit' value='ACCEPT' class='button'></div> ``` **jQuery:** ``` $('.button').click(function() { $('.bu...
Here's a method using onsubmit instead of onlick: This goes at the top: ``` <script type='text/javascript'> function disableButtons() { $('input[type="submit"]').attr('disabled', true); } </script> ``` Then your PHP (note that isset post is NOT for the submit button, because we want to disable the submit button)....
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
If you disable an input, then its value naturally won't be included in the form data. You'll need to disable the button *after* you submit. If you bind a callback to `onclick`, then it runs *before* the form submits. What you need is something like this: **jQuery:** ``` $(document).ready(function() { $(document)...
You could use a hidden field which would hold the value of the button and pull that value out of your POST data: ``` <input type="hidden" id="hiddenField" value="default" /> <input type="button" id="myButton" onclick="buttonClick();"> function buttonClick() { document.myForm.myButton.disabled = true; documen...
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
``` <input type="submit" onclick="this.disabled = true" value="Save"/> ``` or ref [this](https://stackoverflow.com/questions/2545641/how-to-submit-form-only-once-after-multiple-clicking-on-submit)
i found a alternative online. wat i did is to create a fake disable and hidden button. when the actual button is clicked, i will hide it and show the fake disable button. **actual button:** ``` $onclick = " var boolconfirm = confirm('$strconfirmattempt'); if(boolconfirm==true){ finishattempt.style.display='none'; fin...
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
Using **jQuery**, add onClick handler that returns false: ``` <input type="submit" value="Submit" onClick="$(this).click(function() {return false;});"/> ```
You could use a hidden field which would hold the value of the button and pull that value out of your POST data: ``` <input type="hidden" id="hiddenField" value="default" /> <input type="button" id="myButton" onclick="buttonClick();"> function buttonClick() { document.myForm.myButton.disabled = true; documen...
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
I solved it with simple jQuery. The code removes the button on click, then appends the fake button or some like "loading.." text and finally sends the form. **HTML:** ``` <div class="holder"><input type='submit' value='ACCEPT' class='button'></div> ``` **jQuery:** ``` $('.button').click(function() { $('.bu...
You could use a hidden field which would hold the value of the button and pull that value out of your POST data: ``` <input type="hidden" id="hiddenField" value="default" /> <input type="button" id="myButton" onclick="buttonClick();"> function buttonClick() { document.myForm.myButton.disabled = true; documen...
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
``` <input type="submit" onclick="this.disabled = true" value="Save"/> ``` or ref [this](https://stackoverflow.com/questions/2545641/how-to-submit-form-only-once-after-multiple-clicking-on-submit)
Here's a method using onsubmit instead of onlick: This goes at the top: ``` <script type='text/javascript'> function disableButtons() { $('input[type="submit"]').attr('disabled', true); } </script> ``` Then your PHP (note that isset post is NOT for the submit button, because we want to disable the submit button)....
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
If you disable an input, then its value naturally won't be included in the form data. You'll need to disable the button *after* you submit. If you bind a callback to `onclick`, then it runs *before* the form submits. What you need is something like this: **jQuery:** ``` $(document).ready(function() { $(document)...
Here's a method using onsubmit instead of onlick: This goes at the top: ``` <script type='text/javascript'> function disableButtons() { $('input[type="submit"]').attr('disabled', true); } </script> ``` Then your PHP (note that isset post is NOT for the submit button, because we want to disable the submit button)....
3,186,526
In debian recently change de default version of python from 2.5 to 2.6 but i need 2.5, how i can configure apache and/or wsgi script to say it use pythons2.5 and not python default?
2010/07/06
[ "https://Stackoverflow.com/questions/3186526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150647/" ]
If you disable an input, then its value naturally won't be included in the form data. You'll need to disable the button *after* you submit. If you bind a callback to `onclick`, then it runs *before* the form submits. What you need is something like this: **jQuery:** ``` $(document).ready(function() { $(document)...
Why not create a disabled submit button that is hidden, and an active submit button, and onClick show the disabled and hide the active? I could do this in jQuery, but I'm kinda useless without it. Sad, eh?
2,335,762
I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve: ``` sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css ``` So basically I want to take \1, multiply...
2010/02/25
[ "https://Stackoverflow.com/questions/2335762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281403/" ]
use awk ``` $ cat file foo: 3px; bar: 6px $ awk '{for(i=1;i<=NF;i++){if($i~/^[0-9]+px/){o=$i;sub(/^[0-9]+/,"",o);$i=($i+0)*(2/3)o}}}1' file foo: 2px; bar: 4px ```
You can use perl do it like this: ``` echo -e "100px;\n20px;" | perl -pe 's{ (\d*) (?=px) }{ $1*(2/3) }xe' ```
2,335,762
I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve: ``` sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css ``` So basically I want to take \1, multiply...
2010/02/25
[ "https://Stackoverflow.com/questions/2335762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281403/" ]
You can use perl do it like this: ``` echo -e "100px;\n20px;" | perl -pe 's{ (\d*) (?=px) }{ $1*(2/3) }xe' ```
To answer the initial question: Yes, you can do this in sed, and No, you do NOT want to do it unless you have some bizarre set of constraints that prevent you from using any other tool. I say this because the unix dc command (a desktop calculator) has been written in sed, but it works IIRC by performing math the same ...
2,335,762
I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve: ``` sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css ``` So basically I want to take \1, multiply...
2010/02/25
[ "https://Stackoverflow.com/questions/2335762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281403/" ]
You can use perl do it like this: ``` echo -e "100px;\n20px;" | perl -pe 's{ (\d*) (?=px) }{ $1*(2/3) }xe' ```
``` sed $( sed -rn ' :X /([0-9]+)px/ { s##\a\1\a# h s#.*\a(.*)\a.*#echo -e s/\1px/$((\1 * 2/3))px/g#ep x bX } ' cssfile ) cssfile ```
2,335,762
I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve: ``` sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css ``` So basically I want to take \1, multiply...
2010/02/25
[ "https://Stackoverflow.com/questions/2335762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281403/" ]
use awk ``` $ cat file foo: 3px; bar: 6px $ awk '{for(i=1;i<=NF;i++){if($i~/^[0-9]+px/){o=$i;sub(/^[0-9]+/,"",o);$i=($i+0)*(2/3)o}}}1' file foo: 2px; bar: 4px ```
To answer the initial question: Yes, you can do this in sed, and No, you do NOT want to do it unless you have some bizarre set of constraints that prevent you from using any other tool. I say this because the unix dc command (a desktop calculator) has been written in sed, but it works IIRC by performing math the same ...
2,335,762
I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve: ``` sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css ``` So basically I want to take \1, multiply...
2010/02/25
[ "https://Stackoverflow.com/questions/2335762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281403/" ]
use awk ``` $ cat file foo: 3px; bar: 6px $ awk '{for(i=1;i<=NF;i++){if($i~/^[0-9]+px/){o=$i;sub(/^[0-9]+/,"",o);$i=($i+0)*(2/3)o}}}1' file foo: 2px; bar: 4px ```
``` sed $( sed -rn ' :X /([0-9]+)px/ { s##\a\1\a# h s#.*\a(.*)\a.*#echo -e s/\1px/$((\1 * 2/3))px/g#ep x bX } ' cssfile ) cssfile ```
70,581,125
I am to write a program by taking two integers as input and output their sum on Sololearn using python But I don’t seem to get what they want me to do
2022/01/04
[ "https://Stackoverflow.com/questions/70581125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17833033/" ]
``` num1 = int(input('Enter your first number: ')) num2 = int(input('Enter your second number: ')) print('Your sum is', num1 + num2) ``` I would suggest doing more research on the `input` function in python. Also, in the future, please provide the code that you have already written so that it is easier to answer your...
Try with ```py a = int(input("A: ")) # Convert input string to int b = int(input("B: ")) print("A + B =", a+b) ```
70,581,125
I am to write a program by taking two integers as input and output their sum on Sololearn using python But I don’t seem to get what they want me to do
2022/01/04
[ "https://Stackoverflow.com/questions/70581125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17833033/" ]
I am to write a program by **taking two integers as input** and **output their sum** on Sololearn using python But I don’t seem to get what they want me to do This is what the lesson is asking you to do. * Step 1: Take two integers as input * Step 2: Output their sum (addition) Step 1 Using the `input()` function wr...
Try with ```py a = int(input("A: ")) # Convert input string to int b = int(input("B: ")) print("A + B =", a+b) ```
12,960,522
I am trying to create an enumeration in python. I have seen seen several solutions (The second answer [here](https://stackoverflow.com/questions/36932/whats-the-best-way-to-implement-an-enum-in-python) by @alec thomas intrigued me most), but I would like to make the enumeration immutable. I found a [python recipe](http...
2012/10/18
[ "https://Stackoverflow.com/questions/12960522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1255482/" ]
Your immediate problem is that the `getter` of a `property` takes `self` as the only parameter, not `attr`. Therefore, you should use something like `lambda self: val` instead. However, that doesn't work because the `lambda` binds the *name* `val`, which changes from iteration to iteration. So you will need to wrap it...
The final implementation (thanks to @nneonneo). * Checks for duplicate enum keys * Checks if enum is empty * Does not allow deletion or modification of enum items ``` def enum(*sequential, **named): # Check for duplicate keys names = list(sequential) names.extend(named.keys()) if len(set(names)) != le...
63,790,601
``` # Read an integer: a = input() #Now swap it... a[0] = a[1] a[1] = a[0] ``` As you can see I am trying to change the value and trying to swap it.. ``` print(a) ``` ...and then i print it out. But I am getting an error which is as follows: ``` Traceback (most recent call last): File "python", line 4, in <modu...
2020/09/08
[ "https://Stackoverflow.com/questions/63790601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14235043/" ]
Try this: ``` a = input() a = str(a) result = int(a[-1: : -1]) print(result) ``` Output: ( a = 34 ) ``` 43 ```
Based on your question simple thing you can do. As above comment string is not iterable while you as input. You need to convert to `list` to access by index. For swap you need to use temporary variable, so i used `temp` as variable to swap. ``` a = list(input()) #Now swap it... print(a) temp = a[0] a[0] = a[1] a[1] ...
48,272,939
In advance, thank you for looking at my issue community, My python test script will not execute from my Centos 7 Crontab. This script will execute manually if called either in the containing directory or from the root/any other directory with a full path. My Centos Python location is `/bin/python`. This is included at...
2018/01/16
[ "https://Stackoverflow.com/questions/48272939", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6820299/" ]
I had the same problem. Pulling images was working but provisioning a container was not working. In this case the solution was to provide Docker with a configuration file named `~/.docker/config.json` with the following contents. ``` { "proxies": { "default": { "httpProxy": "http://proxy.server....com:808...
I struggled making it work but finally found a working solution on my side. I'm behind a corporate proxy and have a CNTLM properly configured on windows and linked in my docker desktop settings with address `127.0.0.1:3128`. My docker runs under WSL2. The magic tip hereis to link your containers proxies to docker int...
33,981,803
Lets say I am trying to get the number of different peoples names. user inputs names until they enter a -1, once -1 is entered then loop will break Once entered then i am trying to tabulate the output something likes this names : John Max Joan No of occurrences : 4 1 2 % of occurences : 20% 10% 30% ``` #!/usr/bin/...
2015/11/29
[ "https://Stackoverflow.com/questions/33981803", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5466007/" ]
You can use [`collections.Counter`](https://docs.python.org/2/library/collections.html#collections.Counter) to count and accumulate the occurrences of names in the given input: ``` counter = collections.Counter() names = ["John", "Max", "Joan"] while True: lst = raw_input("What is your name?") if lst == "-1":...
Counting word frequency in a multi-word string: ``` import sys from collections import defaultdict WORDS = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip...
45,176,779
I have a python object that looks like this. I am trying to parse this object and turn it to a human readable string which I need to put in the logs. How can I recursively loop through this considering the object could be nested dictionaries or nested lists or dictionaries inside lists inside dictionaries etc. ``` {"...
2017/07/18
[ "https://Stackoverflow.com/questions/45176779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7044618/" ]
The formatting might be a bit off ``` def humanizer(input, result=''): if type(input) == dict: for k, v in input.items(): if type(v) == str: result += '%s:%s\n\t' % (str(k), str(v)) elif type(v) in (dict, list): result += '%s:\n\t' % str(k) ...
Maybe the output of [pformat](https://docs.python.org/3/library/pprint.html#pprint.pformat "pformat") would suit you: ``` from pprint import pformat results_str = pformat(results) ```
45,176,779
I have a python object that looks like this. I am trying to parse this object and turn it to a human readable string which I need to put in the logs. How can I recursively loop through this considering the object could be nested dictionaries or nested lists or dictionaries inside lists inside dictionaries etc. ``` {"...
2017/07/18
[ "https://Stackoverflow.com/questions/45176779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7044618/" ]
Maybe the output of [pformat](https://docs.python.org/3/library/pprint.html#pprint.pformat "pformat") would suit you: ``` from pprint import pformat results_str = pformat(results) ```
You need an elif-condition in case of type == list and a indentation tracker: ``` data = {"plugins": [ {"Chrome PDF Viewer": "mhjfbmdgcfjbbpaeojofohoefgiehjai"}, {"Chrome PDF Viewer": "internal-pdf-viewer"}, {"Native Client": "internal-nacl-plugin"}, {"Shockwave Flash": "PepperFlashPlayer.plugin"...
45,176,779
I have a python object that looks like this. I am trying to parse this object and turn it to a human readable string which I need to put in the logs. How can I recursively loop through this considering the object could be nested dictionaries or nested lists or dictionaries inside lists inside dictionaries etc. ``` {"...
2017/07/18
[ "https://Stackoverflow.com/questions/45176779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7044618/" ]
The formatting might be a bit off ``` def humanizer(input, result=''): if type(input) == dict: for k, v in input.items(): if type(v) == str: result += '%s:%s\n\t' % (str(k), str(v)) elif type(v) in (dict, list): result += '%s:\n\t' % str(k) ...
You need an elif-condition in case of type == list and a indentation tracker: ``` data = {"plugins": [ {"Chrome PDF Viewer": "mhjfbmdgcfjbbpaeojofohoefgiehjai"}, {"Chrome PDF Viewer": "internal-pdf-viewer"}, {"Native Client": "internal-nacl-plugin"}, {"Shockwave Flash": "PepperFlashPlayer.plugin"...
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
Here you go: ``` >>> [100.0 * a1 / a2 - 100 for a1, a2 in zip(a[1:], a)] [5.0, -4.7619047619047592, -5.0, 5.2631578947368354] ``` Since you want to compare neighbor elements of a list, you better create a list of pairs you are interested in, like this: ``` >>> a = range(5) >>> a [0, 1, 2, 3, 4] >>> zip(a, a[1:]) [(...
I don't know how large your list of numbers is going to be, but if you are going to process large amounts of numbers, you should have a look at numpy. The side effect is that calculations look a lot simpler. With numpy, you create an array for your data ``` >>> import numpy as np >>> a = np.array([100,105,100,95,100]...
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
Here you go: ``` >>> [100.0 * a1 / a2 - 100 for a1, a2 in zip(a[1:], a)] [5.0, -4.7619047619047592, -5.0, 5.2631578947368354] ``` Since you want to compare neighbor elements of a list, you better create a list of pairs you are interested in, like this: ``` >>> a = range(5) >>> a [0, 1, 2, 3, 4] >>> zip(a, a[1:]) [(...
Thanks for the answer guys! A function I implemented based on your answers if someone just wanna copy paste (like me): ``` def pct_change(nparray): pct=np.zeros_like(nparray) pct[1:]=np.diff(nparray) / np.abs(nparray[:-1]) #TODO zero divisionerror return pct ```
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
Here you go: ``` >>> [100.0 * a1 / a2 - 100 for a1, a2 in zip(a[1:], a)] [5.0, -4.7619047619047592, -5.0, 5.2631578947368354] ``` Since you want to compare neighbor elements of a list, you better create a list of pairs you are interested in, like this: ``` >>> a = range(5) >>> a [0, 1, 2, 3, 4] >>> zip(a, a[1:]) [(...
You can also to this: ``` >>> a = [100,105,100,95,100] >>> [(a[i]-a[i-1])/a[i-1] for i in range(1, len(a))] [0.05, -0.047619047619047616, -0.05, 0.05263157894736842] ```
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
I don't know how large your list of numbers is going to be, but if you are going to process large amounts of numbers, you should have a look at numpy. The side effect is that calculations look a lot simpler. With numpy, you create an array for your data ``` >>> import numpy as np >>> a = np.array([100,105,100,95,100]...
Thanks for the answer guys! A function I implemented based on your answers if someone just wanna copy paste (like me): ``` def pct_change(nparray): pct=np.zeros_like(nparray) pct[1:]=np.diff(nparray) / np.abs(nparray[:-1]) #TODO zero divisionerror return pct ```
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
I don't know how large your list of numbers is going to be, but if you are going to process large amounts of numbers, you should have a look at numpy. The side effect is that calculations look a lot simpler. With numpy, you create an array for your data ``` >>> import numpy as np >>> a = np.array([100,105,100,95,100]...
You can also to this: ``` >>> a = [100,105,100,95,100] >>> [(a[i]-a[i-1])/a[i-1] for i in range(1, len(a))] [0.05, -0.047619047619047616, -0.05, 0.05263157894736842] ```
10,226,551
I have a list of floating point numbers and I want to generate another list of period returns from my first list. This is a run of the mill implementation (not tested - and OBVIOUSLY no error checking/handling): ``` a = [100,105,100,95,100] def calc_period_returns(values, period): output = [] startpos, endpo...
2012/04/19
[ "https://Stackoverflow.com/questions/10226551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/962891/" ]
Thanks for the answer guys! A function I implemented based on your answers if someone just wanna copy paste (like me): ``` def pct_change(nparray): pct=np.zeros_like(nparray) pct[1:]=np.diff(nparray) / np.abs(nparray[:-1]) #TODO zero divisionerror return pct ```
You can also to this: ``` >>> a = [100,105,100,95,100] >>> [(a[i]-a[i-1])/a[i-1] for i in range(1, len(a))] [0.05, -0.047619047619047616, -0.05, 0.05263157894736842] ```
17,239,077
Im trying to learn python and started with this, I keep getting a syntax error when i try to run it. the cursor jumps to the end of the close " at def start section. Im not sure where the syntax error is coming from as i speech mark all the print ``` #! python3 # J Presents: Rock, paper, Scissors: The Video Game imp...
2013/06/21
[ "https://Stackoverflow.com/questions/17239077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2401529/" ]
1) You have an indentation error here : ``` try: player = int(player) if player in (1,2,3): return player except ValueError: #Try Except Block Statement pass Print "Oops! I didn't understand that. Please enter 1, 2 or 3." ``` --- 2) Also : ``` if rule...
``` if rules[player} == computer: ``` The curly brace should be a bracket.
17,239,077
Im trying to learn python and started with this, I keep getting a syntax error when i try to run it. the cursor jumps to the end of the close " at def start section. Im not sure where the syntax error is coming from as i speech mark all the print ``` #! python3 # J Presents: Rock, paper, Scissors: The Video Game imp...
2013/06/21
[ "https://Stackoverflow.com/questions/17239077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2401529/" ]
1) You have an indentation error here : ``` try: player = int(player) if player in (1,2,3): return player except ValueError: #Try Except Block Statement pass Print "Oops! I didn't understand that. Please enter 1, 2 or 3." ``` --- 2) Also : ``` if rule...
``` if rules[player} == computer: print "Your victory has been assured." player_score +=1 ``` First error: rules[player} => rules[player] second error, you need to ident the lines after the if. ``` else: if rules[player} == computer: print "Your victory has been assured." player_score +=1 els...
39,194,747
I'm coding some python files with sublime and I'd like to comment multiple selected lines which means putting the character '#' at the beginning of each selected line. Is it possible to create a such shortcut-key Binding on sublime to do that ? Thanks Vincent
2016/08/28
[ "https://Stackoverflow.com/questions/39194747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6767684/" ]
There are a few ways to do this. Primarily, *two*: (1) Use the CPU/processor stack. There are some variants, each with its own limitations. (2) Or, recode your function(s) to use a "stack frame" struct that simulates a "stack". The actual function ceases to be recursive. This can be virtually limitless up to whateve...
All of functions, objects, variable and user defined structures use memory spaces which is control by OS and compiler. So, it means your defined stack works under a general memory space which is specified for the stack of your process in OS. As a result, it does not have a big difference, but you can define an optimize...
71,561,891
![This is what I want](https://i.stack.imgur.com/lexMT.png "example of what I want")How to make R side by side two column histogram (above) which I am able to do in python ([image taken from here](https://stackoverflow.com/questions/6871201/plot-two-histograms-on-single-chart-with-matplotlib)) and all the answers I hav...
2022/03/21
[ "https://Stackoverflow.com/questions/71561891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18295411/" ]
We remove the `NA` with `na.omit` and get the `first` element - use `[1]` to coerce to `NA` if there are no non-NA elements present ``` library(dplyr) test %>% group_by(name) %>% summarise(across(everything(), ~ first(na.omit(.x))[1])) ``` -output ``` # A tibble: 2 × 4 name test_1 test_2 make_up_test <ch...
Here is an approach with pivoting: ``` library(tidyr) library(dplyr) test %>% pivot_longer(-name, names_to = "names") %>% drop_na() %>% pivot_wider(names_from = names, values_from = value) %>% relocate(test_2, .after = test_1) ``` ``` name test_1 test_2 make_up_test <chr> <dbl> <dbl> <dbl...
22,358,540
I know how to read bits inside an int in Python but not how to do so on a char. For an int, this elementary operation works: a & (2\*\*bit\_index) . But for a single character it gives the following error message: `unsupported operand type(s) for &: 'str' and 'int'` In case, this "subtlety' matters, I'm also reading m...
2014/03/12
[ "https://Stackoverflow.com/questions/22358540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3275464/" ]
You can use a `bytearray` instead of a string. The individual elements are integers, but you can still do basic string manipulation on the whole: ``` >>> arr = bytearray('foo') >>> type(arr[0]) <type 'int'> >>> arr.replace('o', 'u') bytearray(b'fuu') ```
Python doesn't really have char type. You have a string of length one. You need to convert it to int before you can apply those operators in it. Depending on what is in `my_string` this might work: `int(my_char, 10)`
22,358,540
I know how to read bits inside an int in Python but not how to do so on a char. For an int, this elementary operation works: a & (2\*\*bit\_index) . But for a single character it gives the following error message: `unsupported operand type(s) for &: 'str' and 'int'` In case, this "subtlety' matters, I'm also reading m...
2014/03/12
[ "https://Stackoverflow.com/questions/22358540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3275464/" ]
Try this instead: `ord(a) & (2**bit_index)`. In python there is no separate character type, a character is simply a string of size one. So if you want to perform bit manipulations with string of size 1, you can use [`ord()`](http://docs.python.org/2.7/library/functions.html#ord) to convert it to `int`.
You can use a `bytearray` instead of a string. The individual elements are integers, but you can still do basic string manipulation on the whole: ``` >>> arr = bytearray('foo') >>> type(arr[0]) <type 'int'> >>> arr.replace('o', 'u') bytearray(b'fuu') ```
22,358,540
I know how to read bits inside an int in Python but not how to do so on a char. For an int, this elementary operation works: a & (2\*\*bit\_index) . But for a single character it gives the following error message: `unsupported operand type(s) for &: 'str' and 'int'` In case, this "subtlety' matters, I'm also reading m...
2014/03/12
[ "https://Stackoverflow.com/questions/22358540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3275464/" ]
Correct -- it is a string of length 1 and not a char. Convert your string to a list of integers: ``` >>> s = "hello world" >>> l = [ord(c) for c in s] ``` Then you can use bitwise operators on specific offsets: ``` >>> l[1] = l[1] << 1 >>> print "".join(chr(c) for c in l) h?llo world ```
Python doesn't really have char type. You have a string of length one. You need to convert it to int before you can apply those operators in it. Depending on what is in `my_string` this might work: `int(my_char, 10)`
22,358,540
I know how to read bits inside an int in Python but not how to do so on a char. For an int, this elementary operation works: a & (2\*\*bit\_index) . But for a single character it gives the following error message: `unsupported operand type(s) for &: 'str' and 'int'` In case, this "subtlety' matters, I'm also reading m...
2014/03/12
[ "https://Stackoverflow.com/questions/22358540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3275464/" ]
Try this instead: `ord(a) & (2**bit_index)`. In python there is no separate character type, a character is simply a string of size one. So if you want to perform bit manipulations with string of size 1, you can use [`ord()`](http://docs.python.org/2.7/library/functions.html#ord) to convert it to `int`.
Python doesn't really have char type. You have a string of length one. You need to convert it to int before you can apply those operators in it. Depending on what is in `my_string` this might work: `int(my_char, 10)`
22,358,540
I know how to read bits inside an int in Python but not how to do so on a char. For an int, this elementary operation works: a & (2\*\*bit\_index) . But for a single character it gives the following error message: `unsupported operand type(s) for &: 'str' and 'int'` In case, this "subtlety' matters, I'm also reading m...
2014/03/12
[ "https://Stackoverflow.com/questions/22358540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3275464/" ]
Try this instead: `ord(a) & (2**bit_index)`. In python there is no separate character type, a character is simply a string of size one. So if you want to perform bit manipulations with string of size 1, you can use [`ord()`](http://docs.python.org/2.7/library/functions.html#ord) to convert it to `int`.
Correct -- it is a string of length 1 and not a char. Convert your string to a list of integers: ``` >>> s = "hello world" >>> l = [ord(c) for c in s] ``` Then you can use bitwise operators on specific offsets: ``` >>> l[1] = l[1] << 1 >>> print "".join(chr(c) for c in l) h?llo world ```
50,182,833
I am running a Flask app on Google Cloud App Engine (flex). Running it locally works just fine, but once it deploys I get a `502 Bad Gateway error (nginx)`. Now I would like to figure out what causes this, but I am not able to find any option to view the console logs that my app creates. Since it works just fine on m...
2018/05/04
[ "https://Stackoverflow.com/questions/50182833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6341510/" ]
Had the similar issue. Found that app engine looks for app variable in main.py file. My final app.yaml looks like below. app.yaml -------- ``` runtime: python env: flex entrypoint: gunicorn -b :$PORT main:app runtime_config: python_version: 3 ``` and had requirements.txt, which looks like below. requirements.t...
Here are my theories: * localhost (`127.0.0.1`) is being used; should use `0.0.0.0` * Flask internal WSGI server is being used; should use e.g. [Gunicorn](https://gunicorn.org/) **NB** You **may** develop and test these solutions using Cloud Shell. Cloud Shell (now) includes a [web preview](https://cloud.google.com/s...
17,029,752
I am scraping 23770 webpages with a pretty simple web scraper using `scrapy`. I am quite new to scrapy and even python, but managed to write a spider that does the job. It is, however, really slow (it takes approx. 28 hours to crawl the 23770 pages). I have looked on the `scrapy` webpage and the mailing lists and `sta...
2013/06/10
[ "https://Stackoverflow.com/questions/17029752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183630/" ]
Here's a collection of things to try: * use latest scrapy version (if not using already) * check if non-standard middlewares are used * try to increase `CONCURRENT_REQUESTS_PER_DOMAIN`, `CONCURRENT_REQUESTS` settings ([docs](http://doc.scrapy.org/en/latest/topics/settings.html#concurrent-requests)) * turn off logging ...
Looking at your code, I'd say most of that time is spent in network requests rather than processing the responses. All of the tips @alecxe provides in his answer apply, but I'd suggest the `HTTPCACHE_ENABLED` setting, since it caches the requests and avoids doing it a second time. It would help on following crawls and ...
17,029,752
I am scraping 23770 webpages with a pretty simple web scraper using `scrapy`. I am quite new to scrapy and even python, but managed to write a spider that does the job. It is, however, really slow (it takes approx. 28 hours to crawl the 23770 pages). I have looked on the `scrapy` webpage and the mailing lists and `sta...
2013/06/10
[ "https://Stackoverflow.com/questions/17029752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183630/" ]
Here's a collection of things to try: * use latest scrapy version (if not using already) * check if non-standard middlewares are used * try to increase `CONCURRENT_REQUESTS_PER_DOMAIN`, `CONCURRENT_REQUESTS` settings ([docs](http://doc.scrapy.org/en/latest/topics/settings.html#concurrent-requests)) * turn off logging ...
I work also on web scraping, using optimized C#, and it ends up CPU bound, so I am switching to C. Parsing HTML blows the CPU data cache, and pretty sure your CPU is not using SSE 4.2 at all, as you can only access this feature using C/C++. If you do the math, you are quickly compute bound but not memory bound.
17,029,752
I am scraping 23770 webpages with a pretty simple web scraper using `scrapy`. I am quite new to scrapy and even python, but managed to write a spider that does the job. It is, however, really slow (it takes approx. 28 hours to crawl the 23770 pages). I have looked on the `scrapy` webpage and the mailing lists and `sta...
2013/06/10
[ "https://Stackoverflow.com/questions/17029752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183630/" ]
Here's a collection of things to try: * use latest scrapy version (if not using already) * check if non-standard middlewares are used * try to increase `CONCURRENT_REQUESTS_PER_DOMAIN`, `CONCURRENT_REQUESTS` settings ([docs](http://doc.scrapy.org/en/latest/topics/settings.html#concurrent-requests)) * turn off logging ...
One workaround to speed up your scrapy is to config your `start_urls` appropriately. For example, If our target data is in `http://apps.webofknowledge.com/doc=1` where the doc number range from `1` to `1000`, you can config your `start_urls` in followings: ``` start_urls = [ "http://apps.webofknowledge.com/doc=2...
17,029,752
I am scraping 23770 webpages with a pretty simple web scraper using `scrapy`. I am quite new to scrapy and even python, but managed to write a spider that does the job. It is, however, really slow (it takes approx. 28 hours to crawl the 23770 pages). I have looked on the `scrapy` webpage and the mailing lists and `sta...
2013/06/10
[ "https://Stackoverflow.com/questions/17029752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183630/" ]
Looking at your code, I'd say most of that time is spent in network requests rather than processing the responses. All of the tips @alecxe provides in his answer apply, but I'd suggest the `HTTPCACHE_ENABLED` setting, since it caches the requests and avoids doing it a second time. It would help on following crawls and ...
I work also on web scraping, using optimized C#, and it ends up CPU bound, so I am switching to C. Parsing HTML blows the CPU data cache, and pretty sure your CPU is not using SSE 4.2 at all, as you can only access this feature using C/C++. If you do the math, you are quickly compute bound but not memory bound.
17,029,752
I am scraping 23770 webpages with a pretty simple web scraper using `scrapy`. I am quite new to scrapy and even python, but managed to write a spider that does the job. It is, however, really slow (it takes approx. 28 hours to crawl the 23770 pages). I have looked on the `scrapy` webpage and the mailing lists and `sta...
2013/06/10
[ "https://Stackoverflow.com/questions/17029752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183630/" ]
Looking at your code, I'd say most of that time is spent in network requests rather than processing the responses. All of the tips @alecxe provides in his answer apply, but I'd suggest the `HTTPCACHE_ENABLED` setting, since it caches the requests and avoids doing it a second time. It would help on following crawls and ...
One workaround to speed up your scrapy is to config your `start_urls` appropriately. For example, If our target data is in `http://apps.webofknowledge.com/doc=1` where the doc number range from `1` to `1000`, you can config your `start_urls` in followings: ``` start_urls = [ "http://apps.webofknowledge.com/doc=2...
29,449,659
I have a server application written in python/django (REST api) for accepting a file upload from the client application. I want this uploaded file to be stored in AWS S3. I also want the file to be uploaded from client as multipart form / data . How can i achieve this. Any sample code application will help me to unders...
2015/04/04
[ "https://Stackoverflow.com/questions/29449659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/780805/" ]
If you want to your uploads to go directly to AWS S3, you can use `django-storages` and set your Django file storage backend to use AWS S3. * [django-storages](https://bitbucket.org/david/django-storages) * [django-storages documentation](http://django-storages.readthedocs.org/en/latest/index.html) This will allow yo...
Take a look at `boto` package which provides AWS APIs: ``` from boto.s3.connection import S3Connection s3 = S3Connection(access_key, secret_key) b = s3.get_bucket('<bucket>') mp = b.initiate_multipart_upload('<object>') for i in range(1, <parts>+1): io = <receive-image-part> # E.g. StringIO mp.upload_part_fr...
48,364,573
New to python and deep learning. I was trying to build an RNN with some data and I don't know where am I going wrong. This is my code: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline raw = pd.read_excel('Online Retail.xlsx',index_col='InvoiceDate') sales = raw.drop(['Inv...
2018/01/21
[ "https://Stackoverflow.com/questions/48364573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8766071/" ]
I'm not sure where the number `26` came from, but it doesn't match with your data dimensions. After you dropped four columns, the `training_data` array is `(50000, 3)`, of which you take `(11, 3)` batches. This array obviously can't reshape to `(26, 11)`. What you probably meant is this (in `next_batch` function): ``...
The error says that you trying to reshape a tensor with size `33` into a tensor with size `26x11`, which you can't. You should reshape a tensor with size `286` into `26x11`. Try to debug the `next_batch` function by printing the `y_batch` shape in each step using `print (y_batch.get_shape())` and check it, if it has s...
7,008,175
I wrote such a code to get timezone based on DST for an specific epoch time: ``` def getTimeZoneFromEpoch(epoch) if time.daylight and time.gmtime(epoch).tm_isdst==1: return -time.altzone/3600.0 else: return -time.timezone/3600.0 ``` But i'm not sure its correct, in fact at the moment i mistak...
2011/08/10
[ "https://Stackoverflow.com/questions/7008175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/495838/" ]
I've tested this code to obtain the VM's locale UTC offset. Which, by the way, is only really valid at the moment it is measured. I'm not sure whether your code is equivalent or not. ``` def local_ephemeral_UTC_offset(epoch_time=None): u"Returns a datetime.timedelta object representing the local time offset from UTC...
In short, use `time.localtime()` instead of `time.gmtime()`. --- The problem is that you use `gmtime()` , as the result of the following program shows. ``` from time import * def getTimeZoneFromEpoch(epoch): if daylight and gmtime(epoch).tm_isdst==1: return -altzone/3600.0 else: return -time...
7,008,175
I wrote such a code to get timezone based on DST for an specific epoch time: ``` def getTimeZoneFromEpoch(epoch) if time.daylight and time.gmtime(epoch).tm_isdst==1: return -time.altzone/3600.0 else: return -time.timezone/3600.0 ``` But i'm not sure its correct, in fact at the moment i mistak...
2011/08/10
[ "https://Stackoverflow.com/questions/7008175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/495838/" ]
I've tested this code to obtain the VM's locale UTC offset. Which, by the way, is only really valid at the moment it is measured. I'm not sure whether your code is equivalent or not. ``` def local_ephemeral_UTC_offset(epoch_time=None): u"Returns a datetime.timedelta object representing the local time offset from UTC...
Thanks for the help, besides the two methods that you suggested, I also found a more flexible (and maybe more compatible) version that can also take timezone object (or just use local zone) and return UTC offset There was just this AmbiguousTimeError part that confused me, but I did something about it to make it (kind...
7,008,175
I wrote such a code to get timezone based on DST for an specific epoch time: ``` def getTimeZoneFromEpoch(epoch) if time.daylight and time.gmtime(epoch).tm_isdst==1: return -time.altzone/3600.0 else: return -time.timezone/3600.0 ``` But i'm not sure its correct, in fact at the moment i mistak...
2011/08/10
[ "https://Stackoverflow.com/questions/7008175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/495838/" ]
In short, use `time.localtime()` instead of `time.gmtime()`. --- The problem is that you use `gmtime()` , as the result of the following program shows. ``` from time import * def getTimeZoneFromEpoch(epoch): if daylight and gmtime(epoch).tm_isdst==1: return -altzone/3600.0 else: return -time...
Thanks for the help, besides the two methods that you suggested, I also found a more flexible (and maybe more compatible) version that can also take timezone object (or just use local zone) and return UTC offset There was just this AmbiguousTimeError part that confused me, but I did something about it to make it (kind...
30,540,825
I have an OS X system where I need to install a module for python 2.6. Both `pip` and `easy_install-2.6` are failing: ``` # /usr/bin/easy_install-2.6 pip Searching for pip Reading http://pypi.python.org/simple/pip/ Download error: unknown url type: https -- Some packages may not be found! Couldn't find index page for ...
2015/05/30
[ "https://Stackoverflow.com/questions/30540825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4146877/" ]
Download the source file [here](https://pypi.python.org/packages/source/p/pip/pip-7.0.1.tar.gz#md5=5627bb807cf3d898a2eba276685537aa). Then do ``` >> cd ~/Downloads >> tar -xzvf pip-7.0.1.tar.gz ``` (replacing `~/Downloads` if necessary). Then ``` >> cd pip-7.0.1 >> sudo python2.6 setup.py install >> cd ``` (the...
By default [Homebrew](http://brew.sh/) provides `pip` command via: `brew install python`. So try installing Python using Homebrew. Try to not use `sudo` when working with `brew`. To verify which files are installed with your Python package, try: ``` $ brew list python /usr/local/Cellar/python/2.7.9/bin/pip /usr/loca...
70,714,374
How to loop multi-variable data like this in python ? I have latitude and longitude data and I want to pass all these value and run it for 5 times. e.g. **round 1** lat = 13.29 , longitude = 100.34 city = 'ABC' **round 2** lat = 94.09834 ,longitude = 103.34 city = 'XYZ' ,... ,.. ,round 5 Very new to pytho...
2022/01/14
[ "https://Stackoverflow.com/questions/70714374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17859678/" ]
I was getting permission issues because I was running SLES based docker container inside CentOS based host machine. If I use SLES based host machine, I could run the container without any permission issue.
in my case I fixed it by upgrading docker to latest version. [reference link.](https://travis-ci.community/t/unable-to-access-file-structure-of-docker-container-when-running-in-travis/11229)
28,848,098
I'm trying to make a recursive function that finds all the combinations of a python list. I want to input ['a','b','c'] in my function and as the function runs I want the trace to look like this: ```none ['a','b','c'] ['['a','a'],['b','a'],['c','a']] ['['a','a','b'],['b','a','b'],['c','a','b']] ...
2015/03/04
[ "https://Stackoverflow.com/questions/28848098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1995933/" ]
The right answer is that you should use `itertools.combinations`. But if for some reason you don't want to, and want to write a recursive function, you can use the following piece of code. It is an adaptation of the erlang way of generating combinations, so it may seem a bit weird at first: ``` def combinations(N, it...
Seems that you want all the product of a list, you can use [`itertools.product`](https://docs.python.org/2/library/itertools.html#itertools.product) within the following function to return a list of generators: ``` >>> from itertools import product >>> def pro(li): ... return [product(l,repeat=i) for i in range(...
11,372,033
I'm getting an error when testing a python script which is installed on my Android Emulator running SDK 2.2 I have installed "Python\_for\_android\_r1.apk" and "sl4a\_r5.apk" in my emulator. It seems that my code is trying to import the following: ``` from urllib import urlencode from urllib2 import urlopen ``` And...
2012/07/07
[ "https://Stackoverflow.com/questions/11372033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/953507/" ]
Your urllib module seems to be found. If the module is not found, python will return you an error at the import. Looking at the error, it appears that you are having problems with urlopen. Is the url you are trying to open valid? Line 124 in urllib2 refers to the opener that you are using to get your response.
`A;tanaStudio3Workspace` this is weird. You have no problem with your import module but the path look really wrong. I could assume if you fix the path, it will be alright but for further investigation you need to provide a real traceback.
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
Sometimes if you see "OperationalError: (2006, 'MySQL server has gone away')", it is because you are issuing a query that is too large. This can happen, for instance, if you're storing your sessions in MySQL, and you're trying to put something really big in the session. To fix the problem, you need to increase the valu...
SQLAlchemy now has a great write-up on how you can use pinging to be pessimistic about your connection's freshness: <http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic> From there, ``` from sqlalchemy import exc from sqlalchemy import event from sqlalchemy.pool import Pool @event...
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
I've been struggling with this issue too. I don't like the idea of increasing timeout on mysqlserver. Autoreconnect with `CONNECTION_MAX_AGE` doesn't work either as it was mentioned. Unfortunately I ended up with wrapping every method that queries the database like this ``` def do_db( callback, *arg, **args): try:...
SQLAlchemy now has a great write-up on how you can use pinging to be pessimistic about your connection's freshness: <http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic> From there, ``` from sqlalchemy import exc from sqlalchemy import event from sqlalchemy.pool import Pool @event...
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
The most common issue regarding such warning, is the fact that your application has reached the `wait_timeout` value of MySQL. I had the same problem with a Flask app. Here's how I solved: ``` $ grep timeout /etc/mysql/mysql.conf.d/mysqld.cnf # https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on...
How old is this code? Django has had databases defined in settings since at least .96. Only other thing I can think of is multi-db support, which changed things a bit, but even that was 1.1 or 1.2. Even if you need a special DB for certain views, I think you'd probably be better off defining it in settings.
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
For me this was happening in debug mode. So I tried Persistent connections in debug mode, checkout the link: [Django - Documentation - Databases - Persistent connections](https://docs.djangoproject.com/en/2.2/ref/databases/). In settings: ``` 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '...
Check if you are allowed to create mysql connection object in one thread and then use it in another. If it's forbidden, use threading.Local for per-thread connections: ``` class Db(threading.local): """ thread-local db object """ con = None def __init__(self, ...options...): super(Db, self).__ini...
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
As per the [MySQL documentation](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html), your error message is raised when the client can't send a question to the server, most likely because the server itself has closed the connection. In the most common case the server will close an idle connection after a (default) o...
Firstly, You should make sure the MySQL session & global enviroments `wait_timeout` and `interactive_timeout` values. And secondly Your client should try to reconnect to the server below those enviroments values.
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
Sometimes if you see "OperationalError: (2006, 'MySQL server has gone away')", it is because you are issuing a query that is too large. This can happen, for instance, if you're storing your sessions in MySQL, and you're trying to put something really big in the session. To fix the problem, you need to increase the valu...
I had this problem and did not have the option to change my configuration. I finally figured out that the problem was occurring 49500 records in to my 50000-record loop, because that was the about the time I was trying again (after having tried a long time ago) to hit my second database. So I changed my code so that ...
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
This error is mysterious because MySQL doesn't report why it disconnects, it just goes away. It seems there are many causes of this kind of disconnection. One I just found is, if the query string too large, the server will disconnect. This probably relates to the `max_allowed_packets` setting.
Firstly, You should make sure the MySQL session & global enviroments `wait_timeout` and `interactive_timeout` values. And secondly Your client should try to reconnect to the server below those enviroments values.
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
As per the [MySQL documentation](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html), your error message is raised when the client can't send a question to the server, most likely because the server itself has closed the connection. In the most common case the server will close an idle connection after a (default) o...
I had this problem and did not have the option to change my configuration. I finally figured out that the problem was occurring 49500 records in to my 50000-record loop, because that was the about the time I was trying again (after having tried a long time ago) to hit my second database. So I changed my code so that ...
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
As per the [MySQL documentation](http://dev.mysql.com/doc/refman/5.0/en/gone-away.html), your error message is raised when the client can't send a question to the server, most likely because the server itself has closed the connection. In the most common case the server will close an idle connection after a (default) o...
How old is this code? Django has had databases defined in settings since at least .96. Only other thing I can think of is multi-db support, which changed things a bit, but even that was 1.1 or 1.2. Even if you need a special DB for certain views, I think you'd probably be better off defining it in settings.
14,163,429
Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought it may have been a software update that broke something. I am using python 2.7 with django runfcgi with nginx. Here is my original code: **views.p...
2013/01/04
[ "https://Stackoverflow.com/questions/14163429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/516476/" ]
The most common issue regarding such warning, is the fact that your application has reached the `wait_timeout` value of MySQL. I had the same problem with a Flask app. Here's how I solved: ``` $ grep timeout /etc/mysql/mysql.conf.d/mysqld.cnf # https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on...
I had this problem and did not have the option to change my configuration. I finally figured out that the problem was occurring 49500 records in to my 50000-record loop, because that was the about the time I was trying again (after having tried a long time ago) to hit my second database. So I changed my code so that ...
7,629,753
I have been doing a lot of studying of the BaseHTTPServer and found that its not that good for multiple requests. I went through this article <http://metachris.org/2011/01/scaling-python-servers-with-worker-processes-and-socket-duplication/#python> and I wanted to know what is the best way for building a HTTP Server f...
2011/10/02
[ "https://Stackoverflow.com/questions/7629753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/558397/" ]
I have had very good luck with the CherryPy web server, one of the oldest and most solid of the pure-Python web servers. Just write your application as a WSGI callable and it should be easy to run under CherryPy's multi-threaded server. <http://www.cherrypy.org/>
Indeed, the the HTTP servers provided with the standard python library are meant only for light duty use; For moderate scaling (100's of concurrent connections), `mod_wsgi` in apache is a great choice. If your needs are greater than that(10,000's of concurrent connections), You'll want to look at an asynchronous fram...
7,629,753
I have been doing a lot of studying of the BaseHTTPServer and found that its not that good for multiple requests. I went through this article <http://metachris.org/2011/01/scaling-python-servers-with-worker-processes-and-socket-duplication/#python> and I wanted to know what is the best way for building a HTTP Server f...
2011/10/02
[ "https://Stackoverflow.com/questions/7629753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/558397/" ]
I have had very good luck with the CherryPy web server, one of the oldest and most solid of the pure-Python web servers. Just write your application as a WSGI callable and it should be easy to run under CherryPy's multi-threaded server. <http://www.cherrypy.org/>
[Tornado](http://www.tornadoweb.org/en/stable/) is a really good and easy-to-use asynchronous event-loop / webserver developed by FriendFeed/Facebook. I've personally had very good experiences with it. You can use the HTTP classes as in the example below, or only the io-loop to multiplex plain TCP connections. ``` imp...
18,267,454
The sql expression : ```sql select * from order where status=0 and adddate(created_time, interval 1 day)>now(); ``` python code: ```python from sqlalchemy.sql.expression import func, text from datetime import datetime closed_orders = DBSession.query(Order).filter(func.dateadd(Order.create_time, t...
2013/08/16
[ "https://Stackoverflow.com/questions/18267454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2688431/" ]
Try this: ``` from sqlalchemy import func import datetime DBSession.query(Order)\ .filter(func.ADDDATE(Order.create_time,1)>datetime.datetime.now()) ```
presto: ``` extract('hour', cast(t_table.open_time,TIMESTAMP)) - 5 == 12 extract('dow', cast(cast(t_table.open_time, TIMESTAMP) - 5,TIMESTAMP)) == 3 ```
10,618,956
I want to implement a symbol type, which keeps track of the symbols we already have(saved in `_sym_table`), and return them if they exist, or create new ones otherwise. The code: ``` # -*- coding: utf-8 -*- _sym_table = {} class Symbol(object): def __new__(cls, sym): if sym not in _sym_table: ...
2012/05/16
[ "https://Stackoverflow.com/questions/10618956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/403367/" ]
one problem is that `deepcopy` and `copy` have no way of knowing which arguments to pass to `__new__`, therefore they only work with classes that don't require constructor arguments. the reason why you can have `__init__` arguments is that `__init__` isn't called when copying an object, but `__new__` must be called to...
Seems to me you want the Symbol instances to be singletons. Deepcopy, however is supposed to be used when you want an exact copy of an instance, i.e. a different instance that is equal to the original. So the usage here kinda contradicts the purpose of deepcopy. If you want to make it work anyhow, you can define the [...
10,618,956
I want to implement a symbol type, which keeps track of the symbols we already have(saved in `_sym_table`), and return them if they exist, or create new ones otherwise. The code: ``` # -*- coding: utf-8 -*- _sym_table = {} class Symbol(object): def __new__(cls, sym): if sym not in _sym_table: ...
2012/05/16
[ "https://Stackoverflow.com/questions/10618956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/403367/" ]
Seems to me you want the Symbol instances to be singletons. Deepcopy, however is supposed to be used when you want an exact copy of an instance, i.e. a different instance that is equal to the original. So the usage here kinda contradicts the purpose of deepcopy. If you want to make it work anyhow, you can define the [...
Define `__getnewargs__` — that way you will not only be able to `copy` and `deepcopy`, but you'll also be able to `pickle`.
10,618,956
I want to implement a symbol type, which keeps track of the symbols we already have(saved in `_sym_table`), and return them if they exist, or create new ones otherwise. The code: ``` # -*- coding: utf-8 -*- _sym_table = {} class Symbol(object): def __new__(cls, sym): if sym not in _sym_table: ...
2012/05/16
[ "https://Stackoverflow.com/questions/10618956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/403367/" ]
one problem is that `deepcopy` and `copy` have no way of knowing which arguments to pass to `__new__`, therefore they only work with classes that don't require constructor arguments. the reason why you can have `__init__` arguments is that `__init__` isn't called when copying an object, but `__new__` must be called to...
Define `__getnewargs__` — that way you will not only be able to `copy` and `deepcopy`, but you'll also be able to `pickle`.
70,351,208
I am trying to fit some `experimental data (x and y)` with a `custom function (Srt)` and using `scipy.optimize.curve_fit()`: Reading the data and defining the function, using dummy values (10,10) for Km and Vmax (which are to be determined using the curve fit) works fine, as long as I use `np.asarray()`: ``` from sci...
2021/12/14
[ "https://Stackoverflow.com/questions/70351208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5466187/" ]
Please have a closer look at the [documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) of the `curve_fit` function. Where it states that `ydata` must nominaly be the result of `func(xdata... )`. So the ydata that you hand to `curve_fit` is never passed as argument of the ca...
Your first error is produced by the `t+t0` expression. It `t` is a list `x`, that's a list "concatenate" expression, which is fine for `[1,2,3]+[4,5]` but not `[1,2,3]+5`. That's why `x` and `y` have to arrays. In the second error, what did the ``` print("s",type(s)) print("s",s) ``` show? Apparently `s` is not an ...
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Don't type `python test.py` from inside the Python interpreter. Type it at the command prompt, like so: ![cmd.exe](https://i.stack.imgur.com/gc2Q1.png) ![python test.py](https://i.imgur.com/TFUBm.png)
Running from the command line means running from the terminal or DOS shell. You are running it from Python itself.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Don't type `python test.py` from inside the Python interpreter. Type it at the command prompt, like so: ![cmd.exe](https://i.stack.imgur.com/gc2Q1.png) ![python test.py](https://i.imgur.com/TFUBm.png)
Come out of the "python interpreter." 1. Check out your PATH variable c:\python27 2. cd and your file location. 3.Now type Python yourfilename.py. I hope this should work
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Looks like your problem is that you are trying to run `python test.py` *from within the Python interpreter*, which is why you're seeing that traceback. Make sure you're out of the interpreter, then run the `python test.py` command from bash or command prompt or whatever.
In order to run scripts, you should write the "python test.py" command in the command prompt, and not within the python shell. also, the test.py file should be at the path you run from in the cli.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
You can simply type `exit()` in the Python terminal to exit the Python interpreter. Then when you run the code, there will be no more errors.
In order to run scripts, you should write the "python test.py" command in the command prompt, and not within the python shell. also, the test.py file should be at the path you run from in the cli.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Don't type `python test.py` from inside the Python interpreter. Type it at the command prompt, like so: ![cmd.exe](https://i.stack.imgur.com/gc2Q1.png) ![python test.py](https://i.imgur.com/TFUBm.png)
You can simply type `exit()` in the Python terminal to exit the Python interpreter. Then when you run the code, there will be no more errors.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Looks like your problem is that you are trying to run `python test.py` *from within the Python interpreter*, which is why you're seeing that traceback. Make sure you're out of the interpreter, then run the `python test.py` command from bash or command prompt or whatever.
I faced a similar problem, on my Windows computer, please do check that you have set the Environment Variables correctly. To check that Environment variable is set correctly: 1. Open cmd.exe 2. Type Python and press return 3. (a) If it outputs the version of python then the environment variables are set correctly. (...
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
You can simply type `exit()` in the Python terminal to exit the Python interpreter. Then when you run the code, there will be no more errors.
Come out of the "python interpreter." 1. Check out your PATH variable c:\python27 2. cd and your file location. 3.Now type Python yourfilename.py. I hope this should work
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
I faced a similar problem, on my Windows computer, please do check that you have set the Environment Variables correctly. To check that Environment variable is set correctly: 1. Open cmd.exe 2. Type Python and press return 3. (a) If it outputs the version of python then the environment variables are set correctly. (...
In order to run scripts, you should write the "python test.py" command in the command prompt, and not within the python shell. also, the test.py file should be at the path you run from in the cli.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
You can simply type `exit()` in the Python terminal to exit the Python interpreter. Then when you run the code, there will be no more errors.
Running from the command line means running from the terminal or DOS shell. You are running it from Python itself.
13,961,140
I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains `print("Hello.")`), and it is located in the map C:\Python27. In my system variables, I have specified python to be C:\Python27 (I have other versions of Python installed on my computer as ...
2012/12/19
[ "https://Stackoverflow.com/questions/13961140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1913042/" ]
Looks like your problem is that you are trying to run `python test.py` *from within the Python interpreter*, which is why you're seeing that traceback. Make sure you're out of the interpreter, then run the `python test.py` command from bash or command prompt or whatever.
Running from the command line means running from the terminal or DOS shell. You are running it from Python itself.
61,648,271
**Piece of Code** ``` def wishListCount(): wishlist_count = len(session['Wishlist']) if len(session['Wishlist']) <= 0: return 0 else: return wishlist_count @app.route('/wishlist', methods=['GET', 'POST', 'DELETE']) def wishlist(): if request.method == 'POST': product_id = int(request.form['product_id'...
2020/05/07
[ "https://Stackoverflow.com/questions/61648271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13487131/" ]
To answer my own question, it was happening because of the Spring Boot version which was not ready to handle multistage builds, but after upgrading the service to 2.3.x i can build.
I think it is because of the Jar file not in supported form. That's why jarmode can't process it. Jarmode is a special system used to extracting Layered Jars. You can check out: <https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1> for detail info.
11,121,352
I deleted python .pyc files from my local repo and what I thought I did was to delete from remote github. I pushed all changes. The files are still on the repo but not on my local machine. How do I remove files from the github repo? I tried the following: ``` git rm classes/file.pyc git add . git ``` and even: `...
2012/06/20
[ "https://Stackoverflow.com/questions/11121352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1203556/" ]
You should not do `git add`. That's all ``` git rm classes/file.pyc git commit -m"bla bla bla" git push ```
``` git commit -am "A file was deleted" git push ```
39,545,452
I have a php script that should (I think) run a python script to control the energenie radio controlled plug sockets depending on which button is selected. It seems to work in that it echos back the correct message when the button is pressed but the python scripts don''t appear to run. I have added the line: www-data ...
2016/09/17
[ "https://Stackoverflow.com/questions/39545452", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6842362/" ]
[Parallel.Invoke](https://msdn.microsoft.com/en-us/library/dd992634(v=vs.110).aspx) method: ``` Parallel.Invoke( () => method1(), () => method2(), () => method3(), () => method4() ) ``` Add namespace `System.Threading.Tasks`
You can create a list of `Action` delegate where each delegate is a call to a given method: ``` List<Action> actions = new List<Action> { method1, method2, method3 }; ``` And then use [`Parallel.ForEach`](https://msdn.microsoft.com/en-us/library/dd992001(v=vs.110).aspx) to call them in parallel: ``` ...
57,854,621
I couldn't find any question related to this subject. But does python execute a function after the previous called function is finished or is there in any way parallel execution? **For example:** ``` def a(): print('a') def b(): print('b') a() b() ``` So in this example I would like to know if I can alway...
2019/09/09
[ "https://Stackoverflow.com/questions/57854621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9247792/" ]
Defining the function doesn't mean its execution. Since you defined `a` first, the function object for `a` will be created first, so as for there calls. You can take it as execution timeline starting from top to bottom.
There is no parallel execution of functions in python. The above functions will be executed in the same sequence that they were called in regardless of the amount of computation workload of either of the functions.
57,854,621
I couldn't find any question related to this subject. But does python execute a function after the previous called function is finished or is there in any way parallel execution? **For example:** ``` def a(): print('a') def b(): print('b') a() b() ``` So in this example I would like to know if I can alway...
2019/09/09
[ "https://Stackoverflow.com/questions/57854621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9247792/" ]
TLDR: `b` will only ever run after `a` is exited. Each Python thread will only ever execute one thing at a time and respect ordering of expressions and statements. For the most part, this means executing "top-to-bottom", though function definitions, control flow and other elements can affect execution order. Ordering ...
Defining the function doesn't mean its execution. Since you defined `a` first, the function object for `a` will be created first, so as for there calls. You can take it as execution timeline starting from top to bottom.
57,854,621
I couldn't find any question related to this subject. But does python execute a function after the previous called function is finished or is there in any way parallel execution? **For example:** ``` def a(): print('a') def b(): print('b') a() b() ``` So in this example I would like to know if I can alway...
2019/09/09
[ "https://Stackoverflow.com/questions/57854621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9247792/" ]
Defining the function doesn't mean its execution. Since you defined `a` first, the function object for `a` will be created first, so as for there calls. You can take it as execution timeline starting from top to bottom.
In python functions are by default executed in the order they appear. However if you call them in a different order they will execute as such. So in your example ``` def a(): print('a') def b(): print('b') b() a() ``` then `b()` will execute before `a()`
57,854,621
I couldn't find any question related to this subject. But does python execute a function after the previous called function is finished or is there in any way parallel execution? **For example:** ``` def a(): print('a') def b(): print('b') a() b() ``` So in this example I would like to know if I can alway...
2019/09/09
[ "https://Stackoverflow.com/questions/57854621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9247792/" ]
TLDR: `b` will only ever run after `a` is exited. Each Python thread will only ever execute one thing at a time and respect ordering of expressions and statements. For the most part, this means executing "top-to-bottom", though function definitions, control flow and other elements can affect execution order. Ordering ...
There is no parallel execution of functions in python. The above functions will be executed in the same sequence that they were called in regardless of the amount of computation workload of either of the functions.
57,854,621
I couldn't find any question related to this subject. But does python execute a function after the previous called function is finished or is there in any way parallel execution? **For example:** ``` def a(): print('a') def b(): print('b') a() b() ``` So in this example I would like to know if I can alway...
2019/09/09
[ "https://Stackoverflow.com/questions/57854621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9247792/" ]
TLDR: `b` will only ever run after `a` is exited. Each Python thread will only ever execute one thing at a time and respect ordering of expressions and statements. For the most part, this means executing "top-to-bottom", though function definitions, control flow and other elements can affect execution order. Ordering ...
In python functions are by default executed in the order they appear. However if you call them in a different order they will execute as such. So in your example ``` def a(): print('a') def b(): print('b') b() a() ``` then `b()` will execute before `a()`
69,165,968
I'm trying to run a legacy React app locally for the first time. I'm on a new Mac M1 with Big Sur 11.5.2. My node version is 16.9.0, and I made python3 the default (although the app seems to be looking for python2). I also upgraded CommandLineTools to the latest version. But when I do a simple `npm install`, I get lot...
2021/09/13
[ "https://Stackoverflow.com/questions/69165968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1660256/" ]
Upgrade `node-sass` to a version higher than 6.0.1 (mine was 4.0.0) solves this issue Ref: [error: no template named 'remove\_cv\_t' in namespace 'std'; did you mean 'remove\_cv'?](https://stackoverflow.com/questions/67241196/error-no-template-named-remove-cv-t-in-namespace-std-did-you-mean-remove)
try this ``` rm -rf node_modules package-lock.json npm install --saveDev node-sass npm install ```
13,295,064
As part of my course at university I am learning python. A task I have been trying to complete is to write a program that will print out random letters and their corresponding positions in "antidisestablishmentarianism". It will then print the remaining letters on a single line. I have been trying to do this in probab...
2012/11/08
[ "https://Stackoverflow.com/questions/13295064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1809406/" ]
I think part of the problem is that you're creating and manipulating your `worldList` and `usedValues` lists incorrectly. To create a list of characters as `wordList` use `list(word)`. To add a used index to `usedValues` use `usedValues.append(position)`. There's also an issue with how you remove the used values from ...
There are a few problems with your code as it stands. Firstly, this line: ``` wordList =["antidisestablishmentarianism"] ``` doesn't do what you think - it actually creates a list containing the single item `"antidisestablishmentarianism"`. To convert a string into a list of characters, you can use `list()` - and si...
45,415,081
I have Eclipse with Pydev and RSE installed on my local Windows machine. I want to remote debug a Python application (Odoo 9.0) that is hosted on an Ubuntu 16.04 VPS. I have Pydev installed on the remote machine. I have been able to connect to the remote machine via SSH using a key for authentication and I can browse t...
2017/07/31
[ "https://Stackoverflow.com/questions/45415081", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6489912/" ]
If you want to develop the code all remotely (instead of locally), my suggestion is using sshfs (so, you'd do all the changes there directly). You should even be able to create a shell script to a remote interpreter in that case too (i.e.: the interpreter may be any script, so, you could chroot it or even run some pyt...
I found a way to get remote editing and remote debug going with eclipse and pydev from my mac to a Debian linux server (bitnami setup). To set up remote editing and debugging - Read these first <https://www.pydev.org/manual_adv_remote_debugger.html> <https://sites.google.com/site/programmersnotebook/remote-developmen...
49,168,556
For my project I need to extract the CSS Selectors for a given element that I will find through parsing. What I do is navigate to a page with selenium and then with python-beautiful soup I parse the page and find if there are any elements that I need the CSS Selector of. For example I may try to find any input tags wit...
2018/03/08
[ "https://Stackoverflow.com/questions/49168556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7445289/" ]
Try this. ``` from scrapy.selector import Selector from selenium import webdriver link = "https://example.com" xpath_desire = "normalize-space(//input[@id = 'print'])" path1 = "./chromedriver" driver = webdriver.Chrome(executable_path=path1) driver.get(link) temp_test = driver.find_element_by_css_selector("body") el...
Ok, I am totally new to Python so i am sure that there is a better answer for this, but here's my two cents :) ``` import requests from bs4 import BeautifulSoup url = "https://stackoverflow.com/questions/49168556/extract-css-selector-for- an-element-with-selenium" element = 'a' idName = 'nav-questions' page = request...
51,160,368
Since the start and end times of DST in a timezone can change every year, so how does python tell if dst is in effect or not?
2018/07/03
[ "https://Stackoverflow.com/questions/51160368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10028264/" ]
So the answer was to use a function for a constant lookup: `$handler = new StreamHandler('/var/log/php/php.log', constant("Monolog\Logger::" . $level));`
``` <?php class Logger { const MY = 1; } $lookingfor = 'MY'; // approach 1 $value1 = (new ReflectionClass('Logger'))->getConstants()[$lookingfor]; // approach 2 $value2 = constant("Logger::" . $lookingfor); echo "$value1|$value2"; ?> ``` Result: "1|1"
65,814,036
When I want to import a package in python, I can alias it: ``` import package_with_a_very_long_nameeeeee as pl ``` After that statement, I can refer to the package by it alias: ``` pl.foo() ``` julia allows me to do: ``` using PackageWithAVeryLongName pl = PackageWithAVeryLongName pl.foo() ``` But it feels lik...
2021/01/20
[ "https://Stackoverflow.com/questions/65814036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11926170/" ]
This is now possible on the upcoming Julia 1.6 using the exact same syntax as Python uses: ``` julia> import LinearAlgebra as LA julia> typeof(LA) Module help?> LA.svd svd(A; full::Bool = false, alg::Algorithm = default_svd_alg(A)) -> SVD ``` On prior versions, you can do what [@Bill suggests](https://stackoverf...
python: ``` >>> import matplotlib as plt >>> type(plt) <class 'module'> >>> ``` julia: ``` julia> using Plots [ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80] julia> const plt = Plots Plots julia> typeof(plt) Module ``` So, it is pretty much the identical effect between languages. What may make t...
245,465
How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and password? Whenever I try to specify and IP address, it seems to be taking it locally. In other words, how should the string for cx\_Oracle.connect() ...
2008/10/29
[ "https://Stackoverflow.com/questions/245465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
```py import cx_Oracle dsn = cx_Oracle.makedsn(host='127.0.0.1', port=1521, sid='your_sid') conn = cx_Oracle.connect(user='your_username', password='your_password', dsn=dsn) conn.close() ```
``` import cx_Oracle ip = '172.30.1.234' port = 1524 SID = 'dev3' dsn_tns = cx_Oracle.makedsn(ip, port, SID) conn = cx_Oracle.connect('dbmylike', 'pass', dsn_tns) print conn.version conn.close() ```
245,465
How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and password? Whenever I try to specify and IP address, it seems to be taking it locally. In other words, how should the string for cx\_Oracle.connect() ...
2008/10/29
[ "https://Stackoverflow.com/questions/245465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` import cx_Oracle CONN_INFO = { 'host': 'xxx.xx.xxx.x', 'port': 12345, 'user': 'user_name', 'psw': 'your_password', 'service': 'abc.xyz.com', } CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO) connection = cx_Oracle.connect(CONN_STR) ```
Instead of specifying the SID, you can create a dsn and [connect via service\_name](http://cx-oracle.readthedocs.io/en/latest/module.html#cx_Oracle.makedsn) like: ``` import cx_Oracle ip = '192.168.0.1' port = 1521 service_name = 'my_service' dsn = cx_Oracle.makedsn(ip, port, service_name=service_name) db = cx_Oracl...
245,465
How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and password? Whenever I try to specify and IP address, it seems to be taking it locally. In other words, how should the string for cx\_Oracle.connect() ...
2008/10/29
[ "https://Stackoverflow.com/questions/245465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can specify the server in the connection string, e.g.: ``` import cx_Oracle connstr = 'scott/tiger@server:1521/orcl' conn = cx_Oracle.connect(connstr) ``` * "server" is the server, or the IP address if you want. * "1521" is the port that the database is listening on. * "orcl" is the name of the instance (or data...
``` import cx_Oracle ip = '172.30.1.234' port = 1524 SID = 'dev3' dsn_tns = cx_Oracle.makedsn(ip, port, SID) conn = cx_Oracle.connect('dbmylike', 'pass', dsn_tns) print conn.version conn.close() ```
245,465
How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and password? Whenever I try to specify and IP address, it seems to be taking it locally. In other words, how should the string for cx\_Oracle.connect() ...
2008/10/29
[ "https://Stackoverflow.com/questions/245465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Instead of specifying the SID, you can create a dsn and [connect via service\_name](http://cx-oracle.readthedocs.io/en/latest/module.html#cx_Oracle.makedsn) like: ``` import cx_Oracle ip = '192.168.0.1' port = 1521 service_name = 'my_service' dsn = cx_Oracle.makedsn(ip, port, service_name=service_name) db = cx_Oracl...
```py import cx_Oracle dsn = cx_Oracle.makedsn(host='127.0.0.1', port=1521, sid='your_sid') conn = cx_Oracle.connect(user='your_username', password='your_password', dsn=dsn) conn.close() ```
245,465
How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and password? Whenever I try to specify and IP address, it seems to be taking it locally. In other words, how should the string for cx\_Oracle.connect() ...
2008/10/29
[ "https://Stackoverflow.com/questions/245465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` import cx_Oracle CONN_INFO = { 'host': 'xxx.xx.xxx.x', 'port': 12345, 'user': 'user_name', 'psw': 'your_password', 'service': 'abc.xyz.com', } CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO) connection = cx_Oracle.connect(CONN_STR) ```
```py import cx_Oracle dsn = cx_Oracle.makedsn(host='127.0.0.1', port=1521, sid='your_sid') conn = cx_Oracle.connect(user='your_username', password='your_password', dsn=dsn) conn.close() ```