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 |
|---|---|---|---|---|---|
1,183,420 | I am a .Net / SQL Server developer via my daytime job, and on the side I do some objective C development for the iPhone. I would like to develop a web service and since dreamhost supports mySql, python, ruby on rails and PHP5, I would like to create it using one of those languages. If you had no experience in either py... | 2009/07/26 | [
"https://Stackoverflow.com/questions/1183420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77393/"
] | **The short answer is, I'd go with PHP.**
I have some experience in all two of your three choices: PHP, Ruby with Ruby on Rails. If I had no experience however and I was looking to set out and create a web service that largely just interacts with a database and I wanted it done this weekend, I'd choose PHP. If I had n... | The first programming I ever did was with PHP, and it's definitely very easy to get going with PHP on Dreamhost (I use Dreamhost for my PHP-based blog as well as Ruby on Rails project hosting). Ruby on Rails is pretty easy to get going on Dreamhost as well, now that they've started using [Passenger](http://www.modrails... |
49,496,096 | I'm learning python and I'm not sure why the output of the below code is only "False" and not many "false" if I created a loop and the list of dict have 5 elements.
I was expect an ouput like
"False"
"False"
"False"
"False"
```
"False"
movies = [{
"name": "Usual Suspects"
}, {
"name": "Hitman",
... | 2018/03/26 | [
"https://Stackoverflow.com/questions/49496096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5544653/"
] | Try using the Remote VSCode plugin as explained here: [Using Remote VSCode](https://spin.atomicobject.com/2017/12/18/remote-vscode-file-editing/)
This discussion is exactly about your problem: [VSCode 13643 issue Github](https://github.com/Microsoft/vscode/issues/13643)
EDIT: I have recently found a new VSCode plugin... | The [SSH.NET nuget Package](https://www.nuget.org/packages/SSH.NET) can be used quite nicly to copy files and folders.
Here is an example:
```
var host = "YourServerIpAddress";
var port = 22;
var user = "root"; // TODO: fix
var yourPathToAPrivateKeyFile = @"C:\Users\Bob\mykey"; // Use certificate for login
var authMet... |
49,496,096 | I'm learning python and I'm not sure why the output of the below code is only "False" and not many "false" if I created a loop and the list of dict have 5 elements.
I was expect an ouput like
"False"
"False"
"False"
"False"
```
"False"
movies = [{
"name": "Usual Suspects"
}, {
"name": "Hitman",
... | 2018/03/26 | [
"https://Stackoverflow.com/questions/49496096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5544653/"
] | Try using the Remote VSCode plugin as explained here: [Using Remote VSCode](https://spin.atomicobject.com/2017/12/18/remote-vscode-file-editing/)
This discussion is exactly about your problem: [VSCode 13643 issue Github](https://github.com/Microsoft/vscode/issues/13643)
EDIT: I have recently found a new VSCode plugin... | Search for the extension SSHExtension developed by Vitaly Kondratiev
Install the extension.
And edit the serverlist json with the server details.
ex:
"sshextension.serverList": [
{
"name": "Kuberntes 212",
"host": "10.64.234.54",
"port": 22,
"username": "root",
"password": "byebye"
}
]
save the file
Then log i... |
637,399 | I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/... | 2009/03/12 | [
"https://Stackoverflow.com/questions/637399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9908/"
] | Just make sure Avahi / Bonjour's running, then type *hostname*.local (or also try *hostname*.localdomain) - it resolves using mDNS, so you don't have to care what your IP is or rigging /etc/hosts. | You could also use **arp-scan** (a Debian package of the name exists, not sure about other distributions) to scan your whole network. Have a script parse its output and you'll be all set. |
637,399 | I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/... | 2009/03/12 | [
"https://Stackoverflow.com/questions/637399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9908/"
] | Cleanest solution would be to have a DHCP server that exchanges its assignments with a local DNS server. So regardless which IP address your workstation is being assigned to, it is accessible under the same hostname.
This concept is used in every full-blown windows network as well as in any other well configured netw... | Just make sure Avahi / Bonjour's running, then type *hostname*.local (or also try *hostname*.localdomain) - it resolves using mDNS, so you don't have to care what your IP is or rigging /etc/hosts. |
637,399 | I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/... | 2009/03/12 | [
"https://Stackoverflow.com/questions/637399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9908/"
] | Sorry, it looks like an attempt to create a problem where no problem exists, and subsequently solve it using a bit crazy methods. :)
You can configure your dhcp server (router) to always issue a fixed ip for your workstation. If you don't have dhcp server, then why do you use dhcp for configuring the interface? Change... | You could also use **arp-scan** (a Debian package of the name exists, not sure about other distributions) to scan your whole network. Have a script parse its output and you'll be all set. |
637,399 | I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/... | 2009/03/12 | [
"https://Stackoverflow.com/questions/637399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9908/"
] | Cleanest solution would be to have a DHCP server that exchanges its assignments with a local DNS server. So regardless which IP address your workstation is being assigned to, it is accessible under the same hostname.
This concept is used in every full-blown windows network as well as in any other well configured netw... | You could also use **arp-scan** (a Debian package of the name exists, not sure about other distributions) to scan your whole network. Have a script parse its output and you'll be all set. |
637,399 | I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/... | 2009/03/12 | [
"https://Stackoverflow.com/questions/637399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9908/"
] | Cleanest solution would be to have a DHCP server that exchanges its assignments with a local DNS server. So regardless which IP address your workstation is being assigned to, it is accessible under the same hostname.
This concept is used in every full-blown windows network as well as in any other well configured netw... | Sorry, it looks like an attempt to create a problem where no problem exists, and subsequently solve it using a bit crazy methods. :)
You can configure your dhcp server (router) to always issue a fixed ip for your workstation. If you don't have dhcp server, then why do you use dhcp for configuring the interface? Change... |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You have two separate questions with two separate pythonic ways of answering those questions.
1- Your first concern was that you don't want to keep adding new lines the more arguments you start supporting when formatting a string. The way to work around that is using a `defaultdict` so you're able to return an empty s... | You can simplify it by:
```
middle_name = kwargs.get('middle_name', '')
``` |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | Seem to me your better off not using kwargs and not even a function, you can simply do something like this:
```
print("Your name is", " ".join([first_name, middle_name, last_name]))
```
Or if you do want a function:
```
def call_me_by_name(*args):
print("Your name is", " ".join(args))
``` | I think that your call\_me\_by\_name is no good example for \*\*kwargs. But if you want to avoid omitting some exotic, unconsidered name fields, call\_me\_by\_name could look like:
```
def call_me_by_name(first_name, last_name, middle_name='', **kwargs):
s = "Your name is {} {} {}".format(first_name,middle_name,la... |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You have two separate questions with two separate pythonic ways of answering those questions.
1- Your first concern was that you don't want to keep adding new lines the more arguments you start supporting when formatting a string. The way to work around that is using a `defaultdict` so you're able to return an empty s... | Seem to me your better off not using kwargs and not even a function, you can simply do something like this:
```
print("Your name is", " ".join([first_name, middle_name, last_name]))
```
Or if you do want a function:
```
def call_me_by_name(*args):
print("Your name is", " ".join(args))
``` |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You have two separate questions with two separate pythonic ways of answering those questions.
1- Your first concern was that you don't want to keep adding new lines the more arguments you start supporting when formatting a string. The way to work around that is using a `defaultdict` so you're able to return an empty s... | I think that your call\_me\_by\_name is no good example for \*\*kwargs. But if you want to avoid omitting some exotic, unconsidered name fields, call\_me\_by\_name could look like:
```
def call_me_by_name(first_name, last_name, middle_name='', **kwargs):
s = "Your name is {} {} {}".format(first_name,middle_name,la... |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | If your function care so specifically about keyword arguments, this is probably not the right tool. In this case, you can get the same effect with default arguments:
```
def call_me_by_name(first_name, middle_name="", last_name=""):
print("Your name is {} {} {}".format(first_name,middle_name,last_name))
```
It's... | I think that your call\_me\_by\_name is no good example for \*\*kwargs. But if you want to avoid omitting some exotic, unconsidered name fields, call\_me\_by\_name could look like:
```
def call_me_by_name(first_name, last_name, middle_name='', **kwargs):
s = "Your name is {} {} {}".format(first_name,middle_name,la... |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | If your function care so specifically about keyword arguments, this is probably not the right tool. In this case, you can get the same effect with default arguments:
```
def call_me_by_name(first_name, middle_name="", last_name=""):
print("Your name is {} {} {}".format(first_name,middle_name,last_name))
```
It's... | I will post it as a answer then :
You can instantly unpack the **kwargs** values to the format function like this :
```
"Your name is {} {} {}".format(first_name , *kwargs)
```
But as a User **@PM 2Ring** mentioned You must be aware that doesn't guarantee that the names will be in the correct order. |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You have two separate questions with two separate pythonic ways of answering those questions.
1- Your first concern was that you don't want to keep adding new lines the more arguments you start supporting when formatting a string. The way to work around that is using a `defaultdict` so you're able to return an empty s... | I will post it as a answer then :
You can instantly unpack the **kwargs** values to the format function like this :
```
"Your name is {} {} {}".format(first_name , *kwargs)
```
But as a User **@PM 2Ring** mentioned You must be aware that doesn't guarantee that the names will be in the correct order. |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | Seem to me your better off not using kwargs and not even a function, you can simply do something like this:
```
print("Your name is", " ".join([first_name, middle_name, last_name]))
```
Or if you do want a function:
```
def call_me_by_name(*args):
print("Your name is", " ".join(args))
``` | I will post it as a answer then :
You can instantly unpack the **kwargs** values to the format function like this :
```
"Your name is {} {} {}".format(first_name , *kwargs)
```
But as a User **@PM 2Ring** mentioned You must be aware that doesn't guarantee that the names will be in the correct order. |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You can simplify it by:
```
middle_name = kwargs.get('middle_name', '')
``` | I will post it as a answer then :
You can instantly unpack the **kwargs** values to the format function like this :
```
"Your name is {} {} {}".format(first_name , *kwargs)
```
But as a User **@PM 2Ring** mentioned You must be aware that doesn't guarantee that the names will be in the correct order. |
52,331,595 | I took a look at [this question](https://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python) but it doesn't exactly answer my question.
As an example, I've taken a simple method to print my name.
```
def call_me_by_name(first_name):
print("Your name is {}".format(first_name))
```
Later on, I ... | 2018/09/14 | [
"https://Stackoverflow.com/questions/52331595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4020238/"
] | You have two separate questions with two separate pythonic ways of answering those questions.
1- Your first concern was that you don't want to keep adding new lines the more arguments you start supporting when formatting a string. The way to work around that is using a `defaultdict` so you're able to return an empty s... | If your function care so specifically about keyword arguments, this is probably not the right tool. In this case, you can get the same effect with default arguments:
```
def call_me_by_name(first_name, middle_name="", last_name=""):
print("Your name is {} {} {}".format(first_name,middle_name,last_name))
```
It's... |
12,830,838 | Hello I have what I hope is an easy problem to solve. I am attempting to read a csv file and write a portion into a list. I need to determine the index and the value in each row and then summarize.
so the row will have 32 values...each value is a classification (class 0, class 1, etc.) with a number associated with it... | 2012/10/11 | [
"https://Stackoverflow.com/questions/12830838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1736554/"
] | I find your use case a bit difficult to understand, but does this list comprehension give you some new ideas about how to solve your problem?
```
>>> classes = [' ', '1234', '645', '9897'], [' ', '76541', ' ', '8888']
>>> [sum(int(n) for n in x if n != ' ') for x in zip(*classes)]
[0, 77775, 645, 18785]
``` | ```
>>> classes = [[' ', '1234', '645', '9897'], [' ', '76541', ' ', '8888']]
>>> my_int = lambda s: int(s) if s.isdigit() else 0
>>> class_groups = dict(zip(range(32), zip(*classes)))
>>> class_groups[1]
('1234', '76541')
>>> class_sums = {}
>>> for class_ in class_groups:
... group_sum = sum(map(my_int, class_gr... |
12,830,838 | Hello I have what I hope is an easy problem to solve. I am attempting to read a csv file and write a portion into a list. I need to determine the index and the value in each row and then summarize.
so the row will have 32 values...each value is a classification (class 0, class 1, etc.) with a number associated with it... | 2012/10/11 | [
"https://Stackoverflow.com/questions/12830838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1736554/"
] | I find your use case a bit difficult to understand, but does this list comprehension give you some new ideas about how to solve your problem?
```
>>> classes = [' ', '1234', '645', '9897'], [' ', '76541', ' ', '8888']
>>> [sum(int(n) for n in x if n != ' ') for x in zip(*classes)]
[0, 77775, 645, 18785]
``` | You could sum as you go through the CSV file rows. (e.g. put the for class\_ loop inside your rows loop) .. :
```
>>> classes
[[' ', '1234', '645', '9897'], [' ', '76541', ' ', '8888']]
>>> sums = {}
>>> for row in classes:
... for class_, num in enumerate(row):
... try:
... num = int(num)
... ... |
3,484,976 | I'm trying to write a Python client for a a WSDL service. I'm using the [Suds](https://fedorahosted.org/suds/wiki/Documentation) library to handle the SOAP messages.
When I try to call the service, I get a Suds exception: `<rval />` not mapped to message part. If I set the `retxml` Suds option I get XML which looks OK... | 2010/08/14 | [
"https://Stackoverflow.com/questions/3484976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4697/"
] | Possible dup of [What does suds mean by "<faultcode/> not mapped to message part"?](https://stackoverflow.com/questions/2963094/what-does-suds-mean-by-faultcode-not-mapped-to-message-part/18948575#18948575)
Here is my answer from that question:
I had a similar issue where the call was successful, and Suds crashed on ... | This exception actually means that the answer from SOAP-service contains tag `<rval>`, which doesn't exist in the WSDL-scheme of the service.
Keep in mind that the Suds library caches the WSDL-scheme, that is why the problem may occur if the WSDL-scheme was changed recently. Then the answers match the new scheme, but ... |
35,122,185 | I have a Profiles app that has a model called profile, i use that model to extend the django built in user model without subclassing it.
**models.py**
```
class BaseProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='owner',primary_key=True)
supervisor = models.ForeignKe... | 2016/02/01 | [
"https://Stackoverflow.com/questions/35122185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2031794/"
] | You need to use multiple inline admin.
When you have a model with multiple ForeignKeys to the same parent model, you'll need specify the `fk_name` attribute in your inline admin:
```
class UserProfileInline(admin.StackedInline):
model = Profile
fk_name = "user"
class SupervisorProfileInline(admin.StackedInli... | Here is an example that I have just tested to be working
```
class Task(models.Model):
owner = models.ForeignKey(User, related_name='task_owner')
assignee = models.ForeignKey(User, related_name='task_assigned_to')
```
In admin.py
```
class TaskInLine(admin.TabularInLine):
model = User
@admin.register(T... |
15,351,081 | For example let's say I have a file called myscript.py
This file contains the following code.
```
foo(var):
return var
```
How would I call the function foo with argument var on command line.
I know that I can go to the directory myscript.py is placed in and type.
```
>>> python myscript.py
```
Which will ru... | 2013/03/12 | [
"https://Stackoverflow.com/questions/15351081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2158898/"
] | You don't get any output because you don't generate any. Try calling [`print`](http://docs.python.org/3/library/functions.html#print):
```
def foo(var):
print(var)
if __name__ == '__main__':
foo('Hello, world')
``` | You have to use the `sys` module to pass arguments from the command line.
You can do this:
```
import sys
def foo(var):
return var
if __name__ == '__main__':
# arguments check
if len(sys.argv) != 2:
print "USAGE: %s <value>" % sys.argv[0]
sys.exit(1)
# get the agument so as to use it to the function... |
22,214,463 | The title is self explanatory. What is going on here? How can I get this not to happen? Do I really have to change all of my units (it's a physics problem) just so that I can get a big enough answer that python doesn't round 1-x to 1?
code:
```
import numpy as np
import math
vel=np.array([5e-30,5e-30,5e-30])
c=9.71... | 2014/03/06 | [
"https://Stackoverflow.com/questions/22214463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3347826/"
] | In python [decimal](http://docs.python.org/library/decimal.html#module-decimal) may work and maybe [mpmath](https://code.google.com/p/mpmath/).
as is discussed in this SO [article](https://stackoverflow.com/questions/11522933/python-floating-point-arbitrary-precision-available)
If you are willing to use Java (instead... | I think you won't get the result you are expecting because you are dealing with computer math limits. The thing about this kind of calculations is that nobody can avoid this error, unless you make/find some models that has infinite (theoretically) decimals and you can operate with them. If that is too much for the prob... |
73,007,506 | Hi I want to clean up my code where I am converting a list of items to integers whenever possible in the python programming language.
```
example_list = ["4", "string1", "9", "string2", "10", "string3"]
```
So my goal (which is probably very simple) is to convert all items in the list from integers to integers and k... | 2022/07/16 | [
"https://Stackoverflow.com/questions/73007506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13840524/"
] | Perhaps add this somewhere:
```
<style>
div {
max-width: 306px !important;
}
</style>
``` | u can try and use max width set to 306px for that part |
61,412,481 | I am trying to access Google Sheet (read only mode) from Python (runs in GKE).
I am able to get application default creds, but getting scopes issue (as I am missing `https://www.googleapis.com/auth/spreadsheets.readonly` scope). See code below:
```
from googleapiclient.discovery import build
from oauth2client import ... | 2020/04/24 | [
"https://Stackoverflow.com/questions/61412481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408628/"
] | You need to separate tick values and tick labels.
```
ax.set_xticks([]) # values
ax.set_xticklabels([]) # labels
``` | Just change it to:
```
self.ax.set_xticks([])
self.ax.set_yticks([])
```
The error says that the second parameter cannot be given positionally, meaning that you need to explicitly give the parameter name minor=False for the second parameter or remove the second parameter in your case. |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | What's going on is that you're returning right after the first line of the file doesn't match the id you're looking for. You have to do this:
```
def query(id):
for line in file:
table = {}
(table["ID"],table["name"],table["city"]) = line.split(";")
if id == int(table["ID"]):
f... | I followed approach as shown in code below to return a dictionary. Created a class and declared dictionary as global and created a function to add value corresponding to some keys in dictionary.
\*\*Note have used Python 2.7 so some minor modification might be required for Python 3+
```
class a:
global d
d={}... |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | What's going on is that you're returning right after the first line of the file doesn't match the id you're looking for. You have to do this:
```
def query(id):
for line in file:
table = {}
(table["ID"],table["name"],table["city"]) = line.split(";")
if id == int(table["ID"]):
f... | ```
def prepare_table_row(row):
lst = [i.text for i in row if i != u'\n']
return dict(rank = int(lst[0]),
grade = str(lst[1]),
channel=str(lst[2])),
videos = float(lst[3].replace(",", " ")),
subscribers = float(lst[4].replace(",", "")),
... |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | What's going on is that you're returning right after the first line of the file doesn't match the id you're looking for. You have to do this:
```
def query(id):
for line in file:
table = {}
(table["ID"],table["name"],table["city"]) = line.split(";")
if id == int(table["ID"]):
f... | ```
def query(id):
for line in file:
table = line.split(";")
if id == int(table[0]):
yield table
id = int(input("Enter the ID of the user: "))
for id_, name, city in query(id):
print("ID: " + id_)
print("Name: " + name)
print("City: " + city)
file.close()
```
Using yield.. |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | ```
def prepare_table_row(row):
lst = [i.text for i in row if i != u'\n']
return dict(rank = int(lst[0]),
grade = str(lst[1]),
channel=str(lst[2])),
videos = float(lst[3].replace(",", " ")),
subscribers = float(lst[4].replace(",", "")),
... | I followed approach as shown in code below to return a dictionary. Created a class and declared dictionary as global and created a function to add value corresponding to some keys in dictionary.
\*\*Note have used Python 2.7 so some minor modification might be required for Python 3+
```
class a:
global d
d={}... |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | ```
def query(id):
for line in file:
table = line.split(";")
if id == int(table[0]):
yield table
id = int(input("Enter the ID of the user: "))
for id_, name, city in query(id):
print("ID: " + id_)
print("Name: " + name)
print("City: " + city)
file.close()
```
Using yield.. | I followed approach as shown in code below to return a dictionary. Created a class and declared dictionary as global and created a function to add value corresponding to some keys in dictionary.
\*\*Note have used Python 2.7 so some minor modification might be required for Python 3+
```
class a:
global d
d={}... |
17,713,692 | I am trying to simplify an expression using z3py but am unable to find any documentation on what different tactics do. The best resource I have found is a [stack overflow question](https://stackoverflow.com/questions/16167088/z3-tactics-are-not-available-via-online-interface) that lists all the tactics by name.
Is so... | 2013/07/18 | [
"https://Stackoverflow.com/questions/17713692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016669/"
] | ```
def query(id):
for line in file:
table = line.split(";")
if id == int(table[0]):
yield table
id = int(input("Enter the ID of the user: "))
for id_, name, city in query(id):
print("ID: " + id_)
print("Name: " + name)
print("City: " + city)
file.close()
```
Using yield.. | ```
def prepare_table_row(row):
lst = [i.text for i in row if i != u'\n']
return dict(rank = int(lst[0]),
grade = str(lst[1]),
channel=str(lst[2])),
videos = float(lst[3].replace(",", " ")),
subscribers = float(lst[4].replace(",", "")),
... |
73,381,445 | I need to have bash shell commands run through python in order to be universal with pc and mac/linux. `./bin/production` doesn't work in powershell and putting 'bash' in front would give an error that it doesn't recognize 'docker' command
./bin/production contents:
```
#!/bin/bash
docker run --rm -it \
--volume $... | 2022/08/16 | [
"https://Stackoverflow.com/questions/73381445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19779700/"
] | ### Modification points:
* In your showing script, it seems that `payload` is not used.
* When `getValue()` is used in a loop, the process cost becomes high. [Ref](https://gist.github.com/tanaikech/d102c9600ba12a162c667287d2f20fe4)
When these points are reflected in a sample script for achieving your goal, it becomes... | Your code creates separate objects in each iteration. Create an empty object for every Person, then add the properties you need.
This should look something like this:
```js
for(var i=2; i<=LastRow; i++){
var payload = {}
for(var j=1; j<=LastCol; j++){
payload[arr[j-1]] = ss.getRange(i,j).getValue()};
... |
6,499,839 | >
> **Possible Duplicate:**
>
> [Flatten (an irregular) list of lists in Python](https://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python)
>
>
>
I have the following list --
```
[1,[2,3],4,[5,[6,7]]]
```
And I need to make it flat --
```
[1,2,3,4,5,6,7]
```
To do this, I a... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6499839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/651174/"
] | Hauled from [webhelpers.misc.flatten](http://sluggo.scrapping.cc/python/WebHelpers/modules/misc.html?highlight=flatten#webhelpers.misc.flatten)
```
def flatten(iterable):
"""Recursively iterate lists and tuples.
"""
for elm in iterable:
if isinstance(elm, (list, tuple)):
for relm in fla... | Try this:
```
def flat(mlist):
result = []
for i in mlist:
if type(i) is list:
result.extend(flat(i))
else:
result.append(i)
return result
``` |
72,081,872 | Hi I trying to make RBM Model code using pytorch module but got a issue in visible layer to hidden layer. Here is the problem part code.
```py
h_bias = (self.h_bias.clone()).expand(10)
v = v.clone().expand(10)
p_h = F.sigmoid(
F.linear(v, self.W, bias=h_bias)
)
sam... | 2022/05/02 | [
"https://Stackoverflow.com/questions/72081872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9713429/"
] | If you look at the pytorch functional.linear documentation it shows the weight parameter can be either 1D or 2D: "Weight: (out\_features, in\_features) or (in\_features)". Since your weight is 2D ([1, 10]) it indicates that you are trying to create an output of size "1" with an input size of "10". The linear transform ... | I solved with torch.repeat() function. As mandias said...
>
> you are trying to create an output of size "1" with an input size of "10". The linear transform does not know how to change your inputs of size 10 into an output of size 1.
>
>
>
That was a my problem. So I changed weight input like this.
```py
w = se... |
49,259,985 | I am reading data from a python dictionary and trying to add more book elements in the below tree. Below is just an examplke, i need to copy an element with it's child(s) but replace the content, in this case i need to copy the book element but replace title and author.
```
<store>
<bookstore>
<book>
... | 2018/03/13 | [
"https://Stackoverflow.com/questions/49259985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4977702/"
] | You changing the same object.
You need to actual copy the object with copy.deepcopy
Example:
```
import xml.etree.ElementTree as et
import copy
root = et.parse('Template.xml').getroot()
bookstore = root.find('bookstore')
book = root.find('bookstore').find('book')
bks = ["book_title_1", "book_title_2", "book_title_... | I'm guessing instead of `books.append(book)` you mean `bookstore.append(book)`.
Basically here you have a structure:
```
- store
- bookstore
- book
- book infos
```
with `book = root.find('bookstore').find('book')` you are actually getting a reference to the (only) one you already have, and in the loop ... |
2,741,986 | I'm developing a small python like language using flex, byacc (for lexical and parsing) and C++, but i have a few questions regarding scope control.
just as python it uses white spaces (or tabs) for indentation, not only that but i want to implement index breaking like for instance if you type "break 2" inside a while... | 2010/04/30 | [
"https://Stackoverflow.com/questions/2741986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/208153/"
] | I am currently implementing a programming language rather similar to this (including the multilevel break oddly enough). My solution was to have the tokenizer emit indent and dedent tokens based on indentation. Eg:
```
while 1: # colons help :)
print('foo')
break 1
```
becomes:
```
["while", "1", ":",
i... | Very interesting exercise. Can't you use the `end` keyword to check when the scope ends?
On a different note, I have never seen a language that allows you to break out of several nested loops at once. There may be a good reason for that... |
53,882,241 | I've seen a few similar questions on SO regarding detecting changes to a dictionary and calling a function when the dictionary changes, such as:
* [How to trigger function on value change?](https://stackoverflow.com/questions/6190468/how-to-trigger-function-on-value-change)
* [python detect if any element in a diction... | 2018/12/21 | [
"https://Stackoverflow.com/questions/53882241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/512965/"
] | Building on the answer given in [here](https://stackoverflow.com/questions/26189090/python-detect-if-any-element-in-a-dictionary-changes), just do the following:
```
class MyDict(dict):
def __setitem__(self, item, value):
print("You are changing the value of {} to {}!!".format(item, value))
super(M... | Complete solution borrowing from the [this](https://stackoverflow.com/questions/26189090/python-detect-if-any-element-in-a-dictionary-changes) link(the second one given by OP)
```
class MyDict(dict):
def __setitem__(self, item, value):
print("You are changing the value of {key} to {value}!!".format(key=ite... |
53,882,241 | I've seen a few similar questions on SO regarding detecting changes to a dictionary and calling a function when the dictionary changes, such as:
* [How to trigger function on value change?](https://stackoverflow.com/questions/6190468/how-to-trigger-function-on-value-change)
* [python detect if any element in a diction... | 2018/12/21 | [
"https://Stackoverflow.com/questions/53882241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/512965/"
] | Building on the answer given in [here](https://stackoverflow.com/questions/26189090/python-detect-if-any-element-in-a-dictionary-changes), just do the following:
```
class MyDict(dict):
def __setitem__(self, item, value):
print("You are changing the value of {} to {}!!".format(item, value))
super(M... | You can write an adapter class that automatically wraps values in itself, like this (untested, but I think it illustrates the point):
```
class DictChangeListenerAdapter:
def __init__(self, original, listener):
self._original = original
self._listener = listener
def __getitem__(self, key):
... |
8,662,887 | I've read that subprocess should be used but all the examples i've seen on it shows that it runs only command-line commands. I want my program to run a python command along with another command. The command i want to run is to send an email to a user while a user plays a game i created. i have to have the python comman... | 2011/12/29 | [
"https://Stackoverflow.com/questions/8662887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1082837/"
] | It sounds like you are looking for threading, which is a relatively deep topic, but this should help you get started: <http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/> | Threading is talked about in another answer, but you can get basically what you want by using subprocess's Popen command: <http://docs.python.org/library/subprocess.html#subprocess.Popen>
What you'll basically want is this (assuming proc is initialized somewhere in the game loop):
```
#...game code here...
args = [c... |
23,434,748 | I hate Recursive right now. Any way does any one know how to find square root using recursive solution on python. Or at least break it down to simple problems. All examples I found are linear only using one argument in the function. My function needs square Root(Number, low Guess, high Guess, Accuracy) I think the accu... | 2014/05/02 | [
"https://Stackoverflow.com/questions/23434748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3597291/"
] | Remove the timeout setting:
```
rm config/initializers/timeout.rb
```
Heroku times-out all requests at 30 seconds but the process will continue running in the background.
If you want to avoid that, re-add the line above but [put rack-timeout in your Gemfile](https://github.com/heroku/rack-timeout). | I would suggest trying the following:
```
heroku labs:enable user-env-compile
```
If this fails, you could always precompile your production assets, add them to your codebase and push them to heroku yourself.
```
RAILS_ENV=production rake assets:precompile
git add .
git commit -m 'serving up my precompiled assets'... |
23,434,748 | I hate Recursive right now. Any way does any one know how to find square root using recursive solution on python. Or at least break it down to simple problems. All examples I found are linear only using one argument in the function. My function needs square Root(Number, low Guess, high Guess, Accuracy) I think the accu... | 2014/05/02 | [
"https://Stackoverflow.com/questions/23434748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3597291/"
] | It looks like your problem is actually related to `Rack::Timeout` and not asset compilation.
```
uninitialized constant Rack::Timeout
/tmp/build_d3989303-c1d8-4020-9b98-eb9e1834f0d0/config/initializers/timeout.rb:1:in `<top (required)>'
```
Have you included the rack-timeout gem in your gemfile? And ran `bundle inst... | I would suggest trying the following:
```
heroku labs:enable user-env-compile
```
If this fails, you could always precompile your production assets, add them to your codebase and push them to heroku yourself.
```
RAILS_ENV=production rake assets:precompile
git add .
git commit -m 'serving up my precompiled assets'... |
28,551,263 | ```
import pygame
import time
pygame.mixer.init()
pygame.mixer.music.load('/home/bahara.mp3')
time.sleep(2)
pygame.mixer.music.play()
```
While compiling this code from terminal, no error is thrown, but I am unable to hear any music. But when executed line by line, the code is working fine.
Can you suggest a wa... | 2015/02/16 | [
"https://Stackoverflow.com/questions/28551263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4573517/"
] | Pygame requires an active display which you have not initialized. I suggest you try installing and using `mpg123` command line tool.
Install:
```
$ sudo apt-get install mpg123
```
Program:
```
import os, time
os.system('mpg123 /home/bahara.mp3')
``` | I'm going to post my earlier comment as an answer because I think it's worth trying if you want to retain pygame's ability to control the music player.
I suspect you're getting no sound because pygame is exiting as your script ends, whereas when you run line by line in a python terminal session pygame remains active. ... |
40,739,504 | My project consists of a python script(.py file) which has following dependencies :
1) numpy
2) scipy
3) sklearn
4) opencv (cv2)
5) dlib
6) torch
and many more ...
That is , the python script imports all of the above.
In order to run this script I need to manually install all of the dependencies by running 'pip instal... | 2016/11/22 | [
"https://Stackoverflow.com/questions/40739504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6864242/"
] | I know that this Response may be a bit late. However, even if you can't benefit from this information now, perhaps someone else who may be looking for a similar answer will stumble onto this posting one day.
You can use [py2exe](https://pypi.org/project/py2exe/) or [pyinstaller](https://pypi.org/project/PyInstaller/)... | In case of only python dependencies, use [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/).
In case of others, write a shell script which has all the installation commands. |
15,161,843 | i noticed some seemingly strange behaviour when trying to import a python module named rmod2 in different ways. if i start python from the directory where the *rmod2.py* file is located, it works fine. however, if i move the file to another folder where other modules are locate, it doesn't work as expected anymore.
the... | 2013/03/01 | [
"https://Stackoverflow.com/questions/15161843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2124120/"
] | APK will be generated under \bin\ folder once you run your app for the first time.
Connect your Android device to dev machine via USB cable (assuming you got Android SDK etc installed), right click on Android project and do Run as->Android app.
The app will be installed and started on Android device. APK will be gener... | You can also do an export on the android application project. This is what you would do if you are looking at doing some key signing. This is the way you would want to export it if you are uploading to Google play or an enterprise app store.
Keep in mind, Worklight doesn't build your .ipa, .apk, or etc. It builds you ... |
44,204,937 | I am trying to change the behavior of python's `int` class, but I'm not sure if it can be done using pure python. Here is what I tried so far:
```
import builtins
class int_new(builtins.int):
def __eq__(self, other):
return True
int = int_new
print(5 == 6) # the result is False, but I'm anticipating True
... | 2017/05/26 | [
"https://Stackoverflow.com/questions/44204937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7416363/"
] | You should replace last line with:
```
print(int(5) == int(6))
```
to force/ask Python to use your new class for integer numbers. | A year later I finally learned what I was wondering. When I was learning Python, I was not exposed to the idea of what a primitive type is. After learning C++ I realized that I was actually wondering if it is possible to replace primitive type with other custom types. The answer is obviously no. |
38,909,362 | I'm working with International Phonetic Alphabet (IPA) symbols in my Python program, a rather strange set of characters whose UTF-8 codes can range anywhere from 1 to 3 bytes long. [This thread](https://stackoverflow.com/questions/7291120/python-and-unicode-code-point-extraction) from several years ago basically asked ... | 2016/08/12 | [
"https://Stackoverflow.com/questions/38909362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6707199/"
] | >
> With that no longer an option, is there any way in Python 2.7 to find the Unicode code point of a given character? (And does that character then have to be a unicode type?) I don't mean by just manually looking it up on a Unicode table, either.
>
>
>
You can only find the unicode code point of a unicode object... | ```
>>> u'ɨ'
u'\u0268'
>>> u'i'
u'i'
>>> 'ɨ'.decode('utf-8')
u'\u0268'
``` |
38,909,362 | I'm working with International Phonetic Alphabet (IPA) symbols in my Python program, a rather strange set of characters whose UTF-8 codes can range anywhere from 1 to 3 bytes long. [This thread](https://stackoverflow.com/questions/7291120/python-and-unicode-code-point-extraction) from several years ago basically asked ... | 2016/08/12 | [
"https://Stackoverflow.com/questions/38909362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6707199/"
] | This is actually a bug in Python 2, depending on how it was built, for unicode characters outside the BMP (>= 0xFFFF); see: <https://bugs.python.org/issue8670#msg105656>
For example this works:
```
>>> ord('\uffff')
65535
>>> len('\uffff')
1
```
But this does not:
```
>>> ord(u'\U00010000')
Traceback (most recent ... | ```
>>> u'ɨ'
u'\u0268'
>>> u'i'
u'i'
>>> 'ɨ'.decode('utf-8')
u'\u0268'
``` |
38,909,362 | I'm working with International Phonetic Alphabet (IPA) symbols in my Python program, a rather strange set of characters whose UTF-8 codes can range anywhere from 1 to 3 bytes long. [This thread](https://stackoverflow.com/questions/7291120/python-and-unicode-code-point-extraction) from several years ago basically asked ... | 2016/08/12 | [
"https://Stackoverflow.com/questions/38909362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6707199/"
] | >
> With that no longer an option, is there any way in Python 2.7 to find the Unicode code point of a given character? (And does that character then have to be a unicode type?) I don't mean by just manually looking it up on a Unicode table, either.
>
>
>
You can only find the unicode code point of a unicode object... | This is actually a bug in Python 2, depending on how it was built, for unicode characters outside the BMP (>= 0xFFFF); see: <https://bugs.python.org/issue8670#msg105656>
For example this works:
```
>>> ord('\uffff')
65535
>>> len('\uffff')
1
```
But this does not:
```
>>> ord(u'\U00010000')
Traceback (most recent ... |
61,902,162 | I am working with Python version 2.7 and boto3 , but cannot import boto3 library .
My Python path is
```
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
```
When I look under
```
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
```
I see boto3 installed . But I keep ge... | 2020/05/19 | [
"https://Stackoverflow.com/questions/61902162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3987161/"
] | You may be more familiar and comfortable with the `map` function from its common use in `Iterator`s but using `map` to work with `Result`s and `Option`s is also considered idiomatic in Rust. If you'd like to make your code more concise you can use [`map_or`](https://doc.rust-lang.org/std/result/enum.Result.html#method.... | Alternatively, if you find the `map` unclear, you could use an `if` or `match` to be more explicit (and verbose):
```
let is_dir = if let Ok(file_type) = entry.file_type() {
file_type.is_dir()
} else {
false
};
```
or
```
let is_dir = match entry.file_type() {
Ok(file_type) => file_type.is_dir(),
_ ... |
72,289,828 | I have source of truth stored in yaml file sot-inventory.yaml
```
- Hostname: NY-SW1
IP mgmt address: 10.1.1.1
OS: IOS
Operational status: Install
Role of work: Switch
Site: New_York
- Hostname: MI-SW1
IP mgmt address: 11.1.1.1
OS: NX-OS
Operational status: Install
Role of work: Switch
Site: Maiami... | 2022/05/18 | [
"https://Stackoverflow.com/questions/72289828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19145073/"
] | The **X.509 Client Certificate** option which is part of the docker plugin, has recently changed its name as it used to be named **Docker Certificate Directory** (the behavior itself has not changed), therefore is it is tricky to find it in the `withCredentials` [Documentation](https://www.jenkins.io/doc/pipeline/steps... | On my Jenkins, it's
```
withCredentials([certificate(aliasVariable: 'ALIAS_VAR',
credentialsId: 'myClientCert',
keystoreVariable: 'KEYSTORE_VAR',
passwordVariable: 'PASSWORD_VAR')]) {
...
}
```
Hint: If you add `/pipeline-syntax/` to your Jenkins URL, it will take you to a snippet generator that wil... |
57,218,302 | I have a an excel sheet with one column, the header is Name and the row below it says Jerry. All i want to do is append to this using python with the header: Age then a row below that saying e.g. 14.
How do i do this?
```
with open('simpleexcel.csv', 'r') as f_input: # Declared variable f_input to open and read th... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57218302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6714667/"
] | Use `next(input_reader)` to get the header and then append the new column name and write it back to csv.
**Ex:**
```
with open('simpleexcel.csv', 'r') as f_input: # Declared variable f_input to open and read the input file
input_reader = csv.reader(f_input) # this will iterate ober lines from input file
w... | I don't know what you are trying to accomplish here but for your sample case this can be used.
```
import csv
with open('simpleexcel.csv', 'r') as f_input:
input_reader = list(csv.reader(f_input))
input_reader[0].append('Age')
for row in input_reader[1:]:
row.append(14)
with open('Outputfile.csv', "w", newl... |
66,948,944 | I managed to find python code that defines a LinkedList class and all the defacto methods in it but quite can't figure out what each line of code does...Can someone comment on it explaining what each line does so i can grasp a better understanding of LinkedLists in python?
```
class Node:#what is the significance of a... | 2021/04/05 | [
"https://Stackoverflow.com/questions/66948944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Usually people use macros to append `__LINE__` to the declaration to allow for multiple declarations in one scope block.
Prior to C++20 this was impossible without macros. C++20 and later, with a little work, can use [`std::source_location`](https://en.cppreference.com/w/cpp/utility/source_location).
Jason Turner has... | I was initially not sure to grasp the advantage of that macro, apart hiding the timer instance name (and cause possible conflicts).
But I think that the intent could be to have the possibility to do this:
```
#ifdef _DEBUG
#define SCOPED_TIMER(slot) ScopedTimer __scopedTimer( slot );
#else
#define SCOPED_TIMER(slo... |
7,456,630 | I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
```
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7456630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/856919/"
] | I was gonna post this code sample:
```
Process rsyncProc = Runtime.exec ("rsync");
OutputStreanm rsyncStdIn = rsyncProv.getOutputStream ();
rsyncStdIn.write ("password".getBytes ());
```
But [Vineet Reynolds](https://stackoverflow.com/users/3916/vineet-reynolds) was ahead of me.
As Vineet Reynolds pointed out using... | You can write to the output stream of the `Process`, to pass in any inputs. However, this will require you to have knowledge of `rsync`'s behavior, for you must write the password to the outputstream only when the password prompt is detected (by reading the input stream of the `Process`).
You may however, create a non... |
7,456,630 | I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
```
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7456630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/856919/"
] | You can write to the output stream of the `Process`, to pass in any inputs. However, this will require you to have knowledge of `rsync`'s behavior, for you must write the password to the outputstream only when the password prompt is detected (by reading the input stream of the `Process`).
You may however, create a non... | Need not wait till the password is requested to write it to the stream. Make use of a BufferedWriter instead.
```
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(process.getOutputStream())
);
writer.write(passwd, 0, passwd.length());
writer.newLine();
writer.close();
```
This must work. |
7,456,630 | I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
```
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7456630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/856919/"
] | I was gonna post this code sample:
```
Process rsyncProc = Runtime.exec ("rsync");
OutputStreanm rsyncStdIn = rsyncProv.getOutputStream ();
rsyncStdIn.write ("password".getBytes ());
```
But [Vineet Reynolds](https://stackoverflow.com/users/3916/vineet-reynolds) was ahead of me.
As Vineet Reynolds pointed out using... | Took me some time, but here it goes:
```
Process ssh = Runtime.getRuntime ().exec (new String[] {"rsync", ... /*other arguments*/});
Reader stdOut = new InputStreamReader (ssh.getInputStream (), "US-ASCII");
OutputStream stdIn = ssh.getOutputStream ();
char[] passRequest = new char[128];//Choose it bi... |
7,456,630 | I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
```
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7456630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/856919/"
] | I was gonna post this code sample:
```
Process rsyncProc = Runtime.exec ("rsync");
OutputStreanm rsyncStdIn = rsyncProv.getOutputStream ();
rsyncStdIn.write ("password".getBytes ());
```
But [Vineet Reynolds](https://stackoverflow.com/users/3916/vineet-reynolds) was ahead of me.
As Vineet Reynolds pointed out using... | Need not wait till the password is requested to write it to the stream. Make use of a BufferedWriter instead.
```
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(process.getOutputStream())
);
writer.write(passwd, 0, passwd.length());
writer.newLine();
writer.close();
```
This must work. |
7,456,630 | I have a python REST API server running on my laptop. I am trying to write a rest client in Android (using Eclipse ADT etc) to contact it using Apache's client (org.apache.http.client) libraries.
The code is really simple, and basically does the following -
```
HttpGet httpget = new HttpGet(new URI("http://10.0.2.2... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7456630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/856919/"
] | Took me some time, but here it goes:
```
Process ssh = Runtime.getRuntime ().exec (new String[] {"rsync", ... /*other arguments*/});
Reader stdOut = new InputStreamReader (ssh.getInputStream (), "US-ASCII");
OutputStream stdIn = ssh.getOutputStream ();
char[] passRequest = new char[128];//Choose it bi... | Need not wait till the password is requested to write it to the stream. Make use of a BufferedWriter instead.
```
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(process.getOutputStream())
);
writer.write(passwd, 0, passwd.length());
writer.newLine();
writer.close();
```
This must work. |
10,971,649 | >
> **Possible Duplicate:**
>
> [How to read specific characters from lines in a text file using python?](https://stackoverflow.com/questions/10968973/how-to-read-specific-characters-from-lines-in-a-text-file-using-python)
>
>
>
I have a .txt file with lines looking like this
>
> Water 16:-30.4674 1:-30.4759... | 2012/06/10 | [
"https://Stackoverflow.com/questions/10971649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447337/"
] | If the format is always the same you could do this for each line:
```
items = line.split()[1:]
items = [item.split(':')[0] for item in items]
```
And then if you want them as integers:
```
items = map(int, items)
```
As for storing them, create a list before iterating over each line `rows = []` and then you can a... | Use split method and append it to your array:
```
myArray=line.split(':-')
``` |
10,971,649 | >
> **Possible Duplicate:**
>
> [How to read specific characters from lines in a text file using python?](https://stackoverflow.com/questions/10968973/how-to-read-specific-characters-from-lines-in-a-text-file-using-python)
>
>
>
I have a .txt file with lines looking like this
>
> Water 16:-30.4674 1:-30.4759... | 2012/06/10 | [
"https://Stackoverflow.com/questions/10971649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447337/"
] | This is a job for regular expressions:
```
import re
with open(myFilePath, "r") as f:
text = f.read()
numbers = re.findall(r"(-?\d+):\S+", text)
```
The above is assuming that all of the numbers before the colons are integers. | Use split method and append it to your array:
```
myArray=line.split(':-')
``` |
10,971,649 | >
> **Possible Duplicate:**
>
> [How to read specific characters from lines in a text file using python?](https://stackoverflow.com/questions/10968973/how-to-read-specific-characters-from-lines-in-a-text-file-using-python)
>
>
>
I have a .txt file with lines looking like this
>
> Water 16:-30.4674 1:-30.4759... | 2012/06/10 | [
"https://Stackoverflow.com/questions/10971649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447337/"
] | If the format is always the same you could do this for each line:
```
items = line.split()[1:]
items = [item.split(':')[0] for item in items]
```
And then if you want them as integers:
```
items = map(int, items)
```
As for storing them, create a list before iterating over each line `rows = []` and then you can a... | This is a job for regular expressions:
```
import re
with open(myFilePath, "r") as f:
text = f.read()
numbers = re.findall(r"(-?\d+):\S+", text)
```
The above is assuming that all of the numbers before the colons are integers. |
14,574,595 | What I'm trying to do is make a gaussian function graph. then pick random numbers anywhere in a space say y=[0,1] (because its normalized) & x=[0,200]. Then, I want it to ignore all values above the curve and only keep the values underneath it.
```
import numpy
import random
import math
import matplotlib.... | 2013/01/29 | [
"https://Stackoverflow.com/questions/14574595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1884319/"
] | The immediate cause of the error you're seeing is presumably this line (which should be identified by the full traceback -- it's generally quite helpful to post that):
```
Lower = numpy.where(foos[Upper]>(method[Upper]))
```
because the confusingly-named variable `method` is actually a `set`, as returned by your fun... | It's hard to read your code.. Anyway, you can't access a set using `[]`, that is, `foos[Upper]`, `method[Upper]`, etc are all illegal. I don't see why you convert `foo`, `x` into set. In addition, for a point produced by `method2`, say (x0, y0), it is very likely that x0 is not present in `x`.
I'm not familiar with nu... |
64,155,517 | I am trying to create a CSS grid, but it gets scattered when using width.
I want 3 posts on a row. I believe the problem might be with my border box. Only the desktop view is affected, mobile view looks perfectly normal.
I am using `width: 33.333%` to achieve the grid.
What is wrong with the CSS code?
```css
/*----... | 2020/10/01 | [
"https://Stackoverflow.com/questions/64155517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6499765/"
] | You are better off using `flex-box` or `grid` for this. There are a few things with your code that needed to be changed:
1. You have `float` and `width` set on your inner `li` item. That doesn't work when it's a child element, so, the `li` was floating in relation to its parent `ul`.
2. You can move the padding on the... | I don't get why using that HTML strucure, it looks unnecessarily complicated!
Your problem is that the divs(.cont.contt) have a height and interacts with each other misaliging everything else, I don't think is a correct approach.
A partial solution might be to forse a height to 0 but is not clean at all.
I'd suggest ... |
18,519,217 | When creating a string out of many substrings what is more pythonic - + or %?
```
big_string = string1 + string2 + ... + stringN
big_string = ''
for i in range(n):
big_string+=str(i)
```
or
```
big_string = "%s%s...%s" % (string1, string2, ... , stringN)
big_string = ''
for i in range(n):
big_string = "%s... | 2013/08/29 | [
"https://Stackoverflow.com/questions/18519217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1445070/"
] | ```
big_string = ''.join([string1, string2, ..., stringN])
``` | `big_string = reduce(lambda x, y: x + y, [string1, string2, ..., stringN], "")` |
37,002,134 | I have just started to use Tensorflow and I have done "hello world" with my test.py file. Moving on to next step, I started to do tutorial(<https://www.tensorflow.org/versions/master/tutorials/mnist/beginners/index.html>).
This is what I have done
>
> $ git clone <https://github.com/tensorflow/tensorflow>
>
>
>
a... | 2016/05/03 | [
"https://Stackoverflow.com/questions/37002134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6285272/"
] | You were pretty close with the `drop` function, but I suggest you take a look at its documentation. It drops the given number of elements from the beginning of the list.
What you actually want is `take` the first one and `takeRight` the last one:
```
mp.mapValues(list => list.take(1) ++ list.takeRight(1))
```
This ... | It looks like your map has lists of tuples, not lists of strings. Something like this should work:
```
m.mapValues { case List((a,b,c)) => (a,c) }
```
or
```
m.mapValues { case List((a,b,c)) => List((a,c)) }
```
or
```
m.mapValues { case List((a,b,c)) => List(a,c) }
```
... depending on what type of ou... |
10,713,966 | I am trying to migrate over to Python from Matlab and can't figure out how to get interactive(?) plotting working within the Spyder IDE. My test code is shown below. With the .ion() nothing happens, I get a quick flash of a figure being drawn then the window instantly closes and spits out my Hello. Without the .ion() t... | 2012/05/23 | [
"https://Stackoverflow.com/questions/10713966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1411736/"
] | The run configuration should be set to *Execute in current Python or IPython interpreter* which by default allows for interactive plotting. If the interpreter is set to *Execute in a new dedicated Python interpreter* then *Interact with the Python interpreter after execution* must be selected. | in my case, these were the default settings in spyder however it still didn't show the plot until I typed: **%matplotlib inline**
Not sure if this is helpful but thought of sharing here. |
25,858,331 | Is there a meaningful difference between
```
if self.pk is not None:
```
and
```
if self.pk:
```
when checking a model field in python django?
Other languages have all kinds of differing 'correct' ways to check for a variable being null, empty, nonexistant, whatever.
a) I don't know how python handles the che... | 2014/09/15 | [
"https://Stackoverflow.com/questions/25858331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3539965/"
] | The first check is checking that the primary key is not [`None`](https://docs.python.org/3/library/constants.html#None). The second is checking that the primary key is [truthy](https://docs.python.org/3/library/stdtypes.html#truth-value-testing). So yes, there is a difference. | `Pk` is a [property](https://github.com/django/django/blob/1.7/django/db/models/base.py#L515) that usually resolves to `id`. There is no magic other than that.
So the only difference between the two statements is how Python treats them. The first one explicitely tests if `pk` is None, whereas the second one will pass ... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | The problem here is that `range(1, 11)` returns a list and `for...in` iterates over the list elements hence changing `i` to something else doesn't work as expected. Using a `while` loop should solve your problem. | Just some food for thought.
The for loop loops over an iterable. Create your own iterable that you can move forward yourself.
```
iterator = iter(range(11))
for i in iterator:
print 'for i = ', i
try:
print 'next()', iterator.next()
except StopIteration:
continue
>>> foo()
for i = 0
next... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | One possibility is that you want to skip items. Everything to do with looping over an index is ugly but here's a way to do that with a while loop.
```
i = 1
while i < 11:
if predicate(i):
i = 4
i += 1
```
---
It's better to loop over items of the list that you want to work with directly and just ski... | For this case, you may want to use *while loop* instead of *for loop* in Python.
For example:
```
i = 0
while i < 10:
if ...:
i = 4
``` |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | Python does not permit you to modify your looping variable inline. If you wish to do this you should do the following
```
i = 0
while i < 10:
if i == 3:
i = 7
print(i)
i += 1
```
This should have the effect you desire.
You can also do the following:
```
for i in range(10):
if 2 < i < 7:
c... | For this case, you may want to use *while loop* instead of *for loop* in Python.
For example:
```
i = 0
while i < 10:
if ...:
i = 4
``` |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | Python does not permit you to modify your looping variable inline. If you wish to do this you should do the following
```
i = 0
while i < 10:
if i == 3:
i = 7
print(i)
i += 1
```
This should have the effect you desire.
You can also do the following:
```
for i in range(10):
if 2 < i < 7:
c... | Mind you that is just a bad idea. Changing iteration variable inside a for loop? In my eyes thats equivalent to a goto statement.
Why don't you just ask what you want to accomplish?
* Do you want to filter collection? Use continue statement.
* Or do you want to repeat some things more times? Create a repeat loop insi... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | Python does not permit you to modify your looping variable inline. If you wish to do this you should do the following
```
i = 0
while i < 10:
if i == 3:
i = 7
print(i)
i += 1
```
This should have the effect you desire.
You can also do the following:
```
for i in range(10):
if 2 < i < 7:
c... | Just some food for thought.
The for loop loops over an iterable. Create your own iterable that you can move forward yourself.
```
iterator = iter(range(11))
for i in iterator:
print 'for i = ', i
try:
print 'next()', iterator.next()
except StopIteration:
continue
>>> foo()
for i = 0
next... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | The problem here is that `range(1, 11)` returns a list and `for...in` iterates over the list elements hence changing `i` to something else doesn't work as expected. Using a `while` loop should solve your problem. | Mind you that is just a bad idea. Changing iteration variable inside a for loop? In my eyes thats equivalent to a goto statement.
Why don't you just ask what you want to accomplish?
* Do you want to filter collection? Use continue statement.
* Or do you want to repeat some things more times? Create a repeat loop insi... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | The problem here is that `range(1, 11)` returns a list and `for...in` iterates over the list elements hence changing `i` to something else doesn't work as expected. Using a `while` loop should solve your problem. | For this case, you may want to use *while loop* instead of *for loop* in Python.
For example:
```
i = 0
while i < 10:
if ...:
i = 4
``` |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | Mind you that is just a bad idea. Changing iteration variable inside a for loop? In my eyes thats equivalent to a goto statement.
Why don't you just ask what you want to accomplish?
* Do you want to filter collection? Use continue statement.
* Or do you want to repeat some things more times? Create a repeat loop insi... | For this case, you may want to use *while loop* instead of *for loop* in Python.
For example:
```
i = 0
while i < 10:
if ...:
i = 4
``` |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | One possibility is that you want to skip items. Everything to do with looping over an index is ugly but here's a way to do that with a while loop.
```
i = 1
while i < 11:
if predicate(i):
i = 4
i += 1
```
---
It's better to loop over items of the list that you want to work with directly and just ski... | Just some food for thought.
The for loop loops over an iterable. Create your own iterable that you can move forward yourself.
```
iterator = iter(range(11))
for i in iterator:
print 'for i = ', i
try:
print 'next()', iterator.next()
except StopIteration:
continue
>>> foo()
for i = 0
next... |
4,290,399 | In other languages
```
for(i=0; i<10; i++){
if(...){
i = 4;
}
}
```
the loop will go up,
but in python,it doesn't work
```
for i in range(1, 11):
if ...:
i = 4
```
So can I go up in a loop with 'for'? | 2010/11/27 | [
"https://Stackoverflow.com/questions/4290399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/522057/"
] | Mind you that is just a bad idea. Changing iteration variable inside a for loop? In my eyes thats equivalent to a goto statement.
Why don't you just ask what you want to accomplish?
* Do you want to filter collection? Use continue statement.
* Or do you want to repeat some things more times? Create a repeat loop insi... | Just some food for thought.
The for loop loops over an iterable. Create your own iterable that you can move forward yourself.
```
iterator = iter(range(11))
for i in iterator:
print 'for i = ', i
try:
print 'next()', iterator.next()
except StopIteration:
continue
>>> foo()
for i = 0
next... |
53,158,284 | While trying to input my API key python is giving me a line too long code
```
E501: line too long
```
What I have is
```
notifications_client = NotificationsAPIClient(aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-11111aaa1a1a-aa11a1a1-0aa1-11a1-1111-1aa111a0a111)
```
For obvious reasons I have changed the API key to h... | 2018/11/05 | [
"https://Stackoverflow.com/questions/53158284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5348714/"
] | E501 is a linter error, not a Python interpreter error. Your code, in theory, should work just fine. If you want to prevent this error, simply break the value up (assuming it's a string ... you don't make that clear):
```
my_key = ('aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-'
'11111aaa1a1a-aa11a1a1-0aa1-11a1-... | Use \ to break your line. Like;
notifications\_client = NotificationsAPIClient(aaaaaaa\_aaaaaaaa-11aa1a1a-\
aa11-111a-aaaa-11111aaa1a1a-\
aa11a1a1-0aa1-11a1-1111-1aa111a0a111) |
53,158,284 | While trying to input my API key python is giving me a line too long code
```
E501: line too long
```
What I have is
```
notifications_client = NotificationsAPIClient(aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-11111aaa1a1a-aa11a1a1-0aa1-11a1-1111-1aa111a0a111)
```
For obvious reasons I have changed the API key to h... | 2018/11/05 | [
"https://Stackoverflow.com/questions/53158284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5348714/"
] | E501 is a linter error, not a Python interpreter error. Your code, in theory, should work just fine. If you want to prevent this error, simply break the value up (assuming it's a string ... you don't make that clear):
```
my_key = ('aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-'
'11111aaa1a1a-aa11a1a1-0aa1-11a1-... | Option which doesn't involved breaking the string literal:
```
notifications_client = NotificationsAPIClient(
"kkkkkkkkkkkkkeeeeeeeeeeeeeeeeeeeeeeeeeeyyyyyyyyyyyyyyyyyyyyy"
)
```
So long as your key is <73 (minus scope indentation) characters long. If not, you'll have to split it. |
53,158,284 | While trying to input my API key python is giving me a line too long code
```
E501: line too long
```
What I have is
```
notifications_client = NotificationsAPIClient(aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-11111aaa1a1a-aa11a1a1-0aa1-11a1-1111-1aa111a0a111)
```
For obvious reasons I have changed the API key to h... | 2018/11/05 | [
"https://Stackoverflow.com/questions/53158284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5348714/"
] | E501 is a linter error, not a Python interpreter error. Your code, in theory, should work just fine. If you want to prevent this error, simply break the value up (assuming it's a string ... you don't make that clear):
```
my_key = ('aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-'
'11111aaa1a1a-aa11a1a1-0aa1-11a1-... | E501 is not a python error, rather than a PEP8 error. Meaning your line is longer than 80 chars (in your case it's 137 chars long).
Your editor or runtime are verifying that your code is correct by PEP8 rules and that's why you are getting this "error". Your Python code has actually no errors at all.
If you want your... |
53,158,284 | While trying to input my API key python is giving me a line too long code
```
E501: line too long
```
What I have is
```
notifications_client = NotificationsAPIClient(aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-11111aaa1a1a-aa11a1a1-0aa1-11a1-1111-1aa111a0a111)
```
For obvious reasons I have changed the API key to h... | 2018/11/05 | [
"https://Stackoverflow.com/questions/53158284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5348714/"
] | E501 is not a python error, rather than a PEP8 error. Meaning your line is longer than 80 chars (in your case it's 137 chars long).
Your editor or runtime are verifying that your code is correct by PEP8 rules and that's why you are getting this "error". Your Python code has actually no errors at all.
If you want your... | Use \ to break your line. Like;
notifications\_client = NotificationsAPIClient(aaaaaaa\_aaaaaaaa-11aa1a1a-\
aa11-111a-aaaa-11111aaa1a1a-\
aa11a1a1-0aa1-11a1-1111-1aa111a0a111) |
53,158,284 | While trying to input my API key python is giving me a line too long code
```
E501: line too long
```
What I have is
```
notifications_client = NotificationsAPIClient(aaaaaaa_aaaaaaaa-11aa1a1a-aa11-111a-aaaa-11111aaa1a1a-aa11a1a1-0aa1-11a1-1111-1aa111a0a111)
```
For obvious reasons I have changed the API key to h... | 2018/11/05 | [
"https://Stackoverflow.com/questions/53158284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5348714/"
] | E501 is not a python error, rather than a PEP8 error. Meaning your line is longer than 80 chars (in your case it's 137 chars long).
Your editor or runtime are verifying that your code is correct by PEP8 rules and that's why you are getting this "error". Your Python code has actually no errors at all.
If you want your... | Option which doesn't involved breaking the string literal:
```
notifications_client = NotificationsAPIClient(
"kkkkkkkkkkkkkeeeeeeeeeeeeeeeeeeeeeeeeeeyyyyyyyyyyyyyyyyyyyyy"
)
```
So long as your key is <73 (minus scope indentation) characters long. If not, you'll have to split it. |
43,519,906 | I wrote a program that does the job, however it is not very pythonic, not pythonic and definitly not beautiful.
The program must concatenate two numpy arrays in the following manner:
As an example list0 and list1 are the input
```
list0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 1... | 2017/04/20 | [
"https://Stackoverflow.com/questions/43519906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6786718/"
] | Being NumPy tagged, here's one with it -
```
np.vstack((list0, list1)).ravel('F').tolist()
```
[`ravel()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html) here flattens in `fortran` order with the `F` specifier.
A shorter version with [`np.c_`](https://docs.scipy.org/doc/numpy/reference/gener... | Nice one liner with itertools
```
from itertools import chain
chain(*zip(list0, list1))
[0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]
``` |
43,519,906 | I wrote a program that does the job, however it is not very pythonic, not pythonic and definitly not beautiful.
The program must concatenate two numpy arrays in the following manner:
As an example list0 and list1 are the input
```
list0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 1... | 2017/04/20 | [
"https://Stackoverflow.com/questions/43519906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6786718/"
] | Being NumPy tagged, here's one with it -
```
np.vstack((list0, list1)).ravel('F').tolist()
```
[`ravel()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html) here flattens in `fortran` order with the `F` specifier.
A shorter version with [`np.c_`](https://docs.scipy.org/doc/numpy/reference/gener... | You can use `zip`
```
>>> output = [ data for elem in zip(list0,list1) for data in elem ]
[0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]
``` |
11,400,590 | I have a python dictionary consisting of JSON results. The dictionary contains a nested dictionary, which contains a nested list which contains a nested dictionary. Still with me? Here's an example:
```
{'hits':{'results':[{'key1':'value1',
'key2':'value2',
'key3':{'sub_key':'... | 2012/07/09 | [
"https://Stackoverflow.com/questions/11400590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1046501/"
] | The most appropriate way is to override the `clean` method of your model:
```
from django.template import defaultfilters
class Article(models.Model):
...
def clean(self):
if self.slug.strip() == '':
self.slug = defaultfilters.slugify(self.title)
super(Article, self).clean()
```
... | I would build it into the input form and use a ModelAdmin or ModelForm.
Admin Form:
```
from django.contrib import admin
class ArticleAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title', )}
```
ModelForm:
```
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
def c... |
11,400,590 | I have a python dictionary consisting of JSON results. The dictionary contains a nested dictionary, which contains a nested list which contains a nested dictionary. Still with me? Here's an example:
```
{'hits':{'results':[{'key1':'value1',
'key2':'value2',
'key3':{'sub_key':'... | 2012/07/09 | [
"https://Stackoverflow.com/questions/11400590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1046501/"
] | I would build it into the input form and use a ModelAdmin or ModelForm.
Admin Form:
```
from django.contrib import admin
class ArticleAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title', )}
```
ModelForm:
```
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
def c... | You can also use signals. Use the post save signal that comes with django.
<https://docs.djangoproject.com/en/dev/topics/signals/> |
11,400,590 | I have a python dictionary consisting of JSON results. The dictionary contains a nested dictionary, which contains a nested list which contains a nested dictionary. Still with me? Here's an example:
```
{'hits':{'results':[{'key1':'value1',
'key2':'value2',
'key3':{'sub_key':'... | 2012/07/09 | [
"https://Stackoverflow.com/questions/11400590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1046501/"
] | The most appropriate way is to override the `clean` method of your model:
```
from django.template import defaultfilters
class Article(models.Model):
...
def clean(self):
if self.slug.strip() == '':
self.slug = defaultfilters.slugify(self.title)
super(Article, self).clean()
```
... | You can also use signals. Use the post save signal that comes with django.
<https://docs.djangoproject.com/en/dev/topics/signals/> |
11,928,277 | I cant seem to install Rpy2 for python. Initially I ran across the problem where it displayed the following error.
```
Tried to guess R's HOME but no R command in the PATH.
```
But then I followed instructions in the following thread: [trouble installing rpy2 on win7 (R 2.12, Python 2.5)](https://stackoverflow.com/q... | 2012/08/13 | [
"https://Stackoverflow.com/questions/11928277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1610626/"
] | Me too, I had many difficulties getting rpy2 up and running, even after following the crucial link in the answer from lgauthier. But, the final help came from one of the replies on that mailing list.
Summarized, these were the 4 steps needed to get rpy2 up and running on my Windows7 computer:
1. Install rpy2 from thi... | Check the [rpy-mailing list](http://www.mail-archive.com/rpy-list@lists.sourceforge.net/msg03340.html) on July 18th. There is slight progress on the Windows front for rpy2, and people are reporting some success running it. |
11,928,277 | I cant seem to install Rpy2 for python. Initially I ran across the problem where it displayed the following error.
```
Tried to guess R's HOME but no R command in the PATH.
```
But then I followed instructions in the following thread: [trouble installing rpy2 on win7 (R 2.12, Python 2.5)](https://stackoverflow.com/q... | 2012/08/13 | [
"https://Stackoverflow.com/questions/11928277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1610626/"
] | Check the [rpy-mailing list](http://www.mail-archive.com/rpy-list@lists.sourceforge.net/msg03340.html) on July 18th. There is slight progress on the Windows front for rpy2, and people are reporting some success running it. | I tried four steps above and it works fine. Kudos on Kadee.
For question with regards to user1234440, I just use easy\_install rpy2 and it works just fine.
<http://rpy.sourceforge.net/rpy2/doc-2.2/html/overview.html#download>
Make sure you have set\_up tools installed. If you do not know how to do that,check the lin... |
11,928,277 | I cant seem to install Rpy2 for python. Initially I ran across the problem where it displayed the following error.
```
Tried to guess R's HOME but no R command in the PATH.
```
But then I followed instructions in the following thread: [trouble installing rpy2 on win7 (R 2.12, Python 2.5)](https://stackoverflow.com/q... | 2012/08/13 | [
"https://Stackoverflow.com/questions/11928277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1610626/"
] | Me too, I had many difficulties getting rpy2 up and running, even after following the crucial link in the answer from lgauthier. But, the final help came from one of the replies on that mailing list.
Summarized, these were the 4 steps needed to get rpy2 up and running on my Windows7 computer:
1. Install rpy2 from thi... | I tried four steps above and it works fine. Kudos on Kadee.
For question with regards to user1234440, I just use easy\_install rpy2 and it works just fine.
<http://rpy.sourceforge.net/rpy2/doc-2.2/html/overview.html#download>
Make sure you have set\_up tools installed. If you do not know how to do that,check the lin... |
62,686,320 | How do I stop from printing an extra input line? I'm new with python/coding
```
class1 = "Math"
class2 = "English"
class3 = "PE"
class4 = "Science"
class5 = "Art"
def get_input(className):
classInput = raw_input("Enter the score you received for " + className + ": ")
while int(classInput) >= 101 or int(classInput... | 2020/07/01 | [
"https://Stackoverflow.com/questions/62686320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13850019/"
] | Inside your print, you call `get_input()` method twice:
```
print "Your " + class1 + " score is " + str(get_input(class1)) + ", you got a " +
get_letter_grade(get_input(class1))
```
What you need to do is store your score by calling `get_input()` method once and use the stored value in print method:
```
score = ge... | I would separate out your calls to `get_input` from your print statement, not just here, but generally.
```
score = str(get_input(class1))
print "Your " + class1 + " score is " + score + ", you got a " +
get_letter_grade(score)
```
As a rule of thumb, any user input should almost always be immediately stored in a v... |
48,326,721 | I'm trying to mock **elasticsearch.Elasticsearch.indices.exists** function in my Python test case, but I'm getting the following import error. However, mock just **elasticsearch.Elasticsearch** was working fine.
```
@ddt
class TestElasticSearchConnector(unittest.TestCase):
@patch('elasticsearch.Elasticsearch.ind... | 2018/01/18 | [
"https://Stackoverflow.com/questions/48326721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1187968/"
] | This is legitimately an error. When specifying an attribute/method to mock, it must exist on the object (in this case a class). Perhaps you were expecting this attribute to exist, but it only present on the instantiated object.
```
In [1]: from elasticsearch import Elasticsearch
In [2]: Elasticsearch.indices
---------... | The Elasticserch library generates the `indices` attribute when you instantiante an `Elasticsearch()` object. And it does so using a class of the library called `IndicesClient`, and it is that class who has the `exists` method. Therefore, if you mock the response of that method of the `IndicesClient` class, you test sh... |
13,617,019 | I have a code with heavy symbolic calculations (many multiple symbolic integrals). Also I have access to both an 8-core cpu computer (with 18 GB RAM) and a small 32 cpu cluster. I prefer to remain on my professor's 8-core pc rather than to go to another professor's lab using his cluster in a more limited time, however,... | 2012/11/29 | [
"https://Stackoverflow.com/questions/13617019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1631618/"
] | I would look in to `multiprocessing` [(doc)](http://docs.python.org/2/library/multiprocessing.html) which provides a bunch of nice tools for spawning and working with sub-processes.
To quote the documentation:
>
> multiprocessing is a package that supports spawning processes using an
> API similar to the threading... | I recently ran into a similar problem. However, the following solution is only valid if (1) you wish to run the python script individually on a group of files, AND (2) each invocation of the script is independent of the others.
If the above applies to you, the simplest solution is to write a wrapper in bash along the ... |
13,617,019 | I have a code with heavy symbolic calculations (many multiple symbolic integrals). Also I have access to both an 8-core cpu computer (with 18 GB RAM) and a small 32 cpu cluster. I prefer to remain on my professor's 8-core pc rather than to go to another professor's lab using his cluster in a more limited time, however,... | 2012/11/29 | [
"https://Stackoverflow.com/questions/13617019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1631618/"
] | I would look in to `multiprocessing` [(doc)](http://docs.python.org/2/library/multiprocessing.html) which provides a bunch of nice tools for spawning and working with sub-processes.
To quote the documentation:
>
> multiprocessing is a package that supports spawning processes using an
> API similar to the threading... | It seems like there are a few reasonable ways to design this.
Let me refer to your jobs as the main job, the 9 intermediate jobs, and the many inner jobs the intermediate jobs can spin off. I'm assuming the intermediate jobs have a "merge" step after the inner jobs all finish, and the same for the outer job.
The simp... |
13,617,019 | I have a code with heavy symbolic calculations (many multiple symbolic integrals). Also I have access to both an 8-core cpu computer (with 18 GB RAM) and a small 32 cpu cluster. I prefer to remain on my professor's 8-core pc rather than to go to another professor's lab using his cluster in a more limited time, however,... | 2012/11/29 | [
"https://Stackoverflow.com/questions/13617019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1631618/"
] | It seems like there are a few reasonable ways to design this.
Let me refer to your jobs as the main job, the 9 intermediate jobs, and the many inner jobs the intermediate jobs can spin off. I'm assuming the intermediate jobs have a "merge" step after the inner jobs all finish, and the same for the outer job.
The simp... | I recently ran into a similar problem. However, the following solution is only valid if (1) you wish to run the python script individually on a group of files, AND (2) each invocation of the script is independent of the others.
If the above applies to you, the simplest solution is to write a wrapper in bash along the ... |
31,961,754 | I've got a python script that uses the **ansible** package to ping some remote servers. When executed manually (*python devmanager.py*) it works ok, but when the script is managed with **supervisor** it raises the following error:
```
Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME
```
T... | 2015/08/12 | [
"https://Stackoverflow.com/questions/31961754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/315521/"
] | You may give a try by altering the parameter "remote\_tmp" in ansible.cfg.
Default:-`$HOME/.ansible/tmp`
Update:-`/tmp/.ansible/tmp`
On this case who ever the user try to run the playbook will have enough permission to create necessary temporary files in /tmp directory. | Yes, it seems that it doesn't escape the `$HOME` variable and tries to write under `/$HOME`. |
72,815,781 | I am getting below error when using geopandas and shapely
```
AttributeError: 'DataFrame' object has no attribute 'crs'
```
Below is the code:
```
#geometry = [Point(xy) for xy in zip(complete_major_accidents['longitude'], complete_major_accidents['latitude'])]
#crs='none'
geometry = gpd.points_from_xy(complete_non... | 2022/06/30 | [
"https://Stackoverflow.com/questions/72815781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10908274/"
] | I am finally able to resolve it by changing this below piece of code
```
gdf = GeoDataFrame(complete_major_accidents, geometry)
```
to
```
gdf = GeoDataFrame(complete_nonmajor_accidents, geometry = geometry)
``` | I got the same error after updating Geopandas from an older version. Following fix did the trick.
`self.ax = gpd.GeoDataFrame().plot(figsize=(18, 12))`
to
`self.ax = gpd.GeoDataFrame(geometry=[]).plot(figsize=(18, 12))` |
64,886,214 | I'm a new python developer and I watched a few tutorials on YouTube explaining the functions and the uses for this module, but I cannot get it to work. I installed the module via pip so I don't think that is the issue.
```
import urllib.request
x = urllib.request.urlopen('https://www.google.com')
print(x.read())
``... | 2020/11/18 | [
"https://Stackoverflow.com/questions/64886214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14558709/"
] | I gave the answer to this in the previous question you asked.You do not make any effort and do not follow the answers to the questions you ask.This is probably your homework or part of homework and you just wait for a solution.I hope you will share your works and then ask questions, this can be better for your improvem... | You should not use `from` as a variable since it's a reserved keyword in python.
Maybe that's what causing your problem. |
64,886,214 | I'm a new python developer and I watched a few tutorials on YouTube explaining the functions and the uses for this module, but I cannot get it to work. I installed the module via pip so I don't think that is the issue.
```
import urllib.request
x = urllib.request.urlopen('https://www.google.com')
print(x.read())
``... | 2020/11/18 | [
"https://Stackoverflow.com/questions/64886214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14558709/"
] | You have all the ideas about the rules so I think you can finish the game by yourself. This answer may serve as a reference for you to put ideas together.
```
start_puzzle = ['a', 'a', 'a', ' ', 'b', 'b', 'b']
end_puzzle = ['b', 'b', 'b', ' ', 'a', 'a', 'a']
print(start_puzzle)
while start_puzzle != end_puzzle:
#... | You should not use `from` as a variable since it's a reserved keyword in python.
Maybe that's what causing your problem. |
31,969,540 | My python scripts often contain "executable code" (functions, classes, &c) in the first part of the file and "test code" (interactive experiments) at the end.
I want `python`, `py_compile`, `pylint` &c to completely ignore the experimental stuff at the end.
I am looking for something like `#if 0` for `cpp`.
**How ca... | 2015/08/12 | [
"https://Stackoverflow.com/questions/31969540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/850781/"
] | Use `ipython` rather than `python` for your REPL It has better code completion and introspection and when you paste indented code it can automatically "de-indent" the pasted code.
Thus you can put your experimental code in a test function and then paste in parts without worrying and having to de-indent your code.
If ... | I suggest you use a proper version control system to keep the "real" and the "experimental" parts separated.
For example, using Git, you could only include the real code without the experimental parts in your commits (using [`add -p`](https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging#Staging-Patches)), and ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.