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
25,888,828
I'm trying to make an script which takes all rows starting by 'HELIX', 'SHEET' and 'DBREF' from a .txt, from that rows takes some specifical columns and then saves the results on a new file. ``` #!/usr/bin/python import sys if len(sys.argv) != 3: print("2 Parameters expected: You must introduce your pdb file and ...
2014/09/17
[ "https://Stackoverflow.com/questions/25888828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4027271/" ]
Here is a solution (untested) that separates data and code a little more. There is a data structure (`keyword_and_slices`) describing the keywords searched in the lines paired with the slices to be taken for the result. The code then goes through the lines and builds a data structure (`keyword2lines`) mapping the keyw...
You need to convert the tuple created on RHS in your assignments to string. ``` # Replace this with statement given below cols_id = dbref[0], dbref[3:5], dbref[8:10] # Create a string out of the tuple cols_id = ''.join((dbref[0], dbref[3:5], dbref[8:10])) ```
25,888,828
I'm trying to make an script which takes all rows starting by 'HELIX', 'SHEET' and 'DBREF' from a .txt, from that rows takes some specifical columns and then saves the results on a new file. ``` #!/usr/bin/python import sys if len(sys.argv) != 3: print("2 Parameters expected: You must introduce your pdb file and ...
2014/09/17
[ "https://Stackoverflow.com/questions/25888828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4027271/" ]
cols\_id, cols\_h and cols\_s seems to be lists, not strings. You can only write a string in your file so you have to convert the list to a string. ``` modified_data.write(' '.join(cols_id)) ``` and similar. `'!'.join(a_list_of_things)` converts the list into a string separating each element with an exclamation mar...
Here is a solution (untested) that separates data and code a little more. There is a data structure (`keyword_and_slices`) describing the keywords searched in the lines paired with the slices to be taken for the result. The code then goes through the lines and builds a data structure (`keyword2lines`) mapping the keyw...
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
According to the added code, you mean that words are adjacent? Why not just put them together: ``` print len(re.findall(r'\bmaki sushi\b', sent)) ```
``` def ordered(string, words): pos = [string.index(word) for word in words] return pos == sorted(pos) s = "I like to eat maki sushi and the best sushi is in Japan" w = ["maki", "sushi"] ordered(s, w) #Returns True. ``` Not exactly the most efficient way of doing it but simpler to understand.
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
According to the added code, you mean that words are adjacent? Why not just put them together: ``` print len(re.findall(r'\bmaki sushi\b', sent)) ```
``` s = 'I like to eat maki sushi and the best sushi is in Japan' ``` **check order** ``` indices = [s.split().index(w) for w in ['maki', 'sushi']] sorted(indices) == indices ``` **how to count** ``` s.split().count('maki') ``` --- Note (based on discussion below): suppose the sentence is *'I like makim m...
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
``` s = 'I like to eat maki sushi and the best sushi is in Japan' ``` **check order** ``` indices = [s.split().index(w) for w in ['maki', 'sushi']] sorted(indices) == indices ``` **how to count** ``` s.split().count('maki') ``` --- Note (based on discussion below): suppose the sentence is *'I like makim m...
Just and idea, it might need some more work ``` (sentence.index('maki') <= sentence.index('sushi')) == ('maki' <= 'sushi') ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
According to the added code, you mean that words are adjacent? Why not just put them together: ``` print len(re.findall(r'\bmaki sushi\b', sent)) ```
A regex solution :) ``` import re sent = 'I like to eat maki sushi and the best sushi is in Japan' words = sorted(['maki', 'sushi']) assert re.search(r'\b%s\b' % r'\b.*\b'.join(words), sent) ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
According to the added code, you mean that words are adjacent? Why not just put them together: ``` print len(re.findall(r'\bmaki sushi\b', sent)) ```
if res > 0: words are sorted in the sentence ``` words = ["sushi", "maki", "xxx"] sorted_words = sorted(words) sen = " I like to eat maki sushi and the best sushi is in Japan xxx"; ind = map(lambda x : sen.index(x), sorted_words) res = reduce(lambda a, b: b-a, ind) ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
``` s = 'I like to eat maki sushi and the best sushi is in Japan' ``` **check order** ``` indices = [s.split().index(w) for w in ['maki', 'sushi']] sorted(indices) == indices ``` **how to count** ``` s.split().count('maki') ``` --- Note (based on discussion below): suppose the sentence is *'I like makim m...
if res > 0: words are sorted in the sentence ``` words = ["sushi", "maki", "xxx"] sorted_words = sorted(words) sen = " I like to eat maki sushi and the best sushi is in Japan xxx"; ind = map(lambda x : sen.index(x), sorted_words) res = reduce(lambda a, b: b-a, ind) ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
According to the added code, you mean that words are adjacent? Why not just put them together: ``` print len(re.findall(r'\bmaki sushi\b', sent)) ```
Just and idea, it might need some more work ``` (sentence.index('maki') <= sentence.index('sushi')) == ('maki' <= 'sushi') ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
``` s = 'I like to eat maki sushi and the best sushi is in Japan' ``` **check order** ``` indices = [s.split().index(w) for w in ['maki', 'sushi']] sorted(indices) == indices ``` **how to count** ``` s.split().count('maki') ``` --- Note (based on discussion below): suppose the sentence is *'I like makim m...
A regex solution :) ``` import re sent = 'I like to eat maki sushi and the best sushi is in Japan' words = sorted(['maki', 'sushi']) assert re.search(r'\b%s\b' % r'\b.*\b'.join(words), sent) ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
``` def ordered(string, words): pos = [string.index(word) for word in words] return pos == sorted(pos) s = "I like to eat maki sushi and the best sushi is in Japan" w = ["maki", "sushi"] ordered(s, w) #Returns True. ``` Not exactly the most efficient way of doing it but simpler to understand.
Just and idea, it might need some more work ``` (sentence.index('maki') <= sentence.index('sushi')) == ('maki' <= 'sushi') ```
7,234,518
what is the bes way tho check if two words are ordered in sentence and how many times it occurs in python. For example: I like to eat maki sushi and the best sushi is in Japan. words are: [maki, sushi] Thanks. The code ``` import re x="I like to eat maki sushi and the best sushi is in Japan" x1 = re.split('\W+',...
2011/08/29
[ "https://Stackoverflow.com/questions/7234518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461736/" ]
``` def ordered(string, words): pos = [string.index(word) for word in words] return pos == sorted(pos) s = "I like to eat maki sushi and the best sushi is in Japan" w = ["maki", "sushi"] ordered(s, w) #Returns True. ``` Not exactly the most efficient way of doing it but simpler to understand.
if res > 0: words are sorted in the sentence ``` words = ["sushi", "maki", "xxx"] sorted_words = sorted(words) sen = " I like to eat maki sushi and the best sushi is in Japan xxx"; ind = map(lambda x : sen.index(x), sorted_words) res = reduce(lambda a, b: b-a, ind) ```
64,348,889
There's a code I found in internet that says it gives my machines local network IP address: ``` hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) ``` but the IP it returns is 192.168.94.2 but my IP address in WIFI network is actually 192.168.1.107 How can I only get wifi network local IP addr...
2020/10/14
[ "https://Stackoverflow.com/questions/64348889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848316/" ]
You can use this code: ``` import socket hostname = socket.getfqdn() print("IP Address:",socket.gethostbyname_ex(hostname)[2][1]) ``` or this to get public ip: ``` import requests import json print(json.loads(requests.get("https://ip.seeip.org/jsonip?").text)["ip"]) ```
Here's code from the `whatismyip` Python module that can grab it from public websites: ``` import urllib.request IP_WEBSITES = ( 'https://ipinfo.io/ip', 'https://ipecho.net/plain', 'https://api.ipify.org', 'https://ipaddr.site', 'https://icanhazip.com', ...
5,484,098
I'm new to Python. I'm writing a simple class but I'm with an error. My class: ``` import config # Ficheiro de configuracao import twitter import random import sqlite3 import time import bitly_api #https://github.com/bitly/bitly-api-python class TwitterC: def logToDatabase(self, tweet, timestamp): # Wi...
2011/03/30
[ "https://Stackoverflow.com/questions/5484098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/488735/" ]
It looks like your call to updateTwitterStatus just needs to lose the square brackets: ``` x.updateTwitterStatus({"url": "http://xxxx.com/?cat=31", "msg": "See some strings..., "}) ``` You were passing a list with a single dictionary element. It looks as though the method just requires a dictionary with "url" and "...
The error message tells you everything you need to know. It says "list indices must be integers, not str" and points to the code `short = self.shortUrl(update["url"])`. So obviously the python interpreter thinks `update` is a list, and `"url"` is not a valid index into the list. Since `update` is passed in as a parame...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
You can use an external program, [`xsel`](http://www.vergenet.net/~conrad/software/xsel/): ``` from subprocess import Popen, PIPE p = Popen(['xsel','-pi'], stdin=PIPE) p.communicate(input='Hello, World') ``` With `xsel`, you can set the clipboard you want to work on. * `-p` works with the `PRIMARY` selection. That...
This is not really a Python question but a shell question. You already can send the output of a Python script (or any command) to the clipboard instead of standard out, by piping the output of the Python script into the `xclip` command. ``` myscript.py | xclip ``` If `xclip` is not already installed on your system (...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
You can use an external program, [`xsel`](http://www.vergenet.net/~conrad/software/xsel/): ``` from subprocess import Popen, PIPE p = Popen(['xsel','-pi'], stdin=PIPE) p.communicate(input='Hello, World') ``` With `xsel`, you can set the clipboard you want to work on. * `-p` works with the `PRIMARY` selection. That...
As others have pointed out this is not "Python and batteries" as it involves GUI operations. So It is platform dependent. If you are on windows you can use win32 Python Module and Access win32 clipboard operations. My suggestion though would be picking up one GUI toolkit (PyQT/PySide for QT, PyGTK for GTK+ or wxPython ...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
You can use an external program, [`xsel`](http://www.vergenet.net/~conrad/software/xsel/): ``` from subprocess import Popen, PIPE p = Popen(['xsel','-pi'], stdin=PIPE) p.communicate(input='Hello, World') ``` With `xsel`, you can set the clipboard you want to work on. * `-p` works with the `PRIMARY` selection. That...
As it was posted in another [answer](https://stackoverflow.com/a/11063483/212112), if you want to solve that within python, you can use [Pyperclip](https://pypi.python.org/pypi/pyperclip) which has the added benefit of being cross-platform. ``` >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clip...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
This is not really a Python question but a shell question. You already can send the output of a Python script (or any command) to the clipboard instead of standard out, by piping the output of the Python script into the `xclip` command. ``` myscript.py | xclip ``` If `xclip` is not already installed on your system (...
As others have pointed out this is not "Python and batteries" as it involves GUI operations. So It is platform dependent. If you are on windows you can use win32 Python Module and Access win32 clipboard operations. My suggestion though would be picking up one GUI toolkit (PyQT/PySide for QT, PyGTK for GTK+ or wxPython ...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
As it was posted in another [answer](https://stackoverflow.com/a/11063483/212112), if you want to solve that within python, you can use [Pyperclip](https://pypi.python.org/pypi/pyperclip) which has the added benefit of being cross-platform. ``` >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clip...
This is not really a Python question but a shell question. You already can send the output of a Python script (or any command) to the clipboard instead of standard out, by piping the output of the Python script into the `xclip` command. ``` myscript.py | xclip ``` If `xclip` is not already installed on your system (...
7,606,062
For example, if a python script will spit out a string giving the path of a newly written file that I'm going to edit immediately after running the script, it would be very nice to have it directly sent to the system clipboard rather than `STDOUT`.
2011/09/30
[ "https://Stackoverflow.com/questions/7606062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/560844/" ]
As it was posted in another [answer](https://stackoverflow.com/a/11063483/212112), if you want to solve that within python, you can use [Pyperclip](https://pypi.python.org/pypi/pyperclip) which has the added benefit of being cross-platform. ``` >>> import pyperclip >>> pyperclip.copy('The text to be copied to the clip...
As others have pointed out this is not "Python and batteries" as it involves GUI operations. So It is platform dependent. If you are on windows you can use win32 Python Module and Access win32 clipboard operations. My suggestion though would be picking up one GUI toolkit (PyQT/PySide for QT, PyGTK for GTK+ or wxPython ...
46,062,117
Following [the plotly directions](https://plot.ly/python/distplot/), I would like to plot something similar to the following code: ``` import plotly.plotly as py import plotly.figure_factory as ff import numpy as np # Add histogram data x1 = np.random.randn(200) - 2 x2 = np.random.randn(200) x3 = np.random.randn...
2017/09/05
[ "https://Stackoverflow.com/questions/46062117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3604836/" ]
You could try slicing your dataframe and then putting it into in Ploty. ``` fig = ff.create_distplot([df[df.names == a].value for a in df.names.unique()], df.names.unique(), bin_size=[.1, .25, .5, 1]) ``` --- [![enter image description here](https://i.stack.imgur.com/IsX83.png)](https://i.stack.imgur.com/IsX83.png)...
The [example](https://plot.ly/python/distplot/) in [`plotly`](https://plot.ly/python/)'s documentation works out of the box for uneven sample sizes too: ``` #!/usr/bin/env python import plotly import plotly.figure_factory as ff plotly.offline.init_notebook_mode() import numpy as np # data with different sizes x1 = ...
74,513,701
I am an R User that is trying to learn more about Python. I found this Python library that I would like to use for address parsing: <https://github.com/zehengl/ez-address-parser> I was able to try an example over here: ``` from ez_address_parser import AddressParser ap = AddressParser() result = ap.parse("290 Brem...
2022/11/21
[ "https://Stackoverflow.com/questions/74513701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13203841/" ]
It's not possible to completely remove the authorization prompt but you could make it appear only one time for each user by publishing your script as an Editor add-on. 1. Create a Google Cloud standard project (GCSP) and add the OAuth consent screen. 2. Link the GCSP to the Google Apps Script project. 3. Deploy the sc...
It's just a routine security procedure. If they trust you, then there's no issue in them accepting it, it's just a warning if you don't know the coder
52,683,832
``` Revenue = [400000000,10000000,10000000000,10000000] s1 = [] for x in Revenue: message = (','.join(['{:,.0f}'.format(x)]).split()) s1.append(message) print(s1) The output I am getting is something like this [['400,000,000'], ['10,000,000'], ['10,000,000,000'], ['10,000,000']] and I want it should be like ...
2018/10/06
[ "https://Stackoverflow.com/questions/52683832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10431728/" ]
If your goal is to just add in the commas you will be stuck with the `' '` due to the fact its going to be a `str` but you can eliminate that nesting by using a simpler *list comprehension* ``` Revenue = [400000000,10000000,10000000000,10000000] l = ['{:,}'.format(i) for i in Revenue] # ['400,000,000', '10,000,000', ...
I'm not sure why you want the output you've shown, because it is hard to read, but here is how to make it: ``` >>> Revenue = [400000000,10000000,10000000000,10000000] >>> def revenue_formatted(rev): ... return "[" + ", ".join("{:,d}".format(n) for n in rev) + "]" ... >>> print(revenue_formatted(Revenue)) [400,000,...
56,840,250
I am making an adventure game in python 3.7.3, and I am using F strings for some of my print statements. When running it in the terminal and sublime text, F strings give me an error. ``` import time from time import sleep import sys def printfast(str): for letter in str: sys.stdout.write(letter) s...
2019/07/01
[ "https://Stackoverflow.com/questions/56840250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11723707/" ]
You're doing it wrong. `f` isn't a function, it's more of an syntactic identifier. Whereas regular quotes `"` indicate the beginning of a regular string (or the end of any type of string), the token `f"` indicates the beginning of a format string in particular. The same idea goes for raw strings, indicated by `r"`, or ...
In `f("You ...)`, you're calling a function named `f` with the string as input parameter, and you don't have such a function hence the error. You need to drop the enclosing parentheses `()` to make it a f-string: ``` f"You are the mighty hero {name}. In front of you, there is a grand palace, containing twisting marbl...
56,840,250
I am making an adventure game in python 3.7.3, and I am using F strings for some of my print statements. When running it in the terminal and sublime text, F strings give me an error. ``` import time from time import sleep import sys def printfast(str): for letter in str: sys.stdout.write(letter) s...
2019/07/01
[ "https://Stackoverflow.com/questions/56840250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11723707/" ]
You're doing it wrong. `f` isn't a function, it's more of an syntactic identifier. Whereas regular quotes `"` indicate the beginning of a regular string (or the end of any type of string), the token `f"` indicates the beginning of a format string in particular. The same idea goes for raw strings, indicated by `r"`, or ...
f-strings are not created using a function, it's a type of string, which you denote using `f''` (similar to `b''` or `r''`) So try using: ```py printfast(f"You are the mighty hero {name}. In front of you, there is a grand palace, containing twisting marble spires and spiraling dungeons.\n") ```
36,985,391
I am creating a sql query in python of the sort: ``` select lastupdatedatetime from auth_principal_entity where lastupdateddatetime < '02-05-16 03:46:51:527000000 PM' ``` When it is executed, there are escape sequences that are being added which doesn't return me answers. Although when we print it in stdout, it loo...
2016/05/02
[ "https://Stackoverflow.com/questions/36985391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2576170/" ]
The escape sequences won't cause any problem in the cursor.execute(query) The real issue lies in the date that is being sent as a string is being used to compare and return values from db which are in date-object format. so something like this should work. ``` query = "SELECT LASTUPDATEDDATETIME FROM AUTH_PRINCIPAL_E...
For me, I wrap my SQL statements in triple quotes so it doesn't run into these issues when I execute: ``` query = """ select lastupdatedatetime from auth_principal_entity where lastupdateddatetime < '02-05-16 03:46:51:527000000 PM' """ ```
46,247,340
I am currently running tests between XGBoost/lightGBM for their ability to rank items. I am reproducing the benchmarks presented here: <https://github.com/guolinke/boosting_tree_benchmarks>. I have been able to successfully reproduce the benchmarks mentioned in their work. I want to make sure that I am correctly imple...
2017/09/15
[ "https://Stackoverflow.com/questions/46247340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2800840/" ]
Cross-posting my Cross Validated answer to this cross-posted question: <https://stats.stackexchange.com/questions/303385/how-does-xgboost-lightgbm-evaluate-ndcg-metric-for-ranking/487487#487487> --- I happened across this myself, and finally dug into the code to figure it out. The difference is the handling of a mis...
I think the problem is caused by data in the same query that have same labels. In that case, Both XGBoost and LightGBM will produce ndcg 1 for that query.
15,854,257
I am new to python. As part of writing a module to scrape URLs I noticed that what I get using the python requests module could be different from what I get if I load the URL in a browser. This is because the page could contain JS code which is executed and the result is hat I see in the browser. My questions - 1. h...
2013/04/06
[ "https://Stackoverflow.com/questions/15854257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1645536/" ]
The best way to go about this might be, to use [css-gradients](https://developer.mozilla.org/en-US/docs/CSS/gradient) instead of shadows. I have done a little demo on [jsfiddle](http://jsfiddle.net/Qjgps/1/). I am not sure this is what you are looking for though. Here is the css I used: ``` background: rgb(254,255,25...
I came up with this using [this CSS3 Generator](http://css3generator.com/) ``` -webkit-box-shadow: inset 0px -350px 200px -250px rgba(5, 5, 5, 1); box-shadow: inset 0px -350px 200px -250px rgba(5, 5, 5, 1); ``` This is a very cross-browser friendly method and if you apply a background color it will achieve ...
15,671,875
I seem to have some difficulty getting what I want to work. Basically, I have a series of variables that are assigned strings with some quotes and \ characters. I want to remove the quotes to embed them inside a json doc, since json hates quotes using python dump methods. I figured it would be easy. Just determine how...
2013/03/28
[ "https://Stackoverflow.com/questions/15671875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/933693/" ]
You can't do that. You could make it work using `eval`, but that introduces another level of quoting you have to worry about. Is there some reason you can't use an array? ``` MESSAGE=("this is MESSAGE[0]" "this is MESSAGE[1]") MESSAGE[2]="I can add more, too!" for (( i=0; i<${#MESSAGE[@]}; ++i )); do echo "${MESSAG...
First, a couple of preliminary problems: `MESSAGE23="com."apple".cacng.tokend is present"` will not embed double-quotes in the variable value, use `MESSAGE23="com.\"apple\".cacng.tokend is present"` or `MESSAGE23='com."apple".cacng.tokend is present'` instead. Second, you should almost always put double-quotes around v...
46,721,993
I have a shell script that I use to export Env variables. This script calls a python script to get certain values from a web service that I need to store before running my primary python script. I've tried using a `RUN . /bot/env/setenv.sh`, but this doesn't seem to make the env variables available in the final contai...
2017/10/13
[ "https://Stackoverflow.com/questions/46721993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1143724/" ]
1. You are not running the docker container [as a daemon](https://docs.docker.com/engine/reference/run/#detached--d). > > docker run -d bot > > > 2. In my experience, print messages don't make it to the logs without input buffering disabled in python. > > python -u jbot.py > > >
For your first question, you should check the documentation of `docker run`. Shortly, you are attaching with container so you will never return to your terminal. In order to detach, you need to add option `-d`. The common used command to launch a container is `docker run -idt <container>`. For your second question, t...
52,911,986
I am working with ros on ubuntu 16.04. Because of this I am working with a virtual environment for python 2.7 and the ros python modules (rospy for example). The "python.pythonPath" is set to the virtual environment and the ros modules are linked through "python.autoComplete.extraPaths". This leads to the issue where ...
2018/10/21
[ "https://Stackoverflow.com/questions/52911986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10534965/" ]
I've never used probuilder, but in other 3d max app you will need to delete the inner polygons that to be able to cap that face. select all the polygons in the "well" and delete, you will now have a hole to fill [GIF] [![enter image description here](https://i.stack.imgur.com/W3My9.gif)][1](https://i.stack.imgur.com/W...
update I find a complex but accurate way to do this unity editor > Tools > Probuilder > editor > open vertex position editor when i select vertex, position editor put selected positions to txt file unity editor > tools > probuilder > editor > open new shape editor > shape selector > custom build face with position...
52,911,986
I am working with ros on ubuntu 16.04. Because of this I am working with a virtual environment for python 2.7 and the ros python modules (rospy for example). The "python.pythonPath" is set to the virtual environment and the ros modules are linked through "python.autoComplete.extraPaths". This leads to the issue where ...
2018/10/21
[ "https://Stackoverflow.com/questions/52911986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10534965/" ]
I've never used probuilder, but in other 3d max app you will need to delete the inner polygons that to be able to cap that face. select all the polygons in the "well" and delete, you will now have a hole to fill [GIF] [![enter image description here](https://i.stack.imgur.com/W3My9.gif)][1](https://i.stack.imgur.com/W...
As of probuilder 4, you can achieve this very quickly without using 'fill hole'. Fill Hole is useful, but not for this. 1. Enter edge select mode and select an edge containing two of the vertices you wish to make a face out of. 2. Extrude the edge (ctrl + e or 'extrude edges') to the general area of the third vertex. ...
56,443,552
I will service my django project with uwsgi on Ubuntu Server, but It doesn't run. I am using python 3.6 but the uwsgi shows me it's 2.7 I changed default python to python3.6 but uwsgi still doesn't work. This is my command : ``` uwsgi --http :8001 --home /home/ubuntu/repository/env --chdir /home/ubuntu/repository/...
2019/06/04
[ "https://Stackoverflow.com/questions/56443552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11598754/" ]
Unfortunately, uWSGI has to be compiled with python version matching with your virtualenv. That means: if uWSGI was compiled with python 2.7, you cannot use python 3.6 in your virtualenv (and in your Django app). Fortunately, there are some methods to fix that: * Installing uWSGI inside your virtualenv and using that...
The log tells there is no module named site > > ImportError: No module named site > > > I assume site is an django app. did you register this in your INSTALLED\_APPS (settings.py) Otherwise you may need to register your app. (apps.py in the site app) Please let me know if I helped you. Jasper
56,443,552
I will service my django project with uwsgi on Ubuntu Server, but It doesn't run. I am using python 3.6 but the uwsgi shows me it's 2.7 I changed default python to python3.6 but uwsgi still doesn't work. This is my command : ``` uwsgi --http :8001 --home /home/ubuntu/repository/env --chdir /home/ubuntu/repository/...
2019/06/04
[ "https://Stackoverflow.com/questions/56443552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11598754/" ]
Unfortunately, uWSGI has to be compiled with python version matching with your virtualenv. That means: if uWSGI was compiled with python 2.7, you cannot use python 3.6 in your virtualenv (and in your Django app). Fortunately, there are some methods to fix that: * Installing uWSGI inside your virtualenv and using that...
For those who cannot (or failed to) build language-independent uwsgi binary by following the second option as mentioned by @GwynBleidD, you can also build a seperate standalone uwsgi binary tied to different python plugin, by: * preserving the previously-built uwsgi binary * clean up previous build by running `make cl...
20,200,307
I am using GAE long time but can not find what is maximum length of ListProperty. I was read [documentation](https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#ListProperty) but not found solution I want to create ListProperty(long) to keep about 30 values of long or more. I want use...
2013/11/25
[ "https://Stackoverflow.com/questions/20200307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/665926/" ]
I've a list of 20K strings (not indexed though). I don't think there is limitation on the length, but there is limitation on each entity size. Be careful on indexing multi value properties, it could be expensive.
30 will be fine. Guido's answer about related question: <https://stackoverflow.com/a/15418435/1279005> So up to 100 repeated values will be fine. Repeated properties much easier to understand by using NDB as I think. You should try it. It's does not matter if you using it with Long or String properties - if the prope...
20,200,307
I am using GAE long time but can not find what is maximum length of ListProperty. I was read [documentation](https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#ListProperty) but not found solution I want to create ListProperty(long) to keep about 30 values of long or more. I want use...
2013/11/25
[ "https://Stackoverflow.com/questions/20200307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/665926/" ]
@marcadian has a pretty good answer. There's no limit specifically on a ListProperty. You do need to look at datastore limits on entities though: <https://developers.google.com/appengine/docs/python/datastore/#Python_Quotas_and_limits> The two most obvious limits are the 1MB maximum entity size and 20000 index entrie...
30 will be fine. Guido's answer about related question: <https://stackoverflow.com/a/15418435/1279005> So up to 100 repeated values will be fine. Repeated properties much easier to understand by using NDB as I think. You should try it. It's does not matter if you using it with Long or String properties - if the prope...
20,200,307
I am using GAE long time but can not find what is maximum length of ListProperty. I was read [documentation](https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#ListProperty) but not found solution I want to create ListProperty(long) to keep about 30 values of long or more. I want use...
2013/11/25
[ "https://Stackoverflow.com/questions/20200307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/665926/" ]
@marcadian has a pretty good answer. There's no limit specifically on a ListProperty. You do need to look at datastore limits on entities though: <https://developers.google.com/appengine/docs/python/datastore/#Python_Quotas_and_limits> The two most obvious limits are the 1MB maximum entity size and 20000 index entrie...
I've a list of 20K strings (not indexed though). I don't think there is limitation on the length, but there is limitation on each entity size. Be careful on indexing multi value properties, it could be expensive.
58,260,903
I tried various programs to get the required pattern (Given below). The program which got closest to the required result is given below: **Input:** ``` for i in range(1,6): for j in range(i,i*2): print(j, end=' ') print( ) ``` **Output:** ``` 1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 ``` **Required Outp...
2019/10/06
[ "https://Stackoverflow.com/questions/58260903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9957954/" ]
Store the printed value outside of the loop, then increment after its printed ``` v = 1 lines = 4 for i in range(lines): for j in range(i): print(v, end=' ') v += 1 print( ) ```
If you don't want to keep track of the count and solve this mathematically and be able to directly calculate any n-th line, the formula you are looking for is the one for, well, [triangle numbers](https://en.wikipedia.org/wiki/Triangular_number): ``` triangle = lambda n: n * (n + 1) // 2 for line in range(1, 5): t...
43,043,437
I'm trying to create a wordcloud from csv file. The csv file, as an example, has the following structure: ``` a,1 b,2 c,4 j,20 ``` It has more rows, more or less 1800. The first column has string values (names) and the second column has their respective frequency (int). Then, the file is read and the key,value row i...
2017/03/27
[ "https://Stackoverflow.com/questions/43043437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7658581/" ]
This is because the values in your dictionary are strings but wordcloud expects integer or floats. After I run your code then inspect your dictionary `d` I get the following. ``` In [12]: d Out[12]: {'a': '1', 'b': '2', 'c': '4', 'j': '20'} ``` Note the `' '` around the numbers means these are really strings. A...
``` # LEARNER CODE START HERE file_c="" for index, char in enumerate(file_contents): if(char.isalpha()==True or char.isspace()): file_c+=char file_c=file_c.split() file_w=[] for word in file_c: if word.lower() not in uninteresting_words and word.isalpha()==True: file_w.append(word) frequency={} for ...
5,719,545
I am working on web-crawler [using python]. Situation is, for example, I am behind server-1 and I use proxy setting to connect to the Outside world. So in Python, using proxy-handler I can fetch the urls. Now thing is, I am building a crawler so I cannot use only one IP [otherwise I will be blocked]. To solve this, I ...
2011/04/19
[ "https://Stackoverflow.com/questions/5719545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/715600/" ]
**Update** Sounds like you're looking to connect to proxy A and from there initiate HTTP connections via proxies B, C, D which are outside of A. You might look into the [proxychains project](http://proxychains.sourceforge.net/) which says it can "tunnel any protocol via a user-defined chain of TOR, SOCKS 4/5, and HTTP ...
I recommend you take a look at CherryProxy. It lets you send a proxy request to an intermediate server (where CherryProxy is running) and then forward your HTTP request to a proxy on a second level machine (e.g. squid proxy on another server) for processing. Viola! A two-level proxy chain. <http://www.decalage.info/py...
66,775,948
Some python packages wont work in python 3.7 . So wanted to downgrade the default python version in google colab.Is it possible to do? If so how to proceed.Please guide me..
2021/03/24
[ "https://Stackoverflow.com/questions/66775948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15069182/" ]
You could install python 3.6 with `miniconda`: ``` %%bash MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh MINICONDA_PREFIX=/usr/local wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT chmod +x $MINICONDA_INSTALLER_SCRIPT ./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX ``` And...
The following code snippet below will download Python 3.6 without any Colab pre-installed libraries (such as Tensorflow). You can install them later with pip, like `!pip install tensorflow`. Please note that this won't downgrade your default python in colab, rather it would provide a workaround to work with other pytho...
53,972,642
I'm a lawyer and python beginner, so I'm both (a) dumb and (b) completely out of my lane. I'm trying to apply a regex pattern to a text file. The pattern can sometimes stretch across multiple lines. I'm specifically interested in these lines from the text file: ``` Considered and decided by Hemingway, Presiding...
2018/12/29
[ "https://Stackoverflow.com/questions/53972642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10823652/" ]
You are passing in **single lines**, because you are iterating over the open file referenced by `case`. The regex is never passed anything other than a single line of text. Your regexes can each match *some* of the lines, but they don't all together match the same single line. You'd have to read in more than one line....
Instead of multiple `re.search`, you could use [`re.findall`](https://docs.python.org/3.7/library/re.html#re.findall) with a really short and simple pattern to find all judges at once: ``` import re text = """Considered and decided by Hemingway, Presiding Judge; Bell, Judge; and \n \n Dickinson, Emily, Judg...
53,972,642
I'm a lawyer and python beginner, so I'm both (a) dumb and (b) completely out of my lane. I'm trying to apply a regex pattern to a text file. The pattern can sometimes stretch across multiple lines. I'm specifically interested in these lines from the text file: ``` Considered and decided by Hemingway, Presiding...
2018/12/29
[ "https://Stackoverflow.com/questions/53972642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10823652/" ]
You are passing in **single lines**, because you are iterating over the open file referenced by `case`. The regex is never passed anything other than a single line of text. Your regexes can each match *some* of the lines, but they don't all together match the same single line. You'd have to read in more than one line....
Assuming you can read the file all at once (ie the file is not too big). You can extract judge information as follows: ``` import re regex = re.compile( r'decided\s+by\s+(?P<presiding_judge>[A-Za-z]+)\s*,\s+Presiding\s+Judge;' r'\s+(?P<judge>[A-Za-z]+)\s*,\s+Judge;' r'\s+and\s+(?P<extra_judges>[A-Za-z,\s]...
10,512,026
I'm new to python and am trying to read "blocks" of data from a file. The file is written something like: ``` # Some comment # 4 cols of data --x,vx,vy,vz # nsp, nskip = 2 10 # 0 0.0000000 # 1 4 0.5056E+03 0.8687E-03 -0.1202E-02 0.4652E-02 0.3776E+03 0.8687E-...
2012/05/09
[ "https://Stackoverflow.com/questions/10512026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1325437/" ]
A quick basic read: ``` >>> def read_blocks(input_file, i, j): empty_lines = 0 blocks = [] for line in open(input_file): # Check for empty/commented lines if not line or line.startswith('#'): # If 1st one: new block if empty_lines == 0: blocks.append(...
The following code should probably get you started. You will probably need the re module. You can open the file for reading using: ``` f = open("file_name_here") ``` You can read the file one line at a time by using ``` line = f.readline() ``` To jump to the next line that starts with a "#", you can use: ``` w...
53,949,017
I'm trying to develop a lambda that has to work with S3 and dynamoDB. The thing is that because I am not familiar with the SDK of aws for go I will have lots of tests and tries. Each time I will change the code is another time I have to compile the project and upload it to aws. Is there any way to do it locally? pass s...
2018/12/27
[ "https://Stackoverflow.com/questions/53949017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8885009/" ]
You can use the lambci docker image(s) to execute your code locally using the same Lambda runtimes that are used on AWS. <https://github.com/lambci/docker-lambda> You can also run dynamo DB locally in another container as well <https://hub.docker.com/r/amazon/dynamodb-local/> To simulate credentials/roles that woul...
You could use this [aws-lambda-go-test](https://github.com/yogeshlonkar/aws-lambda-go-test) module which can run lambda locally and can be used to test the actual response from lambda full disclosure I forked and upgraded this module
59,001,784
I am building a webscrape that will run over and over that will insert new data or update data based on ID. `if 'id' == 'id':` My goal is to avoid duplicates. MySQL table is ready and built. What is the best Pythonic way to check your python list before inserting/updating it in MySQL DB using SQLAlchemy? Below are my...
2019/11/22
[ "https://Stackoverflow.com/questions/59001784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11396478/" ]
I am using a helper function to create the dynamic sql update queries: ``` def construct_update(table_name, where_vals, update_vals): query = table_name.update() for k, v in where_vals.items(): query = query.where(getattr(table_name.c, k) == v) return query.values(**update_vals) ``` basically you...
You can try using <https://marshmallow.readthedocs.io/en/stable/> library to make validation Build `Schema` and define fields with types you need. You can also use `@pre_load` and `@post_load` decorators to manipulate your data
2,105,508
I'm new to Cython and I'm trying to use Cython to wrap a C/C++ static library. I made a simple example as follow. **Test.h:** ``` #ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif ``` **Test.cpp** ``` #include "test.h" int add(int a, int b) { return a+b; } int multipy(i...
2010/01/20
[ "https://Stackoverflow.com/questions/2105508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150324/" ]
If your C++ code is only used by the wrapper, another option is to let the setup compile your .cpp file, like this: ``` from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("test", ["test.pyx", "test.cpp"], ...
I think you can fix this specific problem by specifying the right `library_dirs` (where you actually **put** libtest.a -- apparently it's not getting found), but I think then you'll have another problem -- your entry points are not properly declared as `extern "C"`, so the function's names will have been "mangled" by t...
2,105,508
I'm new to Cython and I'm trying to use Cython to wrap a C/C++ static library. I made a simple example as follow. **Test.h:** ``` #ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif ``` **Test.cpp** ``` #include "test.h" int add(int a, int b) { return a+b; } int multipy(i...
2010/01/20
[ "https://Stackoverflow.com/questions/2105508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150324/" ]
Your `Test.pyx` file isn't doing what you expect. The `print add(2,3)` line *will not* call the `add()` C++ function; you have to explicitly create a wrapper function to do that. Cython doesn't create wrappers for you automatically. Something like this is probably what you want: ``` cdef extern from "test.h": ...
I think you can fix this specific problem by specifying the right `library_dirs` (where you actually **put** libtest.a -- apparently it's not getting found), but I think then you'll have another problem -- your entry points are not properly declared as `extern "C"`, so the function's names will have been "mangled" by t...
2,105,508
I'm new to Cython and I'm trying to use Cython to wrap a C/C++ static library. I made a simple example as follow. **Test.h:** ``` #ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif ``` **Test.cpp** ``` #include "test.h" int add(int a, int b) { return a+b; } int multipy(i...
2010/01/20
[ "https://Stackoverflow.com/questions/2105508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/150324/" ]
If your C++ code is only used by the wrapper, another option is to let the setup compile your .cpp file, like this: ``` from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("test", ["test.pyx", "test.cpp"], ...
Your `Test.pyx` file isn't doing what you expect. The `print add(2,3)` line *will not* call the `add()` C++ function; you have to explicitly create a wrapper function to do that. Cython doesn't create wrappers for you automatically. Something like this is probably what you want: ``` cdef extern from "test.h": ...
74,179,391
I am responsible for a series of exercises for nonlinear optimization. I thought it would be cool to start with some examples of optimization problems and solve them with `pyomo` + some black box solvers. However, as the students learn more about optimization algorithms I wanted them to also implement some simple meth...
2022/10/24
[ "https://Stackoverflow.com/questions/74179391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11785620/" ]
You said using jQuery , so no need to loops and addEventListener , all you need is just specifying displayed data inside link using data attribute (like data-text in below snippet ) use the [hover](https://api.jquery.com/hover/) listener then access current hovered by using **`$(this)`** key word , then display the da...
There's a few issues with your code * you need to use `innerText` or `innerHtml` instead of `value` * next you need to pass the event into your mouse over and use the current target instead of `boxLi[i]` * finally, move your ids to the li as that is what the mouse over is on Also this isn't jQuery ```js const firstu...
74,179,391
I am responsible for a series of exercises for nonlinear optimization. I thought it would be cool to start with some examples of optimization problems and solve them with `pyomo` + some black box solvers. However, as the students learn more about optimization algorithms I wanted them to also implement some simple meth...
2022/10/24
[ "https://Stackoverflow.com/questions/74179391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11785620/" ]
You said using jQuery , so no need to loops and addEventListener , all you need is just specifying displayed data inside link using data attribute (like data-text in below snippet ) use the [hover](https://api.jquery.com/hover/) listener then access current hovered by using **`$(this)`** key word , then display the da...
To make your code a bit more readable, you should use `querySelectorAll` to select the links. Then run over the elements with `forEach` to add an `eventListener` per element. In the example below I have created a function called *handleMouseOver*. This function expects an id as a parameter, which is the id of the list...
18,874,387
Just a little question : it's possible to force a build in Buildbot via a python script or command line (and not via the web interface) ? Thank you!
2013/09/18
[ "https://Stackoverflow.com/questions/18874387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1330954/" ]
If you have a PBSource configured in your master.cfg, you can send a change from the command line: ``` buildbot sendchange --master {MASTERHOST}:{PORT} --auth {USER}:{PASS} --who {USER} {FILENAMES..} ```
You can make a python script using the urlib2 or requests library to simulate a POST to the web UI ``` import urllib2 import urllib import cookielib import uuid import unittest import sys from StringIO import StringIO class ForceBuildApi(): MAX_RETRY = 3 def __init__(self, server): self.server = serv...
60,913,598
I am trying to train EfficientNetB1 on Google Colab and constantly running into different issues with correct import statements from Keras or Tensorflow.Keras, currently this is how my imports look like ``` import tensorflow as tf from tensorflow.keras import backend as K from tensorflow.keras.preprocessing.image imp...
2020/03/29
[ "https://Stackoverflow.com/questions/60913598", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9201770/" ]
The problem is the way you import the efficientnet. You import it from the `Keras` package and not from the `TensorFlow.Keras` package. Change your efficientnet import to ``` import efficientnet.tfkeras as enet ```
Not sure, but this error maybe caused by wrong TF version. Google Colab for now comes with TF 1.x by default. Try this to change the TF version and see if this resolves the issue. ``` try: %tensorflow_version 2.x except: print("Failed to load") ```
43,109,167
Below is my data set ``` Date Time 2015-05-13 23:53:00 ``` I want to convert date and time into floats as separate columns in a python script. The output should be like date as `20150513` and time as `235300`
2017/03/30
[ "https://Stackoverflow.com/questions/43109167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7521618/" ]
If all you need is to strip the hyphens and colons, [*str.replace()*](https://docs.python.org/2.7/library/stdtypes.html#str.replace) should do the job: ``` >>> s = '2015-05-13 23:53:00' >>> s.replace('-', '').replace(':', '') '20150513 235300' ``` For mort sophisticated reformatting, parse the input with [*time.strp...
If you have a datetime you can use [strftime()](http://strftime.org/) ``` your_time.strftime('%Y%m%d.%H%M%S') ``` And if your variables are string, You can use replace() ``` dt = '2015-05-13 23:53:00' date = dt.split()[0].replace('-','') time = dt.split()[1].replace(':','') fl = float(date+ '.' + time) ```
43,109,167
Below is my data set ``` Date Time 2015-05-13 23:53:00 ``` I want to convert date and time into floats as separate columns in a python script. The output should be like date as `20150513` and time as `235300`
2017/03/30
[ "https://Stackoverflow.com/questions/43109167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7521618/" ]
If all you need is to strip the hyphens and colons, [*str.replace()*](https://docs.python.org/2.7/library/stdtypes.html#str.replace) should do the job: ``` >>> s = '2015-05-13 23:53:00' >>> s.replace('-', '').replace(':', '') '20150513 235300' ``` For mort sophisticated reformatting, parse the input with [*time.strp...
``` date = "2015-05-13".replace("-", "") time = "10:58:56".replace(":", "") ```
43,109,167
Below is my data set ``` Date Time 2015-05-13 23:53:00 ``` I want to convert date and time into floats as separate columns in a python script. The output should be like date as `20150513` and time as `235300`
2017/03/30
[ "https://Stackoverflow.com/questions/43109167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7521618/" ]
If you have a datetime you can use [strftime()](http://strftime.org/) ``` your_time.strftime('%Y%m%d.%H%M%S') ``` And if your variables are string, You can use replace() ``` dt = '2015-05-13 23:53:00' date = dt.split()[0].replace('-','') time = dt.split()[1].replace(':','') fl = float(date+ '.' + time) ```
``` date = "2015-05-13".replace("-", "") time = "10:58:56".replace(":", "") ```
31,244,525
In python, one can attribute some values to some of the keywords that are already predefined in python, unlike other languages. Why? This is not all, some. ``` > range = 5 > range > 5 ``` But for ``` > def = 5 File "<stdin>", line 1 def = 5 ^ SyntaxError: invalid syntax ``` One possible hypothesis ...
2015/07/06
[ "https://Stackoverflow.com/questions/31244525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3302133/" ]
While `range` is nothing but a built-in function, `def` is a keyword. (Most IDEs should indicate the difference with appropriate colors.) Functions - whether built-in or not - can be redefined. And they don't have to remain functions, but can become integers like `range` in your example. But you can never redefine key...
The keyword 'range' is a function, you can create some other vars as well as sum, max... In the other hand, keyword 'def' expects a defined structure in order to create a function. ``` def <functionName>(args): ```
31,244,525
In python, one can attribute some values to some of the keywords that are already predefined in python, unlike other languages. Why? This is not all, some. ``` > range = 5 > range > 5 ``` But for ``` > def = 5 File "<stdin>", line 1 def = 5 ^ SyntaxError: invalid syntax ``` One possible hypothesis ...
2015/07/06
[ "https://Stackoverflow.com/questions/31244525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3302133/" ]
While `range` is nothing but a built-in function, `def` is a keyword. (Most IDEs should indicate the difference with appropriate colors.) Functions - whether built-in or not - can be redefined. And they don't have to remain functions, but can become integers like `range` in your example. But you can never redefine key...
You are confused between keywords and built-in functions. `def` is a keyword, but `range` and `len` are simply built-in functions. Any function can always be overridden, but a keyword cannot. The full list of keywords can be found in `keywords.kwlist`.
69,023,789
I'm working on automating changing image colors using python. The image I'm using is below, i'd love to move it from red to another range of colors, say green, keeping the detail and shading if possible. I've been able to convert *some* of the image to a solid color, losing all detail. [![Blue instead of red.](https:/...
2021/09/02
[ "https://Stackoverflow.com/questions/69023789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13919173/" ]
This is one way to approach the problem in Python/OpenCV. But for red, it is very hard to do because red spans 0 hue, which also is the hue for gray and white and black, which you have in your image. The other issue you have is that skin tones has red shades, so you cannot pick too large of ranges for your colors. Also...
You can start with red, but the trick is to invert the image so red is now at hue 90 in OpenCV range and for example blue is at hue 30. So in Python/OpenCV, you can do the following: Input: [![enter image description here](https://i.stack.imgur.com/sFW5v.jpg)](https://i.stack.imgur.com/sFW5v.jpg) ``` import cv2 impo...
69,023,789
I'm working on automating changing image colors using python. The image I'm using is below, i'd love to move it from red to another range of colors, say green, keeping the detail and shading if possible. I've been able to convert *some* of the image to a solid color, losing all detail. [![Blue instead of red.](https:/...
2021/09/02
[ "https://Stackoverflow.com/questions/69023789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13919173/" ]
This is one way to approach the problem in Python/OpenCV. But for red, it is very hard to do because red spans 0 hue, which also is the hue for gray and white and black, which you have in your image. The other issue you have is that skin tones has red shades, so you cannot pick too large of ranges for your colors. Also...
Starting with a blue image rather than red allows one to use an expanded range for inRange() and do a better job in Python/OpenCV. Here is a change from blue to red. Input: [![enter image description here](https://i.stack.imgur.com/f4iX0.jpg)](https://i.stack.imgur.com/f4iX0.jpg) ``` import cv2 import numpy as np #...
41,480,055
Using Python 2.7 and Django 1.10.4, I was trying to deploy my app to pythonanywhere, but I keep getting this error. [![enter image description here](https://i.stack.imgur.com/1FGB1.png)](https://i.stack.imgur.com/1FGB1.png) **Error Log** [![enter image description here](https://i.stack.imgur.com/bEiKL.png)](https://i...
2017/01/05
[ "https://Stackoverflow.com/questions/41480055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7248057/" ]
First of all, check the link give in the error log - <https://help.pythonanywhere.com/pages/DebuggingImportError/> You could also search for 'from django core wsgi no module named wsgi'. There are many answers already, and I think you should be able to find the answer to your problem there.
Make sure that your project name is "mysite" if not update this line ``` os.environ['DJANGO_SETTINGS_MODULE'] = '<your-project-name>.settings' ``` Project name will be the directory name parent to your app name, see that in your local machine.
32,814,489
I've read numerous tutorials and stackex questions/answers, but apparently my questions is too specific and my knowledge too limited to piece together a solution. **[Edit]** *My confusion was mostly due to the fact that my project required both a shell script and a makefile to run a simple python program. I was not s...
2015/09/28
[ "https://Stackoverflow.com/questions/32814489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4876803/" ]
To pass data between two otherwise unconnected View Controllers you'll need to use: ``` presentingViewController!.dismissViewControllerAnimated(true, completion: nil) ``` and transmit your data via viewWillDisappear like this: ``` override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animate...
I have found an answer: using global variables. Here is what I did: In my first view controller (the view controller that is sending the string), I made a global variable above the class definition, like this: ``` import UIKit var chosenClass = String() class EntryViewController: UIViewController, UITableViewD...
59,302,243
I'm using this code with python and opencv for displaying about 100 images. But `imshow` function throws an error. Here is my code: ```py nn=[] for j in range (187) : nn.append(j+63) images =[] for i in nn: path = "02291G0AR\\" n1=cv2.imread(path +"Bi000{}".format(i)) ...
2019/12/12
[ "https://Stackoverflow.com/questions/59302243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7415394/" ]
1. You have to visualize one image at a time, while you are passing `images` which is a list 2. `cv2.imshow()` takes as first argument the name of the window So you should iterate on your loaded images like: ```py for image in images: cv2.imshow('Image', image) cv2.waitKey(0) # Wait for user interaction ```...
You can use the following snippet to montage more than one image: ``` from imutils import build_montages im_shape = (129,196) montage_shape = (7,3) montages = build_montages(images, im_shape, montage_shape) ``` `im_shape :` A tuple containing the width and height of each image in the montage. Here we indicate that a...
53,647,426
How can we fetch details of particular row from mysql database using variable in python? I want to print the details of particular row using variable from my database and I think I should use something like this: ``` data = cur.execute("SELECT * FROM loginproject.Pro WHERE Username = '%s';"% rob) ``` But this is sh...
2018/12/06
[ "https://Stackoverflow.com/questions/53647426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10333908/" ]
Don't put html in laravel controller, you can return the $employees as data and then add html in your ajax success action
``` public function search(Request $request){ if($request->ajax()) { $employees = DB::table('employeefms')->where('last_name','LIKE','%'.$request->search.'%') ->orWhere('first_name','LIKE','%'.$request->search.'%')->get(); if(!empty($employees)) { return js...
18,289,377
I'm using Code::Blocks and want to have gdb python-enabled. So I followed the C::B wiki <http://wiki.codeblocks.org/index.php?title=Pretty_Printers> to configure it. My pp.gdb is the same as that in the wiki except that I replace the path with my path to printers.py. ``` python import sys sys.path.insert(0, 'C:/Pro...
2013/08/17
[ "https://Stackoverflow.com/questions/18289377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1549348/" ]
Today, I also see this similar issue, after I update my libstdcxx's pretty from an old gcc4.7.x version to the gcc's trunk HEAD version to fix some other problems. I'm also using Codeblocks, and I have those two lines in my customized gdb script. ``` from libstdcxx.v6.printers import register_libstdcxx_printers regis...
You probably don't need to have this code. It seems like the libstdc++ prnters are preloaded -- which is normal in many setups... we designed printers to "just work", and the approach of using python code to explicitly load printers was a transitional thing. One way to check is to run gdb -nx, start your C++ program, ...
18,289,377
I'm using Code::Blocks and want to have gdb python-enabled. So I followed the C::B wiki <http://wiki.codeblocks.org/index.php?title=Pretty_Printers> to configure it. My pp.gdb is the same as that in the wiki except that I replace the path with my path to printers.py. ``` python import sys sys.path.insert(0, 'C:/Pro...
2013/08/17
[ "https://Stackoverflow.com/questions/18289377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1549348/" ]
You probably don't need to have this code. It seems like the libstdc++ prnters are preloaded -- which is normal in many setups... we designed printers to "just work", and the approach of using python code to explicitly load printers was a transitional thing. One way to check is to run gdb -nx, start your C++ program, ...
If you got this error `RuntimeError: pretty-printer already registered: libstdc++-v6` that's mean that you don't need to do anything mentioned in [C::B wiki](http://wiki.codeblocks.org/index.php?title=Pretty_Printers). You can just uncheck `Disable startup scripts (-nx)` option under: `Codeblocks->Settings->Debugger...
18,289,377
I'm using Code::Blocks and want to have gdb python-enabled. So I followed the C::B wiki <http://wiki.codeblocks.org/index.php?title=Pretty_Printers> to configure it. My pp.gdb is the same as that in the wiki except that I replace the path with my path to printers.py. ``` python import sys sys.path.insert(0, 'C:/Pro...
2013/08/17
[ "https://Stackoverflow.com/questions/18289377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1549348/" ]
Today, I also see this similar issue, after I update my libstdcxx's pretty from an old gcc4.7.x version to the gcc's trunk HEAD version to fix some other problems. I'm also using Codeblocks, and I have those two lines in my customized gdb script. ``` from libstdcxx.v6.printers import register_libstdcxx_printers regis...
If you got this error `RuntimeError: pretty-printer already registered: libstdc++-v6` that's mean that you don't need to do anything mentioned in [C::B wiki](http://wiki.codeblocks.org/index.php?title=Pretty_Printers). You can just uncheck `Disable startup scripts (-nx)` option under: `Codeblocks->Settings->Debugger...
23,480,431
I want to format a .py file (that generates a random face every time the page is refreshed) using HTML, in the Terminal, that can run in a browser. I have **chmod`ed** it so it should work, but whenever I run in it in a browser, I get an **internal service error**. Can someone help me figure out what it wrong? ``` #!/...
2014/05/05
[ "https://Stackoverflow.com/questions/23480431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2888249/" ]
This is neither valid HTML nor valid Python. You can't simply mix in HTML tags into the middle of a Python script like that: you need at the very least to put them inside quotes so that they are a valid string. ``` #!/usr/bin/python print "Content-Type: text/html\n" print """ <!DOCTYPE html> <html> <pre> """ def ... ...
You need a templating engine like jinja to have this <http://jinja.pocoo.org/>
28,979,898
I downloaded `Microsoft Visual C++ Compiler for Python 2.7` and it installed in `C:\Users\user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat` However, I am getting the `error: Unable to find vcvarsall.bat` error when attempting to install "MySQL-python". I added `C:\Users\user\AppDat...
2015/03/11
[ "https://Stackoverflow.com/questions/28979898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3412518/" ]
Use the command prompt shortcut provided from installing the MSI. This will launch the prompt with VCVarsall.bat activated for the targeted environment. Depending on your installation, you can find this in the Start Menu under All Program -> Microsoft Visual C++ For Python -> then pick the command prompt based on x64...
this worked: <https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows> i uninstalled visual studio 2013 and net framework 4 first. i didnt need visual studio. i only installed it because i was playing with c++. this worked on a virtual environment: add `C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin...
28,979,898
I downloaded `Microsoft Visual C++ Compiler for Python 2.7` and it installed in `C:\Users\user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat` However, I am getting the `error: Unable to find vcvarsall.bat` error when attempting to install "MySQL-python". I added `C:\Users\user\AppDat...
2015/03/11
[ "https://Stackoverflow.com/questions/28979898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3412518/" ]
Use the command prompt shortcut provided from installing the MSI. This will launch the prompt with VCVarsall.bat activated for the targeted environment. Depending on your installation, you can find this in the Start Menu under All Program -> Microsoft Visual C++ For Python -> then pick the command prompt based on x64...
Setting ``` SET DISTUTILS_USE_SDK=1 SET MSSdk=1 ``` in Visual C++ 2008 Command Prompt worked for me.
60,063,620
I am working with code that my client insists cannot be changed. It needs to be called using a python command like subprocess.call() ... The code includes a use of the exit() function. When exiting, the exit() function contains data as a parameter: ``` exit(data) ``` How can I capture the data parameter that the scr...
2020/02/04
[ "https://Stackoverflow.com/questions/60063620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7188090/" ]
I found this in 3 Swift files at the end of my code: ``` class UIImage { private func newBorderMask(_ borderSize: Int, size: CGSize) -> CGImageRef? { } } ``` So I saw that the code was redeclaring `class UIImage` after the `extension UIImage`. In each case, I moved the `private func` into the `extension UII...
You need ``` import UIKit ``` at the top of the file
10,188,165
I'm using mongodb for my python(2.7) project with django framework..when i give python manage.py runserver it will work but if i sync the db (python manage.py syncdb) the following error displayed in terminal ``` Creating tables ... Traceback (most recent call last): File "manage.py", line 14, in <module> exec...
2012/04/17
[ "https://Stackoverflow.com/questions/10188165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1095290/" ]
You need to use Django-nonrel instead of Django.
I've used mongoengine with django but you need to create a file like mongo\_models.py for example. In that file you define your Mongo documents. You then create forms to match each Mongo document. Each form has a save method which inserts or updates whats stored in Mongo. Django forms are designed to plug into any data...
56,693,939
My dict (`cpc_docs`) has a structure like ```py { sym1:[app1, app2, app3], sym2:[app1, app6, app56, app89], sym3:[app3, app887] } ``` My dict has 15K keys and they are unique strings. Values for each key are a list of app numbers and they can appear as values for more than one key. I've looked here [[Python: Best W...
2019/06/20
[ "https://Stackoverflow.com/questions/56693939", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5170800/" ]
Your `setdefault` code is almost there, you just need an extra loop over the lists of values: ``` res = {} for k, lst in cpc_docs.items(): for v in lst: res.setdefault(v, []).append(k) ```
### First create a list of key, value tuples ```py new_list=[] for k,v in cpc_docs.items(): for i in range(len(v)): new_list.append((k,v[i])) ``` ### Then for each tuple in the list, add the key if it isn't in the dict and append the ```py doc_cpc = defaultdict(set) for tup in cpc_doc_list: doc_cpc...
6,143,087
For one of my projects I have a python program built around the python [cmd](http://docs.python.org/library/cmd.html) class. This allowed me to craft a mini language around sql statements that I was sending to a database. Besides making it far easier to connect with python, I could do things that sql can't do. This was...
2011/05/26
[ "https://Stackoverflow.com/questions/6143087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/724357/" ]
The limitations of making a "mini language" have become apparent. Proper languages have a tree-like structure and more complex syntax than `cmd` can handle easily. Sometimes it's actually easier to use Python directly than it is to invent your own DSL. Currently, your DSL probably reads a script-like file of command...
After examining the problem set some more, I've come to the conclusion that I can leave the minilanguage alone. It has all the features I need, and I don't have the time to rebuild the project from the ground up. This has been an interesting problem and I'm no longer sure I would build another minilanguage if I encount...
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
Use a module from the [Data Persistence](https://docs.python.org/3/library/persistence.html) section of the standard library, or save it as [json](https://docs.python.org/3/library/json.html), or as a [csv file](https://docs.python.org/3/library/csv.html).
You just convert your list to array inside in function . ``` np.save('path/to/save', np.array(your_list)) ``` to load : ``` arr=np.load(''path/to/save.npy').tolist() ``` I hope it will be helpful
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
You just convert your list to array inside in function . ``` np.save('path/to/save', np.array(your_list)) ``` to load : ``` arr=np.load(''path/to/save.npy').tolist() ``` I hope it will be helpful
There is no way you can do that without any external modules, such as `numpy` or `pickle`. Using `pickle`, you can do this: (I am assuming you want to save the `myBook` variable) ```py import pickle pickle.dump(myBook, open("foo.bar", "wb")) #where foo is name of file and bar is extension #also wb is saving type, you ...
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
You just convert your list to array inside in function . ``` np.save('path/to/save', np.array(your_list)) ``` to load : ``` arr=np.load(''path/to/save.npy').tolist() ``` I hope it will be helpful
As evinced by the many other answers, there are many ways to do this, but I thought it was helpful to have a example. By changing the top of your file as so, you can use the shelve module. There are a variety of other things you can fix in your code if you are curious, you could try <https://codereview.stackexchange....
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
Use a module from the [Data Persistence](https://docs.python.org/3/library/persistence.html) section of the standard library, or save it as [json](https://docs.python.org/3/library/json.html), or as a [csv file](https://docs.python.org/3/library/csv.html).
There is no way you can do that without any external modules, such as `numpy` or `pickle`. Using `pickle`, you can do this: (I am assuming you want to save the `myBook` variable) ```py import pickle pickle.dump(myBook, open("foo.bar", "wb")) #where foo is name of file and bar is extension #also wb is saving type, you ...
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
Use a module from the [Data Persistence](https://docs.python.org/3/library/persistence.html) section of the standard library, or save it as [json](https://docs.python.org/3/library/json.html), or as a [csv file](https://docs.python.org/3/library/csv.html).
There are innumerable kinds of serialization options, but a time-tested favorite is JSON. JavaScript Object Notation looks like: ``` [ "this", "is", "a", "list", "of", "strings", "with", "a", { "dictionary": "of", "values": 4, "an": "example" }, "can ...
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
Use a module from the [Data Persistence](https://docs.python.org/3/library/persistence.html) section of the standard library, or save it as [json](https://docs.python.org/3/library/json.html), or as a [csv file](https://docs.python.org/3/library/csv.html).
As evinced by the many other answers, there are many ways to do this, but I thought it was helpful to have a example. By changing the top of your file as so, you can use the shelve module. There are a variety of other things you can fix in your code if you are curious, you could try <https://codereview.stackexchange....
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
There are innumerable kinds of serialization options, but a time-tested favorite is JSON. JavaScript Object Notation looks like: ``` [ "this", "is", "a", "list", "of", "strings", "with", "a", { "dictionary": "of", "values": 4, "an": "example" }, "can ...
There is no way you can do that without any external modules, such as `numpy` or `pickle`. Using `pickle`, you can do this: (I am assuming you want to save the `myBook` variable) ```py import pickle pickle.dump(myBook, open("foo.bar", "wb")) #where foo is name of file and bar is extension #also wb is saving type, you ...
56,331,413
I am wondering how I can save whatever I added to a list when I close a python file. For example, in this "my contact" program that I wrote below, if I add information about 'Jane Doe', what could I do so that next time I open up the same file, Jane Doe still exists. ``` def main(): myBook = Book([{"name": 'John ...
2019/05/27
[ "https://Stackoverflow.com/questions/56331413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11563937/" ]
There are innumerable kinds of serialization options, but a time-tested favorite is JSON. JavaScript Object Notation looks like: ``` [ "this", "is", "a", "list", "of", "strings", "with", "a", { "dictionary": "of", "values": 4, "an": "example" }, "can ...
As evinced by the many other answers, there are many ways to do this, but I thought it was helpful to have a example. By changing the top of your file as so, you can use the shelve module. There are a variety of other things you can fix in your code if you are curious, you could try <https://codereview.stackexchange....
73,542,262
I've created 3 files, `snek.py`, `requirements.txt` and `runsnek.py`. `runsnek.py` installs all the required modules in `requirements.txt` with pip and runs `snek.py`. Everything works fine on Windows 10, but when trying to run on Ubuntu (WSL2), an error is thrown: ``` ❯ python runsnek.py Requirement already up-to-dat...
2022/08/30
[ "https://Stackoverflow.com/questions/73542262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17747971/" ]
It seems you are using python2 in your WSL2 instance. In the line `os.system('python snek.py')` it should run python2 instead of python3. To correct the problem, you can change this line of code by `os.system('python3 snek.py')`.
Your `run` file can be simplified: ``` import sys, os print('Running with ' + sys.executable) os.system(sys.executable + ' -m pip install --upgrade -r requirements.txt') os.system(sys.executable +' snek.py') ``` `sys.executable` always contains the path of the python interpreter running the current script. Using `py...
72,097,284
How can you set the desktop background to a solid color programmatically in python? The reason I want this is to make myself a utility which changes the background color depending on which of several virtual desktops I'm using.
2022/05/03
[ "https://Stackoverflow.com/questions/72097284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/169774/" ]
With a little help of `row_number` analytic function: ``` SQL> ALTER TABLE dummy_test_table ADD batch_id VARCHAR2 (10); Table altered. SQL> UPDATE dummy_test_table a 2 SET a.batch_id = 3 (WITH 4 temp 5 AS 6 (SELECT seq_no, 7 ...
One option is to use `DENSE_RANK()` analytic function within a MERGE DML statement such as ```sql MERGE INTO dummy_test_table d1 USING (SELECT seq_no, LPAD(DENSE_RANK() OVER(ORDER BY seq_no), 3, '0') AS dr FROM dummy_test_table) d2 ON (d1.rowid = d2.rowid) WHEN MATCHED THEN UPDATE SET d1.batch_id = dr ``...
24,027,579
I am working on a project where I have a client server model in python. I set up a server to monitor requests and send back data. PYZMQ supports: tcp, udp, pgm, epgm, inproc and ipc. I have been using tcp for interprocess communication, but have no idea what i should use for sending a request over the internet to a ser...
2014/06/04
[ "https://Stackoverflow.com/questions/24027579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2383037/" ]
Any particular reason you're not using `ipc` or `inproc` for interprocess communication? Other than that, generally, you can consider `tcp` the universal communicator; it's not always the best choice, but no matter what (so long as you actually have an IP address) it will work. Here's what you need to know when makin...
Over the internet, TCP or UDP are the usual choices. I don't know if pyzmq has its own delivery guarantees on top of the transport protocol. If it doesn't, TCP will guarantee in-order delivery of all messages, while UDP may drop messages if the network is congested. If you don't know what you want, TCP is the simplest...
42,972,184
I am new to python. As part of my project, I am working with python2.7. I am dealing with multiple files in python. Here I am facing a problem to use a variable of particular function from another file which was I already imported in my current file. Please help me to achieve this. ``` file1.py class connect(): # ...
2017/03/23
[ "https://Stackoverflow.com/questions/42972184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7167331/" ]
So you have edited it quite a bit since I started writing about conventions so I have started again. First, your return statement is out of indentation, it should be indented into the output method. ``` def output(): a = "Hello" data = // some operations return data ``` Second, the convention in Python ...
One option you have is to return all the data you need from the function: file1.py ``` class connect(): # Contains different definitions def output(): a = "Hello" data = // some operations return a,data # Return all the variables as a tuple ``` file2.py ``` from file1 import conne...
17,438,469
This python3.3 code on win 7, why I got error: ``` import random guesses_made = 0 name = raw_input('Hello! What is your name?\n') number = random.randint(1, 20) print "Well, {0}, I am thinking of a number between 1 and 20" # error here !!! **print "Well, {0}, I am thinking of a number between 1 and 20" ...
2013/07/03
[ "https://Stackoverflow.com/questions/17438469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2420472/" ]
Two things: In python 3, `raw_input()` [has been changed](http://docs.python.org/3.0/whatsnew/3.0.html#builtins) to `input()`. Also, [`print` is no longer a statement but a function](http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function), so you must do: ``` print("Well, {0}, I am thinking of a number bet...
I think that last line should read: ``` print("Well, {0}, I am thinking of a number between 1 and 20".format(name)) ``` This was tested. I am pretty new to p3.3, so go easy on me :)
5,823,163
I'm currently in the process of programming a server which can let clients interact with a piece of hardware. For the interested readers it's a device which monitors the wavelength of a set of lasers concurrently (and controls the lasers). The server should be able to broadcast the wavelengths (a list of floats) on a r...
2011/04/28
[ "https://Stackoverflow.com/questions/5823163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/729885/" ]
You can start the reactor in a dedicated thread, and then issue calls to it with [`blockingCallFromThread`](http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.threads.html#blockingCallFromThread) from your existing "sequential" code. Also, I'd recommend [AMP](http://twistedmatrix.com/documents/11.0.0/api/t...
Have you tried [zeromq](http://www.zeromq.org/)? It's a library that simplifies working with sockets. It can operate over TCP and implements several topologies, such as publisher/subscriber (for broadcasting data, such as your laser readings) and request/response (that you can use for you control scheme). There are b...
11,274,290
I have made a `.deb` of my app using [fpm](https://github.com/jordansissel/fpm/wiki): ``` fpm -s dir -t deb -n myapp -v 9 -a all -x "*.git" -x "*.bak" -x "*.orig" \ --after-remove debian/postrm --after-install debian/postinst \ --description "Automated build." -d mysql-client -d python-virtualenv home ``` Among oth...
2012/06/30
[ "https://Stackoverflow.com/questions/11274290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17498/" ]
I think the example script you copied is simply wrong. `postinst` is not supposed to be called with any `install` or `upgrade` argument, ever. The authoritative definition of the dpkg format is the Debian Policy Manual. The current version describes `postinst` in [chapter 6](http://www.debian.org/doc/debian-policy/ch-m...
I believe the answer provided by Alan Curry is incorrect, at least as of 2015 and beyond. There must be some fault with the way the that your package is built or an error in the `postinst` file which is causing your problem. You can debug your install by adding the `-D` (debug) option to your command line i.e.: ...
11,274,290
I have made a `.deb` of my app using [fpm](https://github.com/jordansissel/fpm/wiki): ``` fpm -s dir -t deb -n myapp -v 9 -a all -x "*.git" -x "*.bak" -x "*.orig" \ --after-remove debian/postrm --after-install debian/postinst \ --description "Automated build." -d mysql-client -d python-virtualenv home ``` Among oth...
2012/06/30
[ "https://Stackoverflow.com/questions/11274290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17498/" ]
I think the example script you copied is simply wrong. `postinst` is not supposed to be called with any `install` or `upgrade` argument, ever. The authoritative definition of the dpkg format is the Debian Policy Manual. The current version describes `postinst` in [chapter 6](http://www.debian.org/doc/debian-policy/ch-m...
This is an old issue that has been resolved, but it seems to me that the accepted solution is not totally correct and I believe that it is necessary to provide information for those who, like me, are having this same problem. [Chapter 6.5](https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html) details all...
11,274,290
I have made a `.deb` of my app using [fpm](https://github.com/jordansissel/fpm/wiki): ``` fpm -s dir -t deb -n myapp -v 9 -a all -x "*.git" -x "*.bak" -x "*.orig" \ --after-remove debian/postrm --after-install debian/postinst \ --description "Automated build." -d mysql-client -d python-virtualenv home ``` Among oth...
2012/06/30
[ "https://Stackoverflow.com/questions/11274290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17498/" ]
I believe the answer provided by Alan Curry is incorrect, at least as of 2015 and beyond. There must be some fault with the way the that your package is built or an error in the `postinst` file which is causing your problem. You can debug your install by adding the `-D` (debug) option to your command line i.e.: ...
This is an old issue that has been resolved, but it seems to me that the accepted solution is not totally correct and I believe that it is necessary to provide information for those who, like me, are having this same problem. [Chapter 6.5](https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html) details all...
39,103,057
Ok So ive been able to send mail and read mail but I am now trying to attach an attachment to the mail and it doesnt seem to append the document as expected. I dont get any errors but I also dont get the mail if I attempt to add the attachment. The library im using is [here](https://github.com/Narcolapser/python-o365)...
2016/08/23
[ "https://Stackoverflow.com/questions/39103057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3449832/" ]
I've reproduced your attached command as a ``` public class MyBehavior : Behavior<ListBox> { ``` to a XAML ``` <ListBox SelectedItem="SelCust" Name="MyListBox" Loaded="MyListBox_Loaded" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name" ItemsSource="{Binding Customers}"> <i:Interaction.B...
Why not simply scroll to the last value in your collection after you set the DataContext or ItemSource? No data will render until you set your data context, and until you exit the constructor. To my understanding if you do the following to steps in sequence in the constructor, it should work as expected. ```cs listBox...
8,029,363
I am new to django. I have version 1.3.1 installed. I have created two projects: **projectone** and **projecttwo** using django-admin.py And in **projectone** I have an app called **blog** created using python manage.py startapp In **projecttwo** setings.py file when put the following in installed\_apps: ``` INSTA...
2011/11/06
[ "https://Stackoverflow.com/questions/8029363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/614954/" ]
Look at what manage.py does: <https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-py-and-manage-py> It dynamically adds your apps to the python path when you use it - i.e. when you are using **runserver** during development. You have two separate projects so when you run either one you will only hav...
You are trying to install a **Project** in your INSTALLED\_APPS on settings.py, those are different projects. Instead you need to create just one project and create differents apps. Remember that apps are meant to be reusable so if you need the blog app in other project just reuse it. If you are new to Django you sho...
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward: ``` sudo apt-get install python-mysqldb ``` If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked q...
In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me: ``` sudo apt install build-essential python-dev libmysqlclient-dev sudo apt-get install libssl-dev pip install mysqlclient ```
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries. ``` sudo apt-get install libmysqlclient-dev sudo apt-get install python-mysql.connector sudo ...
this worked for me on python 3 pip install mysqlclient -----------------------
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward: ``` sudo apt-get install python-mysqldb ``` If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked q...
Reread the error message. It says: > > sh: mysql\_config: not found > > > If you are on Ubuntu Natty, `mysql_config` belongs to package [libmysqlclient-dev](http://packages.ubuntu.com/search?searchon=contents&keywords=mysql_config&mode=exactfilename&suite=natty&arch=any)
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
Reread the error message. It says: > > sh: mysql\_config: not found > > > If you are on Ubuntu Natty, `mysql_config` belongs to package [libmysqlclient-dev](http://packages.ubuntu.com/search?searchon=contents&keywords=mysql_config&mode=exactfilename&suite=natty&arch=any)
In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me: ``` sudo apt install build-essential python-dev libmysqlclient-dev sudo apt-get install libssl-dev pip install mysqlclient ```
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
``` yum install mysql-devel ``` It worked for me.
1. find the folder: `sudo find / -name "mysql_config"` (assume it's `"/opt/local/lib/mysql5/bin"`) 2. add it into PATH:`export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH` 3. install it again
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
You have 2 options, as described bellow: --- Distribution package like Glaslos suggested: ``` # sudo apt-get install python-mysqldb ``` In this case you can't use virtualenv no-site-packages (default option) but must use: ``` # virtualenv --system-site-packages myenv ``` --- Use clean virtualenv and build your...
this worked for me on python 3 pip install mysqlclient -----------------------
7,459,766
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is `sh: mysql_config: not found` Could someone advice me on what to do? ``` rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python Downloading MySQL-python-1.2.3.tar.g...
2011/09/18
[ "https://Stackoverflow.com/questions/7459766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/618677/" ]
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward: ``` sudo apt-get install python-mysqldb ``` If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked q...
``` yum install mysql-devel ``` It worked for me.