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,029,068
I want to be able to execute the following code: ``` import numpy z=numpy.zeros(4) k="z[i-1]" for i in range(len(b)): z[i]=k ``` Which should return the same output as: ``` z=numpy.zeros(4) for i in range(6): z[i]=z[i-1] ``` If I execute the first code block, I get an expected error message: ``` File "...
2016/08/18
[ "https://Stackoverflow.com/questions/39029068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5510581/" ]
Other then `eval` which is highly discouraged in production code, You can just as easily define a function that returns a specific item based on the array and index: ``` def k(arr,idx): return arr[idx-1] for i in range(len(b)): z[i]= k(z,i) ``` If this rule needs to be applied in various spots in your code t...
Do it as following: ``` import numpy z=numpy.zeros(4) k="z[i-1]" for i in range(len(b)): z[i]=eval(k) ``` But note eval can be a security problem: <http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html>
36,716,304
Im stuck with this very simple code were I'm trying to create a function that takes a parameter and adds 1 to the result and returns it but somehow this code gives me no results. (I've called the function to see if it works.) Somebody please help me since I'm very new to python :) ``` def increment(num): num += 1...
2016/04/19
[ "https://Stackoverflow.com/questions/36716304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6123798/" ]
Basics: `array[slice(a,b,c)]` is equivalent to `array[a:b:c]`, and to reverse ("flip") an array use `slice(None, None, -1)`, which is the same as `array[::-1]`. So let's build the random flips for each image: ``` >>> import random >> flips = [(slice(None, None, None), ... slice(None, None, random.choice([-1,...
Thanks to the [awesome answer of @BlackBear](https://stackoverflow.com/a/36716579/3250126), I was able to get starting. I noticed, however, such functionality would probably run very often and thus might benefit from some performance tweaks. In thinking of how to improve the performance I tackled two things: 1. use a...
48,789,294
I have a file that contains the raw data for an array of 32-bit floats. I would like to read this data and resemble it to floats and store them in a list. [![enter image description here](https://i.stack.imgur.com/1p1J9.jpg)](https://i.stack.imgur.com/1p1J9.jpg) How can I do this using python? Note: The data origina...
2018/02/14
[ "https://Stackoverflow.com/questions/48789294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1235291/" ]
The standard `struct` module is good for dealing with packed binary data like this. Here's a quick example: ``` dataFromFile = "\x67\x66\x1e\x41\x01\x00\x30\x41" # an excerpt from your data import struct numFloats = len(dataFromFile) // 4 # Try decoding it as little-endian print(struct.unpack("<" + "f" * numFloats...
you can read it the file, store it in a string then parse the string and convert to float: ``` with open(“testfile.txt”) as file: data = file.read() values = data.split(" ") floatValues = [float(x) for x in values] ``` or you can use some parser from the numpy module or the csv reading files modules
54,073,810
I was trying to get data(a list) from a file and assign this list to my python script list. I want to know how to do it without having to assign all varibles manually ``` Variables = [MPDev,WDev,DDev,LDev,PDev,MPAll,WAll,DAll,LAll,PAll,MPBlit,WBlit,DBlit,LBlit,PBlit,MPCour,WCour,DCour,LCour,PCour] dataupdate = open("...
2019/01/07
[ "https://Stackoverflow.com/questions/54073810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10236621/" ]
Get used to using data as a pandas dataframe. It's easy to read, easy to write. <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html> ``` import pandas as pd data = pd.read_csv("griddata.txt", names = ['MPDev', 'WDev', 'DDev', 'LDev', 'PDev', 'MPAll', 'WAll', 'DAll', 'LAll', 'PAll', 'M...
``` import ast Variables = [MPDev,WDev,DDev,LDev,PDev,MPAll,WAll,DAll,LAll,PAll,MPBlit,WBlit,DBlit,LBlit,PBlit,MPCour,WCour,DCour,LCour,PCour] dataupdate = open("tmp.txt","r") datalist = ast.literal_eval(dataupdate.read()) #Inside the file is written: #['0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'...
54,073,810
I was trying to get data(a list) from a file and assign this list to my python script list. I want to know how to do it without having to assign all varibles manually ``` Variables = [MPDev,WDev,DDev,LDev,PDev,MPAll,WAll,DAll,LAll,PAll,MPBlit,WBlit,DBlit,LBlit,PBlit,MPCour,WCour,DCour,LCour,PCour] dataupdate = open("...
2019/01/07
[ "https://Stackoverflow.com/questions/54073810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10236621/" ]
Get used to using data as a pandas dataframe. It's easy to read, easy to write. <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html> ``` import pandas as pd data = pd.read_csv("griddata.txt", names = ['MPDev', 'WDev', 'DDev', 'LDev', 'PDev', 'MPAll', 'WAll', 'DAll', 'LAll', 'PAll', 'M...
Another alternative is using dictionary. `mydict={} var = 0 for e in Variables: mydict[e]=datalist[var] var += 1`
58,869,851
I have an issue in using python with matrix multiplication and reshape. for example, I have a column `S` of size `(16,1)` and another matrix `H` of size `(4,4)`, I need to reshape the column `S` into `(4,4)` in order to multiply it with `H` and then reshape it again into `(16,1)`, I did that in matlab as below: ``` c...
2019/11/15
[ "https://Stackoverflow.com/questions/58869851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11082042/" ]
Simply do this: ``` S.shape = (4,4) for ij in range(16): y[:,:,ij] = H[:,:,ij] @ S S.shape = -1 # equivalent to 16 ```
There are two issues in your solution 1) reshape method takes a shape in the form of a single tuple argument, but not multiple arguments. 2) The shape of your y-array should be 16x1x16, not 4x4x16. In Matlab, there is no issue since it automatically reshapes `y` as you update it. The correct version would be the fol...
58,869,851
I have an issue in using python with matrix multiplication and reshape. for example, I have a column `S` of size `(16,1)` and another matrix `H` of size `(4,4)`, I need to reshape the column `S` into `(4,4)` in order to multiply it with `H` and then reshape it again into `(16,1)`, I did that in matlab as below: ``` c...
2019/11/15
[ "https://Stackoverflow.com/questions/58869851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11082042/" ]
Simply do this: ``` S.shape = (4,4) for ij in range(16): y[:,:,ij] = H[:,:,ij] @ S S.shape = -1 # equivalent to 16 ```
[`np.dot`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html) operates over the last and second-to-last axis of the two operands if they have two or more axes. You can move your axes around to use this. Keep in mind that `reshape(S, 4, 4)` in Matlab is likely equivalent to `S.reshape(4, 4).T` in Pyth...
58,869,851
I have an issue in using python with matrix multiplication and reshape. for example, I have a column `S` of size `(16,1)` and another matrix `H` of size `(4,4)`, I need to reshape the column `S` into `(4,4)` in order to multiply it with `H` and then reshape it again into `(16,1)`, I did that in matlab as below: ``` c...
2019/11/15
[ "https://Stackoverflow.com/questions/58869851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11082042/" ]
[`np.dot`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html) operates over the last and second-to-last axis of the two operands if they have two or more axes. You can move your axes around to use this. Keep in mind that `reshape(S, 4, 4)` in Matlab is likely equivalent to `S.reshape(4, 4).T` in Pyth...
There are two issues in your solution 1) reshape method takes a shape in the form of a single tuple argument, but not multiple arguments. 2) The shape of your y-array should be 16x1x16, not 4x4x16. In Matlab, there is no issue since it automatically reshapes `y` as you update it. The correct version would be the fol...
31,092,802
To install dependences, the [appengine-python-flask-skeleton docs](https://github.com/GoogleCloudPlatform/appengine-python-flask-skeleton) advise running this command: ``` pip install -r requirements.txt -t lib ``` That works simply enough. Now say I want to add the [Requests package](http://docs.python-requests.or...
2015/06/27
[ "https://Stackoverflow.com/questions/31092802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1093087/" ]
Like said, updating pip solves the issue for many, but for what it's worth I think you can get around all of this if the use of [virtualenv](https://virtualenv.pypa.io/en/latest/) is an option. Symlink `/path/to/virtualenv's/sitepackages/` to `lib/` and just always keep an up to date `requirements.txt` file. There are ...
Upgrading to the latest version of pip solved my problem (that issue had been closed): ``` pip install -U pip ``` Otherwise, as noted in that thread, you can always just wipe out your `lib` directory and reinstall from scratch. One note of warning: if you manually added additional packages to the `lib` directory not...
54,484,627
I want to monitor EC2 by using CloudWatch-SNS-lambda (python)-SNS-Email. When I testing my python code, i find out that CW alarm "Message" contain escape processing that i cant get specific value from "Message". I check the format of the alarm with code below. ``` from __future__ import print_function import json im...
2019/02/01
[ "https://Stackoverflow.com/questions/54484627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11002216/" ]
The `Message` is a JSON string. You need to convert it to a Python dictionary first. Then, you can access its properties easily. ```py Messagebody = event['Records'][0]['Sns']['Message'] message_dict = json.loads(Messagebody) metric_name = message_dict['Trigger']['MetricName'] ```
To remove the escape-processing, you should do the following: > > MessageBody = event['Records'][0]['Sns']['Message'] > > > MessageBody = json.loads(MessageBody) > > > Then to access the Metric Name, you can do: > > MetricName= event['Records'][0]['Sns']['Message']['Trigger']['MetricName'] > > >
37,991,717
Can anyone help me on a Python reverse shell one-liner for Windows (has to be windows one-liner). I am trying to modify the one for Linux which I have used many times but this is my first time for Windows. Linux one liner : ``` python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM...
2016/06/23
[ "https://Stackoverflow.com/questions/37991717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/803649/" ]
(@rockstar: I think you and I are studying the same thing!) Not a one liner, but learning from David Cullen's answer, I put together this reverse shell for Windows. ``` import os,socket,subprocess,threading; def s2p(s, p): while True: data = s.recv(1024) if len(data) > 0: p.stdin.write...
From the [documentation](https://docs.python.org/2/library/socket.html#socket.socket.fileno) for `socket.fileno()`: > > Under Windows the small integer returned by this method cannot be used where a file descriptor can be used (such as os.fdopen()). Unix does not have this limitation. > > > I do not think you can...
37,991,717
Can anyone help me on a Python reverse shell one-liner for Windows (has to be windows one-liner). I am trying to modify the one for Linux which I have used many times but this is my first time for Windows. Linux one liner : ``` python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM...
2016/06/23
[ "https://Stackoverflow.com/questions/37991717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/803649/" ]
From the [documentation](https://docs.python.org/2/library/socket.html#socket.socket.fileno) for `socket.fileno()`: > > Under Windows the small integer returned by this method cannot be used where a file descriptor can be used (such as os.fdopen()). Unix does not have this limitation. > > > I do not think you can...
Based on Mark E. Haase's answer, here is my improved version [645 Chars] which: * is smaller (threads are now one-liners and as many statements as possible on one line) * does not open a new command window (`shell=True`) * supports universal newlines (`text=True`) * waits for the remote host to come online if it's not...
37,991,717
Can anyone help me on a Python reverse shell one-liner for Windows (has to be windows one-liner). I am trying to modify the one for Linux which I have used many times but this is my first time for Windows. Linux one liner : ``` python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM...
2016/06/23
[ "https://Stackoverflow.com/questions/37991717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/803649/" ]
(@rockstar: I think you and I are studying the same thing!) Not a one liner, but learning from David Cullen's answer, I put together this reverse shell for Windows. ``` import os,socket,subprocess,threading; def s2p(s, p): while True: data = s.recv(1024) if len(data) > 0: p.stdin.write...
Depending on how you deploy the one liner, you may need to specify the path to python.exe as illustrated in the following code. I hope this help. ```html C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('10.11.0.37', 4444)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (la...
37,991,717
Can anyone help me on a Python reverse shell one-liner for Windows (has to be windows one-liner). I am trying to modify the one for Linux which I have used many times but this is my first time for Windows. Linux one liner : ``` python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM...
2016/06/23
[ "https://Stackoverflow.com/questions/37991717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/803649/" ]
(@rockstar: I think you and I are studying the same thing!) Not a one liner, but learning from David Cullen's answer, I put together this reverse shell for Windows. ``` import os,socket,subprocess,threading; def s2p(s, p): while True: data = s.recv(1024) if len(data) > 0: p.stdin.write...
Based on Mark E. Haase's answer, here is my improved version [645 Chars] which: * is smaller (threads are now one-liners and as many statements as possible on one line) * does not open a new command window (`shell=True`) * supports universal newlines (`text=True`) * waits for the remote host to come online if it's not...
37,991,717
Can anyone help me on a Python reverse shell one-liner for Windows (has to be windows one-liner). I am trying to modify the one for Linux which I have used many times but this is my first time for Windows. Linux one liner : ``` python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM...
2016/06/23
[ "https://Stackoverflow.com/questions/37991717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/803649/" ]
Depending on how you deploy the one liner, you may need to specify the path to python.exe as illustrated in the following code. I hope this help. ```html C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('10.11.0.37', 4444)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (la...
Based on Mark E. Haase's answer, here is my improved version [645 Chars] which: * is smaller (threads are now one-liners and as many statements as possible on one line) * does not open a new command window (`shell=True`) * supports universal newlines (`text=True`) * waits for the remote host to come online if it's not...
50,100,629
When I try to run buildout for a existing project, which used to work perfectly fine, it now installs the incorrect version of Django, even though the version is pinned. For some reason, it's installing Django 1.10 even though I've got 1.6 pinned. (I know that's an old version, but client doesn't want me to upgrade ju...
2018/04/30
[ "https://Stackoverflow.com/questions/50100629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433267/" ]
The reason it wasn't working is because the `[versions]` part cannot be extended
Pip can install a specific version of library using pip, you can try: pip install django==1.6.1
15,114,329
How do I save an open excel file using python= I currently read the excel workbook using XLRD but I need to save the excel file so any changes the user inputs are read. I have done this using a VBA script from within excel which saves the workbook every x seconds, but this is not ideal.
2013/02/27
[ "https://Stackoverflow.com/questions/15114329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2040544/" ]
This works on API level 10 for expanding ActionView e.g. SearchView ``` MenuItemCompat.expandActionView(mSearchMenuItem); ```
You always have the option of differentiating your solution depending on the current running version: ``` int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { // pre honeycomb } else { // honeycomb and post } ``` I know this might not be exactly what you are looking for bu...
15,114,329
How do I save an open excel file using python= I currently read the excel workbook using XLRD but I need to save the excel file so any changes the user inputs are read. I have done this using a VBA script from within excel which saves the workbook every x seconds, but this is not ideal.
2013/02/27
[ "https://Stackoverflow.com/questions/15114329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2040544/" ]
This works on API level 10 for expanding ActionView e.g. SearchView ``` MenuItemCompat.expandActionView(mSearchMenuItem); ```
You can use MenuItemCompat static methods. Example: ``` @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem menuItem = menu.findItem(R.id.action_search); MenuItemCompat.expandActionView(menuItem); SearchView searchView = (SearchView)...
29,418,572
I am learning python and am stuck on a tutorial which as far as the guide goes should be working but isn't, i have seen similar questions asked but cant understand how they apply to the code i am following, the code fails at the end of the last line. ``` import os import time source = ["'C:\Users\Administrator\myfile...
2015/04/02
[ "https://Stackoverflow.com/questions/29418572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4707947/" ]
`target_dir` should not be created with brackets. ``` target_dir = 'C:\Users\Administrator\myfile' target = target_dir + os.sep + \ time.strftime('%Y%m%d%H%M%S') + '.zip' ``` --- Incidentally, take care with your backslashes, because they are also used to signify special characters in a string. For exampl...
target\_dir is a list, so in your example you need to do: ``` target = target_dir[0] + os.sep + \ time.strftime('%Y%m%dT%H%M%S') + '.zip' ``` You see that error because you are trying to add a list (target\_list) and strings together, apples and oranges.
29,418,572
I am learning python and am stuck on a tutorial which as far as the guide goes should be working but isn't, i have seen similar questions asked but cant understand how they apply to the code i am following, the code fails at the end of the last line. ``` import os import time source = ["'C:\Users\Administrator\myfile...
2015/04/02
[ "https://Stackoverflow.com/questions/29418572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4707947/" ]
`target_dir` should not be created with brackets. ``` target_dir = 'C:\Users\Administrator\myfile' target = target_dir + os.sep + \ time.strftime('%Y%m%d%H%M%S') + '.zip' ``` --- Incidentally, take care with your backslashes, because they are also used to signify special characters in a string. For exampl...
You should use `os.path.join()` so that the correct platform-specific directory separator will always be used ``` import os import time source = "C:\Users\Administrator\myfile\myfile 1" target_dir = "C:\Users\Administrator\myfile" target = os.path.join(target_dir, time.strftime('%Y%m%d%H%M%S') + '.zip') ```
56,251,211
I have a spark DataFrame consisting of 3 columns: `text1`, `text2` and `number`. I want to filter this DataFrame based on the following constraint: ```python (len(text1)+len(text2))>number ``` where `len` returns the number of words in `text1` or in `text2`. I tried the following: ```python common_df = common_df...
2019/05/22
[ "https://Stackoverflow.com/questions/56251211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11205562/" ]
[`pyspark.sql.functions.length()`](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.functions.length) returns the character length of a string. If you want to count the words, you can use [`split()`](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.functions.split) ...
You can use `length` from `pyspark.sql.functions`: ``` common_df[(F.length('text1') + F.length('text2')) > common_df['number']] ``` Note that `[]` is a substitute for `filter()`.
56,251,211
I have a spark DataFrame consisting of 3 columns: `text1`, `text2` and `number`. I want to filter this DataFrame based on the following constraint: ```python (len(text1)+len(text2))>number ``` where `len` returns the number of words in `text1` or in `text2`. I tried the following: ```python common_df = common_df...
2019/05/22
[ "https://Stackoverflow.com/questions/56251211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11205562/" ]
[`pyspark.sql.functions.length()`](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.functions.length) returns the character length of a string. If you want to count the words, you can use [`split()`](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.functions.split) ...
You are almost close, try this - ``` from pyspark.sql.functions import length common_df.filter("(length(text1) + length(text2)) > number").show() ```
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
In my case I was obliged to leave the venv (deactivate), remove pytest (pip uninstall pytest), enter the venv (source /my/path/to/venv), and then reinstall pytest (pip install pytest). I don't known exacttly why pip refuse to install pytest in venv (it says it already present). I hope this helps
you have to activate your python env every time you want to run your python script, you have several ways to activate it, we assume that your virtualenv is installed under /home/venv : 1- the based one is to run the python with one command line `>>> /home/venv/bin/python <your python file.py>` 2- add this line on th...
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
Inside your environment, you may try ``` python -m pytest ```
you have to activate your python env every time you want to run your python script, you have several ways to activate it, we assume that your virtualenv is installed under /home/venv : 1- the based one is to run the python with one command line `>>> /home/venv/bin/python <your python file.py>` 2- add this line on th...
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
There is a bit of a dance to get this to work: 1. activate your venv : `source venv/bin/activate` 2. install pytest : `pip install pytest` 3. re-activate your venv: `deactivate && source venv/bin/activate` The reason is that the path to `pytest` is set by the `source`ing the `activate` file only after `pytest` is act...
you have to activate your python env every time you want to run your python script, you have several ways to activate it, we assume that your virtualenv is installed under /home/venv : 1- the based one is to run the python with one command line `>>> /home/venv/bin/python <your python file.py>` 2- add this line on th...
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
Inside your environment, you may try ``` python -m pytest ```
In my case I was obliged to leave the venv (deactivate), remove pytest (pip uninstall pytest), enter the venv (source /my/path/to/venv), and then reinstall pytest (pip install pytest). I don't known exacttly why pip refuse to install pytest in venv (it says it already present). I hope this helps
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
There is a bit of a dance to get this to work: 1. activate your venv : `source venv/bin/activate` 2. install pytest : `pip install pytest` 3. re-activate your venv: `deactivate && source venv/bin/activate` The reason is that the path to `pytest` is set by the `source`ing the `activate` file only after `pytest` is act...
In my case I was obliged to leave the venv (deactivate), remove pytest (pip uninstall pytest), enter the venv (source /my/path/to/venv), and then reinstall pytest (pip install pytest). I don't known exacttly why pip refuse to install pytest in venv (it says it already present). I hope this helps
35,045,038
I installed `pytest` into a virtual environment (using `virtualenv`) and am running it from that virtual environment, but it is not using the packages that I installed in that virtual environment. Instead, it is using the main system packages. (Using `python -m unittest discover`, I can actually run my tests with the r...
2016/01/27
[ "https://Stackoverflow.com/questions/35045038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4770429/" ]
There is a bit of a dance to get this to work: 1. activate your venv : `source venv/bin/activate` 2. install pytest : `pip install pytest` 3. re-activate your venv: `deactivate && source venv/bin/activate` The reason is that the path to `pytest` is set by the `source`ing the `activate` file only after `pytest` is act...
Inside your environment, you may try ``` python -m pytest ```
14,279,560
> > **Possible Duplicate:** > > [Is it possible to change the Environment of a parent process in python?](https://stackoverflow.com/questions/263005/is-it-possible-to-change-the-environment-of-a-parent-process-in-python) > > > I am using python 2.4.3. I tried to set my http\_proxy variable. Please see the belo...
2013/01/11
[ "https://Stackoverflow.com/questions/14279560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1970157/" ]
When you run this code, you set the environment variables, its working scope is only within the process. After you exit (exit the interactive mode of python), these environment will be disappear. As your code "os.system("echo $http\_proxy")" indicates, if you want to use these environment variables, you need run exter...
environment variables are not a "global database of settings"; setting the environment here doesn't have any effect there. the exception to this is that programs which invoke other programs can provide a different environment to their child programs. At the shell, when you type ``` [~/]$ FOO=bar baz ``` you're te...
40,009,858
I have a file called fName.txt in a directory. Running the following Python snippet would add 6 numbers into 3 rows and 2 columns into the text file through executing the loop (containing the snippet) three times. However, I would like to empty the file completely before writing new data into it. (Otherwise running th...
2016/10/12
[ "https://Stackoverflow.com/questions/40009858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6407935/" ]
You are using 'append' mode (`'a'`) to open your file. When this mode is specified, new text is appended to the existing file content. You're looking for the 'write' mode, that is `open(filename, 'w')`. This will override the file contents every time you **open** it.
Using mode 'w' is able to delete the content of the file and overwrite the file but prevents the loop containing the above snippet from printing two more times to produce two more rows of data. In other words, using 'w' mode is not compatible with the code I have given the fact that it is supposed to print into the fil...
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
To solve this problem, I uninstalled my existing python 3.7 and anaconda. I re-installed anaconda *with one key difference.* I registered Anaconda as my default Python 3.7 during the Anaconda installation. This lets visual studio, PyDev and other programs automatically detect Anaconda as the primary version to use.
I tried to import fbprophet on Python Anaconda, however, I got some errors. This code works for me.. ``` conda install -c conda-forge/label/cf201901 fbprophet ```
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
To solve this problem, I uninstalled my existing python 3.7 and anaconda. I re-installed anaconda *with one key difference.* I registered Anaconda as my default Python 3.7 during the Anaconda installation. This lets visual studio, PyDev and other programs automatically detect Anaconda as the primary version to use.
(Short n Sweet) For Mac users : ------------------------------- 1. pip3 uninstall pystan 2. pip3 install pystan==2.17.1.0 3. pip3 install fbprophet
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
Use: The first step is to remove pystan and cache: ``` pip uninstall fbprophet pystan pip --no-cache-dir install pystan==2.17 #any version pip --no-cache-dir install fbprophet==0.2 #any version conda install Cython --force pip install pystan conda install pystan -c conda-forge conda install -c conda-forge fbprophet ...
(Short n Sweet) For Mac users : ------------------------------- 1. pip3 uninstall pystan 2. pip3 install pystan==2.17.1.0 3. pip3 install fbprophet
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
Use: The first step is to remove pystan and cache: ``` pip uninstall fbprophet pystan pip --no-cache-dir install pystan==2.17 #any version pip --no-cache-dir install fbprophet==0.2 #any version conda install Cython --force pip install pystan conda install pystan -c conda-forge conda install -c conda-forge fbprophet ...
I tried to import fbprophet on Python Anaconda, however, I got some errors. This code works for me.. ``` conda install -c conda-forge/label/cf201901 fbprophet ```
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
I used the following steps to install fbprophet 0.7.1 on windows 10 (2022-03-10): 1. Install anaconda [here](https://www.anaconda.com/products/individual#windows). 2. Install pystan by following this [guide](https://pystan2.readthedocs.io/en/latest/windows.html). The main line I used was `conda install libpython m2w64...
[![enter image description here](https://i.stack.imgur.com/a1nT5.jpg)](https://i.stack.imgur.com/a1nT5.jpg)If all of the answers did not work lets clone pystan and do not use the above solutions: ``` git clone --recursive https://github.com/stan-dev/pystan.git cd pystan python setup.py install ``` [![enter image des...
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
To solve this problem, I uninstalled my existing python 3.7 and anaconda. I re-installed anaconda *with one key difference.* I registered Anaconda as my default Python 3.7 during the Anaconda installation. This lets visual studio, PyDev and other programs automatically detect Anaconda as the primary version to use.
Reason: The python distribution on Anaconda3 uses an old version of gcc (4.2.x) Please use anaconda prompt as administrator set a new environment for a stan ``` conda create -n stan python=<your_version> numpy cython ``` install pystan and gcc inside the virtual environment. ``` conda activate stan ``` or ...
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
I used the following steps to install fbprophet 0.7.1 on windows 10 (2022-03-10): 1. Install anaconda [here](https://www.anaconda.com/products/individual#windows). 2. Install pystan by following this [guide](https://pystan2.readthedocs.io/en/latest/windows.html). The main line I used was `conda install libpython m2w64...
It looks like `fbprophet` renamed to `prophet` on the FB side, so this command worked for me (Windows 10 + VSCode + Python 3.10.2) ``` pip install prophet --no-cache-dir ```
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
I tried to import fbprophet on Python Anaconda, however, I got some errors. This code works for me.. ``` conda install -c conda-forge/label/cf201901 fbprophet ```
[![enter image description here](https://i.stack.imgur.com/a1nT5.jpg)](https://i.stack.imgur.com/a1nT5.jpg)If all of the answers did not work lets clone pystan and do not use the above solutions: ``` git clone --recursive https://github.com/stan-dev/pystan.git cd pystan python setup.py install ``` [![enter image des...
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
Use: The first step is to remove pystan and cache: ``` pip uninstall fbprophet pystan pip --no-cache-dir install pystan==2.17 #any version pip --no-cache-dir install fbprophet==0.2 #any version conda install Cython --force pip install pystan conda install pystan -c conda-forge conda install -c conda-forge fbprophet ...
It looks like `fbprophet` renamed to `prophet` on the FB side, so this command worked for me (Windows 10 + VSCode + Python 3.10.2) ``` pip install prophet --no-cache-dir ```
56,701,359
I cannot install fbprophet or gcc7. I have manually installed a precompiled ephem. ``` Running setup.py install for fbprophet ... error ``` I have tried with python 3.6 and 3.7. I have tried running as administrator and without. My anaconda prompt cannot install anything without throwing errors. I would rather use...
2019/06/21
[ "https://Stackoverflow.com/questions/56701359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10005867/" ]
I tried to import fbprophet on Python Anaconda, however, I got some errors. This code works for me.. ``` conda install -c conda-forge/label/cf201901 fbprophet ```
(Short n Sweet) For Mac users : ------------------------------- 1. pip3 uninstall pystan 2. pip3 install pystan==2.17.1.0 3. pip3 install fbprophet
31,478,962
So I have an array of numbers, and I want to plot how many times each number occurs in the array. X-axis should be the numbers in the array, and y-axis should be the number of times each number occurs in the array. Is there a way to program this in python? Also I have trouble when I try to import numpy or matplotlib.py...
2015/07/17
[ "https://Stackoverflow.com/questions/31478962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5120932/" ]
``` t = [1, 2, 3, 1, 2, 5, 6, 7, 8] #your original list of numbers noDuplicates = list(set(t)) #gets rid of duplicates in your list listOfTuples = [] for number in noDuplicates: count = t.count(number) newTuple = [number, count] listOfTuples.Append(newTuple) ``` This creates a list of tuples where the f...
your best bet would be to create a separate list to keep track of the number of occurrences in your first list where the number you are tracking is the index of the second list. ``` listOfNumbers = [2,3,4,2,6,4,2] listOfOccurrences = range(x) #x-1 is the largest number that should occur in the first list ...
19,363,736
I've tried using the AWS forums to get help but, oh boy, it's hard to get anything over there. In any case, [the original post](https://forums.aws.amazon.com/thread.jspa?threadID=136256&tstart=0) is still there. Here's the same question. I deployed a Python (Flask) app using Elastic Beanstalk and the Python containe...
2013/10/14
[ "https://Stackoverflow.com/questions/19363736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21420/" ]
I ended up opening a paid case with AWS support and they confirmed it was a bug in the Python container code. As a result of this problem, they have just released (10/25/2013) a new version of the container and any new environments will contain the fix. To fix any of your existing environments... well, you can't. You'...
You can also change the value of the said `/static` alias via the configuration console on your Elastic Beanstalk environment. Under the "Static Files" section, map the virtual path */static* to point to your directory *app/myapp/static/*
49,911,864
I am trying to convert a 16 bit 3-band RGB GeoTIFF file into an 8 bit 3-band JPEG file. It seems like the `gdal` library should work well for this. **My question is how do I specify the conversion to 8-bit output in the python gdal API, and how do I scale the values in that conversion? Also, how do I check to tell whet...
2018/04/19
[ "https://Stackoverflow.com/questions/49911864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1610428/" ]
You could use **options** like this ``` from osgeo import gdal scale = '-scale min_val max_val' options_list = [ '-ot Byte', '-of JPEG', scale ] options_string = " ".join(options_list) gdal.Translate('test.jpg', 'test.tif', options=options_string) ``` Choose the min and m...
I think the gdal way is to use [`gdal.TranslateOptions()`](http://gdal.org/python/osgeo.gdal-module.html#TranslateOptions). ``` from osgeo import gdal translate_options = gdal.TranslateOptions(format='JPEG', outputType=gdal.GDT_Byte, ...
57,189,055
I transferred some code from IDLE 3.5 (64 bits) to pycharm (Python 2.7). Most of the code is still working, for example I can import WD\_LINE\_SPACING from docx.enum.text, but for some reason I can't import WD\_ALIGN\_PARAGRAPH. At first, nearly non of the imports worked, but after I did pip install python-docx ...
2019/07/24
[ "https://Stackoverflow.com/questions/57189055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9434244/" ]
You can use this instead: ```py from docx.enum.text import WD_PARAGRAPH_ALIGNMENT ``` and then substitute `WD_PARAGRAPH_ALIGNMENT` wherever `WD_ALIGN_PARAGRAPH` would have appeared before. The reason this is happening is that the actual enum object is named `WD_PARAGRAPH_ALIGNMENT`, and a decorator is applied that ...
If someone uses pylint it can be easily suppressed with `# pylint: disable=E0611` added at the end of the import line.
55,648,849
I have a problem with a loop in Python. My folder looks like this: ``` |folder_initial |--data_loop |--example1 |--example2 |--example3 |--python_jupyter_notebook ``` I would like to loop through all files in data\_loop, open them, run a simple o...
2019/04/12
[ "https://Stackoverflow.com/questions/55648849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11335403/" ]
let try `margin:0 1px` for `.header` div
This code can fixed your problem but make sure that border width will be 1px fixed, if you want to change border-width you can remove border-width:thin to border:2px solid red; and so on. ``` .border { margin-bottom: 20px; border-radius: 3px; border: 1px #d43f3a solid; border-width: thin; } ```
24,351,087
I'm currently in the process of finding a nice GUI framework for my new project - and Kivy looks quite good. There are many questions here (like [this one](https://stackoverflow.com/questions/15281239/kivy-hello-world-not-working)) about Kivy requiring OpenGL >2.0 (not accepting 1.4) and problems arising from that. As...
2014/06/22
[ "https://Stackoverflow.com/questions/24351087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3762521/" ]
As mentioned in the comment, I am not going to solve every problem. But the main errors. Let the player be responsible for its position, not the game. Furthermore, I would make the player responsible for drawing itself, but that goes a bit too far for this answer. The following code should at least work. ``` public ...
The key solution which Nico included is just that you using the original rectangle coordinates you made when you draw: ``` Rectangle playerPos = new Rectangle( Convert.ToInt32(Player.Pos.X), Convert.ToInt32(Player.Pos.Y), 32, 32); ``` Here you make the rectangle using the players CURRENT ...
18,584,055
I've got an Ubuntu 12.04 x64 Server edition VM that I'm running python2.7 on and trying to install the MySQLdb package via the command (I've already got `easy_install` installed and working): ``` $ sudo easy_install MySQL-python ``` but I get the following traceback error when easy\_install tries to compile: ``` Tr...
2013/09/03
[ "https://Stackoverflow.com/questions/18584055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281488/" ]
You need to use subquery : ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id`= (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2' ) AS contact_id) ) - ( SELECT SUM(`fee_amount`) FROM `civicrm_participant` WHERE `contact_id`= (SELECT `id` FR...
You should limit the result of the subquery to 1 otherwise it will result in an error, the best way is to match the name using `'='` instead of `'like'` ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id`= (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2...
18,584,055
I've got an Ubuntu 12.04 x64 Server edition VM that I'm running python2.7 on and trying to install the MySQLdb package via the command (I've already got `easy_install` installed and working): ``` $ sudo easy_install MySQL-python ``` but I get the following traceback error when easy\_install tries to compile: ``` Tr...
2013/09/03
[ "https://Stackoverflow.com/questions/18584055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281488/" ]
You need to use subquery : ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id`= (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2' ) AS contact_id) ) - ( SELECT SUM(`fee_amount`) FROM `civicrm_participant` WHERE `contact_id`= (SELECT `id` FR...
This could help you ``` SELECT @s:=1+1 ,@s + 4,@s-1 ``` o/p -@s:=1+1|@s + 4 | @s-1 ``` 2 | 6| 1 ```
18,584,055
I've got an Ubuntu 12.04 x64 Server edition VM that I'm running python2.7 on and trying to install the MySQLdb package via the command (I've already got `easy_install` installed and working): ``` $ sudo easy_install MySQL-python ``` but I get the following traceback error when easy\_install tries to compile: ``` Tr...
2013/09/03
[ "https://Stackoverflow.com/questions/18584055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281488/" ]
This should solve your problem : ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id` in (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2' ) AS contact_id) ) - ( SELECT SUM(`fee_amount`) FROM `civicrm_participant` WHERE `contact_id` in (SELEC...
You should limit the result of the subquery to 1 otherwise it will result in an error, the best way is to match the name using `'='` instead of `'like'` ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id`= (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2...
18,584,055
I've got an Ubuntu 12.04 x64 Server edition VM that I'm running python2.7 on and trying to install the MySQLdb package via the command (I've already got `easy_install` installed and working): ``` $ sudo easy_install MySQL-python ``` but I get the following traceback error when easy\_install tries to compile: ``` Tr...
2013/09/03
[ "https://Stackoverflow.com/questions/18584055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/281488/" ]
This should solve your problem : ``` SELECT ( SELECT SUM(`total_amount`) FROM `civicrm_contribution` WHERE `contact_id` in (SELECT `id` FROM `civicrm_contact` WHERE `first_name` LIKE 'test2' ) AS contact_id) ) - ( SELECT SUM(`fee_amount`) FROM `civicrm_participant` WHERE `contact_id` in (SELEC...
This could help you ``` SELECT @s:=1+1 ,@s + 4,@s-1 ``` o/p -@s:=1+1|@s + 4 | @s-1 ``` 2 | 6| 1 ```
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
> > Note: I've considered properties, but I don't think they're a cleaner solution. > > > [But they are.](http://docs.python.org/library/functions.html#property) By using properties, you'll have the class signature you want, while being able to use the property as an attribute itself. ``` def _get_id(self): re...
[Only behind a property.](http://www.archive.org/details/SeanKellyRecoveryfromAddiction)
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
You've missed the point. It isn't the lack of encapsulation that removes the need for accessors, it's the fact that, by changing from a direct attribute to a property, you can add an accessor at a later time without changing the published interface in any way. In many other languages, if you expose an attribute as pub...
[Only behind a property.](http://www.archive.org/details/SeanKellyRecoveryfromAddiction)
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
[Only behind a property.](http://www.archive.org/details/SeanKellyRecoveryfromAddiction)
The discussion already ended a year ago, but this snippet seemed telltale, it's worth discussing: > > However, an implementation of the > class that satisfies all of the > abstract methods will almost certainly > fail, because the author won't know > that they need attributes called > 'author' and 'date' and so ...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
> > Note: I've considered properties, but I don't think they're a cleaner solution. > > > [But they are.](http://docs.python.org/library/functions.html#property) By using properties, you'll have the class signature you want, while being able to use the property as an attribute itself. ``` def _get_id(self): re...
> > "they should be able to do so just by looking at the abstract class" > > > Don't know what this should be true. A "programmer's guide", a "how to extend" document, plus some training seems appropriate to me. > > "the author won't know that they need attributes called 'author' and 'date' and so on". > > > ...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
You've missed the point. It isn't the lack of encapsulation that removes the need for accessors, it's the fact that, by changing from a direct attribute to a property, you can add an accessor at a later time without changing the published interface in any way. In many other languages, if you expose an attribute as pub...
> > "they should be able to do so just by looking at the abstract class" > > > Don't know what this should be true. A "programmer's guide", a "how to extend" document, plus some training seems appropriate to me. > > "the author won't know that they need attributes called 'author' and 'date' and so on". > > > ...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
> > "they should be able to do so just by looking at the abstract class" > > > Don't know what this should be true. A "programmer's guide", a "how to extend" document, plus some training seems appropriate to me. > > "the author won't know that they need attributes called 'author' and 'date' and so on". > > > ...
The discussion already ended a year ago, but this snippet seemed telltale, it's worth discussing: > > However, an implementation of the > class that satisfies all of the > abstract methods will almost certainly > fail, because the author won't know > that they need attributes called > 'author' and 'date' and so ...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
> > Note: I've considered properties, but I don't think they're a cleaner solution. > > > [But they are.](http://docs.python.org/library/functions.html#property) By using properties, you'll have the class signature you want, while being able to use the property as an attribute itself. ``` def _get_id(self): re...
You've missed the point. It isn't the lack of encapsulation that removes the need for accessors, it's the fact that, by changing from a direct attribute to a property, you can add an accessor at a later time without changing the published interface in any way. In many other languages, if you expose an attribute as pub...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
> > Note: I've considered properties, but I don't think they're a cleaner solution. > > > [But they are.](http://docs.python.org/library/functions.html#property) By using properties, you'll have the class signature you want, while being able to use the property as an attribute itself. ``` def _get_id(self): re...
The discussion already ended a year ago, but this snippet seemed telltale, it's worth discussing: > > However, an implementation of the > class that satisfies all of the > abstract methods will almost certainly > fail, because the author won't know > that they need attributes called > 'author' and 'date' and so ...
3,292,631
I realize that in most cases, it's preferred in Python to just access attributes directly, since there's no real concept of encapsulation like there is in Java and the like. However, I'm wondering if there aren't any exceptions, particularly with abstract classes that have disparate implementations. Let's say I'm writ...
2010/07/20
[ "https://Stackoverflow.com/questions/3292631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262271/" ]
You've missed the point. It isn't the lack of encapsulation that removes the need for accessors, it's the fact that, by changing from a direct attribute to a property, you can add an accessor at a later time without changing the published interface in any way. In many other languages, if you expose an attribute as pub...
The discussion already ended a year ago, but this snippet seemed telltale, it's worth discussing: > > However, an implementation of the > class that satisfies all of the > abstract methods will almost certainly > fail, because the author won't know > that they need attributes called > 'author' and 'date' and so ...
4,424,342
When using the kwarg-style dict initialization: ``` In [3]: dict(a=1, b=2, c=3) Out[3]: {'a': 1, 'b': 2, 'c': 3} ``` for some reason, defining the key 'from' raises a syntax error: ``` In [4]: dict(to=0, from=1) ------------------------------------------------------------ File "<ipython console>", line 1 di...
2010/12/12
[ "https://Stackoverflow.com/questions/4424342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/226037/" ]
from is a keyword: ``` from threading import Thread ``` Python doesn't have context-sensitive keywords: A name is either a keyword, or can be used as an identifier. There used to be one exception: "as" used to be special-cased in import statements when it was first introduced, but has since been promoted to "full ke...
you can't use python keywords such as `from` in kwargs
4,424,342
When using the kwarg-style dict initialization: ``` In [3]: dict(a=1, b=2, c=3) Out[3]: {'a': 1, 'b': 2, 'c': 3} ``` for some reason, defining the key 'from' raises a syntax error: ``` In [4]: dict(to=0, from=1) ------------------------------------------------------------ File "<ipython console>", line 1 di...
2010/12/12
[ "https://Stackoverflow.com/questions/4424342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/226037/" ]
`from` is used in imports. [Python Language Reference, §2.3.1, "Keywords"](http://docs.python.org/reference/lexical_analysis.html#keywords) Note that you can still use kwarg expansion to get them through though.
you can't use python keywords such as `from` in kwargs
4,424,342
When using the kwarg-style dict initialization: ``` In [3]: dict(a=1, b=2, c=3) Out[3]: {'a': 1, 'b': 2, 'c': 3} ``` for some reason, defining the key 'from' raises a syntax error: ``` In [4]: dict(to=0, from=1) ------------------------------------------------------------ File "<ipython console>", line 1 di...
2010/12/12
[ "https://Stackoverflow.com/questions/4424342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/226037/" ]
`from`, like a handful of other tokens, are keywords/reserved words in Python (`from` specifically is used when importing a few hand-picked objects from a module into the current namespace). You cannot use them as identifiers or anything (ultimately, kwargs are identifiers). It's simply not allowed, even when *in theor...
you can't use python keywords such as `from` in kwargs
4,424,342
When using the kwarg-style dict initialization: ``` In [3]: dict(a=1, b=2, c=3) Out[3]: {'a': 1, 'b': 2, 'c': 3} ``` for some reason, defining the key 'from' raises a syntax error: ``` In [4]: dict(to=0, from=1) ------------------------------------------------------------ File "<ipython console>", line 1 di...
2010/12/12
[ "https://Stackoverflow.com/questions/4424342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/226037/" ]
`from` is used in imports. [Python Language Reference, §2.3.1, "Keywords"](http://docs.python.org/reference/lexical_analysis.html#keywords) Note that you can still use kwarg expansion to get them through though.
from is a keyword: ``` from threading import Thread ``` Python doesn't have context-sensitive keywords: A name is either a keyword, or can be used as an identifier. There used to be one exception: "as" used to be special-cased in import statements when it was first introduced, but has since been promoted to "full ke...
4,424,342
When using the kwarg-style dict initialization: ``` In [3]: dict(a=1, b=2, c=3) Out[3]: {'a': 1, 'b': 2, 'c': 3} ``` for some reason, defining the key 'from' raises a syntax error: ``` In [4]: dict(to=0, from=1) ------------------------------------------------------------ File "<ipython console>", line 1 di...
2010/12/12
[ "https://Stackoverflow.com/questions/4424342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/226037/" ]
`from` is used in imports. [Python Language Reference, §2.3.1, "Keywords"](http://docs.python.org/reference/lexical_analysis.html#keywords) Note that you can still use kwarg expansion to get them through though.
`from`, like a handful of other tokens, are keywords/reserved words in Python (`from` specifically is used when importing a few hand-picked objects from a module into the current namespace). You cannot use them as identifiers or anything (ultimately, kwargs are identifiers). It's simply not allowed, even when *in theor...
52,305,578
So I am trying to use: ``` sift = cv2.xfeatures2d.SIFT_create() ``` and it is coming up with this error: ``` cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in t...
2018/09/13
[ "https://Stackoverflow.com/questions/52305578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8573126/" ]
I had the same problem. It seems that SIRF and SURF are [no longer available in opencv > 3.4.2.16](https://github.com/DynaSlum/satsense/issues/13). I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the [history version](https://pypi.org/project/opencv-python/#history) ab...
It may be due to a mismatch of opencv version and opencv-contrib version. If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do `pip install opencv-contrib-python==<version of the source>.X` ...
52,305,578
So I am trying to use: ``` sift = cv2.xfeatures2d.SIFT_create() ``` and it is coming up with this error: ``` cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in t...
2018/09/13
[ "https://Stackoverflow.com/questions/52305578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8573126/" ]
Edit: The `opencv-contrib-python-nonfree` was removed from pypi. **On Linux/ MacOS**, I've found a better solution! To access nonfree detectors use: `pip install opencv-contrib-python-nonfree`
It may be due to a mismatch of opencv version and opencv-contrib version. If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do `pip install opencv-contrib-python==<version of the source>.X` ...
52,305,578
So I am trying to use: ``` sift = cv2.xfeatures2d.SIFT_create() ``` and it is coming up with this error: ``` cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in t...
2018/09/13
[ "https://Stackoverflow.com/questions/52305578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8573126/" ]
Since SIFT patent expired, SIFT has been moved to the main repo. To use SIFT in Opencv, You should use cv2.SIFT\_create() instead of cv2.xfeatures2d.SIFT\_create() now. (xfeatures2d only exists in the contrib package, but sift is part of the main package now.) Below link will be helpful. <https://github.com/opencv/ope...
It may be due to a mismatch of opencv version and opencv-contrib version. If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do `pip install opencv-contrib-python==<version of the source>.X` ...
52,305,578
So I am trying to use: ``` sift = cv2.xfeatures2d.SIFT_create() ``` and it is coming up with this error: ``` cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in t...
2018/09/13
[ "https://Stackoverflow.com/questions/52305578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8573126/" ]
I had the same problem. It seems that SIRF and SURF are [no longer available in opencv > 3.4.2.16](https://github.com/DynaSlum/satsense/issues/13). I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the [history version](https://pypi.org/project/opencv-python/#history) ab...
Edit: The `opencv-contrib-python-nonfree` was removed from pypi. **On Linux/ MacOS**, I've found a better solution! To access nonfree detectors use: `pip install opencv-contrib-python-nonfree`
52,305,578
So I am trying to use: ``` sift = cv2.xfeatures2d.SIFT_create() ``` and it is coming up with this error: ``` cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in t...
2018/09/13
[ "https://Stackoverflow.com/questions/52305578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8573126/" ]
I had the same problem. It seems that SIRF and SURF are [no longer available in opencv > 3.4.2.16](https://github.com/DynaSlum/satsense/issues/13). I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the [history version](https://pypi.org/project/opencv-python/#history) ab...
Since SIFT patent expired, SIFT has been moved to the main repo. To use SIFT in Opencv, You should use cv2.SIFT\_create() instead of cv2.xfeatures2d.SIFT\_create() now. (xfeatures2d only exists in the contrib package, but sift is part of the main package now.) Below link will be helpful. <https://github.com/opencv/ope...
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
I think the problem is that cron is going to run your scripts in a "bare" environment, so your DJANGO\_SETTINGS\_MODULE is likely undefined. You may want to wrap this up in a shell script that first defines DJANGO\_SETTINGS\_MODULE Something like this: ``` #!/bin/bash export DJANGO_SETTINGS_MODULE=myproject.settings...
**How to Schedule Django custom Commands on AWS EC-2 Instance?** **Step -1** ``` First, you need to write a .cron file ``` **Step-2** ``` Write your script in .cron file. ``` > > MyScript.cron > > > ``` * * * * * /home/ubuntu/kuzo1/venv/bin/python3 /home/ubuntu/Myproject/manage.py transfer_funds >> /home/ub...
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
I think the problem is that cron is going to run your scripts in a "bare" environment, so your DJANGO\_SETTINGS\_MODULE is likely undefined. You may want to wrap this up in a shell script that first defines DJANGO\_SETTINGS\_MODULE Something like this: ``` #!/bin/bash export DJANGO_SETTINGS_MODULE=myproject.settings...
1. If its a standalone script, you need to do this: ``` from django.conf import settings from django.core.management import setup_environ setup_environ(settings) #your code here which uses django code, like django model ``` 2. If its a django command, its easier: <https://coderwall.com/p/k5p6ag> In (management/comm...
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
``` cd /path/to/project/myapp && python manage.py mycommand ``` By chaining your commands like this, python will not be executed unless cd correctly changes the directory.
**How to Schedule Django custom Commands on AWS EC-2 Instance?** **Step -1** ``` First, you need to write a .cron file ``` **Step-2** ``` Write your script in .cron file. ``` > > MyScript.cron > > > ``` * * * * * /home/ubuntu/kuzo1/venv/bin/python3 /home/ubuntu/Myproject/manage.py transfer_funds >> /home/ub...
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
``` cd /path/to/project/myapp && python manage.py mycommand ``` By chaining your commands like this, python will not be executed unless cd correctly changes the directory.
The runscript extension wasn't well documented. Unlike the django command this one can go anywhere in your project and requires a scripts folder. The .py file requires a run() function.
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
This is what i have done recently in one of my projects,(i maintain venvs for every project i work, so i am assumning you have venvs) > > > ``` > ***** /path/to/venvs/bin/python /path/to/app/manage.py command_name > > ``` > > This worked perfectly for me.
The runscript extension wasn't well documented. Unlike the django command this one can go anywhere in your project and requires a scripts folder. The .py file requires a run() function.
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
``` cd /path/to/project/myapp && python manage.py mycommand ``` By chaining your commands like this, python will not be executed unless cd correctly changes the directory.
1. If its a standalone script, you need to do this: ``` from django.conf import settings from django.core.management import setup_environ setup_environ(settings) #your code here which uses django code, like django model ``` 2. If its a django command, its easier: <https://coderwall.com/p/k5p6ag> In (management/comm...
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
I think the problem is that cron is going to run your scripts in a "bare" environment, so your DJANGO\_SETTINGS\_MODULE is likely undefined. You may want to wrap this up in a shell script that first defines DJANGO\_SETTINGS\_MODULE Something like this: ``` #!/bin/bash export DJANGO_SETTINGS_MODULE=myproject.settings...
The runscript extension wasn't well documented. Unlike the django command this one can go anywhere in your project and requires a scripts folder. The .py file requires a run() function.
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
**How to Schedule Django custom Commands on AWS EC-2 Instance?** **Step -1** ``` First, you need to write a .cron file ``` **Step-2** ``` Write your script in .cron file. ``` > > MyScript.cron > > > ``` * * * * * /home/ubuntu/kuzo1/venv/bin/python3 /home/ubuntu/Myproject/manage.py transfer_funds >> /home/ub...
The runscript extension wasn't well documented. Unlike the django command this one can go anywhere in your project and requires a scripts folder. The .py file requires a run() function.
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
``` cd /path/to/project/myapp && python manage.py mycommand ``` By chaining your commands like this, python will not be executed unless cd correctly changes the directory.
This is what i have done recently in one of my projects,(i maintain venvs for every project i work, so i am assumning you have venvs) > > > ``` > ***** /path/to/venvs/bin/python /path/to/app/manage.py command_name > > ``` > > This worked perfectly for me.
1,601,153
I want my custom made Django command to be executed every minute. However it seems like `python /path/to/project/myapp/manage.py mycommand` doesn't seem to work while at the directory `python manage.py mycommand` works perfectly. How can I achieve this ? I use `/etc/crontab` with: ``` ****** root python /path/to/proj...
2009/10/21
[ "https://Stackoverflow.com/questions/1601153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/151937/" ]
``` cd /path/to/project/myapp && python manage.py mycommand ``` By chaining your commands like this, python will not be executed unless cd correctly changes the directory.
If you want your Django life a lot more simple, use django-command-extensions within your project: <http://code.google.com/p/django-command-extensions/> You'll find a command named "runscript" so you simply add the command to your crontab line: ``` ****** root python /path/to/project/myapp/manage.py runscript mycomm...
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
If you want to mix in the same runtime both 2.6 and 3.1 you may be interested in [execnet](http://codespeak.net/execnet/). Never tested directly, however * Edit: looking at you comments on another answer, I understood better the question
Maybe "Open with..." + 'Remember my choice' in context menu of explorer?
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
the shebang line: ``` #!/usr/bin/python2.6 ``` ... will be ignored in Windows. In Windows, you must call the correct python interpreter directly (AFAIK). Normally, people add their Python version specific directory (c:\Python26) to their PATH (environment variable) so you can just type "python" at any command line...
Maybe "Open with..." + 'Remember my choice' in context menu of explorer?
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
If you want to mix in the same runtime both 2.6 and 3.1 you may be interested in [execnet](http://codespeak.net/execnet/). Never tested directly, however * Edit: looking at you comments on another answer, I understood better the question
If you want to go back from Python 3 to Python 2 you could try [3to2](http://pypi.python.org/pypi/3to2) to convert your code back to Python 2. You can't easily mix Python 2 and 3 in the same program.
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
If you want to mix in the same runtime both 2.6 and 3.1 you may be interested in [execnet](http://codespeak.net/execnet/). Never tested directly, however * Edit: looking at you comments on another answer, I understood better the question
If you go into Control Panel -> System -> Advanced -> Environment Variables, and then add Python 2.6 to the PATH variable (it's probably located at C:\Python26 or C:\Program Files\Python26) -- and make sure Python 3.1 isn't in it -- then if you type python at the command prompt, you'll get 2.6 instead. As for Explorer,...
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
the shebang line: ``` #!/usr/bin/python2.6 ``` ... will be ignored in Windows. In Windows, you must call the correct python interpreter directly (AFAIK). Normally, people add their Python version specific directory (c:\Python26) to their PATH (environment variable) so you can just type "python" at any command line...
If you want to mix in the same runtime both 2.6 and 3.1 you may be interested in [execnet](http://codespeak.net/execnet/). Never tested directly, however * Edit: looking at you comments on another answer, I understood better the question
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
the shebang line: ``` #!/usr/bin/python2.6 ``` ... will be ignored in Windows. In Windows, you must call the correct python interpreter directly (AFAIK). Normally, people add their Python version specific directory (c:\Python26) to their PATH (environment variable) so you can just type "python" at any command line...
If you want to go back from Python 3 to Python 2 you could try [3to2](http://pypi.python.org/pypi/3to2) to convert your code back to Python 2. You can't easily mix Python 2 and 3 in the same program.
3,236,983
My program has been written on python 3.1 (it was the biggest mistake I've ever made). Now I want to use a few modules that were written on 2.6. I know that it's possible to specify the interpreter in Unix `#!/usr/bin/python2.6`. But what if I use Windows? Does any way to specify the interpreter exist in Windows? Edi...
2010/07/13
[ "https://Stackoverflow.com/questions/3236983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/248814/" ]
the shebang line: ``` #!/usr/bin/python2.6 ``` ... will be ignored in Windows. In Windows, you must call the correct python interpreter directly (AFAIK). Normally, people add their Python version specific directory (c:\Python26) to their PATH (environment variable) so you can just type "python" at any command line...
If you go into Control Panel -> System -> Advanced -> Environment Variables, and then add Python 2.6 to the PATH variable (it's probably located at C:\Python26 or C:\Program Files\Python26) -- and make sure Python 3.1 isn't in it -- then if you type python at the command prompt, you'll get 2.6 instead. As for Explorer,...
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
``` from collections import defaultdict data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] if __name__ == '__main__': result = defaultdict(list) for alphabet, number in data: result[alphabet].append(number) ``` or without collections module: ``` if __name__ == '__main__...
You can use `defaultdict` from the `collections` module for this: ``` from collections import defaultdict l = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] d = defaultdict(list) for k,v in l: d[k].append(v) for k,v in d.items(): exec(k + "list=" + str(v)) ```
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
``` from collections import defaultdict data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] if __name__ == '__main__': result = defaultdict(list) for alphabet, number in data: result[alphabet].append(number) ``` or without collections module: ``` if __name__ == '__main__...
If you want to avoid using a `defaultdict` but are comfortable using `itertools`, you can do it with a one-liner ``` from itertools import groupby data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] grouped = dict((key, list(pair[1] for pair in values)) for (key, values) in groupby(data, la...
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
``` from collections import defaultdict data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] if __name__ == '__main__': result = defaultdict(list) for alphabet, number in data: result[alphabet].append(number) ``` or without collections module: ``` if __name__ == '__main__...
After seeing the responses in the thread and reading the implementation of defaultdict, I implemented my own version of it since I didn't want to use the collections library. ``` mydict = {} for alphabet, value in data: try: mydict[alphabet].append(value) except KeyError: ...
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
If you want to avoid using a `defaultdict` but are comfortable using `itertools`, you can do it with a one-liner ``` from itertools import groupby data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] grouped = dict((key, list(pair[1] for pair in values)) for (key, values) in groupby(data, la...
You can use `defaultdict` from the `collections` module for this: ``` from collections import defaultdict l = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] d = defaultdict(list) for k,v in l: d[k].append(v) for k,v in d.items(): exec(k + "list=" + str(v)) ```
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
After seeing the responses in the thread and reading the implementation of defaultdict, I implemented my own version of it since I didn't want to use the collections library. ``` mydict = {} for alphabet, value in data: try: mydict[alphabet].append(value) except KeyError: ...
You can use `defaultdict` from the `collections` module for this: ``` from collections import defaultdict l = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] d = defaultdict(list) for k,v in l: d[k].append(v) for k,v in d.items(): exec(k + "list=" + str(v)) ```
39,654,224
I am trying to come up with a neat way of doing this in python. I have a list of pairs of alphabets and numbers that look like this : ``` [(a,1),(a,2),(a,3),(b,10),(b,100),(c,99),(d,-1),(d,-2)] ``` What I want to do is to create a new list for each alphabet and append all the numerical values to it. So, output sho...
2016/09/23
[ "https://Stackoverflow.com/questions/39654224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2272156/" ]
If you want to avoid using a `defaultdict` but are comfortable using `itertools`, you can do it with a one-liner ``` from itertools import groupby data = [('a',1),('a',2),('a',3),('b',10),('b',100),('c',99),('d',-1),('d',-2)] grouped = dict((key, list(pair[1] for pair in values)) for (key, values) in groupby(data, la...
After seeing the responses in the thread and reading the implementation of defaultdict, I implemented my own version of it since I didn't want to use the collections library. ``` mydict = {} for alphabet, value in data: try: mydict[alphabet].append(value) except KeyError: ...
65,676,114
From one file, I'm trying to import and initialize a class from another file, where that class is initialized with a global variable defined in the calling file. My file setup looks like this. ``` folder ├──subfolder │ └── __init__.py │ └── sub.py ├──__init__.py ├──orig.py ``` My `orig.py` file looks like thi...
2021/01/11
[ "https://Stackoverflow.com/questions/65676114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259896/" ]
You have got your program almost right. The only challenge I see is with resetting the variable `digit_total = 0` after each iteration. ``` def digital_root(n): n_str = str(n) while len(n_str) != 1: digit_total = 0 #move this inside the while loop for digit in n_str: digit_total += ...
Alex, running a recursive function would always be better than a while loop in such scenarios. Try this : ``` def digital_root(n): n=sum([int(i) for i in str(n)]) if len(str(n))==1: print(n) else: digital_root(n) ```
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
Well, it's good that you are providing more information to the user than just printing out the BMI. But in this case, your test wants only a single number as output for validation. Your code is correct but. A few improvements which you can make in your code: ``` height = input("enter your height in m: ") weight = inp...
the testing you are using wants your print to be only the BMI calculated, so the last print should only be ``` print(BMI) ``` or you could try: ``` print("Your BMI is: ", BMI) ```
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
I would suggest to use `f-string` formatting: ``` print(f"Your BMI is: {BMI}") ``` I would suggest to read [`this`](https://towardsdatascience.com/introducing-f-strings-the-best-option-for-string-formatting-in-python-b52975b47b84), notice that the `f-string` formatting is considered the best practice. --- To make ...
the testing you are using wants your print to be only the BMI calculated, so the last print should only be ``` print(BMI) ``` or you could try: ``` print("Your BMI is: ", BMI) ```
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
Well, it's good that you are providing more information to the user than just printing out the BMI. But in this case, your test wants only a single number as output for validation. Your code is correct but. A few improvements which you can make in your code: ``` height = input("enter your height in m: ") weight = inp...
I would suggest to use `f-string` formatting: ``` print(f"Your BMI is: {BMI}") ``` I would suggest to read [`this`](https://towardsdatascience.com/introducing-f-strings-the-best-option-for-string-formatting-in-python-b52975b47b84), notice that the `f-string` formatting is considered the best practice. --- To make ...
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
Well, it's good that you are providing more information to the user than just printing out the BMI. But in this case, your test wants only a single number as output for validation. Your code is correct but. A few improvements which you can make in your code: ``` height = input("enter your height in m: ") weight = inp...
I will not focus on the test's error messages but more on what you are trying to achieve. Python is a "typed" language, meaning that numbers and strings will be considered differently by Python and with some limitations. I am providing two possible solutions (working with Python 3.9 but you might experience a differe...
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
Well, it's good that you are providing more information to the user than just printing out the BMI. But in this case, your test wants only a single number as output for validation. Your code is correct but. A few improvements which you can make in your code: ``` height = input("enter your height in m: ") weight = inp...
This is a bit on the border between an answer and a comment; you're not asking your question correctly, but explaining what's wrong with how you're asking your question (which normally belongs in a comment) will probably get you most of the way, if not all the way, to understanding the problem. It appears that your pro...
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
I would suggest to use `f-string` formatting: ``` print(f"Your BMI is: {BMI}") ``` I would suggest to read [`this`](https://towardsdatascience.com/introducing-f-strings-the-best-option-for-string-formatting-in-python-b52975b47b84), notice that the `f-string` formatting is considered the best practice. --- To make ...
I will not focus on the test's error messages but more on what you are trying to achieve. Python is a "typed" language, meaning that numbers and strings will be considered differently by Python and with some limitations. I am providing two possible solutions (working with Python 3.9 but you might experience a differe...
70,995,571
Im still VERY NEW to programming and python...Any help would be GREATLY appreciated.. I am doing a BMI calculator in my python class.. I actually got it working the way the instructor wanted but I wanted to just improve it slightly and I had no idea it was going to be this difficult. My original code that actually wor...
2022/02/05
[ "https://Stackoverflow.com/questions/70995571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17611193/" ]
I would suggest to use `f-string` formatting: ``` print(f"Your BMI is: {BMI}") ``` I would suggest to read [`this`](https://towardsdatascience.com/introducing-f-strings-the-best-option-for-string-formatting-in-python-b52975b47b84), notice that the `f-string` formatting is considered the best practice. --- To make ...
This is a bit on the border between an answer and a comment; you're not asking your question correctly, but explaining what's wrong with how you're asking your question (which normally belongs in a comment) will probably get you most of the way, if not all the way, to understanding the problem. It appears that your pro...