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
52,318,106
HTML: I have a 'sign-up' form in a modal (index.html) JS: The form data is posted to a python flask function: /signup\_user ``` $(function () { $('#signupButton').click(function () { $.ajax({ url: '/signup_user', method: 'POST', data: $('#signupForm').serialize() }) .done(function (data) { ...
2018/09/13
[ "https://Stackoverflow.com/questions/52318106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5632508/" ]
Another way could be ``` student_marks.each.with_object(Hash.new([])){ |(k,v), h| h[v] += [k] } #=> {50=>["Alex", "Matt"], 54=>["Beth"]} ```
Another easy way ``` student_marks.keys.group_by{ |v| student_marks[v] } {50=>["Alex", "Matt"], 54=>["Beth"]} ```
52,318,106
HTML: I have a 'sign-up' form in a modal (index.html) JS: The form data is posted to a python flask function: /signup\_user ``` $(function () { $('#signupButton').click(function () { $.ajax({ url: '/signup_user', method: 'POST', data: $('#signupForm').serialize() }) .done(function (data) { ...
2018/09/13
[ "https://Stackoverflow.com/questions/52318106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5632508/" ]
``` student_marks.group_by(&:last).transform_values { |v| v.map(&:first) } #=> {50=>["Alex", "Matt"], 54=>["Beth"]} ``` [Hash#transform\_values](https://ruby-doc.org/core-2.4.0/Hash.html) made its debut in Ruby MRI v2.4.0.
Another easy way ``` student_marks.keys.group_by{ |v| student_marks[v] } {50=>["Alex", "Matt"], 54=>["Beth"]} ```
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
first, `which pip` is not going to return the same result as `sudo which pip`, so you should check that out first. you may also consider not running pip as sudo at all. [Is it acceptable & safe to run pip install under sudo?](https://stackoverflow.com/questions/15028648/is-it-acceptable-safe-to-run-pip-install-under-s...
I fixed the same error ("The 'pip==6.1.1' distribution was not found") by using the tip of Wesm : ``` $> which pip && sudo which pip /usr/local/bin/pip /usr/bin/pip ``` So, it seels that "pip" of average user and of root are not the same. Will fix it later. Then I ran "sudo easy\_install --upgrade pip" => succeed ...
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
first, `which pip` is not going to return the same result as `sudo which pip`, so you should check that out first. you may also consider not running pip as sudo at all. [Is it acceptable & safe to run pip install under sudo?](https://stackoverflow.com/questions/15028648/is-it-acceptable-safe-to-run-pip-install-under-s...
I tried a few of these solutions without much success. In the end I just created a new instance using Ubuntu as the operating system. It was already setup properly for using Python properly. If that is not possible then you can try linking the user pip into a folder on root's (sudo) path.
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
first, `which pip` is not going to return the same result as `sudo which pip`, so you should check that out first. you may also consider not running pip as sudo at all. [Is it acceptable & safe to run pip install under sudo?](https://stackoverflow.com/questions/15028648/is-it-acceptable-safe-to-run-pip-install-under-s...
Some additional information for anyone who is also stuck on the same issue:- Running commands with `sudo` searches for the command in `usr/bin` directory. One way to solve this issue is to specify the complete path to the command while using `sudo` as commented by @Cissoid in the question's comment section Or ...w...
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
I fixed the same error ("The 'pip==6.1.1' distribution was not found") by using the tip of Wesm : ``` $> which pip && sudo which pip /usr/local/bin/pip /usr/bin/pip ``` So, it seels that "pip" of average user and of root are not the same. Will fix it later. Then I ran "sudo easy\_install --upgrade pip" => succeed ...
I tried a few of these solutions without much success. In the end I just created a new instance using Ubuntu as the operating system. It was already setup properly for using Python properly. If that is not possible then you can try linking the user pip into a folder on root's (sudo) path.
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
I fixed the same error ("The 'pip==6.1.1' distribution was not found") by using the tip of Wesm : ``` $> which pip && sudo which pip /usr/local/bin/pip /usr/bin/pip ``` So, it seels that "pip" of average user and of root are not the same. Will fix it later. Then I ran "sudo easy\_install --upgrade pip" => succeed ...
Some additional information for anyone who is also stuck on the same issue:- Running commands with `sudo` searches for the command in `usr/bin` directory. One way to solve this issue is to specify the complete path to the command while using `sudo` as commented by @Cissoid in the question's comment section Or ...w...
34,734,436
I am using pip on EC2 now, python version is 2.7. 'sudo pip' suddenly doesn't work anymore. ```none [ec2-user@ip-172-31-17-194 ~]$ sudo pip install validate_email Traceback (most recent call last): File "/usr/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/lib/python2....
2016/01/12
[ "https://Stackoverflow.com/questions/34734436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5326788/" ]
Some additional information for anyone who is also stuck on the same issue:- Running commands with `sudo` searches for the command in `usr/bin` directory. One way to solve this issue is to specify the complete path to the command while using `sudo` as commented by @Cissoid in the question's comment section Or ...w...
I tried a few of these solutions without much success. In the end I just created a new instance using Ubuntu as the operating system. It was already setup properly for using Python properly. If that is not possible then you can try linking the user pip into a folder on root's (sudo) path.
66,559,129
I am writing table to mysql from python using pymysql to\_sql function. I am having 1000 rows with 200 columns. Query to connect to mysql is below: ``` engine = create_engine("mysql://hostname:password#@localhostname/dbname") conn = engine.connect() writing query: df.to_sql('data'.lower(),schema=schema,conn,'replace'...
2021/03/10
[ "https://Stackoverflow.com/questions/66559129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12249443/" ]
You can store the data with 3 methods- 1. Use localStorage if you are using a json object then you can use localStorage.setItem("data123",JSON.stringify(data)) and fetch the data using JSON.prase(localStorage.getItem("data123")) 2. sessionStorgae Syntax is same as localStaorage. Just replace localwith session Dif...
I think the best way to save form data locally is to preserve it in your form handler class like you can create a new Handler class and create setter and getter in it which store the form fields data/values in object key, value pair which you always update whenever fields update.
12,028,496
How do I pass a query string to a HTML frame? I have the following HTML in index.html: ``` <HTML> <FRAMESET rows="200, 200" border=0> <FRAMESET> <FRAME name=top scrolling=no src="top.html"> <FRAME name=main scrolling=yes src="/cgi-bin/main.py"> </FRAMESET> </FRAMESET> </HTML> ``` The frame src is main....
2012/08/19
[ "https://Stackoverflow.com/questions/12028496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65406/" ]
[This](https://stackoverflow.com/a/2880929/1273830) should help you get variables from the query string, which you can use to build your custom queryString. Or if you want to pass the query string as it is to the frame, then you could get it a simpler fashion. `var queryString = window.location.href.split('index.html?...
Not sure if this will work (untested), but perhaps you can load the query parameters onload using jQuery? Here is a proof of concept: ``` <html> <head> //Load jquery here, then do the following: <script type="text/javascript"> $(document).ready(functin(){ // navigator.href holds the current...
22,447,986
I have the following list of string ``` mystring = [ 'FOO_LG_06.ip', 'FOO_LV_06.ip', 'FOO_SP_06.ip', 'FOO_LN_06.id', 'FOO_LV_06.id', 'FOO_SP_06.id'] ``` What I want to do is to print it out so that it gives this: ``` LG.ip LV.ip SP.ip LN.id LV.id SP.id ``` How can I do that in python? I'm stuck w...
2014/03/17
[ "https://Stackoverflow.com/questions/22447986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1380929/" ]
If you want to do this in a manner similar to the one you know in perl, you can use `re.search`: ``` import re mystring = [ 'FOO_LG_06.ip', 'FOO_LV_06.ip', 'FOO_SP_06.ip', 'FOO_LN_06.id', 'FOO_LV_06.id', 'FOO_SP_06.id'] for soth in mystring: matches = re.search(r'FOO_(\w+)_06(\.\w{2})', soth) prin...
different regex: > > > > > > > > > > > > p='[^*]+*([A-Z]+)[^.]+(..\*)' > > > > > > > > > > > > > > > > > > ``` >>> for soth in mystring: ... match=re.search(p,soth) ... print ''.join([match.group(1),match.group(2)]) ``` Output: LG.ip LV.ip SP.ip LN.id LV.id SP.id
1,942,295
Noob @ programming with python and pygtk. I'm creating an application which includes a couple of dialogs for user interaction. ``` #!usr/bin/env python import gtk info = gtk.MessageDialog(type=gtk.DIALOG_INFO, buttons=gtk.BUTTONS_OK) info.set_property('title', 'Test info message') info.set_property('text', 'Message t...
2009/12/21
[ "https://Stackoverflow.com/questions/1942295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234654/" ]
can you give me a last chance? ;) there are some errors in your code: * you did not close a bracket * your syntax in `.set_property` is wrong: use: `.set_property('property', 'value')` but i think they are copy/paste errors. try this code, it works for me. maybe did you forget the `gtk.main()`? ``` import gtk inf...
@mg My bad. Your code is correct (and I guess my initial code was too) The reason my dialog was remaining on the screen is because my gtk.main loop is running on a separate thread. So all I had to was enclose your code (corrected version of mine) in between a ``` gtk.gdk.threads_enter() ``` and a ``` gtk.gdk.thre...
15,852,455
I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one. ...
2013/04/06
[ "https://Stackoverflow.com/questions/15852455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1714385/" ]
There are better options than periodically polling the value of the variable. Polling could miss a variable change, and it requires computational resources even if nothing is happening. You could wrap the variable in a wrapper class and change it only through a setter. If you're using Eclipse, you can ask the debugg...
Using a wrapper class for you variable like: ``` class VarWrapper{ private Object myVar; public Object getMyVar() { return myVar; } public void setMyVar(Object myVar) { //[1],Here you'll know myVar changed this.myVar = myVar; } } ```
15,852,455
I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one. ...
2013/04/06
[ "https://Stackoverflow.com/questions/15852455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1714385/" ]
There are better options than periodically polling the value of the variable. Polling could miss a variable change, and it requires computational resources even if nothing is happening. You could wrap the variable in a wrapper class and change it only through a setter. If you're using Eclipse, you can ask the debugg...
``` Class Test{ private int var; public void setVariable(int var){ this.var = var; varChangedCallBack(); } public void varChangedCallBack(){ //Do something on var changed } } ``` As the variable is private above, it can be changed only thr' setter.After changing we are giving call to...
15,852,455
I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one. ...
2013/04/06
[ "https://Stackoverflow.com/questions/15852455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1714385/" ]
There are better options than periodically polling the value of the variable. Polling could miss a variable change, and it requires computational resources even if nothing is happening. You could wrap the variable in a wrapper class and change it only through a setter. If you're using Eclipse, you can ask the debugg...
If you have a dedicated thread to check the variable state then it should be done with wakening up this waiting thread with sync-notify on the object. The waiting thread is going to sync-wait on that object. If you do not have a dedicated thread then this the Observer pattern. <http://en.wikipedia.org/wiki/Observer_pa...
30,023,898
I'm creating a little calculator as a project And I want it to restart when it type yes when it's done. Problem is, I can't seem to figure out how. I'm not a whiz when it comes to python. ``` import sys OPTIONS = ["Divide", "divide", "Multiply", "multiply", "Add", "add", "Subtract", "subtract"] def useri...
2015/05/04
[ "https://Stackoverflow.com/questions/30023898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4861144/" ]
You don't need to restart your script, just have a little bit of thought about the design before you code. Taking the script you provided, there are two alterations for this issue: ``` def playagain(): while True: again = input("Again? Yes/No: ") if again == "Yes" or again == "yes": r...
Use os.execv().... [Restarting a Python Script Within Itself](http://blog.petrzemek.net/2014/03/23/restarting-a-python-script-within-itself/)
30,023,898
I'm creating a little calculator as a project And I want it to restart when it type yes when it's done. Problem is, I can't seem to figure out how. I'm not a whiz when it comes to python. ``` import sys OPTIONS = ["Divide", "divide", "Multiply", "multiply", "Add", "add", "Subtract", "subtract"] def useri...
2015/05/04
[ "https://Stackoverflow.com/questions/30023898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4861144/" ]
instead of restarting the scrip i made it so you could use it forever and only the user himself can exit it. i only changed the playagain() and the while loop at the end, read the comments for the explanation: ``` import sys OPTIONS = ["Divide", "divide", "Multiply", "multiply", "Add", "add", "Subtract", "subtract"] ...
Use os.execv().... [Restarting a Python Script Within Itself](http://blog.petrzemek.net/2014/03/23/restarting-a-python-script-within-itself/)
30,023,898
I'm creating a little calculator as a project And I want it to restart when it type yes when it's done. Problem is, I can't seem to figure out how. I'm not a whiz when it comes to python. ``` import sys OPTIONS = ["Divide", "divide", "Multiply", "multiply", "Add", "add", "Subtract", "subtract"] def useri...
2015/05/04
[ "https://Stackoverflow.com/questions/30023898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4861144/" ]
You don't need to restart your script, just have a little bit of thought about the design before you code. Taking the script you provided, there are two alterations for this issue: ``` def playagain(): while True: again = input("Again? Yes/No: ") if again == "Yes" or again == "yes": r...
instead of restarting the scrip i made it so you could use it forever and only the user himself can exit it. i only changed the playagain() and the while loop at the end, read the comments for the explanation: ``` import sys OPTIONS = ["Divide", "divide", "Multiply", "multiply", "Add", "add", "Subtract", "subtract"] ...
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
Replace ``` $output .= $c; ``` with ``` $output = $c . $output; ```
strrev() is a function that reverses a string in PHP. <http://php.net/manual/en/function.strrev.php> ``` $s = "foobar"; echo strrev($s); //raboof ``` If you want to check if a word is a palindrome: ``` function is_palindrome($word){ return strrev($word) == $word } $s = "RACECAR"; echo $s." is ".((is_palindrome($s)...
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
I don't try that code, but I think that it should work: ``` $string = "hello"; $output = ""; $arr = array_reverse(str_split($string)); // Transform "" to [] and then reverse => ["o","l","l,"e","h"] foreach($arr as $char) { $output .= $char; } echo $output; ``` Another way: ``` $string = "hello"; $output = ""; ...
strrev() is a function that reverses a string in PHP. <http://php.net/manual/en/function.strrev.php> ``` $s = "foobar"; echo strrev($s); //raboof ``` If you want to check if a word is a palindrome: ``` function is_palindrome($word){ return strrev($word) == $word } $s = "RACECAR"; echo $s." is ".((is_palindrome($s)...
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
Can't be shorter I guess. With a loop :) ``` $word = "Hello"; $result = ''; foreach($word as $letter) $result = $letter . $result; echo $result; ```
strrev() is a function that reverses a string in PHP. <http://php.net/manual/en/function.strrev.php> ``` $s = "foobar"; echo strrev($s); //raboof ``` If you want to check if a word is a palindrome: ``` function is_palindrome($word){ return strrev($word) == $word } $s = "RACECAR"; echo $s." is ".((is_palindrome($s)...
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
Replace ``` $output .= $c; ``` with ``` $output = $c . $output; ```
I don't try that code, but I think that it should work: ``` $string = "hello"; $output = ""; $arr = array_reverse(str_split($string)); // Transform "" to [] and then reverse => ["o","l","l,"e","h"] foreach($arr as $char) { $output .= $char; } echo $output; ``` Another way: ``` $string = "hello"; $output = ""; ...
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
Replace ``` $output .= $c; ``` with ``` $output = $c . $output; ```
Can't be shorter I guess. With a loop :) ``` $word = "Hello"; $result = ''; foreach($word as $letter) $result = $letter . $result; echo $result; ```
15,612,362
Here is python code: ``` def is_palindrome(s): return revers(s) == s def revers(s): ret = '' for ch in s: ret = ch + ret return ret print is_palindrome('RACECAR') # that will print true ``` when i convert that function to php. ``` function is_palindrome($string){ if (strrev($string) =...
2013/03/25
[ "https://Stackoverflow.com/questions/15612362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/740182/" ]
Can't be shorter I guess. With a loop :) ``` $word = "Hello"; $result = ''; foreach($word as $letter) $result = $letter . $result; echo $result; ```
I don't try that code, but I think that it should work: ``` $string = "hello"; $output = ""; $arr = array_reverse(str_split($string)); // Transform "" to [] and then reverse => ["o","l","l,"e","h"] foreach($arr as $char) { $output .= $char; } echo $output; ``` Another way: ``` $string = "hello"; $output = ""; ...
24,931,465
Hi I am very new to python, here i m trying to open a xls file in python code but it is showing me some error as below. Code: ``` from xlrd import open_workbook import os.path wb = open_workbook('C:\Users\xxxx\Desktop\a.xlsx') Error:Traceback (most recent call last): File "C:\Python27\1.py", line 3, in <module> wb =...
2014/07/24
[ "https://Stackoverflow.com/questions/24931465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3872486/" ]
This is a version conflict issue. Your Excel sheet format and the format that xlrd expects are different. You could try to save the Excel sheet in a different format until you find what xlrd expects.
Not familiar with xlrd, but nothing wrong appears on my Mac. According to @jewirth, you can try to rename the suffix to xls which is the old version, and then reopen it or convert it into xlsx.
24,931,465
Hi I am very new to python, here i m trying to open a xls file in python code but it is showing me some error as below. Code: ``` from xlrd import open_workbook import os.path wb = open_workbook('C:\Users\xxxx\Desktop\a.xlsx') Error:Traceback (most recent call last): File "C:\Python27\1.py", line 3, in <module> wb =...
2014/07/24
[ "https://Stackoverflow.com/questions/24931465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3872486/" ]
This is a version conflict issue. Your Excel sheet format and the format that xlrd expects are different. You could try to save the Excel sheet in a different format until you find what xlrd expects.
``` from xlrd import open_workbook import os.path wb = open_workbook(r'C:\Users\XXXX\Desktop\a.xlsx') print wb Output : <xlrd.book.Book object at 0x0260E490> ``` Opened the excel in 'r' format and it shows the excel object. Its working normally. Try to get the xlrd version and update it. Change the excel...
24,931,465
Hi I am very new to python, here i m trying to open a xls file in python code but it is showing me some error as below. Code: ``` from xlrd import open_workbook import os.path wb = open_workbook('C:\Users\xxxx\Desktop\a.xlsx') Error:Traceback (most recent call last): File "C:\Python27\1.py", line 3, in <module> wb =...
2014/07/24
[ "https://Stackoverflow.com/questions/24931465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3872486/" ]
This is a version conflict issue. Your Excel sheet format and the format that xlrd expects are different. You could try to save the Excel sheet in a different format until you find what xlrd expects.
You are getting that error because you are using an old version of [xlrd](https://pypi.python.org/pypi/xlrd) which doesn't support xlsx. You need to upgrade to a recent version of xlrd.
33,686,880
I have a `libpython27.a` file: how to know whether it is 32-bit or 64-bit, on Windows 7 x64?
2015/11/13
[ "https://Stackoverflow.com/questions/33686880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/395857/" ]
Try `dumpbin /headers "libpython27.a"`. ([dumpbin reference](https://msdn.microsoft.com/en-us/library/c1h23y6c.aspx)) The output will contain `FILE HEADER VALUES 14C machine (x86)` or `FILE HEADER VALUES 8664 machine (x64)` --- Note that if you get an error message like: ``` E:\temp>dumpbin /headers "libpython...
When starting the Python interpreter in the terminal/command line you may also see a line like: > > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit > (AMD64)] on win32 > > > Where [MSC v.1500 64 bit (AMD64)] means 64-bit Python. Or Try using ctypes to get the size of a void pointer: ``` impor...
33,686,880
I have a `libpython27.a` file: how to know whether it is 32-bit or 64-bit, on Windows 7 x64?
2015/11/13
[ "https://Stackoverflow.com/questions/33686880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/395857/" ]
When starting the Python interpreter in the terminal/command line you may also see a line like: > > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit > (AMD64)] on win32 > > > Where [MSC v.1500 64 bit (AMD64)] means 64-bit Python. Or Try using ctypes to get the size of a void pointer: ``` impor...
On Linux you can use: `objdump -a libpython27.a|grep 'file format'`. Example: ``` f@f-VirtualBox:/media/code$ objdump -a libpython27.a|grep 'file format' dywkt.o: file format pe-i386 dywkh.o: file format pe-i386 dywks01051.o: file format pe-i386 dywks01050.o: file format pe-i386 dywks01049.o: fil...
33,686,880
I have a `libpython27.a` file: how to know whether it is 32-bit or 64-bit, on Windows 7 x64?
2015/11/13
[ "https://Stackoverflow.com/questions/33686880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/395857/" ]
Try `dumpbin /headers "libpython27.a"`. ([dumpbin reference](https://msdn.microsoft.com/en-us/library/c1h23y6c.aspx)) The output will contain `FILE HEADER VALUES 14C machine (x86)` or `FILE HEADER VALUES 8664 machine (x64)` --- Note that if you get an error message like: ``` E:\temp>dumpbin /headers "libpython...
On Linux you can use: `objdump -a libpython27.a|grep 'file format'`. Example: ``` f@f-VirtualBox:/media/code$ objdump -a libpython27.a|grep 'file format' dywkt.o: file format pe-i386 dywkh.o: file format pe-i386 dywks01051.o: file format pe-i386 dywks01050.o: file format pe-i386 dywks01049.o: fil...
68,764,541
I was reading through the [PEP 526](https://www.python.org/dev/peps/pep-0526/) documentation and I was wondering what is the proper way to annotate a class instance. I have not found the answer in the documentation. I have the following module: ```py class global_variables: # Class body global_variables_dictio...
2021/08/12
[ "https://Stackoverflow.com/questions/68764541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10588212/" ]
**Note**: "Best Practice" for something like this is difficult to define, since everyone's situation is likely different. That being said, one of our projects has a similar situation as yours: we use Git Flow, and our `develop` branch build numbers are always different than the `release` branch build numbers. Our pote...
What about using an external tool to manage the version? We use [GitVersion](https://github.com/GitTools/GitVersion) for this. Now I am not sure if there is a smarter way, but a brute-force one is to have something like this `<version>${env.GitVersion_SemVer}</version>` in your pom.xml, where env.GitVersion\_SemVer is ...
26,472,868
I have a python script (analyze.py) which takes a filename as a parameter and analyzes it. When it is done with analysis, it waits for another file name. What I want to do is: 1. Send file name as a parameter from PHP to Python. 2. Run analyze.py in the background as a daemon with the filename that came from PHP. I c...
2014/10/20
[ "https://Stackoverflow.com/questions/26472868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1430739/" ]
The obvious answer here is to either: 1. Run `analyze.py` once per filename, instead of running it as a daemon. 2. Pass `analyze.py` a whole slew of filenames at startup, instead of passing them one at a time. But there may be a reason neither obvious answer will work in your case. If so, then you need some form of *...
Here is what I did. PHP Part: ``` <?php $param1 = "filename"; $command = "python analyze.py "; $command .= " $param1"; $pid = popen( $command,"r"); echo "<body><pre>"; while( !feof( $pid ) ) { echo fread($pid, 256); flush(); ob_flush(); } pclose($pid); ?> ``` Python Part: ``` 1. I used [JSON-RPC]: https://...
46,877,384
I am reading a text file in python(500 rows) and it seems like: ``` File Input: 0082335401 0094446049 01008544409 01037792084 01040763890 ``` I wanted to ask that is it possible to insert one space after 5th Character in each line: ``` Desired Output: 00823 35401 00944 46049 01008 544409 01037 792084 01040 763890 ...
2017/10/22
[ "https://Stackoverflow.com/questions/46877384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Inside your k6 script use the url `host.docker.internal` to access something running on the host machine. For example to access a service running on the host at `http://localhost:8080` ```js // script.js import http from "k6/http"; import { sleep } from "k6"; export default function () { http.get("http://host.dock...
k6 inside the docker instance should be able to connect to the "public" IP on your host machine - the IP that is configured on your ethernet or Wifi interface. You can do a `ipconfig /all` to see all your interfaces and their IPs. On my Mac I can do this: `$ python httpserv.py & [1] 7824 serving at port 8000 $ ifconf...
36,711,810
I'm going to come out with a disclaimer and say this is my homework problem. So I don't necessarily want you to solve it, I just want some clarification. The exact problem is this: > > Write a function to swap odd and even bits in an integer with as few > instructions as possible (e.g., bit 0 and bit 1 are swapped...
2016/04/19
[ "https://Stackoverflow.com/questions/36711810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1157549/" ]
In assembly one can use [bit masks](https://en.wikipedia.org/wiki/Mask_%28computing%29) together with other [bitwise operations](https://en.wikipedia.org/wiki/Bitwise_operation) to archive your result. ``` result = ((odd-bit-mask & input) << 1) | ((even-bit-mask & input) >> 1) ``` where `odd-bit-mask` is a value wit...
Here are a few hints: * Bitwise boolean operations (these usually have 1:1 counterparts in assembly, but if everything else fails, you can construct them by cleverly combining several XOR calls) + bitwise AND: 0b10110101 & 0b00011000 → 0b00010000 + bitwise OR: 0b10110101 & 0b00011000 → 0b10111101 + bitwise XOR: 0b...
41,132,864
I have been trying to install OpenCV for ages now and finally I succeeded using this tutorial: <http://www.pyimagesearch.com/2016/12/05/macos-install-opencv-3-and-python-3-5/>. However, whenever I try to import cv2 in IDLE, it is not found but I am certain I installed OpenCV. The cv2.so file exists at: /usr/local/li...
2016/12/14
[ "https://Stackoverflow.com/questions/41132864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7293747/" ]
ok i found the answer! after you activate the virtual environment with: ``` work on cv ``` type this on the terminal to open the IDLE with the current virtual environment ``` python -c "from idlelib.PyShell import main; main()" ``` or ``` python -m idlelib ``` and it will do the trick!
Dumb approach but does your IDLE run the same python environment as your terminal?
12,990,462
This is a repost of an issue I posted on the berkelium project on github (<https://github.com/sirikata/berkelium/issues/19>). My question: During chromium compilation on Linux (Debian testing, 64bit, gcc 4.7.1, cmake 2.8.9), the python script `action_makenames.py` fails with the following error: ``` ... ACTION web...
2012/10/20
[ "https://Stackoverflow.com/questions/12990462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/780281/" ]
Turns out to be a preprocessor bug for gcc 4.6. As a fix, you have to remove the `-P` parameter of the gcc preprocessor command in `make_names.pl`. **Bug report**: <http://code.google.com/p/chromium/issues/detail?id=46411> **Bug fix**: <http://trac.webkit.org/changeset/84123>
sounds like you may be missing a directory, a la <http://aur.archlinux.org/packages.php?ID=45713>
53,066,830
I have a python program which I have made work in both Python 2 and 3, and it has more functionality in Python 3 (using new Python 3 features). My script currently starts `#!/usr/bin/env python`, as that seems to be the mostly likely name for a python executable. However, what I'd like to do is "if python3 exists, use...
2018/10/30
[ "https://Stackoverflow.com/questions/53066830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27074/" ]
Another better method modified from [this question](https://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python) is to check the `sys.version`: ``` import sys py_ver = sys.version[0] ``` Original answer: May not be the best method, but one way to do it is test against a fun...
Try with version\_info from sys package
53,066,830
I have a python program which I have made work in both Python 2 and 3, and it has more functionality in Python 3 (using new Python 3 features). My script currently starts `#!/usr/bin/env python`, as that seems to be the mostly likely name for a python executable. However, what I'd like to do is "if python3 exists, use...
2018/10/30
[ "https://Stackoverflow.com/questions/53066830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27074/" ]
Another better method modified from [this question](https://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python) is to check the `sys.version`: ``` import sys py_ver = sys.version[0] ``` Original answer: May not be the best method, but one way to do it is test against a fun...
Maybe I didn't quite get what you want. I understood: You want to look if there is Python 3 installed on the Computer and if so, use it. Inside the script you can check the version with `sys.version` as Idlehands mentioned. To get the latest version you might want to use a small bash script like this ``` py_versions=(...
58,192,211
I'm trying to do something simple in Python. I'm a little rusty so I'm not sure what I'm doing wrong. I want to give random values to dictionary items. Each loop I want to subtract from the original value so if a house has 5 rooms then the total doesn't ever go over 5 for the combined items in the dictionary. This is ...
2019/10/01
[ "https://Stackoverflow.com/questions/58192211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1112733/" ]
In the script you're re-assigning `h1` with `h1 - size` in each iteration of the `for` loop, and if `size` happens to be `h1` as it is the upper bound passed to `randint`, `h1` would become `0` after the assignment, so that in the next iteration you would be effectively calling `random.randint(1, 0)`, where the upper b...
Let's consider a simple example. You randomly select a 4-room house. Your random numbers give you 3 bedrooms and one bath. Your loop continues to "study" and tries to generate a random number form 1 to 0. You neglected to reserve a room for that requirement. Python considers the inverted range to be an error. If you t...
33,306,221
I need in python execute this command and enter password from keyboard, this is works: ``` import os cmd = "cat /home/user1/.ssh/id_rsa.pub | ssh [email protected] \'cat >> .ssh/authorized_keys\' > /dev/null 2>&1" os.system(cmd) ``` As you can see I want append public key to remote host via ssh. See here: [equivalen...
2015/10/23
[ "https://Stackoverflow.com/questions/33306221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2595216/" ]
From [the `pexpect` docs](http://pexpect.readthedocs.org/en/stable/api/pexpect.html#spawn-class): > > Remember that Pexpect does NOT interpret shell meta characters such as > redirect, pipe, or wild cards (`>`, `|`, or `*`). This is a > common mistake. If you want to run a command and pipe it through > another com...
That worked for me: ``` command = "/bin/bash -c \"cat /home/user1/.ssh/id_rsa.pub | ssh [email protected] \'cat >> ~/.ssh/authorized_keys\' > /dev/null 2>&1\"" child = spawn(command=command, timeout=5) ```
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
None of the answers shows how to delete just one table in an app. It's not too difficult. The [`dbshell`](https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-dbshell) command logs the user into the sqlite3 shell. ``` python manage.py dbshell ``` When you are in the shell, type the following command...
In Django 2.1.7, I've opened the `db.sqlite3` file in [SQLite browser](https://sqlitebrowser.org/) (there is also a Python package on [Pypi](https://pypi.org/project/sqlite_bro/)) and deleted the table using command ``` DROP TABLE appname_tablename; ``` and then ``` DELETE FROM django_migrations WHERE App='appname...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
get the DROP statements with `python manage.py sqlclear app_name` then try `python manage.py dbshell` and execute the DROP statement check out <http://docs.djangoproject.com/en/dev/ref/django-admin/>
In Django 1.9 I had to do Kat Russo's steps, but the second migration was a little bit tricky. You have to run ``` ./manage.py migrate --run-syncdb ```
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
get the DROP statements with `python manage.py sqlclear app_name` then try `python manage.py dbshell` and execute the DROP statement check out <http://docs.djangoproject.com/en/dev/ref/django-admin/>
In Django 2.1.7, I've opened the `db.sqlite3` file in [SQLite browser](https://sqlitebrowser.org/) (there is also a Python package on [Pypi](https://pypi.org/project/sqlite_bro/)) and deleted the table using command ``` DROP TABLE appname_tablename; ``` and then ``` DELETE FROM django_migrations WHERE App='appname...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
to clear out an application is as simple as writing: ``` ./manage.py sqlclear app_name | ./manage.py dbshell ``` then in order to rebuild your tables just type: ``` ./manage.py syncdb ```
I had the same problem. For a quick resolve (if you don't care about losing your tables/data), correct your models.py file with the desired data types, delete the Migration folder and db.SQLite3 file, then re-run the following commands: 1. python manage.py migrate 2. python manage.py makemigrations 3. python mana...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
to clear out an application is as simple as writing: ``` ./manage.py sqlclear app_name | ./manage.py dbshell ``` then in order to rebuild your tables just type: ``` ./manage.py syncdb ```
get the DROP statements with `python manage.py sqlclear app_name` then try `python manage.py dbshell` and execute the DROP statement check out <http://docs.djangoproject.com/en/dev/ref/django-admin/>
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
Might be worth expanding on a few answers here: So, you can get access to the `dbshell` with the following command: ``` python manage.py dbshell ``` It is then preferential to use the following: ``` DROP TABLE appname_tablename CASCADE; ``` To drop any related tables, effectively mirroring the "on\_delete=CASCAD...
In Django 1.9 I had to do Kat Russo's steps, but the second migration was a little bit tricky. You have to run ``` ./manage.py migrate --run-syncdb ```
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
to clear out an application is as simple as writing: ``` ./manage.py sqlclear app_name | ./manage.py dbshell ``` then in order to rebuild your tables just type: ``` ./manage.py syncdb ```
In Django 2.1.7, I've opened the `db.sqlite3` file in [SQLite browser](https://sqlitebrowser.org/) (there is also a Python package on [Pypi](https://pypi.org/project/sqlite_bro/)) and deleted the table using command ``` DROP TABLE appname_tablename; ``` and then ``` DELETE FROM django_migrations WHERE App='appname...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
get the DROP statements with `python manage.py sqlclear app_name` then try `python manage.py dbshell` and execute the DROP statement check out <http://docs.djangoproject.com/en/dev/ref/django-admin/>
I had the same problem. For a quick resolve (if you don't care about losing your tables/data), correct your models.py file with the desired data types, delete the Migration folder and db.SQLite3 file, then re-run the following commands: 1. python manage.py migrate 2. python manage.py makemigrations 3. python mana...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
I had the same problem. For a quick resolve (if you don't care about losing your tables/data), correct your models.py file with the desired data types, delete the Migration folder and db.SQLite3 file, then re-run the following commands: 1. python manage.py migrate 2. python manage.py makemigrations 3. python mana...
Might be worth expanding on a few answers here: So, you can get access to the `dbshell` with the following command: ``` python manage.py dbshell ``` It is then preferential to use the following: ``` DROP TABLE appname_tablename CASCADE; ``` To drop any related tables, effectively mirroring the "on\_delete=CASCAD...
2,286,276
I made a model, and ran python manage.py syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one. Then I went to python manage.py shell, and tried to run .objects.all(),...
2010/02/18
[ "https://Stackoverflow.com/questions/2286276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/275779/" ]
to clear out an application is as simple as writing: ``` ./manage.py sqlclear app_name | ./manage.py dbshell ``` then in order to rebuild your tables just type: ``` ./manage.py syncdb ```
In Django 1.9 I had to do Kat Russo's steps, but the second migration was a little bit tricky. You have to run ``` ./manage.py migrate --run-syncdb ```
59,039,858
I am importing a large number of dates in the form DD/MM/YYYY from a csv file into python and want to group them by just MM-YYYY. One method I have tried is the following: ``` str=date.iloc[2] ``` which results in str=7/18/2019. But what I want to do is convert it to Jul 2019 to make groupings by month and year. I h...
2019/11/25
[ "https://Stackoverflow.com/questions/59039858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12432098/" ]
``` datetime.datetime.strptime("str","%m/%d/%Y").strptime("%b %Y") ``` Is to parse literally the string of "str" into the date. Instead, you should do ``` datetime.datetime.strptime(str,"%m/%d/%Y").strftime("%b %Y") ```
In this line ``` datetime.datetime.strptime("str","%m/%d/%Y").strptime("%b %Y") ``` `"str"` is a string literal. You want the variable `str` ``` datetime.datetime.strptime(str,"%m/%d/%Y").strptime("%b %Y") ```
59,039,858
I am importing a large number of dates in the form DD/MM/YYYY from a csv file into python and want to group them by just MM-YYYY. One method I have tried is the following: ``` str=date.iloc[2] ``` which results in str=7/18/2019. But what I want to do is convert it to Jul 2019 to make groupings by month and year. I h...
2019/11/25
[ "https://Stackoverflow.com/questions/59039858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12432098/" ]
You can use datetime's `strftime()`: ``` import datetime a = '07/22/1990' d = datetime.datetime.strptime(a, "%m/%d/%Y") dd = d.strftime("%m/%Y") print('d: ', d) print('dd: ', dd) # or in one line ddd = datetime.datetime.strptime(a, "%m/%d/%Y").strftime("%m/%Y") print('ddd: ', ddd) ``` The output: ``` $ python p...
In this line ``` datetime.datetime.strptime("str","%m/%d/%Y").strptime("%b %Y") ``` `"str"` is a string literal. You want the variable `str` ``` datetime.datetime.strptime(str,"%m/%d/%Y").strptime("%b %Y") ```
4,707,941
I have seen several Questions comparing different ECommerce CMS's: 1. [Prestashop compared to Zen-Cart and osCommerce](https://stackoverflow.com/questions/2040472/prestashop-compared-to-zen-cart-and-oscommerce) 2. [Magento or Prestashop, which is better?](https://stackoverflow.com/search?q=prestashop) 3. [Best php/rub...
2011/01/16
[ "https://Stackoverflow.com/questions/4707941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363701/" ]
"Free" in the e-commerce industry usually works out to a few thousand dollars a month of real cost. E-commerce stores are powering the livelihood of businesses, so there is no way to go with a value hosting company. Additionally security is a huge concern so updates are incredibly important. So this leaves you with a s...
The prices is not the main difference between Shopify and PrestaShop. Talking about the scope- I think both will suit you. 1. Technical Level The choice of hosted Shopify or open-source PrestaShop may depends on the level of technical skills. Without doubt it is easier to maintain your store with hosted shopping cart...
12,624,324
I am facing difficulty in getting the xml structure listing all the directories/ sub directories inside a given directory. I got that working using the recursion in the [given post](https://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion) My problem is little bit...
2012/09/27
[ "https://Stackoverflow.com/questions/12624324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1364646/" ]
[`os.walk`](http://docs.python.org/library/os.html#os.walk) already distinguishes between files and directories: ``` def find_all_dirs(root='.'): for path,dirs,files in os.walk(root): for d in dirs: yield os.path.join(path, d) ```
For just one directory... ``` import os def get_dirs(p): p = os.path.abspath(p) return [n for n in os.listdir(p) if os.path.isdir(os.path.join(p, n))] print "\n".join(get_dirs(".")) ```
12,624,324
I am facing difficulty in getting the xml structure listing all the directories/ sub directories inside a given directory. I got that working using the recursion in the [given post](https://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion) My problem is little bit...
2012/09/27
[ "https://Stackoverflow.com/questions/12624324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1364646/" ]
[`os.walk`](http://docs.python.org/library/os.html#os.walk) already distinguishes between files and directories: ``` def find_all_dirs(root='.'): for path,dirs,files in os.walk(root): for d in dirs: yield os.path.join(path, d) ```
Here is the solution I got after searching and trying different things. I am not saying that this if faster than then method of looking every content in a directory, but it actually produces the result much more quicker( difference visible when directory contain 1000 of files) ``` import os import subprocess from xml...
12,624,324
I am facing difficulty in getting the xml structure listing all the directories/ sub directories inside a given directory. I got that working using the recursion in the [given post](https://stackoverflow.com/questions/2104997/os-walk-python-xml-representation-of-a-directory-structure-recursion) My problem is little bit...
2012/09/27
[ "https://Stackoverflow.com/questions/12624324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1364646/" ]
For just one directory... ``` import os def get_dirs(p): p = os.path.abspath(p) return [n for n in os.listdir(p) if os.path.isdir(os.path.join(p, n))] print "\n".join(get_dirs(".")) ```
Here is the solution I got after searching and trying different things. I am not saying that this if faster than then method of looking every content in a directory, but it actually produces the result much more quicker( difference visible when directory contain 1000 of files) ``` import os import subprocess from xml...
46,552,178
I have two files. `functions.py` has a function and creates a pyspark udf from that function. `main.py` attempts to import the udf. However, `main.py` seems to have trouble accessing the function in `functions.py`. functions.py: ``` from pyspark.sql.functions import udf from pyspark.sql.types import StringType def d...
2017/10/03
[ "https://Stackoverflow.com/questions/46552178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5617110/" ]
Just adding this as answer:- add your py file to sparkcontext in order to make it available to your executors. ``` sc.addPyFile("functions.py") from functions import sample_udf ``` Here is my test notebook <https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/366922160...
I think a cleaner solution would be to use the udf decorator to define your udf function : ``` import pyspark.sql.functions as F from pyspark.sql.types import StringType @F.udf def sample_udf(x): return x + 'hello' ``` With this solution, the udf does not reference any other function and you don't need the `sc...
21,226,366
I have a script to get and setup the latest NodeJS on my .deb system: ``` echo "Downloading, building and installing latest NodeJS" sudo apt-get install python g++ make checkinstall mkdir /tmp/node_build && cd $_ curl -O "http://nodejs.org/dist/node-latest.tar.gz" tar xf node-latest.tar.gz && cd node-v* NODE_VERSION="...
2014/01/20
[ "https://Stackoverflow.com/questions/21226366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/587021/" ]
Is there another "v" in the path, like right before the "i8/"? `#*v` will remove through the *first* "v" in the variable; I'm pretty sure you want `##*v` which'll remove through the *last* "v" in the variable. (Technically, `#` removes the shortest matching prefix, and `##` removes the longest match). Thus: ``` NODE_V...
Try this ``` sudo checkinstall -y --install=no --pkgversion "${NODE_VERSION##*v}" ```
37,445,901
This question comes from [this one](https://stackoverflow.com/questions/37399965/refresh-web-page-using-a-cgi-python-script). What I want is to be able to return the `HTTP 303` header from my python script, when the user clicks on a button. My script is very simple and as far as output is concerned, it *only* prints t...
2016/05/25
[ "https://Stackoverflow.com/questions/37445901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/751115/" ]
Assuming you are using cgi ([2.7](https://docs.python.org/2/library/cgi.html))([3.5](https://docs.python.org/3.5/library/cgi.html)) The example below should redirect to the same page. The example doesn't attempt to parse headers, check what POST was send, it simply redirects to the page `'/'` when a POST is detected. ...
Typically browsers like to see `/r/n/r/n` at the end of an HTTP response.
37,445,901
This question comes from [this one](https://stackoverflow.com/questions/37399965/refresh-web-page-using-a-cgi-python-script). What I want is to be able to return the `HTTP 303` header from my python script, when the user clicks on a button. My script is very simple and as far as output is concerned, it *only* prints t...
2016/05/25
[ "https://Stackoverflow.com/questions/37445901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/751115/" ]
Assuming you are using cgi ([2.7](https://docs.python.org/2/library/cgi.html))([3.5](https://docs.python.org/3.5/library/cgi.html)) The example below should redirect to the same page. The example doesn't attempt to parse headers, check what POST was send, it simply redirects to the page `'/'` when a POST is detected. ...
Be very careful about what Python automatically does. For example, in Python 3, the print function adds line endings to each print, which can mess with HTTP's very specific number of line endings between each message. You also still need a content type header, for some reason. This worked for me in Python 3 on Apache ...
29,848,351
I have the following list of keys in python. ``` [{'country': None, 'percent': 100.0}, {'country': 'IL', 'percent': 100.0}, {'country': 'IT', 'percent': 100.0}, {'country': 'US', 'percent': 2.0202}, {'country': 'JP', 'percent': 11.1111}, {'country': 'US', 'percent': 6.9767}, {'country': 'SG', 'percent': 99.8482}, {'co...
2015/04/24
[ "https://Stackoverflow.com/questions/29848351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/567797/" ]
``` result_map = {} for item in response: if item['country'] is None: continue if item['country'] not in result_map: result_map[item['country']] = item['percent'] else: result_map[item['country']] += item['percent'] results = [ {'country': country, 'percent': percent} for co...
Change the condition of the if to: ``` if response.index(v) != response.index(j) and v['country'] == j['country']: ``` You're addding twice the elements.
29,848,351
I have the following list of keys in python. ``` [{'country': None, 'percent': 100.0}, {'country': 'IL', 'percent': 100.0}, {'country': 'IT', 'percent': 100.0}, {'country': 'US', 'percent': 2.0202}, {'country': 'JP', 'percent': 11.1111}, {'country': 'US', 'percent': 6.9767}, {'country': 'SG', 'percent': 99.8482}, {'co...
2015/04/24
[ "https://Stackoverflow.com/questions/29848351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/567797/" ]
``` result_map = {} for item in response: if item['country'] is None: continue if item['country'] not in result_map: result_map[item['country']] = item['percent'] else: result_map[item['country']] += item['percent'] results = [ {'country': country, 'percent': percent} for co...
A solution using `defaultdict` and filtering out the `None` country: ``` from collections import defaultdict data = [{'country': None, 'percent': 100.0}, {'country': 'IL', 'percent': 100.0}, {'country': 'IT', 'percent': 100.0}, {'country': 'US', 'percent': 2.0202}, {'country': 'JP', 'percent': 11.1111}, {'country': '...
29,848,351
I have the following list of keys in python. ``` [{'country': None, 'percent': 100.0}, {'country': 'IL', 'percent': 100.0}, {'country': 'IT', 'percent': 100.0}, {'country': 'US', 'percent': 2.0202}, {'country': 'JP', 'percent': 11.1111}, {'country': 'US', 'percent': 6.9767}, {'country': 'SG', 'percent': 99.8482}, {'co...
2015/04/24
[ "https://Stackoverflow.com/questions/29848351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/567797/" ]
``` result_map = {} for item in response: if item['country'] is None: continue if item['country'] not in result_map: result_map[item['country']] = item['percent'] else: result_map[item['country']] += item['percent'] results = [ {'country': country, 'percent': percent} for co...
A solution using [`itertools.groupby`](https://docs.python.org/2/library/itertools.html#itertools.groupby): ``` from itertools import groupby new_response = [] def get_country(dct): return dct['country'] sorted_response = sorted(response, key=get_country) # data needs to be sorted for groupby for country, group ...
19,847,275
My function is like ``` def calResult(w,t,l,team): wDict={} for item in team: for x in w: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) for x in t: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) return wDict ``` say ...
2013/11/07
[ "https://Stackoverflow.com/questions/19847275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2844097/" ]
You can not access `wDict[item]` the first time, since your dict is empty This would be ok: ``` wDict[item] = 1 ``` But you can not do this : ``` wDict[item] = wDict[item] + 1 ``` Maybe you want to use this syntax : ``` wDict[item] = int(wDict.get(item, 0)]) + int(x[item.index(" "):item.index(" ") + 1]) ```
Looks like you are trying to use wDict[item] as the rvalue and the lvalue in the same assignment statement, when wDict[item] is not yet initialized. ``` wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) ``` You are trying to access the "value" of the key item, but there is no key value pair init...
19,847,275
My function is like ``` def calResult(w,t,l,team): wDict={} for item in team: for x in w: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) for x in t: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) return wDict ``` say ...
2013/11/07
[ "https://Stackoverflow.com/questions/19847275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2844097/" ]
I'm not quite sure what you're trying to do here (consider using more descriptive variable names than `x`, for starters), but here is the problem: ``` wDict[item]=int(wDict[item])+... ``` The first time you do this, `wDict[item]` doesn't exist, hence the `KeyError`. What you want, I think, is: ``` wDict[item] = wD...
You can not access `wDict[item]` the first time, since your dict is empty This would be ok: ``` wDict[item] = 1 ``` But you can not do this : ``` wDict[item] = wDict[item] + 1 ``` Maybe you want to use this syntax : ``` wDict[item] = int(wDict.get(item, 0)]) + int(x[item.index(" "):item.index(" ") + 1]) ```
19,847,275
My function is like ``` def calResult(w,t,l,team): wDict={} for item in team: for x in w: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) for x in t: wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) return wDict ``` say ...
2013/11/07
[ "https://Stackoverflow.com/questions/19847275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2844097/" ]
I'm not quite sure what you're trying to do here (consider using more descriptive variable names than `x`, for starters), but here is the problem: ``` wDict[item]=int(wDict[item])+... ``` The first time you do this, `wDict[item]` doesn't exist, hence the `KeyError`. What you want, I think, is: ``` wDict[item] = wD...
Looks like you are trying to use wDict[item] as the rvalue and the lvalue in the same assignment statement, when wDict[item] is not yet initialized. ``` wDict[item]=int(wDict[item])+int(x[item.index(" "):item.index(" ")+1]) ``` You are trying to access the "value" of the key item, but there is no key value pair init...
58,117,763
First of all, sorry for any newbie mistakes that I've made. But I couldn't figure out and couldn't find a source specifically for [deeppavlov (NER)](http://docs.deeppavlov.ai/en/master/features/models/ner.html) library. I'm trying to train ner\_ontonotes\_bert\_mult as described [here](http://docs.deeppavlov.ai/en/mast...
2019/09/26
[ "https://Stackoverflow.com/questions/58117763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10183880/" ]
There are at least two problems here: 1. instead of `validation.txt` there should be a `valid.txt` file; 2. you are trying to retrain a model that was pretrained on a different dataset with a different set of tags, it's not necessary. To train your model from scratch you can do something like: ```py import jso...
I tried deeppavlov training, and successfully trained the 'ner' model I also got the same error at first while training, then I overcome by researching more about it things to know before training - -> you can find the 'ner\_ontonotes\_bert\_multi.json' config file link in deeppavlov doc, which gives the dataset pat...
33,114,202
I'm currently testing docker on a Debian 8.2 server and I'm seeking help from mor experienced people. I've followed the official documentation to install docker (<http://docs.docker.com/installation/debian/>) and I'm now trying docker compose (<https://docs.docker.com/compose/>). I've installed compose using pip as de...
2015/10/13
[ "https://Stackoverflow.com/questions/33114202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5243755/" ]
You are on the right track. The first approach just needs two things: * a dot at the beginning to make it [context-specific](http://doc.scrapy.org/en/latest/topics/selectors.html#working-with-relative-xpaths) * `text()` at the end Fixed version: ``` selector.xpath('.//div[@class="score unvoted"]/text()').extract() ...
this should work - ``` selector.xpath('//div[contains(@class, "score unvoted")]/text()').extract() ```
59,711,699
I run my python scrapy project shows the error `no module named 'requests'` So I type `pip install requests` and then terminal information: ``` Requirement already satisfied: requests in ./Library/Python/2.7/lib/python/site-packages (2.22.0) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2....
2020/01/13
[ "https://Stackoverflow.com/questions/59711699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6902961/" ]
Install `python3` and `pip3` and then `pip3 install requests` if you are on ubuntu `python3` is installed by default you should first install `pip3` by `apt install python3-pip` and then `pip3 install requests`
If you are using two different versions of Python, it should explain why you can't use your module. To install the module on Python 3, try: ``` pip3 install requests ``` And make sure, you are using the correct version.
59,711,699
I run my python scrapy project shows the error `no module named 'requests'` So I type `pip install requests` and then terminal information: ``` Requirement already satisfied: requests in ./Library/Python/2.7/lib/python/site-packages (2.22.0) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2....
2020/01/13
[ "https://Stackoverflow.com/questions/59711699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6902961/" ]
Install `python3` and `pip3` and then `pip3 install requests` if you are on ubuntu `python3` is installed by default you should first install `pip3` by `apt install python3-pip` and then `pip3 install requests`
Check if you are using the same interpreter to which you have installed the package using `pip install`. As a best practice to avoid this type of issues when you have multiple versions of python, use pip as a module instead of directly calling pip. eg: `python -m pip install requests` `python3 -m pip install reque...
59,711,699
I run my python scrapy project shows the error `no module named 'requests'` So I type `pip install requests` and then terminal information: ``` Requirement already satisfied: requests in ./Library/Python/2.7/lib/python/site-packages (2.22.0) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2....
2020/01/13
[ "https://Stackoverflow.com/questions/59711699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6902961/" ]
If you are using two different versions of Python, it should explain why you can't use your module. To install the module on Python 3, try: ``` pip3 install requests ``` And make sure, you are using the correct version.
Check if you are using the same interpreter to which you have installed the package using `pip install`. As a best practice to avoid this type of issues when you have multiple versions of python, use pip as a module instead of directly calling pip. eg: `python -m pip install requests` `python3 -m pip install reque...
70,192,924
I have a discord bot running on a python script, and its token is stored in a `.txt` file. If I read from the file using: ``` with open('Stored Discord Token.txt') as storedToken: TOKEN = storedToken.readlines() ``` I can get the discord bot token. The problem is that the discord bot token looks like this: `[' ...
2021/12/02
[ "https://Stackoverflow.com/questions/70192924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12966704/" ]
First of all, `read()` will just return the whole file contents as a string, so you could use `TOKEN = storedToken.read()`. Lists in Python can be accessed using `[index]` so to access the first line in the file you can do `TOKEN = storedToken.readlines()[0]`. If say you wanted to access the `n`th line you could do `s...
As @Brian suggested, slicing out the substring solves the problem. If we simply add one line of code, like this: ``` with open('Stored Discord Token.txt') as file: fileContents = file.readlines() TOKEN = fileContents[-1] ``` we remove the `[`, `]`, `'`, and characters, and can now successfully pass that str...
70,192,924
I have a discord bot running on a python script, and its token is stored in a `.txt` file. If I read from the file using: ``` with open('Stored Discord Token.txt') as storedToken: TOKEN = storedToken.readlines() ``` I can get the discord bot token. The problem is that the discord bot token looks like this: `[' ...
2021/12/02
[ "https://Stackoverflow.com/questions/70192924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12966704/" ]
First of all, `read()` will just return the whole file contents as a string, so you could use `TOKEN = storedToken.read()`. Lists in Python can be accessed using `[index]` so to access the first line in the file you can do `TOKEN = storedToken.readlines()[0]`. If say you wanted to access the `n`th line you could do `s...
Try this one: ``` import re a=[' <token123> '] re.sub(r'[^a-zA-Z0-9]', '', str(a)) ```
56,009,890
Authors of an xml document did not include all the text inside an element that will be converted to a hyperlink. I would like to process or pre-process the xml to include the necessary text. I find this hard to describe but a simple example should show what I'm attempting. I'm using XSLT 2.0. I already do regular expre...
2019/05/06
[ "https://Stackoverflow.com/questions/56009890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/107690/" ]
The existing answer has the right approach but I would sharpen the regular expression pattern and the match patterns: ``` <xsl:param name="pattern" as="xs:string">\s\(Sheet \d\)</xsl:param> <xsl:variable name="pattern2" as="xs:string" select="'^' || $pattern"/> <xsl:variable name="pattern3" as="xs:string" selec...
You can use these two templates in combination with the *Identity template*: ``` <xsl:template match="glink"> <xsl:copy> <xsl:copy-of select="@*|text()" /> <xsl:text> </xsl:text> <xsl:value-of select="normalize-space(replace(following::text()[1],'\s(\(Sheet \d\)).*',' $1'))" /> </xsl:co...
56,009,890
Authors of an xml document did not include all the text inside an element that will be converted to a hyperlink. I would like to process or pre-process the xml to include the necessary text. I find this hard to describe but a simple example should show what I'm attempting. I'm using XSLT 2.0. I already do regular expre...
2019/05/06
[ "https://Stackoverflow.com/questions/56009890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/107690/" ]
In order to reduce the use of regex functions, I would use this approach: ``` <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="glink...
You can use these two templates in combination with the *Identity template*: ``` <xsl:template match="glink"> <xsl:copy> <xsl:copy-of select="@*|text()" /> <xsl:text> </xsl:text> <xsl:value-of select="normalize-space(replace(following::text()[1],'\s(\(Sheet \d\)).*',' $1'))" /> </xsl:co...
56,009,890
Authors of an xml document did not include all the text inside an element that will be converted to a hyperlink. I would like to process or pre-process the xml to include the necessary text. I find this hard to describe but a simple example should show what I'm attempting. I'm using XSLT 2.0. I already do regular expre...
2019/05/06
[ "https://Stackoverflow.com/questions/56009890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/107690/" ]
In order to reduce the use of regex functions, I would use this approach: ``` <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="glink...
The existing answer has the right approach but I would sharpen the regular expression pattern and the match patterns: ``` <xsl:param name="pattern" as="xs:string">\s\(Sheet \d\)</xsl:param> <xsl:variable name="pattern2" as="xs:string" select="'^' || $pattern"/> <xsl:variable name="pattern3" as="xs:string" selec...
64,026,529
I'm trying to accomplish a basic image processing. Here is my algorithm : Find n., n+1., n+2. pixel's RGB values in a row and create a new image from these values. [![Algorithm](https://i.stack.imgur.com/uFwT2.png)](https://i.stack.imgur.com/uFwT2.png) Here is my example code in python : ``` import glob import ntpa...
2020/09/23
[ "https://Stackoverflow.com/questions/64026529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14326860/" ]
Here is an approach: ``` import cv2 import numpy as np # Load input image im = cv2.imread('input.png') # Calculate new first layer - it is every 3rd pixel of the first layer of im n1 = im[:, ::3, 0] # Calculate new second layer - it is every 3rd pixel of the second layer of im, starting with an offset of 1 pixel n2...
As far as I understood from the question, you want to shift the pixel values of each channel of the input image in the output image. So, here is my approach. ``` im = cv2.cvtColor(cv2.imread('my_image.jpg'), cv2.COLOR_BGR2RGB) im = np.pad(im, [(3, 3),(3,3),(0,0)], mode='constant', constant_values=0) # Add padding for ...
62,281,696
I have been doing some googling but I can't really find a good python3 solution to my problem. Given the following HTML code, how do I extract 2019, 0.7 and 4.50% using python3? ``` <td rowspan='2' style='vertical-align:middle'>2019</td><td rowspan='2' style='vertical-align:middle;font-weight:bold;'>4.50%</td><td row...
2020/06/09
[ "https://Stackoverflow.com/questions/62281696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3702643/" ]
A solution using [`BeautifulSoup`](https://www.crummy.com/software/BeautifulSoup/bs4/doc/): ``` from bs4 import BeautifulSoup txt = '''<td rowspan='2' style='vertical-align:middle'>2019</td><td rowspan='2' style='vertical-align:middle;font-weight:bold;'>4.50%</td><td rowspan='2' style='vertical-align:middle;font-weig...
I think this might be helpful if does not exactly answer your question: ``` from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def handle_data(self, data): print(data) parser = MyHTMLParser() parser.feed("<Your HTML here>") ``` For your particular case this will return: 2019 4.50% SGD ...
58,736,295
I have the following `boto3` draft script ```py #!/usr/bin/env python3 import boto3 client = boto3.client('athena') BUCKETS='buckets.txt' DATABASE='some_db' QUERY_STR="""CREATE EXTERNAL TABLE IF NOT EXISTS some_db.{}( BucketOwner STRING, Bucket STRING, RequestDateTime STRING, Rem...
2019/11/06
[ "https://Stackoverflow.com/questions/58736295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2409793/" ]
First of all, `response` simply tells you that your request has been successfully submitted. Method `create_named_query()` creates a snippet of your query, which then can be seen/access in AWS Athena console in **Saved Queries** tab. [![enter image description here](https://i.stack.imgur.com/3rZ5I.png)](https://i.sta...
To reproduce your situation, I did the following: * In the Athena console, I ran: ```sql CREATE DATABASE foo ``` * In the Athena console, I selected `foo` in the Database drop-down * To start things simple, I ran this Python code: ```py import boto3 athena_client = boto3.client('athena', region_name='ap-southeast...
32,954,110
I have the following string in python: ``` foo = 'a_b_c' ``` How do I split the string into 2 parts: `'a_b'` and `'c'`? I.e, I want to split at the second `'_'` `str.split('_')` splits into 3 parts: `'a'`, `'b'` and `'c'`.
2015/10/05
[ "https://Stackoverflow.com/questions/32954110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/308827/" ]
Use the [`str.rsplit()` method](https://docs.python.org/2/library/stdtypes.html#str.rsplit) with a limit: ``` part1, part2 = foo.rsplit('_', 1) ``` `str.rsplit()` splits from the right-hand-side, and the limit (second argument) tells it to only split once. Alternatively, use [`str.rpartition()`](https://docs.python...
``` import re x = "a_b_c" print re.split(r"_(?!.*_)",x) ``` You can do it through `re`.Here in `re` with the use of `lookahead` we state that split by `_` after which there should not be `_`.
19,390,828
I am working on tree based program on python. I need to rewrite this function using recursion and liquidate all of these for-loops: Example of my function: ``` def items_on_level(full_tree, level): for key0, value0 in full_tree.items(): for key1, value1 in value0.items(): for key2, value2 in v...
2013/10/15
[ "https://Stackoverflow.com/questions/19390828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2863834/" ]
``` def itemsOnLevel(root, level): if not level: return list(root.keys()) else: return list(itertools.chain.from_iterable([itemsOnLevel(v, level-1) for k,v in root.items()])) ```
``` itemsOnLevel = lambda r, l: ( lambda f, r, l: f (f, r, l) ) ( lambda f, r, l: [_ for _ in r.keys () ] if not l else [i for k in r.values () for i in f (f, k, l - 1) ], r, l) ```
19,390,828
I am working on tree based program on python. I need to rewrite this function using recursion and liquidate all of these for-loops: Example of my function: ``` def items_on_level(full_tree, level): for key0, value0 in full_tree.items(): for key1, value1 in value0.items(): for key2, value2 in v...
2013/10/15
[ "https://Stackoverflow.com/questions/19390828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2863834/" ]
``` def itemsOnLevel(root, level): if not level: return list(root.keys()) else: return list(itertools.chain.from_iterable([itemsOnLevel(v, level-1) for k,v in root.items()])) ```
I guess this will help a bit ``` if(full_tree != {}): for node in return_list_current_level(full_tree): items_on_level(node, level+1) else: return None ```
19,390,828
I am working on tree based program on python. I need to rewrite this function using recursion and liquidate all of these for-loops: Example of my function: ``` def items_on_level(full_tree, level): for key0, value0 in full_tree.items(): for key1, value1 in value0.items(): for key2, value2 in v...
2013/10/15
[ "https://Stackoverflow.com/questions/19390828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2863834/" ]
``` def itemsOnLevel(root, level): if not level: return list(root.keys()) else: return list(itertools.chain.from_iterable([itemsOnLevel(v, level-1) for k,v in root.items()])) ```
``` def onl(r,l): if l: obj=[] for i in [onl(v,l-1) for v in r.values()]: obj.extend(i) return obj return r.keys() ```
19,390,828
I am working on tree based program on python. I need to rewrite this function using recursion and liquidate all of these for-loops: Example of my function: ``` def items_on_level(full_tree, level): for key0, value0 in full_tree.items(): for key1, value1 in value0.items(): for key2, value2 in v...
2013/10/15
[ "https://Stackoverflow.com/questions/19390828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2863834/" ]
``` itemsOnLevel = lambda r, l: ( lambda f, r, l: f (f, r, l) ) ( lambda f, r, l: [_ for _ in r.keys () ] if not l else [i for k in r.values () for i in f (f, k, l - 1) ], r, l) ```
I guess this will help a bit ``` if(full_tree != {}): for node in return_list_current_level(full_tree): items_on_level(node, level+1) else: return None ```
19,390,828
I am working on tree based program on python. I need to rewrite this function using recursion and liquidate all of these for-loops: Example of my function: ``` def items_on_level(full_tree, level): for key0, value0 in full_tree.items(): for key1, value1 in value0.items(): for key2, value2 in v...
2013/10/15
[ "https://Stackoverflow.com/questions/19390828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2863834/" ]
``` itemsOnLevel = lambda r, l: ( lambda f, r, l: f (f, r, l) ) ( lambda f, r, l: [_ for _ in r.keys () ] if not l else [i for k in r.values () for i in f (f, k, l - 1) ], r, l) ```
``` def onl(r,l): if l: obj=[] for i in [onl(v,l-1) for v in r.values()]: obj.extend(i) return obj return r.keys() ```
45,650,904
I am using celery to do a long-time task. The task will create a subprocess using `subprocess.Popen`. To make the task abortable, I write the code below: ``` from celery.contrib import abortable @task(bind=True, base=abortable.AbortableTask) def my_task(self, *args): p = subprocess.Popen([...]) while True: ...
2017/08/12
[ "https://Stackoverflow.com/questions/45650904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3278171/" ]
You are passing `Int` though the actual type required is `CustomSegmentedControl`. To simply solve this problem just create the `IBOutlet` for your `CustomSegmentedControl` and pass it as parameter to `Button_CustomSegmentValueChanged` method. ``` func SwipedRight(swipe : UISwipeGestureRecognizer){ if currentSelec...
Assuming your `CustomSegmentedControl` is a subclass of `UISegmentedControl`, I have modified few lines of code ``` @IBAction func button_CustomSegmentValueChanged(_ sender: UISegmentedControl?) { // guard sender for nil before use } ``` and when calling this ``` func swipedRight(swipe : UISwipeGestureRecogniz...
45,650,904
I am using celery to do a long-time task. The task will create a subprocess using `subprocess.Popen`. To make the task abortable, I write the code below: ``` from celery.contrib import abortable @task(bind=True, base=abortable.AbortableTask) def my_task(self, *args): p = subprocess.Popen([...]) while True: ...
2017/08/12
[ "https://Stackoverflow.com/questions/45650904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3278171/" ]
I would suggest to use the buttons array on CredentialSegmentedController to mimic the behaviour of change segment 1. Make an outlet from your custom segment control 2. Then modify your code using this segment control like below ``` func SwipedRight(swipe : UISwipeGestureRecognizer) { if currentSelectedV...
Assuming your `CustomSegmentedControl` is a subclass of `UISegmentedControl`, I have modified few lines of code ``` @IBAction func button_CustomSegmentValueChanged(_ sender: UISegmentedControl?) { // guard sender for nil before use } ``` and when calling this ``` func swipedRight(swipe : UISwipeGestureRecogniz...
1,081,698
I have a problem of upgrading python from 2.4 to 2.6: I have CentOS 5 (Full). It has python 2.4 living in /usr/lib/python2.4/ . Additional modules are living in /usr/lib/python2.4/site-packages/ . I've built python 2.6 from sources at /usr/local/lib/python2.6/ . I've set default python to python2.6 . Now old modules f...
2009/07/04
[ "https://Stackoverflow.com/questions/1081698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/133068/" ]
They are not broken, they are simply not installed. The solution to that is to install them under 2.6. But first we should see if you really should do that... Yes, Python will when installed replace the python command to the version installed (unless you run it with --alt-install). You don't exactly state what your pr...
There are a couple of options... 1. If the modules will run under Python 2.6, you can simply create symbolic links to them from the 2.6 site-packages directory to the 2.4 site-packages directory. 2. If they will not run under 2.6, then you may need to re-compile them against 2.6, or install up-to-date versions of them...
1,081,698
I have a problem of upgrading python from 2.4 to 2.6: I have CentOS 5 (Full). It has python 2.4 living in /usr/lib/python2.4/ . Additional modules are living in /usr/lib/python2.4/site-packages/ . I've built python 2.6 from sources at /usr/local/lib/python2.6/ . I've set default python to python2.6 . Now old modules f...
2009/07/04
[ "https://Stackoverflow.com/questions/1081698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/133068/" ]
They are not broken, they are simply not installed. The solution to that is to install them under 2.6. But first we should see if you really should do that... Yes, Python will when installed replace the python command to the version installed (unless you run it with --alt-install). You don't exactly state what your pr...
Some Python libs may be still not accessible as with Python 2.6 `site-packages` is changed to `dist-packages`. The only way in that case is to do move all stuff generated in site-packages (e.g. by `make install`) to dist-packages and create a sym-link.
1,081,698
I have a problem of upgrading python from 2.4 to 2.6: I have CentOS 5 (Full). It has python 2.4 living in /usr/lib/python2.4/ . Additional modules are living in /usr/lib/python2.4/site-packages/ . I've built python 2.6 from sources at /usr/local/lib/python2.6/ . I've set default python to python2.6 . Now old modules f...
2009/07/04
[ "https://Stackoverflow.com/questions/1081698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/133068/" ]
They are not broken, they are simply not installed. The solution to that is to install them under 2.6. But first we should see if you really should do that... Yes, Python will when installed replace the python command to the version installed (unless you run it with --alt-install). You don't exactly state what your pr...
easy\_install is good one but there are low level way for installing module, just: 1. unpack module source to some directory 2. type "python setup.py install" Of course you should do this with required installed python interpreter version; for checking it type: python -V
46,121,057
I'm new to bash and was tasked with scripting a check for a compliance process. From bash (or if python is better), I need to script an ssh connection from within the host running the script. For example: ssh -l testaccount localhost But I need to run this 52 times so that it is trapped by an IPS. When running this...
2017/09/08
[ "https://Stackoverflow.com/questions/46121057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8581142/" ]
In contrast to CSS, JS and HTML files which can be [gzipped using dispatcher](https://docs.adobe.com/content/docs/en/dispatcher/disp-config.html), images can be compressed only by reducing quality or resizing them. It is a quite common case for AEM projects and there are a couple of options to do that, some of them ar...
AEM offers options for "image optimisation" but this is a broad topic so there is no "magic" switch you can turn to "optimise" your images. It all boils down to the amount of kilo- or megabytes that are transferred from AEM to the users browser. The size of an asset is influenced by two things: 1. Asset dimension (wi...
46,121,057
I'm new to bash and was tasked with scripting a check for a compliance process. From bash (or if python is better), I need to script an ssh connection from within the host running the script. For example: ssh -l testaccount localhost But I need to run this 52 times so that it is trapped by an IPS. When running this...
2017/09/08
[ "https://Stackoverflow.com/questions/46121057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8581142/" ]
There are many ways to optimise Images in AEM. Here I will go through 3 of those ways. 1) Using DAM Update Asset Workflow. This is an out of the box workflow in AEM, Where on upload of images renditions get created . You can use those renditions path in img src attribute. 2) Using ACS commons Image transformer Inst...
AEM offers options for "image optimisation" but this is a broad topic so there is no "magic" switch you can turn to "optimise" your images. It all boils down to the amount of kilo- or megabytes that are transferred from AEM to the users browser. The size of an asset is influenced by two things: 1. Asset dimension (wi...
46,121,057
I'm new to bash and was tasked with scripting a check for a compliance process. From bash (or if python is better), I need to script an ssh connection from within the host running the script. For example: ssh -l testaccount localhost But I need to run this 52 times so that it is trapped by an IPS. When running this...
2017/09/08
[ "https://Stackoverflow.com/questions/46121057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8581142/" ]
In contrast to CSS, JS and HTML files which can be [gzipped using dispatcher](https://docs.adobe.com/content/docs/en/dispatcher/disp-config.html), images can be compressed only by reducing quality or resizing them. It is a quite common case for AEM projects and there are a couple of options to do that, some of them ar...
I had the same need, and I looked at ImageMagick too and researched various options. Ultimately I customized the workflows that we use to create our image renditions to integrate with another tool. I modified them to use the [Kraken.io](https://kraken.io/) API to automatically send the rendition images AEM produced to ...
46,121,057
I'm new to bash and was tasked with scripting a check for a compliance process. From bash (or if python is better), I need to script an ssh connection from within the host running the script. For example: ssh -l testaccount localhost But I need to run this 52 times so that it is trapped by an IPS. When running this...
2017/09/08
[ "https://Stackoverflow.com/questions/46121057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8581142/" ]
There are many ways to optimise Images in AEM. Here I will go through 3 of those ways. 1) Using DAM Update Asset Workflow. This is an out of the box workflow in AEM, Where on upload of images renditions get created . You can use those renditions path in img src attribute. 2) Using ACS commons Image transformer Inst...
I had the same need, and I looked at ImageMagick too and researched various options. Ultimately I customized the workflows that we use to create our image renditions to integrate with another tool. I modified them to use the [Kraken.io](https://kraken.io/) API to automatically send the rendition images AEM produced to ...
46,121,057
I'm new to bash and was tasked with scripting a check for a compliance process. From bash (or if python is better), I need to script an ssh connection from within the host running the script. For example: ssh -l testaccount localhost But I need to run this 52 times so that it is trapped by an IPS. When running this...
2017/09/08
[ "https://Stackoverflow.com/questions/46121057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8581142/" ]
In contrast to CSS, JS and HTML files which can be [gzipped using dispatcher](https://docs.adobe.com/content/docs/en/dispatcher/disp-config.html), images can be compressed only by reducing quality or resizing them. It is a quite common case for AEM projects and there are a couple of options to do that, some of them ar...
There are many ways to optimise Images in AEM. Here I will go through 3 of those ways. 1) Using DAM Update Asset Workflow. This is an out of the box workflow in AEM, Where on upload of images renditions get created . You can use those renditions path in img src attribute. 2) Using ACS commons Image transformer Inst...
60,751,007
I am trying to build a simple dictionary of all us english vs uk english differences for a web application I am working on. Is there a non-hacky way to build a dictionary where both the value and key can be looked up in python as efficiently as possible? I'd prefer not to loop through the dict by values for us spell...
2020/03/19
[ "https://Stackoverflow.com/questions/60751007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/872097/" ]
You have a raw `@JoinColumn` in `RolePrivilege`, change it, so that the name of the column is configured: `@JoinColumn(name = "roleId")`. Also you're saving `RolePrivilege`, but the changes are not cascading, change the mapping to: ``` @ManyToOne(cascade = CascadeType.ALL) ``` P.S.: Prefer `List`s over `Set`s in -t...
Firstly, do not return String(wrap it to class for example to `RolePriviligueResponse` with `String status` as response body), secondly you dont need `@ResponseBody` annotation, your `@PostMapping` annotation already has it, third - dont use `Integer` for ID, better use `Long` type. And you did not provide the name of ...
14,657,433
How do I calculate correlation matrix in python? I have an n-dimensional vector in which each element has 5 dimension. For example my vector looks like ``` [ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21] ] ``` In this case dimension of the vector ...
2013/02/02
[ "https://Stackoverflow.com/questions/14657433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1964587/" ]
Using [numpy](http://www.numpy.org/), you could use [np.corrcoef](http://docs.scipy.org/doc/numpy/reference/generated/numpy.corrcoef.html): ``` In [88]: import numpy as np In [89]: np.corrcoef([[0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) Out[89]: array([[ 1....
Here is a [pretty good example](http://www.tradinggeeks.net/2015/08/calculating-correlation-in-python/) of calculating a correlations matrix form multiple time series using Python. Included source code calculates correlation matrix for a set of Forex currency pairs using Pandas, NumPy, and matplotlib to produce a graph...
14,657,433
How do I calculate correlation matrix in python? I have an n-dimensional vector in which each element has 5 dimension. For example my vector looks like ``` [ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21] ] ``` In this case dimension of the vector ...
2013/02/02
[ "https://Stackoverflow.com/questions/14657433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1964587/" ]
Using [numpy](http://www.numpy.org/), you could use [np.corrcoef](http://docs.scipy.org/doc/numpy/reference/generated/numpy.corrcoef.html): ``` In [88]: import numpy as np In [89]: np.corrcoef([[0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) Out[89]: array([[ 1....
You can also use np.array if you don't want to write your matrix all over again. ``` import numpy as np a = np.array([ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) b = np.corrcoef(a) print b ```
14,657,433
How do I calculate correlation matrix in python? I have an n-dimensional vector in which each element has 5 dimension. For example my vector looks like ``` [ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21] ] ``` In this case dimension of the vector ...
2013/02/02
[ "https://Stackoverflow.com/questions/14657433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1964587/" ]
Using [numpy](http://www.numpy.org/), you could use [np.corrcoef](http://docs.scipy.org/doc/numpy/reference/generated/numpy.corrcoef.html): ``` In [88]: import numpy as np In [89]: np.corrcoef([[0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) Out[89]: array([[ 1....
As I almost missed that comment by @Anton Tarasenko, I'll provide a new answer. So given your array: ``` a = np.array([[0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) ``` If you want the correlation matrix of you...
14,657,433
How do I calculate correlation matrix in python? I have an n-dimensional vector in which each element has 5 dimension. For example my vector looks like ``` [ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21] ] ``` In this case dimension of the vector ...
2013/02/02
[ "https://Stackoverflow.com/questions/14657433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1964587/" ]
You can also use np.array if you don't want to write your matrix all over again. ``` import numpy as np a = np.array([ [0.1, .32, .2, 0.4, 0.8], [.23, .18, .56, .61, .12], [.9, .3, .6, .5, .3], [.34, .75, .91, .19, .21]]) b = np.corrcoef(a) print b ```
Here is a [pretty good example](http://www.tradinggeeks.net/2015/08/calculating-correlation-in-python/) of calculating a correlations matrix form multiple time series using Python. Included source code calculates correlation matrix for a set of Forex currency pairs using Pandas, NumPy, and matplotlib to produce a graph...