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 |
|---|---|---|---|---|---|
20,289,373 | I am developing a program in python and have reached a point I don't know how to solve.
My intention is to use a `with` statement, an avoid the usage of try/except.
So far, my idea is being able to use the `continue` statement as it would be used inside the `except`. However, I don't seem to succeed.
Let's supposse t... | 2013/11/29 | [
"https://Stackoverflow.com/questions/20289373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | It's not possible.
The only two options are (a) let the exception propagate by returning a false-y value or (b) swallow the exception by returning True. There is no way to resume the code block from where the exception was thrown. Either way, your `with` block is over. | You can't. The `with` statement's purpose is to handle cleanup automatically (which is why exceptions can be suppressed *when exiting it*), not to act as Visual Basic's infamous `On Error Resume Next`.
If you want to continue the execution of a block after an exception is raised, you need to wrap whatever raises the e... |
20,289,373 | I am developing a program in python and have reached a point I don't know how to solve.
My intention is to use a `with` statement, an avoid the usage of try/except.
So far, my idea is being able to use the `continue` statement as it would be used inside the `except`. However, I don't seem to succeed.
Let's supposse t... | 2013/11/29 | [
"https://Stackoverflow.com/questions/20289373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | It's not possible.
The only two options are (a) let the exception propagate by returning a false-y value or (b) swallow the exception by returning True. There is no way to resume the code block from where the exception was thrown. Either way, your `with` block is over. | Though most of the answers are correct, I'm afraid none suits my problem (I know I didn't provide my whole code, sorry about that).
I've solved the problem taking another approach. I wanted to be able to handle a NameError ("variable not declared") inside a With. If that occurred, I would look inside my object for tha... |
20,289,373 | I am developing a program in python and have reached a point I don't know how to solve.
My intention is to use a `with` statement, an avoid the usage of try/except.
So far, my idea is being able to use the `continue` statement as it would be used inside the `except`. However, I don't seem to succeed.
Let's supposse t... | 2013/11/29 | [
"https://Stackoverflow.com/questions/20289373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | You can't. The `with` statement's purpose is to handle cleanup automatically (which is why exceptions can be suppressed *when exiting it*), not to act as Visual Basic's infamous `On Error Resume Next`.
If you want to continue the execution of a block after an exception is raised, you need to wrap whatever raises the e... | Though most of the answers are correct, I'm afraid none suits my problem (I know I didn't provide my whole code, sorry about that).
I've solved the problem taking another approach. I wanted to be able to handle a NameError ("variable not declared") inside a With. If that occurred, I would look inside my object for tha... |
73,642,679 | I have a function in C which is integrated into python as a library.
The python looks something like this:
```
import ctypes
import numpy as np
lib=ctypes.cdll.LoadLibrary("./array.so")
lib.eq.argtypes=(ctypes.c_int,
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float))
pa... | 2022/09/08 | [
"https://Stackoverflow.com/questions/73642679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18335909/"
] | You were close. The input arrays need to be `dtypes=np.float32` (or `ct.c_float`) to match the C 32-bit `float` parameters. `results` is changed in-place so print the updated `results` after the function call.
You can also use `ndpointer` to declare the *exact* type of arrays expected, so `ctypes` can check the the co... | My suggestion:
```py
import ctypes
import numpy as np
from os.path import abspath
from ctypes import cdll, c_void_p, c_int
params = np.ascontiguousarray(np.zeros(5, dtype=np.float64))
results = np.ascontiguousarray(np.zeros(5, dtype=np.float64))
lib = cdll.LoadLibrary(abspath('array.so')) # loading the compiled... |
73,224,353 | **Context**
An empty list:
`my_list = []`
I also have a list of lists of strings:
words\_list = `[['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]`
But note that there are some elements in the lists that are null.
**Ideal output**
I want to randomly choose a non null element from each list in `words_list`... | 2022/08/03 | [
"https://Stackoverflow.com/questions/73224353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | Maybe you can try to start thinking this way:
The idea is quite simple - just go through the list of words, and choose the non-empty word then passing to *choice*.
```py
>>> for word in words_list:
wd = choice([w for w in word if w]) # if w is non-null, choice will pick it...
print(wd)
# then just add thos... | Try below code and see if it works for you:
```
import random
my_list = []
words_list = [['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]
for sublist in words_list:
filtered_list = list(filter(None, sublist))
my_list.append(random.choice(filtered_list))
print(my_list)
``` |
73,224,353 | **Context**
An empty list:
`my_list = []`
I also have a list of lists of strings:
words\_list = `[['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]`
But note that there are some elements in the lists that are null.
**Ideal output**
I want to randomly choose a non null element from each list in `words_list`... | 2022/08/03 | [
"https://Stackoverflow.com/questions/73224353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | You can use list comprehension:
```py
from random import choice
words_list = [['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]
output = [choice([word for word in words if word]) for words in words_list]
print(output) # ['is', 'a', 'lists']
``` | Try below code and see if it works for you:
```
import random
my_list = []
words_list = [['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]
for sublist in words_list:
filtered_list = list(filter(None, sublist))
my_list.append(random.choice(filtered_list))
print(my_list)
``` |
73,224,353 | **Context**
An empty list:
`my_list = []`
I also have a list of lists of strings:
words\_list = `[['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]`
But note that there are some elements in the lists that are null.
**Ideal output**
I want to randomly choose a non null element from each list in `words_list`... | 2022/08/03 | [
"https://Stackoverflow.com/questions/73224353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | Maybe you can try to start thinking this way:
The idea is quite simple - just go through the list of words, and choose the non-empty word then passing to *choice*.
```py
>>> for word in words_list:
wd = choice([w for w in word if w]) # if w is non-null, choice will pick it...
print(wd)
# then just add thos... | The `random` module contains a function `choices` that's a little more flexible than `choice`. It will take a list of weights that determine the odds of picking a particular element; if the weight is zero, it won't be selected.
```
for words in words_list:
weights = [w != '' for w in words]
if any(weights):
... |
73,224,353 | **Context**
An empty list:
`my_list = []`
I also have a list of lists of strings:
words\_list = `[['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]`
But note that there are some elements in the lists that are null.
**Ideal output**
I want to randomly choose a non null element from each list in `words_list`... | 2022/08/03 | [
"https://Stackoverflow.com/questions/73224353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10587373/"
] | You can use list comprehension:
```py
from random import choice
words_list = [['this', '', 'is'], ['a', 'list', ''], ['of', 'lists']]
output = [choice([word for word in words if word]) for words in words_list]
print(output) # ['is', 'a', 'lists']
``` | The `random` module contains a function `choices` that's a little more flexible than `choice`. It will take a list of weights that determine the odds of picking a particular element; if the weight is zero, it won't be selected.
```
for words in words_list:
weights = [w != '' for w in words]
if any(weights):
... |
46,600,413 | New to programming and currently working with python. I am trying to take a user inputted string (containing letters, numbers and special characters), I then need to split it multiple times at different points to reform new strings. I have done research on the splitting of strings (and lists) and feel I understand it b... | 2017/10/06 | [
"https://Stackoverflow.com/questions/46600413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8660214/"
] | change your jquery code to
```
$('#forgotPassword').click(function() {
var base_url = '<?php echo base_url()?>';
$('#forgotPasswordEmailError').text('');
var email = $('#forgotPasswordEmail').val();
console.log(email);
if(email == ''){
$('#forgotPasswordEmailError').text('Email is require... | Instead of
```
echo $email;
```
use:
```
$response = ["email" => $email];
return json_encode($response);
```
And parse JSON, on client side, using `JSON.parse`. |
46,600,413 | New to programming and currently working with python. I am trying to take a user inputted string (containing letters, numbers and special characters), I then need to split it multiple times at different points to reform new strings. I have done research on the splitting of strings (and lists) and feel I understand it b... | 2017/10/06 | [
"https://Stackoverflow.com/questions/46600413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8660214/"
] | change your jquery code to
```
$('#forgotPassword').click(function() {
var base_url = '<?php echo base_url()?>';
$('#forgotPasswordEmailError').text('');
var email = $('#forgotPasswordEmail').val();
console.log(email);
if(email == ''){
$('#forgotPasswordEmailError').text('Email is require... | hi maybe i can help someone, i had the same problem, in my case the error was here "url : base\_url + 'Home/forgotPassword'"
in this example i have to pass all way like this url : /anotherdirectory/Home/forgotPassword.php',
take a look in your "url"
$.ajax({
url : "change here fo works"',
type : 'POST',
data : {email... |
33,146,316 | Sorry, I'm a newbie of nodejs. I'd like to try the package `win32ole` in nodejs under Windows7, but when I run the installation command `npm install win32ole` in a command prompt window opened as administrator, many errors pop up.
My configuration is:
* Windows 7 64 bit (version 6.1.7601)
* Microsoft Visual Studio Ex... | 2015/10/15 | [
"https://Stackoverflow.com/questions/33146316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/694360/"
] | It's not possible with up to date node.js versions.
Use [node winax](https://www.npmjs.com/package/winax) | First of all you have a **warning** due to the node version
```
npm WARN engine [email protected]: wanted: {"node":">= 0.8.18 && < 0.9.0"} (current: {"node":"4.2.1","npm":"2.14.7"})
```
It should be lower than 0.9.0
Have you installed **node-gyp**? I'm seeing a lot of error complaining it.
If not you can install it wi... |
6,119,038 | I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it? | 2011/05/25 | [
"https://Stackoverflow.com/questions/6119038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Use a "here" document. It looks like this
```
command << HERE
text that someone types in
more text
HERE
```
You don'th have to use "HERE", you can use something that has a little more
meaning relative to the context of your code. | Have you tried `echo "Something for input" | python myPythonScript.py` ? |
6,119,038 | I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it? | 2011/05/25 | [
"https://Stackoverflow.com/questions/6119038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Have you tried `echo "Something for input" | python myPythonScript.py` ? | I haven't used python, but normally I echo a command string and pipe it to the interpreter binary like so:
```
$ echo '<?php echo "2+2\n"; ?>' | /usr/bin/php
2+2
```
I'm assuming you can do the same w/ python. |
6,119,038 | I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it? | 2011/05/25 | [
"https://Stackoverflow.com/questions/6119038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Use a "here" document. It looks like this
```
command << HERE
text that someone types in
more text
HERE
```
You don'th have to use "HERE", you can use something that has a little more
meaning relative to the context of your code. | I haven't used python, but normally I echo a command string and pipe it to the interpreter binary like so:
```
$ echo '<?php echo "2+2\n"; ?>' | /usr/bin/php
2+2
```
I'm assuming you can do the same w/ python. |
6,119,038 | I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it? | 2011/05/25 | [
"https://Stackoverflow.com/questions/6119038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | Use a "here" document. It looks like this
```
command << HERE
text that someone types in
more text
HERE
```
You don'th have to use "HERE", you can use something that has a little more
meaning relative to the context of your code. | If you really need to simulate typing into the Python interpreter, rather than piping a command to python, you can probably do this with [`expect`](http://www.nist.gov/el/msid/expect.cfm)
`expect` should be available in your distribution's repository. For details,
```
man expect
``` |
6,119,038 | I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it? | 2011/05/25 | [
"https://Stackoverflow.com/questions/6119038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193601/"
] | If you really need to simulate typing into the Python interpreter, rather than piping a command to python, you can probably do this with [`expect`](http://www.nist.gov/el/msid/expect.cfm)
`expect` should be available in your distribution's repository. For details,
```
man expect
``` | I haven't used python, but normally I echo a command string and pipe it to the interpreter binary like so:
```
$ echo '<?php echo "2+2\n"; ?>' | /usr/bin/php
2+2
```
I'm assuming you can do the same w/ python. |
28,377,690 | Complete noob with python 3. I have some code and can't figure out for the life of me why I keep getting the output I do. For some reason the elif statements aren't getting recognized. Here is the output first and the code down below:
```
3
Your fortune for today is:
Please press enter to end
```
```
#Program for ... | 2015/02/07 | [
"https://Stackoverflow.com/questions/28377690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2288612/"
] | You are not assigning `varx` to `statement` (in some cases, 3, 4 and 5th cases), but comparing. Just change all:
```
statement == varx
```
To:
```
statement = var3
```
Except from that, it seems to work. | The Problem is for example
```js
statement == var5
```
assignment statement.
Good luck! |
28,377,690 | Complete noob with python 3. I have some code and can't figure out for the life of me why I keep getting the output I do. For some reason the elif statements aren't getting recognized. Here is the output first and the code down below:
```
3
Your fortune for today is:
Please press enter to end
```
```
#Program for ... | 2015/02/07 | [
"https://Stackoverflow.com/questions/28377690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2288612/"
] | You are not assigning `varx` to `statement` (in some cases, 3, 4 and 5th cases), but comparing. Just change all:
```
statement == varx
```
To:
```
statement = var3
```
Except from that, it seems to work. | Check the lines:
```
elif randNum == 3:
statement == var3
elif randNum == 4:
statement == var4
elif randNum == 5:
statement == var5
```
'==' is for checking equality, '=' is for assigning variables. |
28,377,690 | Complete noob with python 3. I have some code and can't figure out for the life of me why I keep getting the output I do. For some reason the elif statements aren't getting recognized. Here is the output first and the code down below:
```
3
Your fortune for today is:
Please press enter to end
```
```
#Program for ... | 2015/02/07 | [
"https://Stackoverflow.com/questions/28377690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2288612/"
] | Check the lines:
```
elif randNum == 3:
statement == var3
elif randNum == 4:
statement == var4
elif randNum == 5:
statement == var5
```
'==' is for checking equality, '=' is for assigning variables. | The Problem is for example
```js
statement == var5
```
assignment statement.
Good luck! |
35,437,380 | I installed Dato's `GraphLab Create` to run with `python 27` first directly from its executable then manually via `pip` ([instructions here](https://dato.com/products/create/)) for troubleshooting.
Code:
```
import graphlab
graphlab.SFrame()
```
Output:
```
[INFO] Start server at: ipc:///tmp/graphlab_server-4908 ... | 2016/02/16 | [
"https://Stackoverflow.com/questions/35437380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4992716/"
] | capitalization error, it should be SFrame, not Sframe | You can only load a graplab package ('file.gl') by `graphlab.SFrame()`.
Instead to load a csv file use `csvf = graphlab.SFrame.read_csv('file.csv')`
for more information and other data types read this docs
<https://dato.com/products/create/docs/graphlab.data_structures.html> |
49,651,351 | I have a similar issues like [How to upload a bytes image on Google Cloud Storage from a Python script](https://stackoverflow.com/questions/46078088/how-to-upload-a-bytes-image-on-google-cloud-storage-from-a-python-script/47140336#comment86305324_47140336).
I tried this
```
from google.cloud import storage
import cv... | 2018/04/04 | [
"https://Stackoverflow.com/questions/49651351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9596737/"
] | As suggested by @A.Queue [in](https://pastebin.com/Jr6k3SW2)(gets deleted after 29 days)
```
from google.cloud import storage
import cv2
from tempfile import TemporaryFile
client = storage.Client()
bucket = client.get_bucket('test-bucket')
image=cv2.imread('example.jpg')
with TemporaryFile() as gcs_image:
image.... | You are calling `blob = bucket.get_blob(gcs_image)` which makes no sense. `get_blob()` is supposed to get a string argument, namely the name of the blob you want to get. A *name*. But you pass a file object.
I propose this code:
```
with TemporaryFile() as gcs_image:
image.tofile(gcs_image)
gcs_image.seek(0)
... |
58,134,808 | I'd like to install some special sub-package from a package.
For example, I want to create package with pkg\_a and pkg\_b. But I want to allow the user to choose which he wants to install.
What I'd like to do:
```
git clone https://github.com/pypa/sample-namespace-packages.git
cd sample-namespace-packages
touch setu... | 2019/09/27 | [
"https://Stackoverflow.com/questions/58134808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5872512/"
] | A solution for your use case seems to be similar to the one I gave here:
<https://stackoverflow.com/a/58024830/11138259>, as well as the one you linked in your question: [Python install sub-package from package](https://stackoverflow.com/questions/45324189/python-install-sub-package-from-package).
Here is an example..... | If the projects are not installed from an index such as *PyPI*, it is not possible to take advantage of the `install_requires` feature. Something like this could be done instead:
```
.
βββ NmspcPing
βΒ Β βββ nmspc.ping
βΒ Β βΒ Β βββ __init__.py
βΒ Β βββ setup.py
βββ NmspcPong
βΒ Β βββ nmspc.pong
βΒ Β βΒ Β βββ __init__.py
βΒ Β ... |
61,933,414 | ```
import tkinter as tk
from tkinter import filedialog, Text
from subprocess import call
import os
root = tk.Tk()
def buttonClick():
print('Button is clicked')
def openAgenda():
call("cd '/media/emilia/Linux/Programming/PycharmProjects/SmartschoolSelenium' && python3 SeleniumMain.py",
shell=True)
... | 2020/05/21 | [
"https://Stackoverflow.com/questions/61933414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13588940/"
] | You should include the necessary JavaScript resource like this:
```
<script src='https://www.google.com/recaptcha/api.js'></script>
```
Besides, set the right site key in the `data-sitekey` attribute.
The result is like this in IE:
[](https://i.st... | Actually it was loading loading first time in IE. So, I tried with making url different everytime by appending current datetime.
"<https://www.google.com/recaptcha/api.js?render=>" + EncodeUrl(SiteKey) + "&time="+CurrTime()
It started working. |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Also of note is that starting with Python 2.6 the built-in function open() is now an alias for the io.open() function. It was even considered removing the built-in open() in Python 3 and requiring the usage of io.open, in order to avoid accidental namespace collisions resulting from things such as "from blah import \*"... | Providing these parameters resolved my issue:
```
with open('tomorrow.txt', mode='w', encoding='UTF-8', errors='strict', buffering=1) as file:
file.write(result)
``` |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Don't do `import * from wherever` without a good reason (and there aren't many).
Your code is picking up the os.open() function instead of the built-in open() function. If you really want to use os.open(), do `import os` then call `os.open(....)`. Whichever open you want to call, read the documentation about what argu... | you have `from os import *` I also got the same error, remove that line and change it to `import os` and behind the os lib functions, add os.[function] |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Because you did `from os import *`, you are (accidenally) using os.open, which indeed requires an integer flag instead of a textual "r" or "w". Take out that line and you'll get past that error. | Don't do `import * from wherever` without a good reason (and there aren't many).
Your code is picking up the os.open() function instead of the built-in open() function. If you really want to use os.open(), do `import os` then call `os.open(....)`. Whichever open you want to call, read the documentation about what argu... |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Because you did `from os import *`, you are (accidenally) using os.open, which indeed requires an integer flag instead of a textual "r" or "w". Take out that line and you'll get past that error. | you have `from os import *` I also got the same error, remove that line and change it to `import os` and behind the os lib functions, add os.[function] |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Also of note is that starting with Python 2.6 the built-in function open() is now an alias for the io.open() function. It was even considered removing the built-in open() in Python 3 and requiring the usage of io.open, in order to avoid accidental namespace collisions resulting from things such as "from blah import \*"... | you have `from os import *` I also got the same error, remove that line and change it to `import os` and behind the os lib functions, add os.[function] |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Providing these parameters resolved my issue:
```
with open('tomorrow.txt', mode='w', encoding='UTF-8', errors='strict', buffering=1) as file:
file.write(result)
``` | you have `from os import *` I also got the same error, remove that line and change it to `import os` and behind the os lib functions, add os.[function] |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Don't do `import * from wherever` without a good reason (and there aren't many).
Your code is picking up the os.open() function instead of the built-in open() function. If you really want to use os.open(), do `import os` then call `os.open(....)`. Whichever open you want to call, read the documentation about what argu... | that's because you should do:
```
open(sys.argv[2], "w", encoding="utf-8")
```
or
```
open(sys.argv[2], "w")
``` |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Also of note is that starting with Python 2.6 the built-in function open() is now an alias for the io.open() function. It was even considered removing the built-in open() in Python 3 and requiring the usage of io.open, in order to avoid accidental namespace collisions resulting from things such as "from blah import \*"... | From <http://www.tutorialspoint.com/python/os_open.htm> you could also keep your import and use
file = os.open( "foo.txt", mode )
and the mode could be :
```
os.O_RDONLY: open for reading only
os.O_WRONLY: open for writing only
os.O_RDWR : open for reading and writing
os.O_NONBLOCK: do not block on open
os.O_APPEND... |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Because you did `from os import *`, you are (accidenally) using os.open, which indeed requires an integer flag instead of a textual "r" or "w". Take out that line and you'll get past that error. | that's because you should do:
```
open(sys.argv[2], "w", encoding="utf-8")
```
or
```
open(sys.argv[2], "w")
``` |
1,046,656 | I have a very simple python script that **should** scan a text file, which contains lines formatted as *id*='*value*' and put them into a dict. the python module is called chval.py and the input file is in.txt. here's the code:
```
import os,sys
from os import *
from sys import *
vals = {}
f = open(sys.argv[1], 'r')... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1046656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/125946/"
] | Don't do `import * from wherever` without a good reason (and there aren't many).
Your code is picking up the os.open() function instead of the built-in open() function. If you really want to use os.open(), do `import os` then call `os.open(....)`. Whichever open you want to call, read the documentation about what argu... | From <http://www.tutorialspoint.com/python/os_open.htm> you could also keep your import and use
file = os.open( "foo.txt", mode )
and the mode could be :
```
os.O_RDONLY: open for reading only
os.O_WRONLY: open for writing only
os.O_RDWR : open for reading and writing
os.O_NONBLOCK: do not block on open
os.O_APPEND... |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | This will check for versions of IE and set headers accordingly.
```
// assume you have a full path to file stored in $filename
if (!is_file($filename)) {
die('The file appears to be invalid.');
}
$filepath = str_replace('\\', '/', realpath($filename));
$filesize = filesize($filepath);
$filename = substr(strrchr('/'... | If you're trying to get the file to download every time, change the content type to 'application/octet-stream'.
Try it without the pragma statement. |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | If you're trying to get the file to download every time, change the content type to 'application/octet-stream'.
Try it without the pragma statement. | Your no-cache directives (Vary, Expires, Pragma) are causing the problem.
See <http://blogs.msdn.com/ieinternals/archive/2009/10/02/Internet-Explorer-cannot-download-over-HTTPS-when-no-cache.aspx> |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | Just use:
```
header('Content-Disposition: attachment');
```
That's all. (Facebook does the same.) | If you're trying to get the file to download every time, change the content type to 'application/octet-stream'.
Try it without the pragma statement. |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | This will check for versions of IE and set headers accordingly.
```
// assume you have a full path to file stored in $filename
if (!is_file($filename)) {
die('The file appears to be invalid.');
}
$filepath = str_replace('\\', '/', realpath($filename));
$filesize = filesize($filepath);
$filename = substr(strrchr('/'... | Your no-cache directives (Vary, Expires, Pragma) are causing the problem.
See <http://blogs.msdn.com/ieinternals/archive/2009/10/02/Internet-Explorer-cannot-download-over-HTTPS-when-no-cache.aspx> |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | This will check for versions of IE and set headers accordingly.
```
// assume you have a full path to file stored in $filename
if (!is_file($filename)) {
die('The file appears to be invalid.');
}
$filepath = str_replace('\\', '/', realpath($filename));
$filesize = filesize($filepath);
$filename = substr(strrchr('/'... | Just use:
```
header('Content-Disposition: attachment');
```
That's all. (Facebook does the same.) |
1,597,732 | Folks, I know there have been lots of threads about forcing the download dialog to pop up, but none of the solutions worked for me yet.
My app sends mail to the user's email account, notifying them that "another user sent them a message". Those messages might have links to Excel files. When the user clicks on a link ... | 2009/10/20 | [
"https://Stackoverflow.com/questions/1597732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16668/"
] | Just use:
```
header('Content-Disposition: attachment');
```
That's all. (Facebook does the same.) | Your no-cache directives (Vary, Expires, Pragma) are causing the problem.
See <http://blogs.msdn.com/ieinternals/archive/2009/10/02/Internet-Explorer-cannot-download-over-HTTPS-when-no-cache.aspx> |
12,460,943 | I have a list of log files, where each line in each file has a timestamp and the lines are pre-sorted ascending within each file. The different files can have overlapping time ranges, and my goal is to blend them together into one large file, sorted by timestamp. There can be ties in the sorting, in which case I want t... | 2012/09/17 | [
"https://Stackoverflow.com/questions/12460943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/233446/"
] | Why roll your own if there is `heapq.merge()` in the standard library? Unfortunately it doesn't provide a key argument -- you have to do the decorate - merge - undecorate dance yourself:
```
from itertools import imap
from operator import itemgetter
import heapq
def extract_timestamp(line):
"""Extract timestamp a... | You want to implement a file-based [merge sort](http://en.wikipedia.org/wiki/Merge_sort). Read a line from both files, output the older line, then read another line from that file. Once one of the files is exhausted, output all the remaining lines from the other file. |
63,214,706 | I'm working on a database with a graphical interface, I made an insert and delete method connected to the database, now I'm working on creating a search method but unfortunately not working for an unexpected error. The code Is a little bit long :
```
import sqlite3
from Tkinter import *
global all,root, main_text, num... | 2020/08/02 | [
"https://Stackoverflow.com/questions/63214706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13421322/"
] | you can give your search function an input. global statement is for an outer scope. for example when you want to make a function in another function. you can [check here](https://www.python-course.eu/python3_global_vs_local_variables.php).
and now about your code. here is a simple way that I have said the idea:
``... | I slightly redisigned your code, and it seems to work. I changed the location of the `root`, `search_ent` and `main_text`, now it's before the functions, so there won't be an error.
```
import sqlite3
from tkinter import *
global all,root, main_text, num_ent, nom_ent, search_ent
global search_ent
root = Tk()
root.con... |
63,940,493 | I want to compare every element of two matrices with the same dimensions. I want to know, if one of the elements in the first matrix is smaller than another with the same indices in the second one. I want to fill a third matrice with the values of the first, but every entry, where my criteria applies, should be a 0. Be... | 2020/09/17 | [
"https://Stackoverflow.com/questions/63940493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14285969/"
] | When you `map` over `question`:
```
question.map(function (quest){
```
The `quest` variable will be each element of that array. Which in this case that element is:
```
[
{
questions: "question1",
answer1: "answer1",
answer2: "answer2"
},
{
questions: "question2",
answer1: "answer1",
answer2:... | In short objects doesn't have .map() function.
Do this instead:
`question.map(function (quest){ return quest.questions; });` |
19,405,223 | I hope not to make a fool of myself by re-asking this question, but I just can't figure out why my fixtures are not loaded when running test. I am using python 2.7.5 and Django 1.5.3.
I can load my fixtures with `python manage.py testserver test_winning_answers`, with a location of `survey/fixtures/test_winning_answer... | 2013/10/16 | [
"https://Stackoverflow.com/questions/19405223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1014862/"
] | This will perform well if you have index on VersionColumn
```
SELECT *
FROM MainTable m
INNER JOIN JoinedTable j on j.ForeignID = m.ID
CROSS APPLY (SELECT TOP 1 *
FROM SubQueryTable sq
WHERE sq.ForeignID = j.ID
ORDER BY VersionColumn DESC) sj
``` | **Answer** :
Hi,
Below query I have created as per your requirement using Country, State and City tables.
>
>
> ```
> SELECT * FROM (
> SELECT m.countryName, j.StateName,c.CityName , ROW_NUMBER() OVER(PARTITION BY c.stateid ORDER BY c.cityid desc) AS 'x'
> FROM CountryMaster m
> INNER JOIN StateMaster j on j.Coun... |
8,373,710 | I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had `F2` and `F5` keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:
```
set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env p... | 2011/12/04 | [
"https://Stackoverflow.com/questions/8373710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501330/"
] | I finally got my function mappings working by resorting to adding mappings like this:
```
if has('mac') && ($TERM == 'xterm-256color' || $TERM == 'screen-256color')
map <Esc>OP <F1>
map <Esc>OQ <F2>
map <Esc>OR <F3>
map <Esc>OS <F4>
map <Esc>[16~ <F5>
map <Esc>[17~ <F6>
map <Esc>[18~ <F7>
map <Esc>[19~... | Regarding your colorscheme/solarized question - make sure you set up Terminal (or iTerm2, which I prefer) with the solarized profiles available in the full solarized distribution that you can download here: <http://ethanschoonover.com/solarized/files/solarized.zip>.
Then the only other issue you may run into is makin... |
8,373,710 | I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had `F2` and `F5` keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:
```
set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env p... | 2011/12/04 | [
"https://Stackoverflow.com/questions/8373710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501330/"
] | Regarding your colorscheme/solarized question - make sure you set up Terminal (or iTerm2, which I prefer) with the solarized profiles available in the full solarized distribution that you can download here: <http://ethanschoonover.com/solarized/files/solarized.zip>.
Then the only other issue you may run into is makin... | I used the following in my vimrc to copy and paste
```
if &term =~ "xterm.*"
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
function XTermPasteBegin(ret)
set pastetoggle=<Esc>[201~
set paste
return a:ret
endfunction
map <expr> <Esc>[200~ XTermPasteBegin("i")... |
8,373,710 | I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had `F2` and `F5` keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:
```
set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env p... | 2011/12/04 | [
"https://Stackoverflow.com/questions/8373710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501330/"
] | I finally got my function mappings working by resorting to adding mappings like this:
```
if has('mac') && ($TERM == 'xterm-256color' || $TERM == 'screen-256color')
map <Esc>OP <F1>
map <Esc>OQ <F2>
map <Esc>OR <F3>
map <Esc>OS <F4>
map <Esc>[16~ <F5>
map <Esc>[17~ <F6>
map <Esc>[18~ <F7>
map <Esc>[19~... | see this answer: <https://stackoverflow.com/a/10524999/210923>
essentially changing my TERM type to xterm-256color allowed me to map the function keys properly. |
8,373,710 | I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had `F2` and `F5` keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:
```
set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env p... | 2011/12/04 | [
"https://Stackoverflow.com/questions/8373710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501330/"
] | see this answer: <https://stackoverflow.com/a/10524999/210923>
essentially changing my TERM type to xterm-256color allowed me to map the function keys properly. | I used the following in my vimrc to copy and paste
```
if &term =~ "xterm.*"
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
function XTermPasteBegin(ret)
set pastetoggle=<Esc>[201~
set paste
return a:ret
endfunction
map <expr> <Esc>[200~ XTermPasteBegin("i")... |
8,373,710 | I have recently started using a Mac OS X Lion system and tried to use Vim in terminal. I previously had a .vimrc file in my Ubuntu system and had `F2` and `F5` keys mapped to pastetoggle and run python interpreter. Here are the two lines I have for it:
```
set pastetoggle=<F2>
map <buffer> <F5> :wa<CR>:!/usr/bin/env p... | 2011/12/04 | [
"https://Stackoverflow.com/questions/8373710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501330/"
] | I finally got my function mappings working by resorting to adding mappings like this:
```
if has('mac') && ($TERM == 'xterm-256color' || $TERM == 'screen-256color')
map <Esc>OP <F1>
map <Esc>OQ <F2>
map <Esc>OR <F3>
map <Esc>OS <F4>
map <Esc>[16~ <F5>
map <Esc>[17~ <F6>
map <Esc>[18~ <F7>
map <Esc>[19~... | I used the following in my vimrc to copy and paste
```
if &term =~ "xterm.*"
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
function XTermPasteBegin(ret)
set pastetoggle=<Esc>[201~
set paste
return a:ret
endfunction
map <expr> <Esc>[200~ XTermPasteBegin("i")... |
67,712,314 | Can anyone see what im doing wrong here? works fine locally, but when running it in docker it cant seem to find my modules ...
The **init**.py files are emtpy if that info could help. Im no expert in docker and non of the tips I've googled/stackoverflowed so far has panned out, such as adding pythonpath env in the doc... | 2021/05/26 | [
"https://Stackoverflow.com/questions/67712314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14994913/"
] | After running `docker container run -it your-docker-container bash` and checked the files, it seems docker does not copy the file hierarchy as i expected. all files was under the same folder /app. none of my subfolder from the project in my local files were added, just the files those contained. No wonder i got ModuleN... | I had almost the same issue with this and I try to fix it not by changing the directory structure of my application or how I copy the files but by running the application directly using gunicorn.
I run it with the following command :
`gunicorn -k uvicorn.workers.UvicornWorker run:app`
that can either be updated in t... |
71,907,288 | Question
========
What is the shortest and most efficient (preferrable most efficient) way of reading in a single depth folder and creating a file tree that consists of the longest substrings of each file?
start with this
---------------
```
.
βββ hello
βββ lima_peru
βββ limabeans
βββ limes
βββ limit
βββ what_are_th... | 2022/04/18 | [
"https://Stackoverflow.com/questions/71907288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17356304/"
] | You are using the same input `ID` in `colorId` when you select the same group the second time. However, you need unique input `ID`s in shiny. I have added a counter to change it. Try this.
```
library(shinyjs) # useShinyjs
library(ggplot2)
library(RColorBrewer)
library(shiny)
ui <- fluidPage(
titlePanel("Reprex"),
... | Following up with @YBS's response to my comment, I resorted to precomputing all the fields that could be made with the input file and using `conditionalPanel()` to selectively show them.
This has the theoretical disadvantage that another file cannot be loaded in, but in practice I'm not seeing it. But I can use @YBS's... |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | Here is my stab at it. This uses regular expressions.
```
import re
pattern = re.compile("(of|the|in|for|at)\W", re.I)
phrases = ['of New York', 'of the New York']
map(lambda phrase: pattern.sub("", phrase), phrases) # ['New York', 'New York']
```
Sans `lambda`:
```
[pattern.sub("", phrase) for phrase in phrases]... | ```
>>> import re
>>> noise_words_list = ['of', 'the', 'in', 'for', 'at']
>>> phrases = ['of New York', 'of the New York']
>>> noise_re = re.compile('\\b(%s)\\W'%('|'.join(map(re.escape,noise_words_list))),re.I)
>>> [noise_re.sub('',p) for p in phrases]
['New York', 'New York']
``` |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | Here is my stab at it. This uses regular expressions.
```
import re
pattern = re.compile("(of|the|in|for|at)\W", re.I)
phrases = ['of New York', 'of the New York']
map(lambda phrase: pattern.sub("", phrase), phrases) # ['New York', 'New York']
```
Sans `lambda`:
```
[pattern.sub("", phrase) for phrase in phrases]... | Since you would like to know what you are doing wrong, this line:
```
stuff = [place.replace(w, "").strip() for w in noise_words_list if place.startswith(w)]
```
takes place, and then begins to loop over words. First it checks for "of". Your place (e.g. "of the New York") is checked to see if it starts with "of". It... |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | Here is my stab at it. This uses regular expressions.
```
import re
pattern = re.compile("(of|the|in|for|at)\W", re.I)
phrases = ['of New York', 'of the New York']
map(lambda phrase: pattern.sub("", phrase), phrases) # ['New York', 'New York']
```
Sans `lambda`:
```
[pattern.sub("", phrase) for phrase in phrases]... | Without regexp you could do like this:
```
places = ['of New York', 'of the New York']
noise_words_set = {'of', 'the', 'at', 'for', 'in'}
stuff = [' '.join(w for w in place.split() if w.lower() not in noise_words_set)
for place in places
]
print stuff
``` |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | ```
>>> import re
>>> noise_words_list = ['of', 'the', 'in', 'for', 'at']
>>> phrases = ['of New York', 'of the New York']
>>> noise_re = re.compile('\\b(%s)\\W'%('|'.join(map(re.escape,noise_words_list))),re.I)
>>> [noise_re.sub('',p) for p in phrases]
['New York', 'New York']
``` | Since you would like to know what you are doing wrong, this line:
```
stuff = [place.replace(w, "").strip() for w in noise_words_list if place.startswith(w)]
```
takes place, and then begins to loop over words. First it checks for "of". Your place (e.g. "of the New York") is checked to see if it starts with "of". It... |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | Without regexp you could do like this:
```
places = ['of New York', 'of the New York']
noise_words_set = {'of', 'the', 'at', 'for', 'in'}
stuff = [' '.join(w for w in place.split() if w.lower() not in noise_words_set)
for place in places
]
print stuff
``` | ```
>>> import re
>>> noise_words_list = ['of', 'the', 'in', 'for', 'at']
>>> phrases = ['of New York', 'of the New York']
>>> noise_re = re.compile('\\b(%s)\\W'%('|'.join(map(re.escape,noise_words_list))),re.I)
>>> [noise_re.sub('',p) for p in phrases]
['New York', 'New York']
``` |
3,510,846 | Sorry if the question is bit confusing. This is similar to [this question](https://stackoverflow.com/questions/2553668/how-to-remove-list-of-words-from-strings)
I think this the above question is close to what I want, but in Clojure.
There is [another](https://stackoverflow.com/questions/3136689/find-and-replace-str... | 2010/08/18 | [
"https://Stackoverflow.com/questions/3510846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24382/"
] | Without regexp you could do like this:
```
places = ['of New York', 'of the New York']
noise_words_set = {'of', 'the', 'at', 'for', 'in'}
stuff = [' '.join(w for w in place.split() if w.lower() not in noise_words_set)
for place in places
]
print stuff
``` | Since you would like to know what you are doing wrong, this line:
```
stuff = [place.replace(w, "").strip() for w in noise_words_list if place.startswith(w)]
```
takes place, and then begins to loop over words. First it checks for "of". Your place (e.g. "of the New York") is checked to see if it starts with "of". It... |
56,401,685 | ### Concepts of objects in python classes
While reading about old style and new style classes in Python , term object occurs many times. What is exactly an object?
Is it a base class or simply an object or a parameter ?
for e.g. :
New style for creating a class in python
```
class Class_name(object):
pass
```
I... | 2019/05/31 | [
"https://Stackoverflow.com/questions/56401685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5084760/"
] | All objects in python are ultimately derived from "object". You don't need to be explicit about it in python 3, but it's common to explicitly derive from object. | Object is a generic term. It could be a class, a string, or any type. (and probably many other things)
As an example look at the term OOP, "Object oriented programming". Object has the same meaning here. |
56,401,685 | ### Concepts of objects in python classes
While reading about old style and new style classes in Python , term object occurs many times. What is exactly an object?
Is it a base class or simply an object or a parameter ?
for e.g. :
New style for creating a class in python
```
class Class_name(object):
pass
```
I... | 2019/05/31 | [
"https://Stackoverflow.com/questions/56401685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5084760/"
] | From [[Python 2.Docs]: Built-in Functions - class object](https://docs.python.org/2/library/functions.html#object) (**emphasis** is mine):
>
> Return a new featureless object. **[object](https://docs.python.org/2/library/functions.html#object) is a base for all new style classes**. It has the methods that are common ... | Object is a generic term. It could be a class, a string, or any type. (and probably many other things)
As an example look at the term OOP, "Object oriented programming". Object has the same meaning here. |
56,401,685 | ### Concepts of objects in python classes
While reading about old style and new style classes in Python , term object occurs many times. What is exactly an object?
Is it a base class or simply an object or a parameter ?
for e.g. :
New style for creating a class in python
```
class Class_name(object):
pass
```
I... | 2019/05/31 | [
"https://Stackoverflow.com/questions/56401685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5084760/"
] | An Object is something in any Object Oriented language including Python, C#, Java and even JavaScript these days. Objects are also prevalent in 3d modeling software but are not per se the same thing.
An Object is an INSTANTIATED class. A class is a blueprint for creating object. Almost everything in Python is an obje... | Object is a generic term. It could be a class, a string, or any type. (and probably many other things)
As an example look at the term OOP, "Object oriented programming". Object has the same meaning here. |
56,401,685 | ### Concepts of objects in python classes
While reading about old style and new style classes in Python , term object occurs many times. What is exactly an object?
Is it a base class or simply an object or a parameter ?
for e.g. :
New style for creating a class in python
```
class Class_name(object):
pass
```
I... | 2019/05/31 | [
"https://Stackoverflow.com/questions/56401685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5084760/"
] | From [[Python 2.Docs]: Built-in Functions - class object](https://docs.python.org/2/library/functions.html#object) (**emphasis** is mine):
>
> Return a new featureless object. **[object](https://docs.python.org/2/library/functions.html#object) is a base for all new style classes**. It has the methods that are common ... | All objects in python are ultimately derived from "object". You don't need to be explicit about it in python 3, but it's common to explicitly derive from object. |
56,401,685 | ### Concepts of objects in python classes
While reading about old style and new style classes in Python , term object occurs many times. What is exactly an object?
Is it a base class or simply an object or a parameter ?
for e.g. :
New style for creating a class in python
```
class Class_name(object):
pass
```
I... | 2019/05/31 | [
"https://Stackoverflow.com/questions/56401685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5084760/"
] | From [[Python 2.Docs]: Built-in Functions - class object](https://docs.python.org/2/library/functions.html#object) (**emphasis** is mine):
>
> Return a new featureless object. **[object](https://docs.python.org/2/library/functions.html#object) is a base for all new style classes**. It has the methods that are common ... | An Object is something in any Object Oriented language including Python, C#, Java and even JavaScript these days. Objects are also prevalent in 3d modeling software but are not per se the same thing.
An Object is an INSTANTIATED class. A class is a blueprint for creating object. Almost everything in Python is an obje... |
63,046,777 | I have in my utils.py the following functions which I use for debugging info ...
```
say = print
log = print
```
I want to declare them in such a way, so that I can switch them ON/OFF. If possible on per module basis.
F.e. let say I want to test something and enable/disable printing ...
I don't want to use loggi... | 2020/07/23 | [
"https://Stackoverflow.com/questions/63046777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1019129/"
] | You can always redefine say/log to do nothing later on.
```
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> say = print
>>> say("hello")
hello
>>> def say(*args, **kwargs):
... return None
...
>>> say("hello")
>>>
``` | You could used `sys.stdout.write("\033[K")` to overwrite/clear the previous line at the terminal when you don't want it logged or like:
```
def removeLine(dontWant):
if dontWant == True:
sys.stdout.write("\033[K")
```
where dontWant is set within the module or class or as a glob even or whatever based on... |
63,046,777 | I have in my utils.py the following functions which I use for debugging info ...
```
say = print
log = print
```
I want to declare them in such a way, so that I can switch them ON/OFF. If possible on per module basis.
F.e. let say I want to test something and enable/disable printing ...
I don't want to use loggi... | 2020/07/23 | [
"https://Stackoverflow.com/questions/63046777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1019129/"
] | You can always redefine say/log to do nothing later on.
```
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> say = print
>>> say("hello")
hello
>>> def say(*args, **kwargs):
... return None
...
>>> say("hello")
>>>
``` | At the end this is what I wrote :
<https://github.com/vsraptor/quick-debug/blob/master/debug.py>
Quick debugging : if you are like me and are not used to a debugger
or logging is too cumbersome, then this is for you. |
55,437,583 | I would like to convert HTML code to JavaScript. Currently I can send a message from the HTML file to a python server, which is then reversed and sent back to the HTML through socket io. I used this tutorial: <https://tutorialedge.net/python/python-socket-io-tutorial/>
What I want to do now is rather than send the mes... | 2019/03/31 | [
"https://Stackoverflow.com/questions/55437583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8973785/"
] | Script tags don't work in node. You need to use require to import modules.
You can use the [socket.io client](https://www.npmjs.com/package/socket.io-client) module to connect to socket io using node. Note that you'll have to `npm install` it before use
Example connection code adapted from socket.io client readme:
`... | `<script>` tags are HTML tags - you can't have them in a JavaScript file. Just place your JavaScript:
```
const socket = io("http://localhost:8080");
function sendMsg() {
socket.emit("message", "HELLO WORLD");
}
socket.on("message", function(data) {
console.log(data);
});
``` |
27,925,447 | I have the following dataframe.
```
c1 c2 v1 v2
0 a a 1 2
1 a a 2 3
2 b a 3 1
3 b a 4 5
5 c d 5 0
```
I wish to have the following output.
```
c1 c2 v1 v2
0 a a 2 3
1 b a 4 5
2 c d 5 0
```
The rule. First group dataframe by c1, c2. Then... | 2015/01/13 | [
"https://Stackoverflow.com/questions/27925447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2063033/"
] | I wanted to add a comment, but my reputation doesn't allow me :). So I will risk posting an incomplete answer here..
As a common practice, when you have a form to submit, you should use @using (Html.BeginForm()). This will take care of all the technicalities of having a form and avoid unnecessary errors (which I can't... | The proper way to redirect is to return RedirectResult.
In your case it seems to be:
```
[HttpGet]
public ActionResult Create(Clients client)
{
if (ModelState.IsValid)
{
_db.Clients.Add(client);
_db.SaveChanges();
}
return new Red... |
15,587,311 | ```
def parabola(h, k, xCoordinates):
```
h
is
the
x
coordinate
where
the
parabola
touches
the
x
axis
and
k
is
the
y
coordinate
where
the
parabola
intersects
the
y
axis
and
xCoordinates
is
a
list
of
x
coordinates
along
the
major
axis.
The
function
returns
a
list
of
y
coordinates
using
the
equation
shown
below.
There
... | 2013/03/23 | [
"https://Stackoverflow.com/questions/15587311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
pricing::pricing(void)
{
m(10,0.0,0.01,50);
}
```
This attempts to *call* `m` as though it were a function (if it had overloaded `operator()`, you would be able to do this, which is what the error is talking about). To initialise `m` instead, use the member initialization list:
```
pricing::pricing(void)
: m(1... | pricing.cpp
```
#include "pricing.h"
pricing::pricing()
: m(10,0.0,0.01,50)
{
}
double pricing::expectedValue()
{
return m.samplePaths[2][3];
}
```
pricing.h
```
#ifndef PRICING_H
#define PRICING_H
#include "monteCarlo.h"
#include <vector>
class pricing
{
public:
pricing();
double euroCall();
... |
15,820,247 | Raymond Hettinger surprised quite a few people when he showed slides 36 and 37. <https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger> -- Many people knew that the with statement could be used for opening files, but not these new things. Looking at python 3.3 docs o... | 2013/04/04 | [
"https://Stackoverflow.com/questions/15820247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/411046/"
] | First, you don't ask if something is "withable", you ask if it's a "context manager".\*
For example, in the docs you linked (which are from 3.1, not 3.3, by the way):
>
> Currently, `Lock`, `RLock`, `Condition`, `Semaphore`, and `BoundedSemaphore` objects may be used as `with` statement context managers.
>
>
>
M... | afaik any class/object that that implements `__exit__` method (you may also need to implement `__enter__`)
```
>>>dir(file)
#notice it includes __enter__ and __exit__
```
so
```
def supportsWith(some_ob):
if "__exit__" in dir(some_ob): #could justas easily used hasattr
return True
``` |
15,820,247 | Raymond Hettinger surprised quite a few people when he showed slides 36 and 37. <https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger> -- Many people knew that the with statement could be used for opening files, but not these new things. Looking at python 3.3 docs o... | 2013/04/04 | [
"https://Stackoverflow.com/questions/15820247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/411046/"
] | First, you don't ask if something is "withable", you ask if it's a "context manager".\*
For example, in the docs you linked (which are from 3.1, not 3.3, by the way):
>
> Currently, `Lock`, `RLock`, `Condition`, `Semaphore`, and `BoundedSemaphore` objects may be used as `with` statement context managers.
>
>
>
M... | Objects that work with Python's `with` statement are called *context managers*. In typically Pythonic fashion, whether an object is a context manager depends only on whether you can do "context manager-y" things with it. (This strategy is called [duck typing](http://en.wikipedia.org/wiki/Duck_typing).)
So what constit... |
46,439,557 | I have a .txt file, each line is in the format like this
1 2,10 3,20
2 6,87
.
.
.
This file actually represents a graph, line 1 says that Vertex 1 have directed edge to vertex 2 and the length is 10, vertex 1 also have directed edge to vertex 3 and the length is 20. Line 2 says that Vertex 2 only have one directe... | 2017/09/27 | [
"https://Stackoverflow.com/questions/46439557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8680259/"
] | Providing you have a method that takes `[FromBody]TestStatus status` as a parameter.
* Click on **Body** tab and select **raw**, then JSON(application/json).
* Use this Json:
```
{
"TestStatus": "expiredTest"
}
```
* Send!
I think above is your case as you stated: "take enum object as a body". Below are some mo... | Just pass 0,1,2... interger in the json body to pass enum objects.
Choose 0 if required to pass the first enum object.
Exmple:
{
"employee": 0
} |
46,439,557 | I have a .txt file, each line is in the format like this
1 2,10 3,20
2 6,87
.
.
.
This file actually represents a graph, line 1 says that Vertex 1 have directed edge to vertex 2 and the length is 10, vertex 1 also have directed edge to vertex 3 and the length is 20. Line 2 says that Vertex 2 only have one directe... | 2017/09/27 | [
"https://Stackoverflow.com/questions/46439557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8680259/"
] | With a method taking the enum as the body, the enum value needs to be entered without curly brackets, simply
```
"expiredTest"
```
or
```
2
```
directly in the Body tab (with `raw` and `JSON(application/json)` and an `ASP.NET Core backend`). | Just pass 0,1,2... interger in the json body to pass enum objects.
Choose 0 if required to pass the first enum object.
Exmple:
{
"employee": 0
} |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
E... | I found this code worked for me.. Hope this will be useful to somebody.
I was using SMTP godaddy webmail..you can put this code into your django setting file.
Since you cannot set Both SSL and TSL together... if you do so you get the error
something as, **At one time either SSL or TSL can be true....**
setting.... |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
E... | I managed to decide to access the site
<https://sso.secureserver.net/?app=emailsetup&realm=pass&>
It seems that when accessing, you can enable email for external use.
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER='aXXXX@xxxx'
EMAIL_HOST_PASSWO... |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
E... | It's been a while but, maybe the answer can help somebody else. I just talked to GoDaddy about the issue and the needed configration they told me was like,
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
DEFAULT_FROM_EMA... |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
E... | use 'smtpout.asia.secureserver.net' as EMAIL\_HOST in Django settings.py. you can refer to the GoDaddy email help page link.
<https://in.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071> |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.
settings.py
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
E... | In my case, this way work for me:
#settings.py
```
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your@domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your@domain'
``` |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | I found this code worked for me.. Hope this will be useful to somebody.
I was using SMTP godaddy webmail..you can put this code into your django setting file.
Since you cannot set Both SSL and TSL together... if you do so you get the error
something as, **At one time either SSL or TSL can be true....**
setting.... | In my case, this way work for me:
#settings.py
```
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your@domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your@domain'
``` |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | I managed to decide to access the site
<https://sso.secureserver.net/?app=emailsetup&realm=pass&>
It seems that when accessing, you can enable email for external use.
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER='aXXXX@xxxx'
EMAIL_HOST_PASSWO... | In my case, this way work for me:
#settings.py
```
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your@domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your@domain'
``` |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | It's been a while but, maybe the answer can help somebody else. I just talked to GoDaddy about the issue and the needed configration they told me was like,
```
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
DEFAULT_FROM_EMA... | In my case, this way work for me:
#settings.py
```
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your@domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your@domain'
``` |
47,483,015 | I have these settings
```
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True
```
Speaking to Godaddy I have found out th... | 2017/11/25 | [
"https://Stackoverflow.com/questions/47483015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1333598/"
] | use 'smtpout.asia.secureserver.net' as EMAIL\_HOST in Django settings.py. you can refer to the GoDaddy email help page link.
<https://in.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071> | In my case, this way work for me:
#settings.py
```
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your@domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your@domain'
``` |
11,027,749 | What's going on? I tried iPython and the regular Python interpreter, both show ^[[A and ^[[B for the up and down arrows instead of previous commands.
**Platform:** Ubuntu 12.04.
**Python:** 2.7.3 installed with pythonbrew
**Terminal:** iTerm 2 on Mac OSX 10.6, connected over SSH.
Has never worked in the Python shel... | 2012/06/14 | [
"https://Stackoverflow.com/questions/11027749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1377021/"
] | Since you installed Python with pythonbrew, you must install the `libreadline-dev` package in your package manager *then* recompile Python.
The package is named `libreadline-dev` or something similar in most Linux distributions (Ubuntu, Debian, Fedora...). This step is not required on Gentoo or Arch systems, which alw... | `libreadline-dev` was not enough, what solved it for me is to install the `readline` package:
```
pip install readline
``` |
3,663,762 | In my models.py, I want to have an optional field to a foreign key. I tried this:
```
field = models.ForeignKey(MyModel, null=True, blank=True, default=None)
```
I am getting this error:
```
model.mymodel_id may not be NULL
```
I am using sqlite. In case it is helpful, here is the exception location:
```
/usr/l... | 2010/09/08 | [
"https://Stackoverflow.com/questions/3663762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440221/"
] | If it was previously not null and you synced it before then resyncing won't change it. Either drop the table, use a migration tool such as South, or alter the column in SQL directly. | I believe that it has to be both `null=True` and `blank=True`. |
3,663,762 | In my models.py, I want to have an optional field to a foreign key. I tried this:
```
field = models.ForeignKey(MyModel, null=True, blank=True, default=None)
```
I am getting this error:
```
model.mymodel_id may not be NULL
```
I am using sqlite. In case it is helpful, here is the exception location:
```
/usr/l... | 2010/09/08 | [
"https://Stackoverflow.com/questions/3663762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440221/"
] | If it was previously not null and you synced it before then resyncing won't change it. Either drop the table, use a migration tool such as South, or alter the column in SQL directly. | I'm not sure on this one, but I think you need to lose the "default=None" and do a reset/syncdb. The default overrides the null/blank info. I.e. if you give a blank in the admin it will store None (whose representation may vary from DB to DB). I would need to look at the code/docs to be more certain. |
3,663,762 | In my models.py, I want to have an optional field to a foreign key. I tried this:
```
field = models.ForeignKey(MyModel, null=True, blank=True, default=None)
```
I am getting this error:
```
model.mymodel_id may not be NULL
```
I am using sqlite. In case it is helpful, here is the exception location:
```
/usr/l... | 2010/09/08 | [
"https://Stackoverflow.com/questions/3663762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440221/"
] | If it was previously not null and you synced it before then resyncing won't change it. Either drop the table, use a migration tool such as South, or alter the column in SQL directly. | I have the same problem, and drilled down to the table creation process itself (because the problems arise in doing tests too.)
For a model like this:
```
class MyModel(models.Model):
owner = models.ForeignKey(User, null=True, blank=True)
```
the generated sql (with `./manage.py sql`) is:
```
CREATE TABLE `app... |
3,663,762 | In my models.py, I want to have an optional field to a foreign key. I tried this:
```
field = models.ForeignKey(MyModel, null=True, blank=True, default=None)
```
I am getting this error:
```
model.mymodel_id may not be NULL
```
I am using sqlite. In case it is helpful, here is the exception location:
```
/usr/l... | 2010/09/08 | [
"https://Stackoverflow.com/questions/3663762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440221/"
] | I believe that it has to be both `null=True` and `blank=True`. | I'm not sure on this one, but I think you need to lose the "default=None" and do a reset/syncdb. The default overrides the null/blank info. I.e. if you give a blank in the admin it will store None (whose representation may vary from DB to DB). I would need to look at the code/docs to be more certain. |
3,663,762 | In my models.py, I want to have an optional field to a foreign key. I tried this:
```
field = models.ForeignKey(MyModel, null=True, blank=True, default=None)
```
I am getting this error:
```
model.mymodel_id may not be NULL
```
I am using sqlite. In case it is helpful, here is the exception location:
```
/usr/l... | 2010/09/08 | [
"https://Stackoverflow.com/questions/3663762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440221/"
] | I believe that it has to be both `null=True` and `blank=True`. | I have the same problem, and drilled down to the table creation process itself (because the problems arise in doing tests too.)
For a model like this:
```
class MyModel(models.Model):
owner = models.ForeignKey(User, null=True, blank=True)
```
the generated sql (with `./manage.py sql`) is:
```
CREATE TABLE `app... |
36,648,800 | I have a BaseEntity class, which defines a bunch (a lot) of non-required properties and has most of functionality. I extend this class in two others, which have some extra methods, as well as initialize one required property.
```
class BaseEntity(object):
def __init__(self, request_url):
self.clearAllFilt... | 2016/04/15 | [
"https://Stackoverflow.com/questions/36648800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2521764/"
] | One way to do it:
```
import copy
class A(object):
def __init__(self, sth, blah):
self.sth = sth
self.blah = blah
def do_sth(self):
print(self.sth, self.blah)
class B(A):
def __init__(self, param):
self.param = param
def do_sth(self):
print(self.param, self.s... | I had the same problem as the OP and was able to use the idea from RadosΕaw Εazarz above of explicitly setting the **class** attribute of the object to the subclass, but without the deep copy:
```
class A:
def __init__(a) : pass
def amethod(a) : return 'aresult'
class B(A):
def __init__(b) : pass
def ... |
61,738,541 | The first line works, but the second doesn't:
```
print(np.fromfunction(lambda x, y: 10 * x + y , (3, 5), dtype=int))
print(np.fromfunction(lambda x, y: str(10 * x + y), (3, 5), dtype=str))
[[ 0 1 2 3 4]
[10 11 12 13 14]
[20 21 22 23 24]]
Traceback (most recent call last):
File "<stdin>", line 1, in <modu... | 2020/05/11 | [
"https://Stackoverflow.com/questions/61738541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | They are both text files with code in them.
The difference isn't in the files, but in how your webserver treats them.
It is configured to run files with a `.php` extension though a PHP engine, and to serve up `.html` files directly. | You have to open the php file through an apache (or other php-handling) server. For instance, if you use XAMPP, and have index.php in the XAMPP directory, you would open a browser and go to localhost/index.php. The server then converts it into html, which a browser can handle. |
24,821,340 | First of all an introduction to my development environment:
```
OS: Windows.
SDK: Microsoft Visual Studio 2008.
```
Earlier today I was facing the problem of trying to define a Timer inside a class. My class is interfacing a Python embedded module and a C++ backend, My problem is that I need to receive some time eve... | 2014/07/18 | [
"https://Stackoverflow.com/questions/24821340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3227543/"
] | Create a static map of your Class object:
```
static std::map<UINT_PTR, CMyClass*> m_CMyClassMap; //declaration
```
At the time of object creation insert the object in this map:
```
CMyClass myClassObj;
CMyClassMap.insert(std::pair<int, CMyClass*>(0, &myClassObj));
```
Now you can use it in static methods to acce... | So long as there is only one instance of this class, there is an easy (if somewhat ugly) solution: Declare your class object and then store a pointer to it in a global object. E.g.,
```
MyClass myObject;
MyClass* self = &myObject;
```
Then inside your static member, you can use self->myMethod() or self->myData to r... |
14,140,902 | I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14140902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165435/"
] | I've found the answer you have to use the same connection string that would be used in a tnsnames.ora file in the connection string after the '@" like so
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | cx\_Oracle supports the passing of a service\_name to the makedsn function.
<http://cx-oracle.sourceforge.net/html/module.html?highlight=makedsn#cx_Oracle.makedsn>
It would be nice if the create\_engine() API passed the service\_name through to the underlying call it makes to makedsn...something like this:
```
oracl... |
14,140,902 | I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14140902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165435/"
] | I've found the answer you have to use the same connection string that would be used in a tnsnames.ora file in the connection string after the '@" like so
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | ```
import cx_Oracle
dsnStr = cx_Oracle.makedsn('myhost','port','MYSERVICENAME')
connect_str = 'oracle://user:password@' + dsnStr.replace('SID', 'SERVICE_NAME')
```
The makedns will create a TNS like this:
>
> (DESCRIPTION=(ADDRESS\_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1530)))(CONNECT\_DATA=(SID=MYSERVICE... |
14,140,902 | I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14140902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165435/"
] | I've found the answer you have to use the same connection string that would be used in a tnsnames.ora file in the connection string after the '@" like so
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | The module sqlalchemy now can handle oracle service\_names. Have a look:
```
from sqlalchemy.engine import create_engine
DIALECT = 'oracle'
SQL_DRIVER = 'cx_oracle'
USERNAME = 'your_username' #enter your username
PASSWORD = 'your_password' #enter your password
HOST = 'subdomain.domain.tld' #enter the oracle db host ... |
14,140,902 | I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14140902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165435/"
] | ```
import cx_Oracle
dsnStr = cx_Oracle.makedsn('myhost','port','MYSERVICENAME')
connect_str = 'oracle://user:password@' + dsnStr.replace('SID', 'SERVICE_NAME')
```
The makedns will create a TNS like this:
>
> (DESCRIPTION=(ADDRESS\_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1530)))(CONNECT\_DATA=(SID=MYSERVICE... | cx\_Oracle supports the passing of a service\_name to the makedsn function.
<http://cx-oracle.sourceforge.net/html/module.html?highlight=makedsn#cx_Oracle.makedsn>
It would be nice if the create\_engine() API passed the service\_name through to the underlying call it makes to makedsn...something like this:
```
oracl... |
14,140,902 | I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)
```
from sqlalchemy import create_engine
if __name__ == "__main__": ... | 2013/01/03 | [
"https://Stackoverflow.com/questions/14140902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/165435/"
] | The module sqlalchemy now can handle oracle service\_names. Have a look:
```
from sqlalchemy.engine import create_engine
DIALECT = 'oracle'
SQL_DRIVER = 'cx_oracle'
USERNAME = 'your_username' #enter your username
PASSWORD = 'your_password' #enter your password
HOST = 'subdomain.domain.tld' #enter the oracle db host ... | cx\_Oracle supports the passing of a service\_name to the makedsn function.
<http://cx-oracle.sourceforge.net/html/module.html?highlight=makedsn#cx_Oracle.makedsn>
It would be nice if the create\_engine() API passed the service\_name through to the underlying call it makes to makedsn...something like this:
```
oracl... |
36,234,988 | I feel it is a more general question, but here is an example I am considering: I have a python class which during its initialization goes through a zip archive and extracts some data.
Should the code-chunk below be written explicitly inside the "def init" or should it be made as a method outside which will be called ... | 2016/03/26 | [
"https://Stackoverflow.com/questions/36234988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3286832/"
] | If you want to execute the statements you are showing in more then one place, then there's really no discussion. Without a method or a function for this task, you will be violating the [DRY](http://c2.com/cgi/wiki?DontRepeatYourself) principle.
Otherwise... well I'd write a method regardless. The task you are showing ... | It is perfectly fine for `__init__()` to call other functions, including methods of the same class. |
52,827,722 | What is the naming convention in python community to set names for project folders and subfolders?
```
my-great-python-project
my_great_python_project
myGreatPythonProject
MyGreatPythonProject
```
I find mixed up in the github.
Appreciate your expert opinion. | 2018/10/16 | [
"https://Stackoverflow.com/questions/52827722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5164382/"
] | There are three conventions, which you might find confusing.
1. The standard
[PEP8](https://www.python.org/dev/peps/pep-0008/) defines a standard for how to name packages and modules:
>
> Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python pa... | >
> Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. [Pep 8 Style Guide](https://www.python.org/dev/peps/pep-0008/#naming-conventions)
>
>
>
This is the recommendation for packages, which is the main folder containing modules, for testing, setup, and scri... |
52,827,722 | What is the naming convention in python community to set names for project folders and subfolders?
```
my-great-python-project
my_great_python_project
myGreatPythonProject
MyGreatPythonProject
```
I find mixed up in the github.
Appreciate your expert opinion. | 2018/10/16 | [
"https://Stackoverflow.com/questions/52827722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5164382/"
] | Here is an example of how we might organize a repository called `altimeter-valport-lcm` which contains the package `altimeter_valeport_lcm`. The package contains the module `altimeter_valeport_lcm.parser`:
```
altimeter-valeport-lcm/
βββ altimeter_valeport_lcm
β βββ __init__.py
β βββ __main__.py
β βββ parser.py
... | >
> Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. [Pep 8 Style Guide](https://www.python.org/dev/peps/pep-0008/#naming-conventions)
>
>
>
This is the recommendation for packages, which is the main folder containing modules, for testing, setup, and scri... |
52,827,722 | What is the naming convention in python community to set names for project folders and subfolders?
```
my-great-python-project
my_great_python_project
myGreatPythonProject
MyGreatPythonProject
```
I find mixed up in the github.
Appreciate your expert opinion. | 2018/10/16 | [
"https://Stackoverflow.com/questions/52827722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5164382/"
] | There are three conventions, which you might find confusing.
1. The standard
[PEP8](https://www.python.org/dev/peps/pep-0008/) defines a standard for how to name packages and modules:
>
> Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python pa... | Here is an example of how we might organize a repository called `altimeter-valport-lcm` which contains the package `altimeter_valeport_lcm`. The package contains the module `altimeter_valeport_lcm.parser`:
```
altimeter-valeport-lcm/
βββ altimeter_valeport_lcm
β βββ __init__.py
β βββ __main__.py
β βββ parser.py
... |
58,475,837 | I am trying to learn the functional programming way of doing things in python. I am trying to serialize a list of strings in python using the following code
```
S = ["geeks", "are", "awesome"]
reduce(lambda x, y: (str(len(x)) + '~' + x) + (str(len(y)) + '~' + y), S)
```
I am expecting:
```
5~geeks3~are7~awesome
`... | 2019/10/20 | [
"https://Stackoverflow.com/questions/58475837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6101835/"
] | `reduce` function on each current iteration relies on previous item/calculation (the nature of all ***reduce*** routines), that's why you got `12` at the start of the resulting string: on the 1st pass the item was `5~geeks3~are` with length `12` and that was used/prepended on next iteration.
Instead, you can go with s... | The `reduce` function is for aggregation. What you're trying to do is mapping instead.
You can use the `map` function for the purpose:
```
''.join(map(lambda x: str(len(x)) + '~' + x, S))
```
This returns:
```
5~geeks3~are7~awesome
``` |
58,475,837 | I am trying to learn the functional programming way of doing things in python. I am trying to serialize a list of strings in python using the following code
```
S = ["geeks", "are", "awesome"]
reduce(lambda x, y: (str(len(x)) + '~' + x) + (str(len(y)) + '~' + y), S)
```
I am expecting:
```
5~geeks3~are7~awesome
`... | 2019/10/20 | [
"https://Stackoverflow.com/questions/58475837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6101835/"
] | You need to add the `initializer` parameter - an empty string to the `reduce()` function. It will be the first argument passed to the `lambda` function before the values from the list.
```
from functools import reduce
S = ["geeks", "are", "awesome"]
reduce(lambda x, y: x + f'{len(y)}~{y}', S, '')
# 5~geeks3~are7~awe... | The `reduce` function is for aggregation. What you're trying to do is mapping instead.
You can use the `map` function for the purpose:
```
''.join(map(lambda x: str(len(x)) + '~' + x, S))
```
This returns:
```
5~geeks3~are7~awesome
``` |
58,475,837 | I am trying to learn the functional programming way of doing things in python. I am trying to serialize a list of strings in python using the following code
```
S = ["geeks", "are", "awesome"]
reduce(lambda x, y: (str(len(x)) + '~' + x) + (str(len(y)) + '~' + y), S)
```
I am expecting:
```
5~geeks3~are7~awesome
`... | 2019/10/20 | [
"https://Stackoverflow.com/questions/58475837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6101835/"
] | `reduce` function on each current iteration relies on previous item/calculation (the nature of all ***reduce*** routines), that's why you got `12` at the start of the resulting string: on the 1st pass the item was `5~geeks3~are` with length `12` and that was used/prepended on next iteration.
Instead, you can go with s... | * here is the solution for `pyton3.7+` using `fstring`.
```py
>>> S = ["geeks", "are", "awesome"]
>>> ''.join(f'{len(s)}~{s}' for s in S)
'5~geeks3~are7~awesome'
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.