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
39,961,414
I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list! For example This is the data in a list. ``` data = [u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[3...
2016/10/10
[ "https://Stackoverflow.com/questions/39961414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6949864/" ]
When you use `$(".form-control")`, jquery select all `.form-control` element. But you need to select target element using `this` variable in event function and use [`.prev()`](https://api.jquery.com/prev/) to select previous element. ```js $(".show").mousedown(function(){ $(this).prev().attr('type','text'); }).mou...
**In react We simply do with** --- We probably need to use the onMouseDown and onMouseUp, onMouseOut events ``` onMouseDown={handleShowPassword} onMouseUp={handleShowPassword} onMouseOut={handleShowPasswordHideOnMouseOut} ```
39,961,414
I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list! For example This is the data in a list. ``` data = [u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[3...
2016/10/10
[ "https://Stackoverflow.com/questions/39961414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6949864/" ]
Just target the previous input instead of all inputs with the given class ```js $(".form-control").on("keyup", function() { if ($(this).val()) $(this).next(".show").show(); else $(this).next(".show").hide(); }).trigger('keyup'); $(".show").mousedown(function() { $(this).prev(".form-contro...
**In react We simply do with** --- We probably need to use the onMouseDown and onMouseUp, onMouseOut events ``` onMouseDown={handleShowPassword} onMouseUp={handleShowPassword} onMouseOut={handleShowPasswordHideOnMouseOut} ```
69,516,584
i am running npm install command on my project but getting error > > Build failed with error code: 1 > > > Part of the log posted below. ``` 0 verbose cli [ 0 verbose cli 'C:\\Program Files\\nodejs\\node.exe', 0 verbose cli 'C:\\Users\\vined\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js', 0 verb...
2021/10/10
[ "https://Stackoverflow.com/questions/69516584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16418162/" ]
You can create a second list that stores the valid index values. ``` import random our = [3, 3, 0, 3, 3, 7] index = [] for i in range(0, len(our)-1) : if our[i] != 0 : index.append(i) # index: [0, 1, 3, 4] random_index = random.choice(index) ``` **EDIT:** You can perform a sanity check for a non-zer...
You can use a while loop to check if the number equals 0 or not. ``` import random our = [3, 6, 2, 0, 3, 0, 5] random_number = 0 while random_number == 0: random_index = random.randint(0, len(our)-2) random_number = our[random_index] print(random_number) ```
16,276,913
at the moment I do: ``` def get_inet_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('mysite.com', 80)) return s.getsockname()[0] ``` This was based on: [Finding local IP addresses using Python's stdlib](https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pyt...
2013/04/29
[ "https://Stackoverflow.com/questions/16276913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2194306/" ]
The question is, do you just want to connect, or do you really want the address? If you just want to connect, you can do ``` s = socket.create_connection(('mysite.com', 80)) ``` and have the connection established. However, if you are interested in the address, you can go one of these ways: ``` def get_ip_6(host,...
You should be using the function [socket.getaddrinfo()](http://docs.python.org/2/library/socket.html#socket.getaddrinfo) Example code to get IPv6 ``` def get_ip_6(host,port=80): # discard the (family, socktype, proto, canonname) part of the tuple # and make sure the ips are unique alladdr = list( ...
4,093,118
Is there a way to increment the year on filtered objects using the update() method? I am using: ``` python 2.6.5 django 1.2.1 final mysql Ver 14.14 Distrib 5.1.41 ``` I know it's possible to do something like this: ``` today = datetime.datetime.today() for event in Event.objects.filter(end_date__lt=today).iterato...
2010/11/04
[ "https://Stackoverflow.com/questions/4093118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/208347/" ]
One potential cause of *"Warning: Data truncated for column X"* exception is the use of non-whole day values for the timedelta being added to the **DateField** - it is fine in python, but fails when written to the mysql db. If you have a **DateTimeField**, it works too, since the precision of the persisted field matche...
Quick but ugly: ``` >>> a.created.timetuple() time.struct_time(tm_year=2000, tm_mon=11, tm_mday=2, tm_hour=2, tm_min=35, tm_se c=14, tm_wday=3, tm_yday=307, tm_isdst=-1) >>> time = list(a.created.timetuple()) >>> time[0] = time[0] + 1 >>> time [2001, 11, 2, 2, 35, 14, 3, 307, -1] >>> ```
4,093,118
Is there a way to increment the year on filtered objects using the update() method? I am using: ``` python 2.6.5 django 1.2.1 final mysql Ver 14.14 Distrib 5.1.41 ``` I know it's possible to do something like this: ``` today = datetime.datetime.today() for event in Event.objects.filter(end_date__lt=today).iterato...
2010/11/04
[ "https://Stackoverflow.com/questions/4093118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/208347/" ]
One potential cause of *"Warning: Data truncated for column X"* exception is the use of non-whole day values for the timedelta being added to the **DateField** - it is fine in python, but fails when written to the mysql db. If you have a **DateTimeField**, it works too, since the precision of the persisted field matche...
``` from dateutil.relativedelta import relativedelta yourdate = datetime.datetime(2010, 11, 4, 10, 14, 54, 518749) yourdate += relativedelta(years=+1) ``` Relativedelta takes many time arguments, from seconds to years...
4,093,118
Is there a way to increment the year on filtered objects using the update() method? I am using: ``` python 2.6.5 django 1.2.1 final mysql Ver 14.14 Distrib 5.1.41 ``` I know it's possible to do something like this: ``` today = datetime.datetime.today() for event in Event.objects.filter(end_date__lt=today).iterato...
2010/11/04
[ "https://Stackoverflow.com/questions/4093118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/208347/" ]
One potential cause of *"Warning: Data truncated for column X"* exception is the use of non-whole day values for the timedelta being added to the **DateField** - it is fine in python, but fails when written to the mysql db. If you have a **DateTimeField**, it works too, since the precision of the persisted field matche...
Have you seen this: [Increasing a datetime field with queryset.update](https://stackoverflow.com/questions/3843250/increasing-a-datetime-field-with-queryset-update) ? I also remember successfully using queryset .update() with timedelta with MySQL backend.
58,537,324
For multiple `csv` files in a folder, I hope to loop all files ends with `csv` and merge as one excel file, here I give two examples: **first.csv** ``` date a b 0 2019.1 1.0 NaN 1 2019.2 NaN 2.0 2 2019.3 3.0 2.0 3 2019.4 3.0 NaN ``` **second.csv** ``` date c d 0 2019.1 1.0 Na...
2019/10/24
[ "https://Stackoverflow.com/questions/58537324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8410477/" ]
You can use Linq to perform your shift, here is a simple method you can use ``` public int[] shiftRight(int[] array, int shift) { var result = new List<int>(); var toTake = array.Take(shift); var toSkip = array.Skip(shift); result.AddRange(toSkip); result.AddRange(toTak...
If this is only for strings and the wraparound is necessary I would suggest to use `str.Substring(0,shift)` and append it to `str.Substring(shift)` (don't try to reinvent the weel) (some info about the substring method: [String.Substring](https://learn.microsoft.com/en-us/dotnet/api/system.string.substring?view=netfram...
58,537,324
For multiple `csv` files in a folder, I hope to loop all files ends with `csv` and merge as one excel file, here I give two examples: **first.csv** ``` date a b 0 2019.1 1.0 NaN 1 2019.2 NaN 2.0 2 2019.3 3.0 2.0 3 2019.4 3.0 NaN ``` **second.csv** ``` date c d 0 2019.1 1.0 Na...
2019/10/24
[ "https://Stackoverflow.com/questions/58537324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8410477/" ]
You can use Linq to perform your shift, here is a simple method you can use ``` public int[] shiftRight(int[] array, int shift) { var result = new List<int>(); var toTake = array.Take(shift); var toSkip = array.Skip(shift); result.AddRange(toSkip); result.AddRange(toTak...
Here is quick fix for you. please check following code. I shift element to left by 1 position you can change code as par your requirement. Input array: 1 2 3 4 5 6 Input how many times to shift left: 1 Output : 2 3 4 5 6 1 ``` int[] nums = {1, 2, 3, 4, 5, 6}; Console.WriteLine("\nArray1: [{0}]", string.Jo...
67,539,918
After installing Flask, When I used `from flask import Flask` to check if flask is properly installed or not, it gave the following error ``` >>> from flask import Flask Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/dist-packages/flask/__init__.py", line 3,...
2021/05/14
[ "https://Stackoverflow.com/questions/67539918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12194111/" ]
Flask is now at 2.0.0, which has ratcheted forward on requirements. If you're on a system that is still on Python3.5, your alternative is to install the most recent in the 1.x line, and put ``` Flask==1.1.4 ``` in your `requirements.txt`, or ``` venv/bin/pip install Flask==1.1.4 ``` to install it manually.
The error indicates that you're running Python 3.5. Variable annotations that the library is attempting to use weren't [introduced until 3.6 though](https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations). Upgrade to at least 3.6 to solve this. 3.9 is available too, so unless you need to use...
67,539,918
After installing Flask, When I used `from flask import Flask` to check if flask is properly installed or not, it gave the following error ``` >>> from flask import Flask Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.5/dist-packages/flask/__init__.py", line 3,...
2021/05/14
[ "https://Stackoverflow.com/questions/67539918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12194111/" ]
Flask is now at 2.0.0, which has ratcheted forward on requirements. If you're on a system that is still on Python3.5, your alternative is to install the most recent in the 1.x line, and put ``` Flask==1.1.4 ``` in your `requirements.txt`, or ``` venv/bin/pip install Flask==1.1.4 ``` to install it manually.
Flask is now at 2.0.0, and has ratcheted forward on requirements. If you're on a system that is still on Python3.5, you are out of luck for 2.0.0. Your alternative is to install the most recent in the 1.x line. Specify ``` Flask==1.4.4 ``` if you're using `requirements.txt`, or ``` venv/bin/pip install Flask==1.1...
37,316,731
I have a bash script which reads variable from environment and then passes it to the python script like this ``` #!/usr/bin/env bash if [ -n "${my_param}" ] then my_param_str="--my_param ${my_param}" fi python -u my_script.py ${my_param_str} ``` Corresponding python script look like this ``` parser = argparse...
2016/05/19
[ "https://Stackoverflow.com/questions/37316731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1744914/" ]
For the limited example you can basically get the same behavior just using ``` arg = os.environ.get('my_param', '') ``` where the first argument to `get` is the variable name and the second is the default value used should the var not be in the environment.
The quotes you write around the string do not get preserved when you assign a Bash string variable: ``` $ export my_param="Some -- string" $ echo $my_param Some -- string ``` You need to place the quotes around the variable again when you use it to create the `my_param_str`: ``` my_param_str="--my_param \"${my_para...
37,316,731
I have a bash script which reads variable from environment and then passes it to the python script like this ``` #!/usr/bin/env bash if [ -n "${my_param}" ] then my_param_str="--my_param ${my_param}" fi python -u my_script.py ${my_param_str} ``` Corresponding python script look like this ``` parser = argparse...
2016/05/19
[ "https://Stackoverflow.com/questions/37316731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1744914/" ]
Your bash needs to look like this: ``` if [ -n "${my_param}" ] then my_param_str="--my_param \"${my_param}\"" fi echo ${my_param_str}|xargs python -u my_script.py ``` Otherwise, the quotes around the parameter string will not be preserved, and "Some", "--" and "thing" will be passed as three separate arguments.
For the limited example you can basically get the same behavior just using ``` arg = os.environ.get('my_param', '') ``` where the first argument to `get` is the variable name and the second is the default value used should the var not be in the environment.
37,316,731
I have a bash script which reads variable from environment and then passes it to the python script like this ``` #!/usr/bin/env bash if [ -n "${my_param}" ] then my_param_str="--my_param ${my_param}" fi python -u my_script.py ${my_param_str} ``` Corresponding python script look like this ``` parser = argparse...
2016/05/19
[ "https://Stackoverflow.com/questions/37316731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1744914/" ]
Your bash needs to look like this: ``` if [ -n "${my_param}" ] then my_param_str="--my_param \"${my_param}\"" fi echo ${my_param_str}|xargs python -u my_script.py ``` Otherwise, the quotes around the parameter string will not be preserved, and "Some", "--" and "thing" will be passed as three separate arguments.
The quotes you write around the string do not get preserved when you assign a Bash string variable: ``` $ export my_param="Some -- string" $ echo $my_param Some -- string ``` You need to place the quotes around the variable again when you use it to create the `my_param_str`: ``` my_param_str="--my_param \"${my_para...
50,420,139
I am using python to generate a query text which I then send to the `SQL server`. The query is created in a function that accepts a list of strings which are then inserted into the query. The query looks like: ``` SELECT * FROM DB WHERE last_word in ('red', 'phone', 'robin') ``` The issue is that here I have just...
2018/05/18
[ "https://Stackoverflow.com/questions/50420139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367204/" ]
How many rows do you have in "DB"? Are there more "last\_word"s matching the 4000 words in the IN clause than not? If so, it would be better to use NOT IN, to exclude instead of include. Also, try to never use SELECT \* since this wildcard is very unperformant, it's better to explicitly define the columns you want to i...
Try doing something like this: ``` SELECT * FROM DB INNER JOIN WORDS_TABLE ON DB.WORDS = WORDS_TABLE.WORDS; ``` Instead of the `*` use whatever you want to get. `JOIN` in this case will be faster than the `IN` as you will have to write another inner query if you are using a table.
50,420,139
I am using python to generate a query text which I then send to the `SQL server`. The query is created in a function that accepts a list of strings which are then inserted into the query. The query looks like: ``` SELECT * FROM DB WHERE last_word in ('red', 'phone', 'robin') ``` The issue is that here I have just...
2018/05/18
[ "https://Stackoverflow.com/questions/50420139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367204/" ]
How many rows do you have in "DB"? Are there more "last\_word"s matching the 4000 words in the IN clause than not? If so, it would be better to use NOT IN, to exclude instead of include. Also, try to never use SELECT \* since this wildcard is very unperformant, it's better to explicitly define the columns you want to i...
Put your data into a temp table or CTE. This would make for easier addition of new data. Likewise, you’ll have to do an inner join to your source table to make sure you capture everything. Hope this helps.
50,420,139
I am using python to generate a query text which I then send to the `SQL server`. The query is created in a function that accepts a list of strings which are then inserted into the query. The query looks like: ``` SELECT * FROM DB WHERE last_word in ('red', 'phone', 'robin') ``` The issue is that here I have just...
2018/05/18
[ "https://Stackoverflow.com/questions/50420139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367204/" ]
optimization strategies: 1. add an index on `last_word` ``` CREATE INDEX ON db(last_word) ``` 2. store the filter words in a table and use a `WHERE exists` (or inner join) ``` WITH words (word) AS ( VALUES ('red'), ('phone'), ('robin') ) SELECT * FROM db WHERE EXISTS (SELECT TRUE FROM words WHERE word = last_word...
How many rows do you have in "DB"? Are there more "last\_word"s matching the 4000 words in the IN clause than not? If so, it would be better to use NOT IN, to exclude instead of include. Also, try to never use SELECT \* since this wildcard is very unperformant, it's better to explicitly define the columns you want to i...
50,420,139
I am using python to generate a query text which I then send to the `SQL server`. The query is created in a function that accepts a list of strings which are then inserted into the query. The query looks like: ``` SELECT * FROM DB WHERE last_word in ('red', 'phone', 'robin') ``` The issue is that here I have just...
2018/05/18
[ "https://Stackoverflow.com/questions/50420139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367204/" ]
optimization strategies: 1. add an index on `last_word` ``` CREATE INDEX ON db(last_word) ``` 2. store the filter words in a table and use a `WHERE exists` (or inner join) ``` WITH words (word) AS ( VALUES ('red'), ('phone'), ('robin') ) SELECT * FROM db WHERE EXISTS (SELECT TRUE FROM words WHERE word = last_word...
Try doing something like this: ``` SELECT * FROM DB INNER JOIN WORDS_TABLE ON DB.WORDS = WORDS_TABLE.WORDS; ``` Instead of the `*` use whatever you want to get. `JOIN` in this case will be faster than the `IN` as you will have to write another inner query if you are using a table.
50,420,139
I am using python to generate a query text which I then send to the `SQL server`. The query is created in a function that accepts a list of strings which are then inserted into the query. The query looks like: ``` SELECT * FROM DB WHERE last_word in ('red', 'phone', 'robin') ``` The issue is that here I have just...
2018/05/18
[ "https://Stackoverflow.com/questions/50420139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367204/" ]
optimization strategies: 1. add an index on `last_word` ``` CREATE INDEX ON db(last_word) ``` 2. store the filter words in a table and use a `WHERE exists` (or inner join) ``` WITH words (word) AS ( VALUES ('red'), ('phone'), ('robin') ) SELECT * FROM db WHERE EXISTS (SELECT TRUE FROM words WHERE word = last_word...
Put your data into a temp table or CTE. This would make for easier addition of new data. Likewise, you’ll have to do an inner join to your source table to make sure you capture everything. Hope this helps.
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
using pieces from both @hharnisc and @mick-t answers. ``` pip install python-ldap \ --global-option=build_ext \ --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl" ```
I had the same problem. I'm using Macports on my Mac and I have cyrus-sasl2 installed which provides sasl.h in /opt/local/include/sasl/. You can pass options to build\_ext using pip's global-option argument. To pass the include PATH to /opt/local/include/sasl/sasl.h run pip like this: `pip install python-ldap --global...
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
I used a combination of posts I found about this problem (including this one) to eventually come up with this (copied from a larger script): ``` export XC_SDK=$(xcrun --show-sdk-path) export USR_INC=$XC_SDK/usr/include export PATH=$USR_INC:$PATH echo "installing python-ldap" ARCHFLAGS=-Wno-error=unused-command-line-a...
I got this error when running buildout. I fixed it, first finding the sasl.h file: ``` mdfind -name sasl.h ``` then defining the corresponding CFLAGS environment variable: ``` export CFLAGS="-I/opt/local/include/sasl" ``` and finally running buildout again.
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
I had the same problem. I'm using Macports on my Mac and I have cyrus-sasl2 installed which provides sasl.h in /opt/local/include/sasl/. You can pass options to build\_ext using pip's global-option argument. To pass the include PATH to /opt/local/include/sasl/sasl.h run pip like this: `pip install python-ldap --global...
I used a combination of posts I found about this problem (including this one) to eventually come up with this (copied from a larger script): ``` export XC_SDK=$(xcrun --show-sdk-path) export USR_INC=$XC_SDK/usr/include export PATH=$USR_INC:$PATH echo "installing python-ldap" ARCHFLAGS=-Wno-error=unused-command-line-a...
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
**A workaround** /usr/include appears to have moved ``` $ xcrun --show-sdk-path $ sudo ln -s <the_path_from_above_command>/usr/include /usr/include ``` Now run pip install!
I had the same problem. I'm using Macports on my Mac and I have cyrus-sasl2 installed which provides sasl.h in /opt/local/include/sasl/. You can pass options to build\_ext using pip's global-option argument. To pass the include PATH to /opt/local/include/sasl/sasl.h run pip like this: `pip install python-ldap --global...
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
In my particular case, I couldn't simply use the `pip` arguments noted in other answers because I'm using it with `tox` to install dependencies from a requirements.txt file, and I need my tox.ini to remain compatible with non-Mac environments. I was able to resolve this in much simpler fashion: exporting `CFLAGS` such...
I used a combination of posts I found about this problem (including this one) to eventually come up with this (copied from a larger script): ``` export XC_SDK=$(xcrun --show-sdk-path) export USR_INC=$XC_SDK/usr/include export PATH=$USR_INC:$PATH echo "installing python-ldap" ARCHFLAGS=-Wno-error=unused-command-line-a...
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
**A workaround** /usr/include appears to have moved ``` $ xcrun --show-sdk-path $ sudo ln -s <the_path_from_above_command>/usr/include /usr/include ``` Now run pip install!
I got this error when running buildout. I fixed it, first finding the sasl.h file: ``` mdfind -name sasl.h ``` then defining the corresponding CFLAGS environment variable: ``` export CFLAGS="-I/opt/local/include/sasl" ``` and finally running buildout again.
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
using pieces from both @hharnisc and @mick-t answers. ``` pip install python-ldap \ --global-option=build_ext \ --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl" ```
In my particular case, I couldn't simply use the `pip` arguments noted in other answers because I'm using it with `tox` to install dependencies from a requirements.txt file, and I need my tox.ini to remain compatible with non-Mac environments. I was able to resolve this in much simpler fashion: exporting `CFLAGS` such...
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
In my particular case, I couldn't simply use the `pip` arguments noted in other answers because I'm using it with `tox` to install dependencies from a requirements.txt file, and I need my tox.ini to remain compatible with non-Mac environments. I was able to resolve this in much simpler fashion: exporting `CFLAGS` such...
I got this error when running buildout. I fixed it, first finding the sasl.h file: ``` mdfind -name sasl.h ``` then defining the corresponding CFLAGS environment variable: ``` export CFLAGS="-I/opt/local/include/sasl" ``` and finally running buildout again.
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
I had the same problem. I'm using Macports on my Mac and I have cyrus-sasl2 installed which provides sasl.h in /opt/local/include/sasl/. You can pass options to build\_ext using pip's global-option argument. To pass the include PATH to /opt/local/include/sasl/sasl.h run pip like this: `pip install python-ldap --global...
I got this error when running buildout. I fixed it, first finding the sasl.h file: ``` mdfind -name sasl.h ``` then defining the corresponding CFLAGS environment variable: ``` export CFLAGS="-I/opt/local/include/sasl" ``` and finally running buildout again.
22,079,173
I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine. Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE\_X86\_64 x86\_64 I tried what was suggested here: <http://projects.skurfer.com/posts/2011...
2014/02/27
[ "https://Stackoverflow.com/questions/22079173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865366/" ]
using pieces from both @hharnisc and @mick-t answers. ``` pip install python-ldap \ --global-option=build_ext \ --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl" ```
I used a combination of posts I found about this problem (including this one) to eventually come up with this (copied from a larger script): ``` export XC_SDK=$(xcrun --show-sdk-path) export USR_INC=$XC_SDK/usr/include export PATH=$USR_INC:$PATH echo "installing python-ldap" ARCHFLAGS=-Wno-error=unused-command-line-a...
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You could do something like the following: ``` <% form_for @user, :url => { :action => "update" } do |user_form| %> ... <% user_form.fields_for :profiles do |profiles_fields| %> Phone Number: <%= profiles_fields.text_field :profile_mobile_number %> <% end %> <% end %> ``` But since you already have an as...
You can use '[accepts\_nested\_attributes\_for](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)' to do this; but there's a little trick in forms: You must use the singular, and call fields\_for for each profile, like this: ``` <% form_for @user do |f| -%> <% @user.profiles.each do ...
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You could do something like the following: ``` <% form_for @user, :url => { :action => "update" } do |user_form| %> ... <% user_form.fields_for :profiles do |profiles_fields| %> Phone Number: <%= profiles_fields.text_field :profile_mobile_number %> <% end %> <% end %> ``` But since you already have an as...
You should watch [RailsCasts Nested Model Form](http://railscasts.com/episodes/196-nested-model-form-part-1). thanks [Ryan Bates](http://workingwithrails.com/person/6491-ryan-bates) great work.
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You could do something like the following: ``` <% form_for @user, :url => { :action => "update" } do |user_form| %> ... <% user_form.fields_for :profiles do |profiles_fields| %> Phone Number: <%= profiles_fields.text_field :profile_mobile_number %> <% end %> <% end %> ``` But since you already have an as...
<http://apidock.com/rails/v3.2.8/ActionView/Helpers/FormHelper/fields_for> This api dock link list many Nested Attributes Examples including one-to-one, one-to-many. It's very helpful!
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You should watch [RailsCasts Nested Model Form](http://railscasts.com/episodes/196-nested-model-form-part-1). thanks [Ryan Bates](http://workingwithrails.com/person/6491-ryan-bates) great work.
You can use '[accepts\_nested\_attributes\_for](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)' to do this; but there's a little trick in forms: You must use the singular, and call fields\_for for each profile, like this: ``` <% form_for @user do |f| -%> <% @user.profiles.each do ...
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
<http://apidock.com/rails/v3.2.8/ActionView/Helpers/FormHelper/fields_for> This api dock link list many Nested Attributes Examples including one-to-one, one-to-many. It's very helpful!
You can use '[accepts\_nested\_attributes\_for](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html)' to do this; but there's a little trick in forms: You must use the singular, and call fields\_for for each profile, like this: ``` <% form_for @user do |f| -%> <% @user.profiles.each do ...
2,249,162
I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as; ``` "Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" ``` But I can't seem to work out how to achieve this. Any suggestions?
2010/02/12
[ "https://Stackoverflow.com/questions/2249162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You should watch [RailsCasts Nested Model Form](http://railscasts.com/episodes/196-nested-model-form-part-1). thanks [Ryan Bates](http://workingwithrails.com/person/6491-ryan-bates) great work.
<http://apidock.com/rails/v3.2.8/ActionView/Helpers/FormHelper/fields_for> This api dock link list many Nested Attributes Examples including one-to-one, one-to-many. It's very helpful!
9,394,947
I have been having a few issues using the quadrature function in python 2.7 (part of the scipy.integrate module). The equation I am trying to integrate is simply: ``` x/(d^2) - (x^2) ``` The integration is between limits a and b. However, I need to do the integration at 40 different values of d and am not sure how t...
2012/02/22
[ "https://Stackoverflow.com/questions/9394947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1171835/" ]
``` In [9]: from scipy.integrate import quad In [10]: a = 0 In [11]: b = 1 In [12]: [quad(lambda x, d: x/(d**2)-x**2, a, b, args=d) for d in range(2, 5)] Out[12]: [(-0.20833333333333334, 2.3717550132075781e-15), (-0.27777777777777773, 3.0886887822595405e-15), (-0.30208333333333337, 3.3546344203581545e-15)] ``` ...
``` from numpy import arange from scipy.integrate import quad beg = 0. end = 4. res = [] for d in arange(1., 40.): res.append(quad(lambda x: x/(d**2.)-(x**2.), beg, end)) ``` You can then access the results by ``` print res[0] ``` or even ``` print res ```
9,394,947
I have been having a few issues using the quadrature function in python 2.7 (part of the scipy.integrate module). The equation I am trying to integrate is simply: ``` x/(d^2) - (x^2) ``` The integration is between limits a and b. However, I need to do the integration at 40 different values of d and am not sure how t...
2012/02/22
[ "https://Stackoverflow.com/questions/9394947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1171835/" ]
``` from numpy import arange from scipy.integrate import quad beg = 0. end = 4. res = [] for d in arange(1., 40.): res.append(quad(lambda x: x/(d**2.)-(x**2.), beg, end)) ``` You can then access the results by ``` print res[0] ``` or even ``` print res ```
If you want exact symbolic integration, you'll need to turn to [SymPy](http://docs.sympy.org/dev/modules/integrals/integrals.html). Try ``` import sympy x = sympy.Symbol('x') a = sympy.Symbol('a') b = sympy.Symbol('b') d = sympy.Symbol('d') res = sympy.integrate(x / (d**2 - x**2), (x, a, b)) print(res) ``` This re...
9,394,947
I have been having a few issues using the quadrature function in python 2.7 (part of the scipy.integrate module). The equation I am trying to integrate is simply: ``` x/(d^2) - (x^2) ``` The integration is between limits a and b. However, I need to do the integration at 40 different values of d and am not sure how t...
2012/02/22
[ "https://Stackoverflow.com/questions/9394947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1171835/" ]
``` In [9]: from scipy.integrate import quad In [10]: a = 0 In [11]: b = 1 In [12]: [quad(lambda x, d: x/(d**2)-x**2, a, b, args=d) for d in range(2, 5)] Out[12]: [(-0.20833333333333334, 2.3717550132075781e-15), (-0.27777777777777773, 3.0886887822595405e-15), (-0.30208333333333337, 3.3546344203581545e-15)] ``` ...
If you want exact symbolic integration, you'll need to turn to [SymPy](http://docs.sympy.org/dev/modules/integrals/integrals.html). Try ``` import sympy x = sympy.Symbol('x') a = sympy.Symbol('a') b = sympy.Symbol('b') d = sympy.Symbol('d') res = sympy.integrate(x / (d**2 - x**2), (x, a, b)) print(res) ``` This re...
217,900
i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script. but i do not how to i write. can any one give me example of small code for unit testing in python. i am thankful
2008/10/20
[ "https://Stackoverflow.com/questions/217900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17451/" ]
Read the [unit testing framework section](http://www.python.org/doc/2.5.2/lib/module-unittest.html) of the [Python Library Reference](http://www.python.org/doc/2.5.2/lib/lib.html). A [basic example](http://www.python.org/doc/2.5.2/lib/minimal-example.html) from the documentation: ``` import random import unittest cl...
Here's an [example](http://www.python.org/doc/2.5.2/lib/minimal-example.html) and you might want to read a little more on [pythons unit testing](http://www.python.org/doc/2.5.2/lib/module-unittest.html).
217,900
i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script. but i do not how to i write. can any one give me example of small code for unit testing in python. i am thankful
2008/10/20
[ "https://Stackoverflow.com/questions/217900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17451/" ]
Read the [unit testing framework section](http://www.python.org/doc/2.5.2/lib/module-unittest.html) of the [Python Library Reference](http://www.python.org/doc/2.5.2/lib/lib.html). A [basic example](http://www.python.org/doc/2.5.2/lib/minimal-example.html) from the documentation: ``` import random import unittest cl...
It's probably best to start off with the given `unittest` example. Some standard best practices: * put all your tests in a `tests` folder at the root of your project. * write one test module for each python module you're testing. * test modules should start with the word `test`. * test methods should start with the w...
217,900
i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script. but i do not how to i write. can any one give me example of small code for unit testing in python. i am thankful
2008/10/20
[ "https://Stackoverflow.com/questions/217900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17451/" ]
It's probably best to start off with the given `unittest` example. Some standard best practices: * put all your tests in a `tests` folder at the root of your project. * write one test module for each python module you're testing. * test modules should start with the word `test`. * test methods should start with the w...
Here's an [example](http://www.python.org/doc/2.5.2/lib/minimal-example.html) and you might want to read a little more on [pythons unit testing](http://www.python.org/doc/2.5.2/lib/module-unittest.html).
64,529,777
I have developed an Azure ARM template to deploy an Ubuntu Linux machine that once provisioned a bash script will run to install a particular software. The software involves downloading some packages as well as pass an input parameter from the user in order to complete the configuration. The issue I am facing is that t...
2020/10/25
[ "https://Stackoverflow.com/questions/64529777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14497508/" ]
I ended up using this code ``` import * as React from "react"; import Form from "@rjsf/material-ui"; import {FormProps, ObjectFieldTemplateProps} from "@rjsf/core"; import Button from "@material-ui/core/Button/Button"; import styles from './LSForm.module.scss'; import Grid from "@material-ui/core/Grid/Grid"; inte...
I found a solution which is not my prefered one: ``` const ObjectFieldTemplate = (props: ObjectFieldTemplateProps) => { return ( <div> {props.title} {props.description} {props.properties.map(element => { return <div className="property-wrapper">{elemen...
68,835,056
I have a python script that I compiled to an EXE, one of the purposes of it is to extract a 7z file and save it to a destination. If I'm running it from PyCharm everything works great, this is the code: ``` def delete_old_version_rename_new(self): winutils.delete(self.old_version) print("Extracting...
2021/08/18
[ "https://Stackoverflow.com/questions/68835056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14895566/" ]
Single-file executables self-extract to a temporary folder and run from there, so any relative paths will be relative to that folder *not* the location of executable you originally ran. My solution is a code snippet such as this: ``` if getattr(sys, 'frozen', False): app_path = os.path.dirname(sys.executable) els...
Eventually i just used a 7z command line i took from <https://superuser.com/questions/95902/7-zip-and-unzipping-from-command-line> and used os.system() to initialize it. Since my program is command line based it worked even better since its providing a status on the extraction process. Only downside is i have to move t...
49,677,269
I'm trying to create an email template in Django which uses [Materialize.css](http://materializecss.com/). Here is the template code: ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m...
2018/04/05
[ "https://Stackoverflow.com/questions/49677269", "https://Stackoverflow.com", "https://Stackoverflow.com/users/995862/" ]
E-mails do not support all CSS functions, I recommend you create your own CSS with alternative functions to achieve the same result. Here's a handy website on which you can check what CSS you can and can't use for certain e-mail clients. <https://www.campaignmonitor.com/css/>
Just to provide you an option, look into MJML. It can be used programmatically with Node. It can create responsive and emails with all the common email clients via what is essentially a combination of HTML and CSS with baked in fixes for displaying through the various email clients. <https://mjml.io/> "MJML is a mark...
19,601,797
i will answer any questions i can Basically I have a list of 70 words that I am looking for in over 500 files, and I need to replace them with new words and numbers. ie... find "hello" and replace with "hello 233.4" but 70 words/numbers and 500+ files. I found an informative post here, but I have been reading about ...
2013/10/26
[ "https://Stackoverflow.com/questions/19601797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2779846/" ]
The code that you posted above is probably to complex for what you need for your assignment. Perhaps something more simple like the following is easier to understand: ``` # example variables word_mapping = [['horse', 'donkey'], ['left', 'right']] filename = 'C:/search/this/file/searchme.txt' # load the text from the ...
Maybe can try this... [Find all files in a directory with extension .txt in Python](https://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-with-python) Put all 500 files in the same directory and process from there.
48,600,481
I'm working with the following string: ``` '"name": "Gnosis", \n "symbol": "GNO", \n "rank": "99", \n "price_usd": "175.029", \n "price_btc": "0.0186887", \n "24h_volume_usd": "753877.0"' ``` and I have to use `re.sub()` in python to replace only the double quotes (`"`) that are en...
2018/02/03
[ "https://Stackoverflow.com/questions/48600481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9167585/" ]
**Regex**: [`"(-?\d+(?:[\.,]\d+)?)"`](https://regex101.com/r/ySz6v5/3) **Substitution**: `\1` Details: * `()` Capturing group * `(?:)` Non capturing group * `\d` Matches a digit (equal to `[0-9]`) * `+` Matches between one and unlimited times * `?` Matches between zero and one times * `\1` Group 1. **Python code**: ...
Parse the string first with json, and later convert numbers to floats: ``` string = '{"name": "Gnosis", \n "symbol": "GNO", \n "rank": "99", \n "price_usd": "175.029", \n "price_btc": "0.0186887", \n "24h_volume_usd": "753877.0"}' data = json.loads(string) response = {} for key, val...
48,600,481
I'm working with the following string: ``` '"name": "Gnosis", \n "symbol": "GNO", \n "rank": "99", \n "price_usd": "175.029", \n "price_btc": "0.0186887", \n "24h_volume_usd": "753877.0"' ``` and I have to use `re.sub()` in python to replace only the double quotes (`"`) that are en...
2018/02/03
[ "https://Stackoverflow.com/questions/48600481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9167585/" ]
Parse the string first with json, and later convert numbers to floats: ``` string = '{"name": "Gnosis", \n "symbol": "GNO", \n "rank": "99", \n "price_usd": "175.029", \n "price_btc": "0.0186887", \n "24h_volume_usd": "753877.0"}' data = json.loads(string) response = {} for key, val...
You came close. You want to **save** the numbers, and the colon, so you need to put them in parentheses, not the rest. Also, numbers are `\d`, not `\D` (that would be *not*-numbers). So: ``` exp = re.compile(r'(: *)"(\d+\.?\d*)"', re.MULTILINE) response = re.sub(exp, "\\1\\2", string) \d+\.?\d* means "a number (or ...
48,600,481
I'm working with the following string: ``` '"name": "Gnosis", \n "symbol": "GNO", \n "rank": "99", \n "price_usd": "175.029", \n "price_btc": "0.0186887", \n "24h_volume_usd": "753877.0"' ``` and I have to use `re.sub()` in python to replace only the double quotes (`"`) that are en...
2018/02/03
[ "https://Stackoverflow.com/questions/48600481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9167585/" ]
**Regex**: [`"(-?\d+(?:[\.,]\d+)?)"`](https://regex101.com/r/ySz6v5/3) **Substitution**: `\1` Details: * `()` Capturing group * `(?:)` Non capturing group * `\d` Matches a digit (equal to `[0-9]`) * `+` Matches between one and unlimited times * `?` Matches between zero and one times * `\1` Group 1. **Python code**: ...
You came close. You want to **save** the numbers, and the colon, so you need to put them in parentheses, not the rest. Also, numbers are `\d`, not `\D` (that would be *not*-numbers). So: ``` exp = re.compile(r'(: *)"(\d+\.?\d*)"', re.MULTILINE) response = re.sub(exp, "\\1\\2", string) \d+\.?\d* means "a number (or ...
36,839,650
I want to execute one python script in Jupyter, but I don't want to use the web browser (IPython Interactive terminal), I want to run a single command in the Linux terminal to load & run the python script, so that I can get the output from Jupyter. I tried to run `jupyter notebook %run <my_script.py>`, but it seems j...
2016/04/25
[ "https://Stackoverflow.com/questions/36839650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6204018/" ]
You can use the `jupyter console -i` command to run an interactive jupyter session in your terminal. From there you can run `import <my_script.py>`. Do note that this is not the intended use case of either jupyter or the notebook environment. You should run scripts using your normal python interpreter instead.
You can run this command to run an interactive jupyter session in your terminal. > > jupyter notebook > > >
36,839,650
I want to execute one python script in Jupyter, but I don't want to use the web browser (IPython Interactive terminal), I want to run a single command in the Linux terminal to load & run the python script, so that I can get the output from Jupyter. I tried to run `jupyter notebook %run <my_script.py>`, but it seems j...
2016/04/25
[ "https://Stackoverflow.com/questions/36839650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6204018/" ]
You can use the `jupyter console -i` command to run an interactive jupyter session in your terminal. From there you can run `import <my_script.py>`. Do note that this is not the intended use case of either jupyter or the notebook environment. You should run scripts using your normal python interpreter instead.
The `jupyter_client` package has a `jupyter run` command since [v5.0](https://github.com/jupyter/jupyter_client/blob/7cfd766b067a2972f9e33ee1d687fa2bc72bb518/setup.py#L93), so you can just do: ``` jupyter run my_script.py ```
36,839,650
I want to execute one python script in Jupyter, but I don't want to use the web browser (IPython Interactive terminal), I want to run a single command in the Linux terminal to load & run the python script, so that I can get the output from Jupyter. I tried to run `jupyter notebook %run <my_script.py>`, but it seems j...
2016/04/25
[ "https://Stackoverflow.com/questions/36839650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6204018/" ]
The `jupyter_client` package has a `jupyter run` command since [v5.0](https://github.com/jupyter/jupyter_client/blob/7cfd766b067a2972f9e33ee1d687fa2bc72bb518/setup.py#L93), so you can just do: ``` jupyter run my_script.py ```
You can run this command to run an interactive jupyter session in your terminal. > > jupyter notebook > > >
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
1- Stop other applications that are using port 80. 2- run application with port 80 : ``` if __name__ == '__main__': app.run(host='0.0.0.0', port=80) ```
You don't need to change port number for your application, just configure your www server (nginx or apache) to proxy queries to flask port. Pay attantion on `uWSGI`.
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
So it's throwing up that error message because you have `apache2` running on port 80. If this is for development, I would just leave it as it is on port 5000. If it's for production either: **Not Recommended** * Stop `apache2` first; Not recommended as it states in the documentation: > > You can use the builtin ...
you can easily disable any process running on port 80 and then run this command ``` flask run --host 0.0.0.0 --port 80 ``` or if u prefer running it within the .py file ``` if __name__ == "__main__": app.run(host='0.0.0.0', port=80) ```
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
If you use the following to change the port or host: ``` if __name__ == '__main__': app.run(host='0.0.0.0', port=80) ``` use the following code to start the server (my main entrance for flask is app.py): ``` python app.py ``` instead of using: ``` flask run ```
On my scenario the following steps worked like a charm: * Installing the package: ``` pip install --upgrade pip pip install python-dotenv ``` * Creating a hidden file in my app directory "flaskr/.flaskenv" * Adding the following content: ``` FLASK_APP=flaskr FLASK_RUN_HOST=localhost FLASK_RUN_PORT=8000 ``` * Final...
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
So it's throwing up that error message because you have `apache2` running on port 80. If this is for development, I would just leave it as it is on port 5000. If it's for production either: **Not Recommended** * Stop `apache2` first; Not recommended as it states in the documentation: > > You can use the builtin ...
I solved 2 times and solved it with 2 solution The first solution, follow these steps: 1 open cmd 2 run `ipconfig` at cmd 3 copy IPv4 Address from cmd 4 Use your IPv4 as the local host in the next: ``` app.run(debug=True, port=5000, host='localhost') ``` at replace 'localhost' with your IPv4 Address 5 for your...
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
For externally visible server, where you don't use apache or other web server you just type ``` flask run --host=0.0.0.0 --port=80 ```
I had to set `FLASK_RUN_PORT` in my environment to the specified port number. Next time you start your app, Flask will load that environment variable with the port number you selected.
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
So it's throwing up that error message because you have `apache2` running on port 80. If this is for development, I would just leave it as it is on port 5000. If it's for production either: **Not Recommended** * Stop `apache2` first; Not recommended as it states in the documentation: > > You can use the builtin ...
Your issue is, that you have an apache webserver already running that is already using port 80. So, you can either: 1. Kill apache: You should probably do this via `/etc/init.d/apache2 stop`, rather than simply killing them. 2. Deploy your flask app in your apache process, as [flask in apache](http://flask.pocoo.org/d...
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
A convinient way is using the package `python-dotenv`: It reads out a `.flaskenv` file where you can store environment variables for flask. * `pip install python-dotenv` * create a file `.flaskenv` in the root directory of your app Inside the file you specify: ``` FLASK_APP=application.py FLASK_RUN_HOST=localhost FL...
I had to set `FLASK_RUN_PORT` in my environment to the specified port number. Next time you start your app, Flask will load that environment variable with the port number you selected.
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
I had to set `FLASK_RUN_PORT` in my environment to the specified port number. Next time you start your app, Flask will load that environment variable with the port number you selected.
On my scenario the following steps worked like a charm: * Installing the package: ``` pip install --upgrade pip pip install python-dotenv ``` * Creating a hidden file in my app directory "flaskr/.flaskenv" * Adding the following content: ``` FLASK_APP=flaskr FLASK_RUN_HOST=localhost FLASK_RUN_PORT=8000 ``` * Final...
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
set the port with `app.run(port=80,debug=True)` you should set debug to true when on dev
I solved 2 times and solved it with 2 solution The first solution, follow these steps: 1 open cmd 2 run `ipconfig` at cmd 3 copy IPv4 Address from cmd 4 Use your IPv4 as the local host in the next: ``` app.run(debug=True, port=5000, host='localhost') ``` at replace 'localhost' with your IPv4 Address 5 for your...
20,212,894
I have a Flask server running through port 5000, and it's fine. I can access it at <http://example.com:5000> But is it possible to simply access it at <http://example.com>? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it. ``` Trac...
2013/11/26
[ "https://Stackoverflow.com/questions/20212894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3024025/" ]
This is the only solution that worked for me on Ubuntu-18. Inside the file `app.py` , use: ``` if __name__ == '__main__': app.run(host='0.0.0.0', port=80) ``` The code above will give the same permission error unless `sudo` is used to run it: ``` sudo python3 app.py ```
You don't need to change port number for your application, just configure your www server (nginx or apache) to proxy queries to flask port. Pay attantion on `uWSGI`.
70,241,576
This is a very weried situation, in vscode, I edited my code in the root directory and saved it as test\_distribution.py. After I run this file in vscode terminal. Everytime I edit and save this file, it gets run automatically. So I moved this file to the subfolder of this project, but I found out it still get run whe...
2021/12/06
[ "https://Stackoverflow.com/questions/70241576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14232877/" ]
I avoid this issue by adding ``` if __name__ == '__main': fun() ``` I guess this file will be import or load or something else, then it gets run. Anyway, this is not important.
Perhaps , You have mistakenly installed an extension 'Run on Save' . I think that's causing the Problem.
70,241,576
This is a very weried situation, in vscode, I edited my code in the root directory and saved it as test\_distribution.py. After I run this file in vscode terminal. Everytime I edit and save this file, it gets run automatically. So I moved this file to the subfolder of this project, but I found out it still get run whe...
2021/12/06
[ "https://Stackoverflow.com/questions/70241576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14232877/" ]
I have the same issue. It's now fixed. To do my test I used [pytest](https://docs.pytest.org/en/7.1.x/) and it was able to read my file when it started with `test_`. Because I'm stupid I named it a random filename `test_func.py` and in this one, I wrote "from main.py import \*". So when I saved, and used pytest to run ...
Perhaps , You have mistakenly installed an extension 'Run on Save' . I think that's causing the Problem.
70,241,576
This is a very weried situation, in vscode, I edited my code in the root directory and saved it as test\_distribution.py. After I run this file in vscode terminal. Everytime I edit and save this file, it gets run automatically. So I moved this file to the subfolder of this project, but I found out it still get run whe...
2021/12/06
[ "https://Stackoverflow.com/questions/70241576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14232877/" ]
I avoid this issue by adding ``` if __name__ == '__main': fun() ``` I guess this file will be import or load or something else, then it gets run. Anyway, this is not important.
I have the same issue. It's now fixed. To do my test I used [pytest](https://docs.pytest.org/en/7.1.x/) and it was able to read my file when it started with `test_`. Because I'm stupid I named it a random filename `test_func.py` and in this one, I wrote "from main.py import \*". So when I saved, and used pytest to run ...
4,170,532
I was not able to come up with a better title for this post, so if anybody does not find it appropriate , please go ahead and edit it. I am using flask as my python framework, and normally I render templates doing somnething like the below:- ``` @app.route('/home') def userhome(): data=go get user details from th...
2010/11/13
[ "https://Stackoverflow.com/questions/4170532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459514/" ]
I would choose server side templating, because unless you find a JS library that handles the same templating language your code isn't going go be DRY. In the `home.html` template, I'd do something like ``` <%extends base.html%> <%include _user_details.html%> ... <% footer and other stuff%> ``` And keep the actual m...
You have two options: template on the server, or template in the browser. To template in the server, you create an endpoint much like you already have, except the template only creates a portion of the page. Then you hit the URL with an Ajax call, and insert the returned HTML somewhere into your page. To template in ...
33,262,919
When writing doc strings in python, I am wondering if the docstring should contain the exceptions that are implicitly raised or if it should also contain the exceptions I explicitly raise. Consider the function ``` def inv(a): if a == 0: raise ZeroDivisionError else: return 1/a ``` So in a d...
2015/10/21
[ "https://Stackoverflow.com/questions/33262919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152563/" ]
It depends what (or whom) you're writing the docstring for. For automatic conversion to API documentation, I like [Google-style docstrings](http://sphinxcontrib-napoleon.readthedocs.org/en/latest/example_google.html), which would look like: ``` def inv(a): """Return the inverse of the argument. Arguments: ...
No. The docstring should describe the input expected. If this were my function, I would include something like this in the docstring: ``` """Return the inverse of an integer. ZeroDivisionError is raised if zero is passed to this function.""" ``` Therefore it is specified that the input should be an integer. Specify...
21,234,884
How can I set a suitable fps number in pygame for any kind of monitor running my game? I know I can set fps using `pygame.time.Clock().tick(fps)` but how can I set suitable fps? Please post example python code along with answer.
2014/01/20
[ "https://Stackoverflow.com/questions/21234884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2837388/" ]
I'm not entirely sure that I understand the question being asked, but I think you will just have to experiment with different numbers and find out what works for you. I find that around 50-100 is a good range. If what you are trying to do is make game events only update a certain number of times per second while rende...
The trick I've figured out is not limiting the frame rate, but calculating based on time. The pygame.time.Clock.tick() returns time in milliseconds, which you can then pass to other parts of the program to calculate events or animation updates. For example, I currently use a pair of variable in my Player object to sto...
58,449,314
When I activate my ipykernel\_py3 environment and try to launch Jupyter Lab in terminal, I get the repeated error messages as follows: ``` Macintosh-8:~ yuenfannie$ source activate ipykernel_py3 (ipykernel_py3) Macintosh-8:~ yuenfannie$ jupyter lab [I 12:38:19.969 LabApp] JupyterLab alpha preview extension loaded from...
2019/10/18
[ "https://Stackoverflow.com/questions/58449314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4632960/" ]
This is the wrong way round and can never be true, because you're asking for `tt` to be less than 2 and at least 12 at the same time: ``` if 2 >= tt >= 12: ``` You probably meant: ``` if 2 <= tt <= 12: ``` And instead of `elif` with a condition, you can just use `else`.
That is. ``` tt = int(input("What times tables would you like: ")) if 2 <= tt <= 12: for x in range(1, 13): aw = tt * x print(tt, "x", x, " = ", aw) else: print("Please enter number between 2 and 12") ```
27,948,420
I am getting confused trying to find a way to **send the left-click in a web browser window in a specific point**. I am using Selenium `selenium-2.44.0` and Python 2.7. My ultimate goal is to be able to click in certain areas in the window, but for now I just want to make sure I am able to click at all. I thought that ...
2015/01/14
[ "https://Stackoverflow.com/questions/27948420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3346915/" ]
Assuming there is nothing else going on on your page that would interfere with the click, this should do it: ``` homeLink = driver.find_element_by_link_text("Home") homeLink.click() #clicking on the Home button and mouse cursor should? stay here print homeLink.size, homeLink.location helpLink = driver.find_element_by...
Hard to say for you exact situation but I know a workaround to the question in the summary and bold > > send the left-click in a web browser window in a specific point > > > You just use execute\_script and do the clicking using javascript. ``` self.driver.execute_script('el = document.elementFromPoint(47, 457)...
18,701,464
I wanted to write a program to scrape a website from python. Since there is no built-in possibility to do so, I decided to give the BeautifulSoup module a try. Unfortunately I encountered some problems using pip and ez\_install, since I use Windows 7 64 bit and Python 3.3. Is there a way to get the BeautifulSoup modu...
2013/09/09
[ "https://Stackoverflow.com/questions/18701464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2733724/" ]
Just download [here](http://www.crummy.com/software/BeautifulSoup/bs3/download//) and then add the `BeautifulSoup.py (uncompress the download tarball file use uncompress soft such as 7z)` to your python sys.path use `sys.path.append("/path/to/BeautifulSoup.py")`, of cource you can just put it under your current src dir...
I haven't tried it, but check out [pip](https://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows) to install python packages. It's supposed to be better. [Why use pip over easy\_install](https://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install) I have personally used BeautifulSoup a...
18,701,464
I wanted to write a program to scrape a website from python. Since there is no built-in possibility to do so, I decided to give the BeautifulSoup module a try. Unfortunately I encountered some problems using pip and ez\_install, since I use Windows 7 64 bit and Python 3.3. Is there a way to get the BeautifulSoup modu...
2013/09/09
[ "https://Stackoverflow.com/questions/18701464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2733724/" ]
You just need to add to download it and add it to your python search path directly. (Which is in sys.path, if you need to check it.) From the documentation: Beautiful Soup is licensed under the MIT license, so you can also download the tarball, drop the bs4/ directory into almost any Python application (or into your l...
I haven't tried it, but check out [pip](https://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows) to install python packages. It's supposed to be better. [Why use pip over easy\_install](https://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install) I have personally used BeautifulSoup a...
41,525,223
I'm just trying to run the simple hello world app on their tutorials page. I used to use Google App Engine frequently, but now I can't seem to get it going at all. I'm on win 10 x64. Downloaded latest google cloud sdk, and python version 2.7.13 ``` > ERROR 2017-01-07 15:25:21,219 wsgi.py:263] Traceback (most recent...
2017/01/07
[ "https://Stackoverflow.com/questions/41525223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4769616/" ]
Google's sample Flask "Hello World" application requires `Flask 0.11.1`. This library is not vendored by Google, so developers are required to install it via `pip` > > This sample shows how to use Flask with Google App Engine Standard. > > > Before running or deploying this application, install the dependencies > ...
For me, the workaround mentioned here [Google's issue tracker](https://issuetracker.google.com/issues/38290292) worked * goto [sdk\_home]\google\appengine\tools\devappserver2\python\sandbox.py * find the definition of \_WHITE\_LIST\_C\_MODULES = [xxx] add following two lines to the list: '\_winreg', '\_ctypes', * t...
52,960,057
I have an assignment where we need to create functions to display text onto the screen in python/pygame. This part I understand. What I don't is that you're supposed to create a function which creates a drop shadow. I know how to make the shadow I just don't know how to make another function to do it and have the optio...
2018/10/24
[ "https://Stackoverflow.com/questions/52960057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10391389/" ]
A dropshadow can be rendered by drawing the text twice. The first is a grey version of the text at an offset, then the actual text at the original position. ``` def dropShadowText(screen, text, size, x, y, colour=(255,255,255), drop_colour=(128,128,128), font=None): # how much 'shadow distance' is best? dropsh...
I figured it out with help from Kingsley's response. Now you can choose to add a shadow or not, where its positioned and what colour it is. Maybe there is an easier way but this worked for me. ``` import pygame import sys pygame.init() screenSizeX = 1080 screenSizeY = 720 screenSize = (screenSizeX,screenSizeY) screen...
52,960,057
I have an assignment where we need to create functions to display text onto the screen in python/pygame. This part I understand. What I don't is that you're supposed to create a function which creates a drop shadow. I know how to make the shadow I just don't know how to make another function to do it and have the optio...
2018/10/24
[ "https://Stackoverflow.com/questions/52960057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10391389/" ]
A dropshadow can be rendered by drawing the text twice. The first is a grey version of the text at an offset, then the actual text at the original position. ``` def dropShadowText(screen, text, size, x, y, colour=(255,255,255), drop_colour=(128,128,128), font=None): # how much 'shadow distance' is best? dropsh...
If you want a transparent drop shadow, you have to: * Create a transparent [`pygame.Surface`](https://www.pygame.org/docs/ref/surface.html) large enough for the text and the shadow. The size of a text to be rendered can be determined with [`Font.size()`](https://www.pygame.org/docs/ref/font.html#pygame.font.Font.size)...
52,960,057
I have an assignment where we need to create functions to display text onto the screen in python/pygame. This part I understand. What I don't is that you're supposed to create a function which creates a drop shadow. I know how to make the shadow I just don't know how to make another function to do it and have the optio...
2018/10/24
[ "https://Stackoverflow.com/questions/52960057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10391389/" ]
I figured it out with help from Kingsley's response. Now you can choose to add a shadow or not, where its positioned and what colour it is. Maybe there is an easier way but this worked for me. ``` import pygame import sys pygame.init() screenSizeX = 1080 screenSizeY = 720 screenSize = (screenSizeX,screenSizeY) screen...
If you want a transparent drop shadow, you have to: * Create a transparent [`pygame.Surface`](https://www.pygame.org/docs/ref/surface.html) large enough for the text and the shadow. The size of a text to be rendered can be determined with [`Font.size()`](https://www.pygame.org/docs/ref/font.html#pygame.font.Font.size)...
18,718,715
I've been looking into scraping, and I cant manage to scrape twitter searches that date long way back by using python code, i can do it however with an addon for chrome but it falls short since it will only let me obtain a very limited amount of tweets. can anybody point me in the right direction¿
2013/09/10
[ "https://Stackoverflow.com/questions/18718715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2761466/" ]
I found a related answer here: <https://stackoverflow.com/a/6082633/1449045> you can get up to 1500 tweets for a search; 3200 for a particular user's timeline source: <https://dev.twitter.com/docs/things-every-developer-should-know> see "There are pagination limits" Here you can find a list of libraries to simplify...
You can use [snscrape](https://github.com/JustAnotherArchivist/snscrape). It doesn't require a Twitter Developer Account it can go back many years.
26,928,817
I will start by saying that I have never created an app that required installation and I have no idea how it works. But now I have to, and I am wondering how to proceed, use some kind os installation tools (installshield, wix) or create a python script and turn into an .exe. What my install needs to do is: * create a...
2014/11/14
[ "https://Stackoverflow.com/questions/26928817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2367912/" ]
I put this logic in my view's `form_valid` like so: ``` def form_valid(self, form): self.object, created = Car.objects.get_or_create( **form.cleaned_data ) return super(CarCreateView, self).form_valid(form) ``` To put that in context, I have a complaints case management system that registers new ...
Do it in form's `clean` method: ``` from django.forms import ModelForm from myapp.models import Car class CarForm(ModelForm): class Meta: model = Car def clean(self): if self._meta.model.objects.filter(**self.cleaned_data).count() > 0: raise forms.ValidationError('Car already exis...
52,138,300
I'm trying to write simple things in a Tkinter module using python 3.6 in Anaconda. This is my code ``` from tkinter import * root = Tk() thelabel = label(root, text="this is our tk window") thelabel.pack() root.mainloop() ``` but I get the error: ``` TclError: can't invoke "label" command: application has been...
2018/09/02
[ "https://Stackoverflow.com/questions/52138300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9784945/" ]
One of the recommended ways to have multiple python installations with differing libraries installed is to use [Virtualenv](https://virtualenv.pypa.io/en/stable/). This gives you the possibility to have a specific python environment with it's own set of dependencies for each project you work on. This works not only for...
I found this to work after searching for a while. Here are the steps I followed to install an older python version alongside my standard one: * Download the Python3.6 tgz file from the official website (eg. Python-3.6.6.tgz) * Unpack it with `tar -xvzf Python-3.6.6.tgz` * `cd Python-3.6.6` * run `./configure` * run `m...
27,751,072
I have an ordinary Python list that contains (multidimensional) numPy arrays, all of the same shape and with the same number of values. Some of the arrays in the list are duplicates of earlier ones. I have the problem that I want to remove all the duplicates, but the fact that the data type is numPy arrays complicates...
2015/01/03
[ "https://Stackoverflow.com/questions/27751072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1541913/" ]
Using the solutions here: [Most efficient property to hash for numpy array](https://stackoverflow.com/questions/16589791/most-efficient-property-to-hash-for-numpy-array) we see that hashing works best with a.tostring() if a is an numpy array. So: ``` import numpy as np arraylist = [np.array([1,2,3,4]), np.array([1,2,3...
Here is one way using `tuple`: ``` >>> import numpy as np >>> t = [np.asarray([1, 2, 3, 4]), np.asarray([1, 2, 3, 4]), np.asarray([1, 1, 3, 4])] >>> map(np.asarray, set(map(tuple, t))) [array([1, 1, 3, 4]), array([1, 2, 3, 4])] ``` If your arrays are multidimensional, then first flatten them to ...
27,751,072
I have an ordinary Python list that contains (multidimensional) numPy arrays, all of the same shape and with the same number of values. Some of the arrays in the list are duplicates of earlier ones. I have the problem that I want to remove all the duplicates, but the fact that the data type is numPy arrays complicates...
2015/01/03
[ "https://Stackoverflow.com/questions/27751072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1541913/" ]
Using the solutions here: [Most efficient property to hash for numpy array](https://stackoverflow.com/questions/16589791/most-efficient-property-to-hash-for-numpy-array) we see that hashing works best with a.tostring() if a is an numpy array. So: ``` import numpy as np arraylist = [np.array([1,2,3,4]), np.array([1,2,3...
Depending on the structure of your data, it may be quicker to directly compare all the arrays rather than finding some way to hash the arrays. The algorithm is O(n^2), but each individual comparison wil be much quicker than creating strings or python lists of your arrays. So it depends how many arrays you have to check...
27,751,072
I have an ordinary Python list that contains (multidimensional) numPy arrays, all of the same shape and with the same number of values. Some of the arrays in the list are duplicates of earlier ones. I have the problem that I want to remove all the duplicates, but the fact that the data type is numPy arrays complicates...
2015/01/03
[ "https://Stackoverflow.com/questions/27751072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1541913/" ]
Depending on the structure of your data, it may be quicker to directly compare all the arrays rather than finding some way to hash the arrays. The algorithm is O(n^2), but each individual comparison wil be much quicker than creating strings or python lists of your arrays. So it depends how many arrays you have to check...
Here is one way using `tuple`: ``` >>> import numpy as np >>> t = [np.asarray([1, 2, 3, 4]), np.asarray([1, 2, 3, 4]), np.asarray([1, 1, 3, 4])] >>> map(np.asarray, set(map(tuple, t))) [array([1, 1, 3, 4]), array([1, 2, 3, 4])] ``` If your arrays are multidimensional, then first flatten them to ...
36,278,220
I have a big third-party python2.7 application, a bunch of python scripts, which is added into `PATH` and it requires python2.7 instead of python 3.5 which I have by default. ``` $ python Python 3.5.1 (default, Mar 3 2016, 09:29:07) [GCC 5.3.0] on linux Type "help", "copyright", "credits" or "license" for more infor...
2016/03/29
[ "https://Stackoverflow.com/questions/36278220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1708058/" ]
My favorite way: use virtualenv or pyenv ======================================== The most used tool for keeping multiple Python environments is [virtualenv](https://virtualenv.pypa.io/en/latest/). I like to use a sugary wrapper around it called [virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/)...
You can make use of terminal alias. **The alias will not be temporary** but it will not affect your system, so you can have a short alias like: **alias pyt "/usr/bin/python2.7"** in your .bashrc file inside home directory
36,278,220
I have a big third-party python2.7 application, a bunch of python scripts, which is added into `PATH` and it requires python2.7 instead of python 3.5 which I have by default. ``` $ python Python 3.5.1 (default, Mar 3 2016, 09:29:07) [GCC 5.3.0] on linux Type "help", "copyright", "credits" or "license" for more infor...
2016/03/29
[ "https://Stackoverflow.com/questions/36278220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1708058/" ]
My favorite way: use virtualenv or pyenv ======================================== The most used tool for keeping multiple Python environments is [virtualenv](https://virtualenv.pypa.io/en/latest/). I like to use a sugary wrapper around it called [virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/)...
As the question is tagged with Linux, I assume your scripts starts with that line ``` #! /usr/bin/env python ``` This is great to allow the system to choose the current Python installation, but here your requirement is to specifically use version 2.7 So IMHO you just have to change the hashbang line to select the ...
36,278,220
I have a big third-party python2.7 application, a bunch of python scripts, which is added into `PATH` and it requires python2.7 instead of python 3.5 which I have by default. ``` $ python Python 3.5.1 (default, Mar 3 2016, 09:29:07) [GCC 5.3.0] on linux Type "help", "copyright", "credits" or "license" for more infor...
2016/03/29
[ "https://Stackoverflow.com/questions/36278220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1708058/" ]
My favorite way: use virtualenv or pyenv ======================================== The most used tool for keeping multiple Python environments is [virtualenv](https://virtualenv.pypa.io/en/latest/). I like to use a sugary wrapper around it called [virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/)...
If you are using Anaconda as your Python distribution, it has virtual enviroments built in. If not, use `virtualenv` and `virtualenvwrapper` as Paul recommended. In addition I recommend `autoenv`. With that you can automatically change your venv depending on the folder you're in. There is one for bash and one for zsh.
42,128,830
I am trying a simple demo code of tensorflow from [github link](https://github.com/llSourcell/tensorflow_demo). I'm currently using python version 3.5.2 ``` Z:\downloads\tensorflow_demo-master\tensorflow_demo-master>py Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32...
2017/02/09
[ "https://Stackoverflow.com/questions/42128830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6833276/" ]
The code link you have provided uses a separate file named `input_data.py` to download data from MNIST using the following two lines in `board.py` ``` import input_data mnist = input_data.read_data_sets("/tmp/data/",one_hot=True) ``` Since MNIST data is so frequently used for demonstration purposes, Tensorflow prov...
This file is likely corrupt: ``` Z:/downloads/MNIST dataset\train-images-idx3-ubyte.gz ``` Let's analyze the error you posted. This, indicates that code is currently working with the file in question: ``` Extracting Z:/downloads/MNIST dataset\train-images-idx3-ubyte.gz ``` `Traceback` indicates that a stack tra...
42,128,830
I am trying a simple demo code of tensorflow from [github link](https://github.com/llSourcell/tensorflow_demo). I'm currently using python version 3.5.2 ``` Z:\downloads\tensorflow_demo-master\tensorflow_demo-master>py Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32...
2017/02/09
[ "https://Stackoverflow.com/questions/42128830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6833276/" ]
you can modify the function: ``` def _read32(bytestream): dt = numpy.dtype(numpy.uint32).newbyteorder('>') return numpy.frombuffer(bytestream.read(4), dtype=dt) ``` new version: ``` def _read32(bytestream): dt = numpy.dtype(numpy.uint32).newbyteorder('>') return numpy.frombuffer(bytestream.read(4), ...
This file is likely corrupt: ``` Z:/downloads/MNIST dataset\train-images-idx3-ubyte.gz ``` Let's analyze the error you posted. This, indicates that code is currently working with the file in question: ``` Extracting Z:/downloads/MNIST dataset\train-images-idx3-ubyte.gz ``` `Traceback` indicates that a stack tra...
42,128,830
I am trying a simple demo code of tensorflow from [github link](https://github.com/llSourcell/tensorflow_demo). I'm currently using python version 3.5.2 ``` Z:\downloads\tensorflow_demo-master\tensorflow_demo-master>py Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32...
2017/02/09
[ "https://Stackoverflow.com/questions/42128830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6833276/" ]
you can modify the function: ``` def _read32(bytestream): dt = numpy.dtype(numpy.uint32).newbyteorder('>') return numpy.frombuffer(bytestream.read(4), dtype=dt) ``` new version: ``` def _read32(bytestream): dt = numpy.dtype(numpy.uint32).newbyteorder('>') return numpy.frombuffer(bytestream.read(4), ...
The code link you have provided uses a separate file named `input_data.py` to download data from MNIST using the following two lines in `board.py` ``` import input_data mnist = input_data.read_data_sets("/tmp/data/",one_hot=True) ``` Since MNIST data is so frequently used for demonstration purposes, Tensorflow prov...
64,785,224
How can I remove keys from python dictionary of dictionaries based on some conditions? Example dictionary: ``` a = { 'k': 'abc', 'r': 20, 'c': { 'd': 'pppq', 'e': 22, 'g': 75 }, 'f': ''} ``` I want to remove all entries whose values are type of string. It can contain dictionar...
2020/11/11
[ "https://Stackoverflow.com/questions/64785224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3056288/" ]
You could do: ``` a = { 'k': 'abc', 'r': 20, 'c': { 'd': 'pppq', 'e': 22, 'g': 75 }, 'f': ''} def remove_string_values(d): result = {} for k, v in d.items(): if not isinstance(v, str): result[k] = remove_string_values(v) if isinstance(v, dict) el...
Something like this should work: ``` def remove_strings(a): no_strings = {} for k,v in a.items(): if type(x) is str: continue elif type(x) is dict: no_strings[k] = remove_strings(v) else: no_strings[k] = v ``` This function is recursive - it calls ...
12,006,267
So I can create Django model like this: ``` from django.db import models class Something(models.Model): title = models.TextField(max_length=200) ``` and I can work with it like this: ``` thing = Something() #set title thing.title = "First thing" #get title thing.title ``` All works as it should but I'd like ...
2012/08/17
[ "https://Stackoverflow.com/questions/12006267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3272/" ]
I think its hard to beat what Django documentation has to [say on this](https://code.djangoproject.com/wiki/DevModelCreation). > > The Model class (see base.py) has a **metaclass** attribute that defines ModelBase (also in base.py) as the class to use for creating new classes. So ModelBase.**new** is called to creat...
python is extremely powerfull and permit the developer to use intrespection. django use a lot of metaclass. and it seem that models.Model use it too. see in django\db\models\base.py ``` class Model(object): __metaclass__ = ModelBase ``` i think the metaclass just take the classes attributes such a the Field an...
64,694,569
aws cdk returns jsii error on empty stack. Steps to reproduce are at the hello world level which makes me think that I have a version mismatch somewhere. I have re-installed aws cli, cdk and nodejs. Any suggestions on what to look for? Steps to reproduce: ``` mkdir myfolder cdk init --language python .env\Scripts\act...
2020/11/05
[ "https://Stackoverflow.com/questions/64694569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14582438/" ]
For AWS-CDK on Windows, there is at least one bug in jsii documented by AWS CDK group. Deep inside the jsiiruntime (line 13278 to be exact), aws cdk group has a comment with a link to a nodejs bug report. I reported my problem to aws-cdk which seemed to be related. They reproduced the bug and created a bug report at no...
TL;DR. Expanded work arounds. (A question was asked in the AWS-CDK bug report noted above). **Workaround 1: replace jsii 1.14.x distro** ***Distro folders:*** jsii is contained in 2 folders jsii and jsii-1.14.1.dist-info REPLACE both of these folders with folders from an older install -- 1.12 or 1.13. The distro f...
11,661,053
I am running Windows 7 currently, and I remember when using Linux at the school computers I was able to type "gedit &" into the terminal for example to open up the gedit text editor. I was wondering whether there is a similar process to open IDLE, and for that matter a Python program/script by typing it into the "termi...
2012/07/26
[ "https://Stackoverflow.com/questions/11661053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1553212/" ]
python.exe is the Python interpreter. All of your Python programs are executed with it. If you run it in the console, you will get an interactive prompt: ``` C:\> python Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more infor...
python.exe **is** Python, the python interpreter specifically.
11,661,053
I am running Windows 7 currently, and I remember when using Linux at the school computers I was able to type "gedit &" into the terminal for example to open up the gedit text editor. I was wondering whether there is a similar process to open IDLE, and for that matter a Python program/script by typing it into the "termi...
2012/07/26
[ "https://Stackoverflow.com/questions/11661053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1553212/" ]
python.exe is the Python interpreter. All of your Python programs are executed with it. If you run it in the console, you will get an interactive prompt: ``` C:\> python Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more infor...
Yes you can start libraries like Idle, you need to import idlelib: ``` import idlelib.idle ``` Alternatively, to start idle from terminal without getting into python.exe shell first, you can do python.exe -m idlelib.idle assuming that idlelib is in your PYTHONPATH The python.exe, is just like the shell in IDLE, is ...
11,661,053
I am running Windows 7 currently, and I remember when using Linux at the school computers I was able to type "gedit &" into the terminal for example to open up the gedit text editor. I was wondering whether there is a similar process to open IDLE, and for that matter a Python program/script by typing it into the "termi...
2012/07/26
[ "https://Stackoverflow.com/questions/11661053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1553212/" ]
Yes you can start libraries like Idle, you need to import idlelib: ``` import idlelib.idle ``` Alternatively, to start idle from terminal without getting into python.exe shell first, you can do python.exe -m idlelib.idle assuming that idlelib is in your PYTHONPATH The python.exe, is just like the shell in IDLE, is ...
python.exe **is** Python, the python interpreter specifically.
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
The `b` inside `func_1()` is local to the function and not available outside of the function. You need to *assign* the returned value of the function `func_1()` to a variable name in the main body. ``` b = func_1() print b ```
> > I am 'expecting' b to be available after the function call, as I have returned it > > > The fundamental misunderstanding: you aren't returning a variable, you're returning a value. Variables are labels (names) for values. Inside the function, you have a name `b` for a value `"foo"`. You use this name to refer ...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
I think this is what you want to do: ``` a = "foo" def func_1(): b = "bar" print a,b return b # Took out parenthasis returned_b = func_1() # Added variable to hold the returned "b" print returned_b ``` It looks like you are just learning to code in general. Your issues look to be with understanding how comp...
> > I am 'expecting' b to be available after the function call, as I have returned it > > > The fundamental misunderstanding: you aren't returning a variable, you're returning a value. Variables are labels (names) for values. Inside the function, you have a name `b` for a value `"foo"`. You use this name to refer ...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
I think this is what you want to do: ``` a = "foo" def func_1(): b = "bar" print a,b return b # Took out parenthasis returned_b = func_1() # Added variable to hold the returned "b" print returned_b ``` It looks like you are just learning to code in general. Your issues look to be with understanding how comp...
Function calls are expressions. Like any expression they have a value. If you don't assign the value to anything, it is lost. ``` def add(a, b): result = a + b return result four = add(2, 2) ``` Any local variables of the function (like `a`, `b` and `result` in above case) aren't visible outside of the func...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
I think you mean, how do I access values that I return from a function. Say you have a function: ``` def func_1(): b = 1 return b ``` If you want the return value from that function, set some variable equal to it, like so: ``` someVariable = func_1() #func_1 executes it's code, and returns the value contai...
> > I am 'expecting' b to be available after the function call, as I have returned it > > > The fundamental misunderstanding: you aren't returning a variable, you're returning a value. Variables are labels (names) for values. Inside the function, you have a name `b` for a value `"foo"`. You use this name to refer ...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
I think this is what you want to do: ``` a = "foo" def func_1(): b = "bar" print a,b return b # Took out parenthasis returned_b = func_1() # Added variable to hold the returned "b" print returned_b ``` It looks like you are just learning to code in general. Your issues look to be with understanding how comp...
Here is your example modified: ``` a = "foo" def func_1(): b = "bar" print a,b return b b = func_1() print b ``` `b` inside the function is a local variable, so it's not available outside of the function, but since you return it, you can assign the returned value to a new variable (which I also called `b...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
You've returned it, but not assigned it to anything: ``` def func_1(): b = "bar" a = 2 return a, b a, b = func_1() print b ```
> > I am 'expecting' b to be available after the function call, as I have returned it > > > The fundamental misunderstanding: you aren't returning a variable, you're returning a value. Variables are labels (names) for values. Inside the function, you have a name `b` for a value `"foo"`. You use this name to refer ...
9,353,457
As I muddle my way through trying to learn how to code (in python) I've hit the same problem I hit frequently. How do you pass variables to and from functions properly. In this example, I want to create a new variable inside the function process, but I don't know how to get it back properly (this method does not wo...
2012/02/19
[ "https://Stackoverflow.com/questions/9353457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191626/" ]
Function calls are expressions. Like any expression they have a value. If you don't assign the value to anything, it is lost. ``` def add(a, b): result = a + b return result four = add(2, 2) ``` Any local variables of the function (like `a`, `b` and `result` in above case) aren't visible outside of the func...
> > I am 'expecting' b to be available after the function call, as I have returned it > > > The fundamental misunderstanding: you aren't returning a variable, you're returning a value. Variables are labels (names) for values. Inside the function, you have a name `b` for a value `"foo"`. You use this name to refer ...