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
44,453,416
I'm packing python application into docker with nix's `dockerTools` and all is good except of the image size. Python itself is about 40Mb, and if you add `numpy` and `pandas` it would be few hundreds of megabytes, while the application code is only ~100Kb. The only solution I see is to pack dependencies in separate im...
2017/06/09
[ "https://Stackoverflow.com/questions/44453416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1307593/" ]
After googling a bit and reading `dockerTools` code I ended with this solution: ``` let deps = pkgs.dockerTools.buildImage { name = "deps"; content = [ list of all deps here ]; }; in pkgs.dockertools.buildImage { name = "app"; fromImage = deps; } ``` This will build two layer docker image, one of them ...
There is no need to package your dependencies in a separate image and inherit it, although that can't do harm. All you need to do is make sure that you add your application code as one of the last steps in the Dockerfile. Each command will have its own layer, so if you only change your application code, all layers abo...
60,397,004
Hi new to python and programming in general I'm trying to find an element in an array based on user input here's what i've done ``` a =[31,41,59,26,41,58] input = input("Enter number : ") for i in range(1,len(a),1) : if input == a[i] : print(i) ``` problem is that it doesn't print out anything. what am...
2020/02/25
[ "https://Stackoverflow.com/questions/60397004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12932148/" ]
`input` returns a string. To make them integers wrap them in `int`. ``` inp=int(input('enter :')) for i in range(0,len(a)-1): if inp==a[i]: print(i) ``` Indices in `list` start from *0* to *len(list)-1*. Instead of using `range(0,len(a)-1)` it's preferred to use `enumerate`. ``` for idx,val in enumera...
`input` returns a string; `a` contains integers. Your loop starts at 1, so it will never test against `a[0]` (in this case, 31). And you shouldn't re-define the name `input`.
60,397,004
Hi new to python and programming in general I'm trying to find an element in an array based on user input here's what i've done ``` a =[31,41,59,26,41,58] input = input("Enter number : ") for i in range(1,len(a),1) : if input == a[i] : print(i) ``` problem is that it doesn't print out anything. what am...
2020/02/25
[ "https://Stackoverflow.com/questions/60397004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12932148/" ]
`input` returns a string. To make them integers wrap them in `int`. ``` inp=int(input('enter :')) for i in range(0,len(a)-1): if inp==a[i]: print(i) ``` Indices in `list` start from *0* to *len(list)-1*. Instead of using `range(0,len(a)-1)` it's preferred to use `enumerate`. ``` for idx,val in enumera...
Please don't declare a variable ***input*** is not a good practise and ***Space*** is very important in Python ``` a =[31,41,59,26,41,58] b = input("Enter number : ") for i in range(1,len(a),1): if int(b) == a[i] : print(i) ``` I think you want to check a value from your list so your input need to be a *...
60,397,004
Hi new to python and programming in general I'm trying to find an element in an array based on user input here's what i've done ``` a =[31,41,59,26,41,58] input = input("Enter number : ") for i in range(1,len(a),1) : if input == a[i] : print(i) ``` problem is that it doesn't print out anything. what am...
2020/02/25
[ "https://Stackoverflow.com/questions/60397004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12932148/" ]
`input` returns a string. To make them integers wrap them in `int`. ``` inp=int(input('enter :')) for i in range(0,len(a)-1): if inp==a[i]: print(i) ``` Indices in `list` start from *0* to *len(list)-1*. Instead of using `range(0,len(a)-1)` it's preferred to use `enumerate`. ``` for idx,val in enumera...
input is providing you a str but you are comparing a list of ints. That and your loop starts at 1 but your index starts at 0
26,532,216
I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using `pip install PackageName`. However, when I type this command at the Anaconda Command Prompt, I get the following error: ``` Fatal error in launcher: Unable to create process using '"C:\Python27\...
2014/10/23
[ "https://Stackoverflow.com/questions/26532216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174494/" ]
When installing anaconda, you are asked if you want to include the installed python to your system PATH variable. Make sure you have it in your PATH. If everything is set up correct, you can run pip from your regular command prompt aswell.
There is a way around the use of pip From the anaconda terminal window you can run: ``` conda install PackageName ``` Because MechanicalSoup isn't in one of anaconda's package channels you will have to do a bit of editing See instructions near the bottom [on their blog](http://www.continuum.io/blog/conda)
26,532,216
I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using `pip install PackageName`. However, when I type this command at the Anaconda Command Prompt, I get the following error: ``` Fatal error in launcher: Unable to create process using '"C:\Python27\...
2014/10/23
[ "https://Stackoverflow.com/questions/26532216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174494/" ]
Using @heinzchr's and @mmann's suggestions I was able to piece together the problem. I already had a version of Python 2.7 saved at `C:\Python27` and I had to remove this from the Path `(My Computer's properties> Advanced system settings> System variables> Path)`. I can now use `pip install` from the command line.
There is a way around the use of pip From the anaconda terminal window you can run: ``` conda install PackageName ``` Because MechanicalSoup isn't in one of anaconda's package channels you will have to do a bit of editing See instructions near the bottom [on their blog](http://www.continuum.io/blog/conda)
26,532,216
I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using `pip install PackageName`. However, when I type this command at the Anaconda Command Prompt, I get the following error: ``` Fatal error in launcher: Unable to create process using '"C:\Python27\...
2014/10/23
[ "https://Stackoverflow.com/questions/26532216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174494/" ]
Using @heinzchr's and @mmann's suggestions I was able to piece together the problem. I already had a version of Python 2.7 saved at `C:\Python27` and I had to remove this from the Path `(My Computer's properties> Advanced system settings> System variables> Path)`. I can now use `pip install` from the command line.
When installing anaconda, you are asked if you want to include the installed python to your system PATH variable. Make sure you have it in your PATH. If everything is set up correct, you can run pip from your regular command prompt aswell.
26,532,216
I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using `pip install PackageName`. However, when I type this command at the Anaconda Command Prompt, I get the following error: ``` Fatal error in launcher: Unable to create process using '"C:\Python27\...
2014/10/23
[ "https://Stackoverflow.com/questions/26532216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174494/" ]
When installing anaconda, you are asked if you want to include the installed python to your system PATH variable. Make sure you have it in your PATH. If everything is set up correct, you can run pip from your regular command prompt aswell.
For those looking for Python packages not added to current channels in anaconda, try <https://conda-forge.org/> For example, if you want to install MechanicalSoup you'll find it at <https://anaconda.org/conda-forge/mechanicalsoup> and use the -c option to tell conda the channel to use: ``` conda install -c conda-forge...
26,532,216
I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using `pip install PackageName`. However, when I type this command at the Anaconda Command Prompt, I get the following error: ``` Fatal error in launcher: Unable to create process using '"C:\Python27\...
2014/10/23
[ "https://Stackoverflow.com/questions/26532216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174494/" ]
Using @heinzchr's and @mmann's suggestions I was able to piece together the problem. I already had a version of Python 2.7 saved at `C:\Python27` and I had to remove this from the Path `(My Computer's properties> Advanced system settings> System variables> Path)`. I can now use `pip install` from the command line.
For those looking for Python packages not added to current channels in anaconda, try <https://conda-forge.org/> For example, if you want to install MechanicalSoup you'll find it at <https://anaconda.org/conda-forge/mechanicalsoup> and use the -c option to tell conda the channel to use: ``` conda install -c conda-forge...
61,302,203
``` File "<ipython-input-6-b985bbbd8c62>", line 21 cv2.rectangle(img,(ix,iy),(x,y),(255,0,0),-1) ^ IndentationError: expected an indented block ``` my code ``` import cv2 import numpy as np #variables #True while mouse button down, False while mouse button up drawing = False ix,iy = -1 #Function de...
2020/04/19
[ "https://Stackoverflow.com/questions/61302203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12148825/" ]
launch `npm install` and in your body add the class `<body class="mat-app-background">`, or if you want you can try to add `import { MatSidenavModule } from "@angular/material/sidenav";` in your app.module.ts and put your html code in `<mat-sidenav-container>`
Try add `@import '@angular/material/prebuilt-themes/pink-bluegrey.css';` in your `styles.css` file.
38,274,695
Can anybody help me with this? I'm a beginner in python and programming. Thanks very much. I got this TypeError: 'dict' object is not callable when I execute this function. ``` def goodVsEvil(good, evil): GoodTeam = {'Hobbits':1, 'Men':2, 'Elves':3, 'Dwarves':3, 'Eagles':4, 'Wizards':10} EvilTeam = {'Orcs':1, 'Men':2,...
2016/07/08
[ "https://Stackoverflow.com/questions/38274695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6566925/" ]
Those parenthesis are unnecessary. You intend to use `.items()` which allows you to iterate on the keys and values of your dictionary: ``` for k, val in GoodTeam.items(): # your code ``` You should replicate this change for `EvilTeam` also.
Like the error says, `GoodTeam` is a dict, but you're trying to call it. I think you mean to call its `items` method: ``` for k, val in GoodTeam.items(): ``` The same is true for BadTeam. Note you have other errors; you're using the string format method but haven't given it anything to actually format.
34,090,999
With pythons [`logging`](https://docs.python.org/2/library/logging.html) module, is there a way to **collect multiple events into one log entry**? An ideal solution would be an extension of python's `logging` module or a **custom formatter/filter** for it so collecting logging events of the same kind happens in the bac...
2015/12/04
[ "https://Stackoverflow.com/questions/34090999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789308/" ]
You should probably be writing a message aggregate/statistics class rather than trying to hook onto the logging system's [singletons](https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python) but I guess you may have an existing code base that uses logging. I'd also sugge...
Create a counter and only log it for `count=1`, then increment thereafter and write out in a finally block (to ensure it gets logged no matter how bad the application crashes and burns). This could of course pose an issue if you have the same exception for different reasons, but you could always search for the line num...
34,090,999
With pythons [`logging`](https://docs.python.org/2/library/logging.html) module, is there a way to **collect multiple events into one log entry**? An ideal solution would be an extension of python's `logging` module or a **custom formatter/filter** for it so collecting logging events of the same kind happens in the bac...
2015/12/04
[ "https://Stackoverflow.com/questions/34090999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789308/" ]
You can subclass the logger class and override the exception method to put your error types in a cache until they reach a certain counter before they are emitted to the log. ``` import logging from collections import defaultdict MAX_COUNT = 99999 class MyLogger(logging.getLoggerClass()): def __init__(self, name)...
Create a counter and only log it for `count=1`, then increment thereafter and write out in a finally block (to ensure it gets logged no matter how bad the application crashes and burns). This could of course pose an issue if you have the same exception for different reasons, but you could always search for the line num...
34,090,999
With pythons [`logging`](https://docs.python.org/2/library/logging.html) module, is there a way to **collect multiple events into one log entry**? An ideal solution would be an extension of python's `logging` module or a **custom formatter/filter** for it so collecting logging events of the same kind happens in the bac...
2015/12/04
[ "https://Stackoverflow.com/questions/34090999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789308/" ]
Your question hides a subliminal assumption of how "very similar" is defined. Log records can either be const-only (whose instances are strictly identical), or a mix of consts and variables (no consts at all is also considered a mix). An aggregator for const-only log records is a piece of cake. You just need to decide...
Create a counter and only log it for `count=1`, then increment thereafter and write out in a finally block (to ensure it gets logged no matter how bad the application crashes and burns). This could of course pose an issue if you have the same exception for different reasons, but you could always search for the line num...
34,090,999
With pythons [`logging`](https://docs.python.org/2/library/logging.html) module, is there a way to **collect multiple events into one log entry**? An ideal solution would be an extension of python's `logging` module or a **custom formatter/filter** for it so collecting logging events of the same kind happens in the bac...
2015/12/04
[ "https://Stackoverflow.com/questions/34090999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789308/" ]
You should probably be writing a message aggregate/statistics class rather than trying to hook onto the logging system's [singletons](https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python) but I guess you may have an existing code base that uses logging. I'd also sugge...
You can subclass the logger class and override the exception method to put your error types in a cache until they reach a certain counter before they are emitted to the log. ``` import logging from collections import defaultdict MAX_COUNT = 99999 class MyLogger(logging.getLoggerClass()): def __init__(self, name)...
34,090,999
With pythons [`logging`](https://docs.python.org/2/library/logging.html) module, is there a way to **collect multiple events into one log entry**? An ideal solution would be an extension of python's `logging` module or a **custom formatter/filter** for it so collecting logging events of the same kind happens in the bac...
2015/12/04
[ "https://Stackoverflow.com/questions/34090999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/789308/" ]
You should probably be writing a message aggregate/statistics class rather than trying to hook onto the logging system's [singletons](https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python) but I guess you may have an existing code base that uses logging. I'd also sugge...
Your question hides a subliminal assumption of how "very similar" is defined. Log records can either be const-only (whose instances are strictly identical), or a mix of consts and variables (no consts at all is also considered a mix). An aggregator for const-only log records is a piece of cake. You just need to decide...
57,907,518
So i'm trying to login web-client wifi login page with python. The web-client keep generating special octal character for every login session. So what i'm trying to do is: requests.get(web-client).text -> get the octal code by looping the text index -> combine with the password the problem is: -if i write ``` pas...
2019/09/12
[ "https://Stackoverflow.com/questions/57907518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11561888/" ]
You need to order comments. in micropost view: ``` <% @post.comments.order(created_at: :asc).each do |comment| %> .. <% end %> ```
Inside your show method: ``` @post = Micropost.find(params[:id]) @comments = @post.includes(:comments).order('comments.created_at DESC') ``` Then you can iterate @comments in your HTML files.
73,770,461
I am using the Twitter API StreamingClient using the python module Tweepy. I am currently doing a short stream where I am collecting tweets and saving the entire ID and text from the tweet inside of a json object and writing it to a file. My goal is to be able to collect the Twitter handle from each specific tweet and...
2022/09/19
[ "https://Stackoverflow.com/questions/73770461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11977945/" ]
So a couple of things Firstly, I'd recommend using `on_response` rather than `on_data` because StreamClient already defines a `on_data` function to parse the json. (Then it will fire `on_tweet`, `on_response`, `on_error`, etc) Secondly, `json_obj.user.screen_name` is part of API v1 I believe, which is why it doesn't ...
```py KEY_FILE = './keys/bearer_token' DURATION = 10 def on_data(json_data): json_obj = json.loads(json_data.decode()) print('Received tweet:', json_obj) with open('./collected_tweets/tweets.json', 'a') as out: json.dump(json_obj, out) bearer_token = open(KEY_FILE).read().strip() streaming_client ...
4,618,373
How do I tell Selenium to use HTMLUnit? I'm running selenium-server-standalone-2.0b1.jar as a Selenium server in the background, and the latest Python bindings installed with "pip install -U selenium". Everything works fine with Firefox. But I'd like to use HTMLUnit, as it is lighter weight and doesn't need X. This i...
2011/01/06
[ "https://Stackoverflow.com/questions/4618373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/284340/" ]
As of the 2.0b3 release of the python client you can create an HTMLUnit webdriver via a remote connection like so: ``` from selenium import webdriver driver = webdriver.Remote( desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT) driver.get('http://www.google.com') ``` You can also use the `HTMLUNITWITHJS`...
I use it like this: ``` from selenium.remote import connect b = connect('htmlunit') ...
4,618,373
How do I tell Selenium to use HTMLUnit? I'm running selenium-server-standalone-2.0b1.jar as a Selenium server in the background, and the latest Python bindings installed with "pip install -U selenium". Everything works fine with Firefox. But I'd like to use HTMLUnit, as it is lighter weight and doesn't need X. This i...
2011/01/06
[ "https://Stackoverflow.com/questions/4618373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/284340/" ]
using the selenium 2.20.0.jar server and matching python version, I am able to use HtmlUnitDriver by specifying the browser as \*mock ``` from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities server_url = "http://%s:%s/wd/hub" % (test_host, test_port) dc = Desir...
I use it like this: ``` from selenium.remote import connect b = connect('htmlunit') ...
41,599,600
(The question was edited based on feedback received. I will continue to edit it based on input received until the issue is resolved) I am learning Pyhton and beautiful soup in particular and I am doing the Google Exercise on Regex using the set of html files that contains popular baby names for different years (e.g. b...
2017/01/11
[ "https://Stackoverflow.com/questions/41599600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7128498/" ]
Your test is failing because those strings are not in ascending order. It fails at `word-e` of first string and `wordc` of second string where `c` is before `e` and hyphen is ignored by default. If you want to include the hyphen in ordering use `StringComparer.Ordinal`: ``` Assert.That(anotherList, Is.Ordered.Ascendin...
Thanks, abdul In some cases, if your collection has an UpperCase item, you should use StringComparer.OrdinalIgnoreCase instead of StringComparer.Ordinal
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
I got this same problem with my raspi. ``` host_name = socket.gethostname()` host_addr = socket.gethostbyname(host_name) ``` and now if i print host\_addr, it will print 127.0.1.1. So i foundthis: <https://www.raspberrypi.org/forums/viewtopic.php?t=188615#p1187999> ``` host_addr = socket.gethostbyname(host_name + ...
i get the same problem what your are facing. but I get the solution with help of my own idea, And don't worry it is simple to use. if you familiar to linux you should heard the `ifconfig` command which return the informations about the network interfaces, and also you should understand about `grep` command which filter...
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
As per the above '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname. This is causing the name resolution to get 127.0.1.1. You can try removing/commenting this line and rerun.
This also worked for me: ``` gethostbyname(gethostname()+'.') ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
[How can I get the IP address of eth0 in Python?](https://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python) ``` s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) print s.getsockname()[0] ```
This solution works for me on Windows. If you're using Linux you could try this line of code instead: ``` IPAddr = socket.gethostbyname(socket.getfqdn()) ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
As per the above '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname. This is causing the name resolution to get 127.0.1.1. You can try removing/commenting this line and rerun.
I got this same problem with my raspi. ``` host_name = socket.gethostname()` host_addr = socket.gethostbyname(host_name) ``` and now if i print host\_addr, it will print 127.0.1.1. So i foundthis: <https://www.raspberrypi.org/forums/viewtopic.php?t=188615#p1187999> ``` host_addr = socket.gethostbyname(host_name + ...
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
I got this same problem with my raspi. ``` host_name = socket.gethostname()` host_addr = socket.gethostbyname(host_name) ``` and now if i print host\_addr, it will print 127.0.1.1. So i foundthis: <https://www.raspberrypi.org/forums/viewtopic.php?t=188615#p1187999> ``` host_addr = socket.gethostbyname(host_name + ...
This solution works for me on Windows. If you're using Linux you could try this line of code instead: ``` IPAddr = socket.gethostbyname(socket.getfqdn()) ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
I got this same problem with my raspi. ``` host_name = socket.gethostname()` host_addr = socket.gethostbyname(host_name) ``` and now if i print host\_addr, it will print 127.0.1.1. So i foundthis: <https://www.raspberrypi.org/forums/viewtopic.php?t=188615#p1187999> ``` host_addr = socket.gethostbyname(host_name + ...
[How can I get the IP address of eth0 in Python?](https://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python) ``` s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) print s.getsockname()[0] ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
I got this same problem with my raspi. ``` host_name = socket.gethostname()` host_addr = socket.gethostbyname(host_name) ``` and now if i print host\_addr, it will print 127.0.1.1. So i foundthis: <https://www.raspberrypi.org/forums/viewtopic.php?t=188615#p1187999> ``` host_addr = socket.gethostbyname(host_name + ...
This also worked for me: ``` gethostbyname(gethostname()+'.') ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
[How can I get the IP address of eth0 in Python?](https://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python) ``` s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) print s.getsockname()[0] ```
i get the same problem what your are facing. but I get the solution with help of my own idea, And don't worry it is simple to use. if you familiar to linux you should heard the `ifconfig` command which return the informations about the network interfaces, and also you should understand about `grep` command which filter...
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
i get the same problem what your are facing. but I get the solution with help of my own idea, And don't worry it is simple to use. if you familiar to linux you should heard the `ifconfig` command which return the informations about the network interfaces, and also you should understand about `grep` command which filter...
This solution works for me on Windows. If you're using Linux you could try this line of code instead: ``` IPAddr = socket.gethostbyname(socket.getfqdn()) ```
55,296,584
I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can i get my LAN ip. Every tutorials shows this way only. I also checked via connecting with mobile hotspo...
2019/03/22
[ "https://Stackoverflow.com/questions/55296584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11090395/" ]
As per the above '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname. This is causing the name resolution to get 127.0.1.1. You can try removing/commenting this line and rerun.
i get the same problem what your are facing. but I get the solution with help of my own idea, And don't worry it is simple to use. if you familiar to linux you should heard the `ifconfig` command which return the informations about the network interfaces, and also you should understand about `grep` command which filter...
46,004,408
I bought a Raspberry Pi yesterday and I am facing quite a large problem. I can't sudo apt-get update. I think this error comes from my dns because I am connected via ethernet (Physically). so the message it prints when I execute the command is that: ``` pi@raspberrypi:~ $ sudo apt-get update Err:1 http://goddess-gate....
2017/09/01
[ "https://Stackoverflow.com/questions/46004408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7767248/" ]
Type following at the command line in order to edit `resolv.conf` which is the linux configuration file where **domain-name to IP mapping** is stored for the purpose of **DNS resolution**. ```sh sudo nano /etc/resolv.conf ``` then add these 2 lines: ``` nameserver 8.8.8.8 nameserver 8.8.4.4 ``` hope it will hel...
The ip-adress range 169.254.0.0 to 169.254.255.255 is used by zeroconf. Probably there is no active DHCP server in the LAN. Mostly the router is also a DHCP server. You also have no public IPv6 address. But this could also come from a IPv4 only internet connection. Try to configure the interface completly manual with c...
46,004,408
I bought a Raspberry Pi yesterday and I am facing quite a large problem. I can't sudo apt-get update. I think this error comes from my dns because I am connected via ethernet (Physically). so the message it prints when I execute the command is that: ``` pi@raspberrypi:~ $ sudo apt-get update Err:1 http://goddess-gate....
2017/09/01
[ "https://Stackoverflow.com/questions/46004408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7767248/" ]
The ip-adress range 169.254.0.0 to 169.254.255.255 is used by zeroconf. Probably there is no active DHCP server in the LAN. Mostly the router is also a DHCP server. You also have no public IPv6 address. But this could also come from a IPv4 only internet connection. Try to configure the interface completly manual with c...
``` sudo nano /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 ``` I connected Raspberry Pi Directly with an Ethernet Cable. it work.
46,004,408
I bought a Raspberry Pi yesterday and I am facing quite a large problem. I can't sudo apt-get update. I think this error comes from my dns because I am connected via ethernet (Physically). so the message it prints when I execute the command is that: ``` pi@raspberrypi:~ $ sudo apt-get update Err:1 http://goddess-gate....
2017/09/01
[ "https://Stackoverflow.com/questions/46004408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7767248/" ]
Type following at the command line in order to edit `resolv.conf` which is the linux configuration file where **domain-name to IP mapping** is stored for the purpose of **DNS resolution**. ```sh sudo nano /etc/resolv.conf ``` then add these 2 lines: ``` nameserver 8.8.8.8 nameserver 8.8.4.4 ``` hope it will hel...
``` sudo nano /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 ``` I connected Raspberry Pi Directly with an Ethernet Cable. it work.
62,585,234
It seems that the output of [`zlib.compress`](https://docs.python.org/3/library/zlib.html#zlib.compress) uses all possible byte values. Is this possible to use 255 of 256 byte values (for example avoid using `\n`)? Note that I just use the python manual as a reference, but the question is not specific to python (i.e. ...
2020/06/25
[ "https://Stackoverflow.com/questions/62585234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1424739/" ]
No, this is not possible. Apart from the compressed data itself, there is standardized control structures which contain integers. Those integers may accidentially lead to any 8-bit character ending up in the bytestream. Your only chance would be to encode the zlib bytestream into another format, e.g. base64.
As [@ypnos says](https://stackoverflow.com/a/62585291/3798897), this isn't possible within zlib itself. You mentioned that base64 encoding is too inefficient, but it's pretty easy to use an escape character to encode a character you want to avoid (like newlines). This isn't the most efficient code in the world (and yo...
62,585,234
It seems that the output of [`zlib.compress`](https://docs.python.org/3/library/zlib.html#zlib.compress) uses all possible byte values. Is this possible to use 255 of 256 byte values (for example avoid using `\n`)? Note that I just use the python manual as a reference, but the question is not specific to python (i.e. ...
2020/06/25
[ "https://Stackoverflow.com/questions/62585234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1424739/" ]
The whole point of compression is to reduce the size as much as possible. If zlib or any compressor only used 255 of the 256 byte values, the size of the output would be increased by at least 0.07%. That may be perfectly fine for you, so you can simply post-process the compressed output, or any data at all, to remove ...
As [@ypnos says](https://stackoverflow.com/a/62585291/3798897), this isn't possible within zlib itself. You mentioned that base64 encoding is too inefficient, but it's pretty easy to use an escape character to encode a character you want to avoid (like newlines). This isn't the most efficient code in the world (and yo...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
Three solutions: 1. Pass in a dict type (second argument to the constructor) which returns the keys in your preferred sort order. 2. Extend the class and overload `write()` (just copy this method from the original source and modify it). 3. Copy the file ConfigParser.py and add the sorting to the method `write()`. See...
The first method looked as the most easier, and safer way. But, after looking at the source code of the ConfigParser, it creates an empty built-in dict, and then copies all the values from the "second parameter" one-by-one. That means it won't use the OrderedDict type. An easy work around can be to overload the Create...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
Three solutions: 1. Pass in a dict type (second argument to the constructor) which returns the keys in your preferred sort order. 2. Extend the class and overload `write()` (just copy this method from the original source and modify it). 3. Copy the file ConfigParser.py and add the sorting to the method `write()`. See...
This is my solution for writing config file in alphabetical sort: ``` class OrderedRawConfigParser( ConfigParser.RawConfigParser ): """ Overload standart Class ConfigParser.RawConfigParser """ def __init__( self, defaults = None, dict_type = dict ): ConfigParser.RawConfigParser.__init__( self, defaults = None, dic...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
Three solutions: 1. Pass in a dict type (second argument to the constructor) which returns the keys in your preferred sort order. 2. Extend the class and overload `write()` (just copy this method from the original source and modify it). 3. Copy the file ConfigParser.py and add the sorting to the method `write()`. See...
I was looking into this for merging a .gitmodules doing a subtree merge with a supermodule -- was super confused to start with, and having different orders for submodules was confusing enough haha. Using GitPython helped alot: ``` from collections import OrderedDict import git filePath = '/tmp/git.config' # Could us...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
Three solutions: 1. Pass in a dict type (second argument to the constructor) which returns the keys in your preferred sort order. 2. Extend the class and overload `write()` (just copy this method from the original source and modify it). 3. Copy the file ConfigParser.py and add the sorting to the method `write()`. See...
I was able to solve this issue by sorting the sections in the ConfigParser from the outside like so: ``` config = ConfigParser.ConfigParser({}, collections.OrderedDict) config.read('testfile.ini') # Order the content of each section alphabetically for section in config._sections: config._sections[section] = collec...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
This is my solution for writing config file in alphabetical sort: ``` class OrderedRawConfigParser( ConfigParser.RawConfigParser ): """ Overload standart Class ConfigParser.RawConfigParser """ def __init__( self, defaults = None, dict_type = dict ): ConfigParser.RawConfigParser.__init__( self, defaults = None, dic...
The first method looked as the most easier, and safer way. But, after looking at the source code of the ConfigParser, it creates an empty built-in dict, and then copies all the values from the "second parameter" one-by-one. That means it won't use the OrderedDict type. An easy work around can be to overload the Create...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
The first method looked as the most easier, and safer way. But, after looking at the source code of the ConfigParser, it creates an empty built-in dict, and then copies all the values from the "second parameter" one-by-one. That means it won't use the OrderedDict type. An easy work around can be to overload the Create...
I was looking into this for merging a .gitmodules doing a subtree merge with a supermodule -- was super confused to start with, and having different orders for submodules was confusing enough haha. Using GitPython helped alot: ``` from collections import OrderedDict import git filePath = '/tmp/git.config' # Could us...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
I was able to solve this issue by sorting the sections in the ConfigParser from the outside like so: ``` config = ConfigParser.ConfigParser({}, collections.OrderedDict) config.read('testfile.ini') # Order the content of each section alphabetically for section in config._sections: config._sections[section] = collec...
The first method looked as the most easier, and safer way. But, after looking at the source code of the ConfigParser, it creates an empty built-in dict, and then copies all the values from the "second parameter" one-by-one. That means it won't use the OrderedDict type. An easy work around can be to overload the Create...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
This is my solution for writing config file in alphabetical sort: ``` class OrderedRawConfigParser( ConfigParser.RawConfigParser ): """ Overload standart Class ConfigParser.RawConfigParser """ def __init__( self, defaults = None, dict_type = dict ): ConfigParser.RawConfigParser.__init__( self, defaults = None, dic...
I was looking into this for merging a .gitmodules doing a subtree merge with a supermodule -- was super confused to start with, and having different orders for submodules was confusing enough haha. Using GitPython helped alot: ``` from collections import OrderedDict import git filePath = '/tmp/git.config' # Could us...
1,984,759
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file. PD:...
2009/12/31
[ "https://Stackoverflow.com/questions/1984759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235709/" ]
I was able to solve this issue by sorting the sections in the ConfigParser from the outside like so: ``` config = ConfigParser.ConfigParser({}, collections.OrderedDict) config.read('testfile.ini') # Order the content of each section alphabetically for section in config._sections: config._sections[section] = collec...
I was looking into this for merging a .gitmodules doing a subtree merge with a supermodule -- was super confused to start with, and having different orders for submodules was confusing enough haha. Using GitPython helped alot: ``` from collections import OrderedDict import git filePath = '/tmp/git.config' # Could us...
36,958,167
I need to update a document in an array inside another document in Mongo DB. ``` { "_id" : ObjectId("51cff693d342704b5047e6d8"), "author" : "test", "body" : "sdfkj dsfhk asdfjad ", "comments" : [ { "author" : "test", "body"...
2016/04/30
[ "https://Stackoverflow.com/questions/36958167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3123752/" ]
The moment you give your HTTP/HTTPS endpoint and create subscription from aws console, what happens is , the Amazon sends a subscription msg to that endpoint. Now this is a rest call, and your app must have a handler for this endpoint, otherwise you miss catching this subscription message. The httpRequest object that y...
There are 3 types of messages with SNS. Subscribe, Unsubscribe, and Notification. You will not get any Notification messages until you have correctly handled the subscribe message. Which involves making an API request to AWS when you receive the Subscribe request. The call in this case is ConfirmSubscription: <http:/...
36,958,167
I need to update a document in an array inside another document in Mongo DB. ``` { "_id" : ObjectId("51cff693d342704b5047e6d8"), "author" : "test", "body" : "sdfkj dsfhk asdfjad ", "comments" : [ { "author" : "test", "body"...
2016/04/30
[ "https://Stackoverflow.com/questions/36958167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3123752/" ]
Try this: ``` const express = require('express'); const router = express.Router(); const request = require('request'); var bodyParser = require('body-parser') router.post('/',bodyParser.text(),handleSNSMessage); module.exports = router; var handleSubscriptionResponse = function (error, re...
There are 3 types of messages with SNS. Subscribe, Unsubscribe, and Notification. You will not get any Notification messages until you have correctly handled the subscribe message. Which involves making an API request to AWS when you receive the Subscribe request. The call in this case is ConfirmSubscription: <http:/...
36,958,167
I need to update a document in an array inside another document in Mongo DB. ``` { "_id" : ObjectId("51cff693d342704b5047e6d8"), "author" : "test", "body" : "sdfkj dsfhk asdfjad ", "comments" : [ { "author" : "test", "body"...
2016/04/30
[ "https://Stackoverflow.com/questions/36958167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3123752/" ]
The moment you give your HTTP/HTTPS endpoint and create subscription from aws console, what happens is , the Amazon sends a subscription msg to that endpoint. Now this is a rest call, and your app must have a handler for this endpoint, otherwise you miss catching this subscription message. The httpRequest object that y...
After you subscribe your endpoint, Amazon SNS will send a subscription confirmation message to the endpoint. You should have code at the endpoint that retrieves the **SubscribeURL** value from the subscription confirmation message and either visit the location specified by **SubscribeURL** itself or make it available ...
36,958,167
I need to update a document in an array inside another document in Mongo DB. ``` { "_id" : ObjectId("51cff693d342704b5047e6d8"), "author" : "test", "body" : "sdfkj dsfhk asdfjad ", "comments" : [ { "author" : "test", "body"...
2016/04/30
[ "https://Stackoverflow.com/questions/36958167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3123752/" ]
Try this: ``` const express = require('express'); const router = express.Router(); const request = require('request'); var bodyParser = require('body-parser') router.post('/',bodyParser.text(),handleSNSMessage); module.exports = router; var handleSubscriptionResponse = function (error, re...
After you subscribe your endpoint, Amazon SNS will send a subscription confirmation message to the endpoint. You should have code at the endpoint that retrieves the **SubscribeURL** value from the subscription confirmation message and either visit the location specified by **SubscribeURL** itself or make it available ...
36,958,167
I need to update a document in an array inside another document in Mongo DB. ``` { "_id" : ObjectId("51cff693d342704b5047e6d8"), "author" : "test", "body" : "sdfkj dsfhk asdfjad ", "comments" : [ { "author" : "test", "body"...
2016/04/30
[ "https://Stackoverflow.com/questions/36958167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3123752/" ]
Try this: ``` const express = require('express'); const router = express.Router(); const request = require('request'); var bodyParser = require('body-parser') router.post('/',bodyParser.text(),handleSNSMessage); module.exports = router; var handleSubscriptionResponse = function (error, re...
The moment you give your HTTP/HTTPS endpoint and create subscription from aws console, what happens is , the Amazon sends a subscription msg to that endpoint. Now this is a rest call, and your app must have a handler for this endpoint, otherwise you miss catching this subscription message. The httpRequest object that y...
67,347,499
I've error in Python Selenium. I'm trying to download all songs with Selenium, but there is some error. Here is code: ``` from selenium import webdriver import time driver = webdriver.Chrome('/home/tigran/Documents/chromedriver/chromedriver') url = 'https://sefon.pro/genres/shanson/top/' driver.get(url) songs = dri...
2021/05/01
[ "https://Stackoverflow.com/questions/67347499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14646178/" ]
You can try to use Image.fromarray: ``` Image.fromarray(matrice, mode=couleur) ```
Sorry for my longtime answer. The problem is in the type being used and converting it to the image. If you use a single-byte type for an image, then the matrix type must also be single-byte. Example: ``` from PIL import Image import numpy as np size_x = 50 size_y = 8 m = "L" matrix = np.array([[255] * 50 for _ in ra...
53,719,606
Without changing any code, the graph plotted will be different. Correct at the first run in a fresh bash, disordered in the next runs. (maybe it can cycle back to correct order) To be specific: Environment: MacOS Mojave 10.14.2, python3.7.1 installed through homebrew. To do: Plot `scatter` for two or three sets of ...
2018/12/11
[ "https://Stackoverflow.com/questions/53719606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6823079/" ]
Since your code is incomplete it is difficult to say for sure, but it seems that the order of markers is being messed up by the `cycle` iterator. Why don't you just try: ``` markerTypes = ['o', 's', '^'] strainLegends = [] for strain, markerType in zip(strains, markerTypes): strainSamples = [sample for sample in ...
I found this issue caused by a de-replication process I made in `strains`. ``` # wrong code: strains = list(set([idx.split('_')[0] for idx in pca2Plot.index])) # correct code: strains = list(OrderedDict.fromkeys([idx.split('_')[0] for idx in pca2Plot.index])) ``` Thus the question I asked was not a valid question. ...
56,937,573
How do they run these python commands in python console within their django project. Here is [example](https://docs.djangoproject.com/en/2.2/intro/overview/#enjoy-the-free-api). I'm using Windows 10, PyCharm and python 3.7. I know how to run the project. But when I run the project, - console opens, which gives regular...
2019/07/08
[ "https://Stackoverflow.com/questions/56937573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7402089/" ]
When you run the project you're using a management command: `python manage.py runserver`. To enter a console that has access to all your Django apps, the ORM, etc., use another management command: `python manage.py shell`. That will allow you to import models as shown in your example. As an additional tip, consider in...
Django has a [Shell](https://docs.djangoproject.com/en/2.2/ref/django-admin/#shell) management command that allows you to open a Python shell with all the Django stuff bootstrapped and ready to be executed. So by using `./manage.py shell` you will get an interactive python shell where you can write code.
59,530,439
I am trying to [`save`](https://code.kx.com/q/ref/save/) a [matrix](https://code.kx.com/q4m3/3_Lists/#3112-formal-definition-of-matrices) to file in binary format in KDB as per below: ``` matrix: (til 10)*/:til 10; save matrix; ``` However, I get the error `'type`. I guess `save` only works with tables? In which c...
2019/12/30
[ "https://Stackoverflow.com/questions/59530439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1681681/" ]
`save` does work, you just have to reference it by name. ``` save`matrix ``` You can also save using ``` `:matrix set matrix; `:matrix 1: matrix; ``` But I don't think you'll be able to read this into python directly using numpy as it is stored in kdb format. It could be read into python using one of the python-...
Another option is to save in KDB+ IPC format and then read it into Python with [qPython](https://github.com/exxeleron/qPython) as a Pandas DataFrame. On the KDB+ side you can save it with ``` matrix:(til 10)*/:til 10; `:matrix.ipc 1: -8!matrix; ``` On the Python side you do ``` from pandas import DataFrame from qp...
3,526,748
Sometimes, when fetching data from the database either through the python shell or through a python script, the python process dies, and one single word is printed to the terminal: `Killed` That's literally all it says. It only happens with certain scripts, but it always happens for those scripts. It consistently happ...
2010/08/19
[ "https://Stackoverflow.com/questions/3526748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/836/" ]
Only one thing I could think of that will kill automatically a process on Linux - the OOM killer. What's in the system logs?
If psycopg is being used the issue is probably that the db connection isn't being closed. As per the psycopg [docs](http://initd.org/psycopg/docs/usage.html) example: ``` # Connect to an existing database >>> conn = psycopg2.connect("dbname=test user=postgres") # Open a cursor to perform database operations >>> cur ...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
As long as you stay within their quota Google Apps Engine provides free hosting for Python. Django is a great framework when you want to do webdevelopment with Python. Django also has great documention with <http://www.djangobook.com/> and the official Django website.
You could learn using books, but nothing beats practical hands-on approach - so make sure you have Python installed in a computer to help you learn. If you decide to buy a Python book, I strongly suggest you **DO NOT** buy a copy of Vernon Ceder's [Python Book](http://valashiya.wordpress.com/2010/04/22/the-quick-python...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
Work through the examples on [www.pythonchallenge.com](http://www.pythonchallenge.com/). Refer to the [language documentation](http://www.python.org/doc/) when you get stuck.
I recently learnt Python and had very little programming experience before. I found that doing a little bit of Python first then diving into Django worked for me. USing Django, looking through its reference material and Googling individual problems when I needed the help was really good. Django has a built in Develop...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
As long as you stay within their quota Google Apps Engine provides free hosting for Python. Django is a great framework when you want to do webdevelopment with Python. Django also has great documention with <http://www.djangobook.com/> and the official Django website.
1. If it is your basics in OOPS that you wish to strengthen, Java is a good option(provided you know c++ or any other non-web-based language which supports OOPS). However, if you are looking towards web-development, Python should be your best option. 2. Yes, Python is a good option 3. Yes, Django is a very good web app...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
I learned Python reading the book [Learning Python](https://rads.stackoverflow.com/amzn/click/com/0596158068). I read almost the whole thing on a plane trip, and when I got home I was able to start building applications immediately. There are newer versions out since I read it (and it's longer), but I found it very eas...
1. If it is your basics in OOPS that you wish to strengthen, Java is a good option(provided you know c++ or any other non-web-based language which supports OOPS). However, if you are looking towards web-development, Python should be your best option. 2. Yes, Python is a good option 3. Yes, Django is a very good web app...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
Here's some answers to your questions: Python is an excellent language for beginners looking to learn OO design/programming. As far as books and websites, the best python book I've read is available free online Mark Pilgrim's [Dive into Python](http://www.diveintopython.net). For web programming there are many m...
1. If it is your basics in OOPS that you wish to strengthen, Java is a good option(provided you know c++ or any other non-web-based language which supports OOPS). However, if you are looking towards web-development, Python should be your best option. 2. Yes, Python is a good option 3. Yes, Django is a very good web app...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
If you want to learn about Object Oriented Programming in general, you may want to look at the answers to [this question](https://stackoverflow.com/questions/574001/what-books-do-you-suggest-for-understanding-object-oriented-programming-design-de), although many of the books are higher level (and some are aimed at Java...
Get [ipython](http://ipython.scipy.org/moin/). Use it as your shell. This means move, copy, view, change, edit files from ipython. Day to day shell stuff anywhere has enough little problems that one ordinarily solves by piping, but are just as easily solvable by python. The real bonus is that your eye for syntax and si...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
I learned Python reading the book [Learning Python](https://rads.stackoverflow.com/amzn/click/com/0596158068). I read almost the whole thing on a plane trip, and when I got home I was able to start building applications immediately. There are newer versions out since I read it (and it's longer), but I found it very eas...
You could learn using books, but nothing beats practical hands-on approach - so make sure you have Python installed in a computer to help you learn. If you decide to buy a Python book, I strongly suggest you **DO NOT** buy a copy of Vernon Ceder's [Python Book](http://valashiya.wordpress.com/2010/04/22/the-quick-python...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
As long as you stay within their quota Google Apps Engine provides free hosting for Python. Django is a great framework when you want to do webdevelopment with Python. Django also has great documention with <http://www.djangobook.com/> and the official Django website.
Get [ipython](http://ipython.scipy.org/moin/). Use it as your shell. This means move, copy, view, change, edit files from ipython. Day to day shell stuff anywhere has enough little problems that one ordinarily solves by piping, but are just as easily solvable by python. The real bonus is that your eye for syntax and si...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
I would pick up a good O'Reilly book on Python and build a strong understanding of the fundamentals before delving into more web specific ventures. Once you've got the essentials then I'd branch out to things like Django. Here's a good starting page: [O'Reilly - Python](http://oreilly.com/pub/topic/python) And here...
1. If it is your basics in OOPS that you wish to strengthen, Java is a good option(provided you know c++ or any other non-web-based language which supports OOPS). However, if you are looking towards web-development, Python should be your best option. 2. Yes, Python is a good option 3. Yes, Django is a very good web app...
2,876,337
I am currently learning PHP and want to learn about OOP. 1. I know Python is a well-organized and is all OOP, so would learning Python be a wise choose to learn OOP? The thing is I am more towards web development then just general programming, and I know Python is just a general purpose language, but there is Djang...
2010/05/20
[ "https://Stackoverflow.com/questions/2876337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/345690/" ]
1. If it is your basics in OOPS that you wish to strengthen, Java is a good option(provided you know c++ or any other non-web-based language which supports OOPS). However, if you are looking towards web-development, Python should be your best option. 2. Yes, Python is a good option 3. Yes, Django is a very good web app...
Get [ipython](http://ipython.scipy.org/moin/). Use it as your shell. This means move, copy, view, change, edit files from ipython. Day to day shell stuff anywhere has enough little problems that one ordinarily solves by piping, but are just as easily solvable by python. The real bonus is that your eye for syntax and si...
55,031,604
So I haven't been doing python for a while and haven't needed to deal with this before so if i'm making some stupid mistake don't go crazy. I have a list that is pulled from an SQLite database with `.fetchall()` on the end and it returns a list of one tuple and inside that tuple are all the results: ``` [('Bob', 'Sci...
2019/03/06
[ "https://Stackoverflow.com/questions/55031604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6635590/" ]
If there is always going to be exactly only one tuple in the returning list, you can unpack it into meaningfully named variables, the number of which should match the number of output columns in your query: ``` (name, test, description, subject, updated, created, flags, score), = cursor.fetchall() ``` Note the comma...
I suggest going from the most outside element to the inner one. At the beginning you have a list with one tuple. ``` >>>> result = [('Bob', 'Science Homework Test', 'Science homework is a test about Crude Oil development', 'Science-Chemistry', '2019-03-06', '2019-02-27', None, 0)] ``` To get the tuple, just get the ...
55,031,604
So I haven't been doing python for a while and haven't needed to deal with this before so if i'm making some stupid mistake don't go crazy. I have a list that is pulled from an SQLite database with `.fetchall()` on the end and it returns a list of one tuple and inside that tuple are all the results: ``` [('Bob', 'Sci...
2019/03/06
[ "https://Stackoverflow.com/questions/55031604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6635590/" ]
If there is always going to be exactly only one tuple in the returning list, you can unpack it into meaningfully named variables, the number of which should match the number of output columns in your query: ``` (name, test, description, subject, updated, created, flags, score), = cursor.fetchall() ``` Note the comma...
You can think of this as nested index of list and tuple, i.e first index will give you an element of the list which is a tuple, and second index will give you an element of that tuple. Let's say the above list is assigned to variable a. `a = [('Bob', 'Science Homework Test', 'Science homework is a test about Crude Oi...
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
If you want to stay in `decimal` numbers, safest is to convert everything: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d - decimal.Decimal('1') Decimal('22.456') >>> d - decimal.Decimal('1.0') Decimal('22.456') ``` In Python 2.7, there's an implicit conversion for integers, but not floats. ``` >>> d - 1 De...
Use the bultin float function: ``` >>> d = float('23.456') >>> d 23.456 >>> d - 1 22.456 ``` See the docs here: <http://docs.python.org/library/functions.html#float>
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
If you want to stay in `decimal` numbers, safest is to convert everything: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d - decimal.Decimal('1') Decimal('22.456') >>> d - decimal.Decimal('1.0') Decimal('22.456') ``` In Python 2.7, there's an implicit conversion for integers, but not floats. ``` >>> d - 1 De...
If using float, when the number gets too large -- **x = 29345678.91 for example** -- you get results that you might not expect. In this case, `float(x)` becomes **2.934567891E7** which seems undesirable especially if working with financial numbers.
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
Is the `Decimal` required for your computations? The [Decimal fixed point and floating point arithmetic](http://docs.python.org/library/decimal.html) doc outlines their differences. If not, you could just do ``` d = float('23.456') d 23.456 d - 1 22.456 ``` Oddly enough re `Decimal`, I get this interactively ...
Use the bultin float function: ``` >>> d = float('23.456') >>> d 23.456 >>> d - 1 22.456 ``` See the docs here: <http://docs.python.org/library/functions.html#float>
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
Is the `Decimal` required for your computations? The [Decimal fixed point and floating point arithmetic](http://docs.python.org/library/decimal.html) doc outlines their differences. If not, you could just do ``` d = float('23.456') d 23.456 d - 1 22.456 ``` Oddly enough re `Decimal`, I get this interactively ...
If using float, when the number gets too large -- **x = 29345678.91 for example** -- you get results that you might not expect. In this case, `float(x)` becomes **2.934567891E7** which seems undesirable especially if working with financial numbers.
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
If you want to stay in `decimal` numbers, safest is to convert everything: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d - decimal.Decimal('1') Decimal('22.456') >>> d - decimal.Decimal('1.0') Decimal('22.456') ``` In Python 2.7, there's an implicit conversion for integers, but not floats. ``` >>> d - 1 De...
My Python seems to do it differently: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d Decimal('23.456') >>> d-1 Decimal('22.456') ``` What version/OS are you using?
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
Is the `Decimal` required for your computations? The [Decimal fixed point and floating point arithmetic](http://docs.python.org/library/decimal.html) doc outlines their differences. If not, you could just do ``` d = float('23.456') d 23.456 d - 1 22.456 ``` Oddly enough re `Decimal`, I get this interactively ...
My Python seems to do it differently: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d Decimal('23.456') >>> d-1 Decimal('22.456') ``` What version/OS are you using?
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
If you want to stay in `decimal` numbers, safest is to convert everything: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d - decimal.Decimal('1') Decimal('22.456') >>> d - decimal.Decimal('1.0') Decimal('22.456') ``` In Python 2.7, there's an implicit conversion for integers, but not floats. ``` >>> d - 1 De...
Are you specifically TRYING specifically to use the Decimal arbitrary precision library or are you just struggling to convert a string to a Python float? If you are TRYING to use Decimal: ``` >>> import decimal >>> s1='23.456' >>> s2='1.0' >>> decimal.Decimal(s1) - decimal.Decimal(s2) Decimal('22.456') >>> s1='23.45...
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
If you want to stay in `decimal` numbers, safest is to convert everything: ``` >>> s = '23.456' >>> d = decimal.Decimal(s) >>> d - decimal.Decimal('1') Decimal('22.456') >>> d - decimal.Decimal('1.0') Decimal('22.456') ``` In Python 2.7, there's an implicit conversion for integers, but not floats. ``` >>> d - 1 De...
In python, to convert a value string to float just do it: ``` num = "29.0" print (float(num)) ``` To convert string to decimal ``` from decimal import Decimal num = "29.0" print (Decimal(num)) ```
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
Is the `Decimal` required for your computations? The [Decimal fixed point and floating point arithmetic](http://docs.python.org/library/decimal.html) doc outlines their differences. If not, you could just do ``` d = float('23.456') d 23.456 d - 1 22.456 ``` Oddly enough re `Decimal`, I get this interactively ...
Are you specifically TRYING specifically to use the Decimal arbitrary precision library or are you just struggling to convert a string to a Python float? If you are TRYING to use Decimal: ``` >>> import decimal >>> s1='23.456' >>> s2='1.0' >>> decimal.Decimal(s1) - decimal.Decimal(s2) Decimal('22.456') >>> s1='23.45...
10,971,468
Similar posts such as the following do not answer my question. [Convert a string to integer with decimal in Python](https://stackoverflow.com/questions/1094717/convert-a-string-to-integer-with-decimal-in-python) Consider the following Python code. ``` >>> import decimal >>> s = '23.456' >>> d = decimal.Decimal(s) >...
2012/06/10
[ "https://Stackoverflow.com/questions/10971468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/322885/" ]
Is the `Decimal` required for your computations? The [Decimal fixed point and floating point arithmetic](http://docs.python.org/library/decimal.html) doc outlines their differences. If not, you could just do ``` d = float('23.456') d 23.456 d - 1 22.456 ``` Oddly enough re `Decimal`, I get this interactively ...
In python, to convert a value string to float just do it: ``` num = "29.0" print (float(num)) ``` To convert string to decimal ``` from decimal import Decimal num = "29.0" print (Decimal(num)) ```
49,519,789
I want to have a black box in python where * The input is a list A. * There is a random number C for the black box which is randomly selected the first time the black box is called and stays the same for the next times the black box is called. * Based on list A and number C, the output is a list B. I was thinking of ...
2018/03/27
[ "https://Stackoverflow.com/questions/49519789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9559925/" ]
Make it a Class so C will persist. ``` class BlackBox(): def __init__(self): self.C = rand.randint(100) etc... ``` *As a side note, using some pretty cool Python functionality...* You can make objects of this class callable by implementing `__call__()` for your new class. ``` #inside the BlackB...
> > the issue is that a function cannot keep the selected number C for next calls. > > > This may be true in other languages, but not so in Python. Functions in Python are objects like any other, so you can store things on them. Here's a minimal example of doing so. ``` import random def this_function_stores_a_v...
49,519,789
I want to have a black box in python where * The input is a list A. * There is a random number C for the black box which is randomly selected the first time the black box is called and stays the same for the next times the black box is called. * Based on list A and number C, the output is a list B. I was thinking of ...
2018/03/27
[ "https://Stackoverflow.com/questions/49519789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9559925/" ]
Make it a Class so C will persist. ``` class BlackBox(): def __init__(self): self.C = rand.randint(100) etc... ``` *As a side note, using some pretty cool Python functionality...* You can make objects of this class callable by implementing `__call__()` for your new class. ``` #inside the BlackB...
Since you are asking in the comments. This is probably not recommended way but it's easy and works so I'll add it here. You can use global variable to achieve your goal. ``` import random persistant_var = 0 def your_func(): global persistant_var if persistant_var: print('variable already set {}'.fo...
49,519,789
I want to have a black box in python where * The input is a list A. * There is a random number C for the black box which is randomly selected the first time the black box is called and stays the same for the next times the black box is called. * Based on list A and number C, the output is a list B. I was thinking of ...
2018/03/27
[ "https://Stackoverflow.com/questions/49519789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9559925/" ]
Make it a Class so C will persist. ``` class BlackBox(): def __init__(self): self.C = rand.randint(100) etc... ``` *As a side note, using some pretty cool Python functionality...* You can make objects of this class callable by implementing `__call__()` for your new class. ``` #inside the BlackB...
There are many ways to store persistent data for a function. They all have their uses, but in general, the ones that come first are useful more often than the ones that come later. (To keep things shorter, I'm solving a slightly simpler problem than the one you asked about, but it should be obvious how to adapt it.) I...
49,519,789
I want to have a black box in python where * The input is a list A. * There is a random number C for the black box which is randomly selected the first time the black box is called and stays the same for the next times the black box is called. * Based on list A and number C, the output is a list B. I was thinking of ...
2018/03/27
[ "https://Stackoverflow.com/questions/49519789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9559925/" ]
> > the issue is that a function cannot keep the selected number C for next calls. > > > This may be true in other languages, but not so in Python. Functions in Python are objects like any other, so you can store things on them. Here's a minimal example of doing so. ``` import random def this_function_stores_a_v...
Since you are asking in the comments. This is probably not recommended way but it's easy and works so I'll add it here. You can use global variable to achieve your goal. ``` import random persistant_var = 0 def your_func(): global persistant_var if persistant_var: print('variable already set {}'.fo...
49,519,789
I want to have a black box in python where * The input is a list A. * There is a random number C for the black box which is randomly selected the first time the black box is called and stays the same for the next times the black box is called. * Based on list A and number C, the output is a list B. I was thinking of ...
2018/03/27
[ "https://Stackoverflow.com/questions/49519789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9559925/" ]
There are many ways to store persistent data for a function. They all have their uses, but in general, the ones that come first are useful more often than the ones that come later. (To keep things shorter, I'm solving a slightly simpler problem than the one you asked about, but it should be obvious how to adapt it.) I...
Since you are asking in the comments. This is probably not recommended way but it's easy and works so I'll add it here. You can use global variable to achieve your goal. ``` import random persistant_var = 0 def your_func(): global persistant_var if persistant_var: print('variable already set {}'.fo...
66,030,433
I am having trouble setting up a GStreamer pipeline to forward a video stream over UDP via OpenCV. I have a laptop, and an AGX Xavier connected to the same network. The idea is to forward the webcam video feed to AGX which will do some OpenCV optical flow estimation on the GPU (in Python), draw flow vectors on the orig...
2021/02/03
[ "https://Stackoverflow.com/questions/66030433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15008550/" ]
you were very close to the solution. The problem lies in the warning you yourself noticed `warning: Invalid component`. The problem is that rtp jpeg payloader gets stuck due to not supporting video format it is getting. Check [this](http://gstreamer-devel.966125.n4.nabble.com/ximagesrc-to-jpegenc-td4669619.html) Howev...
Note: I cannot write a comment due to the low reputation. According to your problem description, it is difficult to understand what your problem is. Simply, you will run two bash scripts (`servevideo.bash` and `receivevideo.bash`) on your laptop, which may receive and send web-cam frames from the laptop (?), while a ...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You could use an `std::map` like: ``` #include <iostream> #include <map> int main() { std::map<std::string,int> counter; counter["dog"] = 8; counter["cat"]++; counter["cat"]++; counter["1"] = 0; for (auto pair : counter) { cout << pair.first << ":" << pair.second << std::endl; } }...
You can use [std::unordered\_map](https://en.cppreference.com/w/cpp/container/unordered_map) if you want constant on average lookup complexity (as you get using collections.Counter). [std::map](https://en.cppreference.com/w/cpp/container/map) "usually implemented as red-black trees", so complexity for lookup is logarit...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You could use an `std::map` like: ``` #include <iostream> #include <map> int main() { std::map<std::string,int> counter; counter["dog"] = 8; counter["cat"]++; counter["cat"]++; counter["1"] = 0; for (auto pair : counter) { cout << pair.first << ":" << pair.second << std::endl; } }...
Python3 code: ``` import collections stringlist = ["Cat","Cat","Cat","Dog","Dog","Lizard"] counterinstance = collections.Counter(stringlist) for key,value in counterinstance.items(): print(key,":",value) ``` C++ code: ``` #include <iostream> #include <unordered_map> #include <vector> using namespace std; int ...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You could use an `std::map` like: ``` #include <iostream> #include <map> int main() { std::map<std::string,int> counter; counter["dog"] = 8; counter["cat"]++; counter["cat"]++; counter["1"] = 0; for (auto pair : counter) { cout << pair.first << ":" << pair.second << std::endl; } }...
You can use CppCounter: ``` #include <iostream> #include "counter.hpp" int main() { collection::Counter<std::string> counter; ++counter["cat"]; ++counter["cat"]; counter["dogs"] = 8; counter["lizards"] = 0; std::cout << "{ "; for (const auto& it: counter) { std::cout << "\"" << it...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You can use [std::unordered\_map](https://en.cppreference.com/w/cpp/container/unordered_map) if you want constant on average lookup complexity (as you get using collections.Counter). [std::map](https://en.cppreference.com/w/cpp/container/map) "usually implemented as red-black trees", so complexity for lookup is logarit...
Python3 code: ``` import collections stringlist = ["Cat","Cat","Cat","Dog","Dog","Lizard"] counterinstance = collections.Counter(stringlist) for key,value in counterinstance.items(): print(key,":",value) ``` C++ code: ``` #include <iostream> #include <unordered_map> #include <vector> using namespace std; int ...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You can use [std::unordered\_map](https://en.cppreference.com/w/cpp/container/unordered_map) if you want constant on average lookup complexity (as you get using collections.Counter). [std::map](https://en.cppreference.com/w/cpp/container/map) "usually implemented as red-black trees", so complexity for lookup is logarit...
You can use CppCounter: ``` #include <iostream> #include "counter.hpp" int main() { collection::Counter<std::string> counter; ++counter["cat"]; ++counter["cat"]; counter["dogs"] = 8; counter["lizards"] = 0; std::cout << "{ "; for (const auto& it: counter) { std::cout << "\"" << it...
53,055,563
The python `collections.Counter` object keeps track of the counts of objects. ``` >> from collections import Counter >> myC = Counter() >> myC.update("cat") >> myC.update("cat") >> myC["dogs"] = 8 >> myC["lizards"] = 0 >> print(myC) {"cat": 2, "dogs": 8, "lizards": 0} ``` Is there an analogous C++ object where I can...
2018/10/30
[ "https://Stackoverflow.com/questions/53055563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5843327/" ]
You can use CppCounter: ``` #include <iostream> #include "counter.hpp" int main() { collection::Counter<std::string> counter; ++counter["cat"]; ++counter["cat"]; counter["dogs"] = 8; counter["lizards"] = 0; std::cout << "{ "; for (const auto& it: counter) { std::cout << "\"" << it...
Python3 code: ``` import collections stringlist = ["Cat","Cat","Cat","Dog","Dog","Lizard"] counterinstance = collections.Counter(stringlist) for key,value in counterinstance.items(): print(key,":",value) ``` C++ code: ``` #include <iostream> #include <unordered_map> #include <vector> using namespace std; int ...
54,726,459
I'm working through an Exploit Development course on Pluralsight and in the lab I'm currently on we are doing a basic function pointer overwrite. The python script for the lab essentially runs the target executable with a 24 byte string input ending with the memory address of the "jackpot" function. Here's the code: `...
2019/02/16
[ "https://Stackoverflow.com/questions/54726459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9919300/" ]
The way this works is by processing the string from the end, each time you look at a character you check it's position in the array (I use a flipped array as it's more efficient than using `array_search()` each time). Then if the character is at the end of the array, then set it to the 0th element of the alphabet and i...
I ended up with something like this: ```php $string = 'ccc'; $alphabet = ['a', 'b', 'c']; $numbers = array_keys($alphabet); $numeric = str_replace($alphabet, $numbers, $string); $base = count($alphabet) + 1; $decimal = base_convert($numeric, $base, 10); $string = base_convert(++$decimal, 10, $base); strlen($decimal) ...
46,716,912
I am new to scala. As title, I would like to create a mutable map `Map[Int,(Int, Int)]` and with default value as tuple (0,0) if key not exist. In python the "defaultdict" make such effort easy. what is the elegant way to do it in Scala?
2017/10/12
[ "https://Stackoverflow.com/questions/46716912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1269298/" ]
Use `withDefaultValue` after creating the map: ``` import scala.collection.mutable val map = mutable.Map[Int,(Int, Int)]().withDefaultValue((0, 0)) ```
you are probably lookign for `.getOrElseUpdate` which takes the key, if not present updates with given value. ``` scala> val googleMap = Map[Int, (Int, Int)]().empty googleMap: scala.collection.mutable.Map[Int,(Int, Int)] = Map() scala> googleMap.getOrElseUpdate(100, (0, 0)) res3: (Int, Int) = (0,0) scala> googleMap...
46,716,912
I am new to scala. As title, I would like to create a mutable map `Map[Int,(Int, Int)]` and with default value as tuple (0,0) if key not exist. In python the "defaultdict" make such effort easy. what is the elegant way to do it in Scala?
2017/10/12
[ "https://Stackoverflow.com/questions/46716912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1269298/" ]
Use `withDefaultValue` after creating the map: ``` import scala.collection.mutable val map = mutable.Map[Int,(Int, Int)]().withDefaultValue((0, 0)) ```
withDefaultValue is much simpler than getOrElseUpdate. ``` import scala.collection.mutable var kv1 = mutable.Map[Int, Int]().withDefaultValue(0) var kv2 = mutable.Map[Int, Int]() kv1(1) += 5 // use default value when key is not exists kv1(2) = 3 kv2(2) = 3 // both can assign value to a new key. println(f"kv1(1) $...
46,716,912
I am new to scala. As title, I would like to create a mutable map `Map[Int,(Int, Int)]` and with default value as tuple (0,0) if key not exist. In python the "defaultdict" make such effort easy. what is the elegant way to do it in Scala?
2017/10/12
[ "https://Stackoverflow.com/questions/46716912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1269298/" ]
you are probably lookign for `.getOrElseUpdate` which takes the key, if not present updates with given value. ``` scala> val googleMap = Map[Int, (Int, Int)]().empty googleMap: scala.collection.mutable.Map[Int,(Int, Int)] = Map() scala> googleMap.getOrElseUpdate(100, (0, 0)) res3: (Int, Int) = (0,0) scala> googleMap...
withDefaultValue is much simpler than getOrElseUpdate. ``` import scala.collection.mutable var kv1 = mutable.Map[Int, Int]().withDefaultValue(0) var kv2 = mutable.Map[Int, Int]() kv1(1) += 5 // use default value when key is not exists kv1(2) = 3 kv2(2) = 3 // both can assign value to a new key. println(f"kv1(1) $...
31,110,801
I am learning recursion in python. I wrote a program but it is not working correctly. I am a beginner in python. I have two functions **scrabbleScore()** and **letterScore()**. **scrabbleScore()** calls **letterscore()** and itself also. Here is my code: ``` def letterScore( let ): if let in ['a','e','i','l','n','...
2015/06/29
[ "https://Stackoverflow.com/questions/31110801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3222665/" ]
I would rewrite your scrabbleScore to something like this ``` def scrabbleScore(S): def helper(S, p): if S == "": return p else: p += letterScore(S[0]) return helper(S[1:], p) return helper(S, 0) ``` this is how you could write it. `p` is called a akkumula...
Your variable `p` should be initialized to zero again after each call to `scrabbleScore(S)`. This will solve your problem. Example: ``` print "scrabbleScore('quetzal'): 25 ==", scrabbleScore('quetzal') p=0 print "scrabbleScore('jonquil'): 23 ==", scrabbleScore('jonquil') ```
31,110,801
I am learning recursion in python. I wrote a program but it is not working correctly. I am a beginner in python. I have two functions **scrabbleScore()** and **letterScore()**. **scrabbleScore()** calls **letterscore()** and itself also. Here is my code: ``` def letterScore( let ): if let in ['a','e','i','l','n','...
2015/06/29
[ "https://Stackoverflow.com/questions/31110801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3222665/" ]
It is not working correctly because you are using global variable for storing intermediate results. After you call "scrabbleScore" for the first time p value would become 25 and you need to reset it. The solution here would be to avoid using global variable at all: ``` def scrabbleScore( S ): p = 0 if S == ""...
Your variable `p` should be initialized to zero again after each call to `scrabbleScore(S)`. This will solve your problem. Example: ``` print "scrabbleScore('quetzal'): 25 ==", scrabbleScore('quetzal') p=0 print "scrabbleScore('jonquil'): 23 ==", scrabbleScore('jonquil') ```
1,826,824
On my ubuntu server I run the following command: ``` python -c 'import os; os.kill(5555, 0)' ``` This is done so that I can see if pid 5555 is running. From my understanding this should raise an OSError if the pid is not running. This is not raising an OSError for me which means it should be a running process. Howev...
2009/12/01
[ "https://Stackoverflow.com/questions/1826824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205114/" ]
Try installing htop (sudo apt-get install htop), it sometimes displays process that ps doesn't.
I don't know why that OSError is not raised in some cases, but it's important to note that there is a max pid value on linux and unix based OS: ``` $> cat /proc/sys/kernel/pid_max 32768 ```
1,826,824
On my ubuntu server I run the following command: ``` python -c 'import os; os.kill(5555, 0)' ``` This is done so that I can see if pid 5555 is running. From my understanding this should raise an OSError if the pid is not running. This is not raising an OSError for me which means it should be a running process. Howev...
2009/12/01
[ "https://Stackoverflow.com/questions/1826824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205114/" ]
Under linux, each process **and** each thread have a different pid. `os.kill` doesn't care whether you have a thread pid, or a task pid, however `ps` doesn't normally show the thread pids. For instance on my machine the process with PID 8502 is running threads which you can see like this ``` $ ls /proc/8502/task/ 850...
Try installing htop (sudo apt-get install htop), it sometimes displays process that ps doesn't.
1,826,824
On my ubuntu server I run the following command: ``` python -c 'import os; os.kill(5555, 0)' ``` This is done so that I can see if pid 5555 is running. From my understanding this should raise an OSError if the pid is not running. This is not raising an OSError for me which means it should be a running process. Howev...
2009/12/01
[ "https://Stackoverflow.com/questions/1826824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205114/" ]
Maybe it's a bug in 2.5? On 2.6.4 I get: ``` gruszczy@gruszczy-laptop:~$ python -c 'import os; os.kill(5555, 0)' Traceback (most recent call last): File "<string>", line 1, in <module> OSError: [Errno 3] No such process ``` I believe, there is a bug report for this: <http://mail.python.org/pipermail/new-bugs-anno...
I don't know why that OSError is not raised in some cases, but it's important to note that there is a max pid value on linux and unix based OS: ``` $> cat /proc/sys/kernel/pid_max 32768 ```
1,826,824
On my ubuntu server I run the following command: ``` python -c 'import os; os.kill(5555, 0)' ``` This is done so that I can see if pid 5555 is running. From my understanding this should raise an OSError if the pid is not running. This is not raising an OSError for me which means it should be a running process. Howev...
2009/12/01
[ "https://Stackoverflow.com/questions/1826824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205114/" ]
Under linux, each process **and** each thread have a different pid. `os.kill` doesn't care whether you have a thread pid, or a task pid, however `ps` doesn't normally show the thread pids. For instance on my machine the process with PID 8502 is running threads which you can see like this ``` $ ls /proc/8502/task/ 850...
Maybe it's a bug in 2.5? On 2.6.4 I get: ``` gruszczy@gruszczy-laptop:~$ python -c 'import os; os.kill(5555, 0)' Traceback (most recent call last): File "<string>", line 1, in <module> OSError: [Errno 3] No such process ``` I believe, there is a bug report for this: <http://mail.python.org/pipermail/new-bugs-anno...
1,826,824
On my ubuntu server I run the following command: ``` python -c 'import os; os.kill(5555, 0)' ``` This is done so that I can see if pid 5555 is running. From my understanding this should raise an OSError if the pid is not running. This is not raising an OSError for me which means it should be a running process. Howev...
2009/12/01
[ "https://Stackoverflow.com/questions/1826824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205114/" ]
Under linux, each process **and** each thread have a different pid. `os.kill` doesn't care whether you have a thread pid, or a task pid, however `ps` doesn't normally show the thread pids. For instance on my machine the process with PID 8502 is running threads which you can see like this ``` $ ls /proc/8502/task/ 850...
I don't know why that OSError is not raised in some cases, but it's important to note that there is a max pid value on linux and unix based OS: ``` $> cat /proc/sys/kernel/pid_max 32768 ```