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
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...
> > I don't know how it can hold csr\_matrix format but not in dictionary. d.update gives MemoryError after some time > > > Here's a variant which doesn't construct the whole output dictionary and JSON string in memory, but prints the individual rows directly to the output file; this should need considerably less ...
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/" ]
> > 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...
> > I don't know how it can hold csr\_matrix format but not in dictionary. d.update gives MemoryError after some time > > > Here's a variant which doesn't construct the whole output dictionary and JSON string in memory, but prints the individual rows directly to the output file; this should need considerably less ...
744,894
I want to pull certain comments from my py files that give context to translations, rather than manually editing the .pot file basically i want to go from this python file: ``` # For Translators: some useful info about the sentence below _("Some string blah blah") ``` to this pot file: ``` # For Translators: some u...
2009/04/13
[ "https://Stackoverflow.com/questions/744894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55565/" ]
After much pissing about I found the best way to do this: ``` #. Translators: # Blah blah blah _("String") ``` Then search for comments with a . like so: ``` xgettext --language=Python --keyword=_ --add-comments=. --output=test.pot *.py ```
I was going to suggest the `compiler` module, but it ignores comments: f.py: ``` # For Translators: some useful info about the sentence below _("Some string blah blah") ``` ..and the compiler module: ``` >>> import compiler >>> m = compiler.parseFile("f.py") >>> m Module(None, Stmt([Discard(CallFunc(Name('_'), [Co...
72,029,157
I read book, I try practice these code snippet ```py >>> from lis import parse >>> parse('1.5') 1.5 ``` Then I follow guide at <https://github.com/adamhaney/lispy#getting-started> . My PC is Windows 11 Pro x64. ``` C:\Users\donhu>python -V Python 3.10.4 C:\Users\donhu>pip -V pip 22.0.4 from C:\Program Files\Python...
2022/04/27
[ "https://Stackoverflow.com/questions/72029157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3728901/" ]
You should use [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) and [`filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). ```js const input = [ { title: "QA", rows: [ { risk: "P1", ...
First your original array needs an opening `[`. Instead of using `Array#forEach` use `Array#map` instead. `.forEach` does not return any result, but can allow you to modify the original array; `.map` on the other hand creates a new array. ```js const input = [{ "title": "QA", "rows": [ { "risk": "P1", "Title": "Server...
40,427,547
I am looking for a conditional statement in python to look for a certain information in a specified column and put the results in a new column Here is an example of my dataset: ``` OBJECTID CODE_LITH 1 M4,BO 2 M4,BO 3 M4,BO 4 M1,HP-M7,HP-M1 ``` and what I want ...
2016/11/04
[ "https://Stackoverflow.com/questions/40427547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6146748/" ]
Use simple `[row][col]` access to your double pointer. It is more readable and you can avoid errors, as you coded. ``` #include<stdio.h> #include<stdlib.h> int main(void) { int **tab; int ligne; int col; printf("saisir le nbre de lignes volous\n"); scanf("%d", &ligne); printf("saisir le nbre d...
``` int main(void) { int ligne; int col; printf("saisir le nbre de lignes volous\n"); scanf("%d", &ligne); printf("saisir le nbre de colonnes volous\n"); scanf("%d", &col); int tableSize = ligne * (col*sizeof(int)); int * table = (int*) malloc(tableSize); int i,j; for (i=0 ; i ...
40,427,547
I am looking for a conditional statement in python to look for a certain information in a specified column and put the results in a new column Here is an example of my dataset: ``` OBJECTID CODE_LITH 1 M4,BO 2 M4,BO 3 M4,BO 4 M1,HP-M7,HP-M1 ``` and what I want ...
2016/11/04
[ "https://Stackoverflow.com/questions/40427547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6146748/" ]
Use simple `[row][col]` access to your double pointer. It is more readable and you can avoid errors, as you coded. ``` #include<stdio.h> #include<stdlib.h> int main(void) { int **tab; int ligne; int col; printf("saisir le nbre de lignes volous\n"); scanf("%d", &ligne); printf("saisir le nbre d...
Here, I did some changes and added some comments to the changes ``` #include<stdio.h> #include<stdlib.h> int main(void) { int **tab = NULL; int ligne = 0; int col = 0; char buffer[128] = {0}; printf("saisir le nbre de lignes volous\n"); // to avoid leaving \n in buffer after you enter the fi...
40,427,547
I am looking for a conditional statement in python to look for a certain information in a specified column and put the results in a new column Here is an example of my dataset: ``` OBJECTID CODE_LITH 1 M4,BO 2 M4,BO 3 M4,BO 4 M1,HP-M7,HP-M1 ``` and what I want ...
2016/11/04
[ "https://Stackoverflow.com/questions/40427547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6146748/" ]
Use simple `[row][col]` access to your double pointer. It is more readable and you can avoid errors, as you coded. ``` #include<stdio.h> #include<stdlib.h> int main(void) { int **tab; int ligne; int col; printf("saisir le nbre de lignes volous\n"); scanf("%d", &ligne); printf("saisir le nbre d...
As you have allocated your arrays, (the one dimensional parts) your array can be addressed as `table[i][j]`, and never as you do in ``` for (i = 0; i < ligne; i++) { for (j = 0; j < col; j++) { **(tab + i+ j) = 0; /* <--- this is an error */ } } ``` as you see `tab + i + j` is a pointer to which you...
25,826,977
I am currently taking a GIS programming class. The directions for using GDAL and ogr to manipulate the data is written for a Windows PC. I am currently working on a MAC. I am hoping to get some insight on how to translate the .bat code to a .sh code. Thanks!! Windows .bat code: ``` cd /d c:\data\PhiladelphiaBaseLaye...
2014/09/13
[ "https://Stackoverflow.com/questions/25826977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4038027/" ]
I think it's telling you that the `false` in your code will never be reached, because the `true` causes the first part of the expression to be returned. You can simplify it to: ```dart onClick.listen((e) => fonixMenu.hidden = !fonixMenu.hidden); ```
I think what you actually wanted to do was ```dart void main() { .... var menuToggle =querySelector('#lines') ..onClick.listen((e) => fonixMenu.hidden = fonixMenu.hidden == true ? = false : fonixMenu.hidden = true); // ^ 2nd = .... } ``` but Danny's solut...
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
``` $("#show a").click(function(e) { e.preventDefault(); $("#info, #hide").show(); $("#show").hide(); }); $("#hide a").click(function(e) { e.preventDefault(); $("#info, #hide").hide(); $("#show").show(); }); ```
Use this to show/hide the "Details" div: <http://api.jquery.com/toggle/> Also, you could use just one span to display the "Show/Hide" link, changing the text accordingly when you click to toggle.
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
You do not need to span for toggling content. using two span for achiving this will make code more complicated. Try this: **Html** ``` <span id="show" class="" style="text-decoration: underline"> <a href="#" class="fill-div" style="width: 100px;"> Show details </a> </span> <div id="info" style="display:...
Use this to show/hide the "Details" div: <http://api.jquery.com/toggle/> Also, you could use just one span to display the "Show/Hide" link, changing the text accordingly when you click to toggle.
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
``` $("#show a").click(function(e) { e.preventDefault(); $("#info, #hide").show(); $("#show").hide(); }); $("#hide a").click(function(e) { e.preventDefault(); $("#info, #hide").hide(); $("#show").show(); }); ```
A breeze with jQuery. Try my example on [**jsfiddle**](http://jsfiddle.net/H8gN8/). ``` // Gets executed when document and markup is fully loaded $(document).ready(function() { // Bind a click event on the element with id 'toggle' $('#toggle').click(function() { // Change text accordingly if ...
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
You do not need to span for toggling content. using two span for achiving this will make code more complicated. Try this: **Html** ``` <span id="show" class="" style="text-decoration: underline"> <a href="#" class="fill-div" style="width: 100px;"> Show details </a> </span> <div id="info" style="display:...
A breeze with jQuery. Try my example on [**jsfiddle**](http://jsfiddle.net/H8gN8/). ``` // Gets executed when document and markup is fully loaded $(document).ready(function() { // Bind a click event on the element with id 'toggle' $('#toggle').click(function() { // Change text accordingly if ...
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
You do not need to span for toggling content. using two span for achiving this will make code more complicated. Try this: **Html** ``` <span id="show" class="" style="text-decoration: underline"> <a href="#" class="fill-div" style="width: 100px;"> Show details </a> </span> <div id="info" style="display:...
``` $("#show a").click(function(e) { e.preventDefault(); $("#info, #hide").show(); $("#show").hide(); }); $("#hide a").click(function(e) { e.preventDefault(); $("#info, #hide").hide(); $("#show").show(); }); ```
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
``` $("#show a").click(function(e) { e.preventDefault(); $("#info, #hide").show(); $("#show").hide(); }); $("#hide a").click(function(e) { e.preventDefault(); $("#info, #hide").hide(); $("#show").show(); }); ```
You can do something like this: <http://jsfiddle.net/Mp8p2/> You don't need nearly as much HTML: ``` <span class="toggle">Show Details</span> <div id="info"> Details shown here </div> ``` along with just `display:none` in the css and the following jQuery: ``` $(".toggle").click(function() { $('#info')...
23,827,284
I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: 1. pass a list (in python) to a casper.js script. 2. Inside the casperjs script I would like to iterate over the python object (a list of search terms) 3. In the casper script I would like t...
2014/05/23
[ "https://Stackoverflow.com/questions/23827284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098818/" ]
You do not need to span for toggling content. using two span for achiving this will make code more complicated. Try this: **Html** ``` <span id="show" class="" style="text-decoration: underline"> <a href="#" class="fill-div" style="width: 100px;"> Show details </a> </span> <div id="info" style="display:...
You can do something like this: <http://jsfiddle.net/Mp8p2/> You don't need nearly as much HTML: ``` <span class="toggle">Show Details</span> <div id="info"> Details shown here </div> ``` along with just `display:none` in the css and the following jQuery: ``` $(".toggle").click(function() { $('#info')...
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
I was having this issue with Cocoapods. The solution was to clean the build folder re-install all pods, and then rebuild the app. The issue resolved itself that way.
In the project pane on the LHS, for your build products, don't select them in the list for Target membership in the RHS pane.
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
I was facing the same issue: below was the error > > Cycle in dependencies between targets 'Pods-MyAppName' and 'RxCocoa'; > building could produce unreliable results. This usually can be > resolved by moving the target's Headers build phase before Compile > Sources. Cycle path: Pods-MyAppName → RxCocoa → Pods-MyA...
> > `cd ios && rm -rf Pods && pod install && cd ..` > > > This worked for me.
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
**Only for Expo** 1. `expo prebuild --clean` 2. `cd ios` 3. `pod install` 4. `yarn ios`
In the project pane on the LHS, for your build products, don't select them in the list for Target membership in the RHS pane.
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
In fact, you only need to pay attention to Xcode's prompt `This usually can be resolved by moving the target's Headers build phase before Compile Sources`, and then you can do it. When I encountered this problem, Xcode prompts me: ```rb :-1: Cycle inside XXXX; building could produce unreliable results. This usually c...
Had this problem for a while as well. Added the following block at the end of the podfile (this will also get rid of some warnings): ``` post_install do |installer| installer.pods_project.targets.each do |target| target.deployment_target = ios_version target.build_configurations.each do |config| config...
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
I was facing the same issue: below was the error > > Cycle in dependencies between targets 'Pods-MyAppName' and 'RxCocoa'; > building could produce unreliable results. This usually can be > resolved by moving the target's Headers build phase before Compile > Sources. Cycle path: Pods-MyAppName → RxCocoa → Pods-MyA...
The best temporary fix I've found (until you resolve the root problem) is to make a simple change to the source code (even something as trivial as adding a new line) then trying again. I find that making even a whitespace change is enough to allow it to build again. However, this is definitely temporary as it will like...
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
I had a similar issue with a mixed interaction between **Swift, Objective-C and CoreData**: in my project (written in Swift) I made use of Core Data's autogenerated Swift classes as well. But at one point I needed an Objective C class with public properties (defined in its header counterpart) referring the the core da...
I was facing the same issue: below was the error > > Cycle in dependencies between targets 'Pods-MyAppName' and 'RxCocoa'; > building could produce unreliable results. This usually can be > resolved by moving the target's Headers build phase before Compile > Sources. Cycle path: Pods-MyAppName → RxCocoa → Pods-MyA...
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
I was finally able to resolve this by moving `Embed App Extensions` script in `Build Phases` of main Target to last position.
I was facing the same issue: below was the error > > Cycle in dependencies between targets 'Pods-MyAppName' and 'RxCocoa'; > building could produce unreliable results. This usually can be > resolved by moving the target's Headers build phase before Compile > Sources. Cycle path: Pods-MyAppName → RxCocoa → Pods-MyA...
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
Xcode 10's new build system detects dependency cycles in your build and provides diagnostics to help you resolve them. Fixing these dependency cycles improves the reliability of your build, so that the correct products are produced consistently (cycles are a possible cause of needing to delete your derived data). It al...
In the project pane on the LHS, for your build products, don't select them in the list for Target membership in the RHS pane.
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
For anybody having an issue with Xcode 10 build system, follow the following steps to fix it: > > 1. In Xcode, go to File->Project/Workspace settings. > 2. Change the build system to Legacy Build system. > > > It will resolve the build issue with the new Xcode. If you want to work with the new build system, then...
Same issue on `Version 10.0 beta 3 (10L201y)` and I wanted to have the *New Build System*. Problem is had disabled `Enable Modules (C and Objective-C)` in `Build Settings -> Apple Clang - Language - Modules` After enabling it (set to YES) got rid of the Error.
50,709,365
I start with the following tabular data : (let's say tests results by version) ``` Item Result Version 0 TO OK V1 1 T1 NOK V1 2 T2 OK V1 3 T3 NOK V1 4 TO OK V2 5 T1 OK V2 6 T2 NOK V2 7 T3 NOK V2 ``` ``` df=p.DataFrame({'Item'...
2018/06/05
[ "https://Stackoverflow.com/questions/50709365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9899968/" ]
For anybody having an issue with Xcode 10 build system, follow the following steps to fix it: > > 1. In Xcode, go to File->Project/Workspace settings. > 2. Change the build system to Legacy Build system. > > > It will resolve the build issue with the new Xcode. If you want to work with the new build system, then...
Xcode 10.2.1/Unit Test Target. My unit test target is independent of host target to improve building time. Solve it by uncheck `Find Implicit Dependencies` in `Scheme` - `Build` options, As i specify all dependencies in `Build Settings` - `Compile Sources`.
60,311,148
I'm trying to pip install a package in an AWS Lambda function. The method recommended by Amazon is to create a zipped deployment package that includes the dependencies and python function all together (as described in [AWS Lambda Deployment Package in Python](https://docs.aws.amazon.com/lambda/latest/dg/lambda-python...
2020/02/20
[ "https://Stackoverflow.com/questions/60311148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11918892/" ]
I solved this with a one-line adjustment to the original attempt. You just need to add /tmp/ to sys.path so that Python knows to search /tmp/ for the module. All you need to do is add the line `sys.path.insert(1, '/tmp/')`. **Solution** ``` import os import sys import subprocess # pip install custom package to /tmp/...
For some reason subprocess.call() was returning a FileNotFound error when I was trying to `pip3.8 install <package> -t <install-directory>`. I solved this by using os.system() instead of subprocess.call(), and I specified the path of pip directly: `os.system('/var/lang/bin/pip3.8 install <package> -t <install-director...
32,779,333
I am trying to start learning about writing encryption algorithms, so while using python I am trying to manipulate data down to a binary level so I can add bits to the end of data as well as manipulate to obscure the data. I am not new to programming I am actually a programmer but I am relatively new to python which i...
2015/09/25
[ "https://Stackoverflow.com/questions/32779333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1779617/" ]
Set the color to UIColor.clearColor()
Use clear color for the scrollView background ``` self.scrollView.backgroundColor = UIColor.clearColor() ``` You don't need to set the background color for the view again once you have set the color with a pattern image. If you set the background color again, the pattern image will be removed.
32,779,333
I am trying to start learning about writing encryption algorithms, so while using python I am trying to manipulate data down to a binary level so I can add bits to the end of data as well as manipulate to obscure the data. I am not new to programming I am actually a programmer but I am relatively new to python which i...
2015/09/25
[ "https://Stackoverflow.com/questions/32779333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1779617/" ]
Set the color to UIColor.clearColor()
As a variant, you could use `UIWebView` in order to use HTML code to set transparency there HTML code. To implement a UIWebView with a transparent background all you need to do is: 1. Set the `UIWebView`'s backgroundColor property to `[UIColor clearColor]`. 2. Use the `UIWebView`'s content in the HTML. 3. The `UIWebV...
32,779,333
I am trying to start learning about writing encryption algorithms, so while using python I am trying to manipulate data down to a binary level so I can add bits to the end of data as well as manipulate to obscure the data. I am not new to programming I am actually a programmer but I am relatively new to python which i...
2015/09/25
[ "https://Stackoverflow.com/questions/32779333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1779617/" ]
Set the color to UIColor.clearColor()
I've faced with same problem (same tutorial), how I fixed it: 1. add in xibSetup method: view.backgroundColor = UIColor(white: 0.9, alpha: 1.0) // or any color 2. creation in a UIViewController: let noDataView = NoDataUIView(frame: self.view.**frame**) view.addSubview(noDataView)
64,727,574
I am new to python I am writing code to count the frequency of numbers in a list However I get KeyError. How to automatically check if value does not exist and return a default value. My code is below ``` arr = [1,1,2,3,2,1] freq={} for i in arr: freq[i] += freq[i] + 1 ```
2020/11/07
[ "https://Stackoverflow.com/questions/64727574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14595676/" ]
Yes you can leverage the get method of a dictionary. You can simply do ``` arr=[1,1,2,3,2,1] freq={} for i in arr: freq[i] = freq.get(i,0)+1 ``` Please Google for basic question like this before asking on stackoverflow
You want the dictionary's `get` method.
64,727,574
I am new to python I am writing code to count the frequency of numbers in a list However I get KeyError. How to automatically check if value does not exist and return a default value. My code is below ``` arr = [1,1,2,3,2,1] freq={} for i in arr: freq[i] += freq[i] + 1 ```
2020/11/07
[ "https://Stackoverflow.com/questions/64727574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14595676/" ]
Yes you can leverage the get method of a dictionary. You can simply do ``` arr=[1,1,2,3,2,1] freq={} for i in arr: freq[i] = freq.get(i,0)+1 ``` Please Google for basic question like this before asking on stackoverflow
In the python library, there is a `defaultdict` which can help you here [Documentation for the defaultdict](https://docs.python.org/3.8/library/collections.html#collections.defaultdict) ``` import collections arr = [1, 1, 2, 3, 2, 1] freq = collections.defaultdict(int) # The `int` makes the default value 0 for i in...
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
If order doesn't matter ======================= If you really want to do this in python (as opposed to the `sort filepath | uniq -c` as Jean suggests), then I would do this: ``` import collections with open('path/to/file') as f: counts = collections.Counter(f) outfile = open('path/to/outfile', 'w') for li...
If it all fits into memory, then you could do: ``` from collections import Counter with open('vectors') as fin: counts = Counter(fin) ``` Or, if large, then you can use sqlite3: ``` import sqlite3 db = sqlite3.conncet('/some/path/some/file.db') db.execute('create table vector (vector)') with open('vectors.txt...
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
Just run this on command prompt ``` sort text.txt | uniq -c > output.txt ``` Remove sort if you want to preserve ordering(Will only count consecutive unique lines) ``` uniq -c text.txt > output.txt ``` Or this will give the required precise output(Solution suggested by ikegami) ``` uniq -c text.txt \ | perl -ple...
Assuming python 2.7, a less memory-intensive solution ``` from collections import Counter with open("some_file.txt") as f: cnt = Counter(f) print cnt ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
If order doesn't matter ======================= If you really want to do this in python (as opposed to the `sort filepath | uniq -c` as Jean suggests), then I would do this: ``` import collections with open('path/to/file') as f: counts = collections.Counter(f) outfile = open('path/to/outfile', 'w') for li...
Assuming python 2.7, a less memory-intensive solution ``` from collections import Counter with open("some_file.txt") as f: cnt = Counter(f) print cnt ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
``` perl -nle' if ($c && $_ ne $last) { print $c > 1 ? "$last repeat$c;" : "$last;"; $c = 0; } $last = $_; ++$c; END { if ($c) { print $c > 1 ? "$last repeat$c;" : "$last;"; } } ' file ``` (You can put that all on one line, or leave it as is.) Output: ``` V1 repe...
Assuming python 2.7, a less memory-intensive solution ``` from collections import Counter with open("some_file.txt") as f: cnt = Counter(f) print cnt ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
Just run this on command prompt ``` sort text.txt | uniq -c > output.txt ``` Remove sort if you want to preserve ordering(Will only count consecutive unique lines) ``` uniq -c text.txt > output.txt ``` Or this will give the required precise output(Solution suggested by ikegami) ``` uniq -c text.txt \ | perl -ple...
``` vectors = {} for vector in open("vect.txt").readlines(): vectors[vector] = vectors.setdefault(vector, 0) + 1 print vectors ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
If order doesn't matter ======================= If you really want to do this in python (as opposed to the `sort filepath | uniq -c` as Jean suggests), then I would do this: ``` import collections with open('path/to/file') as f: counts = collections.Counter(f) outfile = open('path/to/outfile', 'w') for li...
I dont htink you can do this in less than O(n^2) ... (I could be wrong) one way would be (in python) ``` with open("some_file_with_vectors") as f: data = f.read() counts = dict([(line,data.count(line)) for line in data.splitlines()]) print counts #if you want to save to a file with open("output.txt") as f...
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
``` perl -nle' if ($c && $_ ne $last) { print $c > 1 ? "$last repeat$c;" : "$last;"; $c = 0; } $last = $_; ++$c; END { if ($c) { print $c > 1 ? "$last repeat$c;" : "$last;"; } } ' file ``` (You can put that all on one line, or leave it as is.) Output: ``` V1 repe...
If it all fits into memory, then you could do: ``` from collections import Counter with open('vectors') as fin: counts = Counter(fin) ``` Or, if large, then you can use sqlite3: ``` import sqlite3 db = sqlite3.conncet('/some/path/some/file.db') db.execute('create table vector (vector)') with open('vectors.txt...
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
``` perl -nle' if ($c && $_ ne $last) { print $c > 1 ? "$last repeat$c;" : "$last;"; $c = 0; } $last = $_; ++$c; END { if ($c) { print $c > 1 ? "$last repeat$c;" : "$last;"; } } ' file ``` (You can put that all on one line, or leave it as is.) Output: ``` V1 repe...
``` vectors = {} for vector in open("vect.txt").readlines(): vectors[vector] = vectors.setdefault(vector, 0) + 1 print vectors ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
If order doesn't matter ======================= If you really want to do this in python (as opposed to the `sort filepath | uniq -c` as Jean suggests), then I would do this: ``` import collections with open('path/to/file') as f: counts = collections.Counter(f) outfile = open('path/to/outfile', 'w') for li...
``` vectors = {} for vector in open("vect.txt").readlines(): vectors[vector] = vectors.setdefault(vector, 0) + 1 print vectors ```
12,920,856
I have a text file that consists of million of vectors like this:- ``` V1 V1 V1 V3 V4 V1 V1 ``` Note:- ORDER is important. In the above output file, i counted the first vector 3 times. The same pattern is repeated twice after 5th line. There count should be different. I want to count how many times each vector line...
2012/10/16
[ "https://Stackoverflow.com/questions/12920856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
Just run this on command prompt ``` sort text.txt | uniq -c > output.txt ``` Remove sort if you want to preserve ordering(Will only count consecutive unique lines) ``` uniq -c text.txt > output.txt ``` Or this will give the required precise output(Solution suggested by ikegami) ``` uniq -c text.txt \ | perl -ple...
I dont htink you can do this in less than O(n^2) ... (I could be wrong) one way would be (in python) ``` with open("some_file_with_vectors") as f: data = f.read() counts = dict([(line,data.count(line)) for line in data.splitlines()]) print counts #if you want to save to a file with open("output.txt") as f...
51,341,157
``` CREATE OR REPLACE FUNCTION CLEAN_STRING(in_str varchar) returns varchar AS $$ def strip_slashes(in_str): while in_str.endswith("\\") or in_str.endswith("/"): in_str = in_str[:-1] in_str = in_str.replace("\\", "/") return in_str clean_str = strip_slashes(in_str) return clean_str $$ LANGUAG...
2018/07/14
[ "https://Stackoverflow.com/questions/51341157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3601228/" ]
Your functions are asynchronous and asynchronous functions need some way of indicating when they are finished. Typically this is done with a callback or promise. Without that there is no way to know when they are finished. If they returned a promise, you might do something like this: ```js var fun1 = function() { c...
**You can add the next function *inside* the `setTimeout` callback.** For example, ```js var fun1=function(){ console.log('Started fun1'); setTimeout(()=>{ console.log('Finished fun1'); fun2(); // Start the next timeout. },2000) } var fun2=function(){ console.log('Started fun2...
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
This could do the trick: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" vars = locals().copy() for i in vars: if 'Name' in i: print((i, eval(i))) ``` alternative in one line: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" print([(i, eval(i)) for i in...
You can access the global variables through `globals()` or if you want the local variables with `locals()`. They are stored in a `dict`. So ``` for i in range (1,100): print(locals()[f"Name{i:02d}"]) ``` should do what you want.
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
use `eval()` ``` >>> Name01 = "Dorian" >>> Name02 = "Tom" >>> Name04 = "Jerry" >>> Name03 = "Jessica" >>> for i in range(1, 100): ... print(eval('Name%02d'%i)) ... Dorian Tom Jessica Jerry ``` incase if you are using 3.7+ you can go with `f string` ``` f"Name{i:02d}" ```
You can access the global variables through `globals()` or if you want the local variables with `locals()`. They are stored in a `dict`. So ``` for i in range (1,100): print(locals()[f"Name{i:02d}"]) ``` should do what you want.
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
This could do the trick: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" vars = locals().copy() for i in vars: if 'Name' in i: print((i, eval(i))) ``` alternative in one line: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" print([(i, eval(i)) for i in...
You can use exec: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" for i in range(1,5): num = f"{i:02d}" # python3.6+ num = "{0:02d}".format(i) # python 3.x num = "%02d"%i # python 2 exec('print(Name'+num+')') ```
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
This could do the trick: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" vars = locals().copy() for i in vars: if 'Name' in i: print((i, eval(i))) ``` alternative in one line: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" print([(i, eval(i)) for i in...
Using this code, as per requirement, you will just print names without printing duplicates: ``` Name01 = "Dorian" Name02 = "Tom" Name03 = "Tom" Name04 = "Jerry" Name05 = "Jessica" Name06 = "Jessica" vars = locals().copy() names = [] for variable in vars: # This will make sure that we are only # using variab...
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
This could do the trick: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" vars = locals().copy() for i in vars: if 'Name' in i: print((i, eval(i))) ``` alternative in one line: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" print([(i, eval(i)) for i in...
use `eval()` ``` >>> Name01 = "Dorian" >>> Name02 = "Tom" >>> Name04 = "Jerry" >>> Name03 = "Jessica" >>> for i in range(1, 100): ... print(eval('Name%02d'%i)) ... Dorian Tom Jessica Jerry ``` incase if you are using 3.7+ you can go with `f string` ``` f"Name{i:02d}" ```
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
use `eval()` ``` >>> Name01 = "Dorian" >>> Name02 = "Tom" >>> Name04 = "Jerry" >>> Name03 = "Jessica" >>> for i in range(1, 100): ... print(eval('Name%02d'%i)) ... Dorian Tom Jessica Jerry ``` incase if you are using 3.7+ you can go with `f string` ``` f"Name{i:02d}" ```
You can use exec: ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" for i in range(1,5): num = f"{i:02d}" # python3.6+ num = "{0:02d}".format(i) # python 3.x num = "%02d"%i # python 2 exec('print(Name'+num+')') ```
58,484,745
let say that thoses python objects below are **locked** we just cannot change the code, all we can is writing right after it. i know it's aweful. but let say that we are forced to work with this. ``` Name01 = "Dorian" Name02 = "Tom" Name04 = "Jerry" Name03 = "Jessica" #let say that there's 99 of them ``` **How to p...
2019/10/21
[ "https://Stackoverflow.com/questions/58484745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613897/" ]
use `eval()` ``` >>> Name01 = "Dorian" >>> Name02 = "Tom" >>> Name04 = "Jerry" >>> Name03 = "Jessica" >>> for i in range(1, 100): ... print(eval('Name%02d'%i)) ... Dorian Tom Jessica Jerry ``` incase if you are using 3.7+ you can go with `f string` ``` f"Name{i:02d}" ```
Using this code, as per requirement, you will just print names without printing duplicates: ``` Name01 = "Dorian" Name02 = "Tom" Name03 = "Tom" Name04 = "Jerry" Name05 = "Jessica" Name06 = "Jessica" vars = locals().copy() names = [] for variable in vars: # This will make sure that we are only # using variab...
27,627,440
I am trying to use the [python-user-agents](https://github.com/selwin/python-user-agents/blob/master/user_agents/parsers.py). I keep running into a number of bugs within the library itself. First it referred to a `from ua_parser import user_agent_parser` that it never defined. So after banging my head, I looked online...
2014/12/23
[ "https://Stackoverflow.com/questions/27627440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2187407/" ]
if you look at the readme from the github link it tells you what to install and how to use the lib: You need pyyaml and ua-parser: ``` pip install pyyaml ua-parser user-agents ``` A working example: ``` In [1]: from user_agents import parse In [2]: ua_string = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X...
Actually the new version of ua-parser is incompatible with this so you have to install ua-parser==0.3.6
21,214,531
Howdy: somewhat of a python/programming newbie. I am trying to find each time a certain word starts a new sentence and replace it, which in this case is good old "Bob", replaced with "John". I am using a dictionary and the `.replace()` method to do the replacing - replacing the dictionary key with the associated value....
2014/01/19
[ "https://Stackoverflow.com/questions/21214531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
You have to adjust either data you are working with or the algorithm to account for this special case. For example you may decorate the beginning of your data with some value and add corresponding replacement to your dictionary. ``` f_begin_deco = '\0\0\0' # Sequence that won't be in data. start_replacements = { f_...
Question to your question: why don't you want to use regex? ``` >>> import re >>> x = "! Bob is a foo bar" >>> re.sub('^[!?.\\n\\s]*Bob','John', x) 'John is a foo bar' >>> x[:2]+re.sub('^[!?.\\n\\s]*Bob','John', x) '! John is a foo bar' ``` Here's my attempt to do it without regex: ``` >>> x = "! Bob is a foo bar" ...
21,214,531
Howdy: somewhat of a python/programming newbie. I am trying to find each time a certain word starts a new sentence and replace it, which in this case is good old "Bob", replaced with "John". I am using a dictionary and the `.replace()` method to do the replacing - replacing the dictionary key with the associated value....
2014/01/19
[ "https://Stackoverflow.com/questions/21214531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
You can use regular expression (with the dictionary). This does not require iterating dictionary entries. ``` import re nonspaces = re.compile(r'\S+') # To extract the first word def search_and_replace(filepath, replacement): def replace_sentence(match): def replace_name(match): name = match....
Question to your question: why don't you want to use regex? ``` >>> import re >>> x = "! Bob is a foo bar" >>> re.sub('^[!?.\\n\\s]*Bob','John', x) 'John is a foo bar' >>> x[:2]+re.sub('^[!?.\\n\\s]*Bob','John', x) '! John is a foo bar' ``` Here's my attempt to do it without regex: ``` >>> x = "! Bob is a foo bar" ...
21,214,531
Howdy: somewhat of a python/programming newbie. I am trying to find each time a certain word starts a new sentence and replace it, which in this case is good old "Bob", replaced with "John". I am using a dictionary and the `.replace()` method to do the replacing - replacing the dictionary key with the associated value....
2014/01/19
[ "https://Stackoverflow.com/questions/21214531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2680443/" ]
You can use regular expression (with the dictionary). This does not require iterating dictionary entries. ``` import re nonspaces = re.compile(r'\S+') # To extract the first word def search_and_replace(filepath, replacement): def replace_sentence(match): def replace_name(match): name = match....
You have to adjust either data you are working with or the algorithm to account for this special case. For example you may decorate the beginning of your data with some value and add corresponding replacement to your dictionary. ``` f_begin_deco = '\0\0\0' # Sequence that won't be in data. start_replacements = { f_...
61,680,684
I am having trouble with a problem in python. I am making a tic tac toe game, i have created a function that takes in a list of lists containing the state of the game such that [[0,0,0],[0,0,0],[0,0,0]] and output a similar list replacing the 0, 1, 2 by "-", "X", "O" respectively as such - ``` def display_board(b): ...
2020/05/08
[ "https://Stackoverflow.com/questions/61680684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13498818/" ]
I know I'm writing very late, but I hope it helps some other people who are looking for the same thing, it has helped me, especially passing the parameters to the connection to the database, to which the variable is assigned in the where and filter the information that is needed. all from the url: <https://developers....
Expanding on Yeisson's answer. Report parameters are passed via query parameter `params`. Value is URL-encoded JSON object with all report parameters that you want to set. So parameter values such as ```json { "ds0.includeToday": true, "ds0.units": "Metric", "ds1.countries": ["Canada", "Mexico"], "ds1.labelN...
56,576,400
I wanted to create an mapping between two arrays. But in python, doing this resulted in a mapping with **last element getting picked**. ``` array_1 = [0,0,0,1,2,3] array_2 = [4,4,5,6,8,7] mapping = dict(zip(array_1, array_2)) print(mapping) ``` The mapping resulted in `{0: 5, 1: 6, 2: 8, 3: 7}` How to pick the most...
2019/06/13
[ "https://Stackoverflow.com/questions/56576400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11309609/" ]
You can create a dictionary with key and a list of values for the key. Then you can go over the list of values in this dictionary, and update the value to be the most frequent item in the list using [Counter.most\_common](https://docs.python.org/3/library/collections.html#collections.Counter.most_common) ``` from coll...
You can count frequencies of all mappings using `Counter` and then sort those mappings by key and frequency: ``` from collections import Counter array_1 = [0,0,0,1,2,3] array_2 = [4,4,5,6,8,7] c = Counter(zip(array_1, array_2)) dict(i for i, _ in sorted(c.items(), key=lambda x: (x[0], x[1]), reverse=True)) # {3: 7, 2...
73,956,255
Hi I am running this python code to reduce multi-line patterns to singletons however, I am doing this on extremely large files of 200,000+ lines. Here is my current code: ``` import sys import re with open('largefile.txt', 'r+') as file: string = file.read() string = re.sub(r"((?:^.*\n)+)(?=\1)", "", string,...
2022/10/05
[ "https://Stackoverflow.com/questions/73956255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20154432/" ]
Regexps are compact here, but will never be speedy. For one reason, you have an inherently line-based problem, but regexps are inherently character-based. The regexp engine has to deduce, over & over & over again, where "lines" are by searching for newline characters, one at a time. For a more fundamental reason, every...
Nesting a quantifier within a quantifier is expensive and in this case unnecessary. You can use the following regex without nesting instead: ``` string = re.sub(r"(^.*\n)(?=\1)", "", string, flags=re.M | re.S) ``` In the following test it more than cuts the time in half compared to your approach: <https://replit.c...
73,956,255
Hi I am running this python code to reduce multi-line patterns to singletons however, I am doing this on extremely large files of 200,000+ lines. Here is my current code: ``` import sys import re with open('largefile.txt', 'r+') as file: string = file.read() string = re.sub(r"((?:^.*\n)+)(?=\1)", "", string,...
2022/10/05
[ "https://Stackoverflow.com/questions/73956255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20154432/" ]
@TimPeters' line-based comparison approach is good but wastes time in repeated comparisons of the same lines. @KellyBundy's encoding idea is good but wastes time in the overhead of a regex engine and text encoding. A more efficient approach would be to adopt @KellyBundy's encoding idea in @TimPeters' algorithm, but in...
Nesting a quantifier within a quantifier is expensive and in this case unnecessary. You can use the following regex without nesting instead: ``` string = re.sub(r"(^.*\n)(?=\1)", "", string, flags=re.M | re.S) ``` In the following test it more than cuts the time in half compared to your approach: <https://replit.c...
73,956,255
Hi I am running this python code to reduce multi-line patterns to singletons however, I am doing this on extremely large files of 200,000+ lines. Here is my current code: ``` import sys import re with open('largefile.txt', 'r+') as file: string = file.read() string = re.sub(r"((?:^.*\n)+)(?=\1)", "", string,...
2022/10/05
[ "https://Stackoverflow.com/questions/73956255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20154432/" ]
Regexps are compact here, but will never be speedy. For one reason, you have an inherently line-based problem, but regexps are inherently character-based. The regexp engine has to deduce, over & over & over again, where "lines" are by searching for newline characters, one at a time. For a more fundamental reason, every...
Another idea: You're talking about "200,000+ lines", so we can encode each unique line as one of the 1,114,112 possible characters and simplify the regex to `r"(.+)(?=\1)"`. And after the deduplication, decode the characters back to lines. ``` def dedup(s): encode = {} decode = {} lines = s.split('\n') ...
73,956,255
Hi I am running this python code to reduce multi-line patterns to singletons however, I am doing this on extremely large files of 200,000+ lines. Here is my current code: ``` import sys import re with open('largefile.txt', 'r+') as file: string = file.read() string = re.sub(r"((?:^.*\n)+)(?=\1)", "", string,...
2022/10/05
[ "https://Stackoverflow.com/questions/73956255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20154432/" ]
Regexps are compact here, but will never be speedy. For one reason, you have an inherently line-based problem, but regexps are inherently character-based. The regexp engine has to deduce, over & over & over again, where "lines" are by searching for newline characters, one at a time. For a more fundamental reason, every...
@TimPeters' line-based comparison approach is good but wastes time in repeated comparisons of the same lines. @KellyBundy's encoding idea is good but wastes time in the overhead of a regex engine and text encoding. A more efficient approach would be to adopt @KellyBundy's encoding idea in @TimPeters' algorithm, but in...
73,956,255
Hi I am running this python code to reduce multi-line patterns to singletons however, I am doing this on extremely large files of 200,000+ lines. Here is my current code: ``` import sys import re with open('largefile.txt', 'r+') as file: string = file.read() string = re.sub(r"((?:^.*\n)+)(?=\1)", "", string,...
2022/10/05
[ "https://Stackoverflow.com/questions/73956255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20154432/" ]
@TimPeters' line-based comparison approach is good but wastes time in repeated comparisons of the same lines. @KellyBundy's encoding idea is good but wastes time in the overhead of a regex engine and text encoding. A more efficient approach would be to adopt @KellyBundy's encoding idea in @TimPeters' algorithm, but in...
Another idea: You're talking about "200,000+ lines", so we can encode each unique line as one of the 1,114,112 possible characters and simplify the regex to `r"(.+)(?=\1)"`. And after the deduplication, decode the characters back to lines. ``` def dedup(s): encode = {} decode = {} lines = s.split('\n') ...
53,569,407
Is it possible to conditionally replace parts of strings in MySQL? Introduction to a problem: Users in my database stored articles (table called "table", column "value", each row = one article) with wrong links to images. I'd like to repair all of them at once. To do that, I have to replace all of the addresses in "hr...
2018/12/01
[ "https://Stackoverflow.com/questions/53569407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10731133/" ]
``` SELECT regexp_replace( value, '^<a href="([^"]+)"><img class="([^"]+)" src="([^"]+)"(.*)$', '<a href="\\3"><img class="\\2" src="\\3"\\4' ) FROM yourTable ``` The replacement only happens if the pattern is matched. * `^` at the start means `start of the string` * `([^"]+)` means `one of more ch...
Solved, thanks to @MatBailie , but I had to modified his answer. The final query, including the update, is ``` UPDATE `table` SET value = REGEXP_REPLACE(value, '(.*)<a href="([^"]+)"><img class="([^"]+)" src="([^"]+)"(.*)', '\\1<a href="\\4"><img class="\\3" src="\\4"\\5' ``` ) A wildcard (.\*) had to be put at th...
64,950,799
I am trying to group the indexes of the customers based on the following condition with python. If database contains the same contact number or email, the result should return the indexes of the tuples grouped together in a sub-list. For a given database: ``` data = [ ("Customer1","contactA", "emailA"), ("Customer...
2020/11/22
[ "https://Stackoverflow.com/questions/64950799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14091382/" ]
You could build a graph where you connect elements with a common email or with a common contact and then find [connected components](https://en.wikipedia.org/wiki/Component_(graph_theory)) (e.g., by using a [bfs](https://en.wikipedia.org/wiki/Breadth-first_search) visit). In this case I'm using the [networkx](https:...
You could do this: ``` my_contact_dict = {} my_email_dict = {} my_list = [] for pos, cust in enumerate(data): contact_group = my_contact_dict.get(cust[1], set()) # returns empty set if not in dict email_group = my_email_dict.get(cust[2], set()) # contact_group.add (pos) email_group.add (pos) co...
64,950,799
I am trying to group the indexes of the customers based on the following condition with python. If database contains the same contact number or email, the result should return the indexes of the tuples grouped together in a sub-list. For a given database: ``` data = [ ("Customer1","contactA", "emailA"), ("Customer...
2020/11/22
[ "https://Stackoverflow.com/questions/64950799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14091382/" ]
You could build a graph where you connect elements with a common email or with a common contact and then find [connected components](https://en.wikipedia.org/wiki/Component_(graph_theory)) (e.g., by using a [bfs](https://en.wikipedia.org/wiki/Breadth-first_search) visit). In this case I'm using the [networkx](https:...
I usually approach these kinds of problems with the pandas package, as it makes handling of (large) datasets especially easy. ``` import pandas as pd data = [ ("Customer1","contactA", "emailA"), ("CustomerX","contactA", "emailX"), ("CustomerZ","contactZ", "emailW"), ("CustomerY","contactY", "emailX"), ("Customer...
27,773,111
I'm new to cocos2d-X.I'm trying to set up cocos2d-x for android and I exactly followed below [video](https://www.youtube.com/watch?v=2LI1IrRp_0w&index=2&list=PLRtjMdoYXLf4od_bOKN3WjAPr7snPXzoe) tutorial I failed the steps in terminal with problem (python setup.py command result is not as expected). For example when I...
2015/01/05
[ "https://Stackoverflow.com/questions/27773111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2219111/" ]
Do you copy the path to the terminal? If so, try to delete the trailing whitespace, it will solve the problem.
Cocos script uses `os.path.join($your_path, $some_extra_file)`, so you have to add slash `/` at the end: > > /Users/apple/Documents/Development/Cosos2d-x/android-ndk-r9d/ > > >
38,361,916
I am trying to insert the following list of dictionaries named `posts` to mongo, and got a `BulkWriteError: batch op errors occurred` error which I don't know how to fix. `posts:` ``` [{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680', 'Records': [ {'DATE': '07/22/09 05:54 PM', 'STATUS': 'Is flying back friday...
2016/07/13
[ "https://Stackoverflow.com/questions/38361916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6200575/" ]
Not to late to answer here, you almost there. I am not sure if the [FAQ](https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert_many) updated but please read it properly: > > when calling `insert_many()` with a list of references to a **single** document raises BulkWri...
[Here is output](http://i.stack.imgur.com/SIZQQ.png) in this output records are store which are in list. ``` from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client['post'] posts = [{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680', 'Records': [ {'DATE': '07/22/09 05:54 PM', ...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
Depending on how the code tags are formatted, you could split the line on `"` then pick out the second element. ``` s = 'string(15) "Ivor Abeysekera"' temp = s.split('"')[1] # temp is 'Ivor Abeysekera' ``` Note that this will get rid of the trailing `"`, if you need it you can always just add it back on. In your exa...
**BAD SOLUTION Based on current question** but to answer your question just use ``` info_string = lines[i + 1] value_str = info_string.split(" ",1)[-1].strip(" \"") ``` **BETTER SOLUTION** do you have access to the php generating that .... if you do just do `echo json_encode($data);` instead of using `var_dump` i...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
**BAD SOLUTION Based on current question** but to answer your question just use ``` info_string = lines[i + 1] value_str = info_string.split(" ",1)[-1].strip(" \"") ``` **BETTER SOLUTION** do you have access to the php generating that .... if you do just do `echo json_encode($data);` instead of using `var_dump` i...
You should use regular expressions (regex) for this: <http://docs.python.org/2/library/re.html> What you intend to do can be easily done with the following code: ``` # Import the library import re # This is a string just to demonstrate a = 'string(32) "PV Technical Sales Certification"' # Create the regex p = re.co...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
**BAD SOLUTION Based on current question** but to answer your question just use ``` info_string = lines[i + 1] value_str = info_string.split(" ",1)[-1].strip(" \"") ``` **BETTER SOLUTION** do you have access to the php generating that .... if you do just do `echo json_encode($data);` instead of using `var_dump` i...
You can do this statefully by looping across all the lines and keeping track of where you are in a block: ``` # Make field names to dict keys fields = { 'public_state': 'state', 'public_zip': 'zip', 'email': 'email', 'full_name': 'contact', 'org_name': 'name', 'org_website': 'website', 'cit...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
Depending on how the code tags are formatted, you could split the line on `"` then pick out the second element. ``` s = 'string(15) "Ivor Abeysekera"' temp = s.split('"')[1] # temp is 'Ivor Abeysekera' ``` Note that this will get rid of the trailing `"`, if you need it you can always just add it back on. In your exa...
You should use regular expressions (regex) for this: <http://docs.python.org/2/library/re.html> What you intend to do can be easily done with the following code: ``` # Import the library import re # This is a string just to demonstrate a = 'string(32) "PV Technical Sales Certification"' # Create the regex p = re.co...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
Depending on how the code tags are formatted, you could split the line on `"` then pick out the second element. ``` s = 'string(15) "Ivor Abeysekera"' temp = s.split('"')[1] # temp is 'Ivor Abeysekera' ``` Note that this will get rid of the trailing `"`, if you need it you can always just add it back on. In your exa...
You can do this statefully by looping across all the lines and keeping track of where you are in a block: ``` # Make field names to dict keys fields = { 'public_state': 'state', 'public_zip': 'zip', 'email': 'email', 'full_name': 'contact', 'org_name': 'name', 'org_website': 'website', 'cit...
18,388,050
I have a large amount of data of this type: ``` array(14) { ["ap_id"]=> string(5) "22755" ["user_id"]=> string(4) "8872" ["exam_type"]=> string(32) "PV Technical Sales Certification" ["cert_no"]=> string(12) "PVTS081112-2" ["explevel"]=> string(1) "0" ["public_state"]=> ...
2013/08/22
[ "https://Stackoverflow.com/questions/18388050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2646265/" ]
You should use regular expressions (regex) for this: <http://docs.python.org/2/library/re.html> What you intend to do can be easily done with the following code: ``` # Import the library import re # This is a string just to demonstrate a = 'string(32) "PV Technical Sales Certification"' # Create the regex p = re.co...
You can do this statefully by looping across all the lines and keeping track of where you are in a block: ``` # Make field names to dict keys fields = { 'public_state': 'state', 'public_zip': 'zip', 'email': 'email', 'full_name': 'contact', 'org_name': 'name', 'org_website': 'website', 'cit...
64,154,088
I am Python coder and got stuck in a question that "How to check input in textbox of tkinter python". The problem is that it is not giving output on writing this code . ``` def start(event): a = main.get(1.0,END) if a == 'ver': print('.....') main = Text(root) main.pack() root.bind('<Return>',start) ...
2020/10/01
[ "https://Stackoverflow.com/questions/64154088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14225987/" ]
We can do this by `get()` method: ``` from tkinter import * a=Tk() def check(): print(x.get('1.0',END)[:-1]) x=Text(a) b=Button(a,text='Check',command=check) x.pack() b.pack() a.mainloop() ```
You should write something like ``` def start(event): t = var.get() if t == 'something': pass var = StringVar() e = Entry(master, textvariable=var) e.pack() e.bind(bind('<Return>',start) ```
64,154,088
I am Python coder and got stuck in a question that "How to check input in textbox of tkinter python". The problem is that it is not giving output on writing this code . ``` def start(event): a = main.get(1.0,END) if a == 'ver': print('.....') main = Text(root) main.pack() root.bind('<Return>',start) ...
2020/10/01
[ "https://Stackoverflow.com/questions/64154088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14225987/" ]
The text widget guarantees that there is always a trailing newline. When you do `get(1.0,END)` you're getting that trailing newline even if the user doesn't enter a newline. If you want to get exactly what the user entered, use `get("1.0", "end-1c")`. That will get all of the characters up to the end, minus one charac...
You should write something like ``` def start(event): t = var.get() if t == 'something': pass var = StringVar() e = Entry(master, textvariable=var) e.pack() e.bind(bind('<Return>',start) ```
64,154,088
I am Python coder and got stuck in a question that "How to check input in textbox of tkinter python". The problem is that it is not giving output on writing this code . ``` def start(event): a = main.get(1.0,END) if a == 'ver': print('.....') main = Text(root) main.pack() root.bind('<Return>',start) ...
2020/10/01
[ "https://Stackoverflow.com/questions/64154088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14225987/" ]
``` from tkinter import * from threading import Thread root = Tk() def check(): while True : a = main.get(1.0,END)[:-1] if a == 'ver': print('.....') main = Text(root) main.pack() Thread(target=check).start() root.mainloop() ```
You should write something like ``` def start(event): t = var.get() if t == 'something': pass var = StringVar() e = Entry(master, textvariable=var) e.pack() e.bind(bind('<Return>',start) ```
52,113,890
I needed to extend User model to add things like address, score, more user\_types, etc. There are 2 possible ways to achieve that, extend the User model or create a new model that will be connected with the target User with `OneToOneField`. I decided to go with a new model because It seemed easier and It is recommended...
2018/08/31
[ "https://Stackoverflow.com/questions/52113890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4981456/" ]
Take it easy, You can create Profile obj just in the create function. ``` class UserSerializer(serializers.ModelSerializer): trusted = serializers.BooleanField() address = serializers.CharField() class Meta: model = User fields = ('username', 'email', 'password', 'trusted', 'address',) ...
Plase read documentation for Serializers: [Django REST FRAMEWORK](http://www.django-rest-framework.org/api-guide/relations/) -- user related\_name ``` user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="user_profile") # models class ProfileSerializer(serializers.ModelSerializer): user = ser...
27,701,573
I got error message: *{DetachedInstanceError} Parent instance is not bound to a session; lazy load operation of attribute 'owner' cannot proceed* My python code: ``` car_obj = my_query_function() # get a Car object owner_name = car_obj.owner.name # here generate error! ``` My model: ``` class Person(EntityClass):...
2014/12/30
[ "https://Stackoverflow.com/questions/27701573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3778914/" ]
I traced the docs and made it work by adding `lazy='subquery'` ``` owner = relationship('Person', lazy='subquery', cascade='all, delete-orphan', backref=backref('car', cascade='delete'), single_parent=True) ``` <http://docs.sqlalchemy.org/en/rel_0_9/orm/join_conditions.html>
Made it work by adding `joinedload_all()` in `session.query(Car).options()`, for example: ``` cars = session.query(Car).options(joinedload_all('*')).all() session.close() for car in cars: "do your struff" ``` good luck
29,956,181
I am a newbie in this field, and I am trying to solve a problem (not really sure if it is possible actually) where I want to print on the display some information plus some input from the user. The following works fine: ``` >>> print (" Hello " + input("tellmeyourname: ")) tellmeyourname: dfsdf Hello dfsdf ``` How...
2015/04/29
[ "https://Stackoverflow.com/questions/29956181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4848506/" ]
Starting from Python 3.8, this will become possible using an [assignment expression](https://www.python.org/dev/peps/pep-0572/): ``` print("Your name is: " + (name := input("Tell me your name: "))) print("Your name is still: " + name) ``` Though 'possible' is not the same as 'advisable'... --- But in Python <3.8: ...
**no this is not possible**. well except something like ``` x=input("tell me:");print("blah %s"%(x,)); ``` but thats not really one line ... it just looks like it
34,300,908
I've been creating an webapp (just for learning purposes) using python django, and have no intention in deploying it. However, is there a way to let someone else, try the webapplication, or more precisely: Is it possible to somehow test the webapp on another computer. I tried to send det source code (and the whole fold...
2015/12/15
[ "https://Stackoverflow.com/questions/34300908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3799968/" ]
You can use ngrok -- <https://ngrok.com/> -- to create a public URL to your local server for testing, and then give that URL to people so they can try your webapp.
You can also use [Localtunnel](https://localtunnel.me) to easily share a web service on your local development without deploying the code in the server. Install the localtunnel ``` npm install -g localtunnel ``` Start a webserver on some local port (eg <http://localhost:8000>) and use the command line interface to...
56,364,756
My log files have some multiline bytestring in them, like [2019-05-25 19:16:31] b'logstring\r\n\r\nmore log' After I try to extract the original multiline string, how do I convert that to a real string using Python 3? As a simplified example, after reading the log file and stripping the time, I end up with a variabl...
2019/05/29
[ "https://Stackoverflow.com/questions/56364756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2335020/" ]
You can use regex: ``` import re tmp = "b'logstring\r\n\r\nmore log'" r = re.compile(r"b'(.+)'", re.DOTALL|re.MULTILINE) result = r.sub(r"\1", tmp) print(result) # logstring\r\n\r\nmore log ``` You could use this for the entire file or line by line but you may need to slightly change this code to meet your needs. ...
It seems that you can lock down the eval function so that it can't run functions and python builtins. You do this by passing a dictionary of allowed global and local functions. By mapping all builtins to None you can block the execution of regular python commands. With that in place, using eval to evaluate the string c...
6,467,407
I'm using Jython from within Java; so I have a Java setup similar to below: ``` String scriptname="com/blah/myscript.py" PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); InputStream is = this.getClass().getClassLoader().getResourceAsStream(scriptname); interpreter.execfile(is); ``` A...
2011/06/24
[ "https://Stackoverflow.com/questions/6467407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184456/" ]
I'm using Jython 2.5.2 and `runScript` didn't exist, so I had to replace it with `execfile`. Aside from that difference, I also needed to set `argv` in the state object before creating the `PythonInterpreter` object: ``` String scriptname = "myscript.py"; PySystemState state = new PySystemState(); state.argv.append (...
For those people whom the above solution does not work, try the below. This works for me on jython version 2.7.0 ``` String[] params = {"get_AD_accounts.py","-server", "http://xxxxx:8080","-verbose", "-logLevel", "CRITICAL"}; ``` The above replicates the command below. i.e. each argument and its value is separate el...
16,640,624
I am outputting ``` parec -d "name" ``` You don't need to know this command, just know that as soon as you press enter, it outputs binary data representing audio. My goal is to read this with python in real time, ie start it and have it in a variable "data" I can read from with something like ``` data = p.stdout...
2013/05/19
[ "https://Stackoverflow.com/questions/16640624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2348735/" ]
There are multiple problems and they are not simple (unless the version of the ascensor script is outdated). The first issue is fairly simple, and illustrates the initial problem - some of the documentation doesn't match the code. In particular, the case doesn't match. For example, you have `childType: 'section'` (low...
The reverse of the current answer is now true. Using the latest version of Ascensor (1.8.0 (2014-02-23)), you have to specify the property names in lower case. e.g. change `ChildType: 'section'` to `childType: 'section'`. The examples all around the net are unfortunately using older versions.
57,361,849
I'm doing some dockerized code in Python (3.5) and flask (1.1.1) working against a CouchDB database (2.3.1) using the cloudant python extension (2.12.0) which seems to be the most up to date library to work against CouchDB. I'm trying to fetch and use a view from the database, but it is not working. I can fetch docume...
2019/08/05
[ "https://Stackoverflow.com/questions/57361849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6879212/" ]
I'm answering my own question, in case someone in the future stumbles upon this. I got the answer from Esteban Laver in the github for python-cloudant and it is what @chrisinmtown mentions in a response up there. I was failing to call fetch() on the design document before using it. Another good suggestion was to use ...
I believe the code posted above creates a new DesignDocument object, and does not search for an existing DesignDocument. After creating that object, it looks like you need to call its fetch() method and **then** check its views property. HTH. p.s. promoting my comment to an answer, hope that's cool in SO land these da...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to: [Install python3.1 and pygame1.9.1 in Ubuntu](https://sites.google.com/site/cslappe1/knowledge-base-and-how-to-s/installpython31andpygame191inubu...
Just use the below command to install pygame for Python3. I could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2. pip3 install pygame
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to: [Install python3.1 and pygame1.9.1 in Ubuntu](https://sites.google.com/site/cslappe1/knowledge-base-and-how-to-s/installpython31andpygame191inubu...
I installed **pygame for python3** quite easily using the `pip3` (*a tool for installing and managing Python packages*) command on **Ubuntu 16.04.7 LTS**. 1. Open a terminal and install *pip3*, type `sudo apt install python3-pip` 2. Now use it to install *pygame* for **python3**, type `pip3 install pygame` That's it!...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10: ``` sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev hg ...
I installed **pygame for python3** quite easily using the `pip3` (*a tool for installing and managing Python packages*) command on **Ubuntu 16.04.7 LTS**. 1. Open a terminal and install *pip3*, type `sudo apt install python3-pip` 2. Now use it to install *pygame* for **python3**, type `pip3 install pygame` That's it!...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10: ``` sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev hg ...
I followed @Søren 's method, but without the -u number. The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the fol...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to: [Install python3.1 and pygame1.9.1 in Ubuntu](https://sites.google.com/site/cslappe1/knowledge-base-and-how-to-s/installpython31andpygame191inubu...
I followed @Søren 's method, but without the -u number. The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the fol...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to: [Install python3.1 and pygame1.9.1 in Ubuntu](https://sites.google.com/site/cslappe1/knowledge-base-and-how-to-s/installpython31andpygame191inubu...
It's because installing the `python-pygame` package installs it for the default version of Python on your system, 2.6.5 in this case. You should download the pygame package and use setup.py to install it in 3.1.2.
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10: ``` sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev hg ...
The python-pygame package is only compiled for python2.6 and python2.7 where I am. You'll have to install it again, possibly from a python3 branch of the source.
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I installed **pygame for python3** quite easily using the `pip3` (*a tool for installing and managing Python packages*) command on **Ubuntu 16.04.7 LTS**. 1. Open a terminal and install *pip3*, type `sudo apt install python3-pip` 2. Now use it to install *pygame* for **python3**, type `pip3 install pygame` That's it!...
It's because installing the `python-pygame` package installs it for the default version of Python on your system, 2.6.5 in this case. You should download the pygame package and use setup.py to install it in 3.1.2.
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I installed **pygame for python3** quite easily using the `pip3` (*a tool for installing and managing Python packages*) command on **Ubuntu 16.04.7 LTS**. 1. Open a terminal and install *pip3*, type `sudo apt install python3-pip` 2. Now use it to install *pygame* for **python3**, type `pip3 install pygame` That's it!...
I followed @Søren 's method, but without the -u number. The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the fol...
6,539,472
I'm reading the book *Introduction to Computer Science Using Python and Pygame* by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1...
2011/06/30
[ "https://Stackoverflow.com/questions/6539472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/777225/" ]
I installed **pygame for python3** quite easily using the `pip3` (*a tool for installing and managing Python packages*) command on **Ubuntu 16.04.7 LTS**. 1. Open a terminal and install *pip3*, type `sudo apt install python3-pip` 2. Now use it to install *pygame* for **python3**, type `pip3 install pygame` That's it!...
Just use the below command to install pygame for Python3. I could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2. pip3 install pygame
42,349,191
This is a typical use case for FEM/FVM equation systems, so is perhaps of broader interest. From a triangular mesh à la [![enter image description here](https://i.stack.imgur.com/RS6MJ.png)](https://i.stack.imgur.com/RS6MJ.png) I would like to create a `scipy.sparse.csr_matrix`. The matrix rows/columns represent valu...
2017/02/20
[ "https://Stackoverflow.com/questions/42349191", "https://Stackoverflow.com", "https://Stackoverflow.com/users/353337/" ]
I would try creating the csr structure directly, especially if you are resorting to `np.unique` since this gives you sorted keys, which is half the job done. I'm assuming you are at the point where you have `i, j` sorted lexicographically and overlapping `v` summed using `np.add.at` on the optional `inverse` output of...
So, in the end this turned out to be the difference between COO's and CSR's `sum_duplicates` (just like @hpaulj suspected). Thanks to the efforts of everyone involved here (particularly @paul-panzer), [a PR](https://github.com/scipy/scipy/pull/7078) is underway to give `tocsr` a tremendous speedup. SciPy's `tocsr` doe...
69,276,976
I've tried to way I was instructed and moved the code in csv I was given into the same folder as my Jupyter Notebook is located. It still isn't reading it. I'm also trying to convert it into a dataframe and get it to 'describe'. I'll post the code and the errors below. Please help! Thank you in advance! ``` import pan...
2021/09/22
[ "https://Stackoverflow.com/questions/69276976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Deno does not currently support "classic" workers. 1. From [Worker() - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker): > > `type`: A [`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString) specifying the type of worker to create. The value can be `classic` or `modul...
The information provided in [mfulton26's answer](https://stackoverflow.com/a/69292184/438273) is right, but you don't need a data URL: you simply need to add `{ type: "module" }` to your worker instantiation options. Deno even supports TypeScript as the source for your worker: `blob-worker.ts`: ```ts const workerModu...
56,452,581
I've almost the same problem like this one: [How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc)](https://stackoverflow.com/questions/29351492/how-to-make-a-continuous-alphabetic-list-python-from-a-z-then-from-aa-ab-ac-e) But, I am doing a list in gui like excel, where on the vertical h...
2019/06/04
[ "https://Stackoverflow.com/questions/56452581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11329096/" ]
Another alternative, if you want to dive deeper (create up to ~18,000 columns): ``` from string import ascii_lowercase letters = list(ascii_lowercase) num_cols = 100 excel_cols = [] for i in range(0, num_cols - 1): n = i//26 m = n//26 i-=n*26 n-=m*26 col = letters[m-1]+letters[n-1]+letters[i] if ...
Try this code. It works by pretending that all Excel column names have two characters, but the first "character" may be the null string. I get the `product` to accept the null string as a "character" by using a list of characters rather than a string. ``` from string import ascii_lowercase import itertools first_char...
56,452,581
I've almost the same problem like this one: [How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc)](https://stackoverflow.com/questions/29351492/how-to-make-a-continuous-alphabetic-list-python-from-a-z-then-from-aa-ab-ac-e) But, I am doing a list in gui like excel, where on the vertical h...
2019/06/04
[ "https://Stackoverflow.com/questions/56452581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11329096/" ]
Another alternative, if you want to dive deeper (create up to ~18,000 columns): ``` from string import ascii_lowercase letters = list(ascii_lowercase) num_cols = 100 excel_cols = [] for i in range(0, num_cols - 1): n = i//26 m = n//26 i-=n*26 n-=m*26 col = letters[m-1]+letters[n-1]+letters[i] if ...
Here is another way to approach the problem. This also allows you to give the number of columns you want to generate and will work for any "two character" columns and would also work if you changed the allowed letters for some reason: ``` from string import ascii_lowercase letters = list(ascii_lowercase) num_cols = 1...
64,834,395
i use linux nodejs had no problem untill i upgraded my system (sudo apt upgrade) now when i try to install nodejs it say python-minimal mot installed then i knew that it casue of updating python from python2.7.17 to python2.7.18 and python minimal is no longer require ,but now i cant install nodejs cause it ask for pyt...
2020/11/14
[ "https://Stackoverflow.com/questions/64834395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14535629/" ]
jq does not have an `eval` function for evaluating arbitrary jq expressions, but it does provide functions that can be used to achieve much the same effect, the key idea being that certain JSON values can be used to specify query operations. In your case, you would have to translate the jq query into a suitable jq ope...
**TLDR;** The following code does the job: ``` $ a=".[].Header.Tenant"; jq -f <(echo "[$a]") test.json [ "Tenant1", "Tenant2" ] ``` One as well can add/modify the filter in the jq call, if needed: ``` $ a=".[].Header.Tenant"; jq -f <(echo "[$a]|length") test.json 2 ``` **Longer explanation** My ultimate ...
61,081,016
After following the official RTD installation tutorial for ubuntu18 I manage to do everything (even webhooks) until the point of building, for a project called **test**, where I get the following error: > > python3.6 -mvirtualenv /home/myuser/readthedocs.org/user\_builds/test/envs/latest > > > Followed by: > > ...
2020/04/07
[ "https://Stackoverflow.com/questions/61081016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2236386/" ]
Your running job #3 has only 4 tasks (screenshot #2), thats why you see 4 executors. Spark doesn't need 6 executors to complete 4 tasks. Each executor (screenshot #3) has 5 cores and what looks like 14GB memory ((14GB -300MB) \* 0.6 ~ 7.8GB). See [Spark memory management](https://spark.apache.org/docs/latest/configur...
You have only 2 nodes with 16 vCores each, in total of 32 vCores, which you can very well see in your Yarn UI. Now when you are submitting your job you are requesting Yarn to create 6 containers(executors) with 5 vCores each but then on a single node you can have at max of 2 executors considering 5 cores requirement (...
21,579,459
I am just starting on Python from a PHP background. I was wondering if there is a more elegant way in assigning a variable the result of an "if ... in" statement? I currently do ``` is_holiday = False if now_date in holidays: is_holiday = True ``` To me it looks like an unnecessary amount of code line or is thi...
2014/02/05
[ "https://Stackoverflow.com/questions/21579459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/912588/" ]
``` is_holiday = now_date in holidays ```
Use [Conditional expressions](http://docs.python.org/2/reference/expressions.html#conditional-expressions): `is_holiday = True if now_date in holidays else False` or just `is_holiday = now_date in holidays`.
17,502,704
I am trying to use the tempfile module. (<http://docs.python.org/2.7/library/tempfile.html>) I am looking for a temporary file that I could open several times to get several streams to read it. ``` tmp = ... stream1 = # get a stream for the temp file stream2 = # get another stream for the temp file ``` I have tried ...
2013/07/06
[ "https://Stackoverflow.com/questions/17502704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1232891/" ]
File objects (be they temporary or otherwise) cannot be read multiple times without re-positioning the file position back to the start. Your options are: * To reopen the file multiple times, creating multiple file objects for the same file. * To rewind the file object before each read. To reopen the file, use a `Nam...
You could use [`tempfile.mkstemp()`](http://docs.python.org/2.7/library/tempfile.html#tempfile.mkstemp). From the documentation: > > Creates a temporary file in the most secure manner possible. There are no race conditions in the file’s creation, assuming that the platform properly implements the os.O\_EXCL flag for ...