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 |
|---|---|---|---|---|---|
66,636,134 | i have written a python program which makes an api call to a webserver once every minute and then parse the json response and saves parsed values in to the csv files.
here is the code that is saving the values into the csv file :
```
with open('data.csv', 'a', newline='') as file:
writer = csv.writer(file)
wr... | 2021/03/15 | [
"https://Stackoverflow.com/questions/66636134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15392786/"
] | The properties you've put on `<v-col>` don't exist (i.e. align-end and justify-end). They are properties on the `<v-row>` component (which is a flex container). You need to use classes instead.
Make sure to consult the API->props section on the Vuetify component page when choosing component properties.
Try
```html
<... | Add `direction: rtl` to your `v-btn`, Here is [codepen](https://codepen.io/MNSY22/pen/qBqWZEv):
```html
<template>
<v-btn class="btn rtl">
...
</v-btn>
</template>
<style>
.rtl { direction: rtl; }
</style>
``` |
29,711,646 | I'm trying to create examples on how to manipulate massive databases composed of CSV tables using only Python.
I'd like to find out a way to emulate efficient indexed queries in tables spread through some `list()`
The example below takes 24 seconds in a 3.2Ghz Core i5
```
#!/usr/bin/env python
import csv
MAINDIR = "... | 2015/04/18 | [
"https://Stackoverflow.com/questions/29711646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/417415/"
] | You can `itertools.islice` instead of reading all rows and use `itertools.ifilter`:
```
import csv
from itertools import islice,ifilter
MAINDIR = "../"
with open(MAINDIR + "atp_players.csv") as pf, open(MAINDIR + "atp_rankings_current.csv") as rf:
players = list(csv.reader(pf))
rankings = csv.reader(rf)
... | This code doesn't take that much time to run. So I'm going to assume that you were really running through more of the rankings that just 10. When I run through them all it takes a long time. If that is what you are interested in doing, then a dictionary would shorten the search time. For a bit of overhead to setup the ... |
29,711,646 | I'm trying to create examples on how to manipulate massive databases composed of CSV tables using only Python.
I'd like to find out a way to emulate efficient indexed queries in tables spread through some `list()`
The example below takes 24 seconds in a 3.2Ghz Core i5
```
#!/usr/bin/env python
import csv
MAINDIR = "... | 2015/04/18 | [
"https://Stackoverflow.com/questions/29711646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/417415/"
] | You can `itertools.islice` instead of reading all rows and use `itertools.ifilter`:
```
import csv
from itertools import islice,ifilter
MAINDIR = "../"
with open(MAINDIR + "atp_players.csv") as pf, open(MAINDIR + "atp_rankings_current.csv") as rf:
players = list(csv.reader(pf))
rankings = csv.reader(rf)
... | Consider putting your data in an [SQLite database](https://docs.python.org/3/library/sqlite3.html). This meets your requirement of using only Python, since it is built into the standard Python library and supported in (almost) all Python interpreters. SQLite is a database library that allows you to do processing on dat... |
29,711,646 | I'm trying to create examples on how to manipulate massive databases composed of CSV tables using only Python.
I'd like to find out a way to emulate efficient indexed queries in tables spread through some `list()`
The example below takes 24 seconds in a 3.2Ghz Core i5
```
#!/usr/bin/env python
import csv
MAINDIR = "... | 2015/04/18 | [
"https://Stackoverflow.com/questions/29711646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/417415/"
] | Consider putting your data in an [SQLite database](https://docs.python.org/3/library/sqlite3.html). This meets your requirement of using only Python, since it is built into the standard Python library and supported in (almost) all Python interpreters. SQLite is a database library that allows you to do processing on dat... | This code doesn't take that much time to run. So I'm going to assume that you were really running through more of the rankings that just 10. When I run through them all it takes a long time. If that is what you are interested in doing, then a dictionary would shorten the search time. For a bit of overhead to setup the ... |
68,705,417 | I am getting the below error while running a pyspark program on PYCHARM,
Error:
>
> java.io.IOException: Cannot run program "python3": CreateProcess error=2, The system cannot find the file specified ......
>
>
>
The interpreter is recognizing the python.exe file and I have added the Content root in project struc... | 2021/08/08 | [
"https://Stackoverflow.com/questions/68705417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11609306/"
] | create an environment variable PYSPARK\_PYTHON with value 'python'.
it worked for me! | 1. Go to Environmental variable and within System variable set a new variable as `PYSPARK_PYTHON` and value as `python`
>
> PYSPARK\_PYTHON=python
>
>
>
2. Add below codebits to your pyspark code
```
import os
import sys
from pyspark import SparkContext
os.environ['PYSPARK_PYTHON'] = sys.executable
os.environ['P... |
68,705,417 | I am getting the below error while running a pyspark program on PYCHARM,
Error:
>
> java.io.IOException: Cannot run program "python3": CreateProcess error=2, The system cannot find the file specified ......
>
>
>
The interpreter is recognizing the python.exe file and I have added the Content root in project struc... | 2021/08/08 | [
"https://Stackoverflow.com/questions/68705417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11609306/"
] | Before creating your spark session, set the following environment variables in your code:
```py
import os
import sys
from pyspark.sql import SparkSession
os.environ['PYSPARK_PYTHON'] = sys.executable
os.environ['PYSPARK_DRIVER_PYTHON'] = sys.executable
spark = SparkSession.builder.getOrCreate()
``` | 1. Go to Environmental variable and within System variable set a new variable as `PYSPARK_PYTHON` and value as `python`
>
> PYSPARK\_PYTHON=python
>
>
>
2. Add below codebits to your pyspark code
```
import os
import sys
from pyspark import SparkContext
os.environ['PYSPARK_PYTHON'] = sys.executable
os.environ['P... |
60,553,140 | I have the following insert statement that let me parse sql query into a python file and then returning a dataframe of that data that is collected from the query
```
params = 'DRIVER={ODBC Driver 13 for SQL Server};' \
'SERVER=localhost;' \
'PORT=XXX;' \
'DATABASE=database_name;' \
'UID=XXX;' \
... | 2020/03/05 | [
"https://Stackoverflow.com/questions/60553140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12292254/"
] | You can use `?` as a [placeholder](https://learn.microsoft.com/en-us/sql/connect/php/how-to-perform-parameterized-queries?view=sql-server-ver15) in the query and pass the value as a parameter to the `read_sql_query` function:
```
sql = '''
select * from table_name
where column_name= ?
'''
dataframe = pd.read_sql_quer... | You can do something like:
```
sql = '''
select * from table_name
where column_name= {}
'''.format(variable_in_python)
```
For more information, have a look at <https://docs.python.org/3/tutorial/inputoutput.html> |
60,553,140 | I have the following insert statement that let me parse sql query into a python file and then returning a dataframe of that data that is collected from the query
```
params = 'DRIVER={ODBC Driver 13 for SQL Server};' \
'SERVER=localhost;' \
'PORT=XXX;' \
'DATABASE=database_name;' \
'UID=XXX;' \
... | 2020/03/05 | [
"https://Stackoverflow.com/questions/60553140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12292254/"
] | I like the answer by @blhsing.
Another way is f-strings. I particularly like them because they make things very readable.
For example:
```
# Query Parameters
column_name = 'x'
```
and then:
```
sql = f'''
select * from table_name
where column_name= {column_name}
'''
```
You could go further with this and use a ... | You can do something like:
```
sql = '''
select * from table_name
where column_name= {}
'''.format(variable_in_python)
```
For more information, have a look at <https://docs.python.org/3/tutorial/inputoutput.html> |
60,553,140 | I have the following insert statement that let me parse sql query into a python file and then returning a dataframe of that data that is collected from the query
```
params = 'DRIVER={ODBC Driver 13 for SQL Server};' \
'SERVER=localhost;' \
'PORT=XXX;' \
'DATABASE=database_name;' \
'UID=XXX;' \
... | 2020/03/05 | [
"https://Stackoverflow.com/questions/60553140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12292254/"
] | You can use `?` as a [placeholder](https://learn.microsoft.com/en-us/sql/connect/php/how-to-perform-parameterized-queries?view=sql-server-ver15) in the query and pass the value as a parameter to the `read_sql_query` function:
```
sql = '''
select * from table_name
where column_name= ?
'''
dataframe = pd.read_sql_quer... | I like the answer by @blhsing.
Another way is f-strings. I particularly like them because they make things very readable.
For example:
```
# Query Parameters
column_name = 'x'
```
and then:
```
sql = f'''
select * from table_name
where column_name= {column_name}
'''
```
You could go further with this and use a ... |
51,759,688 | Why only ***if*** statement is executed & not ***else*** statement if we write an ***if-else*** with ***if*** having constant value. For example this code in python
```
x=5
if 5:
print("hello 5")
else:
print("bye")
```
Also the point to be noted is that in second line even if I replace 5 with 500 or any number, if... | 2018/08/09 | [
"https://Stackoverflow.com/questions/51759688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6659144/"
] | Threading is your only possibility. Also it always requires the ENTER when you are using std::cin. This could work:
```
#include <future>
#include <iostream>
#include <thread>
int main(int argc, char** argv) {
int i = 1;
std::atomic_int ch{1};
std::atomic_bool readKeyboard{true};
std::thread t([&ch, ... | You can do this but you will have to use threads. Here is the minimal example how to achive this behaviour. Please note that you will need C++11 at least.
```
#include <iostream>
#include <thread>
#include <atomic>
int main()
{
std::atomic<bool> stopLoop;
std::thread t([&]()
{
while (!stopLoop... |
16,066,838 | OK so I have this book
Violent Python - A Cookbook for Hackers, Forensic Analysts, Penetration Testers and Security Engineers.
I have gotten to page 10 and I'm a complete noob at this but it really fascinates me.
But this piece of code has me stumped:
```
import socket
socket.setdefaulttimeout(2)
s = socket.socket()
... | 2013/04/17 | [
"https://Stackoverflow.com/questions/16066838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2282257/"
] | `s.connect(("192.168.95.148",21))` seems to try to connect to an FTP server on IP address 192.168.95.148. If you don't have an FTP server running on that IP, you will get a connection timeout error instead of a response from the FTP server. Do you have a FreeFloat FTP Server running on 192.168.95.148? | Well, you could try connecting to a known public FTP server? If the lack of a server is stopping you.
For example, ftp.mozilla.org |
73,625,732 | I have an table of people where each person can have a associate partner like this:
| id\_person | Name | id\_partner |
| --- | --- | --- |
| 1 | Javi | 5 |
| 2 | John | 4 |
| 3 | Mike | 6 |
| 4 | Lucy | 2 |
| 5 | Jenny | 1 |
| 6 | Cindy | 3 |
So I would like to have a query where I can get all the couples without re... | 2022/09/06 | [
"https://Stackoverflow.com/questions/73625732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17563150/"
] | Assuming you want daily value counts, use `asfreq` and `fillna`:
```
july_log_mel.index = pd.to_datetime(july_log_mel.index)
july_log_mel.asfreq('D').fillna(0)
``` | You can `reindex` your Series with `date_range`:
```
s = df['date'].value_counts()
s = s.reindex(pd.date_range(s.index.min(), s.index.max(), freq='D')
.strftime('%Y-%m-%d'),
fill_value=0)
```
output:
```
2022-07-04 2
2022-07-05 0
2022-07-06 1
2022-07-07 0
2022-07-08 1
N... |
50,717,721 | HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
```
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
```
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python... | 2018/06/06 | [
"https://Stackoverflow.com/questions/50717721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9902618/"
] | I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this [matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'](https://stackoverflow.com/ques... | Try running cmd as **administrator** inside the python directory. Then execute:
```
pip3 install matplotlib-2.2.2-cp36-cp36m-win32.whl
```
Also make sure that you have all dependencies installed. |
50,717,721 | HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
```
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
```
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python... | 2018/06/06 | [
"https://Stackoverflow.com/questions/50717721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9902618/"
] | I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this [matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'](https://stackoverflow.com/ques... | The code seems very specific and something may not be supported any more.
You could first uninstall the current version using:
```
pip uninstall matplotlib
```
and then try installing matplotlib as follows:
```
pip install matplotlib
```
providing that you have admin rights to do so.
Then you can import as: `im... |
50,717,721 | HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
```
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
```
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python... | 2018/06/06 | [
"https://Stackoverflow.com/questions/50717721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9902618/"
] | I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this [matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'](https://stackoverflow.com/ques... | It seems like you are installing the package on Python 2.
Try installing the library using:
```
py -3 -m pip install --user matplotlib
```
Assuming you are using Windows. |
50,717,721 | HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
```
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
```
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python... | 2018/06/06 | [
"https://Stackoverflow.com/questions/50717721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9902618/"
] | I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this [matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'](https://stackoverflow.com/ques... | Try doing as below:
python -m pip install --user matplotlib |
46,630,311 | Actually I'm calculating throughput given certain window size.
However, I don't know how to accumulate the values by window. For instance:
```
time = [0.9, 1.1, 1.2, 2.1, 2.3, 2.6]
value = [1, 2, 3, 4, 5, 6]
```
After window size with 1 is applied, I should get
```
new_value = [1, 5, 15]
```
I've thought of usin... | 2017/10/08 | [
"https://Stackoverflow.com/questions/46630311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5785396/"
] | You could use `itertools.groupby` with a custom grouping function
```
from itertools import groupby
def f(time, values, dt=1):
vit = iter(values)
return [sum(v for _, v in zip(g, vit)) for _, g in groupby(time, lambda x: x // dt)]
```
```
In [14]: f([0.9, 1.1, 1.2, 2.1, 2.3, 2.6], [1, 2, 3, 4, 5, 6])
Out[14... | You could use a [`Counter`](https://docs.python.org/3/library/collections.html#collections.Counter):
```
time = [0.9, 1.1, 1.2, 2.1, 2.3, 2.6]
value = [1, 2, 3, 4, 5, 6]
from collections import Counter
counter = Counter()
for t,v in zip(time, value):
counter[int(t)] += v
print(sorted(counter.items()))
# [(0, 1),... |
48,982,187 | I am using `telegraf` as a measuring/monitoring tool in my tests. I need to edit `telegraf` configurations automatically; since all tests are being executed automatically.
Currently I am using `re` for configuring it; this is the process:
1. Read the whole file content.
2. Use regex to find and edit the required plug... | 2018/02/26 | [
"https://Stackoverflow.com/questions/48982187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1626977/"
] | You can use [toml](https://pypi.org/project/toml/)
Configuration file
```
[[inputs.ping]]
## Hosts to send ping packets to.
urls = ["example.org"]
method = "exec"
```
Usage
```
import toml
conf = (toml.load("/etc/telegraf/telegraf.conf"))
conf.get("inputs")
```
Output
```
{'ping': [{'urls': ['example.org'... | You can use [configobj](http://configobj.readthedocs.io/en/latest/), but you have to specify "list\_values"=False
```
c = configobj.ConfigObj('/etc/telegraf/telegraf.conf', list_values=False)
``` |
56,109,815 | If there is any bug in my code (code within a model that is used within a view which uses LoginRequiredMixin ) e.g. A bug like:
```
if (True: # <-- example bug to show how bugs like this are hidden
```
Then I get the following error:
```
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settin... | 2019/05/13 | [
"https://Stackoverflow.com/questions/56109815",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5506400/"
] | You need to do:
```
$typ = $reqarr['message']['entities'][0]['type'];
```
Output:-<https://3v4l.org/KQc2s> | Try this:
```
if(!isset($reqarr['message']['entities'][0])){
$reqarr['message']['entities']=array($reqarr['message']['entities']);
}
foreach($reqarr['message']['entities'] as $entity){
var_dump($entities);
die();
}
``` |
45,247,778 | Writing a script in python to get data from table, when I use xpath I get the data according to it's row and column wise format. However, when I use css selector with the same I get an error 'list' object has no attribute 'text'. How to get around that? Thanks in advance?
Using xpath which is working errorlessly:
```... | 2017/07/21 | [
"https://Stackoverflow.com/questions/45247778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9189799/"
] | You can do it with CSS only if you use checkbox.
Use the `:checked` selector to display the content.
```
// You css
input[type=checkbox] + label {
color: #ccc;
font-style: italic;
}
// Set the content to be displayed when the radio/checkbox is checked.
// using the css3 selector :checked
input[type=check... | You could give the same class name to everyone of your `<fieldset>` and then loop over all elements having this class name. This loop would be executed once the page is load and on every checkbox event. |
45,247,778 | Writing a script in python to get data from table, when I use xpath I get the data according to it's row and column wise format. However, when I use css selector with the same I get an error 'list' object has no attribute 'text'. How to get around that? Thanks in advance?
Using xpath which is working errorlessly:
```... | 2017/07/21 | [
"https://Stackoverflow.com/questions/45247778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9189799/"
] | Use this javascript snippet
```js
function show(elem, show){
var elements =
elem.parentNode.parentNode.parentNode.getElementsByClassName("hidden");
var i;
for(i=0; i<elements.length; i++){
if(show){
elements[i].style.display = "initial";
}
else{
elements[i].style.di... | You can do it with CSS only if you use checkbox.
Use the `:checked` selector to display the content.
```
// You css
input[type=checkbox] + label {
color: #ccc;
font-style: italic;
}
// Set the content to be displayed when the radio/checkbox is checked.
// using the css3 selector :checked
input[type=check... |
45,247,778 | Writing a script in python to get data from table, when I use xpath I get the data according to it's row and column wise format. However, when I use css selector with the same I get an error 'list' object has no attribute 'text'. How to get around that? Thanks in advance?
Using xpath which is working errorlessly:
```... | 2017/07/21 | [
"https://Stackoverflow.com/questions/45247778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9189799/"
] | Use this javascript snippet
```js
function show(elem, show){
var elements =
elem.parentNode.parentNode.parentNode.getElementsByClassName("hidden");
var i;
for(i=0; i<elements.length; i++){
if(show){
elements[i].style.display = "initial";
}
else{
elements[i].style.di... | You could give the same class name to everyone of your `<fieldset>` and then loop over all elements having this class name. This loop would be executed once the page is load and on every checkbox event. |
6,949,915 | I have several scripts written in perl, python, and java (wrapped under java GUI with system calls to perl & python). And I have many not-tech-savy users that need to use this in their windows machines (xp & 7).
To avoid users from installing perl,python,and java and to avoid potential incompatibility between various ... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6949915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/737088/"
] | Try [Portable Python](http://www.portablepython.com/) and [Portable Perl](http://portableapps.com/node/12595). You can unzip them into your application tree and they should work. | Why don't you try migrating your perl/python code into java and then packagin everything into a nice webstart application? What do perl/python offer that java doesn't support?
For perl you can use something like perl2exe and for python py2exe so you can have 2 exes (which would include all the necessary interpreter bi... |
6,937,505 | I have python application that shoud be launched as windows executable. I'm using py2exe and pymssql 1.9.908.
I used next build script to generate application:
```
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'B... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6937505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/412793/"
] | In the program you are trying to import (eg. in the A.py for A.exe ), specify import statement for \_mssql as well. You might also need to import a couple of other modules (decimal & uuid )to get the exe working | ```
from distutils.core import setup
import py2exe, os, pymssql
import decimal
data_files = []
data_files.append(os.path.join(os.path.split(pymssql.__file__)[0], 'ntwdblib.dll'))
py2exe_options = {"py2exe":{"includes": ['decimal'],
"dll_excludes":["mswsock.dll",
"powrprof.dll",
... |
6,937,505 | I have python application that shoud be launched as windows executable. I'm using py2exe and pymssql 1.9.908.
I used next build script to generate application:
```
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'B... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6937505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/412793/"
] | In the program you are trying to import (eg. in the A.py for A.exe ), specify import statement for \_mssql as well. You might also need to import a couple of other modules (decimal & uuid )to get the exe working | Just add the statement `import _mssql` in your file. Next, run your program. When you get the same thing, just import that module in your code. This method works well for me. |
6,937,505 | I have python application that shoud be launched as windows executable. I'm using py2exe and pymssql 1.9.908.
I used next build script to generate application:
```
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'B... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6937505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/412793/"
] | In the program you are trying to import (eg. in the A.py for A.exe ), specify import statement for \_mssql as well. You might also need to import a couple of other modules (decimal & uuid )to get the exe working | To whom might help
I got lots of issues trying to user pymssql with Pyinstaller and
I finally got it right so posting here might help someone
after you install pymssql using pip install pymssql
use this parameters in pyinstaller to get it included
```
--onefile --paths=.\venv\ --hidden-import='pymssql' --hidden-impor... |
6,937,505 | I have python application that shoud be launched as windows executable. I'm using py2exe and pymssql 1.9.908.
I used next build script to generate application:
```
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'B... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6937505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/412793/"
] | ```
from distutils.core import setup
import py2exe, os, pymssql
import decimal
data_files = []
data_files.append(os.path.join(os.path.split(pymssql.__file__)[0], 'ntwdblib.dll'))
py2exe_options = {"py2exe":{"includes": ['decimal'],
"dll_excludes":["mswsock.dll",
"powrprof.dll",
... | To whom might help
I got lots of issues trying to user pymssql with Pyinstaller and
I finally got it right so posting here might help someone
after you install pymssql using pip install pymssql
use this parameters in pyinstaller to get it included
```
--onefile --paths=.\venv\ --hidden-import='pymssql' --hidden-impor... |
6,937,505 | I have python application that shoud be launched as windows executable. I'm using py2exe and pymssql 1.9.908.
I used next build script to generate application:
```
from distutils.core import setup
import MySQLdb
import fnmatch
import os
import pymssql
import shutil
import py2exe
import glob
##############
name = 'B... | 2011/08/04 | [
"https://Stackoverflow.com/questions/6937505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/412793/"
] | Just add the statement `import _mssql` in your file. Next, run your program. When you get the same thing, just import that module in your code. This method works well for me. | To whom might help
I got lots of issues trying to user pymssql with Pyinstaller and
I finally got it right so posting here might help someone
after you install pymssql using pip install pymssql
use this parameters in pyinstaller to get it included
```
--onefile --paths=.\venv\ --hidden-import='pymssql' --hidden-impor... |
10,068,576 | Is there a way to remove all references to an object at once? I know that's unpythonic, so I'll explain what I'm trying to do and maybe someone knows a better way.
I'm writing an object-oriented wrapper around a SWIG wrapper for a C library. When a proxy for one of the C objects is deleted, it also deletes child objec... | 2012/04/09 | [
"https://Stackoverflow.com/questions/10068576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/429898/"
] | If I understand you correctly, you are wrapping some C code, and the C code has a destructor that can be called. After that, any attempt to use the pointer to the C code object causes a fatal crash.
I am not sure of your exact situation, so I am going to give you two alternate answers.
0) If the C object can be freed... | A note about the [behavior of `__del__()` method](http://docs.python.org/reference/datamodel.html#object.__del__).
>
> del x doesn’t directly call `x.__del__()` — the former decrements the reference count for x by one, and the latter is only called when x‘s reference count reaches zero.
>
>
>
Therefore even if ... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | This is a bug in the font management of matplotlib, on my machine this is the file /usr/lib/pymodules/python2.6/matplotlib/font\_manager.py:1220. I've highlighted the change in the code snippet below; this is fixed in the newest version of matplotlib.
```
if best_font is None or best_score >= 10.0:
verbose.report(... | I experienced a similar error today, concerning code that I know for a fact was working a week ago. I also have recently uninstalled/reinstalled both Matplotlib and Numpy, while checking something else (I'm using Python 2.5).
The code went something like this:
```
self.ax.cla()
if self.logy: self.ax.set_yscale('log')... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | I had the same problem with matplotlib 0.98.5.2. I was able to fix it by upgrading to matplotlib 1.0.1 (0.99.3 didn't work), or by blowing away my ~/.matplotlib directory. Not sure what the equivalent is for Windows. | I experienced a similar error today, concerning code that I know for a fact was working a week ago. I also have recently uninstalled/reinstalled both Matplotlib and Numpy, while checking something else (I'm using Python 2.5).
The code went something like this:
```
self.ax.cla()
if self.logy: self.ax.set_yscale('log')... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | I had the same problem today, and I found the issue in github
<https://github.com/matplotlib/matplotlib/issues/198>
The proposed workaround is to delete the `.matplotlib/fontList.cache` file, and worked for me. | I experienced a similar error today, concerning code that I know for a fact was working a week ago. I also have recently uninstalled/reinstalled both Matplotlib and Numpy, while checking something else (I'm using Python 2.5).
The code went something like this:
```
self.ax.cla()
if self.logy: self.ax.set_yscale('log')... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | This is a bug in the font management of matplotlib, on my machine this is the file /usr/lib/pymodules/python2.6/matplotlib/font\_manager.py:1220. I've highlighted the change in the code snippet below; this is fixed in the newest version of matplotlib.
```
if best_font is None or best_score >= 10.0:
verbose.report(... | I had the same problem today, and I found the issue in github
<https://github.com/matplotlib/matplotlib/issues/198>
The proposed workaround is to delete the `.matplotlib/fontList.cache` file, and worked for me. |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | This is a bug in the font management of matplotlib, on my machine this is the file /usr/lib/pymodules/python2.6/matplotlib/font\_manager.py:1220. I've highlighted the change in the code snippet below; this is fixed in the newest version of matplotlib.
```
if best_font is None or best_score >= 10.0:
verbose.report(... | Thanks for explaining the issue!
Since I'm using the Mac OS 10.6 system install of matplotlib, (and I'm stuck on Python2.5 due to other package requirements) I am not interested in upgrading matplotlib (I just can't handle all the versioning of open-source packages!)
So the fix I randomly tried, which worked, was to... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | I had the same problem with matplotlib 0.98.5.2. I was able to fix it by upgrading to matplotlib 1.0.1 (0.99.3 didn't work), or by blowing away my ~/.matplotlib directory. Not sure what the equivalent is for Windows. | I had the same problem today, and I found the issue in github
<https://github.com/matplotlib/matplotlib/issues/198>
The proposed workaround is to delete the `.matplotlib/fontList.cache` file, and worked for me. |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | I had the same problem with matplotlib 0.98.5.2. I was able to fix it by upgrading to matplotlib 1.0.1 (0.99.3 didn't work), or by blowing away my ~/.matplotlib directory. Not sure what the equivalent is for Windows. | Thanks for explaining the issue!
Since I'm using the Mac OS 10.6 system install of matplotlib, (and I'm stuck on Python2.5 due to other package requirements) I am not interested in upgrading matplotlib (I just can't handle all the versioning of open-source packages!)
So the fix I randomly tried, which worked, was to... |
3,479,887 | I'm using python 2.6 and matplotlib. If I run the sample histogram\_demo.py provided in the matplotlib gallery page, it works fine. I've simplified this script greatly:
```
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
fig = plt.figure()
ax = fig.add_s... | 2010/08/13 | [
"https://Stackoverflow.com/questions/3479887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419902/"
] | I had the same problem today, and I found the issue in github
<https://github.com/matplotlib/matplotlib/issues/198>
The proposed workaround is to delete the `.matplotlib/fontList.cache` file, and worked for me. | Thanks for explaining the issue!
Since I'm using the Mac OS 10.6 system install of matplotlib, (and I'm stuck on Python2.5 due to other package requirements) I am not interested in upgrading matplotlib (I just can't handle all the versioning of open-source packages!)
So the fix I randomly tried, which worked, was to... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | You can do this using [Comparator](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html) as shown below:
```
List<String> sorted = List.of("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2")
.stream()
.sorted((s1, s2) -> {
String[] s1Parts = s1.split("\\.");
... | Assuming:
```
List<String> versions = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
```
You should use a custom `Comparator` as long as the default comparator cannot be applied to this type of the String, otherwise the numbers will not be sorted numerically (ex, `12` is considered lower than `2`.
```... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | ```
public static void main(String[] args) {
String[] versions_list = {"1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"};
Arrays.sort(versions_list, (o1, o2) -> {
String[] str1 = o1.split("\\.");
String[] str2 = o2.split("\\.");
if (!Integer.valueOf(str1[0]).equals(Integer.valueOf(str2[0])))... | Assuming:
```
List<String> versions = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
```
You should use a custom `Comparator` as long as the default comparator cannot be applied to this type of the String, otherwise the numbers will not be sorted numerically (ex, `12` is considered lower than `2`.
```... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | Here is a *modern* solution, using `Comparator.comparing` to build a version string comparator, based on the pre-existing standard library `Arrays.compare(int[])` method.
```
List<String> versionList = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
Pattern pattern = Pattern.compile("\\.");
C... | Assuming:
```
List<String> versions = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
```
You should use a custom `Comparator` as long as the default comparator cannot be applied to this type of the String, otherwise the numbers will not be sorted numerically (ex, `12` is considered lower than `2`.
```... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | Here is a *modern* solution, using `Comparator.comparing` to build a version string comparator, based on the pre-existing standard library `Arrays.compare(int[])` method.
```
List<String> versionList = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
Pattern pattern = Pattern.compile("\\.");
C... | You can do this using [Comparator](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html) as shown below:
```
List<String> sorted = List.of("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2")
.stream()
.sorted((s1, s2) -> {
String[] s1Parts = s1.split("\\.");
... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | You can do this using [Comparator](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html) as shown below:
```
List<String> sorted = List.of("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2")
.stream()
.sorted((s1, s2) -> {
String[] s1Parts = s1.split("\\.");
... | Here is one way using a lambda of the Comparator. Takes care of varying length version ids.
```
Comparator<String> comp = (a, b) -> {
String[] aa = a.split("\\.");
String[] bb = b.split("\\.");
int r = 0;
for (int i = 0; i < Math.min(aa.length, bb.length); i++) {
r = Integer
.co... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | Here is a *modern* solution, using `Comparator.comparing` to build a version string comparator, based on the pre-existing standard library `Arrays.compare(int[])` method.
```
List<String> versionList = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
Pattern pattern = Pattern.compile("\\.");
C... | ```
public static void main(String[] args) {
String[] versions_list = {"1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"};
Arrays.sort(versions_list, (o1, o2) -> {
String[] str1 = o1.split("\\.");
String[] str2 = o2.split("\\.");
if (!Integer.valueOf(str1[0]).equals(Integer.valueOf(str2[0])))... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | ```
public static void main(String[] args) {
String[] versions_list = {"1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"};
Arrays.sort(versions_list, (o1, o2) -> {
String[] str1 = o1.split("\\.");
String[] str2 = o2.split("\\.");
if (!Integer.valueOf(str1[0]).equals(Integer.valueOf(str2[0])))... | Here is one way using a lambda of the Comparator. Takes care of varying length version ids.
```
Comparator<String> comp = (a, b) -> {
String[] aa = a.split("\\.");
String[] bb = b.split("\\.");
int r = 0;
for (int i = 0; i < Math.min(aa.length, bb.length); i++) {
r = Integer
.co... |
63,206,368 | Python does not work in PowerShell anymore.
I've never had any problems, until recently. CMD still recognizes the `py` command, but powershell doesn't recognize any of the basic python commands: `py`,`py3`,`python`,`python3`.
My problem occured after I installed MinGW and added its path to the Path variable.
I have r... | 2020/08/01 | [
"https://Stackoverflow.com/questions/63206368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8583502/"
] | Here is a *modern* solution, using `Comparator.comparing` to build a version string comparator, based on the pre-existing standard library `Arrays.compare(int[])` method.
```
List<String> versionList = Arrays.asList("1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2");
Pattern pattern = Pattern.compile("\\.");
C... | Here is one way using a lambda of the Comparator. Takes care of varying length version ids.
```
Comparator<String> comp = (a, b) -> {
String[] aa = a.split("\\.");
String[] bb = b.split("\\.");
int r = 0;
for (int i = 0; i < Math.min(aa.length, bb.length); i++) {
r = Integer
.co... |
62,326,253 | ```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
--data '{"path": "<subgroup_path>", "name": "<subgroup_name>", "parent_id": <parent_group_id> } \
"https://gitlab.example.com/api/v4/groups/"
```
I was following the documentation from [gitlab](https:... | 2020/06/11 | [
"https://Stackoverflow.com/questions/62326253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11430726/"
] | Here's the equivalent using `requests`:
```
import requests
import json
headers = {
"PRIVATE-TOKEN": "<your_access_token>",
"Content-Type": "application/json",
}
data = {
"path": "<subgroup_path>",
"name": "<subgroup_name>",
"parent_id": "<parent_group_id>",
}
requests.post("https://gitlab.exampl... | It can be done by python's [requests](https://2.python-requests.org/en/master/) package.
```
import requests
import json
url = "https://gitlab.example.com/api/v4/groups/"
headers = {'PRIVATE-TOKEN': '<your_access_token>', 'Content-Type':'application/json'}
data = {"path": "<subgroup_path>", "name": "<subgroup_name>",... |
49,643,205 | I installed ansible on MAC High Sierra 10.13.3 and when I am trying to run
"ansible --version" I am receiving following error
-bash: /usr/local/bin/ansible: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
Please let me know if you have ran into same issue or have solution. | 2018/04/04 | [
"https://Stackoverflow.com/questions/49643205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594666/"
] | `/usr/local/bin/ansible` has PATH `"/usr/local/opt/python/bin/python2.7"` on the first line. and in `/usr/local/opt/python/bin/` directory I had python3.6 instead of python2.7.
So I changed PATH on file `vi /usr/local/bin/ansible`
from `#!/usr/local/opt/python/bin/python2.7`
to `#!/usr/local/opt/python/bin/python3.6`... | Changing the python version might be pushing into some compatibility issues
It happens, when we have multiple python versions installed in our OS.
Simple steps for troubleshooting:
1. Check the python version
command: `which python /usr/bin/python`
2. Create a soft link to the path
command : `ln -s /usr/bin/python /... |
49,643,205 | I installed ansible on MAC High Sierra 10.13.3 and when I am trying to run
"ansible --version" I am receiving following error
-bash: /usr/local/bin/ansible: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
Please let me know if you have ran into same issue or have solution. | 2018/04/04 | [
"https://Stackoverflow.com/questions/49643205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594666/"
] | `/usr/local/bin/ansible` has PATH `"/usr/local/opt/python/bin/python2.7"` on the first line. and in `/usr/local/opt/python/bin/` directory I had python3.6 instead of python2.7.
So I changed PATH on file `vi /usr/local/bin/ansible`
from `#!/usr/local/opt/python/bin/python2.7`
to `#!/usr/local/opt/python/bin/python3.6`... | In my case I am using [pyenv](https://github.com/pyenv/pyenv) to manage my python versions and $PATH and symlinks were all correct pointing to the correct paths.
### Check your python paths
```sh
$ pyenv which python
/Users/<username>/.pyenv/versions/3.7.3/bin/python
$ which python
/Users/<username>/.pyenv/shims/... |
49,643,205 | I installed ansible on MAC High Sierra 10.13.3 and when I am trying to run
"ansible --version" I am receiving following error
-bash: /usr/local/bin/ansible: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
Please let me know if you have ran into same issue or have solution. | 2018/04/04 | [
"https://Stackoverflow.com/questions/49643205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9594666/"
] | In my case I am using [pyenv](https://github.com/pyenv/pyenv) to manage my python versions and $PATH and symlinks were all correct pointing to the correct paths.
### Check your python paths
```sh
$ pyenv which python
/Users/<username>/.pyenv/versions/3.7.3/bin/python
$ which python
/Users/<username>/.pyenv/shims/... | Changing the python version might be pushing into some compatibility issues
It happens, when we have multiple python versions installed in our OS.
Simple steps for troubleshooting:
1. Check the python version
command: `which python /usr/bin/python`
2. Create a soft link to the path
command : `ln -s /usr/bin/python /... |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | You need to store the value of either a or b in a temporary variable first;
```
public Integer increment()
{
int temp = a;
a = b;
b = temp + b;
return value;
}
``` | i'll do this
```
fib = 100;
for(int a = 1, b = 0;a <= fib;a += b, b = (a-b)) {
System.out.print(a + ",");
}
``` |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | The line
```
a, b = b, b+a
```
Doesn't easily translate. It's something like this. You could simplify it. This is the literal meaning.
```
t1 = b
t2 = b+a
a = t1
b = t2
``` | The main problem with your Python-to-Java translation is that Python's assignment statement up there is executed all at once, while Java's are executed serially. Python's statement is equivalent to saying this:
```
Make a list out of 'b' and 'a + b'
Make another list out of references to 'a' and 'b'
Assign all the ele... |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | Java integers can only store the first 46 Fibonacci numbers, use a lookup table. | Don't you want to create a function to return the nth Fibnoacci number? This is how I remember it being taught when I was a kid:
```
public int Fibb(int index) {
if (index < 2)
return 1;
else
return Fibb(index-1)+Fibb(index-2);
};
```
Given the definition being the first pair of Fibbonaci numbers are 1 and e... |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | You need to store the value of either a or b in a temporary variable first;
```
public Integer increment()
{
int temp = a;
a = b;
b = temp + b;
return value;
}
``` | Don't you want to create a function to return the nth Fibnoacci number? This is how I remember it being taught when I was a kid:
```
public int Fibb(int index) {
if (index < 2)
return 1;
else
return Fibb(index-1)+Fibb(index-2);
};
```
Given the definition being the first pair of Fibbonaci numbers are 1 and e... |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | You need to store the value of either a or b in a temporary variable first;
```
public Integer increment()
{
int temp = a;
a = b;
b = temp + b;
return value;
}
``` | I'll just translate your earlier code:
```
public void fibb(int max) {
int a = 0;
int b = 1;
while (a < max) {
System.out.println(a);
int temp = a + b;
a = b;
b = temp;
}
}
``` |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | I'd do it this way:
```
public class FibonacciAlgorithm {
private int a = 0;
private int b = 1;
public FibonacciAlgorithm() {
}
public int increment() {
int temp = b;
b = a + b;
a = temp;
return value;
}
public int getValue() {
return b;
}
}... | The line
```
a, b = b, b+a
```
Doesn't easily translate. It's something like this. You could simplify it. This is the literal meaning.
```
t1 = b
t2 = b+a
a = t1
b = t2
``` |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | There was a recursive solution posted above, but this solution is tail recursive so it grows linearly.
```
public class Fibonacci {
public long fibonacci(int number) {
return fib(0,1,number);
}
private long fib(long result, long next, int n) {
if (n == 0)
return result;
... | public Integer increment() {
a = b;
b = a + b;
return value;
}
Is certainly wrong. I think switching the first two lines should do the trick |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | You need to store the value of either a or b in a temporary variable first;
```
public Integer increment()
{
int temp = a;
a = b;
b = temp + b;
return value;
}
``` | public Integer increment() {
a = b;
b = a + b;
return value;
}
Is certainly wrong. I think switching the first two lines should do the trick |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | I'd do it this way:
```
public class FibonacciAlgorithm {
private int a = 0;
private int b = 1;
public FibonacciAlgorithm() {
}
public int increment() {
int temp = b;
b = a + b;
a = temp;
return value;
}
public int getValue() {
return b;
}
}... | There was a recursive solution posted above, but this solution is tail recursive so it grows linearly.
```
public class Fibonacci {
public long fibonacci(int number) {
return fib(0,1,number);
}
private long fib(long result, long next, int n) {
if (n == 0)
return result;
... |
1,045,151 | I really suck at math. I mean, I REALLY suck at math.
I'm trying to make a simple fibonacci sequence class for an algorithm I'll be using. I have seen the python example which looks something like this:
```
a = 0
b = 1
while b < 10:
print b
a, b = b, b+a
```
The problem is that I can't really make this work... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1045151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/128967/"
] | Java integers can only store the first 46 Fibonacci numbers, use a lookup table. | The main problem with your Python-to-Java translation is that Python's assignment statement up there is executed all at once, while Java's are executed serially. Python's statement is equivalent to saying this:
```
Make a list out of 'b' and 'a + b'
Make another list out of references to 'a' and 'b'
Assign all the ele... |
65,347,497 | What improvements can I make to my python pandas code to make it more efficient? For my case, I have this dataframe
```
In [1]: df = pd.DataFrame({'PersonID': [1, 1, 1, 2, 2, 2, 3, 3, 3],
'Name': ["Jan", "Jan", "Jan", "Don", "Don", "Don", "Joe", "Joe", "Joe"],
'Lab... | 2020/12/17 | [
"https://Stackoverflow.com/questions/65347497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14557333/"
] | It seems like you can filter by the grouped `idxmin` regardless of sorted order and update `RuleNumber` based on that. You can use `loc`, `np.where`, `mask`, or `where` as follows:
```
df.loc[df.groupby(['PersonID', 'Name', 'RuleID'])['RuleNumber'].idxmin(), 'Label'] = 'MAIN'
```
OR with `np.where` as you were tryin... | Use `duplicated` on PersonID:
```
df.loc[~df['PersonID'].duplicated(),'Label'] = 'MAIN'
print(df)
```
Output:
```
PersonID Name Label RuleID RuleNumber
0 1 Jan MAIN 55 3
1 1 Jan REL 55 4
2 1 Jan REL 55 5
3 2 Don MAIN 3... |
65,347,497 | What improvements can I make to my python pandas code to make it more efficient? For my case, I have this dataframe
```
In [1]: df = pd.DataFrame({'PersonID': [1, 1, 1, 2, 2, 2, 3, 3, 3],
'Name': ["Jan", "Jan", "Jan", "Don", "Don", "Don", "Joe", "Joe", "Joe"],
'Lab... | 2020/12/17 | [
"https://Stackoverflow.com/questions/65347497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14557333/"
] | ```
import pandas as pd
df = pd.DataFrame({'PersonID': [1, 1, 1, 2, 2, 2, 3, 3, 3],
'Name': ["Jan", "Jan", "Jan", "Don", "Don", "Don", "Joe", "Joe", "Joe"],
'Label': ["REL", "REL", "REL", "REL", "REL", "REL", "REL", "REL", "REL"],
'RuleID': [55, 55, 55, 3, 3, 3, 10, 10, 10],
'RuleNumber': [3, 4, 5, 1, 2, 3, 234, 567, ... | Use `duplicated` on PersonID:
```
df.loc[~df['PersonID'].duplicated(),'Label'] = 'MAIN'
print(df)
```
Output:
```
PersonID Name Label RuleID RuleNumber
0 1 Jan MAIN 55 3
1 1 Jan REL 55 4
2 1 Jan REL 55 5
3 2 Don MAIN 3... |
73,504,727 | hi i want to make a class in python then import the class in another python file in python
we have a file called `squaretypes` that has a class called `Square` then its imported in `class2` but when i want to import the python file and then use `Square` but it gives an error
note: i am using jupyter notebook
error:
... | 2022/08/26 | [
"https://Stackoverflow.com/questions/73504727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19542186/"
] | "types" is the name of a standard library in python: <https://docs.python.org/3/library/types.html>
Rename your file to something different, e.g. "squaretype.py". | you should try to do following things
**- You can rename the name of classes**
* **if the above technic doesn't work just create an object without main in global and import it in the second python file . it will be imported with the values and functions, but you have to do some change in functions as well** |
38,736,721 | We have a scenario where we have to authenticate the user with LDAP server
Flow 1:
```
client --> application server --> LDAP server
```
In above flow the client enters LDAP credentials which comes to application server and then using python-ldap we can authenticate the user, straight forward. Since the user LDAP c... | 2016/08/03 | [
"https://Stackoverflow.com/questions/38736721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1207003/"
] | If you don't want user credentials to reach the Application server then what you need is a perimeter authentication. You need to have an external authentication provider , say Oracle Access Manager, that will perform the authentication and set a certain token in the request. The application server can assert this token... | Ory Hydra <https://ory.sh/hydra> might be what the original poster was asking for. This question is several years old now but in the interest of helping anyone else who sees this...check out Ory Hydra. It provides the OAuth2/OpenID parts and can be linked to an LDAP server behind the scenes. |
38,736,721 | We have a scenario where we have to authenticate the user with LDAP server
Flow 1:
```
client --> application server --> LDAP server
```
In above flow the client enters LDAP credentials which comes to application server and then using python-ldap we can authenticate the user, straight forward. Since the user LDAP c... | 2016/08/03 | [
"https://Stackoverflow.com/questions/38736721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1207003/"
] | If you don't want user credentials to reach the Application server then what you need is a perimeter authentication. You need to have an external authentication provider , say Oracle Access Manager, that will perform the authentication and set a certain token in the request. The application server can assert this token... | canaille is a free and light OAuth2/OpenID service over a LDAP backend, written in python. *(canaille developper here)*
<https://gitlab.com/yaal/canaille> |
10,296,483 | ```
class Item(models.Model):
name = models.CharField(max_length = 200)
image = models.ImageField(upload_to = 'read', blank=True)
creative_url = models.CharField(max_length = 200)
description = RichTextField()
def save(self, *args, **kwargs):
content = urllib2.urlopen(self.creative_url).rea... | 2012/04/24 | [
"https://Stackoverflow.com/questions/10296483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126545/"
] | Instead of `File`, you need to use [`django.core.files.base.ContentFile`](https://docs.djangoproject.com/en/1.4/ref/files/file/#the-contentfile-class)
```
self.image.save("test.jpg", ContentFile(content), save=False)
```
`File` accepts file object or `StringIO` object having `size` property or you need to manually s... | Try something like:
-------------------
(As supposed at: [Programmatically saving image to Django ImageField](https://stackoverflow.com/questions/1308386/programmatically-saving-image-to-django-imagefield))
```
from django.db import models
from django.core.files.base import ContentFile
import urllib2
from PIL import ... |
10,296,483 | ```
class Item(models.Model):
name = models.CharField(max_length = 200)
image = models.ImageField(upload_to = 'read', blank=True)
creative_url = models.CharField(max_length = 200)
description = RichTextField()
def save(self, *args, **kwargs):
content = urllib2.urlopen(self.creative_url).rea... | 2012/04/24 | [
"https://Stackoverflow.com/questions/10296483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126545/"
] | Try something like:
-------------------
(As supposed at: [Programmatically saving image to Django ImageField](https://stackoverflow.com/questions/1308386/programmatically-saving-image-to-django-imagefield))
```
from django.db import models
from django.core.files.base import ContentFile
import urllib2
from PIL import ... | solution using **requests**
```
from django.core.files.base import ContentFile
from requests import request, HTTPError
def save(self, *args, **kwargs):
try:
data = request('GET', self.creative_url,)
data.raise_for_status()
self.image.save('fname.jpg', ContentFile(data.content),save=False)
... |
10,296,483 | ```
class Item(models.Model):
name = models.CharField(max_length = 200)
image = models.ImageField(upload_to = 'read', blank=True)
creative_url = models.CharField(max_length = 200)
description = RichTextField()
def save(self, *args, **kwargs):
content = urllib2.urlopen(self.creative_url).rea... | 2012/04/24 | [
"https://Stackoverflow.com/questions/10296483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126545/"
] | Instead of `File`, you need to use [`django.core.files.base.ContentFile`](https://docs.djangoproject.com/en/1.4/ref/files/file/#the-contentfile-class)
```
self.image.save("test.jpg", ContentFile(content), save=False)
```
`File` accepts file object or `StringIO` object having `size` property or you need to manually s... | solution using **requests**
```
from django.core.files.base import ContentFile
from requests import request, HTTPError
def save(self, *args, **kwargs):
try:
data = request('GET', self.creative_url,)
data.raise_for_status()
self.image.save('fname.jpg', ContentFile(data.content),save=False)
... |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | Your question was not clear, I assume that you will have multiple rows and multiple elements. There is my solution according to what I understand.
```
payload.rows.forEach(x=> x.elements.forEach(y => console.log(y.distance.value)))
``` | ```
var payload = JSON.parse(body);
console.log(payload.rows[0]["elements"][0].distance.value);
``` |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | Try like below
```js
var body = {
"destination_addresses": ["XXXXXXXX 60, 13XXX Berlin, Germany"],
"origin_addresses": ["XXXXXXX Str. 67, 10XXX Berlin, Germany"],
"rows": [{
"elements": [{
"distance": {
"text": "10.4 km",
"value": 10365
},
"duration": {
"text": "21 m... | ```
var payload = JSON.parse(body);
console.log(payload.rows[0]["elements"][0].distance.value);
``` |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | I don't know exactly what you want, but you can get the distance object with something like that:
```js
const payload = {
"destination_addresses": [
"XXXXXXXX 60, 13XXX Berlin, Germany"
],
"origin_addresses": [
"XXXXXXX Str. 67, 10XXX Berlin, Germany"
],
"rows": [
{
"elements": [
{
... | ```
var payload = JSON.parse(body);
console.log(payload.rows[0]["elements"][0].distance.value);
``` |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | ```
let distance = payload.rows[0].elements[0].distance.value
console.log(payload)
console.log(distance)
```
Please note that the data is a mix of nested arrays and objects, which are different data structures in javascript. You can access an object's property by typing its name followed by a dot and the name of the ... | ```
var payload = JSON.parse(body);
console.log(payload.rows[0]["elements"][0].distance.value);
``` |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | ```
let distance = payload.rows[0].elements[0].distance.value
console.log(payload)
console.log(distance)
```
Please note that the data is a mix of nested arrays and objects, which are different data structures in javascript. You can access an object's property by typing its name followed by a dot and the name of the ... | Your question was not clear, I assume that you will have multiple rows and multiple elements. There is my solution according to what I understand.
```
payload.rows.forEach(x=> x.elements.forEach(y => console.log(y.distance.value)))
``` |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | ```
let distance = payload.rows[0].elements[0].distance.value
console.log(payload)
console.log(distance)
```
Please note that the data is a mix of nested arrays and objects, which are different data structures in javascript. You can access an object's property by typing its name followed by a dot and the name of the ... | Try like below
```js
var body = {
"destination_addresses": ["XXXXXXXX 60, 13XXX Berlin, Germany"],
"origin_addresses": ["XXXXXXX Str. 67, 10XXX Berlin, Germany"],
"rows": [{
"elements": [{
"distance": {
"text": "10.4 km",
"value": 10365
},
"duration": {
"text": "21 m... |
65,009,888 | I wrote a python script (with pandas library) to create txt files. I also use a txt file as an input. It works well but I want to make it more automated.
My code starts like;
```
girdi = input("Lütfen gir: ")
input2 = girdi+".txt"
veriCNR = pd.read_table(
input2, decimal=",",
usecols=[
"Chromosome",
... | 2020/11/25 | [
"https://Stackoverflow.com/questions/65009888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570497/"
] | ```
let distance = payload.rows[0].elements[0].distance.value
console.log(payload)
console.log(distance)
```
Please note that the data is a mix of nested arrays and objects, which are different data structures in javascript. You can access an object's property by typing its name followed by a dot and the name of the ... | I don't know exactly what you want, but you can get the distance object with something like that:
```js
const payload = {
"destination_addresses": [
"XXXXXXXX 60, 13XXX Berlin, Germany"
],
"origin_addresses": [
"XXXXXXX Str. 67, 10XXX Berlin, Germany"
],
"rows": [
{
"elements": [
{
... |
14,659,118 | <http://pypi.python.org/pypi/pylinkgrammar>
I am encountering an error when attempting to install pylinkgrammar:
```
Running setup.py egg_info for package pylinkgrammar
Installing collected packages: pylinkgrammar
Running setup.py install for pylinkgrammar
...
running build_ext
building 'pylinkgrammar/_clinkgramm... | 2013/02/02 | [
"https://Stackoverflow.com/questions/14659118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2011567/"
] | Besides installing the liblink-grammar4 package also install liblink-grammar4-dev package which is available in synaptic.
I had been grappling with the same for over an hour and it worked for me | You first need to install the liblink-grammar4 library:
If you're on ubuntu system, you can run:
```
sudo apt-add-repository ppa:python-pylinkgrammar/getsome
sudo apt-get install liblink-grammar4
```
If you're on a different flavor of linux, just make sure `liblink-grammar4` is installed. |
14,659,118 | <http://pypi.python.org/pypi/pylinkgrammar>
I am encountering an error when attempting to install pylinkgrammar:
```
Running setup.py egg_info for package pylinkgrammar
Installing collected packages: pylinkgrammar
Running setup.py install for pylinkgrammar
...
running build_ext
building 'pylinkgrammar/_clinkgramm... | 2013/02/02 | [
"https://Stackoverflow.com/questions/14659118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2011567/"
] | This worked for me:
```
sudo apt-get install liblink-grammar4-dev
``` | You first need to install the liblink-grammar4 library:
If you're on ubuntu system, you can run:
```
sudo apt-add-repository ppa:python-pylinkgrammar/getsome
sudo apt-get install liblink-grammar4
```
If you're on a different flavor of linux, just make sure `liblink-grammar4` is installed. |
14,659,118 | <http://pypi.python.org/pypi/pylinkgrammar>
I am encountering an error when attempting to install pylinkgrammar:
```
Running setup.py egg_info for package pylinkgrammar
Installing collected packages: pylinkgrammar
Running setup.py install for pylinkgrammar
...
running build_ext
building 'pylinkgrammar/_clinkgramm... | 2013/02/02 | [
"https://Stackoverflow.com/questions/14659118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2011567/"
] | You first need to install the liblink-grammar4 library:
If you're on ubuntu system, you can run:
```
sudo apt-add-repository ppa:python-pylinkgrammar/getsome
sudo apt-get install liblink-grammar4
```
If you're on a different flavor of linux, just make sure `liblink-grammar4` is installed. | This might be helpful
```
sudo apt-get install liblink-grammar4-dev cmake swig
sudo pip install pylinkgrammar
``` |
14,659,118 | <http://pypi.python.org/pypi/pylinkgrammar>
I am encountering an error when attempting to install pylinkgrammar:
```
Running setup.py egg_info for package pylinkgrammar
Installing collected packages: pylinkgrammar
Running setup.py install for pylinkgrammar
...
running build_ext
building 'pylinkgrammar/_clinkgramm... | 2013/02/02 | [
"https://Stackoverflow.com/questions/14659118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2011567/"
] | Besides installing the liblink-grammar4 package also install liblink-grammar4-dev package which is available in synaptic.
I had been grappling with the same for over an hour and it worked for me | This might be helpful
```
sudo apt-get install liblink-grammar4-dev cmake swig
sudo pip install pylinkgrammar
``` |
14,659,118 | <http://pypi.python.org/pypi/pylinkgrammar>
I am encountering an error when attempting to install pylinkgrammar:
```
Running setup.py egg_info for package pylinkgrammar
Installing collected packages: pylinkgrammar
Running setup.py install for pylinkgrammar
...
running build_ext
building 'pylinkgrammar/_clinkgramm... | 2013/02/02 | [
"https://Stackoverflow.com/questions/14659118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2011567/"
] | This worked for me:
```
sudo apt-get install liblink-grammar4-dev
``` | This might be helpful
```
sudo apt-get install liblink-grammar4-dev cmake swig
sudo pip install pylinkgrammar
``` |
58,614,691 | im trying to login into my google account using python selenium with chromedriver,
the code works but not in headless mode. in hm i get the the identifierId never appears :(
EDIT: added missing --disable-gpu
```py
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.a... | 2019/10/29 | [
"https://Stackoverflow.com/questions/58614691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7419986/"
] | You also have to add `--disable-gpu` to your chrome options.
```
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument('--disable-gpu')
```
That's what I had to add to get my headless code fully working. | This code works in headless mode but not with gui enabled
```py
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--window-size=1920,1080')
def do_login(email, password):
driver = webdriver.Chrome(chrome_o... |
58,614,691 | im trying to login into my google account using python selenium with chromedriver,
the code works but not in headless mode. in hm i get the the identifierId never appears :(
EDIT: added missing --disable-gpu
```py
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.a... | 2019/10/29 | [
"https://Stackoverflow.com/questions/58614691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7419986/"
] | I always pass below arguments, Tested and works:
```
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--... | This code works in headless mode but not with gui enabled
```py
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--window-size=1920,1080')
def do_login(email, password):
driver = webdriver.Chrome(chrome_o... |
21,513,899 | I am trying to store the following info in a python list but the strip function isnt working
```
u'Studio', u'5', u'550.00 SqFt', u'No', u'Agent', u'Quarterly', u'Mediterranean Buildings (38-107)', u'Central A/C & Heating\n , \n ... | 2014/02/02 | [
"https://Stackoverflow.com/questions/21513899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1928163/"
] | You can remove internal spaces from string by regular expression:
```
import re
text_result = re.sub('\s+',' ', text_input)
```
*EDIT:*
You can even apply this function to every item in your list:
```
list_result = [re.sub("\s+", " ",x) for x in list_input]
``` | You have a list of strings (which you have left the opening brace off of).
You have one *really* ungainly string in index 7 of that list.
You just need to clean that one up. So:
```
li = [u'Studio', u'5', u'550.00 SqFt', u'No', u'Agent', u'Quarterly', u'Mediterranean Buildings (38-107)', u'Central A/C & Heating\n ... |
21,513,899 | I am trying to store the following info in a python list but the strip function isnt working
```
u'Studio', u'5', u'550.00 SqFt', u'No', u'Agent', u'Quarterly', u'Mediterranean Buildings (38-107)', u'Central A/C & Heating\n , \n ... | 2014/02/02 | [
"https://Stackoverflow.com/questions/21513899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1928163/"
] | You can remove internal spaces from string by regular expression:
```
import re
text_result = re.sub('\s+',' ', text_input)
```
*EDIT:*
You can even apply this function to every item in your list:
```
list_result = [re.sub("\s+", " ",x) for x in list_input]
``` | the strip functions helps you to do something like
```
uns=' this line has extra white spaces '
strv=uns.strip()
#str now has 'this line has extra white spaces'
```
if you want to store striped string to a list you can iterate the list like this
```
pos=0
while pos < len(thelist):
thevalue=thelist[pos]
clea... |
62,228,457 | I'm trying to increase the efficiency of a non-conformity management program. Basically, I have a database containing about a few hundred rows, each row describes a non-conformity using a text field.
Text is provided in Italian and I have no control over what the user writes.
I'm trying to write a python program using ... | 2020/06/06 | [
"https://Stackoverflow.com/questions/62228457",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10511191/"
] | Thank's to Anurag Wagh advice I figured it out.
I used [this tutorial](https://www.machinelearningplus.com/nlp/gensim-tutorial/) about gensim and how to use it in many ways.
[Chapter 18](https://www.machinelearningplus.com/nlp/gensim-tutorial/#18howtocomputesimilaritymetricslikecosinesimilarityandsoftcosinesimilarity)... | Perhaps converting document to vectors and the computing distance between two vectors would be helpful
[doc2vec](https://radimrehurek.com/gensim/auto_examples/tutorials/run_doc2vec_lee.html#sphx-glr-auto-examples-tutorials-run-doc2vec-lee-py) can be helpful over here |
60,621,433 | pip install has suddenly stopped working - unsure if related to recent update. I've tried it both on pip 19.0.3 and pip.20.0.2
When using:
```
python -m pip install matplotlib --user
```
I get an error like this
```
PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\Python37\\Lib\\site-packages\\acc... | 2020/03/10 | [
"https://Stackoverflow.com/questions/60621433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9988108/"
] | Using:
```
python -m pip install matplotlib
```
worked | I suspect you need to run your terminal as an administrator-elevated account to access the restricted resource. |
31,714,060 | For one of my assignments, rather than reading directly from a text file, we are directly taking the input from `sys.in`. I was wondering what the best way of obtaining this input and storing it would be?
So far, I've tried using:
`sys.stdin.readlines()` -- But this will not terminate unless it recieves an EOF stateme... | 2015/07/30 | [
"https://Stackoverflow.com/questions/31714060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5171552/"
] | Looks like a typo. You use thread1 in both calls to pthread\_create.
```
iret1 = pthread_create( &thread1, 0, print_message_function1, (void*) message1);
iret2 = pthread_create( &thread1, 0, print_message_function2, (void*) message2);
```
So `pthread_join(thread2, 0);` is pretty much doomed. | This is really just **relevant information**, not an answer as such, but unfortunately SO does not support code in comments.
The problem that you *noticed* with your code was a simple typo, but I didn't see that until I read the now [accepted answer](https://stackoverflow.com/a/31714197/464581). For, I sat down and re... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | If you want to color fill a specific cell in a table you can use the code below.
For example let's say you need to fill the first cell in the first row of your table with the RGB color 1F5C8B:
```
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
shading_elm_1 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/... | With Nikos Tavoularis' solution, we have to create a new element for every cell.
I have created a function that achieves this. Works in Python revision 3.5.6 and python-docx revision 0.8.10
```
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
def set_table_header_bg_color(table.rows[row_ix].cell):
""... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | What we found is that, if you do cell.add\_paragraph('sometext', style\_object), it will keep the existing empty paragraph and add an additional paragraph with the style, which is not ideal.
What you will want to do is something like:
```
# replace the entire content of cell with new text paragraph
cell.text = 'some ... | Taking from Nikos Tavoularis answer I would just change the shading\_elm\_1 declaration, as if you include the cell color in a loop for instance things might get messy.
As such, my suggestion would be:
```
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
table.rows[0].cells[0]._tc.get_or_add_tcPr().a... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | If you want to color fill a specific cell in a table you can use the code below.
For example let's say you need to fill the first cell in the first row of your table with the RGB color 1F5C8B:
```
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
shading_elm_1 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/... | What we found is that, if you do cell.add\_paragraph('sometext', style\_object), it will keep the existing empty paragraph and add an additional paragraph with the style, which is not ideal.
What you will want to do is something like:
```
# replace the entire content of cell with new text paragraph
cell.text = 'some ... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | If you want to color fill a specific cell in a table you can use the code below.
For example let's say you need to fill the first cell in the first row of your table with the RGB color 1F5C8B:
```
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
shading_elm_1 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/... | If you want to loop through the cells in a row use:
```
def color_row(row=0):
'make row of cells background colored, defaults to column header row'
row = t.rows[row]
for cell in row.cells:
shading_elm_2 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/>'.format(nsdecls('w')))
cell._tc.get_or_add_tcP... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | What we found is that, if you do cell.add\_paragraph('sometext', style\_object), it will keep the existing empty paragraph and add an additional paragraph with the style, which is not ideal.
What you will want to do is something like:
```
# replace the entire content of cell with new text paragraph
cell.text = 'some ... | I made a video demonstrating a way to do it here I took inspiration from the people above but I still had issues so I made this too help others.
<https://www.youtube.com/watch?v=1Mgb95yigkk&list=PL_W7lgC2xeJfWBUllp7ALKOM5GUBMCVoP>
```
from docx import Document
from docx.oxml import OxmlElement
from docx.o... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | It looks like instead of using the `cell.text = "Something"` method you need to use the `cell.add_paragraph("SomeText", a_style)` with a defined style - probably one of:
* ColorfulGrid
* ColorfulGrid-Accent1
* ColorfulGrid-Accent2
* ColorfulGrid-Accent3
* ColorfulGrid-Accent4
* ColorfulGrid-Accent5
* ColorfulGrid-Acce... | I made a video demonstrating a way to do it here I took inspiration from the people above but I still had issues so I made this too help others.
<https://www.youtube.com/watch?v=1Mgb95yigkk&list=PL_W7lgC2xeJfWBUllp7ALKOM5GUBMCVoP>
```
from docx import Document
from docx.oxml import OxmlElement
from docx.o... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | It looks like instead of using the `cell.text = "Something"` method you need to use the `cell.add_paragraph("SomeText", a_style)` with a defined style - probably one of:
* ColorfulGrid
* ColorfulGrid-Accent1
* ColorfulGrid-Accent2
* ColorfulGrid-Accent3
* ColorfulGrid-Accent4
* ColorfulGrid-Accent5
* ColorfulGrid-Acce... | I have compiled the previous answers and added some features.
Feel free to test: Create new file run the "main" part at the bottom.
```
""" adder for python-docx in order to change text style in tables:
font color, italic, bold
cell background color
based on answers on
https://stackoverflow.com/questions/26752856/pyth... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | It looks like instead of using the `cell.text = "Something"` method you need to use the `cell.add_paragraph("SomeText", a_style)` with a defined style - probably one of:
* ColorfulGrid
* ColorfulGrid-Accent1
* ColorfulGrid-Accent2
* ColorfulGrid-Accent3
* ColorfulGrid-Accent4
* ColorfulGrid-Accent5
* ColorfulGrid-Acce... | Taking from Nikos Tavoularis answer I would just change the shading\_elm\_1 declaration, as if you include the cell color in a loop for instance things might get messy.
As such, my suggestion would be:
```
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
table.rows[0].cells[0]._tc.get_or_add_tcPr().a... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | I made a video demonstrating a way to do it here I took inspiration from the people above but I still had issues so I made this too help others.
<https://www.youtube.com/watch?v=1Mgb95yigkk&list=PL_W7lgC2xeJfWBUllp7ALKOM5GUBMCVoP>
```
from docx import Document
from docx.oxml import OxmlElement
from docx.o... | If you want to loop through the cells in a row use:
```
def color_row(row=0):
'make row of cells background colored, defaults to column header row'
row = t.rows[row]
for cell in row.cells:
shading_elm_2 = parse_xml(r'<w:shd {} w:fill="1F5C8B"/>'.format(nsdecls('w')))
cell._tc.get_or_add_tcP... |
26,752,856 | I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.
I could not find any usefull resources about single cell formatting
Any suggestions?
Edit 1
my code
```
style_footer = "DarkList"
style_red = "ColorfulList"
style_yellow = "LightShadin... | 2014/11/05 | [
"https://Stackoverflow.com/questions/26752856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945446/"
] | With Nikos Tavoularis' solution, we have to create a new element for every cell.
I have created a function that achieves this. Works in Python revision 3.5.6 and python-docx revision 0.8.10
```
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
def set_table_header_bg_color(table.rows[row_ix].cell):
""... | If you want to change the text color too, you can set it on the runs within the cell. I wrote this function to handle the cell background and text colors together (using Nikos' method for the fill):
```
def shade_cell(cell, fill=None, color=None):
if fill:
shading_elm = parse_xml(r'<w:shd {} w:fill="{}"/>... |
66,310,704 | ```
Python 3.8.3
asgiref 3.3.1
Django 2.2
django-crispy-forms 1.10.0
djangorestframework 3.11.1
Pillow 7.2.0
pip 19.2.3
psycopg2 2.8.6
pytz 2020.1
setuptools 41.2.0
sqlparse 0.3.1
```
Sorry, I'm not sure where there is... | 2021/02/22 | [
"https://Stackoverflow.com/questions/66310704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15011706/"
] | where you import your models.py in your views.py?
just import your models file in your views and then you will be able to access your models classes in your views file.
something just like this:
```
from <models_directory> import models
def updateItem(request):
data = json.loads(request.body)
productId = data... | make sure you did not define class name or function or varible with same name |
25,709,478 | If I shuffle a small list using [python's `random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle), I'm getting also unshuffled results.
```
import random
for i in range(10):
ori = [1, 2, 3]
per = ori[:]
random.shuffle(per)
print i, per, (per == ori) or ""
```
Here is a sampl... | 2014/09/07 | [
"https://Stackoverflow.com/questions/25709478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2932052/"
] | If you must exclude the original ordering, you could simply retry the shuffle until `per != ori`. | Since it's a short array do a quick shuffle manually:
```
import random
for i in range(len(ori) - 1):
j = random.randint(i + 1, len(ori) - 1)
ori[i], ori[j] = ori[j], ori[i]
```
This way you will ensure that you won't get the original array. This is an `O(n)` solution, you should only use it on small arrays... |
25,709,478 | If I shuffle a small list using [python's `random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle), I'm getting also unshuffled results.
```
import random
for i in range(10):
ori = [1, 2, 3]
per = ori[:]
random.shuffle(per)
print i, per, (per == ori) or ""
```
Here is a sampl... | 2014/09/07 | [
"https://Stackoverflow.com/questions/25709478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2932052/"
] | Well one way would be generate permutations of the list and then drop the first item. After that you can use `random.choice` to pick any of the permutation:
```
>>> from random import choice
>>> from itertools import permutations
>>> data = list(permutations([1, 2, 3], 3))[1:]
>>> for _ in range(10):
... print cho... | Since it's a short array do a quick shuffle manually:
```
import random
for i in range(len(ori) - 1):
j = random.randint(i + 1, len(ori) - 1)
ori[i], ori[j] = ori[j], ori[i]
```
This way you will ensure that you won't get the original array. This is an `O(n)` solution, you should only use it on small arrays... |
42,136,431 | I'm using Active directory with windows server 2008 R2. I have an application running with Django and python 2.7. Now I need to use active directory authentication to access into my application.
To do that, i'm using this packages:
```
sudo apt-get-update
sudo apt-get install python-dev libldap2-dev libsasl2-dev libs... | 2017/02/09 | [
"https://Stackoverflow.com/questions/42136431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787419/"
] | You can't use the cn value in your simple\_bind(). Use the alternate user principal name `sAMAccountName@FQDN` instead, or one of the other [supported bind names](https://msdn.microsoft.com/en-us/library/cc223499.aspx). | @marabu, thanks for the reply. You're right, ican't use any editor attribute (like cn, ....) in the simple bind.
we have an access to this attribute only by search method after having a successfull bind.
In my case i have two choices:
1) simple\_bind\_s(full\_name, password)
2) simple\_bind\_s(sAMAccountName@FQDN, p... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.