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
6,367,014
In my `settings.py`, I have the following: ``` EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Host for sending e-mail. EMAIL_HOST = 'localhost' # Port for sending e-mail. EMAIL_PORT = 1025 # Optional SMTP authentication information for EMAIL_HOST. EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAI...
2011/06/16
[ "https://Stackoverflow.com/questions/6367014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/749477/" ]
I use Gmail as my SMTP server for Django. Much easier than dealing with postfix or whatever other server. I'm not in the business of managing email servers. In settings.py: ``` EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = '[email protected]' EMAIL_HOST_PASSWORD = 'password' ``` *...
For **SendGrid - Django** Specifically: [SendGrid Django Docs here](https://sendgrid.com/docs/Integrate/Frameworks/django.html) Set these variables in **settings.py** ``` EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = 'sendgrid_username' EMAIL_HOST_PASSWORD = 'sendgrid_password' EMAIL_PORT = 587 EMAIL_USE_TLS =...
6,367,014
In my `settings.py`, I have the following: ``` EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Host for sending e-mail. EMAIL_HOST = 'localhost' # Port for sending e-mail. EMAIL_PORT = 1025 # Optional SMTP authentication information for EMAIL_HOST. EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAI...
2011/06/16
[ "https://Stackoverflow.com/questions/6367014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/749477/" ]
I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code - ``` from email import Encoders from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart def sendmail(to, subject, text, att...
For **SendGrid - Django** Specifically: [SendGrid Django Docs here](https://sendgrid.com/docs/Integrate/Frameworks/django.html) Set these variables in **settings.py** ``` EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = 'sendgrid_username' EMAIL_HOST_PASSWORD = 'sendgrid_password' EMAIL_PORT = 587 EMAIL_USE_TLS =...
6,367,014
In my `settings.py`, I have the following: ``` EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Host for sending e-mail. EMAIL_HOST = 'localhost' # Port for sending e-mail. EMAIL_PORT = 1025 # Optional SMTP authentication information for EMAIL_HOST. EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAI...
2011/06/16
[ "https://Stackoverflow.com/questions/6367014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/749477/" ]
For Django version 1.7, if above solutions dont work then try the following in **settings.py** add ``` #For email EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = '[email protected]' #Must generate specific password for your app in [...
I had actually done this from Django a while back. Open up a legitimate GMail account & enter the credentials here. Here's my code - ``` from email import Encoders from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart def sendmail(to, subject, text, att...
6,367,014
In my `settings.py`, I have the following: ``` EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # Host for sending e-mail. EMAIL_HOST = 'localhost' # Port for sending e-mail. EMAIL_PORT = 1025 # Optional SMTP authentication information for EMAIL_HOST. EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' EMAI...
2011/06/16
[ "https://Stackoverflow.com/questions/6367014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/749477/" ]
You need to use **smtp as backend** in settings.py ``` EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' ``` If you use backend as console, you will receive output in console ``` EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' ``` And also below settings in addition ``` EMAIL_USE_TLS...
I found using SendGrid to be the easiest way to set up sending email with Django. Here's how it works: 1. [Create a SendGrid account](https://app.sendgrid.com/signup) (and verify your email) 2. Add the following to your `settings.py`: `EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = '<your sendgrid username>' EMAIL...
58,414,393
Say i have a dataframe as shown below ``` Stock open high low close Avg 0 SBIN 255.85 256.00 255.80 255.90 Nan 1 HDFC 1222.25 1222.45 1220.45 1220.45 Nan 2 SBIN 255.95 255.95 255.85 255.85 Nan 3 HDFC 1222.00 1222.50 1221.70 1221.95 ...
2019/10/16
[ "https://Stackoverflow.com/questions/58414393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10559306/" ]
You can use `groupby` and `rolling` ``` df['Avg'] = df.groupby('Stock', as_index=False)['close'].rolling(3).mean().reset_index(0,drop=True) df Out[1]: Stock open high low close Avg 0 SBIN 255.85 256.00 255.80 255.90 NaN 1 HDFC 1222.25 1222.45 1220.45 1220.45 ...
As I understood from your df you are trying to calculate something like moving average metric. To do this you can simply use for iteration: ``` for i in range(0, df.shape[0] - 2): df.loc[df.index[i + 2], 'AVG'] = np.round(((df.iloc[i, 1] + df.iloc[i + 1, 1] + df.iloc[i + 2, 1]) / 3), 1) ``` Where in pd.loc cla...
14,568,370
I have the following code ``` # logging from twisted.python import log import sys # MIME Multipart handling import email import email.mime.application import uuid # IMAP Connection from twisted.mail import imap4 from twisted.internet import protocol #SMTP Sending import os.path from OpenSSL.SSL import SSLv3_METHOD...
2013/01/28
[ "https://Stackoverflow.com/questions/14568370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/410368/" ]
``` from twisted.internet.endpoints import TCP4ClientEndpoint d = TCP4ClientEndpoint(reactor, host, int(port)).connect(factory) ``` and ``` d.addCallback(lambda r: factory.deferred) ``` instead of ``` d = factory.deferred ``` in `connectToIMAPServer` should do it - your `factory.deferred` will be returned o...
I eventually edited the code around and just managed the deferred's callback or errback internally update code ``` # logging from twisted.python import log import sys # MIME Multipart handling import email import email.mime.application import uuid # IMAP Connection from twisted.mail import imap4 from twisted.intern...
35,266,464
I was trying to build this example: <https://www.linuxvoice.com/build-a-web-browser-with-20-lines-of-python/> I'll just repost it here for completeness: ``` from PyQt5.QtCore import QUrl from PyQt5.QtWidgets import QApplication from PyQt5.QtWebKitWidgets import QWebView import sys app = QApplication(sys.argv) ...
2016/02/08
[ "https://Stackoverflow.com/questions/35266464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5016028/" ]
SO here's the actual answer. I had the same issue and discovered it very fast. `view.setUrl(QUrl(“http://linuxvoice.com”))` Notice that their code uses quotes, look at how the quotes are compared to normal quotes. Normal: "" Theirs: “” Basically, they're using weird ASCII quotes that Python can't handle. Really snea...
You've got a stray byte somewhere in your code. It's popped up on StackOverflow previously and there's a good method for finding it: [Python "SyntaxError: Non-ASCII character '\xe2' in file"](https://stackoverflow.com/questions/21639275/python-syntaxerror-non-ascii-character-xe2-in-file).
43,322,201
I have a Flask application using python3. Sometimes it create daemon process to run script, then I want to kill daemon when timeout (use `signal.SIGINT`). However, some processes which created by `os.system` (for example, `os.system('git clone xxx')`) are still running after daemon was killed. so what should I do? Tha...
2017/04/10
[ "https://Stackoverflow.com/questions/43322201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7844505/" ]
In order to be able to kill a process you need its process id (usually referred to as a pid). `os.system` doesn't give you that, simply returning the value of the subprocess's return code. The newer `subprocess` module gives you much more control, at the expense of somewhat more complexity. In particular it allows you...
The following command on the command line will show you all the running instances of python. ``` $ ps aux | grep -i python username 6488 0.0 0.0 2434840 712 s003 R+ 1:41PM 0:00.00 python ``` The first number, `6488`, is the PID, process identifier. Look through the output of the command on your machine...
40,821,604
I want to write to an element in a nested list named `foo`, but the nesting depth and indexes is only known at runtime, in a (non-nested!) list variable named `indexes`. Examples: If `indexes` is `[4]`, I want `foo[4]`. If `indexes` is `[4,7]`, I want `foo[4][7]`. If `indexes` is `[4,7,3]`, I want `foo[4][7][3]`. ...
2016/11/26
[ "https://Stackoverflow.com/questions/40821604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/174365/" ]
You can use the [`reduce()` function](https://docs.python.org/2/library/functions.html#reduce): ``` from functools import reduce # Python 3 forward compatibility import operator def access(lst, indexes): return reduce(operator.getitem, indexes, lst) ``` You *could* use `list.__getitem__` instead of [`operator....
You can set `item` to `foo`, then proceeds with the indexes list to access deeper nested elements: ``` def access (foo, indexes): item = foo for index in indexes: item = item[index] return item ```
22,864,305
Im a very new Python user (2.7) and have been working my way through the Learn Python The Hard Way course and up to chap 37 and decided to do read through some other learning materials and go over the basics again and do exercises there. I have been reading through this: <http://anh.cs.luc.edu/python/hands-on/3.1/hand...
2014/04/04
[ "https://Stackoverflow.com/questions/22864305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3286810/" ]
[`raw_input()`](https://docs.python.org/2.7/library/functions.html#raw_input) returns a string: ``` >>> credits = raw_input("> ") > 150 >>> type(credits) <type 'str'> ``` You need to cast it to `int`: ``` credits = int(raw_input("> ")) ```
In your code, at the if statement you are comparing a `str` type with a `int` type. so it is not working as you axpected. Cast the `credit` as `int` ``` print "How many credits do you currently have: " credits = raw_input("> ") credits = int(credits) if credits >= 120: print "You have graduated!" else: print "So...
22,864,305
Im a very new Python user (2.7) and have been working my way through the Learn Python The Hard Way course and up to chap 37 and decided to do read through some other learning materials and go over the basics again and do exercises there. I have been reading through this: <http://anh.cs.luc.edu/python/hands-on/3.1/hand...
2014/04/04
[ "https://Stackoverflow.com/questions/22864305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3286810/" ]
[`raw_input()`](https://docs.python.org/2.7/library/functions.html#raw_input) returns a string: ``` >>> credits = raw_input("> ") > 150 >>> type(credits) <type 'str'> ``` You need to cast it to `int`: ``` credits = int(raw_input("> ")) ```
I am refering to the same material by Dr. Andrew Harrington and I am doing the same program, my program may look pretty much amatuerish so I would highly appreciate if someone can kindly refine it ``` def graduateEligibility(credits): if credits >= 120: print("Congratulations on successfully completing the...
22,864,305
Im a very new Python user (2.7) and have been working my way through the Learn Python The Hard Way course and up to chap 37 and decided to do read through some other learning materials and go over the basics again and do exercises there. I have been reading through this: <http://anh.cs.luc.edu/python/hands-on/3.1/hand...
2014/04/04
[ "https://Stackoverflow.com/questions/22864305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3286810/" ]
[`raw_input()`](https://docs.python.org/2.7/library/functions.html#raw_input) returns a string: ``` >>> credits = raw_input("> ") > 150 >>> type(credits) <type 'str'> ``` You need to cast it to `int`: ``` credits = int(raw_input("> ")) ```
You need to accept integer input for that and also need to handle non integer inputs. ``` print "How many credits do you currently have: " try: credits = int(raw_input("> ")) if credits >= 120: print "You have graduated!" else: print "Sorry not enough credits" except ValueError: print "...
11,958,728
python 2.6.8 ``` s= ''' foo bar baz ''' >>>re.findall(r'^\S*',s,re.MULTILINE) ['', 'foo', 'bar', 'baz', ''] >>>ptrn = re.compile(r'^\S*',re.MULTILINE) >>>ptrn.findall(s) ['', 'foo', 'bar', 'baz', ''] >>>ptrn.findall(s,re.MULTILINE) ['baz', ''] ``` Why is there a difference between using MULTILINE flag in findall?
2012/08/14
[ "https://Stackoverflow.com/questions/11958728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1293804/" ]
When calling the `findall()` method on a regex object, the second parameter is not the `flags` argument (because that has already been used when compiling the regex) but the `pos` argument, telling the regex engine at which point in the string to start matching. `re.MULTILINE` is just an integer (that happens to be `8...
Because the `findall` method of the compiled object `ptrn` doesn't take the MULTILINE parameter. It takes a `position` argument. See here: <http://docs.python.org/library/re.html#re.RegexObject.findall> The MULTILINE specifier is only used when you call `re.compile()` The resulting `ptrn` object already 'knows' that ...
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
''missing authentication token' means you need to authenticate before you can talk to this Elasticsearch instance. To index documents, the user must have write access. You can include a username and password in a URL like this: <http://user:password@hostname:port> For example, in a shell: ``` export ES_ENDPOINT="http...
Also, if you do it from Postman tool, for example: Go to Authorization tab, Basic Auth, write here username and password which you was received by clicking elasticsearch-setup-passwords.bat [![enter image description here](https://i.stack.imgur.com/pUSlW.png)](https://i.stack.imgur.com/pUSlW.png)
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
''missing authentication token' means you need to authenticate before you can talk to this Elasticsearch instance. To index documents, the user must have write access. You can include a username and password in a URL like this: <http://user:password@hostname:port> For example, in a shell: ``` export ES_ENDPOINT="http...
The HTTP basic auth can be passed to a `http_auth` parameter when creating the ElasticSearch client: ``` client = Elasticsearch( hosts=['localhost:5000'], http_auth=('username', 'password'), ) s = Search(using=client, index='something') ``` This assumes you are using the underlying [`Urllib3HttpConnection`](...
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
''missing authentication token' means you need to authenticate before you can talk to this Elasticsearch instance. To index documents, the user must have write access. You can include a username and password in a URL like this: <http://user:password@hostname:port> For example, in a shell: ``` export ES_ENDPOINT="http...
OS ubuntu /usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http\_urllib3.py http\_auth=None, -> http\_auth=('username', 'password'), reference: <https://rootkey.tistory.com/113>
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
The HTTP basic auth can be passed to a `http_auth` parameter when creating the ElasticSearch client: ``` client = Elasticsearch( hosts=['localhost:5000'], http_auth=('username', 'password'), ) s = Search(using=client, index='something') ``` This assumes you are using the underlying [`Urllib3HttpConnection`](...
Also, if you do it from Postman tool, for example: Go to Authorization tab, Basic Auth, write here username and password which you was received by clicking elasticsearch-setup-passwords.bat [![enter image description here](https://i.stack.imgur.com/pUSlW.png)](https://i.stack.imgur.com/pUSlW.png)
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
Also, if you do it from Postman tool, for example: Go to Authorization tab, Basic Auth, write here username and password which you was received by clicking elasticsearch-setup-passwords.bat [![enter image description here](https://i.stack.imgur.com/pUSlW.png)](https://i.stack.imgur.com/pUSlW.png)
OS ubuntu /usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http\_urllib3.py http\_auth=None, -> http\_auth=('username', 'password'), reference: <https://rootkey.tistory.com/113>
45,110,802
I am working on using an ElasticSearch database to store data I am pulling from online. However, when I try to index the data in the database I receive an error. Here is my code for creating and indexing the data: ``` es = Elasticsearch() es.index(index='weather', doc_type='data', body=doc) ``` However when I run ...
2017/07/14
[ "https://Stackoverflow.com/questions/45110802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6848466/" ]
The HTTP basic auth can be passed to a `http_auth` parameter when creating the ElasticSearch client: ``` client = Elasticsearch( hosts=['localhost:5000'], http_auth=('username', 'password'), ) s = Search(using=client, index='something') ``` This assumes you are using the underlying [`Urllib3HttpConnection`](...
OS ubuntu /usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http\_urllib3.py http\_auth=None, -> http\_auth=('username', 'password'), reference: <https://rootkey.tistory.com/113>
59,777,244
I am a very new programmer and wanted to try out the AIY voice kit that uses Google Assistant API. I have a step-by-step guide that pretty much tells me how to set it up but now when it's up and running the guide tells me to run "assistant\_library\_demo.py" which is to make sure that the google assistant understands y...
2020/01/16
[ "https://Stackoverflow.com/questions/59777244", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12727174/" ]
You have to return the generate value to the Button. ``` <asp:Button OnClientClick="return Generate()" <script> var test = 2; function Generate() { if (test === 1) return true; else return false; } </script> ```
Your problem lies in `OnClientClick="Generate();" OnClick="Button2_Click"`. You're assigning two inline click events here, so they'll both trigger independently. You have to handle the `Button2_Click` function from inside `Generate`. One way you might do this is to call `Button2_Click` in the else condition: ``` ...
40,245,703
I'm using python to hit a foreman API to gather some facts about all the hosts that foreman knows about. Unfortunately, there is not *get-all-hosts-facts* (or something similar) in the v1 foreman API, so I'm having to loop through all the hosts and get the information. Doing so has lead me to an annoying problem. Each ...
2016/10/25
[ "https://Stackoverflow.com/questions/40245703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2872525/" ]
It would be better to assemble all of your data into one dict and then write it all out one time, instead of each time in the loop. ``` d = {} for i in hosts_data: log.info("Gathering host facts for host: {}".format(i['host']['name'])) try: facts = requests.get(foreman_host+api+"hosts/{}/facts".format(...
Instead of writing json inside the loop, insert the data into a `dict` with the correct structure. Then write that dict to json when the loop is finished. This assumes your dataset fit into memory.
40,245,703
I'm using python to hit a foreman API to gather some facts about all the hosts that foreman knows about. Unfortunately, there is not *get-all-hosts-facts* (or something similar) in the v1 foreman API, so I'm having to loop through all the hosts and get the information. Doing so has lead me to an annoying problem. Each ...
2016/10/25
[ "https://Stackoverflow.com/questions/40245703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2872525/" ]
Instead of writing json inside the loop, insert the data into a `dict` with the correct structure. Then write that dict to json when the loop is finished. This assumes your dataset fit into memory.
For safety/consistency, you need to load in the old data, mutate it, then write it back out. Change the current `with` and `write` to: ``` # If file guaranteed to exist, can use r+ and avoid initial seek with open(results_file, 'a+') as f: f.seek(0) combined_facts = json.load(f) combined_facts.update(fact...
40,245,703
I'm using python to hit a foreman API to gather some facts about all the hosts that foreman knows about. Unfortunately, there is not *get-all-hosts-facts* (or something similar) in the v1 foreman API, so I'm having to loop through all the hosts and get the information. Doing so has lead me to an annoying problem. Each ...
2016/10/25
[ "https://Stackoverflow.com/questions/40245703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2872525/" ]
It would be better to assemble all of your data into one dict and then write it all out one time, instead of each time in the loop. ``` d = {} for i in hosts_data: log.info("Gathering host facts for host: {}".format(i['host']['name'])) try: facts = requests.get(foreman_host+api+"hosts/{}/facts".format(...
For safety/consistency, you need to load in the old data, mutate it, then write it back out. Change the current `with` and `write` to: ``` # If file guaranteed to exist, can use r+ and avoid initial seek with open(results_file, 'a+') as f: f.seek(0) combined_facts = json.load(f) combined_facts.update(fact...
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
Same problem with Node, **just waited and tryed again** the command later and that's work for me (in the same shell, no steps between).
I had the same issue when deploying a Java application to an App Engine. Enabling the 'Cloud Build API' under the APIs & Services section in the Google console resolved the issue for me.
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same problem but with flask. I follow this tutorial of google [here](https://codelabs.developers.google.com/codelabs/cloud-run-hello-python3?hl=en&continue=https%3A%2F%2Fcodelabs.developers.google.com%2Feuropython%3Fhl%3Den) and When I ran the comand `gcloud app deploy` I got the same error. My solution was ...
I had the same issue when deploying a Java application to an App Engine. Enabling the 'Cloud Build API' under the APIs & Services section in the Google console resolved the issue for me.
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
Same problem with Node, **just waited and tryed again** the command later and that's work for me (in the same shell, no steps between).
> > Got the same error, I just activated billing account on the current project on gcp and retry deploy. All works for me > --------------------------------------------------------------------------------------------------------------------- > > >
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same issue when deploying a Java application to an App Engine. Enabling the 'Cloud Build API' under the APIs & Services section in the Google console resolved the issue for me.
> > Got the same error, I just activated billing account on the current project on gcp and retry deploy. All works for me > --------------------------------------------------------------------------------------------------------------------- > > >
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same error with different service ID, I deleted the specified service with that ID than it started working for me.
Trivial, but I had success by making sure all settings are configured outside ``` if __name__ == "__main__": ... ```
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same issue when deploying a Java application to an App Engine. Enabling the 'Cloud Build API' under the APIs & Services section in the Google console resolved the issue for me.
I had the same error with different service ID, I deleted the specified service with that ID than it started working for me.
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same problem but with flask. I follow this tutorial of google [here](https://codelabs.developers.google.com/codelabs/cloud-run-hello-python3?hl=en&continue=https%3A%2F%2Fcodelabs.developers.google.com%2Feuropython%3Fhl%3Den) and When I ran the comand `gcloud app deploy` I got the same error. My solution was ...
> > Got the same error, I just activated billing account on the current project on gcp and retry deploy. All works for me > --------------------------------------------------------------------------------------------------------------------- > > >
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
> > Got the same error, I just activated billing account on the current project on gcp and retry deploy. All works for me > --------------------------------------------------------------------------------------------------------------------- > > >
Trivial, but I had success by making sure all settings are configured outside ``` if __name__ == "__main__": ... ```
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same problem but with flask. I follow this tutorial of google [here](https://codelabs.developers.google.com/codelabs/cloud-run-hello-python3?hl=en&continue=https%3A%2F%2Fcodelabs.developers.google.com%2Feuropython%3Fhl%3Den) and When I ran the comand `gcloud app deploy` I got the same error. My solution was ...
Trivial, but I had success by making sure all settings are configured outside ``` if __name__ == "__main__": ... ```
66,528,149
I'm trying to deploy a Django application on Google App Engine. I followed the instructions given [here](https://cloud.google.com/python/django/appengine#macos-64-bit). The only problem is that when I execute the command `gcloud app deploy` I than get the error: > > ERROR: (gcloud.app.deploy) NOT\_FOUND: Unable to re...
2021/03/08
[ "https://Stackoverflow.com/questions/66528149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13922881/" ]
I had the same issue when deploying a Java application to an App Engine. Enabling the 'Cloud Build API' under the APIs & Services section in the Google console resolved the issue for me.
Trivial, but I had success by making sure all settings are configured outside ``` if __name__ == "__main__": ... ```
4,042,995
> > **Possible Duplicate:** > > [What is the equivalent of the C# “using” block in IronPython?](https://stackoverflow.com/questions/1757296/what-is-the-equivalent-of-the-c-using-block-in-ironpython) > > > I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pyt...
2010/10/28
[ "https://Stackoverflow.com/questions/4042995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
Python 2.6 introduced the `with` statement, which provides for automatic clean up of objects when they leave the `with` statement. I don't know if the IronPython libraries support it, but it would be a natural fit. Dup question with authoritative answer: [What is the equivalent of the C# "using" block in IronPython?](...
If I understand correctly, it looks like the equivalent is the [`with`](http://docs.python.org/reference/compound_stmts.html#with) statement. If your classes define context managers, they will be called automatically after the with block.
4,042,995
> > **Possible Duplicate:** > > [What is the equivalent of the C# “using” block in IronPython?](https://stackoverflow.com/questions/1757296/what-is-the-equivalent-of-the-c-using-block-in-ironpython) > > > I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pyt...
2010/10/28
[ "https://Stackoverflow.com/questions/4042995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
Python 2.6 introduced the `with` statement, which provides for automatic clean up of objects when they leave the `with` statement. I don't know if the IronPython libraries support it, but it would be a natural fit. Dup question with authoritative answer: [What is the equivalent of the C# "using" block in IronPython?](...
I think you are looking for the [with statement](http://docs.python.org/reference/compound_stmts.html#with). More info [here](http://www.python.org/dev/peps/pep-0343/).
4,042,995
> > **Possible Duplicate:** > > [What is the equivalent of the C# “using” block in IronPython?](https://stackoverflow.com/questions/1757296/what-is-the-equivalent-of-the-c-using-block-in-ironpython) > > > I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pyt...
2010/10/28
[ "https://Stackoverflow.com/questions/4042995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
Python 2.6 introduced the `with` statement, which provides for automatic clean up of objects when they leave the `with` statement. I don't know if the IronPython libraries support it, but it would be a natural fit. Dup question with authoritative answer: [What is the equivalent of the C# "using" block in IronPython?](...
Your code with some comments : ``` def Save(self): filename = "record.txt" data = "{0}:{1}".format(self.Level,self.Name) isf = IsolatedStorageFile.GetUserStoreForApplication() try: isfs = IsolatedStorageFileStream(filename, FileMode.Create, isf) try: # These try is usel...
4,042,995
> > **Possible Duplicate:** > > [What is the equivalent of the C# “using” block in IronPython?](https://stackoverflow.com/questions/1757296/what-is-the-equivalent-of-the-c-using-block-in-ironpython) > > > I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pyt...
2010/10/28
[ "https://Stackoverflow.com/questions/4042995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
I think you are looking for the [with statement](http://docs.python.org/reference/compound_stmts.html#with). More info [here](http://www.python.org/dev/peps/pep-0343/).
If I understand correctly, it looks like the equivalent is the [`with`](http://docs.python.org/reference/compound_stmts.html#with) statement. If your classes define context managers, they will be called automatically after the with block.
4,042,995
> > **Possible Duplicate:** > > [What is the equivalent of the C# “using” block in IronPython?](https://stackoverflow.com/questions/1757296/what-is-the-equivalent-of-the-c-using-block-in-ironpython) > > > I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pyt...
2010/10/28
[ "https://Stackoverflow.com/questions/4042995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
I think you are looking for the [with statement](http://docs.python.org/reference/compound_stmts.html#with). More info [here](http://www.python.org/dev/peps/pep-0343/).
Your code with some comments : ``` def Save(self): filename = "record.txt" data = "{0}:{1}".format(self.Level,self.Name) isf = IsolatedStorageFile.GetUserStoreForApplication() try: isfs = IsolatedStorageFileStream(filename, FileMode.Create, isf) try: # These try is usel...
54,560,326
so i'm fairly new to python and coding in general and i decided to make a text based trivia game as a sort of test. and I've coded everything for the first question. code which i will repeat for each question. my problem is specifically on lines 10-11. the intended function is to add one to the current score, then prin...
2019/02/06
[ "https://Stackoverflow.com/questions/54560326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11024647/" ]
`scoregained` isn't a function, it is a variable you assign but do not update. This would be a great place for a function, which you can reuse whenever you want to print the score. For example: ``` def print_score(score): print('Your score is {}'.format(score)) ``` You can reuse this function anytime you wish to...
I'd probably use something like: ``` def score_stats(score): print('Your score is {}'.format(score)) input('TRIVIA: press enter to start') score, strike = 0, 3 strikesleft = 'strikes left: {}'.format(strike) score_stats(score) Q1 = input('What is the diameter of the earth?') if Q1 == '7917.5': print('correct...
63,442,333
When running `npm start`, my code shows a blank page, without favicon either, and the browse console shows ``` Loading failed for the <script> with source “http://localhost:3000/short_text_understanding/static/js/bundle.js”. bundle.js:23:1 Loading failed for the <script> with source “http://localhost:3000/short_text_u...
2020/08/16
[ "https://Stackoverflow.com/questions/63442333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1780570/" ]
``` /// <summary> /// Passengers array /// </summary> public Passenger[] Passengers = new Passenger[10]; public class Passenger { public int Age { get; set; } public Passenger(int age) { Age = age; } } public void AddPassenger() { ...
You can try: ``` public void AddPassengers(Passenger[] passengers) { int i = Array.IndexOf(passengers, null); if (i < 0) { Console.WriteLine("The array is full."); return; } Console.WriteLine("How old is the passenger?"); int age = Int3...
63,442,333
When running `npm start`, my code shows a blank page, without favicon either, and the browse console shows ``` Loading failed for the <script> with source “http://localhost:3000/short_text_understanding/static/js/bundle.js”. bundle.js:23:1 Loading failed for the <script> with source “http://localhost:3000/short_text_u...
2020/08/16
[ "https://Stackoverflow.com/questions/63442333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1780570/" ]
``` /// <summary> /// Passengers array /// </summary> public Passenger[] Passengers = new Passenger[10]; public class Passenger { public int Age { get; set; } public Passenger(int age) { Age = age; } } public void AddPassenger() { ...
``` public void Add_Passengers() { PassengerClass PassengerClass = new PassengerClass(); Console.WriteLine("How old are the passengers?"); PassengerClass.AddPassanger(Int32.Parse(Console.ReadLine())); } public class PassengerClass { public List<int> passangerList; ...
63,442,333
When running `npm start`, my code shows a blank page, without favicon either, and the browse console shows ``` Loading failed for the <script> with source “http://localhost:3000/short_text_understanding/static/js/bundle.js”. bundle.js:23:1 Loading failed for the <script> with source “http://localhost:3000/short_text_u...
2020/08/16
[ "https://Stackoverflow.com/questions/63442333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1780570/" ]
``` /// <summary> /// Passengers array /// </summary> public Passenger[] Passengers = new Passenger[10]; public class Passenger { public int Age { get; set; } public Passenger(int age) { Age = age; } } public void AddPassenger() { ...
I would go with the class solution: ```cs public class Passanger { public int age; public Passanger(int age) { this.age = age; } } public class Passangers { private List<Passanger> passangers; private int limit; public bool ready { get; ...
63,442,333
When running `npm start`, my code shows a blank page, without favicon either, and the browse console shows ``` Loading failed for the <script> with source “http://localhost:3000/short_text_understanding/static/js/bundle.js”. bundle.js:23:1 Loading failed for the <script> with source “http://localhost:3000/short_text_u...
2020/08/16
[ "https://Stackoverflow.com/questions/63442333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1780570/" ]
``` /// <summary> /// Passengers array /// </summary> public Passenger[] Passengers = new Passenger[10]; public class Passenger { public int Age { get; set; } public Passenger(int age) { Age = age; } } public void AddPassenger() { ...
Rather than iterating the array each time, you can keep an additional field tracking the index and increment it within the add operation. ``` private Passenger[] passengers = new Passenger[10]; private int _count = 0; public void Add_Passengers() { // validate overflow. >= not strictly necessary but a better safeg...
73,225,062
I am trying to use `multiprocessing.Queue` to manage some tasks that are sent by the main process and picked up by "worker" processes (`multiprocessing.Process`). The workers then run the task and put the results into a result queue. Here is my main script: ```py from multiprocessing import Process, Queue, freeze_sup...
2022/08/03
[ "https://Stackoverflow.com/questions/73225062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19102984/" ]
``` import pandas as pd import numpy as np rng = np.random.default_rng(92) df = pd.DataFrame({'a':rng.integers(0,5, 10), 'b':rng.integers(0,5, 10), 'c':rng.integers(0,5, 10)}) df ### a b c 0 2 3 1 1 3 4 0 2 4 1 1 3 0 0 1 4 2 3 3 5 1 0 2 6 2 2 2 7 1 3 2 ...
here is one way to do it. If you post the data to reproduce, i would have posted the result set. ``` window=5 df[df['Column']!=0]['Column'].rolling(window).mean() ```
73,225,062
I am trying to use `multiprocessing.Queue` to manage some tasks that are sent by the main process and picked up by "worker" processes (`multiprocessing.Process`). The workers then run the task and put the results into a result queue. Here is my main script: ```py from multiprocessing import Process, Queue, freeze_sup...
2022/08/03
[ "https://Stackoverflow.com/questions/73225062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19102984/" ]
``` import pandas as pd import numpy as np rng = np.random.default_rng(92) df = pd.DataFrame({'a':rng.integers(0,5, 10), 'b':rng.integers(0,5, 10), 'c':rng.integers(0,5, 10)}) df ### a b c 0 2 3 1 1 3 4 0 2 4 1 1 3 0 0 1 4 2 3 3 5 1 0 2 6 2 2 2 7 1 3 2 ...
As commented by @JK Chai ``` window=5 df['rollMeanColumn'] = df.loc[:, 'Column'].replace(0,np.nan).rolling(window).mean() ```
60,155,158
I'm using selenium in python and trying to click an element that is not a button class. I'm using Google Chrome as my browser/web driver Here is my code: ``` from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome(executable_path="/Users/ep9k/Desktop/SeleniumTest/drivers/chromedriver"...
2020/02/10
[ "https://Stackoverflow.com/questions/60155158", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9305645/" ]
The element doesn't need to be a button to be clickable. after I ran your code, I've added: ```py results = driver.find_elements_by_class_name('SearchResults') first_result = results[0] first_result.click() ``` And it worked perfectly fine for me. Most probably you tried to click on some different element and that...
Clicking the first row with xpath - see below. Assuming you want to parse each of the results(parcels) after that, make use of the navigation buttons; this is a structure you could use: ``` table = driver.find_elements_by_xpath("//table[@id='searchResults']") table[0].click() # Extract the total number of parcels fr...
60,155,158
I'm using selenium in python and trying to click an element that is not a button class. I'm using Google Chrome as my browser/web driver Here is my code: ``` from selenium import webdriver from bs4 import BeautifulSoup driver = webdriver.Chrome(executable_path="/Users/ep9k/Desktop/SeleniumTest/drivers/chromedriver"...
2020/02/10
[ "https://Stackoverflow.com/questions/60155158", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9305645/" ]
The element doesn't need to be a button to be clickable. after I ran your code, I've added: ```py results = driver.find_elements_by_class_name('SearchResults') first_result = results[0] first_result.click() ``` And it worked perfectly fine for me. Most probably you tried to click on some different element and that...
induce `WebDriverWait` and following `css` selector to click table item. ``` from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from bs4 import BeautifulSoup driver = webdriv...
34,645,978
I am new to python and would like to have a script that looks at a feature class and compares the values in two text fields and then populates a third field with a `Y` or `N` depending on if the values are the same or not. I think I need to use an UpdateCursor with an if statement. I have tried the following but I get ...
2016/01/07
[ "https://Stackoverflow.com/questions/34645978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5755063/" ]
Try splitting up the for loop that goes through each item and the actual get\_multi call itself. So something like: ``` all_values = ndb.get_multi(all_keys) for counter in all_values: # Insert amazeballs codes here ``` I have a feeling it's one of these: 1. The generator pattern (yield from for loop) is causing...
When I've dug into similar issues, one thing I've learned is that `get_multi` can cause multiple RPCs to be sent from your application. It looks like the default in the SDK is set to 1000 keys per get, but the batch size I've observed in production apps is much smaller: something more like 10 (going from memory). I su...
61,135,030
I'm running a few tasks on the same terminal in bash. Is there a way I can stream all the logs I'm seeing on the bash terminal to a log file? I know can technically pipe the logs of individual tasks, but wondering if there's a more elegant way. So far this is what I'm doing: ``` $> python background1.py > logs/bg1.log...
2020/04/10
[ "https://Stackoverflow.com/questions/61135030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/499363/" ]
Sorry I didn't understand your question :D For this case you can use an input to specify what do you need: type=int(input("What Type Of Def You Want To Use? ")) And then you can put an IF for you selection: if(type==1): command.a(args) elif(type==2): command.b(args) elif(type==3): command.c(args) else: print(...
You can use `input`: ``` name = input ("What's your name") print ("Hello, ", name ) ``` If you're writing a command line tool, it's very doable with the [click package](https://click.palletsprojects.com/en/7.x/). See their Hello World example: ``` import click @click.command() @click.option('--count', default=1, h...
69,555,581
This might be heavily related to similar questions as [Python 3.3: Split string and create all combinations](https://stackoverflow.com/questions/22911367/python-3-3-split-string-and-create-all-combinations/22911505) , but I can't infer a pythonic solution out of this. Question is: Let there be a str such as `'hi|guys...
2021/10/13
[ "https://Stackoverflow.com/questions/69555581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6042172/" ]
An approach, once you have split the string is to use `itertools.combinations` to define the split points in the list, the other positions should be fused again. ``` def lst_merge(lst, positions, sep='|'): '''merges a list on points other than positions''' '''A, B, C, D and 0, 1 -> A, B, C|D''' a = -1 ...
One approach using [`combinations`](https://docs.python.org/3/library/itertools.html#itertools.combinations) and [`chain`](https://docs.python.org/3/library/itertools.html#itertools.chain) ``` from itertools import combinations, chain def partition(alist, indices): # https://stackoverflow.com/a/1198876/4001592 ...
69,555,581
This might be heavily related to similar questions as [Python 3.3: Split string and create all combinations](https://stackoverflow.com/questions/22911367/python-3-3-split-string-and-create-all-combinations/22911505) , but I can't infer a pythonic solution out of this. Question is: Let there be a str such as `'hi|guys...
2021/10/13
[ "https://Stackoverflow.com/questions/69555581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6042172/" ]
An approach, once you have split the string is to use `itertools.combinations` to define the split points in the list, the other positions should be fused again. ``` def lst_merge(lst, positions, sep='|'): '''merges a list on points other than positions''' '''A, B, C, D and 0, 1 -> A, B, C|D''' a = -1 ...
Here is a recursive function I came up with: ``` def splitperms(string, i=0): if len(string) == i: return [[string]] elif string[i] == "|": return [*[[string[:i]] + split for split in splitperms(string[i + 1:])], *splitperms(string, i + 1)] else: return splitperms(string, i + 1) ``...
69,555,581
This might be heavily related to similar questions as [Python 3.3: Split string and create all combinations](https://stackoverflow.com/questions/22911367/python-3-3-split-string-and-create-all-combinations/22911505) , but I can't infer a pythonic solution out of this. Question is: Let there be a str such as `'hi|guys...
2021/10/13
[ "https://Stackoverflow.com/questions/69555581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6042172/" ]
An approach, once you have split the string is to use `itertools.combinations` to define the split points in the list, the other positions should be fused again. ``` def lst_merge(lst, positions, sep='|'): '''merges a list on points other than positions''' '''A, B, C, D and 0, 1 -> A, B, C|D''' a = -1 ...
If you want *all* partitions, try `partitions` from [more-itertools](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.partitions): ``` from more_itertools import partitions s = 'hi|guys|whats|app' for p in partitions(s.split('|')): print(list(map('|'.join, p))) ``` Output: ``` ['hi|guys...
69,555,581
This might be heavily related to similar questions as [Python 3.3: Split string and create all combinations](https://stackoverflow.com/questions/22911367/python-3-3-split-string-and-create-all-combinations/22911505) , but I can't infer a pythonic solution out of this. Question is: Let there be a str such as `'hi|guys...
2021/10/13
[ "https://Stackoverflow.com/questions/69555581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6042172/" ]
An approach, once you have split the string is to use `itertools.combinations` to define the split points in the list, the other positions should be fused again. ``` def lst_merge(lst, positions, sep='|'): '''merges a list on points other than positions''' '''A, B, C, D and 0, 1 -> A, B, C|D''' a = -1 ...
I am surprised that most answers are using `combinations`, where this is clearly a *binary power* sequence (that is, multiple *binary cartesian products concatenated*). Let me elaborate: if we have `n` separators, we have `2**n` possible strings, where each separator is either `on` or `off`. So if we map each bit of a...
64,163,749
I have asyncio crawler, that visits URLs and collects new URLs from HTML responses. I was inspired that great tool: <https://github.com/aio-libs/aiohttp/blob/master/examples/legacy/crawl.py> Here is a very simplified piece of workflow, how it works: ``` import asyncio import aiohttp class Requester: def __init_...
2020/10/01
[ "https://Stackoverflow.com/questions/64163749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14376515/" ]
I have created an example in Node.js that is based on the steps from my previous answer to this question. The first action expects a valid apikey in `params.apikey` as input parameter and returns a bearer token: ```js /** * * main() will be run when you invoke this action * * @param Cloud Functions actions accept...
I can't guide you the full way right now, but I hope the information that I can provide will guide you into the right direction. First you'll need to identify the authorization endpoint: `curl http://api.us-south.cf.cloud.ibm.com/info` With that and a valid IAM API token for your account you can get the bearer token...
53,098,413
I am storing discount codes with different prefixes and unique digits at the end (`10OFF<abc>`, `25OFF<abc>`, `50OFF<abc>`, etc.) in a file, and then loading that file into a list. I am trying to make a function so that when they are redeemed, they are removed from the list, and the file is overwritten. Right now what...
2018/11/01
[ "https://Stackoverflow.com/questions/53098413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10142229/" ]
this should do what you want ``` list_of_codes=open('codes.txt','rt').read().split('\n') while True: code=input('enter code to remove:') if code in list_of_codes: break else: print('code you entered is not in the list') continue list_of_codes.pop(list_of_codes.index(code)) with open...
This code promps the user to input all the code he whishes to remove, then it reads the current file and overwrites the file with only the code that were NOT input by the user. The file considers the whole content of a line as a code (must contain prefix + unique digits). The code also leaves the old file as a backup,...
53,098,413
I am storing discount codes with different prefixes and unique digits at the end (`10OFF<abc>`, `25OFF<abc>`, `50OFF<abc>`, etc.) in a file, and then loading that file into a list. I am trying to make a function so that when they are redeemed, they are removed from the list, and the file is overwritten. Right now what...
2018/11/01
[ "https://Stackoverflow.com/questions/53098413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10142229/" ]
this should do what you want ``` list_of_codes=open('codes.txt','rt').read().split('\n') while True: code=input('enter code to remove:') if code in list_of_codes: break else: print('code you entered is not in the list') continue list_of_codes.pop(list_of_codes.index(code)) with open...
I'd suggest using a database structure for this such as maybe [TinyDB](https://pypi.org/project/tinydb/) *(uses json in the background)*. Or at the very least making the file a .json file and using [dataIO](https://pypi.org/project/dataIO/). This way saving and loading are faster and you keep a `list` in python that's ...
40,703,228
I am trying to run a Flask REST service on CentOS Apache2 using WSGI. The REST service requires a very small storage. So i decided to use SQLite with `sqlite3` python package. The whole application worked perfectly well on my local system and on the CentOS server when ran using `app.run()`. But when i used WSGI to host...
2016/11/20
[ "https://Stackoverflow.com/questions/40703228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6935236/" ]
In addition to changing the database file permissions, you need also to change permissions for the directory that hosts the database file. You can try the following command: ``` chmod 664 /path/to/your/directory/ ``` You can also change the directory's owner as follows: ``` chown apache:apache /path/to/your/directo...
What worked for me (I don't have sudo) was removing the database file and all migrations and starting again, as described here: [How do I delete DB (sqlite3) in Django 1.9 to start from scratch?](https://stackoverflow.com/questions/42150499/how-do-i-delete-db-sqlite3-in-django-1-9-to-start-from-scratch/42150639)
40,703,228
I am trying to run a Flask REST service on CentOS Apache2 using WSGI. The REST service requires a very small storage. So i decided to use SQLite with `sqlite3` python package. The whole application worked perfectly well on my local system and on the CentOS server when ran using `app.run()`. But when i used WSGI to host...
2016/11/20
[ "https://Stackoverflow.com/questions/40703228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6935236/" ]
In addition to changing the database file permissions, you need also to change permissions for the directory that hosts the database file. You can try the following command: ``` chmod 664 /path/to/your/directory/ ``` You can also change the directory's owner as follows: ``` chown apache:apache /path/to/your/directo...
run ``` sudo chmod 774 path-to-your-djangoproject-directory ``` The directory should be the one which contains manage.py and db.sqlite3 files. (the parent container). Worked in my case.
40,703,228
I am trying to run a Flask REST service on CentOS Apache2 using WSGI. The REST service requires a very small storage. So i decided to use SQLite with `sqlite3` python package. The whole application worked perfectly well on my local system and on the CentOS server when ran using `app.run()`. But when i used WSGI to host...
2016/11/20
[ "https://Stackoverflow.com/questions/40703228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6935236/" ]
What worked for me (I don't have sudo) was removing the database file and all migrations and starting again, as described here: [How do I delete DB (sqlite3) in Django 1.9 to start from scratch?](https://stackoverflow.com/questions/42150499/how-do-i-delete-db-sqlite3-in-django-1-9-to-start-from-scratch/42150639)
run ``` sudo chmod 774 path-to-your-djangoproject-directory ``` The directory should be the one which contains manage.py and db.sqlite3 files. (the parent container). Worked in my case.
13,984,423
I am very new to python, this is my first program that I am trying. This function reads the password from the standard input. ``` def getPassword() : passwordArray =[] while 1: char = sys.stdin.read(1) if char == '\\n': break pas...
2012/12/21
[ "https://Stackoverflow.com/questions/13984423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1731553/" ]
Your indentation is not correct. Your `while` should be indented the same as the line above it.
Python uses indentation to "separate" stuff and the thing with that is you need to have the same kind of indentation across the file. Having a fixed kind of indentation in the code you write is good practice. You might want to consider a tab or four spaces(The later being the suggestion in the PEP8 style guide)
13,984,423
I am very new to python, this is my first program that I am trying. This function reads the password from the standard input. ``` def getPassword() : passwordArray =[] while 1: char = sys.stdin.read(1) if char == '\\n': break pas...
2012/12/21
[ "https://Stackoverflow.com/questions/13984423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1731553/" ]
Your indentation is not correct. Your `while` should be indented the same as the line above it.
Python is sensitive and depended on indentation. If it complains "invalid Format", that is better than "invalid syntax".
43,380,783
I wrote a MoviePy script that takes an input video, does some processing, and outputs a video file. I want to run this through an entire folder of videos. Any help or direction is appreciated. Here's what I tried... ``` for f in *; do python resize.py $f; done ``` and resize.py source code here: ``` from moviepy.e...
2017/04/12
[ "https://Stackoverflow.com/questions/43380783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7859068/" ]
I know you have an answer [on Github](https://github.com/Zulko/moviepy/issues/542#issuecomment-293735347), but I'll add my own solution. First, you'll want to put your code inside a function: ``` def process_video(input): """Parameter input should be a string with the full path for a video""" clip = VideoFil...
I responded on your [Github issue #542](https://github.com/Zulko/moviepy/issues/542#issuecomment-293843765), but I copied it here for future reference! First off, the below example isn't ironclad, but it should do what you need. You can achieve this via something like this: ``` #!/usr/bin/env python # -*- coding: utf...
37,124,342
I am "using" `Statsmodel`for less than 2 days and am not at all familiar with the import commands etc. I want to run a simple `variance_inflation_factor` from [here](http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html) but am having some issues. My code...
2016/05/09
[ "https://Stackoverflow.com/questions/37124342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5211377/" ]
The function `variance_inflation_factor` is found in `statsmodels.stats.outlier_influence` as seen [in the docs](http://statsmodels.sourceforge.net/devel/_modules/statsmodels/stats/outliers_influence.html), so to use it you must import correctly, an option would be ``` from statsmodels.stats import outliers_influence...
``` a = df1.years_exp b = df1.leg_totalbills c = df1.log_diff_rgdp d = df1.unemployment e = df1.expendituresfor f = df1.direct_expenditures g = df1.indirect_expenditures ck=np.array([a,b,c,d,e,f,g]) outliers_influence.variance_inflation_factor(ck, 6) ```
37,124,342
I am "using" `Statsmodel`for less than 2 days and am not at all familiar with the import commands etc. I want to run a simple `variance_inflation_factor` from [here](http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html) but am having some issues. My code...
2016/05/09
[ "https://Stackoverflow.com/questions/37124342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5211377/" ]
Thanks for asking this question! I had the same question today, except I wanted to calculate the variance inflation factor for each of the features. Here is a programmatic way to do this: ``` from patsy import dmatrices from statsmodels.stats.outliers_influence import variance_inflation_factor # 'feature_1 + feature_...
``` a = df1.years_exp b = df1.leg_totalbills c = df1.log_diff_rgdp d = df1.unemployment e = df1.expendituresfor f = df1.direct_expenditures g = df1.indirect_expenditures ck=np.array([a,b,c,d,e,f,g]) outliers_influence.variance_inflation_factor(ck, 6) ```
11,809,643
I have some python code with many lines like this: ``` print "some text" + variables + "more text and special characters .. etc" ``` I want to modify this to put everything after print within brackets, like this: ``` print ("some text" + variables + "more text and special characters .. etc") ``` How to do this in...
2012/08/04
[ "https://Stackoverflow.com/questions/11809643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1338814/" ]
Use this substitute: ``` %s/print \(.*$\)/print (\1) ``` `\(.*$\)` matches everything up to the end of the line and captures it in a group using the escaped parentheses. The replacement includes this group using `\1`, surrounded by literal parentheses.
``` :%s/print \(.*\)/print(\1)/c ``` OR if you visually select multiple lines ``` :'<,'>s/print \(.*\)/print(\1)/c ``` `%` - every line `'<,'>` - selected lines `s` - substitute `c` - confirm - show you what matched before you convert `print \(.*\)` - exactly match print followed by a space then group ...
20,553,695
I'm fairly green in Python and trying to get django working to build a simple website. I've installed Django 1.6 under Python 2.7.6 but can't get django-admin to run. According to the tutorial I should create a project as follows, but I get a syntax error: ``` Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 ...
2013/12/12
[ "https://Stackoverflow.com/questions/20553695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1324833/" ]
``` django-admin.py startproject Nutana ``` should be run in the command line, and not in the django shell. If the second case is not working 1. If you are using a virtual-env, did you forget to activate it ? 2. Make sure you add `C:\Python27\Scripts` to the path, and you would not face this issue.
Try this `$ django-admin.py startproject mysite` You don't need the python statement in front.
26,721,113
I have an equation 'a\*x+logx-b=0,(a and b are constants)', and I want to solve x. The problem is that I have numerous constants a(accordingly numerous b). How do I solve this equation by using python?
2014/11/03
[ "https://Stackoverflow.com/questions/26721113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4211557/" ]
You could check out something like <http://docs.scipy.org/doc/scipy-0.13.0/reference/optimize.nonlin.html> which has tools specifically designed for these kinds of equations.
Cool - today I learned about Python's numerical solver. ``` from math import log from scipy.optimize import brentq def f(x, a, b): return a * x + log(x) - b for a in range(1,5): for b in range(1,5): result = brentq(lambda x:f(x, a, b), 1e-10, 20) print a, b, result ``` `brentq` provides es...
26,906,586
**Background:** I have an OpenShift Python 2.7 gear containing my Django 1.6 application. I used django-openshift-quickstart.git as a starting point for my own project and it works well. However, if I have a syntax error in my code or some other exception I have no way of finding it. I can do a tail of the logs via: ...
2014/11/13
[ "https://Stackoverflow.com/questions/26906586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3538533/" ]
I don't know zilch about OpenShift, but 1. you may have to configure your loggers (<https://docs.djangoproject.com/en/1.6/topics/logging/#configuring-logging>) and 2. you have to restart the wsgi processes when you make some changes to your settings. Now I strongly advise you to NOT set `DEBUG=True` on a production ...
To my horror... it turns out I simply hadn't set DEBUG=True! I could have sworn I had set it in settings.py at some point but my commit history strongly suggests I'm wrong. With DEBUG=True in my wsgi/settings.py I can now debug my application on OpenShift. Apologies for the noise. Doug
63,802,423
I have troubles checking the user token inside of middleware. I'm getting token from cookies and then I need to query database to check if this token exists and belongs to user that made a request. **routing.py** ``` from channels.routing import ProtocolTypeRouter, URLRouter import game.routing from authentication.ut...
2020/09/08
[ "https://Stackoverflow.com/questions/63802423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9631956/" ]
Works on my machine. Hard to say without knowing what the data looks like, so I took a stab below: ```js const value = { expenses: [{amount: 1}, {amount: 2}] } const totalExpense = value.expenses.length > 0 ? ( value.expenses.reduce((acc, curr) => { acc += curr.amount return acc }, 0)) : 0; console.lo...
``` {value => { const totalExpense = value.expenses.length > 0 ? ( value.expenses.reduce((acc, curr) => { acc += parseInt(curr.amount) return acc }, 0)) : 0; console.log(totalExpense); console.log(value.e...
48,688,693
New to Django framework. Mostly reading through documentations. But this one i am unable to crack. Trying to add a URL to an headline, that will be forwarded to the 'headlines' post. The Error: > > NoReverseMatch at / Reverse for 'assignment\_detail' with arguments > '('',)' not found. 1 pattern(s) tried: ['assign...
2018/02/08
[ "https://Stackoverflow.com/questions/48688693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8929670/" ]
Your url does not imply that you have to pass an id, but you're passing one in the template: ``` <a href="{% url 'assignment_detail' post_id %}"><h3>{{ post.title }}</h3></a> ``` It should be: ``` url(r'^assignment_detail/(?P<post_id>[0-9]+)', views.assignment_detail,name='assignment_detail'), ```
That error is Django telling you that it can't find any URLs named 'assignment\_detail' that have an argument to pass in. This is because your url entry in `myproject/urls.py` is missing the argument (`post_id`) that you use in your view. You'll need to update that url line to something similar to this: ``` url(r'^as...
36,620,175
I am receiving a warning and I want to check if this will break. I am using np.where like this in a lot of cases (it is similar, for me, to an if statement in excel). Is there a better or more pythonic or pandas way to do this? I'm trying to turn one dimension into something I can easily do mathematical operations on. ...
2016/04/14
[ "https://Stackoverflow.com/questions/36620175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3966601/" ]
This warning occurs when comparing "int" and "str" in your dataset. Add .astype(int) to your comparison dataset. Try: ``` df['closed_item'] = np.where(df['result'].astype(str)=='Action Taken', 1, 0) ```
The issue that you mentioned is actually quite complex, so let me divide it into parts using your words: > > I am receiving a warning and I want to check if this will *break* > > > A `Warning` is a statement that is telling you to be cautious with how you handle your coding logic. A well-designed warning is not g...
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
``` " Relative path of script file: let s:path = expand('<sfile>') " Absolute path of script file: let s:path = expand('<sfile>:p') " Absolute path of script file with symbolic links resolved: let s:path = resolve(expand('<sfile>:p')) " Folder in which script resides: (not safe for symlinks) let s:path = expand('<sf...
Found it: ``` let s:current_file=expand("<sfile>") ```
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
Found it: ``` let s:current_file=expand("<sfile>") ```
It is worth mentioning that the above solution will only work outside of a function. This will not give the desired result: ``` function! MyFunction() let s:current_file=expand('<sfile>:p:h') echom s:current_file endfunction ``` But this will: ``` let s:current_file=expand('<sfile>') function! MyFunction() echom s...
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
Found it: ``` let s:current_file=expand("<sfile>") ```
If you really want to get the script path inside a function (which is what I'd like to), you can still use `<sfile>`'s second semantic, or its equivalent `<stack>` inside `expand()`. > > > ``` > <sfile> ... > When executing a legacy function, is replaced with the call > stack, as wi...
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
``` " Relative path of script file: let s:path = expand('<sfile>') " Absolute path of script file: let s:path = expand('<sfile>:p') " Absolute path of script file with symbolic links resolved: let s:path = resolve(expand('<sfile>:p')) " Folder in which script resides: (not safe for symlinks) let s:path = expand('<sf...
It is worth mentioning that the above solution will only work outside of a function. This will not give the desired result: ``` function! MyFunction() let s:current_file=expand('<sfile>:p:h') echom s:current_file endfunction ``` But this will: ``` let s:current_file=expand('<sfile>') function! MyFunction() echom s...
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
``` " Relative path of script file: let s:path = expand('<sfile>') " Absolute path of script file: let s:path = expand('<sfile>:p') " Absolute path of script file with symbolic links resolved: let s:path = resolve(expand('<sfile>:p')) " Folder in which script resides: (not safe for symlinks) let s:path = expand('<sf...
If you really want to get the script path inside a function (which is what I'd like to), you can still use `<sfile>`'s second semantic, or its equivalent `<stack>` inside `expand()`. > > > ``` > <sfile> ... > When executing a legacy function, is replaced with the call > stack, as wi...
4,976,776
In my vim plugin, I have two files: ``` myplugin/plugin.vim myplugin/plugin_helpers.py ``` I would like to import plugin\_helpers from plugin.vim (using the vim python support), so I believe I first need to put the directory of my plugin on python's sys.path. How can I (in vimscript) get the path to the currently e...
2011/02/12
[ "https://Stackoverflow.com/questions/4976776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144135/" ]
It is worth mentioning that the above solution will only work outside of a function. This will not give the desired result: ``` function! MyFunction() let s:current_file=expand('<sfile>:p:h') echom s:current_file endfunction ``` But this will: ``` let s:current_file=expand('<sfile>') function! MyFunction() echom s...
If you really want to get the script path inside a function (which is what I'd like to), you can still use `<sfile>`'s second semantic, or its equivalent `<stack>` inside `expand()`. > > > ``` > <sfile> ... > When executing a legacy function, is replaced with the call > stack, as wi...
74,266,511
I am making a blackjack simulator with python and are having problems with when the player want another card. To begin with the player gets a random sample of two numbers from a list and then get the option to take another card or not to. When the answer is yes another card is added to the random sample but it gets add...
2022/10/31
[ "https://Stackoverflow.com/questions/74266511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19321160/" ]
`random.sample(kortlek,1)` `random.sample` returns a list, so you end up `append`ing a list to `handspelare` (which creates the sublists). You could change `append` to `extend`, but `random.sample(..., 1)` is just `random.choice`, so it makes more sense to use `handspelare.append(random.choice(kortlek))`.
Use list concatenation rather than append. ``` handspelare += random.sample(kortlek,1) ``` `append` will not unbundle its argument ``` a = [1] a.append([2]) # [1, [2]] a = [1] a += [2] # [1, 2] ```
74,266,511
I am making a blackjack simulator with python and are having problems with when the player want another card. To begin with the player gets a random sample of two numbers from a list and then get the option to take another card or not to. When the answer is yes another card is added to the random sample but it gets add...
2022/10/31
[ "https://Stackoverflow.com/questions/74266511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19321160/" ]
`random.sample(kortlek,1)` `random.sample` returns a list, so you end up `append`ing a list to `handspelare` (which creates the sublists). You could change `append` to `extend`, but `random.sample(..., 1)` is just `random.choice`, so it makes more sense to use `handspelare.append(random.choice(kortlek))`.
you should create a deck then shuffle it ``` deck = [52 cards] deck.shuffle() ``` then just draw off it like a normal deck in the real world ``` hand.append(deck.pop()) if len(deck) < 15: # or something deck = [52 cards] deck.shuffle() ```
74,266,511
I am making a blackjack simulator with python and are having problems with when the player want another card. To begin with the player gets a random sample of two numbers from a list and then get the option to take another card or not to. When the answer is yes another card is added to the random sample but it gets add...
2022/10/31
[ "https://Stackoverflow.com/questions/74266511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19321160/" ]
you should create a deck then shuffle it ``` deck = [52 cards] deck.shuffle() ``` then just draw off it like a normal deck in the real world ``` hand.append(deck.pop()) if len(deck) < 15: # or something deck = [52 cards] deck.shuffle() ```
Use list concatenation rather than append. ``` handspelare += random.sample(kortlek,1) ``` `append` will not unbundle its argument ``` a = [1] a.append([2]) # [1, [2]] a = [1] a += [2] # [1, 2] ```
19,616,168
I am new to Django and I try to follow the official tutorial. since I want to connect to mysql (installed on my computer, and i checked mysql module does exit in python command line), I set the ENGINE in setting.py to be django.db.backends.mysql . and then I tried to run ``` python manage.py syncdb ``` then I g...
2013/10/27
[ "https://Stackoverflow.com/questions/19616168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2379736/" ]
You need to download the [windows binary installer](http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python) for the MySQL drivers for Python. Installing from source will not work since you do not have the development headers in Windows.
You need to install the mysql python connector sudo apt-get install python-mysqldb
13,877,907
``` # python enter code herePython 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os,sys >>> import setup .......... .......... .......... >>> reload(setup) <module 'setup' from 'setup.pyc'> >>> ```...
2012/12/14
[ "https://Stackoverflow.com/questions/13877907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1468198/" ]
`reload` reloads a module, but doesn't recompile it. ``` >>> reload(setup) <module 'setup' from 'setup.pyc'> ``` It is reloading from the compiled `setup.pyc`, not `setup.py`. The easiest way to get around this is simply to delete `setup.pyc` after making changes. Then when it reloads `setup.py` it will first recom...
Try assigning the value returned by `reload` to the same variable: ``` setup = reload(setup) ```
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
**Try this :** This code works for me . ``` from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" x = 0 with open("temp.txt") as myfile : text = myfile.readline() while text !="": sheet.cell (row=1,column=x+1).value=str(text).encode("ascii",errors="ignore") x+=1 ...
You missed to add the value for cell `sheet.cell (row=1,column=x+1).value =` Try like this ``` from openpyxl import * book = Workbook () sheet = book.active sheet.title = "test" for x in range (7): sheet.cell (row=1,column=x+1).value = "Hello" book.save ('test.xlsx') ```
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
I faced similar issue and found out that it is because of \xa1 character which is hex value of ascii 26 (SUB). Openpyxl is not allowing to write such characters (ascii code < 32). I tried [xlsxwriter](https://xlsxwriter.readthedocs.io/) library without any issue it worte this character in xlsx file.
You missed to add the value for cell `sheet.cell (row=1,column=x+1).value =` Try like this ``` from openpyxl import * book = Workbook () sheet = book.active sheet.title = "test" for x in range (7): sheet.cell (row=1,column=x+1).value = "Hello" book.save ('test.xlsx') ```
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
`openpyxl` comes with an illegal characters regular expression, ready for you to use. Presuming you're happy to simply remove these characters, you can do: ``` import re from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (77...
You missed to add the value for cell `sheet.cell (row=1,column=x+1).value =` Try like this ``` from openpyxl import * book = Workbook () sheet = book.active sheet.title = "test" for x in range (7): sheet.cell (row=1,column=x+1).value = "Hello" book.save ('test.xlsx') ```
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
I faced similar issue and found out that it is because of \xa1 character which is hex value of ascii 26 (SUB). Openpyxl is not allowing to write such characters (ascii code < 32). I tried [xlsxwriter](https://xlsxwriter.readthedocs.io/) library without any issue it worte this character in xlsx file.
**Try this :** This code works for me . ``` from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" x = 0 with open("temp.txt") as myfile : text = myfile.readline() while text !="": sheet.cell (row=1,column=x+1).value=str(text).encode("ascii",errors="ignore") x+=1 ...
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
`openpyxl` comes with an illegal characters regular expression, ready for you to use. Presuming you're happy to simply remove these characters, you can do: ``` import re from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (77...
**Try this :** This code works for me . ``` from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" x = 0 with open("temp.txt") as myfile : text = myfile.readline() while text !="": sheet.cell (row=1,column=x+1).value=str(text).encode("ascii",errors="ignore") x+=1 ...
49,844,925
I have the following python code to write processed words into excel file. The words are about 7729 ``` From openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (7729): sheet.cell (row=1,column=x+1).value=x book.save ('test.xlsx') ``` This is the what the code I used looks like...
2018/04/15
[ "https://Stackoverflow.com/questions/49844925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8616724/" ]
`openpyxl` comes with an illegal characters regular expression, ready for you to use. Presuming you're happy to simply remove these characters, you can do: ``` import re from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE from openpyxl import * book=Workbook () sheet=book.active sheet.title="test" for x in range (77...
I faced similar issue and found out that it is because of \xa1 character which is hex value of ascii 26 (SUB). Openpyxl is not allowing to write such characters (ascii code < 32). I tried [xlsxwriter](https://xlsxwriter.readthedocs.io/) library without any issue it worte this character in xlsx file.
58,007,418
I've got a CASIO fx-CG50 with python running extended version of micropython 1.9.4 Decided to make a game but I really need a sleep function, I cannot use any imports as everything is pretty barebones. Any help would be greatly appreciated. I've tried downloading utilities but they're just extra applications, nothing...
2019/09/19
[ "https://Stackoverflow.com/questions/58007418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8402836/" ]
If you cannot import time (or utime) in your code, you could always implement a simple function that loops for a certain number of steps: ``` def wait(step): for i in range(step): pass wait(999999) ``` In that case, the actual time spent in the function will depend on the computational power of your d...
I am trying to do the same exact things and I was trying to benchmark a wait function by animating a square accross the scree. Here is what I have come up width: ``` from casioplot import * def wait(milli): time = milli*50 for i in range(time): pass def drawSquare(x,y,l): for i in range(l): ...
65,559,632
Seems to be impossible currently with Anaconda as well as with Xcode 12. Via idle, it runs via Rosetta. There seems to be no discussion of this so either I'm quite naive or maybe this will be useful to others as well. Python says: "As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and...
2021/01/04
[ "https://Stackoverflow.com/questions/65559632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14936216/" ]
You can now install python 3.9.1 through multiple pathways now but the most comprehensive build environment for the full data-science suite for python at the moment (Feb 2021) on M1 ARM architecture is via miniforge. e.g. ``` brew install --cask miniforge conda init zsh conda activate conda install numpy scipy scikit...
I am using python3.9.4. I installed it using homebrew only. ``` brew install [email protected] ```
65,559,632
Seems to be impossible currently with Anaconda as well as with Xcode 12. Via idle, it runs via Rosetta. There seems to be no discussion of this so either I'm quite naive or maybe this will be useful to others as well. Python says: "As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and...
2021/01/04
[ "https://Stackoverflow.com/questions/65559632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14936216/" ]
You can now install python 3.9.1 through multiple pathways now but the most comprehensive build environment for the full data-science suite for python at the moment (Feb 2021) on M1 ARM architecture is via miniforge. e.g. ``` brew install --cask miniforge conda init zsh conda activate conda install numpy scipy scikit...
I upgraded to 3.9.4 1. Download the Python universal installer - <https://www.python.org/downloads/mac-osx/> Note: I still could not get sudo pip install mysqlclient to install. I had add to 1. update homebrew - See <https://brew.sh> 2. Add /opt/homebrew/bin to PATH in .bash\_profile (don't forget to source .bash...
65,559,632
Seems to be impossible currently with Anaconda as well as with Xcode 12. Via idle, it runs via Rosetta. There seems to be no discussion of this so either I'm quite naive or maybe this will be useful to others as well. Python says: "As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and...
2021/01/04
[ "https://Stackoverflow.com/questions/65559632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14936216/" ]
You can now install python 3.9.1 through multiple pathways now but the most comprehensive build environment for the full data-science suite for python at the moment (Feb 2021) on M1 ARM architecture is via miniforge. e.g. ``` brew install --cask miniforge conda init zsh conda activate conda install numpy scipy scikit...
You can now install Python 3.9.4 natively on Mac M1 (Apple Silicon). I'm using pyenv to install Python 3.7, 3.8 and 3.9 all native ARM. For example, to install 3.9.4: ``` $ pyenv install 3.9.4 python-build: use [email protected] from homebrew python-build: use readline from homebrew Downloading Python-3.9.4.tar.xz... -> htt...
65,559,632
Seems to be impossible currently with Anaconda as well as with Xcode 12. Via idle, it runs via Rosetta. There seems to be no discussion of this so either I'm quite naive or maybe this will be useful to others as well. Python says: "As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and...
2021/01/04
[ "https://Stackoverflow.com/questions/65559632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14936216/" ]
I am using python3.9.4. I installed it using homebrew only. ``` brew install [email protected] ```
I upgraded to 3.9.4 1. Download the Python universal installer - <https://www.python.org/downloads/mac-osx/> Note: I still could not get sudo pip install mysqlclient to install. I had add to 1. update homebrew - See <https://brew.sh> 2. Add /opt/homebrew/bin to PATH in .bash\_profile (don't forget to source .bash...
65,559,632
Seems to be impossible currently with Anaconda as well as with Xcode 12. Via idle, it runs via Rosetta. There seems to be no discussion of this so either I'm quite naive or maybe this will be useful to others as well. Python says: "As of 3.9.1, Python now fully supports building and running on macOS 11.0 (Big Sur) and...
2021/01/04
[ "https://Stackoverflow.com/questions/65559632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14936216/" ]
You can now install Python 3.9.4 natively on Mac M1 (Apple Silicon). I'm using pyenv to install Python 3.7, 3.8 and 3.9 all native ARM. For example, to install 3.9.4: ``` $ pyenv install 3.9.4 python-build: use [email protected] from homebrew python-build: use readline from homebrew Downloading Python-3.9.4.tar.xz... -> htt...
I upgraded to 3.9.4 1. Download the Python universal installer - <https://www.python.org/downloads/mac-osx/> Note: I still could not get sudo pip install mysqlclient to install. I had add to 1. update homebrew - See <https://brew.sh> 2. Add /opt/homebrew/bin to PATH in .bash\_profile (don't forget to source .bash...
23,936,239
Strings are iterable. Lists are iterable. And with a List of Strings, both the List and the Strings can be iterated through with a nested loop. For Example: ``` input = [ 'abcdefg', 'hijklmn', 'opqrstu'] for item in input: for letter in item: print letter ``` Out: ``` a b c d e f g h i j k l m n o p q...
2014/05/29
[ "https://Stackoverflow.com/questions/23936239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1851961/" ]
You can use [`itertools.chain.from_iterable()`](https://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable): ``` >>> from itertools import chain >>> input = ['abcdefg', 'hijklmn', 'opqrstu'] >>> >>> for letter in chain.from_iterable(input): ... print letter ... a b c d e f g h i j k l m n o p ...
Use `itertools.chain`: ``` for letter in itertools.chain(*input): print letter ```
23,936,239
Strings are iterable. Lists are iterable. And with a List of Strings, both the List and the Strings can be iterated through with a nested loop. For Example: ``` input = [ 'abcdefg', 'hijklmn', 'opqrstu'] for item in input: for letter in item: print letter ``` Out: ``` a b c d e f g h i j k l m n o p q...
2014/05/29
[ "https://Stackoverflow.com/questions/23936239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1851961/" ]
You can use [`itertools.chain.from_iterable()`](https://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable): ``` >>> from itertools import chain >>> input = ['abcdefg', 'hijklmn', 'opqrstu'] >>> >>> for letter in chain.from_iterable(input): ... print letter ... a b c d e f g h i j k l m n o p ...
What you've written is already the most pythonic way to do it; there are already two levels of nesting (letters within strings within a list) so it's correct to have two nested `for` loops. If you really want to use a single `for` statement, you can collapse the loops with a generator comprehension: ``` for letter in...
23,936,239
Strings are iterable. Lists are iterable. And with a List of Strings, both the List and the Strings can be iterated through with a nested loop. For Example: ``` input = [ 'abcdefg', 'hijklmn', 'opqrstu'] for item in input: for letter in item: print letter ``` Out: ``` a b c d e f g h i j k l m n o p q...
2014/05/29
[ "https://Stackoverflow.com/questions/23936239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1851961/" ]
You can use [`itertools.chain.from_iterable()`](https://docs.python.org/3/library/itertools.html#itertools.chain.from_iterable): ``` >>> from itertools import chain >>> input = ['abcdefg', 'hijklmn', 'opqrstu'] >>> >>> for letter in chain.from_iterable(input): ... print letter ... a b c d e f g h i j k l m n o p ...
That is good enough, everything else is just an academic puzzle ``` for item in ''.join(input): print item ```
23,936,239
Strings are iterable. Lists are iterable. And with a List of Strings, both the List and the Strings can be iterated through with a nested loop. For Example: ``` input = [ 'abcdefg', 'hijklmn', 'opqrstu'] for item in input: for letter in item: print letter ``` Out: ``` a b c d e f g h i j k l m n o p q...
2014/05/29
[ "https://Stackoverflow.com/questions/23936239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1851961/" ]
Use `itertools.chain`: ``` for letter in itertools.chain(*input): print letter ```
That is good enough, everything else is just an academic puzzle ``` for item in ''.join(input): print item ```
23,936,239
Strings are iterable. Lists are iterable. And with a List of Strings, both the List and the Strings can be iterated through with a nested loop. For Example: ``` input = [ 'abcdefg', 'hijklmn', 'opqrstu'] for item in input: for letter in item: print letter ``` Out: ``` a b c d e f g h i j k l m n o p q...
2014/05/29
[ "https://Stackoverflow.com/questions/23936239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1851961/" ]
What you've written is already the most pythonic way to do it; there are already two levels of nesting (letters within strings within a list) so it's correct to have two nested `for` loops. If you really want to use a single `for` statement, you can collapse the loops with a generator comprehension: ``` for letter in...
That is good enough, everything else is just an academic puzzle ``` for item in ''.join(input): print item ```
14,610,459
Go's time package claims giving a nanosecond precision. <http://golang.org/src/pkg/time/time.go> I'm wondering how it is implemented and if I can trust it. My doubts come from Python, which clearly documents its difficulties and limitations with time: > > *From <http://docs.python.org/2/library/time.html>* > > > T...
2013/01/30
[ "https://Stackoverflow.com/questions/14610459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/520159/" ]
Well as for the implementation, `time.Now()` falls back to a function implemented in the runtime. You can review the [C time implementation](http://code.google.com/p/go/source/browse/src/pkg/runtime/time.goc) and the implementation for [`time·now` in assembly](http://code.google.com/p/go/source/browse/src/pkg/runtime/...
One of the problems with Python's [time.time](http://docs.python.org/2/library/time.html#time.time) function is that it returns a [float](http://docs.python.org/2/library/functions.html#float). A float is an [IEEE 754 double-precision number](http://en.wikipedia.org/wiki/Double-precision_floating-point_format) which ha...