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,966,205 | I want to convert some base64 encoded png images to jpg using python. I know how to decode from base64 back to raw:
```
import base64
pngraw = base64.decodestring(png_b64text)
```
but how can I convert this now to jpg? Just writing pngraw to a file obviously only gives me a png file. **I know I can use PIL, but HOW... | 2011/08/06 | [
"https://Stackoverflow.com/questions/6966205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/561766/"
] | You can use [PIL](http://www.pythonware.com/products/pil/):
```
data = b'''iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAIBJRE
FUOMvN08ENgCAMheG/TGniEo7iEiZuqTeiUkoLHORK++Ul8ODPZ92XS2ZiADITmwI+sWHwi
w2BGtYN1jCAZF1GMYDkGfJix3ZK8g57sJywteTFClBbjmAq+ESiGIBEX9nCqgl7sfyxIykt
... | Right from the PIL tutorial:
>
> To save a file, use the save method of the Image class. When saving files, the name becomes important. Unless you specify the format, the library uses the filename extension to discover which file storage format to use.
>
>
>
Convert files to JPEG
---------------------
```
import... |
48,504,746 | I am trying to add a **GUI** input box and I found out that the way you do that is by using a module called `tkinter`. While I was trying to install it on my arch linux machine through the `ActivePython` package I got the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ... | 2018/01/29 | [
"https://Stackoverflow.com/questions/48504746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9219560/"
] | All you need to do is to install the tkinter package. Now universal precompiled packages such as ActivePython will not work, well at least it didn't work for me. I don't know if this problem occurs in other OSes but I know the solution for Linux: Install the Tk package from the terminal.
In Arch, Tk is available in th... | I'm on Manjaro, use Gnome3 on Wayland. After installed `tk` I got an error about Xorg. So I use Google, and found I need to install `python-pygubu` from [Visual editor for creating GUI in Python 3 tkinter](https://bbs.archlinux.org/viewtopic.php?id=221077).
And then another error like: [Gtk-WARNING \*\*: Unable to loc... |
48,504,746 | I am trying to add a **GUI** input box and I found out that the way you do that is by using a module called `tkinter`. While I was trying to install it on my arch linux machine through the `ActivePython` package I got the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ... | 2018/01/29 | [
"https://Stackoverflow.com/questions/48504746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9219560/"
] | All you need to do is to install the tkinter package. Now universal precompiled packages such as ActivePython will not work, well at least it didn't work for me. I don't know if this problem occurs in other OSes but I know the solution for Linux: Install the Tk package from the terminal.
In Arch, Tk is available in th... | Install tk through command line
```
sudo pacman -S tk
sudo apt-get install tk
```
depending on your OS.
It will work.
```
import tk
```
or
```
import turtle # (turtle uses tk as a dependancy)
```
reproduces the error.
Also doing pip install does not removes the error.
So you must install tk through your pac... |
48,504,746 | I am trying to add a **GUI** input box and I found out that the way you do that is by using a module called `tkinter`. While I was trying to install it on my arch linux machine through the `ActivePython` package I got the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ... | 2018/01/29 | [
"https://Stackoverflow.com/questions/48504746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9219560/"
] | All you need to do is to install the tkinter package. Now universal precompiled packages such as ActivePython will not work, well at least it didn't work for me. I don't know if this problem occurs in other OSes but I know the solution for Linux: Install the Tk package from the terminal.
In Arch, Tk is available in th... | If you happen to be working with [Alpine](https://alpinelinux.org/) then the below command will install `tk`.
```
apk add tk
``` |
48,504,746 | I am trying to add a **GUI** input box and I found out that the way you do that is by using a module called `tkinter`. While I was trying to install it on my arch linux machine through the `ActivePython` package I got the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ... | 2018/01/29 | [
"https://Stackoverflow.com/questions/48504746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9219560/"
] | Install tk through command line
```
sudo pacman -S tk
sudo apt-get install tk
```
depending on your OS.
It will work.
```
import tk
```
or
```
import turtle # (turtle uses tk as a dependancy)
```
reproduces the error.
Also doing pip install does not removes the error.
So you must install tk through your pac... | I'm on Manjaro, use Gnome3 on Wayland. After installed `tk` I got an error about Xorg. So I use Google, and found I need to install `python-pygubu` from [Visual editor for creating GUI in Python 3 tkinter](https://bbs.archlinux.org/viewtopic.php?id=221077).
And then another error like: [Gtk-WARNING \*\*: Unable to loc... |
48,504,746 | I am trying to add a **GUI** input box and I found out that the way you do that is by using a module called `tkinter`. While I was trying to install it on my arch linux machine through the `ActivePython` package I got the following error:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ... | 2018/01/29 | [
"https://Stackoverflow.com/questions/48504746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9219560/"
] | Install tk through command line
```
sudo pacman -S tk
sudo apt-get install tk
```
depending on your OS.
It will work.
```
import tk
```
or
```
import turtle # (turtle uses tk as a dependancy)
```
reproduces the error.
Also doing pip install does not removes the error.
So you must install tk through your pac... | If you happen to be working with [Alpine](https://alpinelinux.org/) then the below command will install `tk`.
```
apk add tk
``` |
58,702,300 | I have python script for SharePoint login (using python office365-rest-python-client) and download a file. I would like to convert script to executable file so i can share it with non-technical people. Python code run fine but when i convert it to exe using Pyinstaller and try to run, it gives me FileNotFoundError.
I ... | 2019/11/04 | [
"https://Stackoverflow.com/questions/58702300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10777463/"
] | Create a copy of `SAML.xml` (in my test case, right next to my python script `test0.py`); you can copy/paste from [this page](https://raw.githubusercontent.com/vgrem/Office365-REST-Python-Client/master/office365/runtime/auth/providers/templates/SAML.xml). Then run:
```
pyinstaller --onefile --add-data "SAML.xml;office... | The `_MEI66362` folder is created when you execute a `Pyinstaller` created `.exe`. It will contain everything that `Pyinstaller` determined is needed by your application. However, it cannot deduce every file that your app needs. In some cases, you must tell `Pyinstaller` about needed resources. You can use the `-add-da... |
62,054,092 | I have looked [here](https://stackoverflow.com/questions/1475123/easiest-way-to-turn-a-list-into-an-html-table-in-python) but the solution is still not working out for me...
I have `2 lists`
```py
list1 = ['src_table', 'error_response_code', 'error_count', 'max_dt']
list2 = ['src_periods_43200', 404, 21, datetime.dat... | 2020/05/27 | [
"https://Stackoverflow.com/questions/62054092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3107664/"
] | This Should do it
```
import pandas as pd
import datetime
list1 = ['src_table', 'error_response_code', 'error_count', 'max_dt']
list2 = [
'src_periods_43200', 404, 21, datetime.datetime(2020, 5, 26, 21, 10, 7),
'src_periods_86400', 404, 19, datetime.datetime(2020, 5, 25, 21, 10, 7)
]
index_break = len(list1... | You can easily write your function for that
Something like:
```py
import datetime
list1 = ['src_table', 'error_response_code', 'error_count', 'max_dt']
list2 = ['src_periods_43200', 404, 21, datetime.datetime(2020, 5, 26, 21, 10, 7), 'src_periods_86400', 404, 19, datetime.datetime(2020, 5, 25, 21, 10, 7)]
print('<t... |
48,529,567 | This is my code:
```
while True:
chosenUser = raw_input("Enter a username: ")
with open("userDetails.txt", "r") as userDetailsFile:
for line in userDetailsFile:
if chosenUser in line:
print "\n"
print chosenUser, "has taken previous tests. "
... | 2018/01/30 | [
"https://Stackoverflow.com/questions/48529567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9244343/"
] | As others have noted, the primary problem is that the `break` only breaks from the inner `for` loop, not from the outer `while` loop, which can be fixed using e.g. a boolean variable or `return`.
But unless you want the "not registered" line to be printed for *every* line that does not contain the user's name, you sho... | The easiest way to work around this is to make the outer `while` alterable by using a boolean variable, and toggling it:
```
loop = True
while loop:
for x in y:
if exit_condition:
loop = False
break
```
That way you can stop the outer loop from within an inner one. |
48,529,567 | This is my code:
```
while True:
chosenUser = raw_input("Enter a username: ")
with open("userDetails.txt", "r") as userDetailsFile:
for line in userDetailsFile:
if chosenUser in line:
print "\n"
print chosenUser, "has taken previous tests. "
... | 2018/01/30 | [
"https://Stackoverflow.com/questions/48529567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9244343/"
] | As others have noted, the primary problem is that the `break` only breaks from the inner `for` loop, not from the outer `while` loop, which can be fixed using e.g. a boolean variable or `return`.
But unless you want the "not registered" line to be printed for *every* line that does not contain the user's name, you sho... | The `break` breaks out the the inner `for` loop only.
Better put everything in a function and stop your `while` loop with a `return`:
```
def main():
while True:
chosenUser = raw_input("Enter a username: ")
with open("userDetails.txt", "r") as userDetailsFile:
for line in userDetai... |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | ```
# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
```
**Download and install Python 3.3.0**
```
# wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
# tar xf Python-3.3.0.tar.bz2
# cd Python-3.3.0
# ./configure -... | I unistalled the original version of python (2.6.6) and install 2.7(with option `make && make altinstall`) but when I tried install something with yum didn't work.
So I solved this issue as follow:
1. `# ln -s /usr/local/bin/python /usr/bin/python`
2. Download the RPM package python-2.6.6-36.el6.i686.rpm from <http:/... |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | [Chris Lea](http://chrislea.com/2009/09/09/easy-python-2-6-django-on-centos-5/) provides a YUM repository for python26 RPMs that can co-exist with the 'native' 2.4 that is needed for quite a few admin tools on CentOS.
Quick instructions that worked at least for me:
```
$ sudo rpm -Uvh http://yum.chrislea.com/centos/5... | ```
rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
rpm -Uvh ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/libffi-3.0.5-1.el5.kb.i386.rpm
yum install python26
python26
```
for dos that just dont know :=) |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | No need to do yum or make your own RPM. Build `python26` from source.
```
wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -zxvf Python-2.6.6.tgz
cd Python-2.6.6
./configure && make && make install
```
There can be a **dependency error** use
```
yum install gcc cc
```
Add the install path (`/usr... | ```
# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
```
**Download and install Python 3.3.0**
```
# wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
# tar xf Python-3.3.0.tar.bz2
# cd Python-3.3.0
# ./configure -... |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | No, that's it. You might want to make sure you have all optional library headers installed too so you don't have to recompile it later. They are listed in the documentation I think.
Also, you can install it even in the standard path if you do `make altinstall`. That way it won't override your current default "python". | Missing Dependency: libffi.so.5 is here :
<ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/libffi-3.0.5-1.el5.kb.i386.rpm> |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | If you want to make it easier on yourself, there are CentOS RPMs for new Python versions floating around the net. E.g. see:
<http://www.geekymedia.com/python_26_centos.html> | I unistalled the original version of python (2.6.6) and install 2.7(with option `make && make altinstall`) but when I tried install something with yum didn't work.
So I solved this issue as follow:
1. `# ln -s /usr/local/bin/python /usr/bin/python`
2. Download the RPM package python-2.6.6-36.el6.i686.rpm from <http:/... |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | I unistalled the original version of python (2.6.6) and install 2.7(with option `make && make altinstall`) but when I tried install something with yum didn't work.
So I solved this issue as follow:
1. `# ln -s /usr/local/bin/python /usr/bin/python`
2. Download the RPM package python-2.6.6-36.el6.i686.rpm from <http:/... | Type the following commands on the terminal to install Python 3.6 on CentOS 7:
```
$ sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
```
Then do :
```
$ sudo yum install python36u
```
You can also install any version instead of 3.6 (if you want to) by just replacing 36 by your version number. |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | When you install your python version (in this case it is python2.6) then issue this command to create your `virtualenv`:
```
virtualenv -p /usr/bin/python2.6 /your/virtualenv/path/here/
``` | ```
rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
rpm -Uvh ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/libffi-3.0.5-1.el5.kb.i386.rpm
yum install python26
python26
```
for dos that just dont know :=) |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | You could also use the [EPEL-repository](http://fedoraproject.org/wiki/EPEL), and then do `sudo yum install python26` to install python 2.6 | Type the following commands on the terminal to install Python 3.6 on CentOS 7:
```
$ sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
```
Then do :
```
$ sudo yum install python36u
```
You can also install any version instead of 3.6 (if you want to) by just replacing 36 by your version number. |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | No need to do yum or make your own RPM. Build `python26` from source.
```
wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -zxvf Python-2.6.6.tgz
cd Python-2.6.6
./configure && make && make install
```
There can be a **dependency error** use
```
yum install gcc cc
```
Add the install path (`/usr... | I unistalled the original version of python (2.6.6) and install 2.7(with option `make && make altinstall`) but when I tried install something with yum didn't work.
So I solved this issue as follow:
1. `# ln -s /usr/local/bin/python /usr/bin/python`
2. Download the RPM package python-2.6.6-36.el6.i686.rpm from <http:/... |
1,465,036 | I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred ... | 2009/09/23 | [
"https://Stackoverflow.com/questions/1465036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/168500/"
] | No need to do yum or make your own RPM. Build `python26` from source.
```
wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -zxvf Python-2.6.6.tgz
cd Python-2.6.6
./configure && make && make install
```
There can be a **dependency error** use
```
yum install gcc cc
```
Add the install path (`/usr... | ```
rpm -Uvh http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
rpm -Uvh ftp://ftp.pbone.net/mirror/centos.karan.org/el5/extras/testing/i386/RPMS/libffi-3.0.5-1.el5.kb.i386.rpm
yum install python26
python26
```
for dos that just dont know :=) |
71,036,475 | There
<https://www.amazon.de/sp?marketplaceID=A1PA6795UKMFR9&seller=A135E02VGPPVQ&isAmazonFulfilled=1&ref=dp_merchant_link>
I just can access on browser as well, but python requests returns 404 error status.
Until yesterday, this page worked as well with python requests. but from today, it does not work for me and i... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71036475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | It works just fine to me. Maybe you can try changing your user agent.
```
import requests
from fake_useragent import UserAgent # fake user agent library
# random user-agent
ua = UserAgent()
user_agent = ua.random
headers = {
'Connection': 'keep-alive',
'rtt': '300',
'downlink': '0.4',
'ect': '3g',
... | I suggest you add a **referer url in header** and generally I don't think Amazon allow scraping but use selenium if you want to scrape it easily (sure it may be overkill) but has more customization |
67,464,761 | I am using python flask framework to develop Apis. I am planning to use mongodb as backend database. How can I connect mongodb database to python? Is there any in built in library? | 2021/05/10 | [
"https://Stackoverflow.com/questions/67464761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15882833/"
] | You almost there. It is better to keep control over appearance/disappearance inside menu view. Find below fixed parts, places are highlighted with comments in code.
Tested with Xcode 12.5 / iOS 14.5
*Note: demo prepared with turned on "Simulator > Debug > Slow Animations" for better visibility*
[
Declare ContentView and MenuView in SceneDelegate:
```
import KYDrawerController
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
let drawerController = KYDrawerController(drawerDir... |
12,816,464 | I am using web.py framework to create a simple web application
I want to create a radio button so I wrote the following code
```
from web import form
from web.contrib.auth import DBAuth
import MySQLdb as mdb
render = web.template.render('templates/')
urls = (
'/project_details', 'Project_Details',
)
class Pro... | 2012/10/10 | [
"https://Stackoverflow.com/questions/12816464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | Looking at the [source](https://github.com/webpy/webpy/blob/master/web/form.py#L291), it looks like you have to use one `Radio` constructor for all of your items as the same `Radio` object will actually generate multiple `<input>` elements.
Try something like::
```
project_details = form.Form(
form.Radio('detail... | Here's what I was able to decipher. checked='checked' seems to select a random (last?) item in the list. Without a default selection, my testing was coming back with a NoneType, if none of the radio-buttons got selected.
```
project_details = form.Form(
form.Radio('selections', ['Home Page', 'Content', 'Contact Us',... |
30,226,891 | I am new at both, python and stackoverflow, so please have that on mind. I tried to do this myself and manage to do it, but it works only if i hardcode hash number of previous version like this one in hash1, and then compare with hash number of currently version. I wolud like that program every time save hash number of... | 2015/05/13 | [
"https://Stackoverflow.com/questions/30226891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4897764/"
] | Just simply save the hash to a file like file.txt and then when you need to compare a hash just read from your file.txt and compare the two strings.
Here is an example of how to read and write to files in python.
<http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python> | For relatively simple comparisons, use [filecmp](https://docs.python.org/2/library/filecmp.html). For finer control and feedback, use [difflib](https://docs.python.org/2/library/difflib.html#module-difflib), which is similar to the \*nix utility, `diff`. |
62,776,024 | I simply want to reorder the rows of my pandas dataframe such that `col1` matches the order of the external list elements in `my_order`.
```
d = {'col1': ['A', 'B', 'C'], 'col2': [1,2,3]}
df = pd.DataFrame(data=d)
my_order = ['B', 'C', 'A']
```
This post [sorting by a custom list in pandas](https://stackoverflow.com... | 2020/07/07 | [
"https://Stackoverflow.com/questions/62776024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7273115/"
] | ```
{{ json.Date.strftime('%Y-%m-%d') }}
``` | strftime converts a date object into a string by specifying a format you want to use
you can do
```
now = datetime.now() # <- datetime object
now_string = now.strftime('%d.%m.%Y')
```
however, if you already converted your datetime object into a string (or getting strings from an api or something), you can convert ... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | You can use,
```
sh.Range(sh.Cells(1,1),sh.Cells(20000,1)).EntireRow.Delete()
```
will delete rows 1 to 20,000 in an open Excel spreadsheet so,
```
if sh.Cells(1,1).Value == 'X':
sh.Cells(1,1).EntireRow.Delete()
``` | I have achieved this using Pandas package....
```
import pandas as pd
#Read from Excel
xl= pd.ExcelFile("test.xls")
#Parsing Excel Sheet to DataFrame
dfs = xl.parse(xl.sheet_names[0])
#Update DataFrame as per requirement
#(Here Removing the row from DataFrame having blank value in "Name" column)
dfs = dfs[dfs['Nam... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | Don't delete. Just copy what you need.
1. read the original file
2. open a new file
3. iterate over rows of the original file (if the first column of the row does not contain the value X, add this row to the new file)
4. close both files
5. rename the new file into the original file | I have achieved this using Pandas package....
```
import pandas as pd
#Read from Excel
xl= pd.ExcelFile("test.xls")
#Parsing Excel Sheet to DataFrame
dfs = xl.parse(xl.sheet_names[0])
#Update DataFrame as per requirement
#(Here Removing the row from DataFrame having blank value in "Name" column)
dfs = dfs[dfs['Nam... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | You can try using the csv reader:
<http://docs.python.org/library/csv.html> | I have achieved this using Pandas package....
```
import pandas as pd
#Read from Excel
xl= pd.ExcelFile("test.xls")
#Parsing Excel Sheet to DataFrame
dfs = xl.parse(xl.sheet_names[0])
#Update DataFrame as per requirement
#(Here Removing the row from DataFrame having blank value in "Name" column)
dfs = dfs[dfs['Nam... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | Don't delete. Just copy what you need.
1. read the original file
2. open a new file
3. iterate over rows of the original file (if the first column of the row does not contain the value X, add this row to the new file)
4. close both files
5. rename the new file into the original file | You can use,
```
sh.Range(sh.Cells(1,1),sh.Cells(20000,1)).EntireRow.Delete()
```
will delete rows 1 to 20,000 in an open Excel spreadsheet so,
```
if sh.Cells(1,1).Value == 'X':
sh.Cells(1,1).EntireRow.Delete()
``` |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | You can try using the csv reader:
<http://docs.python.org/library/csv.html> | If you just need to delete the data (rather than 'getting rid of' the row, i.e. it shifts rows) you can try using my module, PyWorkbooks. You can get the most recent version here:
<https://sourceforge.net/projects/pyworkbooks/>
There is a pdf tutorial to guide you through how to use it. Happy coding! |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | If you just need to delete the data (rather than 'getting rid of' the row, i.e. it shifts rows) you can try using my module, PyWorkbooks. You can get the most recent version here:
<https://sourceforge.net/projects/pyworkbooks/>
There is a pdf tutorial to guide you through how to use it. Happy coding! | I have achieved this using Pandas package....
```
import pandas as pd
#Read from Excel
xl= pd.ExcelFile("test.xls")
#Parsing Excel Sheet to DataFrame
dfs = xl.parse(xl.sheet_names[0])
#Update DataFrame as per requirement
#(Here Removing the row from DataFrame having blank value in "Name" column)
dfs = dfs[dfs['Nam... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | You can try using the csv reader:
<http://docs.python.org/library/csv.html> | You can use,
```
sh.Range(sh.Cells(1,1),sh.Cells(20000,1)).EntireRow.Delete()
```
will delete rows 1 to 20,000 in an open Excel spreadsheet so,
```
if sh.Cells(1,1).Value == 'X':
sh.Cells(1,1).EntireRow.Delete()
``` |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | Don't delete. Just copy what you need.
1. read the original file
2. open a new file
3. iterate over rows of the original file (if the first column of the row does not contain the value X, add this row to the new file)
4. close both files
5. rename the new file into the original file | I like using COM objects for this kind of fun:
```
import win32com.client
from win32com.client import constants
f = r"h:\Python\Examples\test.xls"
DELETE_THIS = "X"
exc = win32com.client.gencache.EnsureDispatch("Excel.Application")
exc.Visible = 1
exc.Workbooks.Open(Filename=f)
row = 1
while True:
exc.Range("B%... |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | You can use,
```
sh.Range(sh.Cells(1,1),sh.Cells(20000,1)).EntireRow.Delete()
```
will delete rows 1 to 20,000 in an open Excel spreadsheet so,
```
if sh.Cells(1,1).Value == 'X':
sh.Cells(1,1).EntireRow.Delete()
``` | If you just need to delete the data (rather than 'getting rid of' the row, i.e. it shifts rows) you can try using my module, PyWorkbooks. You can get the most recent version here:
<https://sourceforge.net/projects/pyworkbooks/>
There is a pdf tutorial to guide you through how to use it. Happy coding! |
5,635,054 | I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won't let me delete such a complex range when using a filter. The condition is:
**If the first column contains the value, X, then I need to be able to delete the entire row.**
I'm trying to auto... | 2011/04/12 | [
"https://Stackoverflow.com/questions/5635054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/704039/"
] | Don't delete. Just copy what you need.
1. read the original file
2. open a new file
3. iterate over rows of the original file (if the first column of the row does not contain the value X, add this row to the new file)
4. close both files
5. rename the new file into the original file | If you just need to delete the data (rather than 'getting rid of' the row, i.e. it shifts rows) you can try using my module, PyWorkbooks. You can get the most recent version here:
<https://sourceforge.net/projects/pyworkbooks/>
There is a pdf tutorial to guide you through how to use it. Happy coding! |
74,245,242 | I want to perform the selection of a group of lines in a text file to get all jobs related to an ipref
The test file is like this :
job numbers : (1,2,3), ip ref : (10,12,10)
text file :
1
... (several lines of text)
xxx 10
2
... (several lines of text)
xxx 12
3
... (several lines of text)
xxx 10
i want to select job... | 2022/10/29 | [
"https://Stackoverflow.com/questions/74245242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20365230/"
] | You can write the pattern in this way, repeating the newline and asserting not xxx followed by 1 or more digits:
```
^\d(?:\n(?!xxx \d+$).*)*\nxxx 10$
```
The pattern matches:
* `^` Start of string
* `\d` Match a single digit (or `\d+` for 1 or more)
* `(?:` Non capture group
+ `\n` Match a newline
+ `(?!xxx \d+$... | Good day to you :) and Thank you very much for your quick response!!
i give you below the result
Note : i have modified re.DOTALL by re.DOTALL|re.MULTILINE (because the result is none without that... Sorry for the previous presentation ... it wat not very clear)
Text file :
```
1
a
b
xxx 10
1
a
b
xxx 12
1
a
b
xxx 10
... |
74,245,242 | I want to perform the selection of a group of lines in a text file to get all jobs related to an ipref
The test file is like this :
job numbers : (1,2,3), ip ref : (10,12,10)
text file :
1
... (several lines of text)
xxx 10
2
... (several lines of text)
xxx 12
3
... (several lines of text)
xxx 10
i want to select job... | 2022/10/29 | [
"https://Stackoverflow.com/questions/74245242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20365230/"
] | You can write the pattern in this way, repeating the newline and asserting not xxx followed by 1 or more digits:
```
^\d(?:\n(?!xxx \d+$).*)*\nxxx 10$
```
The pattern matches:
* `^` Start of string
* `\d` Match a single digit (or `\d+` for 1 or more)
* `(?:` Non capture group
+ `\n` Match a newline
+ `(?!xxx \d+$... | Thank you very much, (you saved my day !!)
as you say :
```
pattern='^\d(?:\n(?!xxx \d+$).*)*\nxxx 10$'
result= re.findall(pattern,texte, re.MULTILINE)
```
result : OK, the line group (1..xxx 12) is ignored,
NOTE : i can adapt it to a case where line 1 is a line giving job information and "xxx 12" is a line giving p... |
74,245,242 | I want to perform the selection of a group of lines in a text file to get all jobs related to an ipref
The test file is like this :
job numbers : (1,2,3), ip ref : (10,12,10)
text file :
1
... (several lines of text)
xxx 10
2
... (several lines of text)
xxx 12
3
... (several lines of text)
xxx 10
i want to select job... | 2022/10/29 | [
"https://Stackoverflow.com/questions/74245242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20365230/"
] | You can write the pattern in this way, repeating the newline and asserting not xxx followed by 1 or more digits:
```
^\d(?:\n(?!xxx \d+$).*)*\nxxx 10$
```
The pattern matches:
* `^` Start of string
* `\d` Match a single digit (or `\d+` for 1 or more)
* `(?:` Non capture group
+ `\n` Match a newline
+ `(?!xxx \d+$... | file :
```
job_number job_id
1 10202
bla bla
bla bla bla
xxx 100.10.10.100
2 10203
bla bla
bla bla bla
bla bla bla
xxx 100.10.10.102
3 10204
bla bla bla
bla bla bla
xxx 100.10.10.100
```
bash script with embedded python script :
```
#!/bin/bash
# function , $1 : ip of a printer
get_jobs_ip ()
{
cat <<EOF | python
... |
74,245,242 | I want to perform the selection of a group of lines in a text file to get all jobs related to an ipref
The test file is like this :
job numbers : (1,2,3), ip ref : (10,12,10)
text file :
1
... (several lines of text)
xxx 10
2
... (several lines of text)
xxx 12
3
... (several lines of text)
xxx 10
i want to select job... | 2022/10/29 | [
"https://Stackoverflow.com/questions/74245242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20365230/"
] | Good day to you :) and Thank you very much for your quick response!!
i give you below the result
Note : i have modified re.DOTALL by re.DOTALL|re.MULTILINE (because the result is none without that... Sorry for the previous presentation ... it wat not very clear)
Text file :
```
1
a
b
xxx 10
1
a
b
xxx 12
1
a
b
xxx 10
... | Thank you very much, (you saved my day !!)
as you say :
```
pattern='^\d(?:\n(?!xxx \d+$).*)*\nxxx 10$'
result= re.findall(pattern,texte, re.MULTILINE)
```
result : OK, the line group (1..xxx 12) is ignored,
NOTE : i can adapt it to a case where line 1 is a line giving job information and "xxx 12" is a line giving p... |
74,245,242 | I want to perform the selection of a group of lines in a text file to get all jobs related to an ipref
The test file is like this :
job numbers : (1,2,3), ip ref : (10,12,10)
text file :
1
... (several lines of text)
xxx 10
2
... (several lines of text)
xxx 12
3
... (several lines of text)
xxx 10
i want to select job... | 2022/10/29 | [
"https://Stackoverflow.com/questions/74245242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20365230/"
] | Good day to you :) and Thank you very much for your quick response!!
i give you below the result
Note : i have modified re.DOTALL by re.DOTALL|re.MULTILINE (because the result is none without that... Sorry for the previous presentation ... it wat not very clear)
Text file :
```
1
a
b
xxx 10
1
a
b
xxx 12
1
a
b
xxx 10
... | file :
```
job_number job_id
1 10202
bla bla
bla bla bla
xxx 100.10.10.100
2 10203
bla bla
bla bla bla
bla bla bla
xxx 100.10.10.102
3 10204
bla bla bla
bla bla bla
xxx 100.10.10.100
```
bash script with embedded python script :
```
#!/bin/bash
# function , $1 : ip of a printer
get_jobs_ip ()
{
cat <<EOF | python
... |
24,309,586 | This is similar to this [question](https://stackoverflow.com/questions/20403387/how-to-remove-a-package-from-pypi) with one exception. I want to remove a few specific versions of the package from our local pypi index, which I had uploaded with the following command in the past.
```
python setup.py sdist upload -r <ind... | 2014/06/19 | [
"https://Stackoverflow.com/questions/24309586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/251096/"
] | Removing packages from local pypi index **depends on type of pypi index you use**.
removing package from `devpi` index
===================================
`devpi` allows [removing packages](http://doc.devpi.net/latest/userman/devpi_packages.html#removing-a-release-file-or-project) only from so called volatile indexes... | I'm using [pypiserver](https://pypi.org/project/pypiserver/) and had to remove a bad package so I just SSH'd in and removed the bad packages and restarted the service.
The commands were roughly:
```
ssh root@pypiserver
cd ~pypiserver/pypiserver/packages
rm bad-package*
systemctl restart pypiserver.service
```
That ... |
24,309,586 | This is similar to this [question](https://stackoverflow.com/questions/20403387/how-to-remove-a-package-from-pypi) with one exception. I want to remove a few specific versions of the package from our local pypi index, which I had uploaded with the following command in the past.
```
python setup.py sdist upload -r <ind... | 2014/06/19 | [
"https://Stackoverflow.com/questions/24309586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/251096/"
] | As an addenum from @jan-vlcinsky's answer
Removing from [`pypiserver`](https://github.com/pypiserver/pypiserver)
======================================================================
Using `curl` for instance:
```
curl --form ":action=remove_pkg" --form "name=<package_name>" --form "version=<version>" <pypiserver_u... | I'm using [pypiserver](https://pypi.org/project/pypiserver/) and had to remove a bad package so I just SSH'd in and removed the bad packages and restarted the service.
The commands were roughly:
```
ssh root@pypiserver
cd ~pypiserver/pypiserver/packages
rm bad-package*
systemctl restart pypiserver.service
```
That ... |
17,321,910 | I have a file with a correspondence key -> value:
```
sort keyFile.txt | head
ENSMUSG00000000001 ENSMUSG00000000001_Gnai3
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17321910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274242/"
] | Use awk command like this:
```
awk 'NR==FNR {a[$1]=$2;next} {
split($1, b, ":");
if (b[1] in a)
print a[b[1]] ":" b[2], $2;
else
print $0;
}' keyFile.txt temp.txt
``` | Another awk option
```
awk -F: 'NR == FNR{split($0, a, " "); x[a[1]]=a[2]; next}{print x[$1]":"$2}' keyFile.txt temp.txt
``` |
17,321,910 | I have a file with a correspondence key -> value:
```
sort keyFile.txt | head
ENSMUSG00000000001 ENSMUSG00000000001_Gnai3
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17321910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274242/"
] | Use awk command like this:
```
awk 'NR==FNR {a[$1]=$2;next} {
split($1, b, ":");
if (b[1] in a)
print a[b[1]] ":" b[2], $2;
else
print $0;
}' keyFile.txt temp.txt
``` | Another `awk` version:
```
awk 'NR==FNR{a[$1]=$2;next}
{sub(/[^:]+/,a[substr($1,1,index($1,":")-1)])}1' keyFile.txt temp.txt
``` |
17,321,910 | I have a file with a correspondence key -> value:
```
sort keyFile.txt | head
ENSMUSG00000000001 ENSMUSG00000000001_Gnai3
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17321910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274242/"
] | Use awk command like this:
```
awk 'NR==FNR {a[$1]=$2;next} {
split($1, b, ":");
if (b[1] in a)
print a[b[1]] ":" b[2], $2;
else
print $0;
}' keyFile.txt temp.txt
``` | Code for GNU [sed](/questions/tagged/sed "show questions tagged 'sed'"):
```
$sed -nr '$!N;/^(.*)\n\1$/!bk;D;:k;s#\S+\s+(\w+)_(\w+)#/^\1/s/(\\w+)(:\\w+)\\s+(\\w+)/\\1_\2\\2 \\3/p#;P;s/^(.*)\n//' keyfile.txt|sed -nrf - temp.txt
ENSMUSG00000000001_Gnai3:001 515
ENSMUSG00000000001_Gnai3:002 108
ENSMUSG00000000001_Gnai3:... |
17,321,910 | I have a file with a correspondence key -> value:
```
sort keyFile.txt | head
ENSMUSG00000000001 ENSMUSG00000000001_Gnai3
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17321910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274242/"
] | Another awk option
```
awk -F: 'NR == FNR{split($0, a, " "); x[a[1]]=a[2]; next}{print x[$1]":"$2}' keyFile.txt temp.txt
``` | Another `awk` version:
```
awk 'NR==FNR{a[$1]=$2;next}
{sub(/[^:]+/,a[substr($1,1,index($1,":")-1)])}1' keyFile.txt temp.txt
``` |
17,321,910 | I have a file with a correspondence key -> value:
```
sort keyFile.txt | head
ENSMUSG00000000001 ENSMUSG00000000001_Gnai3
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000003 ENSMUSG00000000003_Pbsn
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028 ENSMUSG00000000028_Cdc45
ENSMUSG00000000028... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17321910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1274242/"
] | Code for GNU [sed](/questions/tagged/sed "show questions tagged 'sed'"):
```
$sed -nr '$!N;/^(.*)\n\1$/!bk;D;:k;s#\S+\s+(\w+)_(\w+)#/^\1/s/(\\w+)(:\\w+)\\s+(\\w+)/\\1_\2\\2 \\3/p#;P;s/^(.*)\n//' keyfile.txt|sed -nrf - temp.txt
ENSMUSG00000000001_Gnai3:001 515
ENSMUSG00000000001_Gnai3:002 108
ENSMUSG00000000001_Gnai3:... | Another `awk` version:
```
awk 'NR==FNR{a[$1]=$2;next}
{sub(/[^:]+/,a[substr($1,1,index($1,":")-1)])}1' keyFile.txt temp.txt
``` |
34,994,130 | Looking through several projects recently, I noticed some of them use `platforms` argument to `setup()` in `setup.py`, though with only one value of `any`, i.e.
```
#setup.py file in project's package folder
...
setup(
...,
platforms=['any'],
...
)
```
OR
```
#setup.py file in project's packag... | 2016/01/25 | [
"https://Stackoverflow.com/questions/34994130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5738152/"
] | `platforms` is an argument the `setuptools` package inherits from `distutils`; see the [*Additional meta-data* section](https://docs.python.org/2/distutils/setupscript.html#additional-meta-data) in the `distutils` documentation:
>
> *Meta-Data*: `platforms`
>
> *Description*: a list of platforms
>
> *Value*: li... | Just an update to provide more information for anyone interested.
I found an accurate description of `platforms` in a [PEP](https://www.python.org/dev/peps/pep-0345/#platform-multiple-use).
So, "*There's a PEP for that!*":
[PEP-0345](https://www.python.org/dev/peps/pep-0345/) lists all possible arguments to `setup... |
48,465,325 | I am trying to build my container image using docker\_image module of Ansible.
**My host machine details:**
```
OS: Lubuntu 17.10
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/myuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python modu... | 2018/01/26 | [
"https://Stackoverflow.com/questions/48465325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3592502/"
] | Your client (presumably) would not have Sequelize installed and cannot pass a Sequelize operator via JSON, so what you are trying to do is not exactly possible. You would probably to get the client to send string (e.g. `or`, `and` and then you would have to map those string to Sequelize operators) [1].
```
"filters":... | In the end I found out from the sequelize slack group that the old operator method is still in the codebase. I don't know how long it will stay, but since it is the only way of sending via json, it may well stay.
So the way it works is that rather than using [Op.or] you can use $or.
Example:
```
"filters": {"week": ... |
48,465,325 | I am trying to build my container image using docker\_image module of Ansible.
**My host machine details:**
```
OS: Lubuntu 17.10
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/myuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python modu... | 2018/01/26 | [
"https://Stackoverflow.com/questions/48465325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3592502/"
] | Here's an implementation of mcranston18's answer that runs:
```
const Op = this.Sequelize.Op;
this.operatorsMap = { // Add additional operators as needed.
$ne: Op.ne,
};
replaceOperators(oldObject) {
let newObject = {};
for (let key in oldObject) {
let value = oldObject[key];
if (typeof va... | In the end I found out from the sequelize slack group that the old operator method is still in the codebase. I don't know how long it will stay, but since it is the only way of sending via json, it may well stay.
So the way it works is that rather than using [Op.or] you can use $or.
Example:
```
"filters": {"week": ... |
65,363,105 | I am using making use of some user\_types in my application which are is\_admin and is\_landlord. I want it that whenever a user is created using the `python manage.py createsuperuser`. he is automatically assigned is\_admin.
models.py
```
class UserManager(BaseUserManager):
def _create_user(self, email, passwor... | 2020/12/18 | [
"https://Stackoverflow.com/questions/65363105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14434294/"
] | You can automatically construct a `user_type` model in the `create_superuser` function:
```
class UserManager(BaseUserManager):
# …
def create_superuser(self, email, password, **extra_fields):
user = self._create_user(email, password, True, True, **extra_fields)
user.save(using=self._db)
... | So I have tried a method that works not so efficiently but manageably.
What I do is a simple trick.
views.py
```
def Dashboard(request, pk):
user = User.objects.get(id=request.user.pk)
landlord = user.is_staff & user.is_active
if not landlord:
reservations = Tables.objects.all()
... |
68,286,395 | I am trying to create a Toplevel window, however, this Toplevel is called from a different file in the same directory within a function.
Apologies I am by no means a tkinter or python guru. Here are the two parts of the code. (snippets)
#File 1 (Main)
```
import tkinter as tk
from tkinter import *
import comm1
from ... | 2021/07/07 | [
"https://Stackoverflow.com/questions/68286395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11911902/"
] | No, don't make it `static`. If you want you can make it an instance field, but making it a class field is not optimal. E.g. see the note on thread-safety on the `Random` class that it has been derived from:
>
> Instances of `java.util.Random` are threadsafe. However, the concurrent use of the same `java.util.Random` ... | I totally agree with Maartens's answer. However one can notice that java.util classes create statics for SecureRandom themselfes.
```
public final class UUID implements java.io.Serializable, Comparable<UUID> {
...
/*
* The random number generator used by this class to create random
* based UUIDs. I... |
63,306,561 | File/Directory Structure:
```
main/home/script.py
main/home/a/.init
main/home/b/.init
```
I want to setup my `gitignore` to exclude everything in the home directory but to include specific file types.
What i tried:
```
home/* #exclude everything in the home directory and subdirectories
!home/*.py #include py... | 2020/08/07 | [
"https://Stackoverflow.com/questions/63306561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If you want to create, e.g., `home/foo/.init` and have this file be put into Git's *index* (for more about the index, see below), you will need to tell Git *not* to cut off searches into the `home/*/` directories:
```
!home/*/
```
Then, as [Fady Adal noted](https://stackoverflow.com/a/63306691/1256452) (but I've adj... | It should be
```
home/* #exclude everything in the home directory and subdirectories
!home/*.py #include python files immediately in the home directory
!**/*.init #include .init files in all directories and subdirectories.
``` |
58,187,677 | i've worked with tensorflow for a while and everything worked properly until i tried to switch to the gpu version.
Uninstalled previous tensorflow,
pip installed tensorflow-gpu (v2.0)
downloaded and installed visual studio community 2019
downloaded and installed CUDA 10.1
downloaded and installed cuDNN
tested with ... | 2019/10/01 | [
"https://Stackoverflow.com/questions/58187677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149136/"
] | SOLVED, it's mostly an alchemy of versions to avoid conflicts.
Here's what i've done (order matters as far as i know)
1. uninstall everything (tf, cuda, visual studio)
2. pip install tensorflow-gpu
3. download and install visual studio community 2017 (2019 won't work)
4. I also have installed the c++ workload from vis... | tensorflow-gpu v2.0.0 is [now available on conda](https://anaconda.org/anaconda/tensorflow-gpu), and is very easy to install with:
`conda install -c anaconda tensorflow-gpu`. No additional downloads or cuda installs required. |
58,187,677 | i've worked with tensorflow for a while and everything worked properly until i tried to switch to the gpu version.
Uninstalled previous tensorflow,
pip installed tensorflow-gpu (v2.0)
downloaded and installed visual studio community 2019
downloaded and installed CUDA 10.1
downloaded and installed cuDNN
tested with ... | 2019/10/01 | [
"https://Stackoverflow.com/questions/58187677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149136/"
] | SOLVED, it's mostly an alchemy of versions to avoid conflicts.
Here's what i've done (order matters as far as i know)
1. uninstall everything (tf, cuda, visual studio)
2. pip install tensorflow-gpu
3. download and install visual studio community 2017 (2019 won't work)
4. I also have installed the c++ workload from vis... | i had similar problems.
combined with the fact that i am using windows 8 and pycharm. BUt i figured it out eventually using [this post.](https://stackoverflow.com/questions/50622525/which-tensorflow-and-cuda-version-combinations-are-compatible)
the combination that worked:
* Cuda 10
* CuDNN 7.6 for windows7
* Tensor... |
58,187,677 | i've worked with tensorflow for a while and everything worked properly until i tried to switch to the gpu version.
Uninstalled previous tensorflow,
pip installed tensorflow-gpu (v2.0)
downloaded and installed visual studio community 2019
downloaded and installed CUDA 10.1
downloaded and installed cuDNN
tested with ... | 2019/10/01 | [
"https://Stackoverflow.com/questions/58187677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149136/"
] | tensorflow-gpu v2.0.0 is [now available on conda](https://anaconda.org/anaconda/tensorflow-gpu), and is very easy to install with:
`conda install -c anaconda tensorflow-gpu`. No additional downloads or cuda installs required. | i had similar problems.
combined with the fact that i am using windows 8 and pycharm. BUt i figured it out eventually using [this post.](https://stackoverflow.com/questions/50622525/which-tensorflow-and-cuda-version-combinations-are-compatible)
the combination that worked:
* Cuda 10
* CuDNN 7.6 for windows7
* Tensor... |
63,887,379 | I'm using **Visual Studio Code** with **Cloud Code** extension. When I try to "**Deploy to Cloud Run**", I'm having this error:
>
> Automatic image build detection failed. Error: Component map not
> found. Consider adding a Dockerfile to the workspace and try again.
>
>
>
But I already have a Dockerfile:
```
# P... | 2020/09/14 | [
"https://Stackoverflow.com/questions/63887379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5411494/"
] | I wasn't able to repro the issue, but I checked in with the Cloud Code team and it sounds like there could have been an underlying issue with gcloud that wasn't your fault.
I don't think you'll see this error again, but if you do, it would be awesome if you could file an issue at the [Cloud Code VS Code repo](https://... | I don't know why, but after connecting in a different network and running the commands below, the error is gone.
```
gcloud auth revoke
gcloud auth login
gcloud init
``` |
63,544,127 | I'm occasionally learning Java. As a person from python background, I'd like to know whether there exists something like `sorted(iterable, key=function)` of python in java.
For exmaple, in python I can sort a list ordered by an element's specific character, such as
```
>>> a_list = ['bob', 'kate', 'jaguar', 'mazda', ... | 2020/08/23 | [
"https://Stackoverflow.com/questions/63544127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11790764/"
] | Use a custom comparator to compare two strings.
```
Arrays.sort(a_list, Comparator.comparing(s -> s.charAt(1)));
```
This compares two strings by the string's second character.
This will result in
```
[kate, jaguar, mazda, civic, bob, honda, grasshopper]
```
I see that `jaguar` and `kate` are switched in your ou... | You can supply a lambda function to [`Arrays.sort`](https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort(T%5B%5D,%20java.util.Comparator)). For your example, you could use:
```
Arrays.sort(a_list, (String a, String b) -> a.charAt(1) - b.charAt(1));
```
Assuming you have first sorted the array alphabe... |
63,544,127 | I'm occasionally learning Java. As a person from python background, I'd like to know whether there exists something like `sorted(iterable, key=function)` of python in java.
For exmaple, in python I can sort a list ordered by an element's specific character, such as
```
>>> a_list = ['bob', 'kate', 'jaguar', 'mazda', ... | 2020/08/23 | [
"https://Stackoverflow.com/questions/63544127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11790764/"
] | You can use `Comparator.comparing` to sort the list
```
Arrays.sort(a_list, Comparator.comparing(e -> e.charAt(1)));
```
And if you want to sort and collect in the new list using Java Stream API
```
String [] listSorted = Arrays.stream(a_list)
.sorted(Comparator.comparing(s -> s.charA... | You can supply a lambda function to [`Arrays.sort`](https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort(T%5B%5D,%20java.util.Comparator)). For your example, you could use:
```
Arrays.sort(a_list, (String a, String b) -> a.charAt(1) - b.charAt(1));
```
Assuming you have first sorted the array alphabe... |
33,241,842 | I'm using TextBlob for python to do some sentiment analysis on tweets. The default analyzer in TextBlob is the PatternAnalyzer which works resonably well and is appreciably fast.
```
sent = TextBlob(tweet.decode('utf-8')).sentiment
```
I have now tried to switch to the NaiveBayesAnalyzer and found the runtime to be ... | 2015/10/20 | [
"https://Stackoverflow.com/questions/33241842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3174668/"
] | Yes, Textblob will train the analyzer before each run. You can use following code to avoid train the analyzer everytime.
```
from textblob import Blobber
from textblob.sentiments import NaiveBayesAnalyzer
tb = Blobber(analyzer=NaiveBayesAnalyzer())
print tb("sentence you want to test")
``` | Adding to Alan's very useful answer if you have table data in a dataframe and want to use textblob's NaiveBayesAnalyzer then this works. Just change out `word_list` for your relevant series of strings.
```
import textblob
import pandas as pd
tb = textblob.Blobber(analyzer=NaiveBayesAnalyzer())
for index, row in df.it... |
33,241,842 | I'm using TextBlob for python to do some sentiment analysis on tweets. The default analyzer in TextBlob is the PatternAnalyzer which works resonably well and is appreciably fast.
```
sent = TextBlob(tweet.decode('utf-8')).sentiment
```
I have now tried to switch to the NaiveBayesAnalyzer and found the runtime to be ... | 2015/10/20 | [
"https://Stackoverflow.com/questions/33241842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3174668/"
] | Yes, Textblob will train the analyzer before each run. You can use following code to avoid train the analyzer everytime.
```
from textblob import Blobber
from textblob.sentiments import NaiveBayesAnalyzer
tb = Blobber(analyzer=NaiveBayesAnalyzer())
print tb("sentence you want to test")
``` | In Addition to the above solutions, I tried the above solutions and I faced errors, so if someone found this question, I solved the errors as well as tried using PatternAnalyzer the in below code:
```
from textblob import Blobber
from textblob.sentiments import NaiveBayesAnalyzer, PatternAnalyzer
import nltk
nltk.down... |
68,441,299 | I'm trying to get the number of commits of github repos using python and beautiful soup
html code:
```
<div class="flex-shrink-0">
<h2 class="sr-only">Git stats</h2>
<ul class="list-style-none d-flex">
<li class="ml-0 ml-md-3">
<a data-pjax href="..." class="pl-3 pr-3 py-3 p-md-0... | 2021/07/19 | [
"https://Stackoverflow.com/questions/68441299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
from bs4 import BeautifulSoup as bs
html="""<span class="d-none d-sm-inline">
<strong>26</strong>
<span aria-label="Commits on master" class="color-text-secondary d-none d-lg-inline">
commits
</span>
</span>
... | You can use the [`find_next()`](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-all-next-and-find-next) method to look for a `<strong>` after the class `d-none d-sm-inline`.
In your case:
```
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
for tag in soup.find_all("span", class_=... |
68,441,299 | I'm trying to get the number of commits of github repos using python and beautiful soup
html code:
```
<div class="flex-shrink-0">
<h2 class="sr-only">Git stats</h2>
<ul class="list-style-none d-flex">
<li class="ml-0 ml-md-3">
<a data-pjax href="..." class="pl-3 pr-3 py-3 p-md-0... | 2021/07/19 | [
"https://Stackoverflow.com/questions/68441299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Here's an approach using [list commits](https://docs.github.com/en/rest/reference/repos#list-commits) from GitHub's REST API
```
import requests
user = ... # username or organisation
repo = ... # repository name
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/commits")
if response.ok:
ncommi... | You can use the [`find_next()`](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-all-next-and-find-next) method to look for a `<strong>` after the class `d-none d-sm-inline`.
In your case:
```
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
for tag in soup.find_all("span", class_=... |
23,184,410 | I have jobs scheduled thru `apscheduler`. I have 3 jobs so far, but soon will have many more. i'm looking for a way to scale my code.
Currently, each job is its own `.py` file, and in the file, I have turned the script into a function with `run()` as the function name. Here is my code.
```
from apscheduler.scheduler... | 2014/04/20 | [
"https://Stackoverflow.com/questions/23184410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1744744/"
] | ```
import urllib
import threading
import datetime
pages = ['http://google.com', 'http://yahoo.com', 'http://msn.com']
#------------------------------------------------------------------------------
# Getting the pages WITHOUT threads
#------------------------------------------------------------------------------
def... | Look @
<http://furius.ca/pubcode/pub/conf/bin/python-recursive-import-test>
This will help you import all python / .py files.
while importing you can create a list which keeps keeps a function call, for example.
[job1.run(),job2.run()]
Then iterate through them and call function :)
Thanks Arjun |
29,413,719 | When I input the variable a
```
a = int(1388620800)*1000
```
(of course) this variable is returned
```
1388620800000
```
But in the Google Appengine Server, this variable is changed by <https://cloud.google.com/appengine/docs/python/datastore/typesandpropertyclasses#int>
```
1388620800000L
```
How to convert 1... | 2015/04/02 | [
"https://Stackoverflow.com/questions/29413719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1474183/"
] | Maven has a [standard directory layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html). The directory `src/main/resources` is intended for such application resources. Place your text files into it.
You now basically have two options where exactly to place your files:
... | I tried to reproduce your problem given the MWE you provided, but did not succeed. I uploaded my project including a pom.xml (you mentioned you used maven) here: <http://www.filedropper.com/stackoverflow>
This is what my lookup class looks like (also showing how to use the getResourceAsStream method):
```
public class... |
74,127,611 | I am unsure if this is one of those problems that is impossible or not, in my mind it seems like it should be possible. ***Edit** - We more or less agree it is impossible*
Given a range specified by two integers (i.e. `n1 ... n2`), is it possible to create a python generator that yields a random integer from the range... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74127611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8627756/"
] | As I stated in the comment above, what you are seeking is some of the facilities of reactive programming paradigm. (not to be confounded with the JavaScript library which borrows its name from there).
It is possible to instrument objects in Python to do so - I think the minimum setup here would be a specialized target... | You can try using lambdas and calling the value on return. Like this:
```
FOO = {'foo': 1}
BAR = {'test': lambda: FOO['foo'] }
FOO['foo'] = 2
print(BAR['test']()) # Outputs 2
``` |
74,127,611 | I am unsure if this is one of those problems that is impossible or not, in my mind it seems like it should be possible. ***Edit** - We more or less agree it is impossible*
Given a range specified by two integers (i.e. `n1 ... n2`), is it possible to create a python generator that yields a random integer from the range... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74127611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8627756/"
] | As I stated in the comment above, what you are seeking is some of the facilities of reactive programming paradigm. (not to be confounded with the JavaScript library which borrows its name from there).
It is possible to instrument objects in Python to do so - I think the minimum setup here would be a specialized target... | If you're only one level deep, you may wish to try [`ChainMap`](https://docs.python.org/3/library/collections.html#collections.ChainMap), E.g.,
```py
>>> from collections import ChainMap
>>> defaults = {'foo': 42}
>>> myvalues = {}
>>> result = ChainMap(myvalues, defaults)
>>> result['foo']
42
>>> defaults['foo'] = 99... |
48,903,304 | I am naive in Big data, I am trying to connect kafka to spark.
Here is my producer code
```python
import os
import sys
import pykafka
def get_text():
## This block generates my required text.
text_as_bytes=text.encode(text)
producer.produce(text_as_bytes)
if __name__ == "__main__":
client = pykaf... | 2018/02/21 | [
"https://Stackoverflow.com/questions/48903304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9369585/"
] | The same issue happened to me. I was unable to solve it using jsonp. What i ended up doing was to make an action in the controller that recieved the json from external url and send it to the ajax call.
For exmaple
```
return $.ajax({
type: "post",
url: "/ActionInProject/ProjectController",
});
`... | I tried your request with Postman
and I found it not valid json in the respone you can find below what is returned of the server
```
<!DOCTYPE html><html dir="ltr"><head><title>Duolingo</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><meta name="robots"... |
26,106,358 | I have this code at the top of my Google App Engine program:
```
from google.appengine.api import urlfetch
urlfetch.set_default_fetch_deadline(60)
```
I am using an opener to load stuff:
```
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor( cj ) )
opener.addheaders = [... | 2014/09/29 | [
"https://Stackoverflow.com/questions/26106358",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/847663/"
] | Did you try setting the timeout on the `.open()` call?
```
resp = opener.open('http://example.com', None, 60)
```
If you reach the timeout as specified by `set_default_fetch_deadline`, Python will throw a `DownloadError` or `DeadlineExceededErrors` exception: <https://cloud.google.com/appengine/docs/python/urlfetch/... | You can also patch the httplib2 library and set the deadline to 60 seconds
```
httplib2/__init__.py:
def fixed_fetch(url, payload=None, method="GET", headers={},
allow_truncated=False, follow_redirects=True,
deadline=60):
return fetch(url, payload=payload, me... |
13,583,649 | We're using EngineYard which has Python installed by default. But when we enabled SSL we received the following error message from our logentries chef recipe.
"WARNING: The "ssl" module is not present. Using unreliable workaround, host identity cannot be verified. Please install "ssl" module or newer version of Python... | 2012/11/27 | [
"https://Stackoverflow.com/questions/13583649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/421709/"
] | I just wrote a recipe for this, and now am able to run the latest Logentries client on EngineYard. Here you go:
```
file_dir = "/mnt/src/python-ssl"
file_name = "ssl-1.15.tar.gz"
file_path = File.join(file_dir,file_name)
uncompressed_file_dir = File.join(file_dir, file_name.split(".tar.gz").first)
directory file_dir ... | You could install a new Python using PythonBrew: <https://github.com/utahta/pythonbrew>. Just make you install libssl before you build, or it still won't be able to use SSL. However, based on the warning, it seems that SSL *might* work, but it won't be able to verify host. Of course, that is one major purposes of SSL, ... |
13,583,649 | We're using EngineYard which has Python installed by default. But when we enabled SSL we received the following error message from our logentries chef recipe.
"WARNING: The "ssl" module is not present. Using unreliable workaround, host identity cannot be verified. Please install "ssl" module or newer version of Python... | 2012/11/27 | [
"https://Stackoverflow.com/questions/13583649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/421709/"
] | There now appears to be a solution with better community support (based on the fact that it is documented on the [opscode website](http://docs.opscode.com/lwrp_python.html)).
You might try:
```
include_recipe 'python'
python_pip 'ssl'
```
As documented: [here](https://supermarket.getchef.com/cookbooks/python) or [h... | You could install a new Python using PythonBrew: <https://github.com/utahta/pythonbrew>. Just make you install libssl before you build, or it still won't be able to use SSL. However, based on the warning, it seems that SSL *might* work, but it won't be able to verify host. Of course, that is one major purposes of SSL, ... |
13,583,649 | We're using EngineYard which has Python installed by default. But when we enabled SSL we received the following error message from our logentries chef recipe.
"WARNING: The "ssl" module is not present. Using unreliable workaround, host identity cannot be verified. Please install "ssl" module or newer version of Python... | 2012/11/27 | [
"https://Stackoverflow.com/questions/13583649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/421709/"
] | There now appears to be a solution with better community support (based on the fact that it is documented on the [opscode website](http://docs.opscode.com/lwrp_python.html)).
You might try:
```
include_recipe 'python'
python_pip 'ssl'
```
As documented: [here](https://supermarket.getchef.com/cookbooks/python) or [h... | I just wrote a recipe for this, and now am able to run the latest Logentries client on EngineYard. Here you go:
```
file_dir = "/mnt/src/python-ssl"
file_name = "ssl-1.15.tar.gz"
file_path = File.join(file_dir,file_name)
uncompressed_file_dir = File.join(file_dir, file_name.split(".tar.gz").first)
directory file_dir ... |
65,534,980 | This is a little niche, but I want to click on a discord reaction with selenium (python), but only the reaction that has a specific img src.
I had it working where it would be clicking on reactions however it was clicking on every reaction not just the one I wanted.
I've tried to make it only click on the certain ele... | 2021/01/02 | [
"https://Stackoverflow.com/questions/65534980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14924745/"
] | The characters allowed in XML element names are given by the [W3C XML BNF for component names](https://www.w3.org/TR/xml/#NT-NameStartChar):
>
>
> ```
> NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] |
> [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] |
> [#... | Right: Letter, digit, hyphen, underscore and period.
One may use any Unicode letter.
And of course one may prefix the names with *name space* + colon. |
8,281,119 | So I am trying to do this problem where I have to find the most frequent 6-letter string within some lines in python, so I realize one could do something like this:
```
>>> from collections import Counter
>>> x = Counter("ACGTGCA")
>>> x
Counter({'A': 2, 'C': 2, 'G': 2, 'T': 1})
```
Now then, the data I'm using is ... | 2011/11/26 | [
"https://Stackoverflow.com/questions/8281119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067233/"
] | Let us go through a slightly modified version of your test code as it is seen by `irb` and as a stand alone script:
```
def test_method;end
symbols = Symbol.all_symbols # This is already a "fixed" array, no need for map
puts symbols.include?(:test_method)
puts symbols.include?('test_method_nonexistent'.to_sym)
puts sy... | The reason you have to convert symbols to strings when checking for existence of a symbol is that it will always return true otherwise. The argument being passed to the `include?` method gets evaluated first, so if you pass it a symbol, the a new symbol is instantiated and added into the heap, so `Symbol.all_symbols` d... |
9,917,628 | I'm attempting to follow Heroku's python quickstart guide but am running into repeated problems. At the moment, "git push heroku master" is failing because it cannot install Bonjour. Does anyone know if this is a truly necessary requirement, and whether I can change the version required, or somehow otherwise fix this? ... | 2012/03/29 | [
"https://Stackoverflow.com/questions/9917628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/723212/"
] | Are you trying to push the example app from the quickstart? Many of the requirements you're trying to install aren't required at all.
I suspect that you created your requirements file outside of the recommended virtualenv, and that twisted and bonjour-py are packages install in your system python installation. | Why is `bonjour-py` in your requirements.txt file? Removing it should fix your problem.
Furthermore, I can't seem to install it either, so it's no wonder Heroku fails there.
```
(so)modocache $ pip install bonjour-py
Downloading/unpacking bonjour-py
Could not find any downloads that satisfy the requirement bonjour-... |
9,917,628 | I'm attempting to follow Heroku's python quickstart guide but am running into repeated problems. At the moment, "git push heroku master" is failing because it cannot install Bonjour. Does anyone know if this is a truly necessary requirement, and whether I can change the version required, or somehow otherwise fix this? ... | 2012/03/29 | [
"https://Stackoverflow.com/questions/9917628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/723212/"
] | Maybe you are using a virtual environment and you just forgot to activate it
In this case, depending on how you stored the virtual environment in your project, you will probably first need to
```
source venv/bin/activate
```
and after that freeze your requirements
```
pip freeze > requirements.txt
```
finally
... | Why is `bonjour-py` in your requirements.txt file? Removing it should fix your problem.
Furthermore, I can't seem to install it either, so it's no wonder Heroku fails there.
```
(so)modocache $ pip install bonjour-py
Downloading/unpacking bonjour-py
Could not find any downloads that satisfy the requirement bonjour-... |
9,917,628 | I'm attempting to follow Heroku's python quickstart guide but am running into repeated problems. At the moment, "git push heroku master" is failing because it cannot install Bonjour. Does anyone know if this is a truly necessary requirement, and whether I can change the version required, or somehow otherwise fix this? ... | 2012/03/29 | [
"https://Stackoverflow.com/questions/9917628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/723212/"
] | Why is `bonjour-py` in your requirements.txt file? Removing it should fix your problem.
Furthermore, I can't seem to install it either, so it's no wonder Heroku fails there.
```
(so)modocache $ pip install bonjour-py
Downloading/unpacking bonjour-py
Could not find any downloads that satisfy the requirement bonjour-... | I usually had same issue with some project referencing `bonjour-py` in their `requirements.txt`, didn't know which or how to track that one at the moment.
And someone told me that **[pip-tool](https://github.com/nvie/pip-tools)**. It's actually a great alternative to identify which you have, and if you want to update ... |
9,917,628 | I'm attempting to follow Heroku's python quickstart guide but am running into repeated problems. At the moment, "git push heroku master" is failing because it cannot install Bonjour. Does anyone know if this is a truly necessary requirement, and whether I can change the version required, or somehow otherwise fix this? ... | 2012/03/29 | [
"https://Stackoverflow.com/questions/9917628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/723212/"
] | Are you trying to push the example app from the quickstart? Many of the requirements you're trying to install aren't required at all.
I suspect that you created your requirements file outside of the recommended virtualenv, and that twisted and bonjour-py are packages install in your system python installation. | I usually had same issue with some project referencing `bonjour-py` in their `requirements.txt`, didn't know which or how to track that one at the moment.
And someone told me that **[pip-tool](https://github.com/nvie/pip-tools)**. It's actually a great alternative to identify which you have, and if you want to update ... |
9,917,628 | I'm attempting to follow Heroku's python quickstart guide but am running into repeated problems. At the moment, "git push heroku master" is failing because it cannot install Bonjour. Does anyone know if this is a truly necessary requirement, and whether I can change the version required, or somehow otherwise fix this? ... | 2012/03/29 | [
"https://Stackoverflow.com/questions/9917628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/723212/"
] | Maybe you are using a virtual environment and you just forgot to activate it
In this case, depending on how you stored the virtual environment in your project, you will probably first need to
```
source venv/bin/activate
```
and after that freeze your requirements
```
pip freeze > requirements.txt
```
finally
... | I usually had same issue with some project referencing `bonjour-py` in their `requirements.txt`, didn't know which or how to track that one at the moment.
And someone told me that **[pip-tool](https://github.com/nvie/pip-tools)**. It's actually a great alternative to identify which you have, and if you want to update ... |
6,632,954 | [Why is else clause needed for try statement in python ?](https://stackoverflow.com/questions/4836139/why-is-else-clause-needed-for-try-statement-in-python)
Taking it forward:
```
try:
f = open('foo', 'r')
except IOError as e:
error_log.write('Unable to open foo : %s\n' % e)
else:
data = f.read()
f.close()
... | 2011/07/09 | [
"https://Stackoverflow.com/questions/6632954",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1140524/"
] | `try..except..else` may not be *needed*, but it can be nice. In this case, the `try..except..else` form is distinctly nicer, in my opinion.
Just because you can do without an element of syntax, doesn't make it useless. Decorator syntax is purely syntax sugar (the most obvious example, I think), `for` loops are just gl... | Actually, is not always needed you can simply do:
```
f = None
try:
f = open('foo', 'r')
except IOError:
error_log.write('Unable to open foo\n')
if f:
data = f.read()
f.close()
``` |
70,108,696 | So i was solving a question that is in my Lab practical Syllabus. Below is the question:-
>
> Write a python class to reverse a sentence (initialized via
> constructor) word by word. Example: “I am here” should be reversed as
> “here am I”. Create instances of this class for each of the three
> strings input by the u... | 2021/11/25 | [
"https://Stackoverflow.com/questions/70108696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16369432/"
] | You are calling `getVowelCount()` twice. Instead you can use the variable instead of calling in the print command
```
for i in range (len(sorted_item)):
print('Reversed String: ',sorted_item[i].reverser(),'Vowel count: ',sorted_item[i].vowelCount)
``` | This is because you don't reset vowel count in the method. So if you execute the method once (here in sort), you'll get correct count. If you execute it twice (in printing), you will get twice as much. If you execute it once more, you'll get 3x correct amount. And so on.
The solution is to reset the number:
```py
d... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | You could store the partial date as an integer (preferably in a field named for the portion of the date you are storing, such as `year,` `month` or `day`) and do validation and conversion to a date object in the model.
**EDIT**
If you need real date functionality, you probably need real, not partial, dates. For insta... | Can you store the date together with a flag that tells how much of the date is valid?
Something like this:
```
YEAR_VALID = 0x04
MONTH_VALID = 0x02
DAY_VALID = 0x01
Y_VALID = YEAR_VALID
YM_VALID = YEAR_VALID | MONTH_VALID
YMD_VALID = YEAR_VALID | MONTH_VALID | DAY_VALID
```
Then, if you have a date like 2010-00-00... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | First, thanks for all your answers. None of them, as is, was a good solution for my problem, but, for your defense, I should add that I didn't give all the requirements. But each one help me think about my problem and some of your ideas are part of my final solution.
So my final solution, on the DB side, is to use a *... | You could store the partial date as an integer (preferably in a field named for the portion of the date you are storing, such as `year,` `month` or `day`) and do validation and conversion to a date object in the model.
**EDIT**
If you need real date functionality, you probably need real, not partial, dates. For insta... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | You could store the partial date as an integer (preferably in a field named for the portion of the date you are storing, such as `year,` `month` or `day`) and do validation and conversion to a date object in the model.
**EDIT**
If you need real date functionality, you probably need real, not partial, dates. For insta... | Although not in Python - here's an example of how the same problem was solved in Ruby - using a single Integer value - and bitwise operators to store year, month and day - with month and day optional.
<https://github.com/58bits/partial-date>
Look at the source in lib for date.rb and bits.rb.
I'm sure a similar solut... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | It sounds like you want to store a date interval. In Python this would (to my still-somewhat-noob understanding) most readily be implemented by storing two datetime.datetime objects, one specifying the start of the date range and the other specifying the end. In a manner similar to that used to specify list slices, the... | Can you store the date together with a flag that tells how much of the date is valid?
Something like this:
```
YEAR_VALID = 0x04
MONTH_VALID = 0x02
DAY_VALID = 0x01
Y_VALID = YEAR_VALID
YM_VALID = YEAR_VALID | MONTH_VALID
YMD_VALID = YEAR_VALID | MONTH_VALID | DAY_VALID
```
Then, if you have a date like 2010-00-00... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | First, thanks for all your answers. None of them, as is, was a good solution for my problem, but, for your defense, I should add that I didn't give all the requirements. But each one help me think about my problem and some of your ideas are part of my final solution.
So my final solution, on the DB side, is to use a *... | Can you store the date together with a flag that tells how much of the date is valid?
Something like this:
```
YEAR_VALID = 0x04
MONTH_VALID = 0x02
DAY_VALID = 0x01
Y_VALID = YEAR_VALID
YM_VALID = YEAR_VALID | MONTH_VALID
YMD_VALID = YEAR_VALID | MONTH_VALID | DAY_VALID
```
Then, if you have a date like 2010-00-00... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | First, thanks for all your answers. None of them, as is, was a good solution for my problem, but, for your defense, I should add that I didn't give all the requirements. But each one help me think about my problem and some of your ideas are part of my final solution.
So my final solution, on the DB side, is to use a *... | It sounds like you want to store a date interval. In Python this would (to my still-somewhat-noob understanding) most readily be implemented by storing two datetime.datetime objects, one specifying the start of the date range and the other specifying the end. In a manner similar to that used to specify list slices, the... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | It sounds like you want to store a date interval. In Python this would (to my still-somewhat-noob understanding) most readily be implemented by storing two datetime.datetime objects, one specifying the start of the date range and the other specifying the end. In a manner similar to that used to specify list slices, the... | Although not in Python - here's an example of how the same problem was solved in Ruby - using a single Integer value - and bitwise operators to store year, month and day - with month and day optional.
<https://github.com/58bits/partial-date>
Look at the source in lib for date.rb and bits.rb.
I'm sure a similar solut... |
2,971,198 | In one of my Django projects that use MySQL as the database, I need to have a *date* fields that accept also "partial" dates like only year (YYYY) and year and month (YYYY-MM) plus normal date (YYYY-MM-DD).
The *date* field in MySQL can deal with that by accepting *00* for the month and the day. So *2010-00-00* is val... | 2010/06/04 | [
"https://Stackoverflow.com/questions/2971198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146481/"
] | First, thanks for all your answers. None of them, as is, was a good solution for my problem, but, for your defense, I should add that I didn't give all the requirements. But each one help me think about my problem and some of your ideas are part of my final solution.
So my final solution, on the DB side, is to use a *... | Although not in Python - here's an example of how the same problem was solved in Ruby - using a single Integer value - and bitwise operators to store year, month and day - with month and day optional.
<https://github.com/58bits/partial-date>
Look at the source in lib for date.rb and bits.rb.
I'm sure a similar solut... |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[ conversation) was adding
```
"python.analysis.extraPaths": [
"./src/lib"
],
```
(where `.src/lib/` contains your modules and an `__init__.py` file) to your `settin... |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[ What I had to do was to open settings and type "languge server ". Then there are a f... |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[ and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[` and reverting to the `Jedi server`(prompted by Vscode) ,restarted intellisense detection. | My settings were all in order, but still not auto-completing in-line.
I disabled the Kite extension & a couple of other ones that I didn't really need, & IntelliSense started auto-completing.
Not 100% sure, but I reckon it might have been my "Kite" extension settings that were getting in the way. |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[` and reverting to the `Jedi server`(prompted by Vscode) ,restarted intellisense detection. | In my case there was a problem with the python language server after a vs code update. The download of the language server was stuck every time. See [enter link description here](https://github.com/microsoft/vscode-python/issues/10854) What I had to do was to open settings and type "languge server ". Then there are a f... |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[. Upon inspecting the python language server logs:
```
Enumeration of workspace source files is taking longer than 10 seconds.
```
Solution
--------
Add a `pyrightconfig.json` to your workspa... | I just disabled Pylance in the extensions and suggestions worked again instantly. |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[ and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[ with the [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) extension worked. | go to Extensions (Ctrl+Shift+X).
you should have installed following extensions:
[](https://i.stack.imgur.com/9789s.png)
\*:Note: some of them may needs to be restarted, in this way it is shown in the right side of extension. |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[` and reverting to the `Jedi server`(prompted by Vscode) ,restarted intellisense detection. | For me, what fixed it was reinstalling the default Python extension and setting the python language server in the seetings to `Default`.
Steps
=====
1. Open the commands window by simultaneously pressing `CTRL/CMD + Shift + P`. Now search for `install extensions`.
2. Select `Python` and install it (uninstall first if... |
50,389,852 | My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with `Ctrl + Shift`, it only displays a loading message. I'm using Python (with Django) and have installed `ms-python.python`. I also have `Djaneiro`. It is still not working.
[, you need to **echo** the "export foo=bar" into $BASH\_ENV (which is just a file that runs when the a bash session starts):
so in your env-setup.sh file:
```sh
echo "export dbPasswordDev=$dbPassword" >> $BASH_ENV
``` | Here is a more advanced case where variables can be loaded from `.env` file.
```
version: 2
aliases:
- &step_process_dotenv
run:
name: Process .env file variables
command: echo "export $(grep -v '^#' .env | xargs)" >> $BASH_ENV
jobs:
build:
working_directory: ~/project
docker:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.