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
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
Can't you just write a function mapping to each? In fact, a dictionary will do. ``` def convert_monthname(monthname): table = {"January": datetime.datetime(month=1, day=1, year=2018), "February": datetime.datetime(month=2, day=1, year=2018), ...} return table.get(monthname, monthname...
The whole point of passing a format string like `%m/%d/%y` to `strftime` is that you're specifying what format the input strings are going to be in. You can see [the documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior), but it's pretty obvious that a format like `%m/%d/%y` is ...
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
Can't you just write a function mapping to each? In fact, a dictionary will do. ``` def convert_monthname(monthname): table = {"January": datetime.datetime(month=1, day=1, year=2018), "February": datetime.datetime(month=2, day=1, year=2018), ...} return table.get(monthname, monthname...
I'm assuming the data is mostly in the format you have specified (`mm/dd/yyyy`) but some outlier rows have month names in them. Without adding any extra dependencies: ``` DATE_FORMAT = '%m/%d/Y' MONTH_NAME_MAP = { "january": 1, "jan": 1, "february": 2, "feb": 2, # ... } def parse_month_value(valu...
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
Can't you just write a function mapping to each? In fact, a dictionary will do. ``` def convert_monthname(monthname): table = {"January": datetime.datetime(month=1, day=1, year=2018), "February": datetime.datetime(month=2, day=1, year=2018), ...} return table.get(monthname, monthname...
The answer from @DYZ actually did it for me, I added the strftime to create the dict as the date string I wanted ``` months = {str(name).lower(): datetime.datetime(month=val, day=1, year=2016).strftime('%d/%m/%Y') for val, name in enumerate(calendar.month_abbr) if val>0} ```
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
As an elaboration of the answer by @AdamSmith, a better way to define a mapping between names and dates is to use the `calendar` module that already has a list of names: ``` import calendar table = {name: datetime.datetime(month=1, day=val, year=2018) for val, name in enumerate(calendar.month_name) if val>0...
The whole point of passing a format string like `%m/%d/%y` to `strftime` is that you're specifying what format the input strings are going to be in. You can see [the documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior), but it's pretty obvious that a format like `%m/%d/%y` is ...
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
As an elaboration of the answer by @AdamSmith, a better way to define a mapping between names and dates is to use the `calendar` module that already has a list of names: ``` import calendar table = {name: datetime.datetime(month=1, day=val, year=2018) for val, name in enumerate(calendar.month_name) if val>0...
I'm assuming the data is mostly in the format you have specified (`mm/dd/yyyy`) but some outlier rows have month names in them. Without adding any extra dependencies: ``` DATE_FORMAT = '%m/%d/Y' MONTH_NAME_MAP = { "january": 1, "jan": 1, "february": 2, "feb": 2, # ... } def parse_month_value(valu...
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
As an elaboration of the answer by @AdamSmith, a better way to define a mapping between names and dates is to use the `calendar` module that already has a list of names: ``` import calendar table = {name: datetime.datetime(month=1, day=val, year=2018) for val, name in enumerate(calendar.month_name) if val>0...
The answer from @DYZ actually did it for me, I added the strftime to create the dict as the date string I wanted ``` months = {str(name).lower(): datetime.datetime(month=val, day=1, year=2016).strftime('%d/%m/%Y') for val, name in enumerate(calendar.month_abbr) if val>0} ```
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
The whole point of passing a format string like `%m/%d/%y` to `strftime` is that you're specifying what format the input strings are going to be in. You can see [the documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior), but it's pretty obvious that a format like `%m/%d/%y` is ...
I'm assuming the data is mostly in the format you have specified (`mm/dd/yyyy`) but some outlier rows have month names in them. Without adding any extra dependencies: ``` DATE_FORMAT = '%m/%d/Y' MONTH_NAME_MAP = { "january": 1, "jan": 1, "february": 2, "feb": 2, # ... } def parse_month_value(valu...
51,976,580
I am trying to change month name to date in python but i m getting an error: ``` ValueError: time data 'October' does not match format '%m/%d/%Y' ``` My CSV has values such as October in it which I want to change it to 10/01/2018 ``` import pandas as pd import datetime f = pd.read_excel('test.xlsx', 'Sheet1', inde...
2018/08/22
[ "https://Stackoverflow.com/questions/51976580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9488647/" ]
The whole point of passing a format string like `%m/%d/%y` to `strftime` is that you're specifying what format the input strings are going to be in. You can see [the documentation](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior), but it's pretty obvious that a format like `%m/%d/%y` is ...
The answer from @DYZ actually did it for me, I added the strftime to create the dict as the date string I wanted ``` months = {str(name).lower(): datetime.datetime(month=val, day=1, year=2016).strftime('%d/%m/%Y') for val, name in enumerate(calendar.month_abbr) if val>0} ```
45,686,298
I have followed [official doc](https://learn.microsoft.com/en-us/visualstudio/python/debugging-cross-platform-remote) to install ptvsd 3.2.0, and put below code in the very beginning of target code. ``` import ptvsd ptvsd.enable_attach('my_secret') ``` If run this code, I got error: ``` File "~/.virtualenvs/py3/lib...
2017/08/15
[ "https://Stackoverflow.com/questions/45686298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4198142/" ]
I had the same problem today. I've checked the [last version](https://pypi.python.org/pypi/ptvsd/3.2.0) and was released yesterday. I've decided to roll back to version 3.1.0, and that is working fine for me. I've reported the problem to the [gitter room](https://gitter.im/Microsoft/PTVS). I'll update this answer as s...
The `ptvsd` module is not using semantic versioning, which means you cannot safely update it whenever you like. The plan is to switch to semantic versioning when it is fully decoupled from Visual Studio. `ptvsd==3.2.0` was released at the same time that Visual Studio 2017 Update 15.3 because they have dependencies on ...
45,686,298
I have followed [official doc](https://learn.microsoft.com/en-us/visualstudio/python/debugging-cross-platform-remote) to install ptvsd 3.2.0, and put below code in the very beginning of target code. ``` import ptvsd ptvsd.enable_attach('my_secret') ``` If run this code, I got error: ``` File "~/.virtualenvs/py3/lib...
2017/08/15
[ "https://Stackoverflow.com/questions/45686298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4198142/" ]
I had the same problem today. I've checked the [last version](https://pypi.python.org/pypi/ptvsd/3.2.0) and was released yesterday. I've decided to roll back to version 3.1.0, and that is working fine for me. I've reported the problem to the [gitter room](https://gitter.im/Microsoft/PTVS). I'll update this answer as s...
I've installed it globally by specifying certain python because my default python is 3.9 but for azure-functions I needed it installed in 3.8 `/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -m pip install ptvsd` Of course you must replace my python version with yours But [***ptvsd***](https://github...
65,046,032
I'm trying to create an .exe from my python script. The script uses the cloudscraper package. When I create the .exe and I execute it, it shows the following error: ``` FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\MEI1....\\cloudscraper\\user_agent\\browsers.json' ``` The error ONLY APPEARS WHEN...
2020/11/28
[ "https://Stackoverflow.com/questions/65046032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14134850/" ]
The found solution is to copy the required folder inside the .exe path but as for now a days, **I found that this could not be achieved if you're using the** `--onefile` **modifier to create the .exe**, instead you should not use it and copy the cloudscraper folder inside such .exe path, and that should work **NOTE:**...
Your .exe file is looking for browsers.json, but you didn't move that file to the same path as the .exe file. Working with pyinstaller requires good experience handling relative and absolute paths, otherwise, you will face that kind of errors. If cloudscraper is not part of your project tree (maybe is a hidden import)...
65,046,032
I'm trying to create an .exe from my python script. The script uses the cloudscraper package. When I create the .exe and I execute it, it shows the following error: ``` FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\MEI1....\\cloudscraper\\user_agent\\browsers.json' ``` The error ONLY APPEARS WHEN...
2020/11/28
[ "https://Stackoverflow.com/questions/65046032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14134850/" ]
Check this link: <https://stackoverflow.com/a/64586862/14509818> **or** Add this command while creating your exe. ``` --add-data "path_for_cloudscraper_folder;./cloudscraper/" ``` Replace ***path\_for\_cloudscraper\_folder*** with the path of your cloudscraper folder. You can explore and find your path of cloudsc...
Your .exe file is looking for browsers.json, but you didn't move that file to the same path as the .exe file. Working with pyinstaller requires good experience handling relative and absolute paths, otherwise, you will face that kind of errors. If cloudscraper is not part of your project tree (maybe is a hidden import)...
65,046,032
I'm trying to create an .exe from my python script. The script uses the cloudscraper package. When I create the .exe and I execute it, it shows the following error: ``` FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\MEI1....\\cloudscraper\\user_agent\\browsers.json' ``` The error ONLY APPEARS WHEN...
2020/11/28
[ "https://Stackoverflow.com/questions/65046032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14134850/" ]
Check this link: <https://stackoverflow.com/a/64586862/14509818> **or** Add this command while creating your exe. ``` --add-data "path_for_cloudscraper_folder;./cloudscraper/" ``` Replace ***path\_for\_cloudscraper\_folder*** with the path of your cloudscraper folder. You can explore and find your path of cloudsc...
The found solution is to copy the required folder inside the .exe path but as for now a days, **I found that this could not be achieved if you're using the** `--onefile` **modifier to create the .exe**, instead you should not use it and copy the cloudscraper folder inside such .exe path, and that should work **NOTE:**...
60,609,578
I have two sets `set([1,2,3]` and `set([4,5,6]`. I want to add them in order to get set `1,2,3,4,5,6`. I tried: ``` b = set([1,2,3]).add(set([4,5,6])) ``` but it gives me this error: ``` Traceback (most recent call last): File "<ipython-input-27-d2646d891a38>", line 1, in <module> b = set([1,2,3]).add(set([...
2020/03/09
[ "https://Stackoverflow.com/questions/60609578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1601703/" ]
You can take the union of sets with `|` ``` > set([1, 2, 4]) | set([5, 6, 7]) {1, 2, 4, 5, 6, 7} ``` Trying to use `add(set([4,5,6]))` is not working because it tries to add the entire set as a single element rather than the elements in the set — and since it's not hashable, it fails.
You should use the union operation with the `.union` method or the `|` operator: ```py >>> a = set([1, 2, 3]) >>> b = set([4, 5, 3]) >>> c = a.union(b) >>> print(c) {1, 2, 3, 4, 5} >>> d = a | b >>> print(d) {1, 2, 3, 4, 5} ``` See the complete list of operations for [set](https://docs.python.org/3/library/stdtypes....
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
"If you have a problem, and decide to use regex, now you have two problems..." If you are reading one particular web page and you know how it is formatted, then regex is fine - you can use S. Mark's answer. To parse a particular link, you can use Kimvai's answer. However, to get all the links from a page, you're bett...
This will work irrespective of how your links are formatted (e.g. if some look like `<a href="foo=123"/>` and some look like `<A TARGET="_blank" HREF='foo=123'/>`). ``` import re from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(html) p = re.compile('^.*=([\d]*)$') for a in soup.findAll('a'): m = p.match...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` import re re.findall("\?read\.php=(\d+)",data) ```
This will work irrespective of how your links are formatted (e.g. if some look like `<a href="foo=123"/>` and some look like `<A TARGET="_blank" HREF='foo=123'/>`). ``` import re from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(html) p = re.compile('^.*=([\d]*)$') for a in soup.findAll('a'): m = p.match...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This will work irrespective of how your links are formatted (e.g. if some look like `<a href="foo=123"/>` and some look like `<A TARGET="_blank" HREF='foo=123'/>`). ``` import re from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(html) p = re.compile('^.*=([\d]*)$') for a in soup.findAll('a'): m = p.match...
/[0-9]/ thats the regex sytax you want for reference see <http://gnosis.cx/publish/programming/regular_expressions.html>
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
While the other answers are sort of correct, you should probably use the urllib2 library instead; ``` from urllib2 import urlparse import re urlre = re.compile('<a[^>]+href="([^"]+)"[^>]*>',re.IGNORECASE) links = urlre.findall('<a href="http://www.example.com?read.php=123">') for link in links: url = urlparse.urlp...
/[0-9]/ thats the regex sytax you want for reference see <http://gnosis.cx/publish/programming/regular_expressions.html>
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This will work irrespective of how your links are formatted (e.g. if some look like `<a href="foo=123"/>` and some look like `<A TARGET="_blank" HREF='foo=123'/>`). ``` import re from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(html) p = re.compile('^.*=([\d]*)$') for a in soup.findAll('a'): m = p.match...
One without the need for regex ``` >>> s='<a href="http://www.example.com?read.php=123">' >>> for item in s.split(">"): ... if "href" in item: ... print item[item.index("a href")+len("a href="): ] ... "http://www.example.com?read.php=123" ``` if you want to extract the numbers ``` item[item.index("a hre...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
"If you have a problem, and decide to use regex, now you have two problems..." If you are reading one particular web page and you know how it is formatted, then regex is fine - you can use S. Mark's answer. To parse a particular link, you can use Kimvai's answer. However, to get all the links from a page, you're bett...
One without the need for regex ``` >>> s='<a href="http://www.example.com?read.php=123">' >>> for item in s.split(">"): ... if "href" in item: ... print item[item.index("a href")+len("a href="): ] ... "http://www.example.com?read.php=123" ``` if you want to extract the numbers ``` item[item.index("a hre...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
While the other answers are sort of correct, you should probably use the urllib2 library instead; ``` from urllib2 import urlparse import re urlre = re.compile('<a[^>]+href="([^"]+)"[^>]*>',re.IGNORECASE) links = urlre.findall('<a href="http://www.example.com?read.php=123">') for link in links: url = urlparse.urlp...
One without the need for regex ``` >>> s='<a href="http://www.example.com?read.php=123">' >>> for item in s.split(">"): ... if "href" in item: ... print item[item.index("a href")+len("a href="): ] ... "http://www.example.com?read.php=123" ``` if you want to extract the numbers ``` item[item.index("a hre...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
"If you have a problem, and decide to use regex, now you have two problems..." If you are reading one particular web page and you know how it is formatted, then regex is fine - you can use S. Mark's answer. To parse a particular link, you can use Kimvai's answer. However, to get all the links from a page, you're bett...
While the other answers are sort of correct, you should probably use the urllib2 library instead; ``` from urllib2 import urlparse import re urlre = re.compile('<a[^>]+href="([^"]+)"[^>]*>',re.IGNORECASE) links = urlre.findall('<a href="http://www.example.com?read.php=123">') for link in links: url = urlparse.urlp...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` import re re.findall("\?read\.php=(\d+)",data) ```
One without the need for regex ``` >>> s='<a href="http://www.example.com?read.php=123">' >>> for item in s.split(">"): ... if "href" in item: ... print item[item.index("a href")+len("a href="): ] ... "http://www.example.com?read.php=123" ``` if you want to extract the numbers ``` item[item.index("a hre...
1,899,412
I have a web site where there are links like `<a href="http://www.example.com?read.php=123">` Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance.
2009/12/14
[ "https://Stackoverflow.com/questions/1899412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` import re re.findall("\?read\.php=(\d+)",data) ```
/[0-9]/ thats the regex sytax you want for reference see <http://gnosis.cx/publish/programming/regular_expressions.html>
62,163,714
`which python` returns: `/Library/Frameworks/Python.framework/Versions/2.7/bin/python` When I open my shell, the first couple lines of the shell read: `Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "lic...
2020/06/03
[ "https://Stackoverflow.com/questions/62163714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12304196/" ]
CSS: ``` .bi-headphones::before { display: inline-block; content: ""; background-image: url("data:image/svg+xml,%3Csvg width='1em' height='1em' viewBox='0 0 16 16' class='bi bi-headphones' fill='currentColor' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' d='M8 3a5 5 0 0 0-5 5v4.5H2V8a6 6 0 1 1...
i cant find in the doc that bootstrap icon is fontawesome icon after you install it you use it as a svg like this one ``` <svg class="bi bi-app" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" d="M11 2H5a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h6a3 ...
17,461,134
I am using Python2.7.5 in Windows 7. I'm new to command line arguments. I am trying to do this exercise: Write a program that reads in a string on the command line and returns a table of the letters which occur in the string with the number of times each letter occurs. For example: ``` $ python letter_counts.py "ThiS...
2013/07/04
[ "https://Stackoverflow.com/questions/17461134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547317/" ]
You want to use the [`sys.argv`](http://docs.python.org/2/library/sys.html#sys.argv) list from the [sys](http://docs.python.org/2/library/sys.html#module-sys) module. It lets you access arguments passed in the command line. For example, if your command line input was `python myfile.py a b c`, `sys.argv[0]` is myfile.p...
You can do something along these lines: ``` #!/usr/bin/python import sys print sys.argv counts={} for st in sys.argv[1:]: for c in st: counts.setdefault(c.lower(),0) counts[c.lower()]+=1 for k,v in sorted(counts.items(), key=lambda t: t[1], reverse=True): print "'{}' {}".format(k,v) ``` Whe...
47,069,829
This may be a repeated question of attempting to run a mysql query on a remote machine using python. Im using pymysql and SSHTunnelForwarder for this. The mysqldb is located on different server (192.168.10.13 and port 5555). Im trying to use the following snippet: ``` with SSHTunnelForwarder( (host, ssh_port...
2017/11/02
[ "https://Stackoverflow.com/questions/47069829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4670651/" ]
Found this to be working after some digging. ``` with SSHTunnelForwarder( ("192.168.10.13", 22), ssh_username = ssh_user, ssh_password = ssh_pass, remote_bind_address=('127.0.0.1', 5555)) as server: with pymysql.connect('127.0.0.1', user, password, port=server.local_bind_port) as c...
you can do it like this: ``` conn = MySQLdb.connect( host=host, port=port, user=username, passwd=password, db=database charset='utf8',) cur = conn.cursor() cur.execute("select * from billing_cdr limit 1") rows = cur.fetchall() for row in rows: a=row[0] b=row[1] conn.close() ```
16,784,154
With the help of joksnet's programs [here](https://stackoverflow.com/questions/4460921/extract-the-first-paragraph-from-a-wikipedia-article-python) I've managed to get plaintext Wikipedia articles that I'm looking for. The text returned includes Wiki markup for the headings, so for example, the sections of the [Albert...
2013/05/28
[ "https://Stackoverflow.com/questions/16784154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/728286/" ]
I think the best way here would be to let MediaWiki take care of the parsing. I don't know the library you're using, but basically this is the difference between <http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Albert%20Einstein&rvprop=content> which returns the raw wikitext and <http://en.wikip...
You can use regex and scraping modules like Scrapy and Beautifulsoup to parse and scrape wiki pages. Now that you clarified your question I suggest you use the py-wikimarkup module that is hosted on github. The link is <https://github.com/dcramer/py-wikimarkup/> . I hope that helps.
16,784,154
With the help of joksnet's programs [here](https://stackoverflow.com/questions/4460921/extract-the-first-paragraph-from-a-wikipedia-article-python) I've managed to get plaintext Wikipedia articles that I'm looking for. The text returned includes Wiki markup for the headings, so for example, the sections of the [Albert...
2013/05/28
[ "https://Stackoverflow.com/questions/16784154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/728286/" ]
I ended up doing this: ``` def parseWikiTitles(x): counter = 1 while '===' in x: if counter == 1: x = x.replace('===','<i>',1) counter = 2 else: x = x.replace('===',r'</i>',1) counter = 1 counter = 1 while '==' in x: if counter...
You can use regex and scraping modules like Scrapy and Beautifulsoup to parse and scrape wiki pages. Now that you clarified your question I suggest you use the py-wikimarkup module that is hosted on github. The link is <https://github.com/dcramer/py-wikimarkup/> . I hope that helps.
19,542,883
I'm trying to make a program that repeatedly asks an user for an input until the input is of a specific type. My code: ``` value = input("Please enter the value") while isinstance(value, int) == False: print ("Invalid value.") value = input("Please enter the value") if isinstance(value, int) == True: ...
2013/10/23
[ "https://Stackoverflow.com/questions/19542883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2826154/" ]
The reason your code doesn't work is because `input()` will always return a string. Which will always cause `isinstance(value, int)` to always evaluate to `False`. You probably want: ``` value = '' while not value.strip().isdigit(): value = input("Please enter the value") ```
`input` always returns a string, you have to convert it to `int` yourself. Try this snippet: ``` while True: try: value = int(input("Please enter the value: ")) except ValueError: print ("Invalid value.") else: break ```
19,542,883
I'm trying to make a program that repeatedly asks an user for an input until the input is of a specific type. My code: ``` value = input("Please enter the value") while isinstance(value, int) == False: print ("Invalid value.") value = input("Please enter the value") if isinstance(value, int) == True: ...
2013/10/23
[ "https://Stackoverflow.com/questions/19542883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2826154/" ]
The reason your code doesn't work is because `input()` will always return a string. Which will always cause `isinstance(value, int)` to always evaluate to `False`. You probably want: ``` value = '' while not value.strip().isdigit(): value = input("Please enter the value") ```
Be aware when using `.isdigit()`, it will return False on negative integers. So `isinstance(value, int)` is maybe a better choice. I cannot comment on accepted answer because of low rep.
19,542,883
I'm trying to make a program that repeatedly asks an user for an input until the input is of a specific type. My code: ``` value = input("Please enter the value") while isinstance(value, int) == False: print ("Invalid value.") value = input("Please enter the value") if isinstance(value, int) == True: ...
2013/10/23
[ "https://Stackoverflow.com/questions/19542883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2826154/" ]
The reason your code doesn't work is because `input()` will always return a string. Which will always cause `isinstance(value, int)` to always evaluate to `False`. You probably want: ``` value = '' while not value.strip().isdigit(): value = input("Please enter the value") ```
If you want to manage negative integers you should use : ``` value = '' while not value.strip().lstrip("-").isdigit(): value = input("Please enter the value") ```
19,542,883
I'm trying to make a program that repeatedly asks an user for an input until the input is of a specific type. My code: ``` value = input("Please enter the value") while isinstance(value, int) == False: print ("Invalid value.") value = input("Please enter the value") if isinstance(value, int) == True: ...
2013/10/23
[ "https://Stackoverflow.com/questions/19542883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2826154/" ]
Be aware when using `.isdigit()`, it will return False on negative integers. So `isinstance(value, int)` is maybe a better choice. I cannot comment on accepted answer because of low rep.
`input` always returns a string, you have to convert it to `int` yourself. Try this snippet: ``` while True: try: value = int(input("Please enter the value: ")) except ValueError: print ("Invalid value.") else: break ```
19,542,883
I'm trying to make a program that repeatedly asks an user for an input until the input is of a specific type. My code: ``` value = input("Please enter the value") while isinstance(value, int) == False: print ("Invalid value.") value = input("Please enter the value") if isinstance(value, int) == True: ...
2013/10/23
[ "https://Stackoverflow.com/questions/19542883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2826154/" ]
Be aware when using `.isdigit()`, it will return False on negative integers. So `isinstance(value, int)` is maybe a better choice. I cannot comment on accepted answer because of low rep.
If you want to manage negative integers you should use : ``` value = '' while not value.strip().lstrip("-").isdigit(): value = input("Please enter the value") ```
49,993,687
Let's say I am running multiple python processes(not threads) on a multi core CPU (say 4). GIL is process level so GIL within a particular process won't affect other processes. My question here is if the GIL within one process will take hold of only single core out of 4 cores or will it take hold of all 4 cores? If o...
2018/04/24
[ "https://Stackoverflow.com/questions/49993687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4510252/" ]
Python doesn't do anything to [bind processes or threads to cores](https://en.wikipedia.org/wiki/Processor_affinity); it just leaves things up to the OS. When you spawn a bunch of independent processes (or threads, but that's harder to do in Python), the OS's scheduler will quickly and efficiently get them spread out a...
Process to CPU/CPU core allocation is handled by the Operating System.
54,193,625
I'm trying to fetch data for facebook account using selenium browser python but can't able to find the which element I can look out for clicking on an export button. See attached screenshot[![enter image description here](https://i.stack.imgur.com/fd2Mf.png)](https://i.stack.imgur.com/fd2Mf.png) I tried but it seems ...
2019/01/15
[ "https://Stackoverflow.com/questions/54193625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7684584/" ]
Well, I'm able to resolve it by using xpath. Here is the solution ``` self.driver.find_element_by_xpath("//*[contains(@class, '_271k _271m _1qjd layerConfirm')]").click() ```
to run automation scripts on applications like facebook, youtube quite a hard because they are huge coporations and their web applications are developed by the worlds best developers but its not impossible to run automation scripts sometimes elements are generated dynamically sometimes hidden or inactive you cant just ...
54,193,625
I'm trying to fetch data for facebook account using selenium browser python but can't able to find the which element I can look out for clicking on an export button. See attached screenshot[![enter image description here](https://i.stack.imgur.com/fd2Mf.png)](https://i.stack.imgur.com/fd2Mf.png) I tried but it seems ...
2019/01/15
[ "https://Stackoverflow.com/questions/54193625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7684584/" ]
The element with text as **Export** is a dynamically generated element so to locate the element you have to induce *WebDriverWait* for the *element to be clickable* and you can use either of the [locator strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#4837...
to run automation scripts on applications like facebook, youtube quite a hard because they are huge coporations and their web applications are developed by the worlds best developers but its not impossible to run automation scripts sometimes elements are generated dynamically sometimes hidden or inactive you cant just ...
54,193,625
I'm trying to fetch data for facebook account using selenium browser python but can't able to find the which element I can look out for clicking on an export button. See attached screenshot[![enter image description here](https://i.stack.imgur.com/fd2Mf.png)](https://i.stack.imgur.com/fd2Mf.png) I tried but it seems ...
2019/01/15
[ "https://Stackoverflow.com/questions/54193625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7684584/" ]
The element with text as **Export** is a dynamically generated element so to locate the element you have to induce *WebDriverWait* for the *element to be clickable* and you can use either of the [locator strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#4837...
Well, I'm able to resolve it by using xpath. Here is the solution ``` self.driver.find_element_by_xpath("//*[contains(@class, '_271k _271m _1qjd layerConfirm')]").click() ```
55,915,109
Im trying to create a more dynamic program where I define a function's name based on a variable string. Trying to define a function using a variable like this: ```py __func_name__ = "fun" def __func_name__(): print('Hello from ' + __func_name__) fun() ``` Was wanting this to output: ``` Hello from fun ``` Th...
2019/04/30
[ "https://Stackoverflow.com/questions/55915109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6828625/" ]
You can update `globals`: ``` >>> globals()["my_function_name"] = lambda x: x + 1 >>> my_function_name(10) 11 ``` But usually is more convinient to use a dictionary that have the functions related: ``` my_func_dict = { "__func_name__" : __func_name__, } def __func_name__(): print('Hello') ``` And then use ...
This should do it as well, using the `globals` to update function name on the fly. ``` def __func_name__(): print('Hello from ' + __func_name__.__name__) globals()['fun'] = __func_name__ fun() ``` The output will be ``` Hello from __func_name__ ```
47,912,701
There is a solution posted [here](https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python) to create a stoppable thread. However, I am having some problems understanding how to implement this solution. Using the code... ``` import threading class StoppableThread(threading.Thread): ...
2017/12/20
[ "https://Stackoverflow.com/questions/47912701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9124164/" ]
There are a couple of problems with how you are using the code in your original example. First of all, you are not passing any constructor arguments to the base constructor. This is a problem because, as you can see in the plain-Thread example, constructor arguments are often necessary. You should rewrite `StoppableThr...
Inspired by above solution I created a small library, ants, for this problem. Example ``` from ants import worker @worker def do_stuff(): ... thread code ... do_stuff.start() ... do_stuff.stop() ``` In above example do\_stuff will run in a separate thread being called in a `while 1:` loop You can al...
47,912,701
There is a solution posted [here](https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python) to create a stoppable thread. However, I am having some problems understanding how to implement this solution. Using the code... ``` import threading class StoppableThread(threading.Thread): ...
2017/12/20
[ "https://Stackoverflow.com/questions/47912701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9124164/" ]
There are a couple of problems with how you are using the code in your original example. First of all, you are not passing any constructor arguments to the base constructor. This is a problem because, as you can see in the plain-Thread example, constructor arguments are often necessary. You should rewrite `StoppableThr...
I found some implementation of a stoppable thread - and it does not rely that You check if it should continue to run inside the thread - it "injects" an exception into the wrapped function - that will work as long as You dont do something like : ``` while True: try: do something except: pass...
47,912,701
There is a solution posted [here](https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python) to create a stoppable thread. However, I am having some problems understanding how to implement this solution. Using the code... ``` import threading class StoppableThread(threading.Thread): ...
2017/12/20
[ "https://Stackoverflow.com/questions/47912701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9124164/" ]
I found some implementation of a stoppable thread - and it does not rely that You check if it should continue to run inside the thread - it "injects" an exception into the wrapped function - that will work as long as You dont do something like : ``` while True: try: do something except: pass...
Inspired by above solution I created a small library, ants, for this problem. Example ``` from ants import worker @worker def do_stuff(): ... thread code ... do_stuff.start() ... do_stuff.stop() ``` In above example do\_stuff will run in a separate thread being called in a `while 1:` loop You can al...
71,719,341
I made a small pygame app that plays certain wav files in keypress using pygame.mixer All seem to work just fine except the fact that if you minimize the pygame window the program stops working until you open it again. Is there a way to solve this issue or an alternative way to implement sound playing in python? This ...
2022/04/02
[ "https://Stackoverflow.com/questions/71719341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15354246/" ]
Several ways. Here are a couple: Standard SQL: ```sql SELECT DISTINCT CASE WHEN col1 < col2 THEN col1 ELSE col2 END AS col1 , CASE WHEN col1 < col2 THEN col2 ELSE col1 END AS col2 FROM tbl ; ``` or (MySQL supports this one): ```sql SELECT DISTINCT LEAST(col1, col2) AS col1 , GREATEST(c...
``` select distinct least(col_1, col_2), greatest(col_1, col_2) from the_table order by 1 ```
66,239,918
I wrote this code to return a list of skills. If the user already has a specific skill, the list-item should be updated to `active = false`. This is my initial code: ```js setup () { const user = ref ({ id: null, skills: [] }); const available_skills = ref ([ ...
2021/02/17
[ "https://Stackoverflow.com/questions/66239918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7510971/" ]
In JavaScript user or an object is a refence to the object which is the pointer itself will not change upon changing the underling properties hence the computed is not triggered kid of like computed property for an array and if that array get pushed with new values, the pointer of the array does not change but the unde...
`slice` just returns a copy of the changed array, it doesn't change the original instance..hence computed property is not reactive Try using below code ``` user.skills = user.skills.splice(index, 1); ```
66,239,918
I wrote this code to return a list of skills. If the user already has a specific skill, the list-item should be updated to `active = false`. This is my initial code: ```js setup () { const user = ref ({ id: null, skills: [] }); const available_skills = ref ([ ...
2021/02/17
[ "https://Stackoverflow.com/questions/66239918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7510971/" ]
The computed prop is actually being recomputed when you update `user.skills`, but the mapping of `available_skills` produces the same result, so there's no apparent change. Assuming `user.skills` contains the full skill set from `available_skills`, the first computation sets all `skill.active` to `false`. When the use...
`slice` just returns a copy of the changed array, it doesn't change the original instance..hence computed property is not reactive Try using below code ``` user.skills = user.skills.splice(index, 1); ```
66,670,964
I have the following python code: ``` client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(("example.com", 443)) client.send(b'POST /api HTTPS/1.1\r\nHost: example.com\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0\r\nAccept-Encoding: gzip, deflate\r...
2021/03/17
[ "https://Stackoverflow.com/questions/66670964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15414108/" ]
It will **not overwrite** the secret if you create it manually in the console or using AWS SDK. The `aws_secretsmanager_secret` creates only the secret, but not its value. To set value you have to use [aws\_secretsmanager\_secret\_version](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secr...
You could have Terraform [generate random secret values](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/secretsmanager_random_password) for you using: ``` data "aws_secretsmanager_random_password" "dev_password" { password_length = 16 } ``` Then create [the secret metadata](http...
52,277,877
I'm trying to scrape this website using python and selenium. However all the information I need is not on the main page, so how would I click the links in the 'Application number' column one by one go to that page scrape the information then return to original page? Ive tried: ``` def getData(): data = [] select ...
2018/09/11
[ "https://Stackoverflow.com/questions/52277877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10347887/" ]
To open multiple hrefs within a webtable to scrape through selenium you can use the following solution: * Code Block: ``` from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By f...
What you can do is the following: ``` import selenium from selenium.webdriver.common.keys import Keys from selenium import Webdriver import time url = "url" browser = Webdriver.Chrome() #or whatever driver you use browser.find_element_by_class_name("views-field views-field-title").click() # or use this browser.find_e...
52,277,877
I'm trying to scrape this website using python and selenium. However all the information I need is not on the main page, so how would I click the links in the 'Application number' column one by one go to that page scrape the information then return to original page? Ive tried: ``` def getData(): data = [] select ...
2018/09/11
[ "https://Stackoverflow.com/questions/52277877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10347887/" ]
To open multiple hrefs within a webtable to scrape through selenium you can use the following solution: * Code Block: ``` from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By f...
When you navigate to new page DOM is refreshed and you cannot use list method here. Here is my approach for this action (I don't code much in python so syntax and indendation may be broken) ``` count = driver.find_elements_by_xpath("//table[@class='views-table cols-6']/tbody/tr") # to count total number of links len(c...
20,952,629
I am trying to install Python Cassandra Driver and constantly getting error "vcvarsall.bat not found" I tried using lots of solutions posted already in stackoverflow but non of them are working. here is what i tried- 1. Using mingw gcc compiler.I followed every step, setting the path variable etc. and then tried usin...
2014/01/06
[ "https://Stackoverflow.com/questions/20952629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2640953/" ]
You will need to shorten the `memo` field to be able to use it in this manner. Try: ``` CAST(Desc AS NVARCHAR(2000)) ```
Use Having clause instead of where condition in query. ``` Select count(*) as NBoccurrence,descr From tbl_nm Group by descr Having your condition ```
25,996,880
This should be easy, but as ever Python's wildly overcomplicated datetime mess is making simple things complicated... So I've got a time string in HH:MM format (eg. '09:30'), which I'd like to turn into a datetime with today's date. Unfortunately the default date is Jan 1 1900: ``` >>> datetime.datetime.strptime(time...
2014/09/23
[ "https://Stackoverflow.com/questions/25996880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/218340/" ]
The [function signature](https://docs.python.org/3/library/datetime.html#datetime.datetime.combine) says: ``` datetime.combine(date, time) ``` so pass a `datetime.date` object as the first argument, and a `datetime.time` object as the second argument: ``` >>> import datetime as dt >>> today = dt.date.today() >>> ti...
`pip install python-dateutil` ``` >>> from dateutil import parser as dt_parser >>> dt_parser.parse('07:20') datetime.datetime(2016, 11, 25, 7, 20) ``` <https://dateutil.readthedocs.io/en/stable/parser.html>
56,893,578
I am trying to make a python program(python 3.6) that writes commands to terminal to download a specific youtube video(using youtube-dl). If I go on terminal and execute the following command: ``` cd; cd Desktop; youtube-dl "https://www.youtube.com/watch?v=b91ovTKCZGU" ``` It will download the video to my desktop...
2019/07/04
[ "https://Stackoverflow.com/questions/56893578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11303221/" ]
Binary pattern matching can dissect the string: ``` data = ["AM00", "CC11", "CB11"] for <<key::binary-size(2), value::binary>> <- data, into: %{} do {key, value} end ``` output: ``` %{"AM" => "00", "CB" => "11", "CC" => "11"} ``` That only works for single byte characters. To handle `UTF-8` chara...
> > I need to transform this list [into a] map...I tried with `Enum.map`. > > > You can also use [Enum.reduce](https://hexdocs.pm/elixir/Enum.html#reduce/3) instead of `Enum.map` when you want the result to be a map. The following example uses `Enum.reduce` and it can handle single byte `ASCII` characters as well ...
56,893,578
I am trying to make a python program(python 3.6) that writes commands to terminal to download a specific youtube video(using youtube-dl). If I go on terminal and execute the following command: ``` cd; cd Desktop; youtube-dl "https://www.youtube.com/watch?v=b91ovTKCZGU" ``` It will download the video to my desktop...
2019/07/04
[ "https://Stackoverflow.com/questions/56893578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11303221/" ]
Binary pattern matching can dissect the string: ``` data = ["AM00", "CC11", "CB11"] for <<key::binary-size(2), value::binary>> <- data, into: %{} do {key, value} end ``` output: ``` %{"AM" => "00", "CB" => "11", "CC" => "11"} ``` That only works for single byte characters. To handle `UTF-8` chara...
I would do it with [`Map.new/2`](https://hexdocs.pm/elixir/Map.html#new/2) and [`String.split_at/2`](https://hexdocs.pm/elixir/String.html#split_at/2): ```elixir Map.new(["AM00", "CC11", "CB11"], &String.split_at(&1, 2)) ```
9,227,859
I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as `{C:/Documents and Settings/IE User/My Documents/VPC_EULA.txt} {C:/Documents and Settings/IE User/My Documents/VPC_ReadMe.txt}`...
2012/02/10
[ "https://Stackoverflow.com/questions/9227859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94078/" ]
The problem is an “interesting” interaction between Tcl, Tk and Python, each of which is doing something sensible on its own but where the combination isn't behaving correctly. The deep issue is that Tcl and Python have *very* different ideas about what types mean, and this is manifesting itself as a value that Tcl see...
This fix works for me: ``` if sys.hexversion >= 0x030000F0: import tkinter.filedialog as filedialog string_type = str else: import tkFileDialog as filedialog string_type = basestring options = {} options['filetypes'] = [('vnote files', '.vnt') ,('all files', '.*')] options['multiple'] = 1 filenames = ...
9,227,859
I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as `{C:/Documents and Settings/IE User/My Documents/VPC_EULA.txt} {C:/Documents and Settings/IE User/My Documents/VPC_ReadMe.txt}`...
2012/02/10
[ "https://Stackoverflow.com/questions/9227859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94078/" ]
The problem is an “interesting” interaction between Tcl, Tk and Python, each of which is doing something sensible on its own but where the combination isn't behaving correctly. The deep issue is that Tcl and Python have *very* different ideas about what types mean, and this is manifesting itself as a value that Tcl see...
For some reason the tk\_eval based fix doesn't work for me. The filenames in the string returned by tkFileDialog are only wrapped in {} brackets if they contain whitespace, whereas the tcl docs seem to imply that all list items should be delimited by those brackets. Anyway, here's a fix that seems to work for me (pyth...
9,227,859
I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as `{C:/Documents and Settings/IE User/My Documents/VPC_EULA.txt} {C:/Documents and Settings/IE User/My Documents/VPC_ReadMe.txt}`...
2012/02/10
[ "https://Stackoverflow.com/questions/9227859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94078/" ]
The problem is an “interesting” interaction between Tcl, Tk and Python, each of which is doing something sensible on its own but where the combination isn't behaving correctly. The deep issue is that Tcl and Python have *very* different ideas about what types mean, and this is manifesting itself as a value that Tcl see...
A quick way that I've used: ``` filenames = filenames.strip('{}').split('} {') ```
9,227,859
I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as `{C:/Documents and Settings/IE User/My Documents/VPC_EULA.txt} {C:/Documents and Settings/IE User/My Documents/VPC_ReadMe.txt}`...
2012/02/10
[ "https://Stackoverflow.com/questions/9227859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94078/" ]
For some reason the tk\_eval based fix doesn't work for me. The filenames in the string returned by tkFileDialog are only wrapped in {} brackets if they contain whitespace, whereas the tcl docs seem to imply that all list items should be delimited by those brackets. Anyway, here's a fix that seems to work for me (pyth...
This fix works for me: ``` if sys.hexversion >= 0x030000F0: import tkinter.filedialog as filedialog string_type = str else: import tkFileDialog as filedialog string_type = basestring options = {} options['filetypes'] = [('vnote files', '.vnt') ,('all files', '.*')] options['multiple'] = 1 filenames = ...
9,227,859
I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as `{C:/Documents and Settings/IE User/My Documents/VPC_EULA.txt} {C:/Documents and Settings/IE User/My Documents/VPC_ReadMe.txt}`...
2012/02/10
[ "https://Stackoverflow.com/questions/9227859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/94078/" ]
For some reason the tk\_eval based fix doesn't work for me. The filenames in the string returned by tkFileDialog are only wrapped in {} brackets if they contain whitespace, whereas the tcl docs seem to imply that all list items should be delimited by those brackets. Anyway, here's a fix that seems to work for me (pyth...
A quick way that I've used: ``` filenames = filenames.strip('{}').split('} {') ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP): ``` brew unlink postgresql && brew link postgresql brew link --overwrite postgresql ``` [H/T Farhan Ahmad](http://www.thebitguru.com/blog/view/432-psycopg2%20on%20El%20C...
well, I'd like to give my solution, the problem is related with the version of c. So, I just typed: ``` CFLAGS='-std=c99' pip install psycopg2==2.6.1 ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
You need to replace the /usr/lib/libpq.5.dylib library because its version is too old. Here's my solution to this problem: ``` $ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old $ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib ```
Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP): ``` brew unlink postgresql && brew link postgresql brew link --overwrite postgresql ``` [H/T Farhan Ahmad](http://www.thebitguru.com/blog/view/432-psycopg2%20on%20El%20C...
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
You need to replace the /usr/lib/libpq.5.dylib library because its version is too old. Here's my solution to this problem: ``` $ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old $ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib ```
In El Capitan, I used the same solution as @Forbze but 2 more commands as follows. ``` sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.3/lib/libpq.5.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so sudo install_name_tool -change libssl.1.0.0.dylib /Library/PostgreSQL/9.3/lib/libssl.1.0....
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
If you are using PostgresApp, you need to run the following two commands: ``` sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib ```
well, I'd like to give my solution, the problem is related with the version of c. So, I just typed: ``` CFLAGS='-std=c99' pip install psycopg2==2.6.1 ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
You need to replace the /usr/lib/libpq.5.dylib library because its version is too old. Here's my solution to this problem: ``` $ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old $ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib ```
If you are using PostgresApp, you need to run the following two commands: ``` sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
I was able to fix this on my Mac (running Catalina, 10.15.3) by using psycopg2-binary rather than psycopg2. `pip3 uninstall psycopg2 pip3 install psycopg2-binary`
Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP): ``` brew unlink postgresql && brew link postgresql brew link --overwrite postgresql ``` [H/T Farhan Ahmad](http://www.thebitguru.com/blog/view/432-psycopg2%20on%20El%20C...
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
If you are using PostgresApp, you need to run the following two commands: ``` sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib ```
Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP): ``` brew unlink postgresql && brew link postgresql brew link --overwrite postgresql ``` [H/T Farhan Ahmad](http://www.thebitguru.com/blog/view/432-psycopg2%20on%20El%20C...
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
You need to replace the /usr/lib/libpq.5.dylib library because its version is too old. Here's my solution to this problem: ``` $ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old $ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib ```
For those of you on El Capitan who can't use @KungFuLucky7's answer - I used the following to fix the issue (Adjust paths to match yours where required). ``` sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
I was able to fix this on my Mac (running Catalina, 10.15.3) by using psycopg2-binary rather than psycopg2. `pip3 uninstall psycopg2 pip3 install psycopg2-binary`
For those of you on El Capitan who can't use @KungFuLucky7's answer - I used the following to fix the issue (Adjust paths to match yours where required). ``` sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so ```
28,515,972
Currently I am installing psycopg2 for work within eclipse with python. I am finding a lot of problems: 1. The first problem `sudo pip3.4 install psycopg2` is not working and it is showing the following message > > Error: pg\_config executable not found. > > > FIXED WITH:`export PATH=/Library/PostgreSQL/9.4/bi...
2015/02/14
[ "https://Stackoverflow.com/questions/28515972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3964833/" ]
If you are using PostgresApp, you need to run the following two commands: ``` sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib ```
For those of you on El Capitan who can't use @KungFuLucky7's answer - I used the following to fix the issue (Adjust paths to match yours where required). ``` sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so ```
43,424,895
I have created a virtualenv using the following command: `python3 -m venv --without-pip ./env_name` I am now wondering if it is possible to add PIP to it manually.
2017/04/15
[ "https://Stackoverflow.com/questions/43424895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5969463/" ]
Once you opened the file, use this one-liner using `split` as you mentionned and nested list comprehension: ``` with open(f, encoding="UTF-8") as file: # safer way to open the file (and close it automatically on block exit) result = [[int(x) for x in l.split()] for l in file] ``` * the inner listcomp splits & ...
You can do like this, ``` [map(int,i.split()) for i in filter(None,open('abc.txt').read().split('\n'))] ``` Line by line execution for more information ``` In [75]: print open('abc.txt').read() 3 2 7 4 1 8 9 3 6 5 4 1 1 0 8 7 ``` `split` with newline. ``` In [76]: print open('abc.txt').read().split('\n') ['3 ...
43,424,895
I have created a virtualenv using the following command: `python3 -m venv --without-pip ./env_name` I am now wondering if it is possible to add PIP to it manually.
2017/04/15
[ "https://Stackoverflow.com/questions/43424895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5969463/" ]
Once you opened the file, use this one-liner using `split` as you mentionned and nested list comprehension: ``` with open(f, encoding="UTF-8") as file: # safer way to open the file (and close it automatically on block exit) result = [[int(x) for x in l.split()] for l in file] ``` * the inner listcomp splits & ...
The following uses a [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) to create a list-of-lists. It reads each line from the file, splits it up using whitespace as a delimiter, uses the `map` function to create an iterator that returns the result of calling the `int` inte...
43,424,895
I have created a virtualenv using the following command: `python3 -m venv --without-pip ./env_name` I am now wondering if it is possible to add PIP to it manually.
2017/04/15
[ "https://Stackoverflow.com/questions/43424895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5969463/" ]
Once you opened the file, use this one-liner using `split` as you mentionned and nested list comprehension: ``` with open(f, encoding="UTF-8") as file: # safer way to open the file (and close it automatically on block exit) result = [[int(x) for x in l.split()] for l in file] ``` * the inner listcomp splits & ...
``` with open('intFile.txt') as f: res = [[int(x) for x in line.split()] for line in f] with open('intList.txt', 'w') as f: f.write(str(res)) ``` Adding to accepted answer. If you want to write that list to file, you need to open file and write as string as `write` only accepts string.
43,424,895
I have created a virtualenv using the following command: `python3 -m venv --without-pip ./env_name` I am now wondering if it is possible to add PIP to it manually.
2017/04/15
[ "https://Stackoverflow.com/questions/43424895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5969463/" ]
You can do like this, ``` [map(int,i.split()) for i in filter(None,open('abc.txt').read().split('\n'))] ``` Line by line execution for more information ``` In [75]: print open('abc.txt').read() 3 2 7 4 1 8 9 3 6 5 4 1 1 0 8 7 ``` `split` with newline. ``` In [76]: print open('abc.txt').read().split('\n') ['3 ...
``` with open('intFile.txt') as f: res = [[int(x) for x in line.split()] for line in f] with open('intList.txt', 'w') as f: f.write(str(res)) ``` Adding to accepted answer. If you want to write that list to file, you need to open file and write as string as `write` only accepts string.
43,424,895
I have created a virtualenv using the following command: `python3 -m venv --without-pip ./env_name` I am now wondering if it is possible to add PIP to it manually.
2017/04/15
[ "https://Stackoverflow.com/questions/43424895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5969463/" ]
The following uses a [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) to create a list-of-lists. It reads each line from the file, splits it up using whitespace as a delimiter, uses the `map` function to create an iterator that returns the result of calling the `int` inte...
``` with open('intFile.txt') as f: res = [[int(x) for x in line.split()] for line in f] with open('intList.txt', 'w') as f: f.write(str(res)) ``` Adding to accepted answer. If you want to write that list to file, you need to open file and write as string as `write` only accepts string.
22,845,913
I am trying to implement a function to generate java hashCode equivalent in node.js and python to implement redis sharding. I am following the really good blog @below mentioned link to achieve this <http://mechanics.flite.com/blog/2013/06/27/sharding-redis/> But i am stuck at the difference in hashCode if string conta...
2014/04/03
[ "https://Stackoverflow.com/questions/22845913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3230928/" ]
```py def java_string_hashcode(s): """Mimic Java's hashCode in python 2""" try: s = unicode(s) except: try: s = unicode(s.decode('utf8')) except: raise Exception("Please enter a unicode type string or utf8 bytestring.") h = 0 for c in s: h = in...
Python 2 will assume ASCII encoding unless told otherwise. Since [PEP 0263](http://legacy.python.org/dev/peps/pep-0263/), you can specify utf-8 encoded strings with the following at the top of the file. ``` #!/usr/bin/python # -*- coding: utf-8 -*- ```
12,311,226
I am new to python and am having difficulties with an assignment for a class. Here's my code: ``` print ('Plants for each semicircle garden: ',round(semiPlants,0)) ``` Here's what gets printed: ``` ('Plants for each semicircle garden:', 50.0) ``` As you see I am getting the parenthesis and apostrophes, which I d...
2012/09/07
[ "https://Stackoverflow.com/questions/12311226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1355158/" ]
You're clearly using python2.x when you think you're using python3.x. In python 2.x, the stuff in the parenthesis is being interpreted as a `tuple`. One fix is to use string formatting to do this: ``` print ( 'Plants for each semicircle garden: {0}'.format(round(semiPlants,0))) ``` which will work with python2.6 an...
You've tagged this question Python-3.x, but it looks like you are actually running your code with Python 2. To see what version you're using, run, "python -V".
12,311,226
I am new to python and am having difficulties with an assignment for a class. Here's my code: ``` print ('Plants for each semicircle garden: ',round(semiPlants,0)) ``` Here's what gets printed: ``` ('Plants for each semicircle garden:', 50.0) ``` As you see I am getting the parenthesis and apostrophes, which I d...
2012/09/07
[ "https://Stackoverflow.com/questions/12311226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1355158/" ]
You're clearly using python2.x when you think you're using python3.x. In python 2.x, the stuff in the parenthesis is being interpreted as a `tuple`. One fix is to use string formatting to do this: ``` print ( 'Plants for each semicircle garden: {0}'.format(round(semiPlants,0))) ``` which will work with python2.6 an...
Remove the parentheses as print is a statement, not a function in Python 2.x: ``` print 'Plants for each semicircle garden: ',round(semiPlants,0) Plants for each simicircle garden: 50.0 ```
57,169,454
My dataset is a set of 2 columns with Spanish and English sentences. I created a training dataset using the Dataset API using the below code: ``` train_examples = tf.data.experimental.CsvDataset("./Data/train.csv", [tf.string, tf.string]) val_examples = tf.data.experimental.CsvDataset("./Data/validation.csv", [tf.str...
2019/07/23
[ "https://Stackoverflow.com/questions/57169454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8382950/" ]
You can perform ordering on the job\_set queryset, for example. Is something like this what you are looking for? ``` for worker in Worker.objects.all(): latest_job = worker.job_set.latest('start_date') print(worker.name, latest_job.location, latest_job.start_date) ```
You can use the `last` method on the filtered and ordered (by `start_date`, in ascending order) queryset of a worker. For example, if the name of the worker is `foobar`, you can do: ``` Job.objects.filter(worker__name='foobar').order_by('start_date').last() ``` this will give you the last `Job` (based on `start_dat...
57,169,454
My dataset is a set of 2 columns with Spanish and English sentences. I created a training dataset using the Dataset API using the below code: ``` train_examples = tf.data.experimental.CsvDataset("./Data/train.csv", [tf.string, tf.string]) val_examples = tf.data.experimental.CsvDataset("./Data/validation.csv", [tf.str...
2019/07/23
[ "https://Stackoverflow.com/questions/57169454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8382950/" ]
I think the other two answers are very simplistic. Both of them are tackling the problem you are trying to accomplish now, but these solutions will fail once you have more and more workers/jobs since all their solutions are O(N\*N). This solution is O(N). ``` subqry = models.Subquery(Job.objects.filter(worker_id=m...
You can use the `last` method on the filtered and ordered (by `start_date`, in ascending order) queryset of a worker. For example, if the name of the worker is `foobar`, you can do: ``` Job.objects.filter(worker__name='foobar').order_by('start_date').last() ``` this will give you the last `Job` (based on `start_dat...
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
The most secure encryption is no encryption. Passwords should be reduced to a hash. This is a one-way transformation, making the password (almost) unrecoverable. When giving someone a code, you can do the following to be *actually* secure. (1) generate some random string. (2) give them the string. (3) save the has...
If it's a web game, can't you store the codes server side and send them to the client when he completed a task? What's the architecture of your game? As for encryption, maybe try something like [pyDes](http://twhiteman.netfirms.com/des.html)?
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
If it's a web game, can't you store the codes server side and send them to the client when he completed a task? What's the architecture of your game? As for encryption, maybe try something like [pyDes](http://twhiteman.netfirms.com/des.html)?
Your question isn't quite clear. Where do you want the decryption to occur? One way or another, the plaintext has to surface since you need players to eventually know it. Pick a [cipher](http://en.wikipedia.org/wiki/Stream_cipher) and be done with it.
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
If your script can decode the passwords, so can someone breaking in to your server. Encryption is only really useful when someone enters a password to unlock it - if it remains unlocked (or the script has the password to unlock it), the encryption is pointless This is why hashing is more useful, since it is a one way ...
If it's a web game, can't you store the codes server side and send them to the client when he completed a task? What's the architecture of your game? As for encryption, maybe try something like [pyDes](http://twhiteman.netfirms.com/des.html)?
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
The most secure encryption is no encryption. Passwords should be reduced to a hash. This is a one-way transformation, making the password (almost) unrecoverable. When giving someone a code, you can do the following to be *actually* secure. (1) generate some random string. (2) give them the string. (3) save the has...
Your question isn't quite clear. Where do you want the decryption to occur? One way or another, the plaintext has to surface since you need players to eventually know it. Pick a [cipher](http://en.wikipedia.org/wiki/Stream_cipher) and be done with it.
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
If your script can decode the passwords, so can someone breaking in to your server. Encryption is only really useful when someone enters a password to unlock it - if it remains unlocked (or the script has the password to unlock it), the encryption is pointless This is why hashing is more useful, since it is a one way ...
The most secure encryption is no encryption. Passwords should be reduced to a hash. This is a one-way transformation, making the password (almost) unrecoverable. When giving someone a code, you can do the following to be *actually* secure. (1) generate some random string. (2) give them the string. (3) save the has...
1,043,735
I am making a little webgame that has tasks and solutions, the solutions are solved by entering a code given to user after completion of a task. To have some security (against cheating) i dont want to store the codes genereted by the game in plain text. But since i need to be able to give a player the code when he has ...
2009/06/25
[ "https://Stackoverflow.com/questions/1043735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
If your script can decode the passwords, so can someone breaking in to your server. Encryption is only really useful when someone enters a password to unlock it - if it remains unlocked (or the script has the password to unlock it), the encryption is pointless This is why hashing is more useful, since it is a one way ...
Your question isn't quite clear. Where do you want the decryption to occur? One way or another, the plaintext has to surface since you need players to eventually know it. Pick a [cipher](http://en.wikipedia.org/wiki/Stream_cipher) and be done with it.
24,497,121
I ask because the examples in the Facebook Ads API (<https://developers.facebook.com/docs/reference/ads-api/adimage/#create>) for creating an Ad Image all use curl, but I want to do it with python requests. Or if someone can answer the more specific question of how to create an Ad Image on the Facebook Ads API from pyt...
2014/06/30
[ "https://Stackoverflow.com/questions/24497121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3391108/" ]
Try `Holders.grailsApplication.config`: ``` @TestMixin(GrailsUnitTestMixin) class TicketRequestEmailInfoSpec extends Specification { def setup() { Holders.grailsApplication.config.acme.purchase.trsUrlBase = "http://localhost:8082/purchase/order/" } ```
Didn't works injecting `grailsApplication` to test as `def grailsApplication` ? Also you can import it as `import static grails.util.Holders.config as grailsConfig`. And then use it as ``` @TestMixin(GrailsUnitTestMixin) class TicketRequestEmailInfoSpec extends Specification { def setup() { grailsConfig...
55,582,117
GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: ``` for x in range(rows)...
2019/04/08
[ "https://Stackoverflow.com/questions/55582117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6202327/" ]
Here is my attempt only using `numpy` matrix operations. My input image `colortrans.png` looks like this: [![Input image](https://i.stack.imgur.com/l1ZPc.png)](https://i.stack.imgur.com/l1ZPc.png) I want to make the diagonal purple part `(128, 0, 128)` transparent with some tolerance `+/- (25, 0, 25)` to the left an...
I've done a project that converted all pixels that are close to white into transparent pixels using the `PIL` (python image library) module. I'm not sure how to implement your algorithm for "relative to how far away from chosen color they are", but my code looks like: ``` from PIL import Image planeIm = Image.open('I...
55,582,117
GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: ``` for x in range(rows)...
2019/04/08
[ "https://Stackoverflow.com/questions/55582117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6202327/" ]
I've done a project that converted all pixels that are close to white into transparent pixels using the `PIL` (python image library) module. I'm not sure how to implement your algorithm for "relative to how far away from chosen color they are", but my code looks like: ``` from PIL import Image planeIm = Image.open('I...
Remove white background ======================= Here is an efficent way to remove white background. You can change the `np.argwhere` condition to select a specific color. ``` image = Image.open(in_pth) # convert image to numpy array transparent_img = np.ones((480,640,4),dtype=np.uint8) * 255 transparent_img[:,:,:3] =...
55,582,117
GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: ``` for x in range(rows)...
2019/04/08
[ "https://Stackoverflow.com/questions/55582117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6202327/" ]
Here is my attempt only using `numpy` matrix operations. My input image `colortrans.png` looks like this: [![Input image](https://i.stack.imgur.com/l1ZPc.png)](https://i.stack.imgur.com/l1ZPc.png) I want to make the diagonal purple part `(128, 0, 128)` transparent with some tolerance `+/- (25, 0, 25)` to the left an...
I had a go using [pyvips](https://pypi.org/project/pyvips/). This version calculates the pythagorean distance between each RGB pixel in your file and the target colour, then makes an alpha by scaling that distance metric by a tolerance. ``` import sys import pyvips image = pyvips.Image.new_from_file(sys.argv[1], a...
55,582,117
GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: ``` for x in range(rows)...
2019/04/08
[ "https://Stackoverflow.com/questions/55582117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6202327/" ]
Here is my attempt only using `numpy` matrix operations. My input image `colortrans.png` looks like this: [![Input image](https://i.stack.imgur.com/l1ZPc.png)](https://i.stack.imgur.com/l1ZPc.png) I want to make the diagonal purple part `(128, 0, 128)` transparent with some tolerance `+/- (25, 0, 25)` to the left an...
Remove white background ======================= Here is an efficent way to remove white background. You can change the `np.argwhere` condition to select a specific color. ``` image = Image.open(in_pth) # convert image to numpy array transparent_img = np.ones((480,640,4),dtype=np.uint8) * 255 transparent_img[:,:,:3] =...
55,582,117
GIMP has a convenient function that allows you to convert an arbitrary color to an alpha channel. Essentially all pixels become transparent relative to how far away from the chosen color they are. I want to replicate this functionality with opencv. I tried iterating through the image: ``` for x in range(rows)...
2019/04/08
[ "https://Stackoverflow.com/questions/55582117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6202327/" ]
I had a go using [pyvips](https://pypi.org/project/pyvips/). This version calculates the pythagorean distance between each RGB pixel in your file and the target colour, then makes an alpha by scaling that distance metric by a tolerance. ``` import sys import pyvips image = pyvips.Image.new_from_file(sys.argv[1], a...
Remove white background ======================= Here is an efficent way to remove white background. You can change the `np.argwhere` condition to select a specific color. ``` image = Image.open(in_pth) # convert image to numpy array transparent_img = np.ones((480,640,4),dtype=np.uint8) * 255 transparent_img[:,:,:3] =...
11,483,366
> > **Possible Duplicate:** > > [Making a method private in a python subclass](https://stackoverflow.com/questions/451963/making-a-method-private-in-a-python-subclass) > > [Private Variables and Methods in Python](https://stackoverflow.com/questions/3385317/private-variables-and-methods-in-python) > > > How...
2012/07/14
[ "https://Stackoverflow.com/questions/11483366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1254709/" ]
Python does not support access protection as C++/Java/C# does. Everything is public. The motto is, "We're all adults here." Document your classes, and insist that your collaborators read and follow the documentation. The culture in Python is that names starting with underscores mean, "don't use these unless you really...
You can't. Python intentionally does not support access control. By convention, methods starting with an underscore are private, and you should clearly state in the documentation who is supposed to use the method.
30,061,620
I am calculating Euclidean Distance with python code below: ``` def getNeighbors(trainingSet, testInstance, k, labels): distances = [] for x in range(len(trainingSet)): dist = math.sqrt(((testInstance[0] - trainingSet[x][0]) ** 2) + ((testInstance[1] - trainingSet[x][1]) ** 2)) distances.app...
2015/05/05
[ "https://Stackoverflow.com/questions/30061620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2831683/" ]
You can speed this up by converting to NumPy first, then using vector operations, instead of doing the work in a loop, then converting to NumPy. Something like this: ``` trainingArray = np.array(trainingSet) distances = ((testInstance[0] - trainingArray[:, 0]) ** 2 + (testInstance[1] - trainingArray[:, 1]...
Writing own sqrt calculator has its own risks, hypot is very safe for resistance to overflow and underflow ```py x_y = np.array(trainingSet) x = x_y[0] y = x_y[1] distances = np.hypot( np.subtract.outer(x, x), np.subtract.outer(y, y) ) ``` Speed wise they are same ``` %%timeit np.hypot(i, j) # 1.29 µs ± 13....
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
Short answer: Use `python -m notebook` After updating to OS Catalina, I installed a brewed python: `brew install python`. It symlinks the Python3, but not the `python` command, so I added to my `$PATH` variable the following: ``` /usr/local/opt/python/libexec/bin ``` to make the brew python the default python com...
You need to add the local python install directory to your path. Apparently this is not done by default on MacOS. Try: ``` export PATH="$HOME/Library/Python/<version number>/bin:$PATH" ``` and/or add it to your `~/.bashrc`.
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
My MacOS has python 2.7, I installed python3 with **brew**, then the following commands work for me ``` brew install python3 brew link --overwrite python ``` ``` pip3 install ipython python3 -m pip install jupyter ```
You need to add the local python install directory to your path. Apparently this is not done by default on MacOS. Try: ``` export PATH="$HOME/Library/Python/<version number>/bin:$PATH" ``` and/or add it to your `~/.bashrc`.
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
You need to add the local python install directory to your path. Apparently this is not done by default on MacOS. Try: ``` export PATH="$HOME/Library/Python/<version number>/bin:$PATH" ``` and/or add it to your `~/.bashrc`.
Try solving this with [Conda](https://docs.conda.io/en/latest/) or Poetry. [Poetry](https://python-poetry.org/) makes it a lot easier to manage Python dependencies (including Jupyter) and build a virtual environment. Here are the steps to adding Jupyter to a project: * Run `poetry add pandas jupyter ipykernel` to ad...
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
Short answer: Use `python -m notebook` After updating to OS Catalina, I installed a brewed python: `brew install python`. It symlinks the Python3, but not the `python` command, so I added to my `$PATH` variable the following: ``` /usr/local/opt/python/libexec/bin ``` to make the brew python the default python com...
My MacOS has python 2.7, I installed python3 with **brew**, then the following commands work for me ``` brew install python3 brew link --overwrite python ``` ``` pip3 install ipython python3 -m pip install jupyter ```
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
Short answer: Use `python -m notebook` After updating to OS Catalina, I installed a brewed python: `brew install python`. It symlinks the Python3, but not the `python` command, so I added to my `$PATH` variable the following: ``` /usr/local/opt/python/libexec/bin ``` to make the brew python the default python com...
Try solving this with [Conda](https://docs.conda.io/en/latest/) or Poetry. [Poetry](https://python-poetry.org/) makes it a lot easier to manage Python dependencies (including Jupyter) and build a virtual environment. Here are the steps to adding Jupyter to a project: * Run `poetry add pandas jupyter ipykernel` to ad...
45,495,753
After many different ways of trying to install jupyter, it does not seem to install correctly. May be MacOS related based on how many MacOS system python issues I've been having recently `pip install jupyter --user` Seems to install correctly But then jupyter is not found `where jupyter` `jupyter not found` Not f...
2017/08/03
[ "https://Stackoverflow.com/questions/45495753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1018733/" ]
My MacOS has python 2.7, I installed python3 with **brew**, then the following commands work for me ``` brew install python3 brew link --overwrite python ``` ``` pip3 install ipython python3 -m pip install jupyter ```
Try solving this with [Conda](https://docs.conda.io/en/latest/) or Poetry. [Poetry](https://python-poetry.org/) makes it a lot easier to manage Python dependencies (including Jupyter) and build a virtual environment. Here are the steps to adding Jupyter to a project: * Run `poetry add pandas jupyter ipykernel` to ad...
4,710,037
I'm having trouble with SWIG, shared pointers, and inheritance. I am creating various c++ classes which inherit from one another, using Boost shared pointers to refer to them, and then wrapping these shared pointers with SWIG to create the python classes. My problem is the following: * B is a subclass of A * sA is a...
2011/01/17
[ "https://Stackoverflow.com/questions/4710037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1229275/" ]
The following change appears to solve the problem. In **swig\_shared\_ptr.i** the two lines: ``` %template(base_sptr) boost::shared_ptr<Base>; %template(derived_sptr) boost::shared_ptr<Derived>; ``` are moved so that they are above the line ``` %include <swig_shared_ptr.h> ``` and are then replaced (in SWIG 1.3)...
SWIG doesn't know anything about the `boost::shared_ptr<T>` class. It therefore can't tell that `derived_sptr` can be "cast" (which is, I believe, implemented with some crazy constructors and template metaprogramming) to `derived_sptr`. Because SWIG requires fairly simple class definitions (or inclusion of simple files...
2,400,605
I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), also I want...
2010/03/08
[ "https://Stackoverflow.com/questions/2400605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235131/" ]
PHP is the best to start, but as experienced programmer you may want to look at Python, because PHP is a C style language. Python would be easier after Pascal, I think. Take a look at examples: On PHP: <http://en.wikipedia.org/wiki/Php#Syntax> On Python: <http://en.wikipedia.org/wiki/Python_(programming_language)#Sy...
Only good answer - C# ;) Seriously ;) Why? Anders Hejlsberg. He made it. It is the direct continuation of his work that started with Turbo Pascal and went over to Delphi... then Microsoft hired him and he moved from Pascal to C (core langauge) and made C#. Read it up on <http://en.wikipedia.org/wiki/Anders_Hejlsberg>...
2,400,605
I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), also I want...
2010/03/08
[ "https://Stackoverflow.com/questions/2400605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/235131/" ]
PHP is the best to start, but as experienced programmer you may want to look at Python, because PHP is a C style language. Python would be easier after Pascal, I think. Take a look at examples: On PHP: <http://en.wikipedia.org/wiki/Php#Syntax> On Python: <http://en.wikipedia.org/wiki/Python_(programming_language)#Sy...
I have done a fairly large (4-5 FTE) project based on webhub (www.href.com). I can certainly advise this if it is a webapp for internal use.