qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
3,589,214
So here is the deal: I want to (for example) generate 4 pseudo-random numbers, that when added together would equal 40. How could this be dome in python? I could generate a random number 1-40, then generate another number between 1 and the remainder,etc, but then the first number would have a greater chance of "grabbin...
2010/08/28
[ "https://Stackoverflow.com/questions/3589214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433493/" ]
Generate 4 random numbers, compute their sum, divide each one by the sum and multiply by 40. If you want Integers, then this will require a little non-randomness.
If you want true randomness then use: ``` import numpy as np def randofsum_unbalanced(s, n): # Where s = sum (e.g. 40 in your case) and n is the output array length (e.g. 4 in your case) r = np.random.rand(n) a = np.array(np.round((r/np.sum(r))*s,0),dtype=int) while np.sum(a) > s: a[np.random.c...
74,271,418
I'm pretty new at Power BI (so forgive my rough terminology), and I'm trying to create a bar chart from some existing financial data. Specifically, I'd like to know how to transform my data. I've looked at DAX and python, and can't quite figure out the right commands. My existing table looks like the following. The se...
2022/11/01
[ "https://Stackoverflow.com/questions/74271418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4019700/" ]
1. Avoid Excel-style cross-tables in Power BI. In the PowerQuery Editor transform your table by selecting Categorie and then **Unpivot other columns** [![enter image description here](https://i.stack.imgur.com/UAHij.png)](https://i.stack.imgur.com/UAHij.png) 2. Back in the designer view you can directly use this data...
Here is the full M-Code to achieve your goal: Just change the source step with your source file: ``` let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0ABLmpkhErE60khOMb2oJl7EEyziD9ID4xkYgljFIDVyLEYhraATXgtBhDiQsLGASQANiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let...
13,391,549
I try to use a Bixolon receipt printer with OE on Windows 7. I success to print directly from a small python module using win32print (coming with py32win) with the code below : win32print is not natively in OE so I paste win32print.pyd in OE server directory and put the code in a wizard of my OE module. I can see my ...
2012/11/15
[ "https://Stackoverflow.com/questions/13391549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1682857/" ]
Remember that the python code runs on the server. Is your printer connected to the server? Also, you don't have an `except` section in your `try`. That makes errors go by silently. Try removing the `try` block so that errors are raised. Looking at them you might figure out the issue.
Well, I don't know if you typed here incorrectly, but the way you imported the `win32print` module force you to attach it to module function calls and you haven't done this in your first line: ``` printer = OpenPrinter(win32print.GetDefaultPrinter()) ``` should be ``` printer = win32print.OpenPrinter(win32print.Get...
11,878,300
I would like to serialize on machine A and deserialize on machine B a python lambda. There are a couple of obvious problems with that: * the pickle module does not serialize or deserialize code. It only serializes the names of classes/methods/functions * some of the answers I found with google suggest the use of the l...
2012/08/09
[ "https://Stackoverflow.com/questions/11878300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/782529/" ]
Surprisingly, checking whether a lambda will work without its associated closure is actually fairly easy. According to the [data model documentation](http://docs.python.org/release/2.6.2/reference/datamodel.html), you can just check the `func_closure` attribute: ``` >>> def get_lambdas(): ... bar = 42 ... ret...
I'm not sure exactly what you want to do, but you could try [dill](https://github.com/uqfoundation/dill). Dill can serialize and deserialize lambdas and I believe also works for lambdas inside closures. The pickle API is a subset of it's API. To use it, just "import dill as pickle" and go about your business pickling s...
39,278,419
I am trying to POST a request to server side from android client side, using AsyncHttpClient : For now i just want to check whether the response is coming back or not , so i have not implemented anything to parse request parameters at server side and have just returned some json as response. ``` RequestParams param...
2016/09/01
[ "https://Stackoverflow.com/questions/39278419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3820753/" ]
The way I found to do it is by using the token provider from the namespace manager. So: ``` var namespaceMngr = NamespaceManager.CreateFromConnectionString(namespaceConnString); MessagingFactorySettings mfs = new MessagingFactorySettings(); mfs.TokenProvider = namespaceMngr.Settings.TokenProvider; mfs.NetMessagingTran...
JordanSchillers answer fixes the token provider issue but my address was now using port 9355 instead of 9354. I ended using a mixture of the ServiceBusConnectionStringBuilder and the NamespaceManager: ``` var serviceBusConnectionString = new ServiceBusConnectionStringBuilder(connection.ConnectionString); ...
17,004,946
I have some logging in my application (it happens to be log4cxx but I am flexible on that), and I have some unit tests using the boost unit test framework. When my unit tests run, I get lots of log output, from both the passing and failing tests (not just boost assertions logged, but my own application code's debug log...
2013/06/08
[ "https://Stackoverflow.com/questions/17004946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99876/" ]
There are start of test and end of test hooks that you can use for this purpose. To set up these hooks you need to define a subclass of [boost::unit\_test::test\_observer](https://www.boost.org/doc/libs/1_70_0/libs/test/doc/html/boost/unit_test/test_observer.html), create an instance of the class that will persist thro...
According to the [Boost.Test documentation](http://www.boost.org/doc/libs/1_53_0/libs/test/doc/html/utf/user-guide/runtime-config/reference.html), run your test executable with `--log_level=error`. This will catch only failing test cases. I checked that it works using a `BOOST_CHECK(false)` on an otherwise correctly ...
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
> > also I don't know how the original find functions > > > A good way to learn about functions without googling is to use [Ipython](http://ipython.org/)and especially the [notebook variant](http://ipython.org/notebook.html/). These allow you to write python code interactively, and have some special features. Typi...
There is a simple solution to this problem, however there are also much faster solutions which you may want to look at after you've implemented the simple version. What you want to be doing is checking each position in the string you're search over and seeing if the string you're searching for starts there. This is ine...
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
Here is a solution that returns all the hints in a list, and `rfind` is defined using the original `find` keyword `backwards`. You can use for integers or floats also. You can easily modify it in order to return only the first hint. ``` def find( x, string, backward = False, ignore_case = False ): x = str(x) ...
There is a simple solution to this problem, however there are also much faster solutions which you may want to look at after you've implemented the simple version. What you want to be doing is checking each position in the string you're search over and seeing if the string you're searching for starts there. This is ine...
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
> > also I don't know how the original find functions > > > A good way to learn about functions without googling is to use [Ipython](http://ipython.org/)and especially the [notebook variant](http://ipython.org/notebook.html/). These allow you to write python code interactively, and have some special features. Typi...
I think [Steve](https://stackoverflow.com/a/16092297/1258041) means something like this: ``` def find(s, sub): for i, _ in enumerate(s): if s.startswith(sub, i): return i return -1 def rfind(s, sub): for i in range(len(s)-1, -1, -1): if s.startswith(sub, i): return ...
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
> > also I don't know how the original find functions > > > A good way to learn about functions without googling is to use [Ipython](http://ipython.org/)and especially the [notebook variant](http://ipython.org/notebook.html/). These allow you to write python code interactively, and have some special features. Typi...
``` 'mystring'.rindex('my_substring') ``` this returns the first position of the substring, beginning from the right side ``` 'mystring'.index('my_substring') ``` does the same thing, but beginns searching the string from the left hand side.
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
Here is a solution that returns all the hints in a list, and `rfind` is defined using the original `find` keyword `backwards`. You can use for integers or floats also. You can easily modify it in order to return only the first hint. ``` def find( x, string, backward = False, ignore_case = False ): x = str(x) ...
I think [Steve](https://stackoverflow.com/a/16092297/1258041) means something like this: ``` def find(s, sub): for i, _ in enumerate(s): if s.startswith(sub, i): return i return -1 def rfind(s, sub): for i in range(len(s)-1, -1, -1): if s.startswith(sub, i): return ...
16,092,153
I wish to create a 'find' procedure **myself**, which is capable of finding a sub-string in a string and it also should be able to read a string backward and give position of match- just like the original find function in python. I am unable to figure out what logic should I use- also I don't know how the original fi...
2013/04/18
[ "https://Stackoverflow.com/questions/16092153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1050305/" ]
Here is a solution that returns all the hints in a list, and `rfind` is defined using the original `find` keyword `backwards`. You can use for integers or floats also. You can easily modify it in order to return only the first hint. ``` def find( x, string, backward = False, ignore_case = False ): x = str(x) ...
``` 'mystring'.rindex('my_substring') ``` this returns the first position of the substring, beginning from the right side ``` 'mystring'.index('my_substring') ``` does the same thing, but beginns searching the string from the left hand side.
27,967,988
So I was dissapointed to find out that JavaScript's `for ( var in array/object)` was not equivalent to pythons `for var in list:`. In JavaScript you are iterating over the indices themselves e.g. ``` 0, 1, 2, ... ``` where as with Python, you are iterating over the values pointed to by the indices e.g. ``` "s...
2015/01/15
[ "https://Stackoverflow.com/questions/27967988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3581485/" ]
for an array the most similar is the forEach loop (of course index is optional) ``` [1,2,3,4,].forEach(function(value,index){ console.log(value); console.log(index); }); ``` So you will get the following output: ``` 1 0 2 1 3 2 4 3 ```
In the next version of ECMAScript (ECMAScript6 aka Harmony) will be [for-of construct](http://tc39wiki.calculist.org/es6/for-of/): ``` for (let word of ["one", "two", "three"]) { alert(word); } ``` `for-of` could be used to iterate over various objects, Arrays, Maps, Sets and custom iterable objects. In that sense...
27,967,988
So I was dissapointed to find out that JavaScript's `for ( var in array/object)` was not equivalent to pythons `for var in list:`. In JavaScript you are iterating over the indices themselves e.g. ``` 0, 1, 2, ... ``` where as with Python, you are iterating over the values pointed to by the indices e.g. ``` "s...
2015/01/15
[ "https://Stackoverflow.com/questions/27967988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3581485/" ]
for an array the most similar is the forEach loop (of course index is optional) ``` [1,2,3,4,].forEach(function(value,index){ console.log(value); console.log(index); }); ``` So you will get the following output: ``` 1 0 2 1 3 2 4 3 ```
I'm not sure I see MUCH difference. It's easy to access the value at a given index/key ``` var list = [1,2,3,4,5]; // or... var list = {a: 'foo', b: 'bar', c: 'baz'}; for (var item in list) console.log(list[item]); ``` and as mentioned, you could use forEach for arrays or objects... heres an obj: ``` var list = {...
27,967,988
So I was dissapointed to find out that JavaScript's `for ( var in array/object)` was not equivalent to pythons `for var in list:`. In JavaScript you are iterating over the indices themselves e.g. ``` 0, 1, 2, ... ``` where as with Python, you are iterating over the values pointed to by the indices e.g. ``` "s...
2015/01/15
[ "https://Stackoverflow.com/questions/27967988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3581485/" ]
In the next version of ECMAScript (ECMAScript6 aka Harmony) will be [for-of construct](http://tc39wiki.calculist.org/es6/for-of/): ``` for (let word of ["one", "two", "three"]) { alert(word); } ``` `for-of` could be used to iterate over various objects, Arrays, Maps, Sets and custom iterable objects. In that sense...
I'm not sure I see MUCH difference. It's easy to access the value at a given index/key ``` var list = [1,2,3,4,5]; // or... var list = {a: 'foo', b: 'bar', c: 'baz'}; for (var item in list) console.log(list[item]); ``` and as mentioned, you could use forEach for arrays or objects... heres an obj: ``` var list = {...
66,650,626
Is there any to restore files from the recycle bin in python? Here's the code: ``` from send2trash import send2trash file_name = "test.txt" operation = input("Enter the operation to perform[delete/restore]: ") if operation == "delete": send2trash(file_name) print(f"Successfully deleted {file_name}") else:...
2021/03/16
[ "https://Stackoverflow.com/questions/66650626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14909172/" ]
It would depend on your operating system. **Linux** it's as simple as moving it from the trash folder to the original path. The location of the trash folder differs from distro to distro, but this is where it typically is. There is a [command line tool](https://github.com/andreafrancia/trash-cli) that you can use, o...
**Google Colab** (you are the `root` user) Import the shell utility for Python: ```py import shutil ``` Move the file from trash to a selected destination: ```py shutil.move('/root/.local/share/Trash/files/<deleted-file>', '<destination-path>') ```
54,207,540
I'm trying to find any python library or package which implements [newgrnn (Generalized Regression Neural Network)](https://www.mathworks.com/help/deeplearning/ref/newgrnn.html) using python. Is there any package or library available where I can use neural network for regression. I'm trying to find python equivalent ...
2019/01/15
[ "https://Stackoverflow.com/questions/54207540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5347207/" ]
I found the library neupy which solved my problem: ``` from neupy import algorithms from neupy.algorithms.rbfn.utils import pdf_between_data grnn = algorithms.GRNN(std=0.003) grnn.train(X, y) # In this part of the code you can do any moifications you want ratios = pdf_between_data(grnn.input_train, X, grnn.std) pre...
A more upgraded form is [pyGRNN](https://github.com/federhub/pyGRNN) which offers in addition to the normal GRNN the Anisotropic GRNN, which optimizes the hyperparameters automatically: ``` from sklearn import datasets from sklearn import preprocessing from sklearn.model_selection import train_test_split from sklearn....
33,713,149
I have a text file containing CPU stats as below (from sar/sysstat) ``` 17:30:38 CPU %user %nice %system %iowait %steal %idle 17:32:49 all 14.56 2.71 3.79 0.00 0.00 78.94 17:42:49 all 12.68 2.69 3.44 0.00 0.00 81.19 17:52:4...
2015/11/14
[ "https://Stackoverflow.com/questions/33713149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1247154/" ]
Here is a more dynamic version that would scale to more columns. But there isn't really anything bad about your implementation. ``` # build a dict of column name -> list of column values stats = {} with open('stats.txt') as F: header = None for idx, line in enumerate(F): # This is the header i...
First you could use `_` or `__` to represent ignored values (this is a common convention). Next you could store all values into a single list and then unpack the list into multiple lists using `zip`. ``` cpu_stats = [] with open('stats.txt') as stats_file: for line in stats_file: time, _, user, _, system,...
33,713,149
I have a text file containing CPU stats as below (from sar/sysstat) ``` 17:30:38 CPU %user %nice %system %iowait %steal %idle 17:32:49 all 14.56 2.71 3.79 0.00 0.00 78.94 17:42:49 all 12.68 2.69 3.44 0.00 0.00 81.19 17:52:4...
2015/11/14
[ "https://Stackoverflow.com/questions/33713149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1247154/" ]
Here is a more dynamic version that would scale to more columns. But there isn't really anything bad about your implementation. ``` # build a dict of column name -> list of column values stats = {} with open('stats.txt') as F: header = None for idx, line in enumerate(F): # This is the header i...
This is a bit more generic. You can define a list of desired column names. It uses [csv-Dictreader](https://docs.python.org/3/library/csv.html?highlight=csv#csv.DictReader) to read the file. The names are given without the `%` suffix. In addition, it converts the time into a `datetime.time` object from the module [date...
33,713,149
I have a text file containing CPU stats as below (from sar/sysstat) ``` 17:30:38 CPU %user %nice %system %iowait %steal %idle 17:32:49 all 14.56 2.71 3.79 0.00 0.00 78.94 17:42:49 all 12.68 2.69 3.44 0.00 0.00 81.19 17:52:4...
2015/11/14
[ "https://Stackoverflow.com/questions/33713149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1247154/" ]
This is a bit more generic. You can define a list of desired column names. It uses [csv-Dictreader](https://docs.python.org/3/library/csv.html?highlight=csv#csv.DictReader) to read the file. The names are given without the `%` suffix. In addition, it converts the time into a `datetime.time` object from the module [date...
First you could use `_` or `__` to represent ignored values (this is a common convention). Next you could store all values into a single list and then unpack the list into multiple lists using `zip`. ``` cpu_stats = [] with open('stats.txt') as stats_file: for line in stats_file: time, _, user, _, system,...
21,881,748
This may be a stupid question but I'm not sure how to phrase it in a google-friendly way... In a terminal if you type something like: ``` nano some_file ``` then nano opens up an edit window inside the terminal. A text based application. Ctrl+X closes it again and you see the terminal as it was. Here's another exa...
2014/02/19
[ "https://Stackoverflow.com/questions/21881748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/742082/" ]
You probably need to use alternative screen buffer. To enable it just print '\0033[?1049h' and for disabling '\0033[?1049l' (Terminal Control Escape Sequences). <http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#The%20Alternate%20Screen%20Buffer> Example: ``` print('\033[?1049h', end='') print('Alternative scree...
This does the trick: <http://docs.python.org/2/howto/curses.html> Example: ``` import curses oScreen = curses.initscr() curses.noecho() curses.curs_set(0) oScreen.keypad(1) oScreen.addstr("Woooooooooooooo\n\n",curses.A_BOLD) while True: oEvent = oScreen.getch() if oEvent == ord("q"): break curses.end...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
I suspect that Celery bound to existing backends is the wrong solution for the reliability guarantees you need. Given that you want a distributed queueing system with strong durability and reliability guarantees, I'd start by looking for such a system (they do exist) and then figuring out the best way to bind to it in...
I've used Amazon SQS for this propose and got good results. You will recieve message until you will delete it from queue and it allows to grow you app as high as you will need.
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
You might want to check out [IronMQ](http://iron.io/celery), it covers your requirements (durable, highly available, etc) and is a cloud native solution so zero maintenance. And there's a Celery broker for it: <https://github.com/iron-io/iron_celery> so you can start using it just by changing your Celery config.
I've used Amazon SQS for this propose and got good results. You will recieve message until you will delete it from queue and it allows to grow you app as high as you will need.
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
A lot has changed since the OP! There is now an option for high-availability aka "mirrored" queues. This goes pretty far toward solving the problem you described. See <http://www.rabbitmq.com/ha.html>.
I've used Amazon SQS for this propose and got good results. You will recieve message until you will delete it from queue and it allows to grow you app as high as you will need.
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
I suspect that Celery bound to existing backends is the wrong solution for the reliability guarantees you need. Given that you want a distributed queueing system with strong durability and reliability guarantees, I'd start by looking for such a system (they do exist) and then figuring out the best way to bind to it in...
Is using a distributed rendering system an option? Normally reserved for HPC but alot of concepts are the same. Check out Qube or Deadline Render. There are other, open source solutions as well. All have failover in mind given the high degree of complexity and risk of failure in some renders that can take hours per ima...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
You might want to check out [IronMQ](http://iron.io/celery), it covers your requirements (durable, highly available, etc) and is a cloud native solution so zero maintenance. And there's a Celery broker for it: <https://github.com/iron-io/iron_celery> so you can start using it just by changing your Celery config.
I suspect that Celery bound to existing backends is the wrong solution for the reliability guarantees you need. Given that you want a distributed queueing system with strong durability and reliability guarantees, I'd start by looking for such a system (they do exist) and then figuring out the best way to bind to it in...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
A lot has changed since the OP! There is now an option for high-availability aka "mirrored" queues. This goes pretty far toward solving the problem you described. See <http://www.rabbitmq.com/ha.html>.
I suspect that Celery bound to existing backends is the wrong solution for the reliability guarantees you need. Given that you want a distributed queueing system with strong durability and reliability guarantees, I'd start by looking for such a system (they do exist) and then figuring out the best way to bind to it in...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
You might want to check out [IronMQ](http://iron.io/celery), it covers your requirements (durable, highly available, etc) and is a cloud native solution so zero maintenance. And there's a Celery broker for it: <https://github.com/iron-io/iron_celery> so you can start using it just by changing your Celery config.
Is using a distributed rendering system an option? Normally reserved for HPC but alot of concepts are the same. Check out Qube or Deadline Render. There are other, open source solutions as well. All have failover in mind given the high degree of complexity and risk of failure in some renders that can take hours per ima...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
A lot has changed since the OP! There is now an option for high-availability aka "mirrored" queues. This goes pretty far toward solving the problem you described. See <http://www.rabbitmq.com/ha.html>.
Is using a distributed rendering system an option? Normally reserved for HPC but alot of concepts are the same. Check out Qube or Deadline Render. There are other, open source solutions as well. All have failover in mind given the high degree of complexity and risk of failure in some renders that can take hours per ima...
6,577,218
I have a python application where I want to start doing more work in the background so that it will scale better as it gets busier. In the past I have used Celery for doing normal background tasks, and this has worked well. The only difference between this application and the others I have done in the past is that I ...
2011/07/05
[ "https://Stackoverflow.com/questions/6577218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356788/" ]
A lot has changed since the OP! There is now an option for high-availability aka "mirrored" queues. This goes pretty far toward solving the problem you described. See <http://www.rabbitmq.com/ha.html>.
You might want to check out [IronMQ](http://iron.io/celery), it covers your requirements (durable, highly available, etc) and is a cloud native solution so zero maintenance. And there's a Celery broker for it: <https://github.com/iron-io/iron_celery> so you can start using it just by changing your Celery config.
21,669,632
I am trying to open a Windows Media Video file on a macintosh using OpenCV. To view this video in MacOS I had to install a player called Flip4Mac. I am assuming that this came with the codecs for decoding WMV. Is there something I can now do to get OpenCV to open the videos using the codec? In python/opencv2 opening a...
2014/02/10
[ "https://Stackoverflow.com/questions/21669632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/391339/" ]
use split function. ``` var str = "Architecture, Royal Melbourne Institute of Technology"; console.log(str.split(",")[0]);// logs Architecture ``` output array after splitting your string by `,` would have the expected result at the zeroth index.
Its again a normal Javascript, all the methods can be used in nodeJS. var name = "any string"; For example: ``` var str = "Hi, world", arrayOfStrings = str.split(','), output = arrayOfStrings[0]; // output contains "Hi" ``` You can update the required field by directly replacing the string ie. ``` arrayOfStrings[0]...
7,020,630
I wish to run a long-running script in the background upon receiving a request. I read about `subprocess` but I require that the call is nonblocking so that the request can complete in time. ``` def controlCrawlers(request): if request.method == 'POST' and 'type' in request.POST and 'cc' in request.POST: ...
2011/08/11
[ "https://Stackoverflow.com/questions/7020630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357236/" ]
Yeah, don't do this, use [celery](http://docs.celeryproject.org/en/master/getting-started/introduction.html) instead. It makes running asynchronous tasks a lot easier, more reliable.
If you don't want to use asynchronous task queues with something like celery you can always just run a python script via cron. There are several options to do this. An example: * create a model which save the values which are needed by your process * write a standalone python/django script which get the values from th...
19,742,451
I'm trying to use Django with virtualenv. I actually got the Django hello world webpage to display with 127.0.0.1:8001. Later I had to do some minor tweaks and now its giving me this error when I try to launch it again (I ctrl-Z from the previous working gunicorn session so I don't think it is because of that). ``` ...
2013/11/02
[ "https://Stackoverflow.com/questions/19742451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1661745/" ]
`ctrl+z` halts the process, but does not close it. In consequence it does not release its ports. You can bring the process back with `fg` and then close it properly using `ctrl+c`.
The port 8000 was probably bound and thus unavailable for the connection.
19,742,451
I'm trying to use Django with virtualenv. I actually got the Django hello world webpage to display with 127.0.0.1:8001. Later I had to do some minor tweaks and now its giving me this error when I try to launch it again (I ctrl-Z from the previous working gunicorn session so I don't think it is because of that). ``` ...
2013/11/02
[ "https://Stackoverflow.com/questions/19742451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1661745/" ]
`ctrl+z` halts the process, but does not close it. In consequence it does not release its ports. You can bring the process back with `fg` and then close it properly using `ctrl+c`.
The error `Connection in use: ...` basically means that the port is still in use even though you exited the server. You need to find who is currently using the port and turn them off. This command can help you find who is there: ```py $ sudo netstat -nlp | grep :80 ``` Then you can sudo kill that process: ```py sud...
19,742,451
I'm trying to use Django with virtualenv. I actually got the Django hello world webpage to display with 127.0.0.1:8001. Later I had to do some minor tweaks and now its giving me this error when I try to launch it again (I ctrl-Z from the previous working gunicorn session so I don't think it is because of that). ``` ...
2013/11/02
[ "https://Stackoverflow.com/questions/19742451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1661745/" ]
The error `Connection in use: ...` basically means that the port is still in use even though you exited the server. You need to find who is currently using the port and turn them off. This command can help you find who is there: ```py $ sudo netstat -nlp | grep :80 ``` Then you can sudo kill that process: ```py sud...
The port 8000 was probably bound and thus unavailable for the connection.
62,295,863
I have this (python) list my\_list = [['dog','cat','mat','fun'],['bob','cat','pan','fun'],['dog','ben','mat','rat'], ['cat','mat','fun','dog'],['mat','fun','dog','cat'],['fun','dog','cat','mat'], ['rat','dog','ben','mat'],['dog','mat','cat','fun'], ... ] my\_list has 200704 elements Note here my\_...
2020/06/10
[ "https://Stackoverflow.com/questions/62295863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13717822/" ]
Your implementation is an n-squared algorithm, which means that the implementation time will grow dramatically for a large data set. 200,000 squared is a very large number. You need to convert this to an order n or n-log(n) algorithm. To do that you need to preprocess the data so that you can check whether a circularly...
@BradBudlong Brad Budlong's answer is right. Following is the implementation result of the same. My method (given in the question): Time taken: ~274 min Result: len(my\_list\_without\_circular\_duplicates) >> 50176 Brad Budlong's method: Time taken: ~12 sec (great !) Result: len(my\_list\_with...
58,909,624
While reading this [article](https://pbpython.com/pandas_transform.html), I came across this statement. ``` order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index() ``` Other than `reset_index()` method call, everything else is clear to me. My question is what will happen if I don't...
2019/11/18
[ "https://Stackoverflow.com/questions/58909624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1465553/" ]
I think better here is use [`GroupBy.transform`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.transform.html) for new `Series` with same size like original DataFrame filled by aggregate values, so `merge` is not necessary: ``` df_1 = pd.DataFrame({ 'A':list('abcdef'), ...
A simplified explanation is that; `reset_index()` takes the current index, and places it in column 'index'. Then it recreates a new 'linear' index for the data-set. ``` df=pd.DataFrame([20,30,40,50],index=[2,3,4,5]) 0 2 20 3 30 4 40 5 50 df.reset_index() index 0 0 2 20 1 3 30 2 4 40 3...
58,909,624
While reading this [article](https://pbpython.com/pandas_transform.html), I came across this statement. ``` order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index() ``` Other than `reset_index()` method call, everything else is clear to me. My question is what will happen if I don't...
2019/11/18
[ "https://Stackoverflow.com/questions/58909624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1465553/" ]
A simplified explanation is that; `reset_index()` takes the current index, and places it in column 'index'. Then it recreates a new 'linear' index for the data-set. ``` df=pd.DataFrame([20,30,40,50],index=[2,3,4,5]) 0 2 20 3 30 4 40 5 50 df.reset_index() index 0 0 2 20 1 3 30 2 4 40 3...
To answer your question: > > My question is what will happen if I don't call reset\_index() considering the sequence? > > > You will have a multi-index formed by the keys you have applied group-by statement on. for eg- 'order' in your case. Specific to the article, difference in indices of two dataframes may cau...
58,909,624
While reading this [article](https://pbpython.com/pandas_transform.html), I came across this statement. ``` order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index() ``` Other than `reset_index()` method call, everything else is clear to me. My question is what will happen if I don't...
2019/11/18
[ "https://Stackoverflow.com/questions/58909624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1465553/" ]
I think better here is use [`GroupBy.transform`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.transform.html) for new `Series` with same size like original DataFrame filled by aggregate values, so `merge` is not necessary: ``` df_1 = pd.DataFrame({ 'A':list('abcdef'), ...
Reset Index will create index starting from 0 and remove if there is any column set as index. ``` import pandas as pd df = pd.DataFrame( { "ID": [1, 2, 3, 4, 5], "name": [ "Hello Kitty", "Hello Puppy", "It is an Helloexample", "for stackoverflow", ...
58,909,624
While reading this [article](https://pbpython.com/pandas_transform.html), I came across this statement. ``` order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index() ``` Other than `reset_index()` method call, everything else is clear to me. My question is what will happen if I don't...
2019/11/18
[ "https://Stackoverflow.com/questions/58909624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1465553/" ]
I think better here is use [`GroupBy.transform`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.transform.html) for new `Series` with same size like original DataFrame filled by aggregate values, so `merge` is not necessary: ``` df_1 = pd.DataFrame({ 'A':list('abcdef'), ...
To answer your question: > > My question is what will happen if I don't call reset\_index() considering the sequence? > > > You will have a multi-index formed by the keys you have applied group-by statement on. for eg- 'order' in your case. Specific to the article, difference in indices of two dataframes may cau...
58,909,624
While reading this [article](https://pbpython.com/pandas_transform.html), I came across this statement. ``` order_total = df.groupby('order')["ext price"].sum().rename("Order_Total").reset_index() ``` Other than `reset_index()` method call, everything else is clear to me. My question is what will happen if I don't...
2019/11/18
[ "https://Stackoverflow.com/questions/58909624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1465553/" ]
Reset Index will create index starting from 0 and remove if there is any column set as index. ``` import pandas as pd df = pd.DataFrame( { "ID": [1, 2, 3, 4, 5], "name": [ "Hello Kitty", "Hello Puppy", "It is an Helloexample", "for stackoverflow", ...
To answer your question: > > My question is what will happen if I don't call reset\_index() considering the sequence? > > > You will have a multi-index formed by the keys you have applied group-by statement on. for eg- 'order' in your case. Specific to the article, difference in indices of two dataframes may cau...
55,276,170
I have been using Selenium and python to web scrape for a couple of weeks now. It has been working fairly good. Been running on a macOS and windows 7. However all the sudden the headless web driver has stopped working. I have been using chromedriver with the following settings: ``` from selenium import webdriver from ...
2019/03/21
[ "https://Stackoverflow.com/questions/55276170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9428990/" ]
You could try giving your svg an id (or class) and then styling it like so: ``` #test{ opacity:0; } #test:hover{ opacity:1; } ``` --- the id should be inside your svg: ``` <svg id="test" .............. > </svg> ``` Im not sure if this is what you exactly mean but its an easy way to do it
I would suggest taking a look at [ngx-svg](https://www.npmjs.com/package/ngx-svg) which allows to create containers and add multiple elements within those containers - in your case circles. It has other elements as well, and there is a documentation, which allows to understand what you have to do as well.
17,779,480
Recently, I've been attempting to defeat one of my main weaknesses in programming in general, random generation. I thought it would be an easy thing to do, but the lack of simple information is killing me on it. I don't want to sound dumb, but it feels to me like most of the information from places like [this](http://f...
2013/07/22
[ "https://Stackoverflow.com/questions/17779480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2577669/" ]
The direct answer to your question is "No, you cannot do what you are asking", and the second answer is "Yes, you are thinking about this all wrong". The reason is that you are generating completely random noise. What you are asking for is coherent noise. They are two completely different animals and you cannot get co...
Rather use cellular automatons. The algorithm that you find [here](http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels) creates similar patterns that you you would like to see: ``` . . . . . . . . . . . . . . . . . . . . # # . . . . . # . . . . . . # # # # . . . # ...
17,779,480
Recently, I've been attempting to defeat one of my main weaknesses in programming in general, random generation. I thought it would be an easy thing to do, but the lack of simple information is killing me on it. I don't want to sound dumb, but it feels to me like most of the information from places like [this](http://f...
2013/07/22
[ "https://Stackoverflow.com/questions/17779480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2577669/" ]
This is a fun little problem, you can solve it with this sort of algorithm: 1. generate a small uniform noise 2. resample it to a higher resolution (giving you a smooth noise image) 3. Apply threshold to get a False/True array 4. Map False/True to '-'/'#' And with a bit of printing formatting it works well. Demonstra...
Rather use cellular automatons. The algorithm that you find [here](http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels) creates similar patterns that you you would like to see: ``` . . . . . . . . . . . . . . . . . . . . # # . . . . . # . . . . . . # # # # . . . # ...
48,166,183
I have a problem which my novice knowledge cannot solve. I'm trying to copy some python-2.x code (which is working) to python-3.x. Now it gives me an error. Here's a snippet of the code: ``` def littleUglyDataCollectionInTheSourceCode(): a = { 'Aabenraa': [842.86917819535, 25.58264089252], 'Aalborg': [...
2018/01/09
[ "https://Stackoverflow.com/questions/48166183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6551344/" ]
In your example `myDict` is a dictionary with strings as keys and lists as values. ``` key = data.kommune.encode("utf-8") ``` will be a bytes object, so there can't ever be any corresponding value for that key in the dictionary. This worked in python2 where automatic conversion was performed, but not anymore in pyth...
You are using `0` as a default value for `rd`, whereas the values in the dict are lists, so if the key is not found, `rd[0]` or `rd[1]` will fail. Instead, use a list or tuple as default, then it should work. ``` rd = myDict.get(key.strip(), [0, 0]) ```
48,166,183
I have a problem which my novice knowledge cannot solve. I'm trying to copy some python-2.x code (which is working) to python-3.x. Now it gives me an error. Here's a snippet of the code: ``` def littleUglyDataCollectionInTheSourceCode(): a = { 'Aabenraa': [842.86917819535, 25.58264089252], 'Aalborg': [...
2018/01/09
[ "https://Stackoverflow.com/questions/48166183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6551344/" ]
In your example `myDict` is a dictionary with strings as keys and lists as values. ``` key = data.kommune.encode("utf-8") ``` will be a bytes object, so there can't ever be any corresponding value for that key in the dictionary. This worked in python2 where automatic conversion was performed, but not anymore in pyth...
And that is why googling the TypeError text didn't lead me to a solution, as my problem were twofold. I forgot about the integrated encoding in Python3. I changed: ``` key = data.kommune.encode("utf-8") rd = myDict.get(key.strip(), 0) ``` to: ``` key = data.kommune rd = myDict.get(key.strip(), [0, 0]) ``` ...
48,166,183
I have a problem which my novice knowledge cannot solve. I'm trying to copy some python-2.x code (which is working) to python-3.x. Now it gives me an error. Here's a snippet of the code: ``` def littleUglyDataCollectionInTheSourceCode(): a = { 'Aabenraa': [842.86917819535, 25.58264089252], 'Aalborg': [...
2018/01/09
[ "https://Stackoverflow.com/questions/48166183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6551344/" ]
You are using `0` as a default value for `rd`, whereas the values in the dict are lists, so if the key is not found, `rd[0]` or `rd[1]` will fail. Instead, use a list or tuple as default, then it should work. ``` rd = myDict.get(key.strip(), [0, 0]) ```
And that is why googling the TypeError text didn't lead me to a solution, as my problem were twofold. I forgot about the integrated encoding in Python3. I changed: ``` key = data.kommune.encode("utf-8") rd = myDict.get(key.strip(), 0) ``` to: ``` key = data.kommune rd = myDict.get(key.strip(), [0, 0]) ``` ...
6,493,681
I have a list of ids in python. For example: ``` x = [1,2,3,4,5,6] ``` And i want to select a list of records in my (mysql ) data-base under the condition that the ids of these records are in x. something like below: ``` SELECT * FROM mytable WHERE id IN x ``` but I don't know who I can do this in python. I have ...
2011/06/27
[ "https://Stackoverflow.com/questions/6493681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/313245/" ]
Try something like this: ``` '(%s)' % ','.join(map(str,x)) ``` This will give you a string that you could use to send to MySql as a valid `IN` clause: ``` (1,2,3,4,5,6) ```
Well, if all of those are known to be numbers of good standing, then you can simply call ``` "SELECT * FROM mytable WHERE ID IN ({0})".format(','.join(x)) ``` If you know that they are numbers but *any* of them might have been from the user, then I might use: ``` "SELECT * FROM mytable WHERE ID IN ({0})".format(','...
11,360,161
I get this error while running a python script (called by ./waf --run): TypeError: abspath() takes exactly 1 argument (2 given) The problem is that it is indeed called with: obj.path.abspath(env). This is not a python issue, because that code worked perfectly before, and it's part of a huge project (ns3) so I doubt t...
2012/07/06
[ "https://Stackoverflow.com/questions/11360161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1502564/" ]
The documentation of the method [`Node.abspath()`](http://docs.waf.googlecode.com/git/apidocs_16/Node.html#waflib.Node.Node.abspath) states it does not take an additional `env` parameter, and I confirmed that it never did by checking the git history. I suggest replacing ``` if not (obj.path.abspath().startswith(launch...
You should have a file name and line number in the traceback. Go to that file and line and find out was "obj" and "obj.path.abspath" are. A simple solution would be to put the offending line in a try/except block to print (or log) more informations, ie: ``` # your code here try: whatever = obj.path.abspath(env) ex...
11,360,161
I get this error while running a python script (called by ./waf --run): TypeError: abspath() takes exactly 1 argument (2 given) The problem is that it is indeed called with: obj.path.abspath(env). This is not a python issue, because that code worked perfectly before, and it's part of a huge project (ns3) so I doubt t...
2012/07/06
[ "https://Stackoverflow.com/questions/11360161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1502564/" ]
The documentation of the method [`Node.abspath()`](http://docs.waf.googlecode.com/git/apidocs_16/Node.html#waflib.Node.Node.abspath) states it does not take an additional `env` parameter, and I confirmed that it never did by checking the git history. I suggest replacing ``` if not (obj.path.abspath().startswith(launch...
The problem came from the fact that apparently waf doesn't like symlinks, the python code must not be prepared for such cases. Problem solved, thanks for your help everybody
48,264,720
I am starting to learn the application of different types of classifiers in python sklearn module. The clf\_LR.predict(X\_predict) predicts the 'Loan\_Status' of the test data. In the training data it is either 1 or 0 depending on loan approval. But the predict gives a numpy array of float values around 0 and 1. I want...
2018/01/15
[ "https://Stackoverflow.com/questions/48264720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8380563/" ]
``` import numpy as np np.round(np.clip(clf_LR.predict(X_predict), 0, 1)) # floats np.round(np.clip(clf_LR.predict(X_predict), 0, 1)).astype(bool) # binary ``` * [numpy.clip](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.clip.html) * [numpy.round](https://docs.scipy.org/doc/numpy-1.13.0/referen...
As said in @Pault comment what you need is a classifier, sklearn has many classifiers! The choice of a classifier to use depend on many factors: The following picture from [sklearn](http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html) can help you to choose : [![The following picture ](https://i.st...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
There are many ways to organise ipython research project. I am managing a team of 5 Data Scientists and 3 Data Engineers and I found those tips to be working well for our usecase: This is a summary of my PyData London talk: <http://www.slideshare.net/vladimirkazantsev/clean-code-in-jupyter-notebook> **1. Create a sh...
You should ideally have a library hierarchy. I would organize it as follows: Package wsautils ---------------- Fundamental, lowest level package [No dependencies] stringutils.py: Contains the most basic files such string manipulation dateutils.py: Date manipulation methods Package wsadata --------------- * Parsing...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
While the given answers cover the topic thoroughly it is still worth mentioning [Cookiecutter](https://cookiecutter.readthedocs.io/en/latest/) which provides a data science boilerplate project structure: ### [Cookiecutter Data Sciencee](https://drivendata.github.io/cookiecutter-data-science/) provides data science te...
You should ideally have a library hierarchy. I would organize it as follows: Package wsautils ---------------- Fundamental, lowest level package [No dependencies] stringutils.py: Contains the most basic files such string manipulation dateutils.py: Date manipulation methods Package wsadata --------------- * Parsing...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
You should ideally have a library hierarchy. I would organize it as follows: Package wsautils ---------------- Fundamental, lowest level package [No dependencies] stringutils.py: Contains the most basic files such string manipulation dateutils.py: Date manipulation methods Package wsadata --------------- * Parsing...
Strange that no one mentioned this. Write out your next project using [nbdev](https://github.com/fastai/nbdev/tree/master/). From the [docs](https://nbdev.fast.ai/), we have Features of Nbdev ----------------- `nbdev` provides the following tools for developers: * **Automatically generate docs** from Jupyter noteboo...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
You should ideally have a library hierarchy. I would organize it as follows: Package wsautils ---------------- Fundamental, lowest level package [No dependencies] stringutils.py: Contains the most basic files such string manipulation dateutils.py: Date manipulation methods Package wsadata --------------- * Parsing...
If you hate notebooks, try out these cookiecutters * [Dr Michael Goerz's cookiecutter](https://github.com/goerz/cookiecutter-pypackage) * [Ionel Cristian Mărieș](https://github.com/ionelmc/cookiecutter-pylibrary) * [University of Washington Escience institute's shablona](https://github.com/uwescience/shablona)
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
There are many ways to organise ipython research project. I am managing a team of 5 Data Scientists and 3 Data Engineers and I found those tips to be working well for our usecase: This is a summary of my PyData London talk: <http://www.slideshare.net/vladimirkazantsev/clean-code-in-jupyter-notebook> **1. Create a sh...
While the given answers cover the topic thoroughly it is still worth mentioning [Cookiecutter](https://cookiecutter.readthedocs.io/en/latest/) which provides a data science boilerplate project structure: ### [Cookiecutter Data Sciencee](https://drivendata.github.io/cookiecutter-data-science/) provides data science te...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
There are many ways to organise ipython research project. I am managing a team of 5 Data Scientists and 3 Data Engineers and I found those tips to be working well for our usecase: This is a summary of my PyData London talk: <http://www.slideshare.net/vladimirkazantsev/clean-code-in-jupyter-notebook> **1. Create a sh...
Strange that no one mentioned this. Write out your next project using [nbdev](https://github.com/fastai/nbdev/tree/master/). From the [docs](https://nbdev.fast.ai/), we have Features of Nbdev ----------------- `nbdev` provides the following tools for developers: * **Automatically generate docs** from Jupyter noteboo...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
There are many ways to organise ipython research project. I am managing a team of 5 Data Scientists and 3 Data Engineers and I found those tips to be working well for our usecase: This is a summary of my PyData London talk: <http://www.slideshare.net/vladimirkazantsev/clean-code-in-jupyter-notebook> **1. Create a sh...
If you hate notebooks, try out these cookiecutters * [Dr Michael Goerz's cookiecutter](https://github.com/goerz/cookiecutter-pypackage) * [Ionel Cristian Mărieș](https://github.com/ionelmc/cookiecutter-pylibrary) * [University of Washington Escience institute's shablona](https://github.com/uwescience/shablona)
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
While the given answers cover the topic thoroughly it is still worth mentioning [Cookiecutter](https://cookiecutter.readthedocs.io/en/latest/) which provides a data science boilerplate project structure: ### [Cookiecutter Data Sciencee](https://drivendata.github.io/cookiecutter-data-science/) provides data science te...
Strange that no one mentioned this. Write out your next project using [nbdev](https://github.com/fastai/nbdev/tree/master/). From the [docs](https://nbdev.fast.ai/), we have Features of Nbdev ----------------- `nbdev` provides the following tools for developers: * **Automatically generate docs** from Jupyter noteboo...
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
While the given answers cover the topic thoroughly it is still worth mentioning [Cookiecutter](https://cookiecutter.readthedocs.io/en/latest/) which provides a data science boilerplate project structure: ### [Cookiecutter Data Sciencee](https://drivendata.github.io/cookiecutter-data-science/) provides data science te...
If you hate notebooks, try out these cookiecutters * [Dr Michael Goerz's cookiecutter](https://github.com/goerz/cookiecutter-pypackage) * [Ionel Cristian Mărieș](https://github.com/ionelmc/cookiecutter-pylibrary) * [University of Washington Escience institute's shablona](https://github.com/uwescience/shablona)
36,427,747
I'm using Ipython Notebook to my research. As my file grows bigger, I constantly extract code out, things like plot method, fitting method etc. I think I need a way to organize this. Is there any good way to do it?? --- Currently, I do this by: ``` data/ helpers/ my_notebook.ipynb import_file.py ``` I store data...
2016/04/05
[ "https://Stackoverflow.com/questions/36427747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1794744/" ]
Strange that no one mentioned this. Write out your next project using [nbdev](https://github.com/fastai/nbdev/tree/master/). From the [docs](https://nbdev.fast.ai/), we have Features of Nbdev ----------------- `nbdev` provides the following tools for developers: * **Automatically generate docs** from Jupyter noteboo...
If you hate notebooks, try out these cookiecutters * [Dr Michael Goerz's cookiecutter](https://github.com/goerz/cookiecutter-pypackage) * [Ionel Cristian Mărieș](https://github.com/ionelmc/cookiecutter-pylibrary) * [University of Washington Escience institute's shablona](https://github.com/uwescience/shablona)
54,292,049
I play to HackNet game and i have to guess a word to bypass a firewall. The key makes 6 characters long and contains the letters K,K,K,U,A,N. What is the simplest way to generate all possible combinations either in bash or in python ? (bonus point for bash)
2019/01/21
[ "https://Stackoverflow.com/questions/54292049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10945277/" ]
Git uses a tree organization that is only allowed to be added new nodes (commits). If you really want to delete a wrongly pushed commit you must update your repository locally and than force push to the according remote. I found an issue talking about it. [How to undo the initial commit on a remote repository in git?]...
use `git revert <commit_id_to_be_reverted>`
54,292,049
I play to HackNet game and i have to guess a word to bypass a firewall. The key makes 6 characters long and contains the letters K,K,K,U,A,N. What is the simplest way to generate all possible combinations either in bash or in python ? (bonus point for bash)
2019/01/21
[ "https://Stackoverflow.com/questions/54292049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10945277/" ]
You should use `git rebase -i --root` and squash the commit removing the `node_modules` folder with the first commit.
use `git revert <commit_id_to_be_reverted>`
54,292,049
I play to HackNet game and i have to guess a word to bypass a firewall. The key makes 6 characters long and contains the letters K,K,K,U,A,N. What is the simplest way to generate all possible combinations either in bash or in python ? (bonus point for bash)
2019/01/21
[ "https://Stackoverflow.com/questions/54292049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10945277/" ]
You should use `git rebase -i --root` and squash the commit removing the `node_modules` folder with the first commit.
Git uses a tree organization that is only allowed to be added new nodes (commits). If you really want to delete a wrongly pushed commit you must update your repository locally and than force push to the according remote. I found an issue talking about it. [How to undo the initial commit on a remote repository in git?]...
1,265,078
I want to used python to get the executed file version, and i know the [pefile.py](http://code.google.com/p/pefile/) how to used it to do this? notes: the executed file may be not completely.
2009/08/12
[ "https://Stackoverflow.com/questions/1265078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154106/" ]
This is the best answer I think you can find: ``` import pefile pe = pefile.PE("/path/to/something.exe") print hex(pe.VS_VERSIONINFO.Length) print hex(pe.VS_VERSIONINFO.Type) print hex(pe.VS_VERSIONINFO.ValueLength) print hex(pe.VS_FIXEDFILEINFO.Signature) print hex(pe.VS_FIXEDFILEINFO.FileFlags) print hex(pe.VS_FIXE...
I'm not sure that I understand your problem correctly, but if it's something along the lines of using pefile to retrieve the version of a provided executable, then perhaps (taken from [the tutorial][1]) ``` import pefile pe = pefile.PE("/path/to/pefile.exe") print pe.dump_info() ``` will provide you with the version...
62,017,437
I am new to programming. I have made a python script. It runs without errors in pycharm. Using pyinstaller i tried to make an exe. When i run the exe in build or dist folder or even through command prompt, it gives me the error 'Failed to execute Script Main' I am attaching the warnings file link: <https://drive.goog...
2020/05/26
[ "https://Stackoverflow.com/questions/62017437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13605404/" ]
There is one pip script for each virtual environment. So when you install a python module it get installed into the projectname\venv\Lib\site-packages directory. When you run pyinstaller from terminal to make the executable, pyinstaller checks for dependencies in Sys.path . But that path does not include the projectna...
I know I write this 10 months after but i run into the same problem and i know the solution. so, maybe some people who have the same problem could get help. If your script has any additional files such as db,csv,png etc. you should add this files same directory. in this way you could solve the problem i guess. at leas...
48,021,748
I have two mysql database one is localhost and another is in server now, am going to create simple app in python using flask for that application i would like to connect the both mysql DB (local and server). Any one please suggest how to connect multiple DB into flask. ``` app = Flask(__name__) client = MongoClient()...
2017/12/29
[ "https://Stackoverflow.com/questions/48021748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5483189/" ]
I had the same issue, finally figured it out. Instead of using ``` client = MongoClient() client = MongoClient('localhost', 27017) db = client.sampleDB1 ``` Delete all that and try this: ``` mongo1 = PyMongo(app, uri = 'mongodb://localhost:27017/Database1') mongo2 = PyMongo(app, uri = 'mongodb://localhost:27017/Da...
create model.py and separate instances of 2 databases inside it, then in app.py: ``` app = Flask(__name__) app.config['MODEL'] = model.my1st_database() app.config['MODEL2'] = model.my2nd_database() ``` works for me :)
48,021,748
I have two mysql database one is localhost and another is in server now, am going to create simple app in python using flask for that application i would like to connect the both mysql DB (local and server). Any one please suggest how to connect multiple DB into flask. ``` app = Flask(__name__) client = MongoClient()...
2017/12/29
[ "https://Stackoverflow.com/questions/48021748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5483189/" ]
``` #This technique can be used to connect to multiple databases or database servers: app = Flask(__name__) # connect to MongoDB with the defaults mongo1 = PyMongo(app) # connect to another MongoDB database on the same host app.config['MONGO2_DBNAME'] = 'dbname_two' mongo2 = PyMongo(app, config_prefix='MONGO2') # co...
create model.py and separate instances of 2 databases inside it, then in app.py: ``` app = Flask(__name__) app.config['MODEL'] = model.my1st_database() app.config['MODEL2'] = model.my2nd_database() ``` works for me :)
48,021,748
I have two mysql database one is localhost and another is in server now, am going to create simple app in python using flask for that application i would like to connect the both mysql DB (local and server). Any one please suggest how to connect multiple DB into flask. ``` app = Flask(__name__) client = MongoClient()...
2017/12/29
[ "https://Stackoverflow.com/questions/48021748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5483189/" ]
I had the same issue, finally figured it out. Instead of using ``` client = MongoClient() client = MongoClient('localhost', 27017) db = client.sampleDB1 ``` Delete all that and try this: ``` mongo1 = PyMongo(app, uri = 'mongodb://localhost:27017/Database1') mongo2 = PyMongo(app, uri = 'mongodb://localhost:27017/Da...
``` #This technique can be used to connect to multiple databases or database servers: app = Flask(__name__) # connect to MongoDB with the defaults mongo1 = PyMongo(app) # connect to another MongoDB database on the same host app.config['MONGO2_DBNAME'] = 'dbname_two' mongo2 = PyMongo(app, config_prefix='MONGO2') # co...
57,010,207
I want to use R to split some chat messages, here is an example: ``` example <- "[29.01.18, 23:33] Alice: Ist das hier ein Chatverlauf?\n[29.01.18, 23:45] Bob: Ja ist es!\n[29.01.18, 23:45] Bob: Der ist dazu da die funktionsweise des Parsers zu demonstrieren\n[29.01.18, 23:46] Alice: ‎PTT-20180129-WA0025.opus (Datei a...
2019/07/12
[ "https://Stackoverflow.com/questions/57010207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6039913/" ]
You could add a negative lookahead `(?!^)` to assert not the start of the string. Your updated line might look like: ``` chat <- strsplit(example,"(?!^)(?=\\[\\d\\d.\\d\\d.\\d\\d, \\d\\d:\\d\\d\\])",perl=TRUE) ``` [R demo](https://ideone.com/KlRaFp) Result ``` [1] "[29.01.18, 23:33] Alice: Ist das hier ein Chatv...
You can use `stringi` and extract the info you want by slightly modifying the end of your pattern (i.e., matching everything until the next `[`). You could include more of your pattern to ensure there aren't any false-matches but this should get your started. Good luck! ``` library(stringi) stri_extract_all(example, ...
25,567,791
I've been trying for several days now to send a python array by i2c. ``` data = [x,x,x,x] # `x` is a number from 0 to 127. bus.write_i2c_block_data(i2c_address, 0, data) bus.write_i2c_block_data(addr, cmd, array) ``` In the function above: addr - arduino i2c adress; cmd - Not sure what this is; array - python arra...
2014/08/29
[ "https://Stackoverflow.com/questions/25567791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3866306/" ]
The function is the good one. But you should take care of some points: * bus.write\_i2c\_block\_data(addr, cmd, []) send the value of cmd AND the values in the list on the I2C bus. So ``` bus.write_i2c_block_data(0x20, 42, [12, 23, 34, 45]) ``` doesn't send 4 bytes but 5 bytes to the device. I doesn't know how t...
It took me a while,but i got it working. On the arduino side: ``` int count = 0; ... ... void receiveData(int numByte){ while(Wire.available()){ if(count < 4){ byteArray[count] = Wire.read(); count++; } else{ count = 0; byteArray[count] = Wire.read(); } ...
25,567,791
I've been trying for several days now to send a python array by i2c. ``` data = [x,x,x,x] # `x` is a number from 0 to 127. bus.write_i2c_block_data(i2c_address, 0, data) bus.write_i2c_block_data(addr, cmd, array) ``` In the function above: addr - arduino i2c adress; cmd - Not sure what this is; array - python arra...
2014/08/29
[ "https://Stackoverflow.com/questions/25567791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3866306/" ]
The function is the good one. But you should take care of some points: * bus.write\_i2c\_block\_data(addr, cmd, []) send the value of cmd AND the values in the list on the I2C bus. So ``` bus.write_i2c_block_data(0x20, 42, [12, 23, 34, 45]) ``` doesn't send 4 bytes but 5 bytes to the device. I doesn't know how t...
cmd is offset on which you want to write a data. so its like ``` bus.write_byte(i2c_address, offset, byte) ``` but if you want to write array of bytes then you need to write block data so your code will look like this ``` bus.write_i2c_block_data(i2c_address, offset, [array_of_bytes]) ```
25,567,791
I've been trying for several days now to send a python array by i2c. ``` data = [x,x,x,x] # `x` is a number from 0 to 127. bus.write_i2c_block_data(i2c_address, 0, data) bus.write_i2c_block_data(addr, cmd, array) ``` In the function above: addr - arduino i2c adress; cmd - Not sure what this is; array - python arra...
2014/08/29
[ "https://Stackoverflow.com/questions/25567791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3866306/" ]
It took me a while,but i got it working. On the arduino side: ``` int count = 0; ... ... void receiveData(int numByte){ while(Wire.available()){ if(count < 4){ byteArray[count] = Wire.read(); count++; } else{ count = 0; byteArray[count] = Wire.read(); } ...
cmd is offset on which you want to write a data. so its like ``` bus.write_byte(i2c_address, offset, byte) ``` but if you want to write array of bytes then you need to write block data so your code will look like this ``` bus.write_i2c_block_data(i2c_address, offset, [array_of_bytes]) ```
12,758,591
Are there any libraries in Python that does or allows Text To Speech Conversion using Mac Lion's built in text to speech engine? I did google but most are windows based. I tried pyttx. I tried to run ``` import pyttsx engine = pyttsx.init() engine.say('Sally sells seashells by the seashore.') engine.say('The quick br...
2012/10/06
[ "https://Stackoverflow.com/questions/12758591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1657827/" ]
Wouldn't it be much simpler to do this? ``` from os import system system('say Hello world!') ``` You can enter `man say` to see other things you can do with the `say` command. However, if you want some more advanced features, importing `AppKit` would also be a possibility, although some Cocoa/Objective C knowledge ...
If you are targeting Mac OS X as your platform - PyObjC and NSSpeechSynthesizer is your best bet. Here is a quick example for you ``` #!/usr/bin/env python from AppKit import NSSpeechSynthesizer import time import sys if len(sys.argv) < 2: text = raw_input('type text to speak> ') else: text = sys.argv[1] n...
12,758,591
Are there any libraries in Python that does or allows Text To Speech Conversion using Mac Lion's built in text to speech engine? I did google but most are windows based. I tried pyttx. I tried to run ``` import pyttsx engine = pyttsx.init() engine.say('Sally sells seashells by the seashore.') engine.say('The quick br...
2012/10/06
[ "https://Stackoverflow.com/questions/12758591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1657827/" ]
Wouldn't it be much simpler to do this? ``` from os import system system('say Hello world!') ``` You can enter `man say` to see other things you can do with the `say` command. However, if you want some more advanced features, importing `AppKit` would also be a possibility, although some Cocoa/Objective C knowledge ...
This might work: ``` import subprocess subprocess.call(["say","Hello World! (MESSAGE)"]) ```
12,758,591
Are there any libraries in Python that does or allows Text To Speech Conversion using Mac Lion's built in text to speech engine? I did google but most are windows based. I tried pyttx. I tried to run ``` import pyttsx engine = pyttsx.init() engine.say('Sally sells seashells by the seashore.') engine.say('The quick br...
2012/10/06
[ "https://Stackoverflow.com/questions/12758591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1657827/" ]
If you are targeting Mac OS X as your platform - PyObjC and NSSpeechSynthesizer is your best bet. Here is a quick example for you ``` #!/usr/bin/env python from AppKit import NSSpeechSynthesizer import time import sys if len(sys.argv) < 2: text = raw_input('type text to speak> ') else: text = sys.argv[1] n...
This might work: ``` import subprocess subprocess.call(["say","Hello World! (MESSAGE)"]) ```
53,622,737
I have a Pandas Dataframe which has columns which look something like this: ``` df: Column0 Column1 Column2 'MSC' '1' 'R2' 'MIS' 'Tuesday' '22' '13' 'Finance' 'Monday' ``` So overall, in these columns are actual strings but also numeric values (integers) which are in string format....
2018/12/04
[ "https://Stackoverflow.com/questions/53622737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10027078/" ]
100% agree with the comments—mixing dtypes in columns is a terrible idea, performance wise. For reference, however, I would do this with `pd.to_numeric` and `fillna`: ``` df2 = df.apply(pd.to_numeric, errors='coerce').fillna(df) print(df2) Column0 Column1 Column2 0 MSC 1 R2 1 MIS Tuesday ...
I would apply `pd.to_numeric` with `errors='coerce'`, and `update` the original dataframe according to the results (see caveats in comments): ``` # show original string type: df.loc[0,'Column1'] # '1' df.update(df.apply(pd.to_numeric, errors='coerce')) >>> df Column0 Column1 Column2 0 MSC 1 R2 1 ...
53,622,737
I have a Pandas Dataframe which has columns which look something like this: ``` df: Column0 Column1 Column2 'MSC' '1' 'R2' 'MIS' 'Tuesday' '22' '13' 'Finance' 'Monday' ``` So overall, in these columns are actual strings but also numeric values (integers) which are in string format....
2018/12/04
[ "https://Stackoverflow.com/questions/53622737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10027078/" ]
100% agree with the comments—mixing dtypes in columns is a terrible idea, performance wise. For reference, however, I would do this with `pd.to_numeric` and `fillna`: ``` df2 = df.apply(pd.to_numeric, errors='coerce').fillna(df) print(df2) Column0 Column1 Column2 0 MSC 1 R2 1 MIS Tuesday ...
Or you could simply use the `isnumeric()` method of `str`. I like it because the syntax is clear, although according to coldspeed's comment, this can become very slow on large df. > > `df = df.applymap(lambda x: int(x) if x.isnumeric() else x)` > > > Example: ``` In [1]: import pandas as pd In [2]: df = pd.Data...
53,622,737
I have a Pandas Dataframe which has columns which look something like this: ``` df: Column0 Column1 Column2 'MSC' '1' 'R2' 'MIS' 'Tuesday' '22' '13' 'Finance' 'Monday' ``` So overall, in these columns are actual strings but also numeric values (integers) which are in string format....
2018/12/04
[ "https://Stackoverflow.com/questions/53622737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10027078/" ]
100% agree with the comments—mixing dtypes in columns is a terrible idea, performance wise. For reference, however, I would do this with `pd.to_numeric` and `fillna`: ``` df2 = df.apply(pd.to_numeric, errors='coerce').fillna(df) print(df2) Column0 Column1 Column2 0 MSC 1 R2 1 MIS Tuesday ...
Using `to_numeric` + `ignore` ``` df=df.applymap(lambda x : pd.to_numeric(x,errors='ignore')) df Column0 Column1 Column2 0 MSC 1 R2 1 MIS Tuesday 22 2 13 Finance Monday df.applymap(type) Column0 Column1 Column2 0 <class 'str'> ...
7,504,129
I have a variable, `fulltext`, which contains the full text of what I want the description of a new changelist in P4V to be. There are already files in the default changelist. I want to use python to populate the description of a new changelist (based on default) with the contents of `fulltext`. How can this be done....
2011/09/21
[ "https://Stackoverflow.com/questions/7504129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/343381/" ]
If you're trying to write Python programs that work against Perforce, you might find P4Python helpful: <http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html>
It is easiest if you have the changelist numbers that you know you are going to change. ``` #changeListIDNumber is the desired changelist to edit import P4 p4 = P4.connect() cl = p4.fetch_changelist(changeListIDNumber) cl['Description'] = 'your description here' p4.save_change(cl) ``` If you...
7,504,129
I have a variable, `fulltext`, which contains the full text of what I want the description of a new changelist in P4V to be. There are already files in the default changelist. I want to use python to populate the description of a new changelist (based on default) with the contents of `fulltext`. How can this be done....
2011/09/21
[ "https://Stackoverflow.com/questions/7504129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/343381/" ]
If you're trying to write Python programs that work against Perforce, you might find P4Python helpful: <http://www.perforce.com/perforce/doc.current/manuals/p4script/03_python.html>
on shell this works, you may use in any language echo "Change:new\nClient:myclient\nUser:me\nStatus:new\nDescription:test" | p4 change -i
7,504,129
I have a variable, `fulltext`, which contains the full text of what I want the description of a new changelist in P4V to be. There are already files in the default changelist. I want to use python to populate the description of a new changelist (based on default) with the contents of `fulltext`. How can this be done....
2011/09/21
[ "https://Stackoverflow.com/questions/7504129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/343381/" ]
It is easiest if you have the changelist numbers that you know you are going to change. ``` #changeListIDNumber is the desired changelist to edit import P4 p4 = P4.connect() cl = p4.fetch_changelist(changeListIDNumber) cl['Description'] = 'your description here' p4.save_change(cl) ``` If you...
on shell this works, you may use in any language echo "Change:new\nClient:myclient\nUser:me\nStatus:new\nDescription:test" | p4 change -i
45,406,847
I use Django to send email,everything is OK when running on development environment, which uses command "python manage.py runserver 0.0.0.0:8100". But in the production environment which deployed by nginx+uwsgi+Django do not work. Here is the code: ``` #Email settings EMAIL_HOST='smtp.exmail.qq.com' EMAIL_PORT='465'...
2017/07/31
[ "https://Stackoverflow.com/questions/45406847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6133601/" ]
You could wrapping the check in a `setTimeout`: ``` $(".menu-toggle").first().click(function () { setTimeout(function() { if (!$("#wrapper").hasClass("menu-active")) { $("#wrapper").find("div:first").addClass("overlay"); } if ($("#wrapper").hasClass("menu-active")) { ...
Make the following, ``` <link rel="preload" href="path-to-your-script.js" as="script"> <script> var scriptPriority = document.createElement('script'); scriptPriority.src = 'path-to-your-script.js'; document.body.appendChild(scriptPriority); </script> ``` About: Link rel Preload Link rel preload is m...
71,461,517
We have just updated our jenkins (2.337) and the python console output has gone weird: [![enter image description here](https://i.stack.imgur.com/n2Yxn.png)](https://i.stack.imgur.com/n2Yxn.png) I've searched the jenkins settings (ANSI plugin etc) and I can change the inner colours but the gray background and line br...
2022/03/13
[ "https://Stackoverflow.com/questions/71461517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2325752/" ]
We had a similar problem ... we had an almost Black Background with Black Text We found that the Extra CSS in the Theme section of the Jenkins Configuration has changed. After putting it through a code formatter (there are no new lines or whitespace in the field) we had the following for the console-output: ``` .con...
When you have broken console colors (black font on black screen) after jenkins update, * Go to Manage Jenkins -> configure system * scroll to theme * click add -> extra CSS put this in the new field: ``` .console-output{ color:#fff!important; } ``` You can also add any other CSS to please your eye.
14,081,949
How to turn off collisions for some objects and then again turn it on using pymunk lib in python? Let me show you the example, based on the code below. I want all red balls to go through first border of lines and stop on the lower border. Blue balls should still collide with upper border. What needs to be changed in...
2012/12/29
[ "https://Stackoverflow.com/questions/14081949", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789021/" ]
Chipmunk has a few options filtering collisions: <http://chipmunk-physics.net/release/ChipmunkLatest-Docs/#cpShape-Filtering> It sounds like you just need to use a layers bitmask though. ex: ``` # This layer bit is for balls colliding with other balls # I'm only guessing that you want this though. ball_layer = 1 # T...
In Pymunk you can use the [ShapeFilter](http://www.pymunk.org/en/latest/pymunk.html#pymunk.ShapeFilter) class to set the categories (layers) with which an object can collide. I put the upper and lower lines into the categories 1 and 2 and then set the masks of the balls so that they ignore these layers. You need to und...
44,705,385
I have this BT speaker , with in built mic , <http://www.intex.in/speakers/bluetooth-speakers/it-11s-bt> i want to build something like google home with it , using python .Please guide me.
2017/06/22
[ "https://Stackoverflow.com/questions/44705385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8071763/" ]
Try with that : ``` function cari($d,$p) { $this->db->select('cf_pakar,gejala'); $this->db->from('gejalapenyakit'); $this->db->where('id_penyakit',$p); $this->db->where_in('id_gejala',$d); return $this->db->get()->result(); } ``` And your `$d = ('1','2','3','4','5')` should be `$d = ['1','2','3','4...
You need to send ',' seperated values in query. $d = implode(",",$d); This will work.
44,705,385
I have this BT speaker , with in built mic , <http://www.intex.in/speakers/bluetooth-speakers/it-11s-bt> i want to build something like google home with it , using python .Please guide me.
2017/06/22
[ "https://Stackoverflow.com/questions/44705385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8071763/" ]
Try with that : ``` function cari($d,$p) { $this->db->select('cf_pakar,gejala'); $this->db->from('gejalapenyakit'); $this->db->where('id_penyakit',$p); $this->db->where_in('id_gejala',$d); return $this->db->get()->result(); } ``` And your `$d = ('1','2','3','4','5')` should be `$d = ['1','2','3','4...
Answered : Initially i use foreach to make my : ``` $input = $this->input->post('input'); $i = 0; foreach($input as $i){ $i++; $d = $d.$i.','; $d = ('1','2','3','4','5'); ``` and when i use $input for parameter, its work perfectly
64,902,105
I have a requirement below but I am getting some error: Write a separate Privileges class. The class should have one attribute, privileges, that stores a list of strings.Move the show\_privileges() method to this class. Make a Privileges instance as an attribute in the Admin class. Create a new instance of Admin and u...
2020/11/18
[ "https://Stackoverflow.com/questions/64902105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14179096/" ]
As stated in the related questions, the easiest thing to do is to use an index instead as it requires no unsafe code. I might write it like this: ``` pub fn insert<'a, K: Eq, V>(this: &'a mut Vec<(K, V)>, key: K, val: V) -> &'a mut V { let idx = this .iter() .enumerate() .find_map(|(i, (k, ...
Safe alternative ---------------- Firstly, here is what I would suggest instead. You can iterate over the `Vec` once to get the index of the target value via `position(|x| x == y)`. You are then able to match the now owned value and continue like before. This should have very similar performance to your previous versi...
44,913,971
I'm coding a little python program for ROT13. If you don't know what it means, it means it will replace the letter of the alphabet to 13th letter in front of it therefore 'a' would become 'n'. A user will ask for an input and I shall replace each character in the sentence to the 13th letter in front. This means I ne...
2017/07/04
[ "https://Stackoverflow.com/questions/44913971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7637737/" ]
[Vertically concatenate](https://www.mathworks.com/help/matlab/ref/vertcat.html) the matrices inside the cell arrays and use `intersect` with the [`'rows'`](https://www.mathworks.com/help/matlab/ref/intersect.html#btcnv0p-12) flag. i.e. ``` Q1={[1 2 3 4], [3 2 4 1], [4 2 1 3]}; Q2={[2 4 3 1], [1 2 3 4], [1 2 4 3]}; Q...
You can do it by using two loops and check all off them. ``` q1=[1 2 3 4; 3 2 4 1; 4 2 1 3]; q2=[2 4 3 1; 1 2 3 4; 1 2 4 3]; %find the size of matrix [m1,n1] = size(q1); [m2] = size(q2,1); for (ii=1:m1) for (jj=1:m2) %if segments are equal, it will return 1 %if sum of same segment = 4 it means t...
44,092,459
Undertaking a task to Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example ``` power(2, 3) => 8 ``` Note: Don't use ``` 2 ** 3 ``` and don't use ``` Math.pow(2, 3) ``` I have tried this ``` def power(a,b): return eval(((str(a)+"*")*b)[:-1]) ``` And ...
2017/05/21
[ "https://Stackoverflow.com/questions/44092459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173798/" ]
You can use a for loop ``` x=1 for i in range(b): x=x*a print(x) ```
``` def power(a, b): if b == 0: return 1 else: return a ** b ```
44,092,459
Undertaking a task to Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example ``` power(2, 3) => 8 ``` Note: Don't use ``` 2 ** 3 ``` and don't use ``` Math.pow(2, 3) ``` I have tried this ``` def power(a,b): return eval(((str(a)+"*")*b)[:-1]) ``` And ...
2017/05/21
[ "https://Stackoverflow.com/questions/44092459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173798/" ]
Using eval is a terrible idea, but if you really wanted to then using `join()` would be a better way to create the string: ``` def power(a, b): return eval('*'.join([str(a)]*b)) >>> power(2, 3) 8 ``` If you add `['1']` to the front then the `0` exponent behaves properly: ``` def power(a, b): return eval('*...
``` def power(a, b): if b == 0: return 1 else: return a ** b ```
44,092,459
Undertaking a task to Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example ``` power(2, 3) => 8 ``` Note: Don't use ``` 2 ** 3 ``` and don't use ``` Math.pow(2, 3) ``` I have tried this ``` def power(a,b): return eval(((str(a)+"*")*b)[:-1]) ``` And ...
2017/05/21
[ "https://Stackoverflow.com/questions/44092459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173798/" ]
This worked fine ``` def power(a,b): if b == 0: return 1 else: return eval(((str(a)+"*")*b)[:-1]) ```
``` def power(a, b): if b == 0: return 1 else: return a ** b ```
44,092,459
Undertaking a task to Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example ``` power(2, 3) => 8 ``` Note: Don't use ``` 2 ** 3 ``` and don't use ``` Math.pow(2, 3) ``` I have tried this ``` def power(a,b): return eval(((str(a)+"*")*b)[:-1]) ``` And ...
2017/05/21
[ "https://Stackoverflow.com/questions/44092459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173798/" ]
``` def power(theNumber, thePower): #basically, multiply the number for power times try: theNumber=int(theNumber) thePower=int(thePower) if theNumber == 0: return 0 elif thePower == 0: return 1 else: return theNumber * power(theNumber,thePower-1) except exception as err: ...
``` def power(a, b): if b == 0: return 1 else: return a ** b ```
44,092,459
Undertaking a task to Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example ``` power(2, 3) => 8 ``` Note: Don't use ``` 2 ** 3 ``` and don't use ``` Math.pow(2, 3) ``` I have tried this ``` def power(a,b): return eval(((str(a)+"*")*b)[:-1]) ``` And ...
2017/05/21
[ "https://Stackoverflow.com/questions/44092459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173798/" ]
You should avoid `eval` by all costs, especially when it's very simple to implement pure algorithmic efficient solution. Classic efficient algorithm is [Exponentiation\_by\_squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring). Instead of computing and multiplying numbers `n` times, you can always divide ...
``` def power(a, b): if b == 0: return 1 else: return a ** b ```
898,091
I have previously read Spolsky's article on character-encoding, as well as [this from dive into python 3](http://diveintopython3.org/strings.html). I know php is getting Unicode at some point, but I am having trouble understanding why this is such a big deal. If php-CLI is being used, ok it makes sense. However, in th...
2009/05/22
[ "https://Stackoverflow.com/questions/898091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Well, for one thing you need to somehow generate the strings the browser displays :-)
There's an awesome FAQ section on Unicode and the Web [here.](http://unicode.org/faq/unicode_web.html) See if it answers some of your questions.
898,091
I have previously read Spolsky's article on character-encoding, as well as [this from dive into python 3](http://diveintopython3.org/strings.html). I know php is getting Unicode at some point, but I am having trouble understanding why this is such a big deal. If php-CLI is being used, ok it makes sense. However, in th...
2009/05/22
[ "https://Stackoverflow.com/questions/898091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
PHP does "support" UTF8, look at the mbstring[1](http://uk2.php.net/mbstring) extension. Most of the problem comes from PHP developers who don't use the mb\* functions when dealing with UTF8 data. UTF8 characters are often more than one character so you need to use functions which appreciate that fact like mb\_strpos[...
Well, for one thing you need to somehow generate the strings the browser displays :-)
898,091
I have previously read Spolsky's article on character-encoding, as well as [this from dive into python 3](http://diveintopython3.org/strings.html). I know php is getting Unicode at some point, but I am having trouble understanding why this is such a big deal. If php-CLI is being used, ok it makes sense. However, in th...
2009/05/22
[ "https://Stackoverflow.com/questions/898091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
The PHP string functions often treat strings as sequences of 8-byte characters. I've had all sorts of issues with Chinese text going through the string functions. `substr()`, for example, can cut a multi-byte character in half, which causes all manner of problems for XML parsers.
There's an awesome FAQ section on Unicode and the Web [here.](http://unicode.org/faq/unicode_web.html) See if it answers some of your questions.
898,091
I have previously read Spolsky's article on character-encoding, as well as [this from dive into python 3](http://diveintopython3.org/strings.html). I know php is getting Unicode at some point, but I am having trouble understanding why this is such a big deal. If php-CLI is being used, ok it makes sense. However, in th...
2009/05/22
[ "https://Stackoverflow.com/questions/898091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
PHP does "support" UTF8, look at the mbstring[1](http://uk2.php.net/mbstring) extension. Most of the problem comes from PHP developers who don't use the mb\* functions when dealing with UTF8 data. UTF8 characters are often more than one character so you need to use functions which appreciate that fact like mb\_strpos[...
There's an awesome FAQ section on Unicode and the Web [here.](http://unicode.org/faq/unicode_web.html) See if it answers some of your questions.
898,091
I have previously read Spolsky's article on character-encoding, as well as [this from dive into python 3](http://diveintopython3.org/strings.html). I know php is getting Unicode at some point, but I am having trouble understanding why this is such a big deal. If php-CLI is being used, ok it makes sense. However, in th...
2009/05/22
[ "https://Stackoverflow.com/questions/898091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
PHP does "support" UTF8, look at the mbstring[1](http://uk2.php.net/mbstring) extension. Most of the problem comes from PHP developers who don't use the mb\* functions when dealing with UTF8 data. UTF8 characters are often more than one character so you need to use functions which appreciate that fact like mb\_strpos[...
The PHP string functions often treat strings as sequences of 8-byte characters. I've had all sorts of issues with Chinese text going through the string functions. `substr()`, for example, can cut a multi-byte character in half, which causes all manner of problems for XML parsers.
42,512,141
I have written the following simple program which should print out all events detected by `pygame.event.get()`. ``` import pygame, sys from pygame.locals import * display = pygame.display.set_mode((300, 300)) pygame.init() while True: for event in pygame.event.get(): print(event) if event.type ==...
2017/02/28
[ "https://Stackoverflow.com/questions/42512141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4191155/" ]
If you're working in a virtualenv, don't use the `virtualenv` command. Use `python3 -m venv`. Then install pygame (*e.g.* `pip3 install hg+http://bitbucket.org/pygame/pygame`). See [this thread](https://bitbucket.org/pygame/pygame/issues/203/window-does-not-get-focus-on-os-x-with#comment-32656108) for more details o...
Firstly i doubt you are but pygame only registers inputs when your focused on the pygame screen so there's that. I don't have a direct answer to your question so sorry but i do have my solution or work around to it. Because i dislike the normal event system i use pygame.key.get\_pressed() (<https://www.pygame.org/docs/...