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
37,422,530
Working my way through a beginners Python book and there's two fairly simple things I don't understand, and was hoping someone here might be able to help. The example in the book uses regular expressions to take in email addresses and phone numbers from a clipboard and output them to the console. The code looks like ...
2016/05/24
[ "https://Stackoverflow.com/questions/37422530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5195054/" ]
every opening left `(` marks the beginning of a capture group, and you can nest them: ``` ( #[1] around whole pattern (\d{3}|\(\d{3}\))? #[2] area code (\s|-|\.)? #[3] separator (\d{3}) #[4] first 3 digits (\s|-|\.) ...
for the first part of your question see sweaver2112's answer for the second part, the both use lists and tuples. In Regex \d is the same as [0-9] it's just easier to write. in the same vein they could have written \w for [a-zA-Z] but that wouldn't account for special characters or 0-9 making it a little easier to put ...
14,074,149
I'm having a bit of difficulty figuring out what my next steps should be. I am using tastypie to create an API for my web application. From another application, specifically ifbyphone.com, I am receiving a POST with no headers that looks something like this: ``` post data:http://myapp.com/api/ callerid=1&someid=2&n...
2012/12/28
[ "https://Stackoverflow.com/questions/14074149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/170352/" ]
This worked as expected when I edited my resource model to actually use the serializer class I created. This was not clear in the documentation. ``` class urlencodeSerializer(Serializer): formats = ['json', 'jsonp', 'xml', 'yaml', 'html', 'plist', 'urlencode'] content_types = { 'json': 'application/js...
I would add a modification to the from\_urlencode mentioned in Brandon Bertelsen's post to work better with international characters: ``` def from_urlencode(self, data, options=None): """ handles basic formencoded url posts """ qs = {} for k, v in urlparse.parse_qs(data).iteritems(): value = v if l...
65,934,494
I have three boolean arrays: shift\_list, shift\_assignment, work。 shift\_list:rows represent shift, columns represent time. shift\_assignment:rows represent employee, columns represent shifts work: rows represent employee, columns represent time. **I want to change the value in work by changing the value in shi...
2021/01/28
[ "https://Stackoverflow.com/questions/65934494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13863269/" ]
thank to @Laurent Perron! ``` from ortools.sat.python import cp_model model = cp_model.CpModel() solver = cp_model.CpSolver() shift_list=[[1,1,1,0,0,0,0], [0,1,1,1,0,0,0], [0,0,1,1,1,0,0], [0,0,0,1,1,1,0], [0,0,0,0,1,1,1]] num_emp = 5 num_shift=5 num_time = 7 work={} ...
Basically you need a set of implications. looking only at the first worker: work = [w0, w1, w2, w3, w4, w5, w6] shift = [s0, s1, s2, s3, s4] ``` shift_list=[[1,1,1,0,0,0,0], [0,1,1,1,0,0,0], [0,0,1,1,1,0,0], [0,0,0,1,1,1,0], [0,0,0,0,1,1,1]] ``` so ``` w0 <=> s0 w1...
30,893,843
I've the same issue as asked by the OP in [How to import or include data structures (e.g. a dict) into a Python file from a separate file](https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a). However for some reason i'm unable to get it working. My...
2015/06/17
[ "https://Stackoverflow.com/questions/30893843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3149936/" ]
There are two ways you can access variable `TMP_DATA_FILE` in file `file1.py`: ``` import file1 var = 'a' print(file1.TMP_DATA_FILE[var]) ``` or: ``` from file1 import TMP_DATA_FILE var = 'a' print(TMP_DATA_FILE[var]) ``` `file1.py` is in a directory contained in the python search path, or in the same directory a...
You calling it the wrong way. It should be like this : ``` print file1.TMP_DATA_FILE[var] ```
30,893,843
I've the same issue as asked by the OP in [How to import or include data structures (e.g. a dict) into a Python file from a separate file](https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a). However for some reason i'm unable to get it working. My...
2015/06/17
[ "https://Stackoverflow.com/questions/30893843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3149936/" ]
If you have the `package`s created in your project, then you have to link the file from the main project. For example: If you have a folder `Z` which contains 2 folders `A` and `B` and those 2 files `file1.py` and `file2.py` are present in `A` and `B` folders, then you have to import it this way ``` import Z.A.fil...
You calling it the wrong way. It should be like this : ``` print file1.TMP_DATA_FILE[var] ```
30,893,843
I've the same issue as asked by the OP in [How to import or include data structures (e.g. a dict) into a Python file from a separate file](https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a). However for some reason i'm unable to get it working. My...
2015/06/17
[ "https://Stackoverflow.com/questions/30893843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3149936/" ]
There are two ways you can access variable `TMP_DATA_FILE` in file `file1.py`: ``` import file1 var = 'a' print(file1.TMP_DATA_FILE[var]) ``` or: ``` from file1 import TMP_DATA_FILE var = 'a' print(TMP_DATA_FILE[var]) ``` `file1.py` is in a directory contained in the python search path, or in the same directory a...
Correct variant: ``` import file1 var = 'a' print(file1.TMP_DATA_FILE[var]) ``` or ``` from file1 import TMP_DATA_FILE var = 'a' print(TMP_DATA_FILE[var]) ```
30,893,843
I've the same issue as asked by the OP in [How to import or include data structures (e.g. a dict) into a Python file from a separate file](https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a). However for some reason i'm unable to get it working. My...
2015/06/17
[ "https://Stackoverflow.com/questions/30893843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3149936/" ]
If you have the `package`s created in your project, then you have to link the file from the main project. For example: If you have a folder `Z` which contains 2 folders `A` and `B` and those 2 files `file1.py` and `file2.py` are present in `A` and `B` folders, then you have to import it this way ``` import Z.A.fil...
Correct variant: ``` import file1 var = 'a' print(file1.TMP_DATA_FILE[var]) ``` or ``` from file1 import TMP_DATA_FILE var = 'a' print(TMP_DATA_FILE[var]) ```
30,893,843
I've the same issue as asked by the OP in [How to import or include data structures (e.g. a dict) into a Python file from a separate file](https://stackoverflow.com/questions/2132985/how-to-import-or-include-data-structures-e-g-a-dict-into-a-python-file-from-a). However for some reason i'm unable to get it working. My...
2015/06/17
[ "https://Stackoverflow.com/questions/30893843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3149936/" ]
There are two ways you can access variable `TMP_DATA_FILE` in file `file1.py`: ``` import file1 var = 'a' print(file1.TMP_DATA_FILE[var]) ``` or: ``` from file1 import TMP_DATA_FILE var = 'a' print(TMP_DATA_FILE[var]) ``` `file1.py` is in a directory contained in the python search path, or in the same directory a...
If you have the `package`s created in your project, then you have to link the file from the main project. For example: If you have a folder `Z` which contains 2 folders `A` and `B` and those 2 files `file1.py` and `file2.py` are present in `A` and `B` folders, then you have to import it this way ``` import Z.A.fil...
60,992,072
I have a mini-program that can read text files and turn simple phrases into python code, it has Lexer, Parser, everything, I managed to make it play sound using "winsound" but for some reason, it plays the sound as long as the function does not return, this specific part in the code looks like this: ``` wins...
2020/04/02
[ "https://Stackoverflow.com/questions/60992072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12420682/" ]
Add `update` to your `ChangeNotifierProxyProvider` and change `build` to `create`. ``` ChangeNotifierProxyProvider<MyModel, MyChangeNotifier>( create: (_) => MyChangeNotifier(), update: (_, myModel, myNotifier) => myNotifier ..update(myModel), child: ... ); ``` See: <https://github.com/rrousselGit/provide...
You can use it like this: ``` ListView.builder( physics: NeverScrollableScrollPhysics(), scrollDirection: Axis.vertical, itemCount: rrr.length, itemBuilder: (ctx, index) => ChangeNotifierProvider.value( value: rrr[index], c...
16,903,936
How can I change the location of the .vim folder and the .vimrc file so that I can use two (or more) independent versions of vim? Is there a way to configure that while compiling vim from source? (maybe an entry in the feature.h?) Why do I want to do such a thing?: I have to work on project that use python2 as well as...
2013/06/03
[ "https://Stackoverflow.com/questions/16903936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2344834/" ]
You can influence which `~/.vimrc` is used via the `-u vimrc-file` command-line argument. Since this is the first initialization, you can then influence from where plugins are loaded (i.e. the `.vim` location) by modifying `'runtimepath'` in there. Note that for editing Python files of different versions, those settin...
I think the easiest solution would be just to let pathogen handle your runtimepath for you. `pathogen#infect()` can take paths that specify different directories that you can use for your bundle directory. So if your `.vim` directory would look like this ``` .vim/ autoload/ pathogen.vim bundle_pytho...
16,903,936
How can I change the location of the .vim folder and the .vimrc file so that I can use two (or more) independent versions of vim? Is there a way to configure that while compiling vim from source? (maybe an entry in the feature.h?) Why do I want to do such a thing?: I have to work on project that use python2 as well as...
2013/06/03
[ "https://Stackoverflow.com/questions/16903936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2344834/" ]
You can influence which `~/.vimrc` is used via the `-u vimrc-file` command-line argument. Since this is the first initialization, you can then influence from where plugins are loaded (i.e. the `.vim` location) by modifying `'runtimepath'` in there. Note that for editing Python files of different versions, those settin...
Note: I don't really recommend doing this. If you really really want to recompile vim so that it uses a different vimrc and different configuration directory take a look at `src/feature.h` Search this file for `USR_VIMRC_FILE`. Uncomment it and place the name of your vimrc here. This will change the defualt vimrc fi...
16,903,936
How can I change the location of the .vim folder and the .vimrc file so that I can use two (or more) independent versions of vim? Is there a way to configure that while compiling vim from source? (maybe an entry in the feature.h?) Why do I want to do such a thing?: I have to work on project that use python2 as well as...
2013/06/03
[ "https://Stackoverflow.com/questions/16903936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2344834/" ]
You can influence which `~/.vimrc` is used via the `-u vimrc-file` command-line argument. Since this is the first initialization, you can then influence from where plugins are loaded (i.e. the `.vim` location) by modifying `'runtimepath'` in there. Note that for editing Python files of different versions, those settin...
I found a way to do this! You can just create a fake $HOME, whose contents are simply the `.vim` folder and `.vimrc`. Then, when running vim, set the HOME environment variable to that folder, and change it back on `VimEnter`. Run vim with: ``` OLD_HOME="$HOME" HOME="$FAKE_HOME" vim ``` Add this to your `.vimrc`: `...
16,130,549
I've got an internet site running on tornado, with video features (convert, cut, merge). The video traitement is quite long, so i want to move it to another python process, and keep the tornado process as light as possible. I use the mongo db for commun db functionalities, synchronously as the db will stay light.
2013/04/21
[ "https://Stackoverflow.com/questions/16130549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1538095/" ]
There are several options: * [jQuery UI](http://jqueryui.com/) * [YUI](http://yuilibrary.com/) * [ninjaui](http://ninjaui.com/)
Use [kendo UI](http://www.kendoui.com/) Comprehensive HTML5/JavaScript framework for modern web and mobile app development Kendo UI is everything professional developers need to build HTML5 sites and mobile apps. Today, productivity of an average HTML/jQuery developer is hampered by assembling a Frankenstein framewo...
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
**Python 3.X** ``` myString.translate({ord('X'):'X\n'}) ``` `translate()` allows a dict, so, you can replace more than one different character at time. Why `translate()` over `replace()` ? Check [translate vs replace](https://stackoverflow.com/questions/31143290/python-str-translate-vs-str-replace) **Python 2.7**...
A list has no `split` method (as the error says). Assuming `myList` is a list of strings and you want to replace `'X'` with `'X\n'` in each once of them, you can use list comprehension: ``` new_list = [string.replace('X', 'X\n') for string in myList] ```
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
``` myString = '1X2X3X' print (myString.replace ('X', 'X\n')) ```
**Python 3.X** ``` myString.translate({ord('X'):'X\n'}) ``` `translate()` allows a dict, so, you can replace more than one different character at time. Why `translate()` over `replace()` ? Check [translate vs replace](https://stackoverflow.com/questions/31143290/python-str-translate-vs-str-replace) **Python 2.7**...
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
**Python 3.X** ``` myString.translate({ord('X'):'X\n'}) ``` `translate()` allows a dict, so, you can replace more than one different character at time. Why `translate()` over `replace()` ? Check [translate vs replace](https://stackoverflow.com/questions/31143290/python-str-translate-vs-str-replace) **Python 2.7**...
Based on your question details, it sounds like the most suitable is str.replace, as suggested by @DeepSpace. @levi's answer is also applicable, but could be a bit of a too big cannon to use. I add to those an even more powerful tool - regex, which is slower and harder to grasp, but in case this is not really "X" -> "X\...
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
``` myString = '1X2X3X' print (myString.replace ('X', 'X\n')) ```
A list has no `split` method (as the error says). Assuming `myList` is a list of strings and you want to replace `'X'` with `'X\n'` in each once of them, you can use list comprehension: ``` new_list = [string.replace('X', 'X\n') for string in myList] ```
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
You can simply replace X by "X\n" ``` myString.replace("X","X\n") ```
A list has no `split` method (as the error says). Assuming `myList` is a list of strings and you want to replace `'X'` with `'X\n'` in each once of them, you can use list comprehension: ``` new_list = [string.replace('X', 'X\n') for string in myList] ```
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
A list has no `split` method (as the error says). Assuming `myList` is a list of strings and you want to replace `'X'` with `'X\n'` in each once of them, you can use list comprehension: ``` new_list = [string.replace('X', 'X\n') for string in myList] ```
Based on your question details, it sounds like the most suitable is str.replace, as suggested by @DeepSpace. @levi's answer is also applicable, but could be a bit of a too big cannon to use. I add to those an even more powerful tool - regex, which is slower and harder to grasp, but in case this is not really "X" -> "X\...
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
``` myString = '1X2X3X' print (myString.replace ('X', 'X\n')) ```
You can simply replace X by "X\n" ``` myString.replace("X","X\n") ```
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
``` myString = '1X2X3X' print (myString.replace ('X', 'X\n')) ```
Based on your question details, it sounds like the most suitable is str.replace, as suggested by @DeepSpace. @levi's answer is also applicable, but could be a bit of a too big cannon to use. I add to those an even more powerful tool - regex, which is slower and harder to grasp, but in case this is not really "X" -> "X\...
38,888,714
What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error ``` for myItem in myList.split('X'): myString = myString.join(myItem.replace('X','X\n')) ```
2016/08/11
[ "https://Stackoverflow.com/questions/38888714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6284097/" ]
You can simply replace X by "X\n" ``` myString.replace("X","X\n") ```
Based on your question details, it sounds like the most suitable is str.replace, as suggested by @DeepSpace. @levi's answer is also applicable, but could be a bit of a too big cannon to use. I add to those an even more powerful tool - regex, which is slower and harder to grasp, but in case this is not really "X" -> "X\...
72,432,540
as you see "python --version show python3.10.4 but the interpreter show python 3.7.3 [![enter image description here](https://i.stack.imgur.com/RUqlc.png)](https://i.stack.imgur.com/RUqlc.png) how can i change the envirnment in vscode
2022/05/30
[ "https://Stackoverflow.com/questions/72432540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16776924/" ]
If you click on the interpreter version being used by VSCode, you should be able to select different versions across your device. [![Interpreter version](https://i.stack.imgur.com/6tWBe.png)](https://i.stack.imgur.com/6tWBe.png)
Selecting the interpreter in VSCode: <https://code.visualstudio.com/docs/python/environments#_work-with-python-interpreters> To run `streamlit` in `vscode`: Open the `launch.json` file of your project. Copy the following: ``` { "configurations": [ { "name": "Python:Streamlit", "t...
72,432,540
as you see "python --version show python3.10.4 but the interpreter show python 3.7.3 [![enter image description here](https://i.stack.imgur.com/RUqlc.png)](https://i.stack.imgur.com/RUqlc.png) how can i change the envirnment in vscode
2022/05/30
[ "https://Stackoverflow.com/questions/72432540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16776924/" ]
If you click on the interpreter version being used by VSCode, you should be able to select different versions across your device. [![Interpreter version](https://i.stack.imgur.com/6tWBe.png)](https://i.stack.imgur.com/6tWBe.png)
Adding the following line to your setting.json (crtl+shift+P "preferences: open settings(JSON)"). ``` "terminal.integrated.env.osx": { "PATH": "" } ```
70,971,382
I want to compare two files and display the differences and the missing records in both files. Based on suggestions on this forum, I found awk is the fastest way to do it. Comparison is to be done based on composite key - match\_key and issuer\_grid\_id **Code:** ``` BEGIN { FS="[= ]" } { match(" "$0,/ match_key...
2022/02/03
[ "https://Stackoverflow.com/questions/70971382", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17742463/" ]
Just tweak the setting of `key` at the top to use whatever set of fields you want, and the printing of the mismatch message to be `from key ... key` instead of `from line ... FNR`: ``` $ cat tst.awk BEGIN { FS="[= ]" } { match(" "$0,/ issuer_grid_id="[^"]+"/) key = substr($0,RSTART,RLENGTH) match(" "$0,/ m...
You can use ruby sets: ``` $ cat tst.rb def f2h(fn) data={} File.open(fn){|fh| fh. each_line{|line| h=line.scan(/(\w+)="([^"]+)"/).to_h k=h.slice("issuer_grid_id", "match_key"). map{|k,v| "#{k}=#{v}"}.join(", ") data[k]=h} } data end f1=f2h(ARGV[0]) f2=f2h(...
72,337,348
I would like to get all text separated by double quotes and commas using python Beautifulsoup. The sample has no class or ids. Could use the div with "Information:" for parent like this: ``` try: test_var = soup.find(text='Information:').find_next('ul').find_next('li') for ...
2022/05/22
[ "https://Stackoverflow.com/questions/72337348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2615887/" ]
Just use the [:not](https://api.jquery.com/not-selector/) selector like this: ```js $('.one:not([data-id="two"])').on('click', function() { $('.A').show(); }); $("[data-id='two'].one").on('click', function() { $('.B').show(); }); ``` ```css .one {width: 50px;margin: 10px;padding: 10px 0;text-align: center;outline...
Change it to accept one or the other when any `$('.one')` is clicked: ``` $('.one').on('click', function() { if ($(this).data('id')) { $('.B').show(); } else { $('.A').show(); } }); ``` ```js if ($(this).data('id')) {... // if the `data-id` has a value ex. "2", then it is true ``` ```js $('.one').on(...
72,337,348
I would like to get all text separated by double quotes and commas using python Beautifulsoup. The sample has no class or ids. Could use the div with "Information:" for parent like this: ``` try: test_var = soup.find(text='Information:').find_next('ul').find_next('li') for ...
2022/05/22
[ "https://Stackoverflow.com/questions/72337348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2615887/" ]
Change it to accept one or the other when any `$('.one')` is clicked: ``` $('.one').on('click', function() { if ($(this).data('id')) { $('.B').show(); } else { $('.A').show(); } }); ``` ```js if ($(this).data('id')) {... // if the `data-id` has a value ex. "2", then it is true ``` ```js $('.one').on(...
JQuery selector equals to `querySelectorAll`, while `querySelector` selects only the first element it finds: ```js document.querySelector(".one").onclick = function() { $('.A').show(); } $("[data-id='two'].one").on('click', function() { $('.B').show(); }); ``` ```css .one { width: 50px; margin: 10px; paddin...
72,337,348
I would like to get all text separated by double quotes and commas using python Beautifulsoup. The sample has no class or ids. Could use the div with "Information:" for parent like this: ``` try: test_var = soup.find(text='Information:').find_next('ul').find_next('li') for ...
2022/05/22
[ "https://Stackoverflow.com/questions/72337348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2615887/" ]
Just use the [:not](https://api.jquery.com/not-selector/) selector like this: ```js $('.one:not([data-id="two"])').on('click', function() { $('.A').show(); }); $("[data-id='two'].one").on('click', function() { $('.B').show(); }); ``` ```css .one {width: 50px;margin: 10px;padding: 10px 0;text-align: center;outline...
JQuery selector equals to `querySelectorAll`, while `querySelector` selects only the first element it finds: ```js document.querySelector(".one").onclick = function() { $('.A').show(); } $("[data-id='two'].one").on('click', function() { $('.B').show(); }); ``` ```css .one { width: 50px; margin: 10px; paddin...
67,018,079
I have probem with this code , why ? the code : ``` import cv2 import numpy as np from PIL import Image import os import numpy as np import cv2 import os import h5py import dlib from imutils import face_utils from keras.models import load_model import sys from keras.models import Sequential from keras.layers import C...
2021/04/09
[ "https://Stackoverflow.com/questions/67018079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15558831/" ]
**Keras** is now fully intregrated into **Tensorflow**. So, importing only **Keras** causes error. It should be imported as: ``` from tensorflow.keras.utils import to_categorical ``` **Avoid** importing as: ``` from keras.utils import to_categorical ``` It is safe to use `from tensorflow.keras.` instead of `from...
First thing is you can install this `keras.utils` with ``` $!pip install keras.utils ``` or another simple method just import `to_categorical` module as ``` $ tensorflow.keras.utils import to_categorical ``` because keras comes under tensorflow package
67,018,079
I have probem with this code , why ? the code : ``` import cv2 import numpy as np from PIL import Image import os import numpy as np import cv2 import os import h5py import dlib from imutils import face_utils from keras.models import load_model import sys from keras.models import Sequential from keras.layers import C...
2021/04/09
[ "https://Stackoverflow.com/questions/67018079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15558831/" ]
**Keras** is now fully intregrated into **Tensorflow**. So, importing only **Keras** causes error. It should be imported as: ``` from tensorflow.keras.utils import to_categorical ``` **Avoid** importing as: ``` from keras.utils import to_categorical ``` It is safe to use `from tensorflow.keras.` instead of `from...
Alternatively, you can use: `from keras.utils.np_utils import to_categorical` Please note the **np\_utils** after **keras.uitls**
67,018,079
I have probem with this code , why ? the code : ``` import cv2 import numpy as np from PIL import Image import os import numpy as np import cv2 import os import h5py import dlib from imutils import face_utils from keras.models import load_model import sys from keras.models import Sequential from keras.layers import C...
2021/04/09
[ "https://Stackoverflow.com/questions/67018079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15558831/" ]
**Keras** is now fully intregrated into **Tensorflow**. So, importing only **Keras** causes error. It should be imported as: ``` from tensorflow.keras.utils import to_categorical ``` **Avoid** importing as: ``` from keras.utils import to_categorical ``` It is safe to use `from tensorflow.keras.` instead of `from...
``` y_train = tensorflow.keras.utils.to_categorical(y_train, num_classes) y_test = tensorflow.keras.utils.to_categorical(y_test, num_classes) ``` It solves my problem!
67,018,079
I have probem with this code , why ? the code : ``` import cv2 import numpy as np from PIL import Image import os import numpy as np import cv2 import os import h5py import dlib from imutils import face_utils from keras.models import load_model import sys from keras.models import Sequential from keras.layers import C...
2021/04/09
[ "https://Stackoverflow.com/questions/67018079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15558831/" ]
Alternatively, you can use: `from keras.utils.np_utils import to_categorical` Please note the **np\_utils** after **keras.uitls**
First thing is you can install this `keras.utils` with ``` $!pip install keras.utils ``` or another simple method just import `to_categorical` module as ``` $ tensorflow.keras.utils import to_categorical ``` because keras comes under tensorflow package
67,018,079
I have probem with this code , why ? the code : ``` import cv2 import numpy as np from PIL import Image import os import numpy as np import cv2 import os import h5py import dlib from imutils import face_utils from keras.models import load_model import sys from keras.models import Sequential from keras.layers import C...
2021/04/09
[ "https://Stackoverflow.com/questions/67018079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15558831/" ]
Alternatively, you can use: `from keras.utils.np_utils import to_categorical` Please note the **np\_utils** after **keras.uitls**
``` y_train = tensorflow.keras.utils.to_categorical(y_train, num_classes) y_test = tensorflow.keras.utils.to_categorical(y_test, num_classes) ``` It solves my problem!
4,424,004
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), wha...
2010/12/12
[ "https://Stackoverflow.com/questions/4424004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/530877/" ]
``` bool perfectNumber(number); ``` This does not call the `perfectNumber` function; it declares a local variable named `perfectNumber` of type `bool` and initializes it with the value of `number` converted to type `bool`. In order to call the `perfectNumber` function, you need to use something along the lines of: ...
``` void primenum(long double x) { bool prime = true; int number2; number2 = (int) floor(sqrt(x));// Calculates the square-root of 'x' for (int i = 1; i <= x; i++) { for (int j = 2; j <= number2; j++) { if (i != j && i % j == 0) { prime = false; brea...
4,424,004
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), wha...
2010/12/12
[ "https://Stackoverflow.com/questions/4424004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/530877/" ]
``` bool perfectNumber(number); ``` This does not call the `perfectNumber` function; it declares a local variable named `perfectNumber` of type `bool` and initializes it with the value of `number` converted to type `bool`. In order to call the `perfectNumber` function, you need to use something along the lines of: ...
``` #pragma hdrstop #include <tchar.h> #include <stdio.h> #include <conio.h> //--------------------------------------------------------------------------- bool is_prim(int nr) { for (int i = 2; i < nr-1; i++) { if (nr%i==0) return false; } return true; } bool is_ptr(int nr) { int sum=0; ...
4,424,004
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), wha...
2010/12/12
[ "https://Stackoverflow.com/questions/4424004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/530877/" ]
``` bool perfectNumber(number); ``` This does not call the `perfectNumber` function; it declares a local variable named `perfectNumber` of type `bool` and initializes it with the value of `number` converted to type `bool`. In order to call the `perfectNumber` function, you need to use something along the lines of: ...
``` bool isPerfect( int number){ int i; int sum=0; for(i=1;i<number ;i++){ if(number %i == 0){ cout<<" " << i ; sum+=i; } } if (sum == number){ cout<<"\n \t\t THIS NUMBER >>> "<< number <<" IS PERFECT \n\n"; return i; ...
4,424,004
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), wha...
2010/12/12
[ "https://Stackoverflow.com/questions/4424004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/530877/" ]
``` void primenum(long double x) { bool prime = true; int number2; number2 = (int) floor(sqrt(x));// Calculates the square-root of 'x' for (int i = 1; i <= x; i++) { for (int j = 2; j <= number2; j++) { if (i != j && i % j == 0) { prime = false; brea...
``` #pragma hdrstop #include <tchar.h> #include <stdio.h> #include <conio.h> //--------------------------------------------------------------------------- bool is_prim(int nr) { for (int i = 2; i < nr-1; i++) { if (nr%i==0) return false; } return true; } bool is_ptr(int nr) { int sum=0; ...
4,424,004
I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), wha...
2010/12/12
[ "https://Stackoverflow.com/questions/4424004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/530877/" ]
``` bool isPerfect( int number){ int i; int sum=0; for(i=1;i<number ;i++){ if(number %i == 0){ cout<<" " << i ; sum+=i; } } if (sum == number){ cout<<"\n \t\t THIS NUMBER >>> "<< number <<" IS PERFECT \n\n"; return i; ...
``` #pragma hdrstop #include <tchar.h> #include <stdio.h> #include <conio.h> //--------------------------------------------------------------------------- bool is_prim(int nr) { for (int i = 2; i < nr-1; i++) { if (nr%i==0) return false; } return true; } bool is_ptr(int nr) { int sum=0; ...
66,413,002
I'm attempting to translate the following curl request to something that will run in django. ``` curl -X POST https://api.lemlist.com/api/hooks --data '{"targetUrl":"https://example.com/lemlist-hook"}' --header "Content-Type: application/json" --user ":1234567980abcedf" ``` I've run this in git bash and it returns t...
2021/02/28
[ "https://Stackoverflow.com/questions/66413002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7609684/" ]
One way you can do this at the *word* level is: ``` select t.* from t cross apply (select count(*) as cnt from string_split(t.text, ' ') s1 cross join string_split(@sentence, ' ') s2 on s1.value = s2.value ) ss order by ss.cnt desc; ``` Notes: * This only looks for exact word m...
There's a lot of way two select item. For example: ``` SELECT 'I want to buy a ' + A.BrandName + ' cellphone and the model should be ' + A.ModelName FROM ( SELECT SUBSTRING(TEXT, 1, LEN('sumsung')) AS BrandName , SUBSTRING(TEXT, LEN(SUBSTRING(TEXT, 1, LEN('sumsung')))+1, LEN(TEXT)) AS ModelName FROM T...
66,755,583
I've tried all the installing methods in geopandas' [documentation](https://geopandas.org/getting_started/install.html) and nothing works. `conda install geopandas` gives ``` UnsatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Availab...
2021/03/23
[ "https://Stackoverflow.com/questions/66755583", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13083530/" ]
@duckboycool and @Ken Y-N are right, downgrading to Python 3.7 did the trick! Downgrading with conda `conda install python=3.7` and then `conda install geopandas`
You need to create an environment initially, Then inside the new environment try to install Geopandas: ```none 1- conda create -n geo_env 2- conda activate geo_env 3- conda config --env --add channels conda-forge 4- conda config --env --set channel_priority strict 5- conda install python=3 geopandas ``` and followin...
66,755,583
I've tried all the installing methods in geopandas' [documentation](https://geopandas.org/getting_started/install.html) and nothing works. `conda install geopandas` gives ``` UnsatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Availab...
2021/03/23
[ "https://Stackoverflow.com/questions/66755583", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13083530/" ]
@duckboycool and @Ken Y-N are right, downgrading to Python 3.7 did the trick! Downgrading with conda `conda install python=3.7` and then `conda install geopandas`
I found that the following works. I first tried conda install geopandas in the base environment, and that didn't work. Several times. I created a new environment in Anaconda Navigator, activated my new environment and repeated conda install geopandas, and tried installing geopandas from the Navigator and that failed to...
66,755,583
I've tried all the installing methods in geopandas' [documentation](https://geopandas.org/getting_started/install.html) and nothing works. `conda install geopandas` gives ``` UnsatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Availab...
2021/03/23
[ "https://Stackoverflow.com/questions/66755583", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13083530/" ]
I found that the following works. I first tried conda install geopandas in the base environment, and that didn't work. Several times. I created a new environment in Anaconda Navigator, activated my new environment and repeated conda install geopandas, and tried installing geopandas from the Navigator and that failed to...
You need to create an environment initially, Then inside the new environment try to install Geopandas: ```none 1- conda create -n geo_env 2- conda activate geo_env 3- conda config --env --add channels conda-forge 4- conda config --env --set channel_priority strict 5- conda install python=3 geopandas ``` and followin...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
Freesurfer segments and annotates the brain in the patient's native space, resulting in patient-specific regions, like [so](http://dl.dropbox.com/u/2467665/freesurfer_segmentation.png). I'm not sure what you mean by patching, or to what other images you'd like to apply this transformation, but it seems like the softw...
I think [ITK](http://www.itk.org/) is made for this kind if purpose. A Python wrapper exists ([Paul Novotny](http://www.paulnovo.org/) distributes binaries for Ubuntu on his site), but this is mainly C++. If you work under Linux then it is quite simple to compile if you are familiar with cmake. As this toolkit is a ve...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
Freesurfer segments and annotates the brain in the patient's native space, resulting in patient-specific regions, like [so](http://dl.dropbox.com/u/2467665/freesurfer_segmentation.png). I'm not sure what you mean by patching, or to what other images you'd like to apply this transformation, but it seems like the softw...
Along SPM's lines, you can use [IBSPM](http://www.thomaskoenig.ch/Lester/ibaspm.htm). It was developed to solve exactly that problem.
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
Freesurfer segments and annotates the brain in the patient's native space, resulting in patient-specific regions, like [so](http://dl.dropbox.com/u/2467665/freesurfer_segmentation.png). I'm not sure what you mean by patching, or to what other images you'd like to apply this transformation, but it seems like the softw...
You can use ANTs software, or u can use Python within 3dSclicer for template registration. However, I did mane template registration in SPM and I recommend it for fMRI data better than ITK or Slicer. I found these links very helpful :) let me know if you need more help. <https://fmri-training-course.psych.lsa.umich...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
There is a bulk of tools for image registration, e.g. look at <http://www.nitrc.org> under "Spatial transformation" -> "Registration". Nipype is indeed a nice Python module which wraps many of those (e.g. FSL, Freesurfer, etc) so you could explore different available tools within somewhat unified interface. Besides th...
I think [ITK](http://www.itk.org/) is made for this kind if purpose. A Python wrapper exists ([Paul Novotny](http://www.paulnovo.org/) distributes binaries for Ubuntu on his site), but this is mainly C++. If you work under Linux then it is quite simple to compile if you are familiar with cmake. As this toolkit is a ve...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
I think [ITK](http://www.itk.org/) is made for this kind if purpose. A Python wrapper exists ([Paul Novotny](http://www.paulnovo.org/) distributes binaries for Ubuntu on his site), but this is mainly C++. If you work under Linux then it is quite simple to compile if you are familiar with cmake. As this toolkit is a ve...
You can use ANTs software, or u can use Python within 3dSclicer for template registration. However, I did mane template registration in SPM and I recommend it for fMRI data better than ITK or Slicer. I found these links very helpful :) let me know if you need more help. <https://fmri-training-course.psych.lsa.umich...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
There is a bulk of tools for image registration, e.g. look at <http://www.nitrc.org> under "Spatial transformation" -> "Registration". Nipype is indeed a nice Python module which wraps many of those (e.g. FSL, Freesurfer, etc) so you could explore different available tools within somewhat unified interface. Besides th...
Along SPM's lines, you can use [IBSPM](http://www.thomaskoenig.ch/Lester/ibaspm.htm). It was developed to solve exactly that problem.
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
There is a bulk of tools for image registration, e.g. look at <http://www.nitrc.org> under "Spatial transformation" -> "Registration". Nipype is indeed a nice Python module which wraps many of those (e.g. FSL, Freesurfer, etc) so you could explore different available tools within somewhat unified interface. Besides th...
You can use ANTs software, or u can use Python within 3dSclicer for template registration. However, I did mane template registration in SPM and I recommend it for fMRI data better than ITK or Slicer. I found these links very helpful :) let me know if you need more help. <https://fmri-training-course.psych.lsa.umich...
6,767,990
So, I use [SPM](http://www.fil.ion.ucl.ac.uk/spm/) to register fMRI brain images between the same patient; however, I am having trouble registering images between patients. Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warpi...
2011/07/20
[ "https://Stackoverflow.com/questions/6767990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402632/" ]
Along SPM's lines, you can use [IBSPM](http://www.thomaskoenig.ch/Lester/ibaspm.htm). It was developed to solve exactly that problem.
You can use ANTs software, or u can use Python within 3dSclicer for template registration. However, I did mane template registration in SPM and I recommend it for fMRI data better than ITK or Slicer. I found these links very helpful :) let me know if you need more help. <https://fmri-training-course.psych.lsa.umich...
23,533,566
I want to use /etc/sudoers to change the owner of a file from bangtest(user) to root. Reason to change: when I uploaded an image from bangtest(user) to my server using Django application then image file permission are like ``` ls -l /home/bangtest/alpha/media/products/image_2093.jpg -rw-r--r-- 1 bangtest bangtest 2...
2014/05/08
[ "https://Stackoverflow.com/questions/23533566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2479352/" ]
I strongly suggest you use a browser such as Firefox with Firebug installed. Load any page, hit Tools > Web Developer > Inspector (or its hot key equivalent), then click on your object, the HTML code inspector will reference the exact line of the css file that is governing the style being generated (either the style d...
After several attempts and some help from Zurb support the CSS i needed was: ``` .top-bar-section .dropdown li:not(.has-form) a:not(.button) { color: white; background: #740707; } ``` Thanks for the help
23,533,566
I want to use /etc/sudoers to change the owner of a file from bangtest(user) to root. Reason to change: when I uploaded an image from bangtest(user) to my server using Django application then image file permission are like ``` ls -l /home/bangtest/alpha/media/products/image_2093.jpg -rw-r--r-- 1 bangtest bangtest 2...
2014/05/08
[ "https://Stackoverflow.com/questions/23533566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2479352/" ]
I strongly suggest you use a browser such as Firefox with Firebug installed. Load any page, hit Tools > Web Developer > Inspector (or its hot key equivalent), then click on your object, the HTML code inspector will reference the exact line of the css file that is governing the style being generated (either the style d...
If you use the SCSS/SASS version of foundation you should change the defaultvalues for the topbar. The defaultsettings are stored in `_settings.scss`. For example to change it to cornflowerblue I used these settings: ``` $topbar-bg-color: cornflowerblue; $topbar-bg: $topbar-bg-color; $topbar-link-bg-hover: scale-co...
23,533,566
I want to use /etc/sudoers to change the owner of a file from bangtest(user) to root. Reason to change: when I uploaded an image from bangtest(user) to my server using Django application then image file permission are like ``` ls -l /home/bangtest/alpha/media/products/image_2093.jpg -rw-r--r-- 1 bangtest bangtest 2...
2014/05/08
[ "https://Stackoverflow.com/questions/23533566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2479352/" ]
After several attempts and some help from Zurb support the CSS i needed was: ``` .top-bar-section .dropdown li:not(.has-form) a:not(.button) { color: white; background: #740707; } ``` Thanks for the help
If you use the SCSS/SASS version of foundation you should change the defaultvalues for the topbar. The defaultsettings are stored in `_settings.scss`. For example to change it to cornflowerblue I used these settings: ``` $topbar-bg-color: cornflowerblue; $topbar-bg: $topbar-bg-color; $topbar-link-bg-hover: scale-co...
60,103,642
I already know how to open windows command prompt through python, but I was wondering how if there is a way to open a windows powershellx86 window and run commands through python 3.7 on windows 10?
2020/02/06
[ "https://Stackoverflow.com/questions/60103642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can just call out to powershell.exe using `subprocess.run` ``` import subprocess subprocess.run('powershell.exe Get-Item *') ```
If you know how to run the command prompt (CMD.EXE) then you should be able to use the same method to run PowerShell (PowerShell.EXE). PowerShell.EXE is located in c:\windows\system32\windowspowershell\v1.0\ by default. To run the shell with commands use: ``` c:\windows\system32\windowspowershell\v1.0\PowerShell.exe -...
49,411,277
I'm using Python to automate some reporting, but I am stuck trying to connect to an SSAS cube. I am on Windows 7 using Anaconda 4.4, and I am unable to install any libraries beyond those included in Anaconda. I have used pyodbc+pandas to connect to SQL Server databases and extract data with SQL queries, and the goal n...
2018/03/21
[ "https://Stackoverflow.com/questions/49411277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9529670/" ]
SSAS doesn't support [ODBC clients](https://learn.microsoft.com/en-us/sql/analysis-services/instances/data-providers-used-for-analysis-services-connections) . It does provide HTTP access through IIS, which requires [a few configuration steps](https://learn.microsoft.com/en-us/sql/analysis-services/instances/configure-h...
Perhaps this solution will help you <https://stackoverflow.com/a/65434789/14872543> the idea is to use the construct on linced MSSQL Server ``` SELECT olap.* from OpenRowset ('"+ olap_conn_string+"',' " + mdx_string +"') "+ 'as olap' ```
49,411,277
I'm using Python to automate some reporting, but I am stuck trying to connect to an SSAS cube. I am on Windows 7 using Anaconda 4.4, and I am unable to install any libraries beyond those included in Anaconda. I have used pyodbc+pandas to connect to SQL Server databases and extract data with SQL queries, and the goal n...
2018/03/21
[ "https://Stackoverflow.com/questions/49411277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9529670/" ]
SSAS doesn't support [ODBC clients](https://learn.microsoft.com/en-us/sql/analysis-services/instances/data-providers-used-for-analysis-services-connections) . It does provide HTTP access through IIS, which requires [a few configuration steps](https://learn.microsoft.com/en-us/sql/analysis-services/instances/configure-h...
The Pyadomd package might help you with your problem: [Pyadomd](https://github.com/S-C-O-U-T/Pyadomd) It is not tested on Windows 7, but I would expect it to work fine :-)
65,605,972
Before downgrading my GCC, I want to know if there's a way to figure which programs/frameworks or dependencies in my machine will break and if there is a better way to do this for openpose installation? (e.g. changing something in CMake) Is there a hack to fix this without changing my system GCC version and potentiall...
2021/01/07
[ "https://Stackoverflow.com/questions/65605972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
Solved by downgrading the GCC from 9.3.0 to 7: ``` $ sudo apt remove gcc $ sudo apt-get install gcc-7 g++-7 -y $ sudo ln -s /usr/bin/gcc-7 /usr/bin/gcc $ sudo ln -s /usr/bin/g++-7 /usr/bin/g++ $ sudo ln -s /usr/bin/gcc-7 /usr/bin/cc $ sudo ln -s /usr/bin/g++-7 /usr/bin/c++ $ gcc --version gcc (Ubuntu 7.5.0-6ubuntu2) 7...
You should point to a correct GCC bin file (below 9) from the dependencies in cmake command. no need to downgrade the GCC for example: ``` cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 ```
53,369,766
Following the [Microsoft Azure documentation for Python developers](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.models.blob?view=azure-python). The `azure.storage.blob.models.Blob` class does have a private method called `__sizeof__()`. But it returns a constant value of 16, wheth...
2018/11/19
[ "https://Stackoverflow.com/questions/53369766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2604247/" ]
> > I want to have an additional check on the size to judge whether I am dealing with an empty blob. > > > We could use the [BlobProperties().content\_length](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.models.blobproperties?view=azure-python) to check whether it is a empty b...
``` from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient.from_connection_string(connect_str) blob_list = blob_service_client.get_container_client(my_container).list_blobs() for blob in blob_list: print("\t" + blob.name) print('\tsize=', blob.size) ```
39,981,667
I installed Robotframework RIDE with my user credentials and trying to access that by logging in with the another user in the same machine. when i copy paste the ride.py(available in C:/Python27/Scripts) file from my user to another user i can access RIDE by double clicking the ride.py file, but when i try to access us...
2016/10/11
[ "https://Stackoverflow.com/questions/39981667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5295988/" ]
I'm using gem [breadcrumbs on rails](https://github.com/weppos/breadcrumbs_on_rails) with devise in my project. If you haven't made User model with devise make that first: ``` rails g devise User rake db:migrate rails generate devise:views users ``` My registration\_controller.rb looks like this: ``` # app/control...
You can generate the devise views with: `rails generate devise:views users` Make sure to replace `users` with whatever your user model name is if it isn't `User` (e.g. `Admin`, `Manager`, etc) You can then add to those views whatever you need to show breadcrumbs.
14,672,640
I am trying to use python-twitter api in GAE. I need to import Oauth2 and httplib2. Here is how I did For OAuth2, I downloaded github.com/simplegeo/python-oauth2/tree/master/oauth2. For HTTPLib2, I dowloaded code.google.com/p/httplib2/wiki/Install and extracted folder python2/httplib2 to project root folder. my v...
2013/02/03
[ "https://Stackoverflow.com/questions/14672640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/496837/" ]
``` ‘%A%’; ``` v.s. ``` '%A%'; ``` The first has fancy `'` characters. The usual cause for that is Outlook's AutoCorrect.
Problem with the 1st is the single quote. `SQL` doesn't accept that quote. I dont find the one in my keyboard. May be you copied the query from somewhere.
14,672,640
I am trying to use python-twitter api in GAE. I need to import Oauth2 and httplib2. Here is how I did For OAuth2, I downloaded github.com/simplegeo/python-oauth2/tree/master/oauth2. For HTTPLib2, I dowloaded code.google.com/p/httplib2/wiki/Install and extracted folder python2/httplib2 to project root folder. my v...
2013/02/03
[ "https://Stackoverflow.com/questions/14672640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/496837/" ]
``` ‘%A%’; ``` v.s. ``` '%A%'; ``` The first has fancy `'` characters. The usual cause for that is Outlook's AutoCorrect.
You have used `‘%A%’`. SQL doesn't accept this character - this should be `'%A%'`. I could not find this in my keyboard.
53,241,645
In Python 3.6, I can use the `__set_name__` hook to get the class attribute name of a descriptor. How can I achieve this in python 2.x? This is the code which works fine in Python 3.6: ``` class IntField: def __get__(self, instance, owner): if instance is None: return self return inst...
2018/11/10
[ "https://Stackoverflow.com/questions/53241645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5766927/" ]
You may be looking for metaclasses, with it you can process the class attributes at class creation time. ``` class FooDescriptor(object): def __get__(self, obj, objtype): print('calling getter') class FooMeta(type): def __init__(cls, name, bases, attrs): for k, v in attrs.iteritems(): ...
There are various solutions with different degrees of hackishness. I always liked to use a class decorator for this. ``` class IntField(object): def __get__(self, instance, owner): if instance is None: return self return instance.__dict__[self.name] def __set__(self, in...
41,595,720
I am about to upgrade from Django 1.9 to 1.10 and would like to test if I have some deprecated functionality. However using ``` python -Wall manage.py test ``` will show tons and tons of warnings for Django 2.0. Is there a way to suppress warnings only for 2.0 or show only warnings for 1.10?
2017/01/11
[ "https://Stackoverflow.com/questions/41595720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5047630/" ]
**Solution 1 - Using groups** ``` Private Sub Workbook_Open() With Sheet1 Dim i As Long, varLast As Long .Cells.ClearOutline varLast = .Cells(.Rows.Count, "A").End(xlUp).Row .Columns("A:A").Insert Shift:=xlToRight 'helper column For i = 1 To varLast .Range("A" ...
One possibility would be to add a button to each cell and to hide its children rows on *collapse* and display its children rows on *expand*. Each `Excel.Button` executes one common method `TreeNodeClick` where the `Click` method is called on corresponding instance of `TreeNode`. The child rows are hidden or displayed...
39,469,409
I've just created Django project and ran the server. It works fine but showed me warnings like ``` You have 14 unapplied migration(s)... ``` Then I ran ``` python manage.py migrate ``` in the terminal. It worked but showed me this ``` ?: (1_7.W001) MIDDLEWARE_CLASSES is not set. HINT: Django 1.7 changed the ...
2016/09/13
[ "https://Stackoverflow.com/questions/39469409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4727702/" ]
So my problem was that I used wrong python version for migration. ``` python3.5 manage.py migrate ``` solves the problem.
You are probably using wrong django version. You need `django1.10`
44,916,289
When I try to install a package for python, the setup.py has the following lines: ``` import os, sys, platform from distutils.core import setup, Extension import subprocess from numpy import get_include from Cython.Distutils import build_ext from Cython.Build import cythonize from Cython.Compiler.Options import get_di...
2017/07/05
[ "https://Stackoverflow.com/questions/44916289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8256442/" ]
Your `package.json` is missing `should` as a dependency. Install it via; `npm install --save-dev should` Also I would recommend you look into [chai](http://chaijs.com/api/bdd/) which in my opinion provides a slightly different API.
**should is an expressive, readable, framework-agnostic assertion library. The main goals of this library are to be expressive and to be helpful. It keeps your test code clean, and your error messages helpful. By default (when you require('should')) should extends the Object.prototype with a single non-enumerable gette...
23,421,031
What I put in python: ``` phoneNumber = input("Enter your Phone Number: ") print("Your number is", str(phoneNumber)) ``` What I get if I put 021999888: ``` Enter your Phone Number: 021999888 ``` > > Traceback (most recent call last): File "None", line 1, in > invalid token: , line 1, pos 9 > > > What I ge...
2014/05/02
[ "https://Stackoverflow.com/questions/23421031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3595018/" ]
If you have a `0` before a numeric literal, then it is in octal format. In this case any digit greater than 7 will result in an error. I think you should consider storing the phone number as a string, so use `raw_input()` instead. This will also keep the leading 0's.
@perreal is right. You should use `raw_input` instead: ``` >>> phoneNumber = raw_input("Enter your Phone Number: ") >>> print("Your number is", phoneNumber) Enter your Phone Number: 091234123 Your number is 091234123 ```
23,421,031
What I put in python: ``` phoneNumber = input("Enter your Phone Number: ") print("Your number is", str(phoneNumber)) ``` What I get if I put 021999888: ``` Enter your Phone Number: 021999888 ``` > > Traceback (most recent call last): File "None", line 1, in > invalid token: , line 1, pos 9 > > > What I ge...
2014/05/02
[ "https://Stackoverflow.com/questions/23421031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3595018/" ]
If you have a `0` before a numeric literal, then it is in octal format. In this case any digit greater than 7 will result in an error. I think you should consider storing the phone number as a string, so use `raw_input()` instead. This will also keep the leading 0's.
A `0` before a number is in octal format: ``` >>> 02 2 >>> 021 17 >>> 0562 370 >>> 02412 1290 >>> oct(1) '01' >>> oct(1290) '02412' ``` Using `raw_input()` instead makes sure that the input doesn't have to be something you can call in a shell: ``` >>> number = raw_input('Enter your phone number: ') Enter your phone...
23,421,031
What I put in python: ``` phoneNumber = input("Enter your Phone Number: ") print("Your number is", str(phoneNumber)) ``` What I get if I put 021999888: ``` Enter your Phone Number: 021999888 ``` > > Traceback (most recent call last): File "None", line 1, in > invalid token: , line 1, pos 9 > > > What I ge...
2014/05/02
[ "https://Stackoverflow.com/questions/23421031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3595018/" ]
A `0` before a number is in octal format: ``` >>> 02 2 >>> 021 17 >>> 0562 370 >>> 02412 1290 >>> oct(1) '01' >>> oct(1290) '02412' ``` Using `raw_input()` instead makes sure that the input doesn't have to be something you can call in a shell: ``` >>> number = raw_input('Enter your phone number: ') Enter your phone...
@perreal is right. You should use `raw_input` instead: ``` >>> phoneNumber = raw_input("Enter your Phone Number: ") >>> print("Your number is", phoneNumber) Enter your Phone Number: 091234123 Your number is 091234123 ```
67,360,917
i would like to make a groupby on my data to put together dates that are close. (less than 2 minutes) Here an example of what i get ``` > datas = [['A', 51, 'id1', '2020-05-27 05:50:43.346'], ['A', 51, 'id2', > '2020-05-27 05:51:08.347'], ['B', 45, 'id3', '2020-05-24 > 17:23:55.142'],['B', 45, 'id4', '2020-05-24 17:2...
2021/05/02
[ "https://Stackoverflow.com/questions/67360917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15817735/" ]
A compiler is allowed to choose if `char` is signed or unsigned. The standard says that they have to pick, but don't mandate which way they choose. GCC supports `-fsigned-char` and `-funsigned-char` to force this behavior.
The shown output is consistent with `char` being an unsigned data type on the platform in question. The C++ standard allows `char` to be equivalent to either `unsigned char` or `signed char`. If you wish a specific behavior you can explicitly use a cast to `signed char` in your code.
67,360,917
i would like to make a groupby on my data to put together dates that are close. (less than 2 minutes) Here an example of what i get ``` > datas = [['A', 51, 'id1', '2020-05-27 05:50:43.346'], ['A', 51, 'id2', > '2020-05-27 05:51:08.347'], ['B', 45, 'id3', '2020-05-24 > 17:23:55.142'],['B', 45, 'id4', '2020-05-24 17:2...
2021/05/02
[ "https://Stackoverflow.com/questions/67360917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15817735/" ]
A compiler is allowed to choose if `char` is signed or unsigned. The standard says that they have to pick, but don't mandate which way they choose. GCC supports `-fsigned-char` and `-funsigned-char` to force this behavior.
From the ISO C++ International Standard (Tip of trunk): | §6.8.2 Fundamental Types | [[basic.fundamental]](https://timsong-cpp.github.io/cppwp/basic.types#basic.fundamental) | | --- | --- | > > [7](https://timsong-cpp.github.io/cppwp/basic.types#basic.fundamental-7) - *Type char is a distinct type that has an implem...
67,360,917
i would like to make a groupby on my data to put together dates that are close. (less than 2 minutes) Here an example of what i get ``` > datas = [['A', 51, 'id1', '2020-05-27 05:50:43.346'], ['A', 51, 'id2', > '2020-05-27 05:51:08.347'], ['B', 45, 'id3', '2020-05-24 > 17:23:55.142'],['B', 45, 'id4', '2020-05-24 17:2...
2021/05/02
[ "https://Stackoverflow.com/questions/67360917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15817735/" ]
From the ISO C++ International Standard (Tip of trunk): | §6.8.2 Fundamental Types | [[basic.fundamental]](https://timsong-cpp.github.io/cppwp/basic.types#basic.fundamental) | | --- | --- | > > [7](https://timsong-cpp.github.io/cppwp/basic.types#basic.fundamental-7) - *Type char is a distinct type that has an implem...
The shown output is consistent with `char` being an unsigned data type on the platform in question. The C++ standard allows `char` to be equivalent to either `unsigned char` or `signed char`. If you wish a specific behavior you can explicitly use a cast to `signed char` in your code.
69,046,120
It shows that tables are successfully created when I do `heroku run -a "app-name" python manage.py migrate` ``` Running python manage.py migrate on ⬢ app_name... up, run.0000 (Free) System check identified some issues: ... Operations to perform: Apply all migrations: admin, auth, blog, contenttypes, home, sessions...
2021/09/03
[ "https://Stackoverflow.com/questions/69046120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11235791/" ]
Re-check your database configuration. The error trace shows that it's using sqlite as the database backend, instead of Postgres as expected: ``` File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 423, in execute ``` This is then failing because the sqlite database is stor...
please run these command ``` python manage.py syncdb python manage.py migrate python manage.py createsuperuser ``` please make sure that you in your installed app ``` 'django.contrib.auth' ``` and tell me if you still got the same error and then please add your settings.py
41,875,358
I'm following this guide <https://developers.google.com/sheets/api/quickstart/python> Upon running the sample code they provided (The only thing I changed was the location of the api secret since we already had one set up and the APPLICATION\_NAME) I get this error ``` AttributeError: 'module' object has no attribut...
2017/01/26
[ "https://Stackoverflow.com/questions/41875358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5838056/" ]
I got the same error and investigated on the problem. In my case, it was caused by a file named ''calendar.py" in the same directory. It's said you should avoid using general names that can be used for standard python library.
It may be versioning problem. It could be `python3` version of `httplib2` which cause troubles, try to follow answer from this [post](https://stackoverflow.com/questions/48941042/google-cloud-function-attributeerror-module-object-has-no-attribute-defaul/49970238#49970238)
33,309,904
On my local environment, with Python 2.7.10, my Django project seems to run perfectly well using .manage.py runserver. But when I tried to deploy the project to my Debian Wheezy server using the same version of python 2.7.10, it encountered 500 internal server error. Upon checking my apache log, I found the error to be...
2015/10/23
[ "https://Stackoverflow.com/questions/33309904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2970242/" ]
writing solution in answer separately for readability of others. ``` for i in [i for i, x in enumerate(hanksArray) if x == hanksYear]: print(hanksArray[i-1]) print(hanksArray[i]) print(hanksArray[i+1]) ```
Quick solution for you will be ``` for i in [i for i, x in enumerate(hanksArray) if x == hanksYear]: print("\n".join(hanksArray[i-1:i+2])) ``` There are numerous other problems with your code anyway
33,309,904
On my local environment, with Python 2.7.10, my Django project seems to run perfectly well using .manage.py runserver. But when I tried to deploy the project to my Debian Wheezy server using the same version of python 2.7.10, it encountered 500 internal server error. Upon checking my apache log, I found the error to be...
2015/10/23
[ "https://Stackoverflow.com/questions/33309904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2970242/" ]
writing solution in answer separately for readability of others. ``` for i in [i for i, x in enumerate(hanksArray) if x == hanksYear]: print(hanksArray[i-1]) print(hanksArray[i]) print(hanksArray[i+1]) ```
This looks a lot cleaner. ``` for line,val in enumerate(hanksArray): if val == hanksYear: print(hanksArray[line-1]) print(val) print(hanksArray[line+1]) ```
39,091,551
I am planning on making a game with pygame using gpio buttons. Here is the code: ``` from gpiozero import Button import pygame from time import sleep from sys import exit up = Button(2) left = Button(3) right = Button(4) down = Button(14) fps = pygame.time.Clock() pygame.init() surface = pygame.display.set_mode((1...
2016/08/23
[ "https://Stackoverflow.com/questions/39091551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2945954/" ]
There are two possible ways to close the pygame window . 1. after the end of while loop simply write ``` import sys while 1: ....... pygame.quit() sys.exit() ``` 2.instead of putting a break statement ,replace break in for loop immediately after while as ``` while 1: for event in pygame.event.get(): ...
You need to make a event and within it you need to quit the pygame ``` for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() ```
14,086,830
I'm punching way above my weight here, but please bear with this Python amateur. I'm a PHP developer by trade and I've hardly touched this language before. What I'm trying to do is call a method in a class...sounds simple enough? I'm utterly baffled about what 'self' refers to, and what is the correct procedure to cal...
2012/12/29
[ "https://Stackoverflow.com/questions/14086830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1122776/" ]
The first argument of all methods is usually called `self`. It refers to the instance for which the method is being called. Let's say you have: ``` class A(object): def foo(self): print 'Foo' def bar(self, an_argument): print 'Bar', an_argument ``` Then, doing: ``` a = A() a.foo() #prints...
> > Could someone explain to me, how to call the move method with the variable RIGHT > > > ``` >>> myMissile = MissileDevice(myBattery) # looks like you need a battery, don't know what that is, you figure it out. >>> myMissile.move(MissileDevice.RIGHT) ``` If you have programmed in any other language with class...
14,086,830
I'm punching way above my weight here, but please bear with this Python amateur. I'm a PHP developer by trade and I've hardly touched this language before. What I'm trying to do is call a method in a class...sounds simple enough? I'm utterly baffled about what 'self' refers to, and what is the correct procedure to cal...
2012/12/29
[ "https://Stackoverflow.com/questions/14086830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1122776/" ]
The first argument of all methods is usually called `self`. It refers to the instance for which the method is being called. Let's say you have: ``` class A(object): def foo(self): print 'Foo' def bar(self, an_argument): print 'Bar', an_argument ``` Then, doing: ``` a = A() a.foo() #prints...
Let's say you have a shiny Foo class. Well you have 3 options: 1) You want to use the method (or attribute) of a class inside the definition of that class: ``` class Foo(object): attribute1 = 1 # class attribute (those don't use 'self' in declaration) def __init__(self): self.attribu...
14,086,830
I'm punching way above my weight here, but please bear with this Python amateur. I'm a PHP developer by trade and I've hardly touched this language before. What I'm trying to do is call a method in a class...sounds simple enough? I'm utterly baffled about what 'self' refers to, and what is the correct procedure to cal...
2012/12/29
[ "https://Stackoverflow.com/questions/14086830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1122776/" ]
Let's say you have a shiny Foo class. Well you have 3 options: 1) You want to use the method (or attribute) of a class inside the definition of that class: ``` class Foo(object): attribute1 = 1 # class attribute (those don't use 'self' in declaration) def __init__(self): self.attribu...
> > Could someone explain to me, how to call the move method with the variable RIGHT > > > ``` >>> myMissile = MissileDevice(myBattery) # looks like you need a battery, don't know what that is, you figure it out. >>> myMissile.move(MissileDevice.RIGHT) ``` If you have programmed in any other language with class...
74,663,591
I'm trying to remake Tic-Tac-Toe on python. But, it wont work. I tried ` ``` game_board = ['_'] * 9 print(game_board[0]) + " | " + (game_board[1]) + ' | ' + (game_board[2]) print(game_board[3]) + ' | ' + (game_board[4]) + ' | ' + (game_board[5]) print(game_board[6]) + ' | ' + (game_board[7]) + ' | ' + (game_board[8])...
2022/12/03
[ "https://Stackoverflow.com/questions/74663591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20671383/" ]
``` function put() { var num0 = document.getElementById("text") var num1 = Number(num0.value) var num4 = document.getElementById("text2") var num2 = Number(num4.value) var sub = document.getElementById("submit") var res = num1 + num2 document.getElementById("myp").innerHTML...
You can use the `+` operator, like that: ``` var num1 = +num0.value; ... var num2 = +num4.value; ``` and this will turn your string number into a *floating* point number ```html <input type="text" id="text" placeholder="Number 1" /> <input type="text" id="text2" placeholder="Number 2" /> <button type="submit" id="s...
74,663,591
I'm trying to remake Tic-Tac-Toe on python. But, it wont work. I tried ` ``` game_board = ['_'] * 9 print(game_board[0]) + " | " + (game_board[1]) + ' | ' + (game_board[2]) print(game_board[3]) + ' | ' + (game_board[4]) + ' | ' + (game_board[5]) print(game_board[6]) + ' | ' + (game_board[7]) + ' | ' + (game_board[8])...
2022/12/03
[ "https://Stackoverflow.com/questions/74663591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20671383/" ]
``` function put() { var num0 = document.getElementById("text").value var num1 = Number.parseInt(num0) var num4 = document.getElementById("text2").value var num2 = Number.parseInt(num4) var res = num1 + num2 document.getElementById("myp").innerHTML = res } ```
You can use the `+` operator, like that: ``` var num1 = +num0.value; ... var num2 = +num4.value; ``` and this will turn your string number into a *floating* point number ```html <input type="text" id="text" placeholder="Number 1" /> <input type="text" id="text2" placeholder="Number 2" /> <button type="submit" id="s...
43,708,668
I have a simplified python code looking like the following: ``` a = 100 x = 0 for i in range(0, a): x = x + i / float(a) ``` Is there a way to access the maximum amount of iterations inside a `for` loop? Basically the code would change to: ``` x = 0 for i in range(0, 100): x = x + i / float(thisloopsmaxco...
2017/04/30
[ "https://Stackoverflow.com/questions/43708668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6786718/" ]
Yeah, you can.. ``` a = 100 x = 0 r = range(0,a) for i in r: x = x + i / r.stop ``` but if the range isn't counting 1,2,3... then the `stop` won't be the number of steps, e.g. `range(10,12)` doesn't have 12 steps it has 2 steps. And `range(0,100,10)` counts in tens, so it doesn't have 100 steps. So you need to ...
There's nothing built-in, but you can easily compute it yourself: ``` x = 0 myrange = range(0, 100) thisloopsmaxcount = sum(1 for _ in myrange) for i in myrange: x = x + i / float(thisloopsmaxcount) ```
43,708,668
I have a simplified python code looking like the following: ``` a = 100 x = 0 for i in range(0, a): x = x + i / float(a) ``` Is there a way to access the maximum amount of iterations inside a `for` loop? Basically the code would change to: ``` x = 0 for i in range(0, 100): x = x + i / float(thisloopsmaxco...
2017/04/30
[ "https://Stackoverflow.com/questions/43708668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6786718/" ]
Yeah, you can.. ``` a = 100 x = 0 r = range(0,a) for i in r: x = x + i / r.stop ``` but if the range isn't counting 1,2,3... then the `stop` won't be the number of steps, e.g. `range(10,12)` doesn't have 12 steps it has 2 steps. And `range(0,100,10)` counts in tens, so it doesn't have 100 steps. So you need to ...
In your example, you already know the number of iterations, so why not use that. But in general, if you want the number of elements in a (Python 3) `range()`, you can take its [`len()`](https://docs.python.org/3/library/stdtypes.html#typesseq): ``` x = 0 rang = range(12,999,123) for i in rang: x = x + i / float(...
43,708,668
I have a simplified python code looking like the following: ``` a = 100 x = 0 for i in range(0, a): x = x + i / float(a) ``` Is there a way to access the maximum amount of iterations inside a `for` loop? Basically the code would change to: ``` x = 0 for i in range(0, 100): x = x + i / float(thisloopsmaxco...
2017/04/30
[ "https://Stackoverflow.com/questions/43708668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6786718/" ]
There's nothing built-in, but you can easily compute it yourself: ``` x = 0 myrange = range(0, 100) thisloopsmaxcount = sum(1 for _ in myrange) for i in myrange: x = x + i / float(thisloopsmaxcount) ```
In your example, you already know the number of iterations, so why not use that. But in general, if you want the number of elements in a (Python 3) `range()`, you can take its [`len()`](https://docs.python.org/3/library/stdtypes.html#typesseq): ``` x = 0 rang = range(12,999,123) for i in rang: x = x + i / float(...
42,212,502
I have a list of strings, for example: ``` py python co comp computer ``` I simply want to get a string, which contains the biggest possible amount of prefixes. The result should be 'computer' because its prefixes are 'co' and 'comp' (2 prefixes). I have this code (wordlist is a dictionary): ``` for i in wordlist:...
2017/02/13
[ "https://Stackoverflow.com/questions/42212502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7396899/" ]
The data structure you are looking for is called a [trie](https://en.wikipedia.org/wiki/Trie). The Wikipedia article about this kind of search tree is certainly worth reading. The key property of the trie that comes in handy here is this: > > All the descendants of a node have a common prefix of the string associated...
For a large amount of words, you could build a [trie](https://en.wikipedia.org/wiki/Trie). You could then iterate over all the leaves and count the amount of nodes (terminal nodes) with a value between the root and the leaf. With n words, this should require `O(n)` steps compared to your `O(n**2)` solution. This [pa...
42,212,502
I have a list of strings, for example: ``` py python co comp computer ``` I simply want to get a string, which contains the biggest possible amount of prefixes. The result should be 'computer' because its prefixes are 'co' and 'comp' (2 prefixes). I have this code (wordlist is a dictionary): ``` for i in wordlist:...
2017/02/13
[ "https://Stackoverflow.com/questions/42212502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7396899/" ]
The data structure you are looking for is called a [trie](https://en.wikipedia.org/wiki/Trie). The Wikipedia article about this kind of search tree is certainly worth reading. The key property of the trie that comes in handy here is this: > > All the descendants of a node have a common prefix of the string associated...
The "correct" way is with some sort of trie data structure or similar. However, if your words are already sorted you can get quite a speedup in practical terms with some rather simple code that uses a prefix stack instead of a brute force search. This works since in sorted order, all prefixes precede their prefixed wor...
52,884,584
I have this array: ``` countOverlaps = [numA, numB, numC, numD, numE, numF, numG, numH, numI, numJ, numK, numL] ``` and then I condense this array by getting rid of all 0 values: ``` countOverlaps = [x for x in countOverlaps if x != 0] ``` When I do this, I get an output like this: [2, 1,...
2018/10/19
[ "https://Stackoverflow.com/questions/52884584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7010858/" ]
**Updated** Please check below: ``` >>> a = [2, 1, 3, 2, 3, 1, 1] >>> [b for b in a for _ in range(b)] [2, 2, 1, 3, 3, 3, 2, 2, 3, 3, 3, 1, 1] ```
This can be done using list comprehension. So far you had: ``` countOverlaps = [10,25,11,0,10,6,9,0,12,6,0,6,6,11,18] countOverlaps = [x for x in countOverlaps if x != 0] ``` This gives us all non=0 numbers. Then we can do what you want with the following code: ``` mylist = [number for number in list(set(countOverl...
42,066,449
So I have a function in python which generates a dict like so: ``` player_data = { "player": "death-eater-01", "guild": "monster", "points": 50 } ``` I get this data by calling a function. Once I get this data I want to write this into a file, so I call: ``` g = open('team.json', 'a') with g as outfile: ...
2017/02/06
[ "https://Stackoverflow.com/questions/42066449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1591731/" ]
You shouldn't append data to an existing file. Rather, you should build up a list in Python first which contains all the dicts you want to write, and only then dump it to JSON and write it to the file. If you really can't do that, one option would be to load the existing file, convert it back to Python, then append yo...
To produce valid JSON you will need to load the previous contents of the file, append the new data to that and then write it back to the file. Like so: ``` def append_player_data(player_data, file_name="team.json"): if os.path.exists(file_name): with open(file_name, 'r') as f: all_data = json....
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
Since it seems like you want to run one, and only one, function depending on the arguments given, I would suggest you use a mandatory positional argument `./prog command`, instead of optional arguments (`./prog --command1` or `./prog --command2`). so, something like this should do it: ``` FUNCTION_MAP = {'top20' : my...
``` # based on parser input to invoke either regression/classification plus other params import argparse parser = argparse.ArgumentParser() parser.add_argument("--path", type=str) parser.add_argument("--target", type=str) parser.add_argument("--type", type=str) parser.add_argument("--deviceType", type=str) args =...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
There are lots of ways of skinning this cat. Here's one using `action='store_const'` (inspired by the documented subparser example): ``` p=argparse.ArgumentParser() p.add_argument('--cmd1', action='store_const', const=lambda:'cmd1', dest='cmd') p.add_argument('--cmd2', action='store_const', const=lambda:'cmd2', dest='...
You can evaluate using `eval`whether your argument value is callable: ``` import argparse def list_showtop20(): print("Calling from showtop20") def list_apps(): print("Calling from listapps") my_funcs = [x for x in dir() if x.startswith('list_')] parser = argparse.ArgumentParser() parser.add_argument("-f", ...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
Since it seems like you want to run one, and only one, function depending on the arguments given, I would suggest you use a mandatory positional argument `./prog command`, instead of optional arguments (`./prog --command1` or `./prog --command2`). so, something like this should do it: ``` FUNCTION_MAP = {'top20' : my...
At least from what you have described, `--showtop20` and `--listapps` sound more like sub-commands than options. Assuming this is the case, we can use subparsers to achieve your desired result. Here is a proof of concept: ``` import argparse import sys def showtop20(): print('running showtop20') def listapps(): ...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
At least from what you have described, `--showtop20` and `--listapps` sound more like sub-commands than options. Assuming this is the case, we can use subparsers to achieve your desired result. Here is a proof of concept: ``` import argparse import sys def showtop20(): print('running showtop20') def listapps(): ...
Instead of using your code as `your_script --showtop20`, make it into a sub-command `your_script showtop20` and use the [`click` library](https://click.palletsprojects.com) instead of `argparse`. You define functions that are the name of your subcommand and use decorators to specify the arguments: ``` import click @c...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
If your functions are "simple enough" take adventage of `type` parameter <https://docs.python.org/2.7/library/argparse.html#type> > > type= can take any callable that takes a single string argument and > returns the converted value: > > > In your example (even if you don't need a converted value): ``` parser.a...
Instead of using your code as `your_script --showtop20`, make it into a sub-command `your_script showtop20` and use the [`click` library](https://click.palletsprojects.com) instead of `argparse`. You define functions that are the name of your subcommand and use decorators to specify the arguments: ``` import click @c...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
There are lots of ways of skinning this cat. Here's one using `action='store_const'` (inspired by the documented subparser example): ``` p=argparse.ArgumentParser() p.add_argument('--cmd1', action='store_const', const=lambda:'cmd1', dest='cmd') p.add_argument('--cmd2', action='store_const', const=lambda:'cmd2', dest='...
``` # based on parser input to invoke either regression/classification plus other params import argparse parser = argparse.ArgumentParser() parser.add_argument("--path", type=str) parser.add_argument("--target", type=str) parser.add_argument("--type", type=str) parser.add_argument("--deviceType", type=str) args =...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
If your functions are "simple enough" take adventage of `type` parameter <https://docs.python.org/2.7/library/argparse.html#type> > > type= can take any callable that takes a single string argument and > returns the converted value: > > > In your example (even if you don't need a converted value): ``` parser.a...
``` # based on parser input to invoke either regression/classification plus other params import argparse parser = argparse.ArgumentParser() parser.add_argument("--path", type=str) parser.add_argument("--target", type=str) parser.add_argument("--type", type=str) parser.add_argument("--deviceType", type=str) args =...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
At least from what you have described, `--showtop20` and `--listapps` sound more like sub-commands than options. Assuming this is the case, we can use subparsers to achieve your desired result. Here is a proof of concept: ``` import argparse import sys def showtop20(): print('running showtop20') def listapps(): ...
``` # based on parser input to invoke either regression/classification plus other params import argparse parser = argparse.ArgumentParser() parser.add_argument("--path", type=str) parser.add_argument("--target", type=str) parser.add_argument("--type", type=str) parser.add_argument("--deviceType", type=str) args =...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
Since it seems like you want to run one, and only one, function depending on the arguments given, I would suggest you use a mandatory positional argument `./prog command`, instead of optional arguments (`./prog --command1` or `./prog --command2`). so, something like this should do it: ``` FUNCTION_MAP = {'top20' : my...
You can evaluate using `eval`whether your argument value is callable: ``` import argparse def list_showtop20(): print("Calling from showtop20") def list_apps(): print("Calling from listapps") my_funcs = [x for x in dir() if x.startswith('list_')] parser = argparse.ArgumentParser() parser.add_argument("-f", ...
27,529,610
I'm new to python and currently playing with it. I have a script which does some API Calls to an appliance. I would like to extend the functionality and call different functions based on the arguments given when calling the script. Currently I have the following: ``` parser = argparse.ArgumentParser() parser.add_argu...
2014/12/17
[ "https://Stackoverflow.com/questions/27529610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4370943/" ]
At least from what you have described, `--showtop20` and `--listapps` sound more like sub-commands than options. Assuming this is the case, we can use subparsers to achieve your desired result. Here is a proof of concept: ``` import argparse import sys def showtop20(): print('running showtop20') def listapps(): ...
You can evaluate using `eval`whether your argument value is callable: ``` import argparse def list_showtop20(): print("Calling from showtop20") def list_apps(): print("Calling from listapps") my_funcs = [x for x in dir() if x.startswith('list_')] parser = argparse.ArgumentParser() parser.add_argument("-f", ...
48,643,925
I am looking through some code and found the following lines: ``` def get_char_count(tokens): return sum(len(t) for t in tokens) def get_long_words_ratio(tokens, nro_tokens): ratio = sum(1 for t in tokens if len(t) > 6) / nro_tokens return ratio ``` As you can see, in the first case the complete express...
2018/02/06
[ "https://Stackoverflow.com/questions/48643925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150683/" ]
> > Does it return by reference[?] > > > Effectively yes. When you return an object, the id (i.e. memory address) of the object inside the function is the same as the id of the object outside the function. It doesn't make a copy or anything. > > [...] or does it return the value directly? > > > If you're say...
While I prefer the first approach (Since it uses less memory), both expressions are equivalent in behavior. The PEP8 Style Guide doesn't really say anything about this, other than being consistent with your return statements. > > Be consistent in return statements. Either all return statements in a function should r...
57,948,945
I have a very large square matrix of order around 570,000 x 570,000 and I want to power it by 2. The data is in json format casting to associative array in array (dict inside dict in python) form Let's say I want to represent this matrix: ``` [ [0, 0, 0], [1, 0, 5], [2, 0, 0] ] ``` In json it's stored like: `...
2019/09/15
[ "https://Stackoverflow.com/questions/57948945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10530951/" ]
Numpy is not the problem, you need to input it on a format that numpy can understand, but since your matrix is really big, it probably won't fit in memory, so it's probably a good idea to use a sparse matrix (`scipy.sparse.csr_matrix`): ``` m = scipy.sparse.csr_matrix(( [v for row in data.values() for v in row.val...
> > now I have to somehow translate csr\_matrix back to json serializable > > > Here's one way to do that, using the attributes **data**, **indices**, **indptr** - `m` is the *csr\_matrix*: ``` d = {} end = m.indptr[0] for row in range(m.shape[0]): start = end end = m.indptr[row+1] if end > start: # i...