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 |
|---|---|---|---|---|---|
13,283,253 | I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
```
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
```
Trac... | 2012/11/08 | [
"https://Stackoverflow.com/questions/13283253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328021/"
] | Django introduced a messages app in 1.2 ([release notes](https://docs.djangoproject.com/en/dev/releases/1.2/#messages-framework)), and deprecated the old user messages API.
In Django 1.4, the old message\_set API has been removed completely, so you'll have to update your code. If you follow the [messages docs](https:/... | What is in your `INSTALLED_APPS` in your `settings.py`?
Do you have `'django.contrib.messages',` included there?
Something like:
```
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.c... |
13,283,253 | I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
```
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
```
Trac... | 2012/11/08 | [
"https://Stackoverflow.com/questions/13283253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328021/"
] | Add
```
from django.contrib import messages
```
And then
```
def foo(request):
messages.add_message(request, messages.INFO, "Your message.")
``` | What is in your `INSTALLED_APPS` in your `settings.py`?
Do you have `'django.contrib.messages',` included there?
Something like:
```
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.c... |
13,283,253 | I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
```
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
```
Trac... | 2012/11/08 | [
"https://Stackoverflow.com/questions/13283253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328021/"
] | Django introduced a messages app in 1.2 ([release notes](https://docs.djangoproject.com/en/dev/releases/1.2/#messages-framework)), and deprecated the old user messages API.
In Django 1.4, the old message\_set API has been removed completely, so you'll have to update your code. If you follow the [messages docs](https:/... | From Django 1.4 docs
To enable message functionality, in settings.py do the following:
Edit the `MIDDLEWARE_CLASSES` setting and make sure it contains
```
'django.contrib.messages.middleware.MessageMiddleware'
```
If you are using a storage backend that relies on sessions (the default), `django.contrib.sessions.mid... |
13,283,253 | I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
```
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
```
Trac... | 2012/11/08 | [
"https://Stackoverflow.com/questions/13283253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328021/"
] | Django introduced a messages app in 1.2 ([release notes](https://docs.djangoproject.com/en/dev/releases/1.2/#messages-framework)), and deprecated the old user messages API.
In Django 1.4, the old message\_set API has been removed completely, so you'll have to update your code. If you follow the [messages docs](https:/... | Add
```
from django.contrib import messages
```
And then
```
def foo(request):
messages.add_message(request, messages.INFO, "Your message.")
``` |
13,283,253 | I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
```
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
```
Trac... | 2012/11/08 | [
"https://Stackoverflow.com/questions/13283253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328021/"
] | Add
```
from django.contrib import messages
```
And then
```
def foo(request):
messages.add_message(request, messages.INFO, "Your message.")
``` | From Django 1.4 docs
To enable message functionality, in settings.py do the following:
Edit the `MIDDLEWARE_CLASSES` setting and make sure it contains
```
'django.contrib.messages.middleware.MessageMiddleware'
```
If you are using a storage backend that relies on sessions (the default), `django.contrib.sessions.mid... |
64,518,660 | I am currently working with an API in python and trying to retrieve previous institution ID's from certain authors.
I have come to this point
```py
my_auth.hist_names['affiliation']
```
which outputs:
```
[{'@_fa': 'true',
'@id': '60016491',
'@href': 'http://api.elsevier.com/content/affiliation/affiliation_id/... | 2020/10/24 | [
"https://Stackoverflow.com/questions/64518660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12758690/"
] | @Anton Sizikov,
Thanks for reply, but my problem was another. Unlike Downloadpipelineartifact@2, the DownloadBuildArtifacts@0 task did not work by entering the project name and pipeline for me:
```
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
project: 'Leaf'
... | Based on your log I can see that your artifact was downloaded to `$(Build.ArtifactStagingDirectory)` directory, which is `D:\a\1\a` in your case. Then you run `dir` command there:
```sh
Successfully downloaded artifacts to D:\a\1\a
2020-10-24T22:25:48.7993950Z Directory of D:\a\1\a
2020-10-24T22:25:48.7994230Z
2020-... |
32,342,262 | I am looking for a way to search a large string for a large number of equal length substrings.
My current method is basically this:
```
offset = 0
found = []
while offset < len(haystack):
current_chunk = haystack[offset*8:offset*8+8]
if current_chunk in needles:
found.append(current_chunk)
offset += 1
``... | 2015/09/01 | [
"https://Stackoverflow.com/questions/32342262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2448592/"
] | More Pythonic, much faster:
```
for needle in needles:
if needle in haystack:
found.append(needle)
```
Edit: With some limited testing here are test results
**This algorithm:**
0.000135183334351
**Your algorithm:**
0.984048128128
Much faster. | I think that you can break it up on a multicore and parallelize your search. Something along the lines of:
```
from multiprocessing import Pool
text = "Your very long string"
"""
A generator function for chopping up a given list into chunks of
length n.
"""
def chunks(l, n):
for i in xrange(0, len(l), n):
yiel... |
37,661,456 | I would like to use spark jdbc with python. First step was to add a jar:
```
%AddJar http://central.maven.org/maven2/org/apache/hive/hive-jdbc/2.0.0/hive-jdbc-2.0.0.jar -f
```
However, the response:
```
ERROR: Line magic function `%AddJar` not found.
```
How can I add JDBC jar files in a python script? | 2016/06/06 | [
"https://Stackoverflow.com/questions/37661456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1033422/"
] | Presently, this is not possible only from a python notebook; but it is understood as an important requirement. What you can do until this is supported, is from the same spark service instance of your python notebook, create a scala notebook and `%AddJar` from there. Then all python notebooks of that same spark service ... | I don't think this is possible in Notebook's Python Kernel as %Addjar is scala kernel magic function in notebook.
You would need to rely on the service provider to add this jar to python kernel.
Another thing you could try is sc.addjar() but not sure how would it work.
[Add jar to pyspark when using notebook](https:... |
37,661,456 | I would like to use spark jdbc with python. First step was to add a jar:
```
%AddJar http://central.maven.org/maven2/org/apache/hive/hive-jdbc/2.0.0/hive-jdbc-2.0.0.jar -f
```
However, the response:
```
ERROR: Line magic function `%AddJar` not found.
```
How can I add JDBC jar files in a python script? | 2016/06/06 | [
"https://Stackoverflow.com/questions/37661456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1033422/"
] | I don't think this is possible in Notebook's Python Kernel as %Addjar is scala kernel magic function in notebook.
You would need to rely on the service provider to add this jar to python kernel.
Another thing you could try is sc.addjar() but not sure how would it work.
[Add jar to pyspark when using notebook](https:... | You can try this:
```
spark.sparkContext.addFile("filename")
``` |
37,661,456 | I would like to use spark jdbc with python. First step was to add a jar:
```
%AddJar http://central.maven.org/maven2/org/apache/hive/hive-jdbc/2.0.0/hive-jdbc-2.0.0.jar -f
```
However, the response:
```
ERROR: Line magic function `%AddJar` not found.
```
How can I add JDBC jar files in a python script? | 2016/06/06 | [
"https://Stackoverflow.com/questions/37661456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1033422/"
] | Presently, this is not possible only from a python notebook; but it is understood as an important requirement. What you can do until this is supported, is from the same spark service instance of your python notebook, create a scala notebook and `%AddJar` from there. Then all python notebooks of that same spark service ... | You can try this:
```
spark.sparkContext.addFile("filename")
``` |
36,533,759 | I have a file.dat of this type but with a lot more data:
```
Apr 1 18:15 [n1_Cam_A_120213_O.fits]:
4101.77 1. -3.5612 3.561 -0.278635 4.707 6.448 #data1
0.03223 0. 0.05278 0.05278 0.00237 0.4393 0.4125 #error1
4088.9 1. -0.404974 0.405 -0.06538 5.819 0. #data2
0. 0. 0... | 2016/04/10 | [
"https://Stackoverflow.com/questions/36533759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6184340/"
] | Try to write **system("pause");** before **return 0;** at the end of your program and press ctrl + F5. | Try this:
```
std::cin.get();
if (oper == 1)
ans = num1*num2;
else if(oper == 2)
ans = num1 / num2;
else if(oper == 3)
ans = num1 + num2;
else if(oper == 4)
ans = num1 - num2;
std::cout << ans;
std::cin.get();//this will block and prevent the console from closing until you press a key
return 0... |
57,257,751 | I've created my application in python and I want the application to be executed only one at a time. So I have used the singleton approach:
```py
from math import fmod
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import SIGNAL
import tendo
import pywinusb.hid as hid
import sys
import os
import time
import threadin... | 2019/07/29 | [
"https://Stackoverflow.com/questions/57257751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6078511/"
] | >
> Hello, it's me again! So, I have found the solution. I search a lot and I found very different ways to make the program runs only one time (singleinstance).
>
>
>
>
> In summary, it's possible to use a lock file, using the library OS, but if the computer shutdowns in a energy fall, this file will stay locking... | I had the same problem and I didn't find a way to use the singleinstance of tendo. If You need a solution right now, you can create a file using the "os" library, and put a variable there that when the program is running it is 1, else is 0, so you just have to verify that variable in the beginning of your program.
This... |
5,871,621 | I have a list of cities (simple cvs file) and I want to populate the citeis table while creating the City model.
Class description:
```
class City(models.Model):
city = modeld.CharField('city_name', max_length=50)
class Meta:
berbuse_name =....
...........
def __unicode__(self):
r... | 2011/05/03 | [
"https://Stackoverflow.com/questions/5871621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288219/"
] | We do something like this, usually.
```
import csv
from my_django_app.forms import CityForm
with open( "my file", "rb" ) as source:
rdr = csv.DictReader( source )
for row in rdr:
form= CityForm( **row )
if form.is_valid():
form.save()
else:
print form.errors
``... | [Providing initial data for models](http://docs.djangoproject.com/en/1.3/howto/initial-data/). |
30,397,107 | I want to build a simple tool that uses functions from an open source project from GitHub, SourceForge, etc. (e.g., a project such as <https://github.com/vishnubob/python-midi/>).
I searched the documentation but could not find the right way to do this. (I assume I need to point PyCharm at the source somehow and "impo... | 2015/05/22 | [
"https://Stackoverflow.com/questions/30397107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4929051/"
] | Yes there is a convention. Use `bower` if a package exists. If it doesn't, download the repo into the `vendor` folder. Import the file in your `Brocfile.js`
```
app.import('vendor/path_to/main_js_file.js');
``` | Yes, use bower or place them in `vendor/`. Then register them in `ember-cli-build.js`
Here's the documentation: <https://guides.emberjs.com/v2.14.0/addons-and-dependencies/managing-dependencies/> |
4,589,696 | I apologize up front for the dumbness of this question, but I can't figure it out and its driving me crazy.
In ruby I can do:
```
irb(main):001:0> s = "\t\t\n"
=> "\t\t\n"
irb(main):003:0> puts s
=> nil
irb(main):004:0> puts s.inspect
"\t\t\n"
```
Is there an equivalent of ruby's `inspect` function in ... | 2011/01/04 | [
"https://Stackoverflow.com/questions/4589696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/561964/"
] | [`repr()`](http://docs.python.org/library/functions.html#repr):
```
>>> print repr('\t\t\n')
'\t\t\n'
``` | You can use repr or (backticks), I am doing the exactly the same things as you did above.
```
>>> s = "\t\t\n"
>>> s
'\t\t\n'
>>> print s
>>> repr(s)
"'\\t\\t\\n'"
>>> print repr(s)
'\t\t\n'
>>> print `s`
'\t\t\n'
``` |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Thanks for your responses. Most were very good and provided good links so I'll just say that and answer my own question.
Caspin posted this [link](http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
He also mentioned that Google Tests used ULP comparison and when I looked at t... | >
> What is the best way to avoid problems
> like this?... In Python or in general.
>
>
>
What problem? You're working with physical measurements. Unless you have some *really* sophisticated equipment, the error in your measurements is going to be several orders of magnitude higher than floating-point epsilon. So... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | The difference is that if you replace `factors[units_to ]` with `1.0 / 2.54`, you're doing:
```
(base_value * 1.0) / 2.54
```
With the dictionary, you're doing:
```
base_value * (1.0 / 2.54)
```
The order of rounding matters. This is easier to see if you do:
```
>>> print (((25.4 / 10.0) * 1.0) / 2.54).__repr__(... | >
> Also interesting is how many floating points there
> are between equal numbers when one of them is
> written out as a string and read back in.
>
>
>
That is arguably a Python bug. That number was written out with just twelve digits. Two uniquely identify a 64-bit double (Python's float type) you need sevente... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Let me first answer by saying that you should read David Goldberg's classic [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&rep=rep1&type=pdf).
As some other commentators already said, the discrepancy you notice is intrinsicall... | In order to compare floats in general compare the absolute value of the difference of the floats to a chosen delta that is small enough to fit your needs.
Rhetorical Questions
* This \*\*IS a dangerous problem \*\* as it might hide errors or generate infinite loops if such a comparison is used as stop criteria.
* Mo... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Let me first answer by saying that you should read David Goldberg's classic [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&rep=rep1&type=pdf).
As some other commentators already said, the discrepancy you notice is intrinsicall... | >
> What is the best way to avoid problems
> like this?... In Python or in general.
>
>
>
What problem? You're working with physical measurements. Unless you have some *really* sophisticated equipment, the error in your measurements is going to be several orders of magnitude higher than floating-point epsilon. So... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | The difference is that if you replace `factors[units_to ]` with `1.0 / 2.54`, you're doing:
```
(base_value * 1.0) / 2.54
```
With the dictionary, you're doing:
```
base_value * (1.0 / 2.54)
```
The order of rounding matters. This is easier to see if you do:
```
>>> print (((25.4 / 10.0) * 1.0) / 2.54).__repr__(... | Let me first answer by saying that you should read David Goldberg's classic [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&rep=rep1&type=pdf).
As some other commentators already said, the discrepancy you notice is intrinsicall... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Thanks for your responses. Most were very good and provided good links so I'll just say that and answer my own question.
Caspin posted this [link](http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
He also mentioned that Google Tests used ULP comparison and when I looked at t... | >
> Also interesting is how many floating points there
> are between equal numbers when one of them is
> written out as a string and read back in.
>
>
>
That is arguably a Python bug. That number was written out with just twelve digits. Two uniquely identify a 64-bit double (Python's float type) you need sevente... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Let me first answer by saying that you should read David Goldberg's classic [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&rep=rep1&type=pdf).
As some other commentators already said, the discrepancy you notice is intrinsicall... | >
> Also interesting is how many floating points there
> are between equal numbers when one of them is
> written out as a string and read back in.
>
>
>
That is arguably a Python bug. That number was written out with just twelve digits. Two uniquely identify a 64-bit double (Python's float type) you need sevente... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | The difference is that if you replace `factors[units_to ]` with `1.0 / 2.54`, you're doing:
```
(base_value * 1.0) / 2.54
```
With the dictionary, you're doing:
```
base_value * (1.0 / 2.54)
```
The order of rounding matters. This is easier to see if you do:
```
>>> print (((25.4 / 10.0) * 1.0) / 2.54).__repr__(... | if I run this
```
x = 0.3+0.3+0.3
if (x != 0.9): print "not equal"
if (x == 0.9): print "equal"
```
it prints "not equal" which is wrong but as
```
x-0.9
```
gives the float error as -1.11022302e-16 i just do something like this:
```
if (x - 0.9 < 10**-8): print "equal (almost)"
```
otherwise you can convert... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | if I run this
```
x = 0.3+0.3+0.3
if (x != 0.9): print "not equal"
if (x == 0.9): print "equal"
```
it prints "not equal" which is wrong but as
```
x-0.9
```
gives the float error as -1.11022302e-16 i just do something like this:
```
if (x - 0.9 < 10**-8): print "equal (almost)"
```
otherwise you can convert... | >
> Also interesting is how many floating points there
> are between equal numbers when one of them is
> written out as a string and read back in.
>
>
>
That is arguably a Python bug. That number was written out with just twelve digits. Two uniquely identify a 64-bit double (Python's float type) you need sevente... |
3,049,101 | I have a piece of code that behaves differently depending on whether I go through a dictionary to get conversion factors or whether I use them directly.
The following piece of code will print `1.0 == 1.0 -> False`
But if you replace `factors[units_from]` with `10.0` and `factors[units_to ]` with `1.0 / 2.54` it will ... | 2010/06/15 | [
"https://Stackoverflow.com/questions/3049101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180464/"
] | Thanks for your responses. Most were very good and provided good links so I'll just say that and answer my own question.
Caspin posted this [link](http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
He also mentioned that Google Tests used ULP comparison and when I looked at t... | Let me first answer by saying that you should read David Goldberg's classic [What Every Computer Scientist Should Know About Floating-Point Arithmetic](http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.102.244&rep=rep1&type=pdf).
As some other commentators already said, the discrepancy you notice is intrinsicall... |
45,078,474 | I want to implement import feature with required and optional parameters, to run this in this way:
```
python manage.py import --mode archive
```
where `--mode` is required and `archive` also.
I'm using argparse library.
```
class Command(BaseCommand):
help = 'Import'
def add_arguments(self, parser):
... | 2017/07/13 | [
"https://Stackoverflow.com/questions/45078474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7985656/"
] | You created a positional argument (no `--` option in front of the name). Positional arguments are *always* required. You can't use `required=True` for such options, just drop the `required`. Drop the `default` too; a required argument can't have a default value (it would never be used anyway):
```
parser.add_argument(... | I think that `--mode archive` is supposed to mean "mode is archive", in other words `archive` is the *value* of the `--mode` argument, not a separate argument. If it were, it would have to be `--archive` which is not what you want.
Just leave out the definition of `archive`. |
15,768,136 | In python 2.7, I want to run:
$ ./script.py initparms.py
This is a trick to supply a parameter file to script.py, since initparms.py contains several python variables e.g.
```
Ldir = '/home/marzipan/jelly'
LMaps = True
# etc.
```
script.py contains:
```
X = __import__(sys.argv[1])
Ldir = X.Ldir
LMaps = X.Lmaps
... | 2013/04/02 | [
"https://Stackoverflow.com/questions/15768136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021819/"
] | You can use [`execfile`](http://docs.python.org/2/library/functions.html#execfile):
```
execfile(sys.argv[1])
```
Of course, the usual warnings with `exec` or `eval` apply (Your script has no way of knowing whether it is running trusted or untrusted code).
My suggestion would be to not do what you're doing and inst... | You could do something like this:
```
import os
import imp
import sys
try:
module_name = sys.argv[1]
module_info = imp.find_module(module_name, [os.path.abspath(os.path.dirname(__file__))] + sys.path)
module_properties = imp.load_module(module_name, *module_info)
except ImportError:
pass
else:
try... |
15,768,136 | In python 2.7, I want to run:
$ ./script.py initparms.py
This is a trick to supply a parameter file to script.py, since initparms.py contains several python variables e.g.
```
Ldir = '/home/marzipan/jelly'
LMaps = True
# etc.
```
script.py contains:
```
X = __import__(sys.argv[1])
Ldir = X.Ldir
LMaps = X.Lmaps
... | 2013/04/02 | [
"https://Stackoverflow.com/questions/15768136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021819/"
] | here's a one-liner:
```
globals().update(__import__(sys.argv[1]).__dict__)
``` | You can use [`execfile`](http://docs.python.org/2/library/functions.html#execfile):
```
execfile(sys.argv[1])
```
Of course, the usual warnings with `exec` or `eval` apply (Your script has no way of knowing whether it is running trusted or untrusted code).
My suggestion would be to not do what you're doing and inst... |
15,768,136 | In python 2.7, I want to run:
$ ./script.py initparms.py
This is a trick to supply a parameter file to script.py, since initparms.py contains several python variables e.g.
```
Ldir = '/home/marzipan/jelly'
LMaps = True
# etc.
```
script.py contains:
```
X = __import__(sys.argv[1])
Ldir = X.Ldir
LMaps = X.Lmaps
... | 2013/04/02 | [
"https://Stackoverflow.com/questions/15768136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1021819/"
] | here's a one-liner:
```
globals().update(__import__(sys.argv[1]).__dict__)
``` | You could do something like this:
```
import os
import imp
import sys
try:
module_name = sys.argv[1]
module_info = imp.find_module(module_name, [os.path.abspath(os.path.dirname(__file__))] + sys.path)
module_properties = imp.load_module(module_name, *module_info)
except ImportError:
pass
else:
try... |
70,668,633 | I am currently on a Discord Bot interacting with the Controlpanel API. (<https://documenter.getpostman.com/view/9044962/TzY69ub2#02b8da43-ab01-487d-b2f5-5f8699b509cd>)
Now, I am getting an KeyError when listing a specific user.
```
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer <censored>'... | 2022/01/11 | [
"https://Stackoverflow.com/questions/70668633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17903752/"
] | This KeyError happens usually when the Key doesn't exist(not exist or even a typo). in your case I think you dont have the 'data' key in your response and your should use something like:
```
data.json()
```
if you can post the complete response it would be more convinient to give you some hints. | The endpoint you're hitting does not return a list but a single object.
You should use the generic endpoint : `{{url}}/api/users`
Also I don't think you want to recreate your `embed` object for each user.
```py
headers = {
'Authorization': 'Bearer <censored>'
}
url = 'https://<censored>'
endpoint = '/api/users'... |
41,281,072 | I would like to make a file with 3 main columns but my current file has different number of columns per row.
an example of my file is like this:
```
BPIFB3,chr20;ENST00000375494.3
PXDN,chr2,ENST00000252804.4;ENST00000483018.1
RP11,chr2,ENST00000607956.1
RNF19B,chr1,ENST00000373456.7;ENST00000356990.5;ENS... | 2016/12/22 | [
"https://Stackoverflow.com/questions/41281072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7310023/"
] | **If** your input is actually well-formed, you can do this:
```
for row in reader:
for thing in row[2].split(';'):
writer.writerow(row[:2]+[thing])
```
But as it exists, your first row has malformed data that doesn't match the rest of your rows. So if that *is* an example of your data, then [you could tr... | Try this:
```
import csv
with open('data.tbl') as f, open('out.tbl', 'w') as out:
reader = csv.reader(f, delimiter='\t')
writer = csv.writer(out, delimiter='\t')
for row in reader:
if len(row) == 3:
writer.writerow(row)
else:
n = len(row)
writer.writerow... |
41,281,072 | I would like to make a file with 3 main columns but my current file has different number of columns per row.
an example of my file is like this:
```
BPIFB3,chr20;ENST00000375494.3
PXDN,chr2,ENST00000252804.4;ENST00000483018.1
RP11,chr2,ENST00000607956.1
RNF19B,chr1,ENST00000373456.7;ENST00000356990.5;ENS... | 2016/12/22 | [
"https://Stackoverflow.com/questions/41281072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7310023/"
] | You don't need dictionary for this problem list is sufficient for this. And delimiter '\t' won't work in your problem coz there are multiple space not tab. so we need to remove multiple space with re. so below program will work for your solution.
```
import re
with open('data.tbl') as f, open('out.tbl', 'w') as out:
... | Try this:
```
import csv
with open('data.tbl') as f, open('out.tbl', 'w') as out:
reader = csv.reader(f, delimiter='\t')
writer = csv.writer(out, delimiter='\t')
for row in reader:
if len(row) == 3:
writer.writerow(row)
else:
n = len(row)
writer.writerow... |
41,281,072 | I would like to make a file with 3 main columns but my current file has different number of columns per row.
an example of my file is like this:
```
BPIFB3,chr20;ENST00000375494.3
PXDN,chr2,ENST00000252804.4;ENST00000483018.1
RP11,chr2,ENST00000607956.1
RNF19B,chr1,ENST00000373456.7;ENST00000356990.5;ENS... | 2016/12/22 | [
"https://Stackoverflow.com/questions/41281072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7310023/"
] | Try splitting on either commas or semicolons with `re`:
```
import re
import csv
with open('data.tbl') as infile, open('out.tbl','w') as outfile:
data = [re.split(",|;",x.strip("\n")) for x in infile]
output = []
for line in data:
if len(line) > 3:
output.append(line[:3])
f... | Try this:
```
import csv
with open('data.tbl') as f, open('out.tbl', 'w') as out:
reader = csv.reader(f, delimiter='\t')
writer = csv.writer(out, delimiter='\t')
for row in reader:
if len(row) == 3:
writer.writerow(row)
else:
n = len(row)
writer.writerow... |
17,517,718 | I am working on a project which aims to fetch some data from some websites and then stores into database. But these websites contains different charsets such as utf-8, gbk. The fetched data is unicode so i wonder when to convert to string is the right way. I convert to string immediately for now, but it seems that the ... | 2013/07/08 | [
"https://Stackoverflow.com/questions/17517718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/674199/"
] | Your `start_time` (`Time.now.in_time.zone`) is populated on the page load/render. Whereas the `updated_at` is re-populated when you save the model. Your times are only off by a few seconds, which indicates that it took the person a few seconds to submit the form.
Based on the updated requirement of it being when a sta... | 1 . You set a static time in the view witch gets generated on page load.
2 . Set the time in the controller when you save the object. Basic example:
```
@object = Object.new(params[:object].merge(:start_time => Time.now))
if @object.save
redirect_to 'best side in da world'
else
render :new
end
``` |
8,397,617 | I am trying to get python to emulatue mouse clicks, and then type a phrase into the pop up window that the mouse clicks into or the text box.
1) click a security box "run" link with mouse
2) move inside a pop up and enter different phrases with python
What would be the best way to control the mouse and keyboard in th... | 2011/12/06 | [
"https://Stackoverflow.com/questions/8397617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1027427/"
] | To trigger an event simply call the relevant event function in jQuery on the element, with no handler function defined, like this:
```
$("#2").click();
```
Or there is also `trigger()`, which accepts the event type as a parameter:
```
$("#2").trigger('click');
```
However it's worth noting that `Id` attributes be... | You can use `trigger`:
```
$('#2').trigger('click');
```
<http://api.jquery.com/trigger/> |
8,397,617 | I am trying to get python to emulatue mouse clicks, and then type a phrase into the pop up window that the mouse clicks into or the text box.
1) click a security box "run" link with mouse
2) move inside a pop up and enter different phrases with python
What would be the best way to control the mouse and keyboard in th... | 2011/12/06 | [
"https://Stackoverflow.com/questions/8397617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1027427/"
] | To trigger an event simply call the relevant event function in jQuery on the element, with no handler function defined, like this:
```
$("#2").click();
```
Or there is also `trigger()`, which accepts the event type as a parameter:
```
$("#2").trigger('click');
```
However it's worth noting that `Id` attributes be... | Yes, the `.click()` methods is used also to trigger the `click` event.
```
$('#2').click();
```
This is a shorthand for `$('#2').trigger('click');`.
**Also note that an id cannot start with a digit.**
[jQuery documentation for `click()`](http://api.jquery.com/click/)
[jQuery documentation for `trigger()`](http://... |
8,397,617 | I am trying to get python to emulatue mouse clicks, and then type a phrase into the pop up window that the mouse clicks into or the text box.
1) click a security box "run" link with mouse
2) move inside a pop up and enter different phrases with python
What would be the best way to control the mouse and keyboard in th... | 2011/12/06 | [
"https://Stackoverflow.com/questions/8397617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1027427/"
] | To trigger an event simply call the relevant event function in jQuery on the element, with no handler function defined, like this:
```
$("#2").click();
```
Or there is also `trigger()`, which accepts the event type as a parameter:
```
$("#2").trigger('click');
```
However it's worth noting that `Id` attributes be... | Usually you could just call the same function as the click calls.
Did you need something like the $(this) to be populated? |
8,397,617 | I am trying to get python to emulatue mouse clicks, and then type a phrase into the pop up window that the mouse clicks into or the text box.
1) click a security box "run" link with mouse
2) move inside a pop up and enter different phrases with python
What would be the best way to control the mouse and keyboard in th... | 2011/12/06 | [
"https://Stackoverflow.com/questions/8397617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1027427/"
] | To trigger an event simply call the relevant event function in jQuery on the element, with no handler function defined, like this:
```
$("#2").click();
```
Or there is also `trigger()`, which accepts the event type as a parameter:
```
$("#2").trigger('click');
```
However it's worth noting that `Id` attributes be... | You can use [`triggerHandler`](http://api.jquery.com/triggerHandler/) for this:
```
$("#2").triggerHandler("click");
``` |
51,209,598 | Here is a sample of json data I created from defaultdict in python.
```
[{
"company": [
"ABCD"
],
"fullname": [
"Bruce Lamont",
"Ariel Zilist",
"Bruce Lamont",
"Bobby Ramirez"
],
"position": [
" The Hesh",
" Server",
" HESH",
... | 2018/07/06 | [
"https://Stackoverflow.com/questions/51209598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7655640/"
] | you are adding an extra comma in the end for profile\_url array. The proper json should be
```
[{
"company": [
"ABCD"
],
"fullname": [
"Bruce Lamont",
"Ariel Zilist",
"Bruce Lamont",
"Bobby Ramirez"
],
"position": [
" The Hesh",
" Server",
... | ```
import json
j = '[{"company":["ABCD"],"fullname":["Bruce Lamont","Ariel Zilist","Bruce Lamont","Bobby Ramirez"],"position":[" The Hesh"," Server"," HESH"," Production Assistant"],"profile_url":["http://www.url1.com","http://www.url2.com","http://www.url3.com","http://www.url4.com"]}]'
json_obj = json.loads(j)
`... |
55,962,661 | I am very new to python and have trouble printing the length of a variable I have created.
I have tried len(), and I have tried converting to lists, arrays and tuples and so on and cannot get it to print the length correctly.
```
print(k1_idx_label0)
len(k1_idx_label0)
```
And the output is ---
```
(array([ 0... | 2019/05/03 | [
"https://Stackoverflow.com/questions/55962661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11338333/"
] | The tuple has just `1` element, if you want to know the size of that element inside the tuple:
```
len(k1_idx_label0[0])
```
if you want to know the size of **all** elements in the tuple:
```
[len(e) for e in k1_idx_label0]
``` | Try:
```
print(len(k1_idx_label0[0]))
``` |
55,962,661 | I am very new to python and have trouble printing the length of a variable I have created.
I have tried len(), and I have tried converting to lists, arrays and tuples and so on and cannot get it to print the length correctly.
```
print(k1_idx_label0)
len(k1_idx_label0)
```
And the output is ---
```
(array([ 0... | 2019/05/03 | [
"https://Stackoverflow.com/questions/55962661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11338333/"
] | Your `k1_idx_label0` variable is actually a tuple containing a single item. That item happens to be a `numpy.array`, but `len()` is correctly reporting the length of the object you’re passing to it.
Instead try:
```
len(k1_idx_label0[0])
```
Which should give you what you want: the length of the first element of th... | Try:
```
print(len(k1_idx_label0[0]))
``` |
55,962,661 | I am very new to python and have trouble printing the length of a variable I have created.
I have tried len(), and I have tried converting to lists, arrays and tuples and so on and cannot get it to print the length correctly.
```
print(k1_idx_label0)
len(k1_idx_label0)
```
And the output is ---
```
(array([ 0... | 2019/05/03 | [
"https://Stackoverflow.com/questions/55962661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11338333/"
] | Your `k1_idx_label0` variable is actually a tuple containing a single item. That item happens to be a `numpy.array`, but `len()` is correctly reporting the length of the object you’re passing to it.
Instead try:
```
len(k1_idx_label0[0])
```
Which should give you what you want: the length of the first element of th... | The tuple has just `1` element, if you want to know the size of that element inside the tuple:
```
len(k1_idx_label0[0])
```
if you want to know the size of **all** elements in the tuple:
```
[len(e) for e in k1_idx_label0]
``` |
24,890,259 | **I'm not looking for a solution (I have two ;) ), but on insight to compare the strengths and weaknesses of each solution considering python's internals. Thanks !**
With a coworker, we wish to extract the difference between two successive list elements, for all elements. So, for list :
```
[1,2,4]
```
the expected... | 2014/07/22 | [
"https://Stackoverflow.com/questions/24890259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2481478/"
] | With a generator:
```
def diff_elements(lst):
"""
>>> list(diff_elements([]))
[]
>>> list(diff_elements([1]))
[]
>>> list(diff_elements([1, 2, 4, 7]))
[1, 2, 3]
"""
as_iter = iter(lst)
last = next(as_iter)
for value in as_iter:
yield value - last
last = value... | If I understood your question I suggest you use something like that:
```
diffList = lambda l: [(l[i] - l[i-1]) for i in range(1, len(l))]
answer = diffList( [ 1,2,4] )
```
This function will give you a list with the differences between all consecutive elements in the input list.
This one is similar with your first ... |
24,890,259 | **I'm not looking for a solution (I have two ;) ), but on insight to compare the strengths and weaknesses of each solution considering python's internals. Thanks !**
With a coworker, we wish to extract the difference between two successive list elements, for all elements. So, for list :
```
[1,2,4]
```
the expected... | 2014/07/22 | [
"https://Stackoverflow.com/questions/24890259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2481478/"
] | With a generator:
```
def diff_elements(lst):
"""
>>> list(diff_elements([]))
[]
>>> list(diff_elements([1]))
[]
>>> list(diff_elements([1, 2, 4, 7]))
[1, 2, 3]
"""
as_iter = iter(lst)
last = next(as_iter)
for value in as_iter:
yield value - last
last = value... | With no lambdas:
```
[l[i+1] - l[i] for i in range(len(l) - 1)]
```
Eg:
```
>>> l = [1, 4, 8, 15, 16]
>>> [l[i+1] - l[i] for i in range(len(l) - 1)]
[3, 4, 7, 1]
```
A bit faster, as you can see (EDIT: Adding the most voted solution in <https://stackoverflow.com/a/2400875/1171280>):
```
>>> import timeit
>>>
>>... |
12,805,699 | recently i understand the great advantage to use the list comprehension. I am working with several milion of points (x,y,z) stored in a special format \*.las file. In python there are two way to work with this format:
```
Liblas module [http://www.liblas.org/tutorial/python.html][1] (in a C++/Python)
laspy module [ht... | 2012/10/09 | [
"https://Stackoverflow.com/questions/12805699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493192/"
] | Python is case-sensitive. Too me it looks like you ask for attribute `x`, but it should be an uppercase `X`. | Try
```
import numpy as np
...
points = np.array([f.X, f.Y]).T
``` |
12,805,699 | recently i understand the great advantage to use the list comprehension. I am working with several milion of points (x,y,z) stored in a special format \*.las file. In python there are two way to work with this format:
```
Liblas module [http://www.liblas.org/tutorial/python.html][1] (in a C++/Python)
laspy module [ht... | 2012/10/09 | [
"https://Stackoverflow.com/questions/12805699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493192/"
] | Python is case-sensitive. Too me it looks like you ask for attribute `x`, but it should be an uppercase `X`. | It looks like `Point` has a `make_nice()` method that makes more attributes show up.
```
for p in f: p.make_nice()
```
Now your list comp should work (with uppercase X and Y--see comments below).
```
[(p.X,p.Y) for p in f]
```
note: This answer is not tested. It is based on reading the source of [`laspy.util.Poin... |
39,190,274 | I am currently developing a Python application which I continually performance test, simply by recording the runtime of various parts.
A lot of the code is related only to the testing environment and would not exist in the real world application, I have these separated into functions and at the moment I comment out th... | 2016/08/28 | [
"https://Stackoverflow.com/questions/39190274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2071737/"
] | That's because of
>
> Let `shiftCount` be the result of masking out all but the least significant 5 bits of `rnum`, that is, compute `rnum & 0x1F`.
>
>
>
of how the `<<` operation is defined. See <http://www.ecma-international.org/ecma-262/6.0/#sec-left-shift-operator-runtime-semantics-evaluation>
So according t... | JavaScript defines a left-shift by 32 to do nothing, presumably because it smacks up against the 32-bit boundary. You cannot actually shift anything more than 31 bits across.
Your approach of first shifting 31 bits, then a final bit, works around JavaScript thinking that shifting so much doesn't make sense. Indeed, it... |
39,190,274 | I am currently developing a Python application which I continually performance test, simply by recording the runtime of various parts.
A lot of the code is related only to the testing environment and would not exist in the real world application, I have these separated into functions and at the moment I comment out th... | 2016/08/28 | [
"https://Stackoverflow.com/questions/39190274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2071737/"
] | That's because of
>
> Let `shiftCount` be the result of masking out all but the least significant 5 bits of `rnum`, that is, compute `rnum & 0x1F`.
>
>
>
of how the `<<` operation is defined. See <http://www.ecma-international.org/ecma-262/6.0/#sec-left-shift-operator-runtime-semantics-evaluation>
So according t... | The reason is that the shift count is considered modulo 32.
This itself happens because (my guess) this is how most common hardware for desktops/laptops works today (x86).
This itself happens because.... well, just because.
These shift limitations are indeed in some cases annoying... for example it would have been b... |
531,487 | I'm looking for a python browser widget (along the lines of pyQT4's [QTextBrowser](http://doc.trolltech.com/3.3/qtextbrowser.html) class or [wxpython's HTML module](http://www.wxpython.org/docs/api/wx.html-module.html)) that has events for interaction with the DOM. For example, if I highlight an h1 node, the widget cla... | 2009/02/10 | [
"https://Stackoverflow.com/questions/531487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11110/"
] | It may not be ideal for your purposes, but you might want to take a look at the Python bindings to KHTML that are part of PyKDE. One place to start looking is the KHTMLPart class:
<http://api.kde.org/pykde-4.2-api/khtml/KHTMLPart.html>
Since the API for this class is based on the signals and slots paradigm used in Qt... | I would also love such a thing. I suspect one with Python bindings does not exist, but would be really happy to be wrong about this.
One option I recently looked at (but never tried) is the [Webkit](http://webkit.org/) browser. Now this has some bindings for Python, and built against different toolkits (I use GTK). Ho... |
531,487 | I'm looking for a python browser widget (along the lines of pyQT4's [QTextBrowser](http://doc.trolltech.com/3.3/qtextbrowser.html) class or [wxpython's HTML module](http://www.wxpython.org/docs/api/wx.html-module.html)) that has events for interaction with the DOM. For example, if I highlight an h1 node, the widget cla... | 2009/02/10 | [
"https://Stackoverflow.com/questions/531487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11110/"
] | It may not be ideal for your purposes, but you might want to take a look at the Python bindings to KHTML that are part of PyKDE. One place to start looking is the KHTMLPart class:
<http://api.kde.org/pykde-4.2-api/khtml/KHTMLPart.html>
Since the API for this class is based on the signals and slots paradigm used in Qt... | If you don't mind being limited to Windows, you can use the IE browser control. From wxPython, it's in wx.lib.iewin.IEHtmlWindow (there's a demo in the wxPython demo). This gives you full access to the DOM and ability to sink events, e.g.
```
ie.document.body.innerHTML = u"<p>Hello, world</p>"
``` |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | you are looking for [crontab](http://en.wikipedia.org/wiki/Crontab) rather than loop. | Sounds like you want to use something like cron instead, but... if you are sure you want something to run in the same terminal-window every N minutes (or seconds, actually), you could use the 'watch' command.
```
watch -n 60 python myscripy.py
``` |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | you are looking for [crontab](http://en.wikipedia.org/wiki/Crontab) rather than loop. | If you really need to schedule something, then you want crontab.
But if this is temporary (i.e. checking to see if a file has appeared or whatever), then here's how you could do this
`while true ; do python myscript.py ; sleep 15m; done`
This will execute forever ("while true") so you'll have to ctrl-c to cancel it ... |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | you are looking for [crontab](http://en.wikipedia.org/wiki/Crontab) rather than loop. | using crontab you can add an entry like `*/15 * * * * python /path/to/myscript.py` |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If you really need to schedule something, then you want crontab.
But if this is temporary (i.e. checking to see if a file has appeared or whatever), then here's how you could do this
`while true ; do python myscript.py ; sleep 15m; done`
This will execute forever ("while true") so you'll have to ctrl-c to cancel it ... | Sounds like you want to use something like cron instead, but... if you are sure you want something to run in the same terminal-window every N minutes (or seconds, actually), you could use the 'watch' command.
```
watch -n 60 python myscripy.py
``` |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Sounds like you want to use something like cron instead, but... if you are sure you want something to run in the same terminal-window every N minutes (or seconds, actually), you could use the 'watch' command.
```
watch -n 60 python myscripy.py
``` | using crontab you can add an entry like `*/15 * * * * python /path/to/myscript.py` |
5,475,549 | In the Ubuntu terminal, how do I loop a command like
```
python myscript.py
```
so that it runs every 15 minutes? | 2011/03/29 | [
"https://Stackoverflow.com/questions/5475549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If you really need to schedule something, then you want crontab.
But if this is temporary (i.e. checking to see if a file has appeared or whatever), then here's how you could do this
`while true ; do python myscript.py ; sleep 15m; done`
This will execute forever ("while true") so you'll have to ctrl-c to cancel it ... | using crontab you can add an entry like `*/15 * * * * python /path/to/myscript.py` |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | Everything from the request is just a string. The modelbinder matches up keys in the request body with property names, and then attempts to coerce them to the appropriate type. If the property is not posted or is posted with an empty string, that will obviously fail when trying to convert to an int. As a result, you en... | >
> non-nullable required types.
>
>
>
You do not. It is either required - then there is no sense in it being nullable - or it is not required, then you nullable makes sense, but it makes no sense to require it.
Attributes are always for the whole request. You are in a logical problem because you try to use them ... |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | >
> non-nullable required types.
>
>
>
You do not. It is either required - then there is no sense in it being nullable - or it is not required, then you nullable makes sense, but it makes no sense to require it.
Attributes are always for the whole request. You are in a logical problem because you try to use them ... | There was the way to do that, at least it works for me, try `[BindRequired]` for non-nullable types. |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | Solution working with json requests
-----------------------------------
You **cannot validate an already created model instance**, because a non-nullable property has always a value (no matter whether it was assigned from json or is a default value). The **solution is to report the missing value already during deseria... | >
> non-nullable required types.
>
>
>
You do not. It is either required - then there is no sense in it being nullable - or it is not required, then you nullable makes sense, but it makes no sense to require it.
Attributes are always for the whole request. You are in a logical problem because you try to use them ... |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | Everything from the request is just a string. The modelbinder matches up keys in the request body with property names, and then attempts to coerce them to the appropriate type. If the property is not posted or is posted with an empty string, that will obviously fail when trying to convert to an int. As a result, you en... | There was the way to do that, at least it works for me, try `[BindRequired]` for non-nullable types. |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | Solution working with json requests
-----------------------------------
You **cannot validate an already created model instance**, because a non-nullable property has always a value (no matter whether it was assigned from json or is a default value). The **solution is to report the missing value already during deseria... | Everything from the request is just a string. The modelbinder matches up keys in the request body with property names, and then attempts to coerce them to the appropriate type. If the property is not posted or is posted with an empty string, that will obviously fail when trying to convert to an int. As a result, you en... |
50,910,136 | I am new to python and I currently have one text file that I sliced into two columns. I am looking for unique one-to-one relationships in the text file to determine new home buyers:
**Main File**
1234 Address , Billy Joel
Joe Martin, 45 Other Address
63 OtherOther Address, Joe Martin
Billy Joel, 1234 Address
***... | 2018/06/18 | [
"https://Stackoverflow.com/questions/50910136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9574850/"
] | Solution working with json requests
-----------------------------------
You **cannot validate an already created model instance**, because a non-nullable property has always a value (no matter whether it was assigned from json or is a default value). The **solution is to report the missing value already during deseria... | There was the way to do that, at least it works for me, try `[BindRequired]` for non-nullable types. |
1,250,779 | I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?
The problem I have... | 2009/08/09 | [
"https://Stackoverflow.com/questions/1250779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64313/"
] | Class attributes are often used to allow overriding defaults in subclasses. For example, BaseHTTPRequestHandler has class constants sys\_version and server\_version, the latter defaulting to `"BaseHTTP/" + __version__`. SimpleHTTPRequestHandler overrides server\_version to `"SimpleHTTP/" + __version__`. | Encapsulation is a good principle: when an attribute is inside the class it pertains to instead of being in the global scope, this gives additional information to people reading the code.
In your situations 1-4, I would thus avoid globals as much as I can, and prefer using class attributes, which allow one to benefit ... |
1,250,779 | I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?
The problem I have... | 2009/08/09 | [
"https://Stackoverflow.com/questions/1250779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64313/"
] | #4:
I *never* use class attributes to initialize default instance attributes (the ones you normally put in `__init__`). For example:
```
class Obj(object):
def __init__(self):
self.users = 0
```
and never:
```
class Obj(object):
users = 0
```
Why? Because it's inconsistent: it doesn't do what you... | Class attributes are often used to allow overriding defaults in subclasses. For example, BaseHTTPRequestHandler has class constants sys\_version and server\_version, the latter defaulting to `"BaseHTTP/" + __version__`. SimpleHTTPRequestHandler overrides server\_version to `"SimpleHTTP/" + __version__`. |
1,250,779 | I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?
The problem I have... | 2009/08/09 | [
"https://Stackoverflow.com/questions/1250779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64313/"
] | #4:
I *never* use class attributes to initialize default instance attributes (the ones you normally put in `__init__`). For example:
```
class Obj(object):
def __init__(self):
self.users = 0
```
and never:
```
class Obj(object):
users = 0
```
Why? Because it's inconsistent: it doesn't do what you... | Encapsulation is a good principle: when an attribute is inside the class it pertains to instead of being in the global scope, this gives additional information to people reading the code.
In your situations 1-4, I would thus avoid globals as much as I can, and prefer using class attributes, which allow one to benefit ... |
1,250,779 | I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?
The problem I have... | 2009/08/09 | [
"https://Stackoverflow.com/questions/1250779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64313/"
] | >
> what is a good use case for class attributes
>
>
>
**Case 0.** Class methods are just class attributes. This is not just a technical similarity - you can access and modify class methods at runtime by assigning callables to them.
**Case 1.** A module can easily define several classes. It's reasonable to encaps... | Encapsulation is a good principle: when an attribute is inside the class it pertains to instead of being in the global scope, this gives additional information to people reading the code.
In your situations 1-4, I would thus avoid globals as much as I can, and prefer using class attributes, which allow one to benefit ... |
1,250,779 | I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?
The problem I have... | 2009/08/09 | [
"https://Stackoverflow.com/questions/1250779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64313/"
] | #4:
I *never* use class attributes to initialize default instance attributes (the ones you normally put in `__init__`). For example:
```
class Obj(object):
def __init__(self):
self.users = 0
```
and never:
```
class Obj(object):
users = 0
```
Why? Because it's inconsistent: it doesn't do what you... | >
> what is a good use case for class attributes
>
>
>
**Case 0.** Class methods are just class attributes. This is not just a technical similarity - you can access and modify class methods at runtime by assigning callables to them.
**Case 1.** A module can easily define several classes. It's reasonable to encaps... |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | The null filehandle [diamond operator](http://perldoc.perl.org/perlop.html#I%2fO-Operators) `<>` has its place in building command line tools. It acts like `<FH>` to read from a handle, except that it magically selects whichever is found first: command line filenames or STDIN. Taken from perlop:
```
while (<>) {
... ... | @Schwern mentioned turning warnings into errors by localizing `$SIG{__WARN__}`. You can do also do this (lexically) with `use warnings FATAL => "all";`. See `perldoc lexwarn`.
On that note, since Perl 5.12, you've been able to say `perldoc foo` instead of the full `perldoc perlfoo`. Finally! :) |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | The operators ++ and unary - don't only work on numbers, but also on strings.
```
my $_ = "a"
print -$_
```
prints *-a*
```
print ++$_
```
prints *b*
```
$_ = 'z'
print ++$_
```
prints *aa* | A bit obscure is the tilde-tilde "operator" which forces scalar context.
```
print ~~ localtime;
```
is the same as
```
print scalar localtime;
```
and different from
```
print localtime;
``` |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | It's simple to quote almost any kind of strange string in Perl.
```
my $url = q{http://my.url.com/any/arbitrary/path/in/the/url.html};
```
In fact, the various quoting mechanisms in Perl are quite interesting. The Perl regex-like quoting mechanisms allow you to quote anything, specifying the delimiters. You can use ... | You can expand function calls in a string, for example;
```
print my $foo = "foo @{[scalar(localtime)]} bar";
```
>
> foo Wed May 26 15:50:30 2010 bar
>
>
> |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | Binary "x" is the [repetition operator](http://perldoc.perl.org/perlop.html#Multiplicative-Operators):
```
print '-' x 80; # print row of dashes
```
It also works with lists:
```
print for (1, 4, 9) x 3; # print 149149149
``` | The feature I like the best is statement modifiers.
Don't know how many times I've wanted to do:
```
say 'This will output' if 1;
say 'This will not output' unless 1;
say 'Will say this 3 times. The first Time: '.$_ for 1..3;
```
in other languages.
etc...
The 'etc' reminded me of another 5.12 feature, the Yada Ya... |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | Two things that work well together: IO handles on in-core strings, and using function prototypes to enable you to write your own functions with grep/map-like syntax.
```
sub with_output_to_string(&) { # allows compiler to accept "yoursub {}" syntax.
my $function = shift;
my $string = '';
my $handle ... | Next time you're at a geek party pull out this one-liner in a bash shell and the women will swarm you and your friends will worship you:
find . -name "\*.txt"|xargs perl -pi -e 's/1:(\S+)/uc($1)/ge'
Process all \*.txt files and do an in-place find and replace using perl's regex. This one converts text after a '1:' to... |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | Let's start easy with the [Spaceship Operator](http://en.wikipedia.org/wiki/Spaceship_operator).
```
$a = 5 <=> 7; # $a is set to -1
$a = 7 <=> 5; # $a is set to 1
$a = 6 <=> 6; # $a is set to 0
``` | How about the ability to use
```
my @symbols = map { +{ 'key' => $_ } } @things;
```
to generate an array of hashrefs from an array -- the + in front of the hashref disambiguates the block so the interpreter knows that it's a hashref and not a code block. Awesome.
(Thanks to Dave Doyle for explaining this to me at t... |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | It's simple to quote almost any kind of strange string in Perl.
```
my $url = q{http://my.url.com/any/arbitrary/path/in/the/url.html};
```
In fact, the various quoting mechanisms in Perl are quite interesting. The Perl regex-like quoting mechanisms allow you to quote anything, specifying the delimiters. You can use ... | tie, the variable tying interface. |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | [Autovivification](http://en.wikipedia.org/wiki/Autovivification). AFAIK **no other language has it**. | ```
rename("$_.part", $_) for "data.txt";
```
renames data.txt.part to data.txt without having to repeat myself. |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | My favorite semi-hidden feature of Perl is the `eof` function. Here's an example pretty much directly from `perldoc -f eof` that shows how you can use it to reset the file name and `$.` (the current line number) easily across multiple files loaded up at the command line:
```
while (<>) {
print "$ARGV:$.\t$_";
}
co... | Showing progress in the script by printing on the same line:
```
$| = 1; # flush the buffer on the next output
for $i(1..100) {
print "Progress $i %\r"
}
``` |
161,872 | What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
* Try to limit answers to the Perl core and not CPAN
* Please give an example and a short description
---
Hidden Features also found in other languages' Hidden Features:
-------... | 2008/10/02 | [
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] | There are many non-obvious features in Perl.
For example, did you know that there can be a space after a sigil?
```
$ perl -wle 'my $x = 3; print $ x'
3
```
Or that you can give subs numeric names if you use symbolic references?
```
$ perl -lwe '*4 = sub { print "yes" }; 4->()'
yes
```
There's also the "bool"... | I personally love the /e modifier to the s/// operation:
```
while(<>) {
s/(\w{0,4})/reverse($1);/e; # reverses all words between 0 and 4 letters
print;
}
```
Input:
```
This is a test of regular expressions
^D
```
Output (I think):
```
sihT si a tset fo regular expressions
``` |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | I found a way to do this. We used GatsbyJS for a project and it relies on a
.env.production file for the env variables. I tried to pass them as
`env:` to the github action, but that didn't work and they were ignored.
Here is what I did. I base 64 encoded the .env.production file:
```
base64 -i .env.production
```
A... | Here is how to solve your actual problem of securely logging into an SSH server using a secret stored in GitHub Actions, named `GITHUB_ACTIONS_DEPLOY`.
Let's call this "beep", because it will cause an audible bell on the server you login to. Maybe you use this literally ping a server in your house when somebody pushes... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | Here is how to solve your actual problem of securely logging into an SSH server using a secret stored in GitHub Actions, named `GITHUB_ACTIONS_DEPLOY`.
Let's call this "beep", because it will cause an audible bell on the server you login to. Maybe you use this literally ping a server in your house when somebody pushes... | The good solution is to use gpg for encrypting the key, adding it to a repo and decrypting it on the server using passphrase. The passprase should be stored as github project secret of course.
More info how I did it here: <https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-usi... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | I used sed in a GHA to replace a TOKEN in a file like this :
```
run: |-
sed -i "s/TOKEN/${{secrets.MY_SECRET}}/g" "thefile"
```
The file looks like this:
```
credentials "app.terraform.io" {
token = "TOKEN"
}
``` | Here is how to solve your actual problem of securely logging into an SSH server using a secret stored in GitHub Actions, named `GITHUB_ACTIONS_DEPLOY`.
Let's call this "beep", because it will cause an audible bell on the server you login to. Maybe you use this literally ping a server in your house when somebody pushes... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | GitHub Actions should be able to write a secret to a file this way. The reason you see the stars is that the log is filtered, so if a secret would be logged, it's replaced in the log with three asterisks instead. This is a security measure against an accidental disclosure of secrets, since logs are often publicly avail... | I used sed in a GHA to replace a TOKEN in a file like this :
```
run: |-
sed -i "s/TOKEN/${{secrets.MY_SECRET}}/g" "thefile"
```
The file looks like this:
```
credentials "app.terraform.io" {
token = "TOKEN"
}
``` |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | GitHub Actions should be able to write a secret to a file this way. The reason you see the stars is that the log is filtered, so if a secret would be logged, it's replaced in the log with three asterisks instead. This is a security measure against an accidental disclosure of secrets, since logs are often publicly avail... | encode it and decode back
```
- run: 'echo "$SSH_KEY" | base64'
shell: bash
env:
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
```
and decode it back `echo "<encoded string>" | base64 -d` |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | I found a way to do this. We used GatsbyJS for a project and it relies on a
.env.production file for the env variables. I tried to pass them as
`env:` to the github action, but that didn't work and they were ignored.
Here is what I did. I base 64 encoded the .env.production file:
```
base64 -i .env.production
```
A... | I used sed in a GHA to replace a TOKEN in a file like this :
```
run: |-
sed -i "s/TOKEN/${{secrets.MY_SECRET}}/g" "thefile"
```
The file looks like this:
```
credentials "app.terraform.io" {
token = "TOKEN"
}
``` |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | encode it and decode back
```
- run: 'echo "$SSH_KEY" | base64'
shell: bash
env:
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
```
and decode it back `echo "<encoded string>" | base64 -d` | The good solution is to use gpg for encrypting the key, adding it to a repo and decrypting it on the server using passphrase. The passprase should be stored as github project secret of course.
More info how I did it here: <https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-usi... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | GitHub Actions should be able to write a secret to a file this way. The reason you see the stars is that the log is filtered, so if a secret would be logged, it's replaced in the log with three asterisks instead. This is a security measure against an accidental disclosure of secrets, since logs are often publicly avail... | The good solution is to use gpg for encrypting the key, adding it to a repo and decrypting it on the server using passphrase. The passprase should be stored as github project secret of course.
More info how I did it here: <https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-usi... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | GitHub Actions should be able to write a secret to a file this way. The reason you see the stars is that the log is filtered, so if a secret would be logged, it's replaced in the log with three asterisks instead. This is a security measure against an accidental disclosure of secrets, since logs are often publicly avail... | I found a way to do this. We used GatsbyJS for a project and it relies on a
.env.production file for the env variables. I tried to pass them as
`env:` to the github action, but that didn't work and they were ignored.
Here is what I did. I base 64 encoded the .env.production file:
```
base64 -i .env.production
```
A... |
59,481,941 | I am new to python and I am trying to disable TAB2 from widget notebook tkinter, through the support\_test.py file I have the command of the disable\_tab2 button, which should have the command to disable the option, but I get the error below:
```
Exception in Tkinter callback Traceback (most recent call last): File
... | 2019/12/25 | [
"https://Stackoverflow.com/questions/59481941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596546/"
] | I found a way to do this. We used GatsbyJS for a project and it relies on a
.env.production file for the env variables. I tried to pass them as
`env:` to the github action, but that didn't work and they were ignored.
Here is what I did. I base 64 encoded the .env.production file:
```
base64 -i .env.production
```
A... | encode it and decode back
```
- run: 'echo "$SSH_KEY" | base64'
shell: bash
env:
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
```
and decode it back `echo "<encoded string>" | base64 -d` |
44,150,069 | I've implemented the "xor problem" with cntk (python).
Currently it solves the problem only occasionally. How could I implement a more reliable network?
I guess the problem gets solved whenever the starting random weights are near optimal. I have tried `binary_cross_entropy` as the loss function but it didn't improve... | 2017/05/24 | [
"https://Stackoverflow.com/questions/44150069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635993/"
] | One option is to apply the [`TO_JSON_STRING` function](https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#to_json_string) to the results of your query. For example,
```
#standardSQL
SELECT TO_JSON_STRING(t)
FROM (
SELECT x, y
FROM YourTable
WHERE z = 10
) AS t;
```
If you wan... | I'm using a service account to access the BigQuery REST API to get the response in JSON format.
In order to use a service account, you will have to go to credentials (<https://console.cloud.google.com/apis/credentials>) and choose a project.
[](ht... |
36,054,382 | I have succeeded ran the code in C++,with the code below:
```
int countOnes(int num) {
int count =0;
while (num) {
count ++;
num = num & (num-1);
}
return count;
}
```
but it didn't work in Python version:
```
def countOnes(num):
count = 0
while(num):
count += 1
... | 2016/03/17 | [
"https://Stackoverflow.com/questions/36054382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6075620/"
] | The reason this function works differently in the two languages is that they have different fundamental number types. In C++, `int` is indeed often a 32 bit integer in two's complement representation, though the language standard allows other representations. In Python, however, the standard number type has arbitrary p... | Python doesn't have "32-bit integers". Its integers are arbitrary (read:infinite) length. This means that -1 is *not* 0xffffffff, but is instead an infinitely long binary sequence of 1s. |
36,054,382 | I have succeeded ran the code in C++,with the code below:
```
int countOnes(int num) {
int count =0;
while (num) {
count ++;
num = num & (num-1);
}
return count;
}
```
but it didn't work in Python version:
```
def countOnes(num):
count = 0
while(num):
count += 1
... | 2016/03/17 | [
"https://Stackoverflow.com/questions/36054382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6075620/"
] | The reason this function works differently in the two languages is that they have different fundamental number types. In C++, `int` is indeed often a 32 bit integer in two's complement representation, though the language standard allows other representations. In Python, however, the standard number type has arbitrary p... | You can create the 32bit representation limit
```
def countOnes(num):
num = num % (1 << 32)
count = 0
while(num):
count += 1
num = num&(num-1)
return count
``` |
68,116,542 | I am trying to recode an existing python script to Java.
It includes this following line:
```
r = requests.get('https://{}/redfish/v1/{}'.format(ip, query), auth=('ADMIN', 'ADMIN'), verify=False)
```
I don't have a lot of experience in Python and didn't write the script myself. So far I've only been able to figure o... | 2021/06/24 | [
"https://Stackoverflow.com/questions/68116542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8298497/"
] | First, read [this tutorial on the java HTTP client](https://openjdk.java.net/groups/net/httpclient/intro.html). (Note that it requires jdk11 or up).
From there it should be fairly simply; that `.format()` thing is just replacing the `{}` with the provided ip and query parts. The auth part is more interesting. The veri... | At first, you can use `String.format` for the formatting:
```java
String url=String.format("https://%s/redfish/v1/%s",ip,query);
```
You could also use `MessageFormat` if you want to.
For connecting, you can create a `URL`-object and creating a `URLConnection` (in your case `HttpsURLConnection`) and opening an `Inp... |
44,962,225 | I imported a table with the years that each coach served as the football coach. Some of the years listed look like this: "1903–1910, 1917, 1919"
I am aiming for [1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1917, 1919]
In my original DataFrame this list is an object.
I have tried:
`x = "1903–1910, 1917, 1919"`
... | 2017/07/07 | [
"https://Stackoverflow.com/questions/44962225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8268427/"
] | The hyphen you see is not really a hyphen. It could be some other character, like an unicode en-dash which would look very similar.
Try to copy-paste the actual character into the split string.
Looking at the text you posted, here's the difference:
```
➜ ~ echo '1903–1910' | xxd
00000000: 3139 3033 e280 9331 3931 3... | Your character is not an hyfen, it's a dash:
```
>>> "–" == "-"
False
>>> x = "1903–1910, 1917, 1919"
>>> x.split("–")
['1903', '1910, 1917, 1919']
``` |
44,962,225 | I imported a table with the years that each coach served as the football coach. Some of the years listed look like this: "1903–1910, 1917, 1919"
I am aiming for [1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1917, 1919]
In my original DataFrame this list is an object.
I have tried:
`x = "1903–1910, 1917, 1919"`
... | 2017/07/07 | [
"https://Stackoverflow.com/questions/44962225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8268427/"
] | The hyphen you see is not really a hyphen. It could be some other character, like an unicode en-dash which would look very similar.
Try to copy-paste the actual character into the split string.
Looking at the text you posted, here's the difference:
```
➜ ~ echo '1903–1910' | xxd
00000000: 3139 3033 e280 9331 3931 3... | This works but not optimal
```
# -*- coding: utf-8 -*-
x = "1903–1910, 1917, 1919"
endash = '–'
years = x.split(', ')
new_list = []
for year in years:
if endash in year:
start, finish = year.split(endash)
new_list.extend(range(int(start), int(finish)+1))
else:
new_list.append(int(year))... |
44,962,225 | I imported a table with the years that each coach served as the football coach. Some of the years listed look like this: "1903–1910, 1917, 1919"
I am aiming for [1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1917, 1919]
In my original DataFrame this list is an object.
I have tried:
`x = "1903–1910, 1917, 1919"`
... | 2017/07/07 | [
"https://Stackoverflow.com/questions/44962225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8268427/"
] | Your character is not an hyfen, it's a dash:
```
>>> "–" == "-"
False
>>> x = "1903–1910, 1917, 1919"
>>> x.split("–")
['1903', '1910, 1917, 1919']
``` | This works but not optimal
```
# -*- coding: utf-8 -*-
x = "1903–1910, 1917, 1919"
endash = '–'
years = x.split(', ')
new_list = []
for year in years:
if endash in year:
start, finish = year.split(endash)
new_list.extend(range(int(start), int(finish)+1))
else:
new_list.append(int(year))... |
34,902,486 | There are many posts about 'latin-1' codec , however those answers can't solve my problem, maybe it's my question, I am just a rookie to learn Python, somewhat. When I used `cwd(dirname)` to change directory of FTP site, the unicodeerror occurred. Note that `dirname` included Chinese characters, obviously, those charac... | 2016/01/20 | [
"https://Stackoverflow.com/questions/34902486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5816236/"
] | No need to edit ftplib source code. Just set `ftp.encoding` property in your code:
```
ftp.encoding = "UTF-8"
ftp.cwd(dirname)
```
A similar question, about FTP output, rather then input:
[List files with UTF-8 characters in the name in Python ftplib](https://stackoverflow.com/q/53091871/850848) | I solved this problem by editing `ftplib.py`. On my machine, it is under `C:\Users\<user>\AppData\Local\Programs\Python\Python36\Lib`.
You just need to replace `encoding = "latin-1"` with `encoding = "utf-8"` |
30,433,983 | This is what I have in my `Procfile`:
```
web: gunicorn --pythonpath meraki meraki.wsgi
```
and when I do `foreman start`, I get this error:
```
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
```
the reason, as far as I can see in the traceback, is:
```
ImportError: No module named wsgi
```... | 2015/05/25 | [
"https://Stackoverflow.com/questions/30433983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4137194/"
] | You've confused yourself by following an unnecessarily complicated structure. You don't need that outer meraki directory, and your Procfile and requirements.txt should be in the same directory as manage.py. Then you can remove the pythonpath parameter and all should be well. | As Roseman said, it is unnecessarily complicated structure.If you want it to do so,Try
```
web: gunicorn --pythonpath /path/to/meraki meraki.wsgi
```
That is `/absolutepath/to/secondmeroki(out of 3)` which contains `apps`. |
71,266,145 | I wrote a python function called `plot_ts_ex` that takes two arguments `ts_file` and `ex_file` (and the file name for this function is `pism_plot_routine`). I want to run this function from a bash script from terminal.
When I don't use variables in the bash script in pass the function arguments (in this case `ts_file =... | 2022/02/25 | [
"https://Stackoverflow.com/questions/71266145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18308686/"
] | When you use single quotes the variables aren’t going to be expanded, you should use double quotes instead:
```
#!/bin/sh
ts_name="ts_g10km_10ka_hy.nc"
ex_name="ex_g10km_10ka_hy.nc"
python -c "import pism_plot_routine; pism_plot_routine.plot_ts_ex('$ts_name', '$ex_name')"
```
---
You can also use sys.argv, argum... | You are giving the value `$ts_name` to python as string, bash does not do anything with it. You need to close the `'`, so that it becomes a string in bash, and then open it again for it to become a string in python.
The result will be something like this:
```
#!/bin/sh
ts_name="ts_g10km_10ka_hy.nc"
ex_name="ex_g10k... |
36,915,188 | I have a large csv file with 25 columns, that I want to read as a pandas dataframe. I am using `pandas.read_csv()`.
The problem is that some rows have extra columns, something like that:
```
col1 col2 stringColumn ... col25
1 12 1 str1 3
...
33657 2 3 ... | 2016/04/28 | [
"https://Stackoverflow.com/questions/36915188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5841927/"
] | If you want Coded UI to launch your forms application on start of a test, use the method
```
ApplicationUnderTest.Launch("FORMS_APP_PATH");
```
You can check the precise method details on MSDN.
Update:
To handle changing paths I created a new Forms solution and called it LabPlus.
I then added a CodedUI test proje... | My fix:
1. add reference from test project to WinForm project
2. decorate test class with `[DeploymentItem('your-app.exe')]` attribute
3. add `ApplicationUnderTest.Launch("your-app.exe");` to the test method |
37,009,587 | I'm making a python app to automate some tasks in AutoCAD (drawing specific shapes in specific layers and checking the location of some circles).
For the first part, drawing things, it was easy to use the AutoCAD Interop library, as you could easily put objects in the active document without doing anything on AutoCAD,... | 2016/05/03 | [
"https://Stackoverflow.com/questions/37009587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6266184/"
] | You can iterate through list of available resources using method of Assembly class:
```
var names = someInstance.GetType()
.GetTypeInfo()
.Assembly
.GetManifestResourceNames();
```
And then load resource by full name from the list above:
```
var stream = someAssembly.GetManife... | You need to get Assembly which you embedded resource then call GetManifestResourceStream.
I have sample with namespace YourProjectNameSpace have MyFolder contain MyFile.json:
```
public class EndpointBuilder
{
private static String _filePath = "YourProjectNameSpace.MyFolder.MyFile.json";
public async Task<E... |
718,040 | <http://pypi.python.org/pypi/simplejson>
I am just diving into the Python world and want to make a simple twitter application which requires the installation of simplejson but not sure how I can set it up and get it working..
I am on a Windows System | 2009/04/04 | [
"https://Stackoverflow.com/questions/718040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32372/"
] | I would recommend [EasyInstall](http://pypi.python.org/pypi/setuptools#windows), a package management application for Python.
Once you've installed EasyInstall, you should be able to go to a command window and type:
```
easy_install simplejson
```
This may require putting easy\_install.exe on your PATH first, I don... | If you have Python 2.6 installed then you already have simplejson - just import `json`; it's the same thing. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.