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
10,354,000
I using python 2.7 and openCV 2.3.1 (win 7). I trying open video file: ``` stream = cv.VideoCapture("test1.avi") if stream.isOpened() == False: print "Cannot open input video!" exit() ``` But I have warning: ``` warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394) ``` If use video ca...
2012/04/27
[ "https://Stackoverflow.com/questions/10354000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1361499/" ]
Try using `cv.CaptureFromFile()` instead. Copy this code if you must: [Watch Video in Python with OpenCV](http://web.michaelchughes.com/how-to/watch-video-in-python-with-opencv).
you can use the new interface of OpenCV (cv2), the object oriented one, which is binded from c++. I find it easier and more readable. note: if your open a picture with this, the fps doesn't mean anything, so the picture stays still. ``` import cv2 import sys try: vidFile = cv2.VideoCapture(sys.argv[1]) except: ...
10,354,000
I using python 2.7 and openCV 2.3.1 (win 7). I trying open video file: ``` stream = cv.VideoCapture("test1.avi") if stream.isOpened() == False: print "Cannot open input video!" exit() ``` But I have warning: ``` warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394) ``` If use video ca...
2012/04/27
[ "https://Stackoverflow.com/questions/10354000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1361499/" ]
Try using `cv.CaptureFromFile()` instead. Copy this code if you must: [Watch Video in Python with OpenCV](http://web.michaelchughes.com/how-to/watch-video-in-python-with-opencv).
As from [this answer](https://stackoverflow.com/a/11703998/623999), try copying all the `.dll` files from your OpenCV installation into `C:\Python27`.
10,354,000
I using python 2.7 and openCV 2.3.1 (win 7). I trying open video file: ``` stream = cv.VideoCapture("test1.avi") if stream.isOpened() == False: print "Cannot open input video!" exit() ``` But I have warning: ``` warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl_v2.hpp:394) ``` If use video ca...
2012/04/27
[ "https://Stackoverflow.com/questions/10354000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1361499/" ]
you can use the new interface of OpenCV (cv2), the object oriented one, which is binded from c++. I find it easier and more readable. note: if your open a picture with this, the fps doesn't mean anything, so the picture stays still. ``` import cv2 import sys try: vidFile = cv2.VideoCapture(sys.argv[1]) except: ...
As from [this answer](https://stackoverflow.com/a/11703998/623999), try copying all the `.dll` files from your OpenCV installation into `C:\Python27`.
43,044,060
There is this similar [question](https://stackoverflow.com/questions/22214086/python-a-program-to-find-the-length-of-the-longest-run-in-a-given-list), but not quite what I am asking. Let's say I have a list of ones and zeroes: ``` # i.e. [1, 0, 0, 0, 1, 1, 1, 1, 0, 1] sample = np.random.randint(0, 2, (10,)).tolist() ...
2017/03/27
[ "https://Stackoverflow.com/questions/43044060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3120489/" ]
You can first create tuples of indices and values with `enumerate(..)`. Next you `groupby` but on the second element of the tuple, and finally you map them back on the second index. Like: ``` **map(lambda x:x[0][0],** # obtain the index of the first element sorted([list(l) for _,l in itertools.groupby(**enumerate(...
You can use a `groupby` the `sorted` function with generator function to do this efficiently. ``` from itertools import groupby from operator import itemgetter data = [1, 0, 0, 0, 1, 1, 1, 1, 0, 1] def gen(items): for _, elements in groupby(enumerate(items)): indexes, values = zip(*elements) yiel...
60,182,910
In my droplet is running several PHP websites, recently I tried to deploy a Django website that I build. But it's doesn't work properly. I will explain the step that I did. 1, Pointed a Domain name to my droplet. 2, Added Domain name using Plesk Add Domain Option. 3, Uploaded the Django files to httpdocs by Plesk ...
2020/02/12
[ "https://Stackoverflow.com/questions/60182910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9892045/" ]
[Django Runserver is not a production one](https://vsupalov.com/django-runserver-in-production/), it should be used only for development. That's why you need to explicitly type in the port and it sometimes go down because of code reload or other triggers. Check [Gunicorn](https://gunicorn.org/) for example, as a prod...
I suggest following this [guide](https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04). Covers initial setup of django with gunicorn and nginx which is essential for deployment, you don't have to add the port to access the site. It doesn't cover how to a...
3,631,510
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
2010/09/02
[ "https://Stackoverflow.com/questions/3631510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427183/" ]
JavaScript is single threaded. So this wouldn't apply to JavaScript. However, it is possible to spawn multiple threads through a very **limited** [Worker](http://www.w3.org/TR/workers/#dedicated-workers-and-the-worker-interface) interface introduced in HTML5 and is already available on some browsers. From an [MDC arti...
For most things in JavaScript there's one thread, so there's no method for this, since it'd invariable by "1" where you could access such information. There are more threads in the background for events and queuing (handled by the browser), but as far as your code's concerned, there's a main thread. Java != JavaScript...
3,631,510
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
2010/09/02
[ "https://Stackoverflow.com/questions/3631510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427183/" ]
Aside from the name, Javascript is totally unrelated to Java. Javascript does not have threads that you can access.
For most things in JavaScript there's one thread, so there's no method for this, since it'd invariable by "1" where you could access such information. There are more threads in the background for events and queuing (handled by the browser), but as far as your code's concerned, there's a main thread. Java != JavaScript...
3,631,510
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
2010/09/02
[ "https://Stackoverflow.com/questions/3631510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427183/" ]
JavaScript is single threaded. So this wouldn't apply to JavaScript. However, it is possible to spawn multiple threads through a very **limited** [Worker](http://www.w3.org/TR/workers/#dedicated-workers-and-the-worker-interface) interface introduced in HTML5 and is already available on some browsers. From an [MDC arti...
Aside from the name, Javascript is totally unrelated to Java. Javascript does not have threads that you can access.
3,631,510
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
2010/09/02
[ "https://Stackoverflow.com/questions/3631510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427183/" ]
JavaScript is single threaded. So this wouldn't apply to JavaScript. However, it is possible to spawn multiple threads through a very **limited** [Worker](http://www.w3.org/TR/workers/#dedicated-workers-and-the-worker-interface) interface introduced in HTML5 and is already available on some browsers. From an [MDC arti...
In javascript the scripts run in a browser thread, and your code have no access to that info, actually your code have no idea whatsoever how it's being run. So NO! there's no such thing in javascript.
3,631,510
how to do a zoom in/out with wxpython? what are the very basics for this purpose? I googled this, but could not find much, thanks!!
2010/09/02
[ "https://Stackoverflow.com/questions/3631510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/427183/" ]
Aside from the name, Javascript is totally unrelated to Java. Javascript does not have threads that you can access.
In javascript the scripts run in a browser thread, and your code have no access to that info, actually your code have no idea whatsoever how it's being run. So NO! there's no such thing in javascript.
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
The file is passed by the Apple Event, see [this Apple document](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-BBCBCIJE). You need to receive that from inside your Python script. If it's a PyObjC script...
Are we referring to the file where per-user binding of file types/extensions are set to point to certain applications? ``` ~/Library/Preferences/com.apple.LaunchServices.plist ``` The framework is [launchservices](http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCIntr...
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
The file is passed by the Apple Event, see [this Apple document](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-BBCBCIJE). You need to receive that from inside your Python script. If it's a PyObjC script...
This is not an answer but it wouldn't fit in the comments. To respond to @Sacrilicious and to give everyone else insight on this: @Sacrilicious You're talking about something different. [Download this sample application](http://www.filedropper.com/myscript1), it's a python script wrapped as an "App". Look inside and f...
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
The file is passed by the Apple Event, see [this Apple document](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-BBCBCIJE). You need to receive that from inside your Python script. If it's a PyObjC script...
I've never heard of it being done without a Cocoa / Carbon wrapper.
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
The file is passed by the Apple Event, see [this Apple document](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-BBCBCIJE). You need to receive that from inside your Python script. If it's a PyObjC script...
I described how to link certain filetypes to py2app-bundled Python applications at <https://moosystems.com/articles/8-double-click-on-files-in-finder-to-open-them-in-your-python-and-tk-application.html>
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
This is not an answer but it wouldn't fit in the comments. To respond to @Sacrilicious and to give everyone else insight on this: @Sacrilicious You're talking about something different. [Download this sample application](http://www.filedropper.com/myscript1), it's a python script wrapped as an "App". Look inside and f...
Are we referring to the file where per-user binding of file types/extensions are set to point to certain applications? ``` ~/Library/Preferences/com.apple.LaunchServices.plist ``` The framework is [launchservices](http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCIntr...
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
This is not an answer but it wouldn't fit in the comments. To respond to @Sacrilicious and to give everyone else insight on this: @Sacrilicious You're talking about something different. [Download this sample application](http://www.filedropper.com/myscript1), it's a python script wrapped as an "App". Look inside and f...
I've never heard of it being done without a Cocoa / Carbon wrapper.
3,664,124
I posted this basic question before, but didn't get an answer I could work with. I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and...
2010/09/08
[ "https://Stackoverflow.com/questions/3664124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428582/" ]
This is not an answer but it wouldn't fit in the comments. To respond to @Sacrilicious and to give everyone else insight on this: @Sacrilicious You're talking about something different. [Download this sample application](http://www.filedropper.com/myscript1), it's a python script wrapped as an "App". Look inside and f...
I described how to link certain filetypes to py2app-bundled Python applications at <https://moosystems.com/articles/8-double-click-on-files-in-finder-to-open-them-in-your-python-and-tk-application.html>
52,079,637
I have been trying to scroll the output of a script run via Ipython in a separate window/session created by tmux (off notebook, meaning that I am not using Ipython notebook as usual: I am just using Ipython). I see that, while the program is loading the output, I can’t scroll the window to see what has been published b...
2018/08/29
[ "https://Stackoverflow.com/questions/52079637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10285919/" ]
I finally found the answer to my problem right here <https://superuser.com/questions/209437/how-do-i-scroll-in-tmux> , it did not depend on Ipython but on tmux as I was suspecting. To scroll on tmux press ctrl+b and then [, so that you can enter the copy mode, and then use arrows or page up/down to scroll through the w...
Use threads for data processing, visualization, and gui interaction that is how you can avoid freez.
38,079,862
Sometimes this code works just fine and runs through, but other times it throws the int object not callable error. I am not real sure as to why it is doing so. ``` for ship in ships: vert_or_horz = randint(0,100) % 2 for size in range(ship.size): if size == 0: ship.location.append((random_r...
2016/06/28
[ "https://Stackoverflow.com/questions/38079862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2759574/" ]
You might be able to directly call [TransferHandler#exportAsDrag(...)](http://docs.oracle.com/javase/8/docs/api/javax/swing/TransferHandler.html#exportAsDrag-javax.swing.JComponent-java.awt.event.InputEvent-int-) method in `MouseMotionListener#mouseDragged(...)`: ``` import java.awt.*; import java.awt.event.*; import ...
> > Selection mode should only be possible via click and should be extendable via shift + click, not via dragging > > > You may be able to alter the behavior by overriding JTable's `processMouseEvent` method with some additional logic. When a button down event occurs - and shift is not down - alter the selection o...
49,280,016
I'm trying to create a dataset from a CSV file with 784-bit long rows. Here's my code: ``` import tensorflow as tf f = open("test.csv", "r") csvreader = csv.reader(f) gen = (row for row in csvreader) ds = tf.data.Dataset() ds.from_generator(gen, [tf.uint8]*28**2) ``` I get the following error: ``` ----------------...
2018/03/14
[ "https://Stackoverflow.com/questions/49280016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3128156/" ]
The `generator` argument (perhaps confusingly) should not actually be a generator, but a callable returning an iterable (for example, a generator function). Probably the easiest option here is to use a `lambda`. Also, a couple of errors: 1) [`tf.data.Dataset.from_generator`](https://www.tensorflow.org/api_docs/python/t...
[From the docs](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator), which you linked: > > The `generator` argument must be a callable object that returns an > object that support the `iter()` protocol (e.g. a generator function) > > > This means you should be able to do something like thi...
49,280,016
I'm trying to create a dataset from a CSV file with 784-bit long rows. Here's my code: ``` import tensorflow as tf f = open("test.csv", "r") csvreader = csv.reader(f) gen = (row for row in csvreader) ds = tf.data.Dataset() ds.from_generator(gen, [tf.uint8]*28**2) ``` I get the following error: ``` ----------------...
2018/03/14
[ "https://Stackoverflow.com/questions/49280016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3128156/" ]
The `generator` argument (perhaps confusingly) should not actually be a generator, but a callable returning an iterable (for example, a generator function). Probably the easiest option here is to use a `lambda`. Also, a couple of errors: 1) [`tf.data.Dataset.from_generator`](https://www.tensorflow.org/api_docs/python/t...
Yuck, two years later... But hey! Another solution! :D This might not be the cleanest answer but for generators that are more complicated, you can use a decorator. I made a generator that yields two dictionaries, for example: ```py >>> train,val = dataloader("path/to/dataset") >>> x,y = next(train) >>> print(x) {"da...
49,244,935
I am trying to execute a Python program as a background process inside a container with `kubectl` as below (`kubectl` issued on local machine): `kubectl exec -it <container_id> -- bash -c "cd some-dir && (python xxx.py --arg1 abc &)"` When I log in to the container and check `ps -ef` I do not see this process running...
2018/03/12
[ "https://Stackoverflow.com/questions/49244935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1650281/" ]
The [nohup](https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging) Wikipedia page can help; you need to redirect all three IO streams (stdout, stdin and stderr) - an example with `yes`: ``` kubectl exec pod -- bash -c "yes > /dev/null 2> /dev/null &" ``` `nohup` is not required in the above case because I did not ...
Actually, the best way to make this kind of things is adding an entry point to your container and run execute the commands there. Like: `entrypoint.sh`: ``` #!/bin/bash set -e cd some-dir && (python xxx.py --arg1 abc &) ./somethingelse.sh exec "$@" ``` You wouldn't need to go manually inside every single contain...
21,255,168
I am trying to understand why does the recursive function returns 1003 instead of 1005. ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` According to [pythontutor](http://pythontutor.com/visualize.html) the last value of `y` list is 5 and that would make return value `1000 +...
2014/01/21
[ "https://Stackoverflow.com/questions/21255168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1984680/" ]
> > According to pythontutor the last value of y list is 5 and that would make return value `1000 + sum([2,3])` 1005, am I correct? > > > No, the last value of `y` is `[]`. It's never anything but a list, and besides, there are no `5`s for it to ever be. On top of that, the recursive return value is always on the ...
Recursion step by step 1) `x = 1` `y = [2,3]` 2) `x = 2` `y = [3]` 3) `x = 3` `y = []` Note that step 3) returns `1000` since `not y`. This is because your return statement is equivalent to ``` (x + sum(y)) if y else 1000 ``` Thus we have 3) `1000` 2) `1000 + 2` 1) `1002 + 1` The result is `1003`. So perha...
21,255,168
I am trying to understand why does the recursive function returns 1003 instead of 1005. ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` According to [pythontutor](http://pythontutor.com/visualize.html) the last value of `y` list is 5 and that would make return value `1000 +...
2014/01/21
[ "https://Stackoverflow.com/questions/21255168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1984680/" ]
Recursion step by step 1) `x = 1` `y = [2,3]` 2) `x = 2` `y = [3]` 3) `x = 3` `y = []` Note that step 3) returns `1000` since `not y`. This is because your return statement is equivalent to ``` (x + sum(y)) if y else 1000 ``` Thus we have 3) `1000` 2) `1000 + 2` 1) `1002 + 1` The result is `1003`. So perha...
You should try to use a debugger or actually print things inside the function. Without executing the code I guess that it should be something like this: ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` It will call a such: ``` -> sum([1,2,3]) x : 1 y : [2, 3] -> sum([2, 3])...
21,255,168
I am trying to understand why does the recursive function returns 1003 instead of 1005. ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` According to [pythontutor](http://pythontutor.com/visualize.html) the last value of `y` list is 5 and that would make return value `1000 +...
2014/01/21
[ "https://Stackoverflow.com/questions/21255168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1984680/" ]
> > According to pythontutor the last value of y list is 5 and that would make return value `1000 + sum([2,3])` 1005, am I correct? > > > No, the last value of `y` is `[]`. It's never anything but a list, and besides, there are no `5`s for it to ever be. On top of that, the recursive return value is always on the ...
You should try to use a debugger or actually print things inside the function. Without executing the code I guess that it should be something like this: ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` It will call a such: ``` -> sum([1,2,3]) x : 1 y : [2, 3] -> sum([2, 3])...
21,255,168
I am trying to understand why does the recursive function returns 1003 instead of 1005. ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` According to [pythontutor](http://pythontutor.com/visualize.html) the last value of `y` list is 5 and that would make return value `1000 +...
2014/01/21
[ "https://Stackoverflow.com/questions/21255168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1984680/" ]
> > According to pythontutor the last value of y list is 5 and that would make return value `1000 + sum([2,3])` 1005, am I correct? > > > No, the last value of `y` is `[]`. It's never anything but a list, and besides, there are no `5`s for it to ever be. On top of that, the recursive return value is always on the ...
You should add parentheses: ``` l = [1,2,3] def sum(l): x, *y = l return x + (sum(y) if y else 1000) ```
21,255,168
I am trying to understand why does the recursive function returns 1003 instead of 1005. ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` According to [pythontutor](http://pythontutor.com/visualize.html) the last value of `y` list is 5 and that would make return value `1000 +...
2014/01/21
[ "https://Stackoverflow.com/questions/21255168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1984680/" ]
You should add parentheses: ``` l = [1,2,3] def sum(l): x, *y = l return x + (sum(y) if y else 1000) ```
You should try to use a debugger or actually print things inside the function. Without executing the code I guess that it should be something like this: ``` l = [1,2,3] def sum(l): x, *y = l return x + sum(y) if y else 1000 sum(l) ``` It will call a such: ``` -> sum([1,2,3]) x : 1 y : [2, 3] -> sum([2, 3])...
72,173,762
I am trying to speed up my code by splitting the job among several python processes. In the single-threaded version of the code, I am looping through a code that accumulates the result in several matrices of different dimensions. Since there's no data sharing between each iteration, I can divide the task among several ...
2022/05/09
[ "https://Stackoverflow.com/questions/72173762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11342618/" ]
Sort a Range ------------ ```vb Sub SortData() 'Dim wb As Workbook: Set wb = ThisWorkbook 'Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1") Dim ws As Worksheet: Set ws = ActiveSheet With ws.Range("A1").CurrentRegion .Sort _ Key1:=.Columns(1), Order1:=xlAscending, _ ...
You aren't quite using the `With` statement correctly. Try it like this: ``` Sub Sort() With ActiveSheet.Sort Cells.Select .SortFields.Clear .SortFields.Add2 key:=Range("A2:A35" _ ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SortFields.Add2 ...
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
Use could use defaultdict here. ``` from collections import defaultdict res = defaultdict(list) for (k,v) in items: res[k].append(v) # Use as dict(res) ``` **EDIT:** This is using groupby, but please note, **the above is far cleaner and neater to the eyes**: ``` >>> data = [('A', 1), ('B', 1), ('B', 2), ('C',...
This is very easy to do with `defaultdict`, which can be imported from `collections`. ``` >>> from collections import defaultdict >>> items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] >>> d = defaultdict(list) >>> for k, v in items: d[k].append(v) >>> d defaultdict(<class 'list'>, {'A': [1], 'C': [3], 'B': [1, 2]})...
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
Use could use defaultdict here. ``` from collections import defaultdict res = defaultdict(list) for (k,v) in items: res[k].append(v) # Use as dict(res) ``` **EDIT:** This is using groupby, but please note, **the above is far cleaner and neater to the eyes**: ``` >>> data = [('A', 1), ('B', 1), ('B', 2), ('C',...
You can use the WebOb multidict implementation: ``` >>> from webob import multidict >>> a = multidict.MultiDict(items) >>> a.getall('B') [1,2] ```
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
Use could use defaultdict here. ``` from collections import defaultdict res = defaultdict(list) for (k,v) in items: res[k].append(v) # Use as dict(res) ``` **EDIT:** This is using groupby, but please note, **the above is far cleaner and neater to the eyes**: ``` >>> data = [('A', 1), ('B', 1), ('B', 2), ('C',...
If you don't want to use `defaultdict`/`groupby`, the following works: ``` d = {} for k,v in items: d.setdefault(k, []).append(v) ```
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
Use could use defaultdict here. ``` from collections import defaultdict res = defaultdict(list) for (k,v) in items: res[k].append(v) # Use as dict(res) ``` **EDIT:** This is using groupby, but please note, **the above is far cleaner and neater to the eyes**: ``` >>> data = [('A', 1), ('B', 1), ('B', 2), ('C',...
Maybe it looks ugly, but it works. ``` In [1]: items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] In [2]: d = {} In [3]: map(lambda i: d.update({i[0]: i[1] if d.get(i[0], i[1]) == i[1] else [d[i[0]], i[1]]}), items) Out[3]: [None, None, None, None] In [4]: print d {'A': 1, 'C': 3, 'B': [1, 2]} ``` In `else` branch ...
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
Use could use defaultdict here. ``` from collections import defaultdict res = defaultdict(list) for (k,v) in items: res[k].append(v) # Use as dict(res) ``` **EDIT:** This is using groupby, but please note, **the above is far cleaner and neater to the eyes**: ``` >>> data = [('A', 1), ('B', 1), ('B', 2), ('C',...
To convert dictionary to list of items ``` dict_items = list(dict_1.items()) ``` To convert the list of items back to the dictionary ``` dict2 = dict(dict_items) ```
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
If you don't want to use `defaultdict`/`groupby`, the following works: ``` d = {} for k,v in items: d.setdefault(k, []).append(v) ```
This is very easy to do with `defaultdict`, which can be imported from `collections`. ``` >>> from collections import defaultdict >>> items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] >>> d = defaultdict(list) >>> for k, v in items: d[k].append(v) >>> d defaultdict(<class 'list'>, {'A': [1], 'C': [3], 'B': [1, 2]})...
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
If you don't want to use `defaultdict`/`groupby`, the following works: ``` d = {} for k,v in items: d.setdefault(k, []).append(v) ```
You can use the WebOb multidict implementation: ``` >>> from webob import multidict >>> a = multidict.MultiDict(items) >>> a.getall('B') [1,2] ```
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
If you don't want to use `defaultdict`/`groupby`, the following works: ``` d = {} for k,v in items: d.setdefault(k, []).append(v) ```
Maybe it looks ugly, but it works. ``` In [1]: items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] In [2]: d = {} In [3]: map(lambda i: d.update({i[0]: i[1] if d.get(i[0], i[1]) == i[1] else [d[i[0]], i[1]]}), items) Out[3]: [None, None, None, None] In [4]: print d {'A': 1, 'C': 3, 'B': [1, 2]} ``` In `else` branch ...
20,213,981
I have following list of items (key-value pairs): ``` items = [('A', 1), ('B', 1), ('B', 2), ('C', 3)] ``` What I want to get: ``` { 'A' : 1, 'B' : [1,2] 'C' : 3 } ``` My naive solution: ``` res = {} for (k,v) in items: if k in res: res[k].append(v) else: res[k] = [v] ``` I'm ...
2013/11/26
[ "https://Stackoverflow.com/questions/20213981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/940208/" ]
If you don't want to use `defaultdict`/`groupby`, the following works: ``` d = {} for k,v in items: d.setdefault(k, []).append(v) ```
To convert dictionary to list of items ``` dict_items = list(dict_1.items()) ``` To convert the list of items back to the dictionary ``` dict2 = dict(dict_items) ```
12,924,287
I have a text file like this:- ``` V1xx AB1 V2xx AC34 V3xx AB1 ``` Can we add `;` at each end of line through python script? ``` V1xx AB1; V2xx AC34; V3xx AB1; ```
2012/10/16
[ "https://Stackoverflow.com/questions/12924287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
Here's what you can try. I have `overwritten the same file` though. You can `try creating a new one`(I leave it to you) - You'll need to modify your `with` statement a little : - ``` lines = "" with open('D:\File.txt') as file: for line in file: lines += line.strip() + ";\n" file = open('D:\File.txt', ...
``` #Open the original file, and create a blank file in write mode File = open("D:\myfilepath\myfile.txt") FileCopy = open("D:\myfilepath\myfile_Copy.txt","w") #For each line in the file, remove the end line character, #insert a semicolon, and then add a new end line character. #copy these lines into the blank fil...
12,924,287
I have a text file like this:- ``` V1xx AB1 V2xx AC34 V3xx AB1 ``` Can we add `;` at each end of line through python script? ``` V1xx AB1; V2xx AC34; V3xx AB1; ```
2012/10/16
[ "https://Stackoverflow.com/questions/12924287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
``` input_file_name = 'input.txt' output_file_name = 'output.txt' with open(input_file_name, 'rt') as input, open(output_file_name, 'wt') as output: for line in input: output.write(line[:-1]+';\n') ```
``` #Open the original file, and create a blank file in write mode File = open("D:\myfilepath\myfile.txt") FileCopy = open("D:\myfilepath\myfile_Copy.txt","w") #For each line in the file, remove the end line character, #insert a semicolon, and then add a new end line character. #copy these lines into the blank fil...
12,924,287
I have a text file like this:- ``` V1xx AB1 V2xx AC34 V3xx AB1 ``` Can we add `;` at each end of line through python script? ``` V1xx AB1; V2xx AC34; V3xx AB1; ```
2012/10/16
[ "https://Stackoverflow.com/questions/12924287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1750896/" ]
Here's what you can try. I have `overwritten the same file` though. You can `try creating a new one`(I leave it to you) - You'll need to modify your `with` statement a little : - ``` lines = "" with open('D:\File.txt') as file: for line in file: lines += line.strip() + ";\n" file = open('D:\File.txt', ...
``` input_file_name = 'input.txt' output_file_name = 'output.txt' with open(input_file_name, 'rt') as input, open(output_file_name, 'wt') as output: for line in input: output.write(line[:-1]+';\n') ```
34,839,184
Which approach is the best when we want to deploy two websites on the same aws EC2 instance? * two separate Docker container each consists a django project * one Docker container consists of two separate django project if the two of them are basic django-cms projects and we know they wont expand in future (nor python...
2016/01/17
[ "https://Stackoverflow.com/questions/34839184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4566737/" ]
I am sure the answer is "It depends" but I believe the whole reason for using Docker is to isolate your environment, and gain flexibility. So what happens if one project uses a bunch of python packages, and the other uses a bunch of other packages. Worse, what if any of them conflict with each other. Forget about a ca...
What is easier to maintain for you? * Handling software updates? * Redeploying sources? * Reconfiguring each app? I like separation and therefore I would define two separate Docker container but then your in need of a load balancer in front because both containers will need a separate port. The load balancer itself w...
34,839,184
Which approach is the best when we want to deploy two websites on the same aws EC2 instance? * two separate Docker container each consists a django project * one Docker container consists of two separate django project if the two of them are basic django-cms projects and we know they wont expand in future (nor python...
2016/01/17
[ "https://Stackoverflow.com/questions/34839184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4566737/" ]
I am sure the answer is "It depends" but I believe the whole reason for using Docker is to isolate your environment, and gain flexibility. So what happens if one project uses a bunch of python packages, and the other uses a bunch of other packages. Worse, what if any of them conflict with each other. Forget about a ca...
I don't know why you don't choose the simpler option: 1. 2 x Python virtual environments; one for each django application. 2. 2 x uwsgi master processes, one for each django application 3. 1 x supervisor process to manage the uwsgi threads 4. 1 x nginx mapped correctly for both applications. This is how things were s...
34,839,184
Which approach is the best when we want to deploy two websites on the same aws EC2 instance? * two separate Docker container each consists a django project * one Docker container consists of two separate django project if the two of them are basic django-cms projects and we know they wont expand in future (nor python...
2016/01/17
[ "https://Stackoverflow.com/questions/34839184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4566737/" ]
What is easier to maintain for you? * Handling software updates? * Redeploying sources? * Reconfiguring each app? I like separation and therefore I would define two separate Docker container but then your in need of a load balancer in front because both containers will need a separate port. The load balancer itself w...
I don't know why you don't choose the simpler option: 1. 2 x Python virtual environments; one for each django application. 2. 2 x uwsgi master processes, one for each django application 3. 1 x supervisor process to manage the uwsgi threads 4. 1 x nginx mapped correctly for both applications. This is how things were s...
67,404,079
I want to read a file and return word and space in the file with python. and i don't want to pass caractere to caractere. I already used : ``` def openfile(name_file) : with open(name_file) as f : l = re.split(' ',re.sub('\n',' ',f.read())) sentence = [] for i in l : sentence.append(i) ...
2021/05/05
[ "https://Stackoverflow.com/questions/67404079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15844030/" ]
This is not the best solution for this, but you can do something like this: ``` import re def openfile(name_file): with open(name_file) as f: original_list = [] lines = f.readlines() for line in lines: li = line.split(' ') for item in li: if item !=...
Add a parameter on the end of print ```py def openfile(name_file) : with open(name_file) as f : l = re.split(' ',re.sub('\n',' ',f.read())) for i in l : print('i :', i, '\ni : ') ```
67,404,079
I want to read a file and return word and space in the file with python. and i don't want to pass caractere to caractere. I already used : ``` def openfile(name_file) : with open(name_file) as f : l = re.split(' ',re.sub('\n',' ',f.read())) sentence = [] for i in l : sentence.append(i) ...
2021/05/05
[ "https://Stackoverflow.com/questions/67404079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15844030/" ]
your code is ok but something you should pay attention first your txt file that includes your characters, in operating systems, each line ends with \n if you go to next line but here you don't have any new line character because its a single line second `re.split` make a list of characters based on pattern you give...
Add a parameter on the end of print ```py def openfile(name_file) : with open(name_file) as f : l = re.split(' ',re.sub('\n',' ',f.read())) for i in l : print('i :', i, '\ni : ') ```
67,404,079
I want to read a file and return word and space in the file with python. and i don't want to pass caractere to caractere. I already used : ``` def openfile(name_file) : with open(name_file) as f : l = re.split(' ',re.sub('\n',' ',f.read())) sentence = [] for i in l : sentence.append(i) ...
2021/05/05
[ "https://Stackoverflow.com/questions/67404079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15844030/" ]
This is not the best solution for this, but you can do something like this: ``` import re def openfile(name_file): with open(name_file) as f: original_list = [] lines = f.readlines() for line in lines: li = line.split(' ') for item in li: if item !=...
your code is ok but something you should pay attention first your txt file that includes your characters, in operating systems, each line ends with \n if you go to next line but here you don't have any new line character because its a single line second `re.split` make a list of characters based on pattern you give...
54,879,916
I've the following string in python, example: ``` "Peter North / John West" ``` Note that there are two spaces before and after the forward slash. What should I do such that I can clean it to become ``` "Peter North_John West" ``` I tried using regex but I am not exactly sure how. Should I use re.sub or pand...
2019/02/26
[ "https://Stackoverflow.com/questions/54879916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11117700/" ]
You can use ``` a = "Peter North / John West" import re a = re.sub(' +/ +','_',a) ``` Any number of spaces with slash followed by any number of slashes can be replaced by this pattern.
In case of varying number of white spaces before and after `/`: ``` import re re.sub("\s+/\s+", "_", "Peter North / John West") # Peter North_John West ```
10,184,476
I'm making a Django page that has a sidebar with some info that is loaded from external websites(e.g. bus arrival times). I'm new to web development and I recognize this as a bottleneck. As it is, the page hangs for a fraction of a second as it loads the data from the other sites. It doesn't display anything until it ...
2012/04/17
[ "https://Stackoverflow.com/questions/10184476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1337686/" ]
You probably don't need up-to-the-second information, so have [another process](http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/) load the data into a cache, and have your website read it from the local cache.
The easiest but not most beautiful way to integrate something like this would be with iframes. Just make iframes for the secondary stuff, and they will load themselves in due time. No javascript required.
48,282,074
I'm trying to learn python for data science application and signed up for a course. I am doing the exercises and got stuck even though my answer is the same as the one in the answer key. I'm basically trying to add two new items to a dictionary with the following piece of code: ``` # Create a new key-value pair for '...
2018/01/16
[ "https://Stackoverflow.com/questions/48282074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9224360/" ]
I had a list in there with the sets I think that was what was throwing the error I just converted the list to a set and joined them with .union. Thank you @Adelin, @Bilkokuya, @ Piinthesky, and @Kurast for you're quick responses and input!
for union of sets you can use `|` ``` location_dict['Camden'] | location_dict['Southwark'] ```
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
There is XMODEM module on PyPi. It handles both sending and receiving of data with XModem. Below is sample of its usage: ``` import serial try: from cStringIO import StringIO except: from StringIO import StringIO from xmodem import XMODEM, NAK from time import sleep def readUntil(char = None): def serialP...
I think you’re stuck with rolling your own. You might be able to use [sz](http://linux.about.com/library/cmd/blcmdl1_sz.htm), which implements X/Y/ZMODEM. You could call out to the binary, or port the necessary code to Python.
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Here is a link to [XMODEM](http://www.programmersheaven.com/download/2167/download.aspx) documentation that will be useful if you have to write your own. It has detailed description of the original XMODEM, XMODEM-CRC and XMODEM-1K. You might also find this [c-code](http://www.menie.org/georges/embedded/index.html) of ...
You can try using [SWIG](http://www.swig.org/) to create Python bindings for the C libraries linked above (or any other C/C++ libraries you find online). That will allow you to use the same C API directly from Python. The actual implementation will of course still be in C/C++, since SWIG merely creates bindings to the...
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` def xmodem_send(serial, file): t, anim = 0, '|/-\\' serial.setTimeout(1) while 1: if serial.read(1) != NAK: t = t + 1 print anim[t%len(anim)],'\r', if t == 60 : return False else: break p = 1 s = file.read(128) while s: s = s + '\xFF'*(128 - len(s)) chk = 0 for c...
There is a python module that you can use -> <https://pypi.python.org/pypi/xmodem> You can see the transfer protocol in <http://pythonhosted.org//xmodem/xmodem.html>
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` def xmodem_send(serial, file): t, anim = 0, '|/-\\' serial.setTimeout(1) while 1: if serial.read(1) != NAK: t = t + 1 print anim[t%len(anim)],'\r', if t == 60 : return False else: break p = 1 s = file.read(128) while s: s = s + '\xFF'*(128 - len(s)) chk = 0 for c...
Here is a link to [XMODEM](http://www.programmersheaven.com/download/2167/download.aspx) documentation that will be useful if you have to write your own. It has detailed description of the original XMODEM, XMODEM-CRC and XMODEM-1K. You might also find this [c-code](http://www.menie.org/georges/embedded/index.html) of ...
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I think you’re stuck with rolling your own. You might be able to use [sz](http://linux.about.com/library/cmd/blcmdl1_sz.htm), which implements X/Y/ZMODEM. You could call out to the binary, or port the necessary code to Python.
You can try using [SWIG](http://www.swig.org/) to create Python bindings for the C libraries linked above (or any other C/C++ libraries you find online). That will allow you to use the same C API directly from Python. The actual implementation will of course still be in C/C++, since SWIG merely creates bindings to the...
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` def xmodem_send(serial, file): t, anim = 0, '|/-\\' serial.setTimeout(1) while 1: if serial.read(1) != NAK: t = t + 1 print anim[t%len(anim)],'\r', if t == 60 : return False else: break p = 1 s = file.read(128) while s: s = s + '\xFF'*(128 - len(s)) chk = 0 for c...
You can try using [SWIG](http://www.swig.org/) to create Python bindings for the C libraries linked above (or any other C/C++ libraries you find online). That will allow you to use the same C API directly from Python. The actual implementation will of course still be in C/C++, since SWIG merely creates bindings to the...
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
There is XMODEM module on PyPi. It handles both sending and receiving of data with XModem. Below is sample of its usage: ``` import serial try: from cStringIO import StringIO except: from StringIO import StringIO from xmodem import XMODEM, NAK from time import sleep def readUntil(char = None): def serialP...
There is a python module that you can use -> <https://pypi.python.org/pypi/xmodem> You can see the transfer protocol in <http://pythonhosted.org//xmodem/xmodem.html>
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` def xmodem_send(serial, file): t, anim = 0, '|/-\\' serial.setTimeout(1) while 1: if serial.read(1) != NAK: t = t + 1 print anim[t%len(anim)],'\r', if t == 60 : return False else: break p = 1 s = file.read(128) while s: s = s + '\xFF'*(128 - len(s)) chk = 0 for c...
I think you’re stuck with rolling your own. You might be able to use [sz](http://linux.about.com/library/cmd/blcmdl1_sz.htm), which implements X/Y/ZMODEM. You could call out to the binary, or port the necessary code to Python.
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
There is XMODEM module on PyPi. It handles both sending and receiving of data with XModem. Below is sample of its usage: ``` import serial try: from cStringIO import StringIO except: from StringIO import StringIO from xmodem import XMODEM, NAK from time import sleep def readUntil(char = None): def serialP...
Here is a link to [XMODEM](http://www.programmersheaven.com/download/2167/download.aspx) documentation that will be useful if you have to write your own. It has detailed description of the original XMODEM, XMODEM-CRC and XMODEM-1K. You might also find this [c-code](http://www.menie.org/georges/embedded/index.html) of ...
358,471
I am writing a program that requires the use of XMODEM to transfer data from a sensor device. I'd like to avoid having to write my own XMODEM code, so I was wondering if anyone knew if there was a python XMODEM module available anywhere?
2008/12/11
[ "https://Stackoverflow.com/questions/358471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Here is a link to [XMODEM](http://www.programmersheaven.com/download/2167/download.aspx) documentation that will be useful if you have to write your own. It has detailed description of the original XMODEM, XMODEM-CRC and XMODEM-1K. You might also find this [c-code](http://www.menie.org/georges/embedded/index.html) of ...
There is a python module that you can use -> <https://pypi.python.org/pypi/xmodem> You can see the transfer protocol in <http://pythonhosted.org//xmodem/xmodem.html>
12,243,129
For a research project I am trying to boot as many VM's as possible, using python libvirt bindings, in KVM under Ubuntu server 12.04. All the VM's are set to idle after boot, and to use a minimum amount of memory. At the most I was able to boot 1000 VM's on a single host, at which point the kernel (Linux 3x) became unr...
2012/09/03
[ "https://Stackoverflow.com/questions/12243129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1642856/" ]
You are booting all the VMs using qemu-kvm right, and after 100s of VM you feel it's becoming successively slow. So when you feels it stop using kvm, just boot using qemu, I expect you see the same slowliness. My guess is that after those many VMs, KVM (hardware support) exhausts. Because KVM is nothing but software la...
The following virtual hardware limits for guests have been tested. We ensure host and VMs install and work successfully, even when reaching the limits and there are no major performance regressions (CPU, memory, disk, network) since the last release (SUSE Linux Enterprise Server 11 SP1). Max. Guest RAM Size --- 512 GB...
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
I know this is an old question, but since the "right" answer has changed thanks to Heroku offering support for `nltk`, I thought it might be worthwhile to answer. Heroku now supports `nltk`. If you need to download something for `nltk` (wordnet in this example, or perhaps stopwords or a corpora), you can do so by simp...
I was also facing the issue when i tried to use this code lemmatizer.lemmatize('goes'), its actually because of packages they have not downloaded. so try to download them using following code, may be it can solve many problems regarding to these, nltk.download('wordnet') nltk.download('omw-1.4') Thank You..
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
This one works: For Mac OS users. ``` python -m nltk.downloader -d /usr/local/share/nltk_data wordnet ```
Heroku now officially supports NLTK data, built-in! <https://devcenter.heroku.com/articles/python-nltk>
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
This one works: For Mac OS users. ``` python -m nltk.downloader -d /usr/local/share/nltk_data wordnet ```
I faced the exact same problem while deploying a chatbot on Heroku platform. Although the answer from follyroof is a fool-proof solution, but in many cases, the size of the repository would be increased drastically. So, I used the nltk.download('PACKAGE') in my app.py file. This way whenever app.py is run, the depend...
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
Heroku now officially supports NLTK data, built-in! <https://devcenter.heroku.com/articles/python-nltk>
On Mac: I still needed to download the `omw-1.4` data. The code was running from an Python file and the `nltk_data/` directory is in the same directory like the Python file. `nltk.download('wordnet', "nltk_data/")` `nltk.download('omw-1.4', "nltk_data/")` `nltk.data.path.append('nltk_data/')`
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
I was getting this issue. For those who are not working in virtual environment, will need to download to following directory in ubuntu: ``` /usr/share/nltk_data/corpora/wordnet ``` Instead of wordnet it could be brown or whatever. You can directly run this command in your terminal if you want to download the corpus....
I faced the same error. This workaround by *Fred Foo* helped me to fix the issue The following works for me: ``` # 1) execute the below written code # 2) a NLTK Download window will open # 3) select "Corpora" tab and scroll down until "wordnet" # 4) doubleclick to install nltk.download() from nltk.corpus import word...
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
I just had this same problem. What ended up working for me is creating an 'nltk\_data' directory in the application's folder itself, downloading the corpus to that directory and adding a line to my code that lets the nltk know to look in that directory. You can do this all locally and then push the changes to Heroku. ...
Heroku now officially supports NLTK data, built-in! <https://devcenter.heroku.com/articles/python-nltk>
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
For Mac OS user only. `python -m nltk.downloader -d /usr/share/nltk_data wordnet` the corpora data can't be downloaded directly to the `/usr/share/nltk_data` folder. error reports "no permission", two solutions: 1. Add additional permission change to the Mac system, details refer to [Operation Not Permitted when o...
This one works: For Mac OS users. ``` python -m nltk.downloader -d /usr/local/share/nltk_data wordnet ```
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
I faced the same **problem** and I tried this solution and it is works. I just did put these: ``` import nltk nltk.download('wordnet') ``` in the above code and it is run without problem. so try it maybe help you.
I was also facing the issue when i tried to use this code lemmatizer.lemmatize('goes'), its actually because of packages they have not downloaded. so try to download them using following code, may be it can solve many problems regarding to these, nltk.download('wordnet') nltk.download('omw-1.4') Thank You..
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
Heroku now officially supports NLTK data, built-in! <https://devcenter.heroku.com/articles/python-nltk>
I was also facing the issue when i tried to use this code lemmatizer.lemmatize('goes'), its actually because of packages they have not downloaded. so try to download them using following code, may be it can solve many problems regarding to these, nltk.download('wordnet') nltk.download('omw-1.4') Thank You..
13,965,823
I'm trying to get NLTK and wordnet working on Heroku. I've already done ``` heroku run python nltk.download() wordnet pip install -r requirements.txt ``` But I get this error: ``` Resource 'corpora/wordnet' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: ...
2012/12/20
[ "https://Stackoverflow.com/questions/13965823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1881006/" ]
I faced the same **problem** and I tried this solution and it is works. I just did put these: ``` import nltk nltk.download('wordnet') ``` in the above code and it is run without problem. so try it maybe help you.
I faced the same error. This workaround by *Fred Foo* helped me to fix the issue The following works for me: ``` # 1) execute the below written code # 2) a NLTK Download window will open # 3) select "Corpora" tab and scroll down until "wordnet" # 4) doubleclick to install nltk.download() from nltk.corpus import word...
64,734,118
I'm trying to make a discord bot, and when I try to load a .env with load\_dotenv() it doesn't work because it says ``` Traceback (most recent call last): File "/home/fanjin/Documents/Python Projects/Discord Bot/bot.py", line 15, in <module> client.run(TOKEN) File "/home/fanjin/.local/lib/python3.8/site-packag...
2020/11/08
[ "https://Stackoverflow.com/questions/64734118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9509783/" ]
I had same error trying to load my environment configuration on ubuntu 20.04 and python-dotenv 0.15.0. I was able to rectify this using python interpreter which will log out any error encountered while trying to load your environments. Whenever your environment variable is loaded successfully, load\_dotenv() returns `T...
So this took me a while. My load\_dotenv() was returning True. I had commas after some records which is not correct. Once I removed the commas the variables were working.
64,734,118
I'm trying to make a discord bot, and when I try to load a .env with load\_dotenv() it doesn't work because it says ``` Traceback (most recent call last): File "/home/fanjin/Documents/Python Projects/Discord Bot/bot.py", line 15, in <module> client.run(TOKEN) File "/home/fanjin/.local/lib/python3.8/site-packag...
2020/11/08
[ "https://Stackoverflow.com/questions/64734118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9509783/" ]
##### I was facing a similar issue and found out these three possible solutions/reasons: 1. Check if the syntax in your .env file is correct or not, the original documentation will be the best source - [Python Dotenv](https://pypi.org/project/python-dotenv/) (sample below) ``` DOMAIN=example.org ADMIN_EMAIL=admin@$...
So this took me a while. My load\_dotenv() was returning True. I had commas after some records which is not correct. Once I removed the commas the variables were working.
64,734,118
I'm trying to make a discord bot, and when I try to load a .env with load\_dotenv() it doesn't work because it says ``` Traceback (most recent call last): File "/home/fanjin/Documents/Python Projects/Discord Bot/bot.py", line 15, in <module> client.run(TOKEN) File "/home/fanjin/.local/lib/python3.8/site-packag...
2020/11/08
[ "https://Stackoverflow.com/questions/64734118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9509783/" ]
You need to put the full path. Use * either `os.path.expanduser('~/Documents/MY_PROJECT/.env')` * or: `load_dotenv('/home/MY_USER/Documents/MY_PROJECT/.env')` and it will work. Or you change your current working directory in your code editor to where the ".env" file is (which should be the project folder). Or you ...
So this took me a while. My load\_dotenv() was returning True. I had commas after some records which is not correct. Once I removed the commas the variables were working.
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
Thanks to @suuuehgi. When Jupyter Notebook isn't opened as root: ``` import sys !{sys.executable} -m pip install --user numpy ```
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form: `!pip install numpy` fixes it. Let me know how it goes.
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form: `!pip install numpy` fixes it. Let me know how it goes.
I had a similar issue. Turns out I renamed an upstream path. And I hadn't deactivated my conda env first. When I deactivated the env. ``` conda deactivate ``` Then when I activated it again, everything was as it should have been. ``` conda activate sample ``` Now I am seeing other issues with jupyter themes... bu...
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form: `!pip install numpy` fixes it. Let me know how it goes.
I have the same problem. My numpy is installed, I am using the same folder as usual. If I try 'conda deactivate', I get the message: ValueError: The python kernel does not appear to be a conda environment. Please use `%pip install` instead. [I added a print of the 'pip install numpy' result and the 'Module not found er...
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form: `!pip install numpy` fixes it. Let me know how it goes.
Here is a solution which worked for me: ``` lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\" MODULE_NAME = "module_to_import" MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py" import importlib import sys spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH) module = importlib.util.module_...
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
Thanks to @suuuehgi. When Jupyter Notebook isn't opened as root: ``` import sys !{sys.executable} -m pip install --user numpy ```
I had a similar issue. Turns out I renamed an upstream path. And I hadn't deactivated my conda env first. When I deactivated the env. ``` conda deactivate ``` Then when I activated it again, everything was as it should have been. ``` conda activate sample ``` Now I am seeing other issues with jupyter themes... bu...
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
Thanks to @suuuehgi. When Jupyter Notebook isn't opened as root: ``` import sys !{sys.executable} -m pip install --user numpy ```
I have the same problem. My numpy is installed, I am using the same folder as usual. If I try 'conda deactivate', I get the message: ValueError: The python kernel does not appear to be a conda environment. Please use `%pip install` instead. [I added a print of the 'pip install numpy' result and the 'Module not found er...
63,756,673
I'm facing weird issue in my Jupyter-notebook. In my first cell: ``` import sys !{sys.executable} -m pip install numpy !{sys.executable} -m pip install Pillow ``` In the second cell: ``` import numpy as np from PIL import Image ``` But it says : **ModuleNotFoundError: No module named 'numpy'** [![ModuleNotFound...
2020/09/05
[ "https://Stackoverflow.com/questions/63756673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10305444/" ]
Thanks to @suuuehgi. When Jupyter Notebook isn't opened as root: ``` import sys !{sys.executable} -m pip install --user numpy ```
Here is a solution which worked for me: ``` lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\" MODULE_NAME = "module_to_import" MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py" import importlib import sys spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH) module = importlib.util.module_...
36,481,891
Is there a way to call Excel add-ins from python? In my company there are several excel add-ins that are available, they usually provide direct access to some database and make additional calculations. What is the best way to call those functions directly from python? To clarify, I'm NOT interested in accessing pytho...
2016/04/07
[ "https://Stackoverflow.com/questions/36481891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5181181/" ]
There are at least 3 possible ways to call an Excel add-in, call the COM add-in directly or through automation. Microsoft provide online documentation for it's Excel interop (<https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel>). Whilst it's for .NET, it highlights the main limitations. You ca...
This [link](https://docs.continuum.io/anaconda/excel) list some of the available packages to work with Excel and Excel files. You might find the answer to your question there. As a summary, here are the name of some of the listed packages: > > 1. openpyxl - Read/Write Excel 2007 xlsx/xlsm files > 2. xlrd - Extract d...
74,111,833
I want to add a new field to a PostgreSQL database. It's a not null and unique CharField, like ``` dyn = models.CharField(max_length=31, null=False, unique=True) ``` The database already has relevant records, so it's not an option to * delete the database * reset the migrations * wipe the data * set a default stat...
2022/10/18
[ "https://Stackoverflow.com/questions/74111833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5675325/" ]
I ended up using [one of the methods](https://stackoverflow.com/a/56398787/5675325) shown by Oleg ``` def dynamic_default_value(): """ This function will be called when a default value is needed. It'll return a 31 length string with a-z, 0-9. """ alphabet = string.ascii_lowercase + string.digits ...
you can reset the migrations or edit it or create new one like: ``` python manage.py makemigrations name_you_want ``` after that: ``` python manage.py migrate same_name ``` edit: example for funcation: ``` def generate_default_data(): return datetime.now() class MyModel(models.Model): field = models.Da...
70,133,541
I have a list of 4 binary numbers and i want to check if they are divisible by 5, and if it's the case, i print them. I've tried something but i'm stuck with an error, showing you the error and the code i made. ``` --------------------------------------------------------------------------- TypeError ...
2021/11/27
[ "https://Stackoverflow.com/questions/70133541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17522853/" ]
EDIT: Originally answered [here](https://discussions.apple.com/thread/253425286?answerId=256408798022#256408798022). If you are using any package manager (e.g. homebrew), then you need the command line tools. Here is my current SDK for macOS Monterey 12.0.1: [![enter image description here](https://i.stack.imgur.com/...
If you uninstall the command line tools, and some software you are using is dependent on them, then they (or the latest version) can just be re-installed.
62,562,064
One Population Proportion Research Question: In previous years 52% of parents believed that electronics and social media was the cause of their teenager’s lack of sleep. Do more parents today believe that their teenager’s lack of sleep is caused due to electronics and social media? Population: Parents with a teenager...
2020/06/24
[ "https://Stackoverflow.com/questions/62562064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13807934/" ]
You approximate the binomial distribution with the normal since n\*p > 30 and the zscore for a [proportion test](https://online.stat.psu.edu/statprogram/reviews/statistical-concepts/proportions) is: [![enter image description here](https://i.stack.imgur.com/Iue0em.png)](https://i.stack.imgur.com/Iue0em.png) So the ca...
The question is formulated as a binomial problem: 1018 people take a yes/no decision with constant probability. In your case 570 out of 1018 people hold that belief and that probability is to be compared to 52 % I do not know about Python, but I con confirm your teachers result in R: ``` > binom.test(570, 1018, p = ....
18,487,171
I am having a direcotry structure as : ``` D:\testfolder\folder_to_tar: |---folder1 |--- file1.txt |---folder2 |--- file2.txt |---file3.txt ``` I want to create a tarball using Python at the same directory level. However, I a...
2013/08/28
[ "https://Stackoverflow.com/questions/18487171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1514773/" ]
Try replacing the tarout.add line with: ``` tarout.add(tarname,arcname=os.path.basename(tarname)) ``` Note: you also need to `import os`
Have you tried adding `\` at the end of `tarname`?
21,820,104
I am attempting to use the Python [requests](http://requests.readthedocs.org/en/latest/) library to login to a website called surfline.com, then `get` a webpage once logged in (presumably within a persisting [session](http://docs.python-requests.org:8000/en/latest/user/advanced/)). The login form that surfline.com use...
2014/02/17
[ "https://Stackoverflow.com/questions/21820104", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1337422/" ]
Consider using WPF's built in validation techniques. See this MSDN documentation on the [`ValidationRule`](http://msdn.microsoft.com/en-us/library/system.windows.controls.validationrule%28v=vs.110%29.aspx) class, and this [how-to](http://msdn.microsoft.com/en-us/library/ms753962%28v=vs.110%29.aspx).
Based on your clarification, you want to limit user input to be a number with decimal points. You also mentioned you are creating the TextBox programmatically. Use the TextBox.PreviewTextInput event to determine the type of characters and validate the string inside the TextBox, and then use e.Handled to cancel the use...
21,820,104
I am attempting to use the Python [requests](http://requests.readthedocs.org/en/latest/) library to login to a website called surfline.com, then `get` a webpage once logged in (presumably within a persisting [session](http://docs.python-requests.org:8000/en/latest/user/advanced/)). The login form that surfline.com use...
2014/02/17
[ "https://Stackoverflow.com/questions/21820104", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1337422/" ]
What you probably need is a masked input. WPF doesn't have one, so you can either implement it yourself (by using [validation](http://msdn.microsoft.com/en-us/library/ms753962.aspx), for example), or use one of available third-party controls: * [`FilteredTextBox` from WPFDeveloperTools](http://www.codeplex.com/WPFDeve...
Based on your clarification, you want to limit user input to be a number with decimal points. You also mentioned you are creating the TextBox programmatically. Use the TextBox.PreviewTextInput event to determine the type of characters and validate the string inside the TextBox, and then use e.Handled to cancel the use...
66,200,173
I have the following question, why is `myf(x)` giving less accurate results than `myf2(x)`. Here is my python code: ``` from math import e, log def Q1(): n = 15 for i in range(1, n): #print(myf(10**(-i))) #print(myf2(10**(-i))) return def myf(x): return ((e**x - 1)/x) def myf2(x): ...
2021/02/14
[ "https://Stackoverflow.com/questions/66200173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14858513/" ]
Let's start with the difference between `x` and `log(exp(x))`, because the rest of the computation is the same. ```py >>> for i in range(10): ... x = 10**-i ... y = exp(x) ... print(x, log(y)) ... 1 1.0 0.1 0.10000000000000007 0.01 0.009999999999999893 0.001 0.001000000000000043 0.0001 0.00010000000000004...
> > Why is this result more accurate than another result by equivalent functions > > > Bad luck. Neither function is reliable pass about `(17-n)/2` digits. Difference in results relies on common implementations of `exp` and `log`, yet not language specified. --- For a given `x` as a negative `n` power of 10, th...
5,591,557
I have some python code that does a certain task. I need to call this code from C# without converting the python file as an .exe, since the whole application is built on C#. How can I do this?
2011/04/08
[ "https://Stackoverflow.com/questions/5591557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/692856/" ]
If your python code can be executed via [IronPython](http://www.ironpython.net/) then this is definitely the way to go - it offers the best interop and means that you will be able to use .Net objects in your scripts. There are many ways to invoke IronPython scripts from C# ranging from compiling the script up as an e...
Have a look at [IronPython](http://www.ironpython.net/). Based on your answer and comments, I believe that the best thing you can do is to embed IronPython in your application. As always, there is a relevant SO [question](https://stackoverflow.com/questions/208393/how-to-embed-ironpython-in-a-net-application) about th...
5,591,557
I have some python code that does a certain task. I need to call this code from C# without converting the python file as an .exe, since the whole application is built on C#. How can I do this?
2011/04/08
[ "https://Stackoverflow.com/questions/5591557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/692856/" ]
Have a look at [IronPython](http://www.ironpython.net/). Based on your answer and comments, I believe that the best thing you can do is to embed IronPython in your application. As always, there is a relevant SO [question](https://stackoverflow.com/questions/208393/how-to-embed-ironpython-in-a-net-application) about th...
[Process.Start](http://visualbasic.about.com/od/usingvbnet/a/prstrt.htm) is what you're after. It allows you to call another program, passing it arguments.
5,591,557
I have some python code that does a certain task. I need to call this code from C# without converting the python file as an .exe, since the whole application is built on C#. How can I do this?
2011/04/08
[ "https://Stackoverflow.com/questions/5591557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/692856/" ]
If your python code can be executed via [IronPython](http://www.ironpython.net/) then this is definitely the way to go - it offers the best interop and means that you will be able to use .Net objects in your scripts. There are many ways to invoke IronPython scripts from C# ranging from compiling the script up as an e...
[Process.Start](http://visualbasic.about.com/od/usingvbnet/a/prstrt.htm) is what you're after. It allows you to call another program, passing it arguments.
52,943,850
Example I have this two csv, how can overwrite the value of column `type` in a.csv or replace if it matched both the string in column `fruit` in a.csv and b.csv ``` a.csv fruit,name,type apple,anna,A banana,lisa,A orange,red,A pine,tin,A b.csv fruit,type banana,B apple,B ``` **How to output this:** OR how to over...
2018/10/23
[ "https://Stackoverflow.com/questions/52943850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
As per your input you have given ``` import pandas as pd df1=pd.read_csv("a.csv") df2=pd.read_csv("b.csv") df = pd.merge(df1, df2, on='fruit', how='outer') df['type_x'] = df['type_y'].combine_first(df['type_x']) del df["type_y"] df = df[pd.notnull(df['name'])] ``` input df1 ``` fruit name type 0 apple ...
Use [`map`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html) by `Series` created by [`set_index`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html) and then rewrite missing unmatched values by original column values by [`fillna`](http://pandas.pydata.org...
52,943,850
Example I have this two csv, how can overwrite the value of column `type` in a.csv or replace if it matched both the string in column `fruit` in a.csv and b.csv ``` a.csv fruit,name,type apple,anna,A banana,lisa,A orange,red,A pine,tin,A b.csv fruit,type banana,B apple,B ``` **How to output this:** OR how to over...
2018/10/23
[ "https://Stackoverflow.com/questions/52943850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
As per your input you have given ``` import pandas as pd df1=pd.read_csv("a.csv") df2=pd.read_csv("b.csv") df = pd.merge(df1, df2, on='fruit', how='outer') df['type_x'] = df['type_y'].combine_first(df['type_x']) del df["type_y"] df = df[pd.notnull(df['name'])] ``` input df1 ``` fruit name type 0 apple ...
You don't need `merge`, this can be implemented via a simple `.loc`: ``` df2.set_index('fruit', inplace=True) mask = df1.fruit.isin(df2.index) df1.loc[mask, 'type'] = df2.loc[df1.loc[mask, 'fruit'], 'type'].values fruit name type 0 apple anna B 1 banana lisa B 2 orange red A 3 pine t...
52,943,850
Example I have this two csv, how can overwrite the value of column `type` in a.csv or replace if it matched both the string in column `fruit` in a.csv and b.csv ``` a.csv fruit,name,type apple,anna,A banana,lisa,A orange,red,A pine,tin,A b.csv fruit,type banana,B apple,B ``` **How to output this:** OR how to over...
2018/10/23
[ "https://Stackoverflow.com/questions/52943850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
As per your input you have given ``` import pandas as pd df1=pd.read_csv("a.csv") df2=pd.read_csv("b.csv") df = pd.merge(df1, df2, on='fruit', how='outer') df['type_x'] = df['type_y'].combine_first(df['type_x']) del df["type_y"] df = df[pd.notnull(df['name'])] ``` input df1 ``` fruit name type 0 apple ...
You can align indices, [`update`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.update.html), then `reset_index`: ``` # align indices df1 = pd.read_csv(s1).set_index('fruit') df2 = pd.read_csv(s2).set_index('fruit') # update df1.update(df2) # reset index res = df1.reset_index() print(res) ...
56,923,131
I have a string converted to an MD5 hash using a python script with the following command: ```py admininfo['password'] = hashlib.md5(admininfo['password'].encode("utf-8")).hexdigest() ``` This value is now stored in an online database. Now I'm creating a C++ script to do a login on this database. During the login, ...
2019/07/07
[ "https://Stackoverflow.com/questions/56923131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10006055/" ]
``` (unsigned char*)&string ``` You're hashing the pointer itself (and unspecified data after it), not the string that it points to. And it changes on every execution (maybe). You meant just `(unsigned char*)string`.
Make it `MD5((unsigned char*)string, ...)`; drop the ampersand. You are not passing the character data to `MD5` - you are passing the value of the `string` pointer itself (namely, the address of the first character of the password), plus whatever garbage happens to be on the stack after it.
65,544,809
I'm trying to create several class instances of graphs and initialize each one with an empty set, so that I can add in-neighbors/out-neighbors to each instance: ``` class Graphs: def __init__(self, name, in_neighbors=None, out_neighbors=None): self.name = name if in_neighbors is None: ...
2021/01/02
[ "https://Stackoverflow.com/questions/65544809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14735451/" ]
``` Dog dog1 = new Dog(1, "Dog1", "Cheese"); Dog dog2 = new Dog(1, "Dog1", "Meat"); Dog dog3 = new Dog(2, "Dog2", "Fish"); Dog dog4 = new Dog(2, "Dog2", "Milk"); List<Dog> dogList = List.of(dog1, dog2, dog3, dog4); //insert dog objects into dog list //Creating HashMap that will have id as the key and dog objects as ...
Hi Tosh and welcome to Stackoverflow. The problem is in your if statement when you check for IDs of your two objects. ``` for (Dog dog : dogList) { if(dog.getId() == dog.getId()){ crMap.put(cr.getIndividualId(), clientReceivables.); } } ``` Here you check IDs of the same object named "dog" and you will alw...
65,544,809
I'm trying to create several class instances of graphs and initialize each one with an empty set, so that I can add in-neighbors/out-neighbors to each instance: ``` class Graphs: def __init__(self, name, in_neighbors=None, out_neighbors=None): self.name = name if in_neighbors is None: ...
2021/01/02
[ "https://Stackoverflow.com/questions/65544809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14735451/" ]
You can use `Collectors.groupingBy(Dog::getId)` to group the dogs with the same `id`. **Demo:** ``` public class Main { public static void main(String[] args) { List<Dog> list = List.of(new Dog(1, "Dog1", "Cheese"), new Dog(1, "Dog1", "Meat"), new Dog(2, "Dog2", "Fish"), new Dog(2, "Dog2",...
Hi Tosh and welcome to Stackoverflow. The problem is in your if statement when you check for IDs of your two objects. ``` for (Dog dog : dogList) { if(dog.getId() == dog.getId()){ crMap.put(cr.getIndividualId(), clientReceivables.); } } ``` Here you check IDs of the same object named "dog" and you will alw...
68,319,575
I see that the example python code from Intel offers a way to change the resolution as below: ``` config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # Start streaming pipeline.start(config) ``` <https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/opencv_viewer_example....
2021/07/09
[ "https://Stackoverflow.com/questions/68319575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1231714/" ]
You were close, but you need to set the revised object to a new variable. Also, you probably want to aggregate arrays since there are multiple 'completed'. This first creates the base object and then populates it using `reduce()` for both actions ``` let keys=todos.reduce((b,a) => ({...b, [a.status]:[]}),{}), rev...
``` function getByValue(arr, value) { var result = arr.filter(function(o){return o.status == value;} ); return result? result[0] : null; // or undefined } todo_obj = getByValue(arr, 'todo') deleted_obj = getByValue(arr, 'deleted') completed_obj = getByValue(arr, 'completed') ```
68,319,575
I see that the example python code from Intel offers a way to change the resolution as below: ``` config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # Start streaming pipeline.start(config) ``` <https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/opencv_viewer_example....
2021/07/09
[ "https://Stackoverflow.com/questions/68319575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1231714/" ]
You were close, but you need to set the revised object to a new variable. Also, you probably want to aggregate arrays since there are multiple 'completed'. This first creates the base object and then populates it using `reduce()` for both actions ``` let keys=todos.reduce((b,a) => ({...b, [a.status]:[]}),{}), rev...
Your code is fine, you just need to use the reduce function as an output - it doesn't mutate `todos` it returns a new value. ```js const todos = [{id: 'a',name: 'Buy dog',action: 'a',status: 'deleted',},{id: 'b',name: 'Buy food',tooltip: null,status: 'completed',},{id: 'c',name: 'Heal dog',tooltip: null,status: 'compl...
68,319,575
I see that the example python code from Intel offers a way to change the resolution as below: ``` config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # Start streaming pipeline.start(config) ``` <https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/opencv_viewer_example....
2021/07/09
[ "https://Stackoverflow.com/questions/68319575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1231714/" ]
You were close, but you need to set the revised object to a new variable. Also, you probably want to aggregate arrays since there are multiple 'completed'. This first creates the base object and then populates it using `reduce()` for both actions ``` let keys=todos.reduce((b,a) => ({...b, [a.status]:[]}),{}), rev...
You haven't been very clear in your question, I assume you want an output that looks like `{todo: [], completed: [], deleted: []}`. In that case here is a simple solution. ```js var todos = [{ id: 'a', name: 'Buy dog', action: 'a', status: 'deleted', }, { id: 'b', name: 'Buy food', too...