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 |
|---|---|---|---|---|---|
55,975,930 | I'm locally running a standard app engine environment through dev\_appserver and cannot get rid of the following error:
>
> ImportError: No module named google.auth
>
>
>
Full traceback (replaced personal details with `...`):
```
Traceback (most recent call last):
File "/Users/.../google-cloud-sdk/platform/goo... | 2019/05/03 | [
"https://Stackoverflow.com/questions/55975930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3793914/"
] | Your `google.auth` is installed in the system's Python site packages, not in your app:
>
> Location: /Users/.../Library/Python/2.7/lib/python/site-packages
>
>
>
You need to install your app's python dependencies inside your app instead - note the `-t lib/` pip option in the [Copying a third-party library](https:... | After much trial and error, I found the bug: A python runtime version issue.
In my app.yaml file I had specified:
```
service: default
runtime: python27
api_version: 1
threadsafe: false
```
There I changed runtime to:
```
runtime: python37
```
Thanks to @AlassaneNdiaye for pointing me in this direction in the co... |
56,317,630 | I am new in python and I am working with CSV file with over 10000 rows. In my CSV file, there are many rows with the same id which I would like to merge them in one and also combine their information as well.
For instance, the data.csv look like (id and info is the name of columns):
```
id| info
1112| storage is fu... | 2019/05/26 | [
"https://Stackoverflow.com/questions/56317630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8921989/"
] | I think about some simplier way:
```
some_dict = {}
for idt, txt in line: #~ For line use your id, info reader.
some_dict[idt] = some_dict.get(idt, "") + txt
```
It should create your dream structure without imports, and i hope most efficient way.
Just to understand, `get` have secound argument, what must retur... | Just make a dictionary where id's are keys:
```
from collections import defaultdict
by_id = defaultdict(list)
for id, info in your_list:
by_id[id].append(info)
for key, value in by_id.items():
print(key, value)
``` |
25,012,031 | I've migrated a Liferay 6.2-CE-GA2 server from Liferay 6.1.1-ce-ga2.
I made a few changes in custom hooks and themes to addapt to the new version.
On locale I have never had a problem with memory nor with the 6.1 version, but once in production, server runs out of memory in a few hours.
I tried to adjust heap parame... | 2014/07/29 | [
"https://Stackoverflow.com/questions/25012031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3837065/"
] | As it seems the `open`-method doesn't update the `position` of the `infowindow`, you'll need to do it on your own(e.g. by binding the position of the infowindow to the position of the marker):
```
infowindow.unbind('position');
if(infowindow.getPosition() != this.getPosition()) {
infowindow.bindTo('pos... | I am not sure about `infowindow.getPosition()` . But you can try this code if you want to check whether the infowindow is open or not.
JS:
```
function check(infoWindow) {
var map = infoWindow.getMap();
return (map !== null && typeof map !== "undefined");
}
```
pass `infowindow` into the function and it wil... |
25,012,031 | I've migrated a Liferay 6.2-CE-GA2 server from Liferay 6.1.1-ce-ga2.
I made a few changes in custom hooks and themes to addapt to the new version.
On locale I have never had a problem with memory nor with the 6.1 version, but once in production, server runs out of memory in a few hours.
I tried to adjust heap parame... | 2014/07/29 | [
"https://Stackoverflow.com/questions/25012031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3837065/"
] | As it seems the `open`-method doesn't update the `position` of the `infowindow`, you'll need to do it on your own(e.g. by binding the position of the infowindow to the position of the marker):
```
infowindow.unbind('position');
if(infowindow.getPosition() != this.getPosition()) {
infowindow.bindTo('pos... | Apparently the google.maps.InfoWindow won't have a position unless you set one, if I do this:
```
var infowindow = new google.maps.InfoWindow({
content: '<div id="content">test</div>',
position: new google.maps.LatLng(0,0)
});
```
[fiddle](http://jsfiddle.net/5yj2a/25/)
or:
```
var infowindow = new google.... |
17,066,347 | I have this issue with Titanium Studio. I can't compile my project for Android. I try to Run or Debug to project, but I've got this message:
```
Titanium Command-Line Interface, CLI version 3.1.0, Titanium SDK version 3.1.0.GA
Copyright (c) 2012-2013, Appcelerator, Inc. All Rights Reserved.
[INFO] : Running emulato... | 2013/06/12 | [
"https://Stackoverflow.com/questions/17066347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/486286/"
] | If this happens with the Kitchen Sink demo, the fix is to go into the Android SDK Manager and install "Android 3.0 (API 11)". Make sure the app uses emulator "Google APIs (Android 2.3.3)" and "WVGA854". I assume there's a Titanium bug because you have to install a higher API level (3.0) than is actually used (2.3.3). U... | Did you read [System Requirements](http://docs.appcelerator.com/titanium/latest/#!/guide/Quick_Start-section-29004949_QuickStart-SystemRequirements)?
From Documentation:
>
> For Windows, the 32-bit version of Java JDK is required regardless of
> whether Titanium is running on a 32-bit or 64-bit system.
>
>
>
Try... |
17,066,347 | I have this issue with Titanium Studio. I can't compile my project for Android. I try to Run or Debug to project, but I've got this message:
```
Titanium Command-Line Interface, CLI version 3.1.0, Titanium SDK version 3.1.0.GA
Copyright (c) 2012-2013, Appcelerator, Inc. All Rights Reserved.
[INFO] : Running emulato... | 2013/06/12 | [
"https://Stackoverflow.com/questions/17066347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/486286/"
] | If this happens with the Kitchen Sink demo, the fix is to go into the Android SDK Manager and install "Android 3.0 (API 11)". Make sure the app uses emulator "Google APIs (Android 2.3.3)" and "WVGA854". I assume there's a Titanium bug because you have to install a higher API level (3.0) than is actually used (2.3.3). U... | Answer 1 :
==========
Seems build tools got moved to another directory with the latest Android SDK update. Created symlinks to aapt and dx in /Applications/Android-sdk/platform-tools:
```
ln -s /Applications/Android-sdk/build-tools/17.0.0/aapt aapt ln -s /Applications/Android-sdk/build-tools/17.0.0/dx dx
```
This s... |
17,066,347 | I have this issue with Titanium Studio. I can't compile my project for Android. I try to Run or Debug to project, but I've got this message:
```
Titanium Command-Line Interface, CLI version 3.1.0, Titanium SDK version 3.1.0.GA
Copyright (c) 2012-2013, Appcelerator, Inc. All Rights Reserved.
[INFO] : Running emulato... | 2013/06/12 | [
"https://Stackoverflow.com/questions/17066347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/486286/"
] | If this happens with the Kitchen Sink demo, the fix is to go into the Android SDK Manager and install "Android 3.0 (API 11)". Make sure the app uses emulator "Google APIs (Android 2.3.3)" and "WVGA854". I assume there's a Titanium bug because you have to install a higher API level (3.0) than is actually used (2.3.3). U... | I had a similar problem, when I was trying to run a project on Android I got:
```
[ERROR] : Emulator process exited with code 1
[ERROR] : Build process exited with code 1
[ERROR] : Project failed to build after 234ms
[ERROR] Application Installer abnormal process termination. Process exit value was 1
```
I tried ... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | I had the same issue and just running the below command solved it for me:
```
easy_install pip
``` | The short answer is don't do this. Use `setup.py` or a straight import statement.
[Here is why this doesn't work with pip and how to get around it if necessary.](https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program)
`pip` affects the whole environment. Depending on who is running this and why, they ... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | pip Developers do not recommend calling pip from within the program.
And the pip.main() method has been removed from pip v10.
As an alternative method it is recommended to execute pip in subprocess.
<https://pip.pypa.io/en/stable/user_guide/?highlight=_internal#using-pip-from-your-program>
```
try:
import request... | I had the same issue and just running the below command solved it for me:
```
easy_install pip
``` |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | I had the same issue and just running the below command solved it for me:
```
easy_install pip
``` | The pip.main function was moved, not removed by pip devs. The highest voted solution here is not good. Going from python -> shell -> python is not a good practice when you can just run the python code direct. Try `from pip._internal import main` then you can use that main function to execute your pip calls like before. |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | I had the same issue and just running the below command solved it for me:
```
easy_install pip
``` | You can define a function to install a lib if needed. It is convenient.
```
#%%
# IMPORTS
import pip
def import_or_install(package):
try:
__import__(package)
except:
import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
_... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | pip Developers do not recommend calling pip from within the program.
And the pip.main() method has been removed from pip v10.
As an alternative method it is recommended to execute pip in subprocess.
<https://pip.pypa.io/en/stable/user_guide/?highlight=_internal#using-pip-from-your-program>
```
try:
import request... | The short answer is don't do this. Use `setup.py` or a straight import statement.
[Here is why this doesn't work with pip and how to get around it if necessary.](https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program)
`pip` affects the whole environment. Depending on who is running this and why, they ... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | The pip.main function was moved, not removed by pip devs. The highest voted solution here is not good. Going from python -> shell -> python is not a good practice when you can just run the python code direct. Try `from pip._internal import main` then you can use that main function to execute your pip calls like before. | The short answer is don't do this. Use `setup.py` or a straight import statement.
[Here is why this doesn't work with pip and how to get around it if necessary.](https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program)
`pip` affects the whole environment. Depending on who is running this and why, they ... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | pip Developers do not recommend calling pip from within the program.
And the pip.main() method has been removed from pip v10.
As an alternative method it is recommended to execute pip in subprocess.
<https://pip.pypa.io/en/stable/user_guide/?highlight=_internal#using-pip-from-your-program>
```
try:
import request... | The pip.main function was moved, not removed by pip devs. The highest voted solution here is not good. Going from python -> shell -> python is not a good practice when you can just run the python code direct. Try `from pip._internal import main` then you can use that main function to execute your pip calls like before. |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | pip Developers do not recommend calling pip from within the program.
And the pip.main() method has been removed from pip v10.
As an alternative method it is recommended to execute pip in subprocess.
<https://pip.pypa.io/en/stable/user_guide/?highlight=_internal#using-pip-from-your-program>
```
try:
import request... | You can define a function to install a lib if needed. It is convenient.
```
#%%
# IMPORTS
import pip
def import_or_install(package):
try:
__import__(package)
except:
import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
_... |
49,870,594 | I am trying to install few of the python packages from within a python script and I am using `pip.main(install)` for that. Below is code snippet
```
try:
import requests
except:
import pip
pip.main(['install', '-q', 'requests==2.0.1','PyYAML==3.11'])
import requests
```
I have tried using importing m... | 2018/04/17 | [
"https://Stackoverflow.com/questions/49870594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4943621/"
] | The pip.main function was moved, not removed by pip devs. The highest voted solution here is not good. Going from python -> shell -> python is not a good practice when you can just run the python code direct. Try `from pip._internal import main` then you can use that main function to execute your pip calls like before. | You can define a function to install a lib if needed. It is convenient.
```
#%%
# IMPORTS
import pip
def import_or_install(package):
try:
__import__(package)
except:
import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
_... |
3,215,455 | Is it possible to use multiple languages along side with ruby. For example, I have my application code in Ruby on Rails. I would like to calculate the recommendations and I would like to use python for that. So essentially, python code would get the data and calculate all the stuff and probably get the data from DB, ca... | 2010/07/09 | [
"https://Stackoverflow.com/questions/3215455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/88898/"
] | If you are offloading work to an exterior process, you may want to make this a webservice (ajax, perhaps) of some sort so that you have some sort of consistent interface.
Otherwise, you could always execute the python script in a subshell through ruby, using stdin/stdout/argv, but this can get ugly quick. | I would use the system command
as such
```
system("python myscript.py")
``` |
3,215,455 | Is it possible to use multiple languages along side with ruby. For example, I have my application code in Ruby on Rails. I would like to calculate the recommendations and I would like to use python for that. So essentially, python code would get the data and calculate all the stuff and probably get the data from DB, ca... | 2010/07/09 | [
"https://Stackoverflow.com/questions/3215455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/88898/"
] | If you are offloading work to an exterior process, you may want to make this a webservice (ajax, perhaps) of some sort so that you have some sort of consistent interface.
Otherwise, you could always execute the python script in a subshell through ruby, using stdin/stdout/argv, but this can get ugly quick. | An easy, quick 'n' dirty solution in case you have python scripts and you want to execute them from inside rails, is this:
`%x[shell commands or python path/of/pythonscript.py #{ruby variables to pass on the script}]`
or
``shell commands or python path/of/pythonscript.py #{ruby variables to pass on the script}`\` (w... |
3,215,455 | Is it possible to use multiple languages along side with ruby. For example, I have my application code in Ruby on Rails. I would like to calculate the recommendations and I would like to use python for that. So essentially, python code would get the data and calculate all the stuff and probably get the data from DB, ca... | 2010/07/09 | [
"https://Stackoverflow.com/questions/3215455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/88898/"
] | Depending on your exact needs, you can either call out to an external process (using popen, system, etc) or you can setup another mini-web-server or something along those lines and have the rails server communicate with it over HTTP with a REST-style API (or whatever best suits your needs).
In your example, you have a... | I would use the system command
as such
```
system("python myscript.py")
``` |
3,215,455 | Is it possible to use multiple languages along side with ruby. For example, I have my application code in Ruby on Rails. I would like to calculate the recommendations and I would like to use python for that. So essentially, python code would get the data and calculate all the stuff and probably get the data from DB, ca... | 2010/07/09 | [
"https://Stackoverflow.com/questions/3215455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/88898/"
] | Depending on your exact needs, you can either call out to an external process (using popen, system, etc) or you can setup another mini-web-server or something along those lines and have the rails server communicate with it over HTTP with a REST-style API (or whatever best suits your needs).
In your example, you have a... | An easy, quick 'n' dirty solution in case you have python scripts and you want to execute them from inside rails, is this:
`%x[shell commands or python path/of/pythonscript.py #{ruby variables to pass on the script}]`
or
``shell commands or python path/of/pythonscript.py #{ruby variables to pass on the script}`\` (w... |
48,160,819 | I want to write a python program to process csv sheets, the total numbers of rows and cols are different each time.
One of things I want to do is to delete columns containing a specific string.
```
import csv
input = open("1.csv","rb")
reader = csv.reader(input)
output = open("2.csv","wb")
writer = csv.writer(output)... | 2018/01/09 | [
"https://Stackoverflow.com/questions/48160819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9190725/"
] | You can find the column index with this code and can delete it. I test it ok
import csv
```
with open("SampleCSVFile_2kb.csv","rb") as source:
rdr= csv.reader( source )
with open("result","wb") as result:
wtr= csv.writer( result )
index = -1
for r in rdr:
for item in r:
... | Assume csv looks like
```
name,color,price
apple,red,10
banana,yellow,5
```
```
import csv
with open(file_path, "r") as f:
file = csv.reader(f)
for line in file:
print(line[0], line[1], line[2])
```
print out would be
```
name color price
apple red 10
banana yellow 5
``` |
48,892,348 | I have a for loop in python and at the end of each step I want the output to be added as a new column in a csv file. The output I have is a 40x1 array. So if the for loop consists of 100 steps, I want to have a csv file with 100 columns and 40 rows at the end. What I have now, at the end of each time step is the follow... | 2018/02/20 | [
"https://Stackoverflow.com/questions/48892348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6756920/"
] | The insight would be that when `serverUrl` is truthy, you don't need the `switch` at all - you always return the same value that was switched upon. So don't do the test in every switch `case`, but do it once before that:
```
function checkField(str: string) : string {
if (serverUrl === 'abc')
return str.to... | Borrowing a bit from @Bergi's answer, I would create a mapping object to make it a little cleaner. E.g.:
```
function checkField(str: string) : string {
//create a mapping
var myMapping = {
'code' : 'CODE',
'webid' : 'Webid',
'pkid' : 'PkId',
'barcode': 'Barcode',
... |
48,892,348 | I have a for loop in python and at the end of each step I want the output to be added as a new column in a csv file. The output I have is a 40x1 array. So if the for loop consists of 100 steps, I want to have a csv file with 100 columns and 40 rows at the end. What I have now, at the end of each time step is the follow... | 2018/02/20 | [
"https://Stackoverflow.com/questions/48892348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6756920/"
] | The insight would be that when `serverUrl` is truthy, you don't need the `switch` at all - you always return the same value that was switched upon. So don't do the test in every switch `case`, but do it once before that:
```
function checkField(str: string) : string {
if (serverUrl === 'abc')
return str.to... | You can put all the values in a map.
```
function checkField(String str) {
let map = new Map([["code", "CODE"], ["webid", "Webid"]]);
if (serverUrl === 'abc')
return str.toLowerCase();
else
return map[str]
}
``` |
28,334,966 | I am trying to open an Excel file (.xls) using xlrd. This is a summary of the code I am using:
```
import xlrd
workbook = xlrd.open_workbook('thefile.xls')
```
This works for most files, but fails for files I get from a specific organization. The error I get when I try to open Excel files from this organization foll... | 2015/02/05 | [
"https://Stackoverflow.com/questions/28334966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/382374/"
] | What are they using to generate that file ?
They are using some Java Excel API (see below, [link here](http://jexcelapi.sourceforge.net/)), probably on an IBM mainframe or similar.
From the stack trace the writeaccess information can't decoding into Unicode because the @ character.
For more information on the write... | This worked for me.
```
import xlrd
my_xls = xlrd.open_workbook('//myshareddrive/something/test.xls',encoding_override="gb2312")
``` |
21,867,596 | I'm a little new to web parsing in python. I am using beautiful soup. I would like to create a list by parsing strings from a webpage. I've looked around and can't seem to find the right answer. Doe anyone know how to create a list of strings from a web page? Any help is appreciated.
My code is something like this:
`... | 2014/02/18 | [
"https://Stackoverflow.com/questions/21867596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2278570/"
] | Having difficulty understanding what you are trying to achieve... If you want all values of `page_data.string` in `page_List`, then your code should look like this:
```
page_List = []
for page_data in page_find:
page_List.append(page_data.string)
```
Or using a list comprehension:
```
page_List = [page_data.str... | Here it is modified to call the web page as a string
```
import requests
the_web_page_as_a_string = requests.get(some_path).content
from lxml import html
myTree = html.fromstring(the_web_page_as_a_string)
td_list = [ e for e in myTree.iter() if e.tag == 'td']
text_list = []
for td_e in td_list:
text = td_e.text_c... |
21,867,596 | I'm a little new to web parsing in python. I am using beautiful soup. I would like to create a list by parsing strings from a webpage. I've looked around and can't seem to find the right answer. Doe anyone know how to create a list of strings from a web page? Any help is appreciated.
My code is something like this:
`... | 2014/02/18 | [
"https://Stackoverflow.com/questions/21867596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2278570/"
] | I'd recommend lxml over BeautifulSoup, when you start scraping alot of pages the speed advantage of lxml is hard to ignore.
```
import requests
import lxml.html
dom = lxml.html.fromstring(requests.get('http://www.any_url.com').content)
page_list = [x for x in dom.xpath('//td/text()')]
print page_list
``` | Here it is modified to call the web page as a string
```
import requests
the_web_page_as_a_string = requests.get(some_path).content
from lxml import html
myTree = html.fromstring(the_web_page_as_a_string)
td_list = [ e for e in myTree.iter() if e.tag == 'td']
text_list = []
for td_e in td_list:
text = td_e.text_c... |
21,867,596 | I'm a little new to web parsing in python. I am using beautiful soup. I would like to create a list by parsing strings from a webpage. I've looked around and can't seem to find the right answer. Doe anyone know how to create a list of strings from a web page? Any help is appreciated.
My code is something like this:
`... | 2014/02/18 | [
"https://Stackoverflow.com/questions/21867596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2278570/"
] | Having difficulty understanding what you are trying to achieve... If you want all values of `page_data.string` in `page_List`, then your code should look like this:
```
page_List = []
for page_data in page_find:
page_List.append(page_data.string)
```
Or using a list comprehension:
```
page_List = [page_data.str... | I'd recommend lxml over BeautifulSoup, when you start scraping alot of pages the speed advantage of lxml is hard to ignore.
```
import requests
import lxml.html
dom = lxml.html.fromstring(requests.get('http://www.any_url.com').content)
page_list = [x for x in dom.xpath('//td/text()')]
print page_list
``` |
16,815,170 | So this is probably a very basic question about output formatting in python using '.format' and since I'm a beginner, I can't figure this out for the life of me. I've tried to be as detailed as possible, just to make sure that there's no confusion.
Let me give you an example so that you can better understand my dilem... | 2013/05/29 | [
"https://Stackoverflow.com/questions/16815170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2396553/"
] | Look at the *for loop*:
```
for students in students:
# ^^^^^^^^
```
So, `students`(inside loop) does not actually refers to **list of list**. And `students[0]` refers to **first element** from **element** from **list of lists**, as expected.
I suggest replace `students` from function argument, say, with `all_stu... | Try renaming the variable `list` into something that's not a reserved word or built-in function or type.
What's confusing to beginners - and it happens to everyone sooner or later - is what happens if you redefine or use in unintended ways a reserved word or a builtin.
If you do
```
list = [1, 2, 3, 4]
```
you re-... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | You may try mlxtend which got various selection methods.
```
from mlxtend.feature_selection import SequentialFeatureSelector as sfs
clf = LinearRegression()
# Build step forward feature selection
sfs1 = sfs(clf,k_features = 10,forward=True,floating=False, scoring='r2',cv=5)
# Perform SFFS
sfs1 = sfs1.fit(X_train, ... | You can make forward-backward selection based on `statsmodels.api.OLS` model, as shown [in this answer](https://datascience.stackexchange.com/a/24447/24162).
However, [this answer](https://stats.stackexchange.com/questions/20836/algorithms-for-automatic-model-selection/20856#20856) describes why you should not use ste... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | I developed this repository <https://github.com/xinhe97/StepwiseSelectionOLS>
My Stepwise Selection Classes (best subset, forward stepwise, backward stepwise) are compatible to sklearn. You can do Pipeline and GridSearchCV with my Classes.
The essential part of my code is as follows:
```
################### Criteria... | ```
"""Importing the api class from statsmodels"""
import statsmodels.formula.api as sm
"""X_opt variable has all the columns of independent variables of matrix X
in this case we have 5 independent variables"""
X_opt = X[:,[0,1,2,3,4]]
"""Running the OLS method on X_opt and storing results in regressor_OLS"""
regres... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | You may try mlxtend which got various selection methods.
```
from mlxtend.feature_selection import SequentialFeatureSelector as sfs
clf = LinearRegression()
# Build step forward feature selection
sfs1 = sfs(clf,k_features = 10,forward=True,floating=False, scoring='r2',cv=5)
# Perform SFFS
sfs1 = sfs1.fit(X_train, ... | Here's a method I just wrote that uses "mixed selection" as described in Introduction to Statistical Learning. As input, it takes:
* lm, a statsmodels.OLS.fit(Y,X), where X is an array of n ones, where n is the
number of data points, and Y, where Y is the response in the training data
* curr\_preds- a list with ['con... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | Trevor Smith and I wrote a little forward selection function for linear regression with statsmodels: <http://planspace.org/20150423-forward_selection_with_statsmodels/> You could easily modify it to minimize a p-value, or select based on beta p-values with just a little more work. | ```
"""Importing the api class from statsmodels"""
import statsmodels.formula.api as sm
"""X_opt variable has all the columns of independent variables of matrix X
in this case we have 5 independent variables"""
X_opt = X[:,[0,1,2,3,4]]
"""Running the OLS method on X_opt and storing results in regressor_OLS"""
regres... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | You can make forward-backward selection based on `statsmodels.api.OLS` model, as shown [in this answer](https://datascience.stackexchange.com/a/24447/24162).
However, [this answer](https://stats.stackexchange.com/questions/20836/algorithms-for-automatic-model-selection/20856#20856) describes why you should not use ste... | Here's a method I just wrote that uses "mixed selection" as described in Introduction to Statistical Learning. As input, it takes:
* lm, a statsmodels.OLS.fit(Y,X), where X is an array of n ones, where n is the
number of data points, and Y, where Y is the response in the training data
* curr\_preds- a list with ['con... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | You can make forward-backward selection based on `statsmodels.api.OLS` model, as shown [in this answer](https://datascience.stackexchange.com/a/24447/24162).
However, [this answer](https://stats.stackexchange.com/questions/20836/algorithms-for-automatic-model-selection/20856#20856) describes why you should not use ste... | Statsmodels has additional methods for regression: <http://statsmodels.sourceforge.net/devel/examples/generated/example_ols.html>. I think it will help you to implement stepwise regression. |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | ```
"""Importing the api class from statsmodels"""
import statsmodels.formula.api as sm
"""X_opt variable has all the columns of independent variables of matrix X
in this case we have 5 independent variables"""
X_opt = X[:,[0,1,2,3,4]]
"""Running the OLS method on X_opt and storing results in regressor_OLS"""
regres... | Here's a method I just wrote that uses "mixed selection" as described in Introduction to Statistical Learning. As input, it takes:
* lm, a statsmodels.OLS.fit(Y,X), where X is an array of n ones, where n is the
number of data points, and Y, where Y is the response in the training data
* curr\_preds- a list with ['con... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | Trevor Smith and I wrote a little forward selection function for linear regression with statsmodels: <http://planspace.org/20150423-forward_selection_with_statsmodels/> You could easily modify it to minimize a p-value, or select based on beta p-values with just a little more work. | Here's a method I just wrote that uses "mixed selection" as described in Introduction to Statistical Learning. As input, it takes:
* lm, a statsmodels.OLS.fit(Y,X), where X is an array of n ones, where n is the
number of data points, and Y, where Y is the response in the training data
* curr\_preds- a list with ['con... |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | You may try mlxtend which got various selection methods.
```
from mlxtend.feature_selection import SequentialFeatureSelector as sfs
clf = LinearRegression()
# Build step forward feature selection
sfs1 = sfs(clf,k_features = 10,forward=True,floating=False, scoring='r2',cv=5)
# Perform SFFS
sfs1 = sfs1.fit(X_train, ... | Statsmodels has additional methods for regression: <http://statsmodels.sourceforge.net/devel/examples/generated/example_ols.html>. I think it will help you to implement stepwise regression. |
15,433,372 | How to perform **stepwise regression** in **python**? There are methods for OLS in SCIPY but I am not able to do stepwise. Any help in this regard would be a great help. Thanks.
Edit: I am trying to build a linear regression model. I have 5 independent variables and using forward stepwise regression, I aim to select v... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15433372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2174063/"
] | I developed this repository <https://github.com/xinhe97/StepwiseSelectionOLS>
My Stepwise Selection Classes (best subset, forward stepwise, backward stepwise) are compatible to sklearn. You can do Pipeline and GridSearchCV with my Classes.
The essential part of my code is as follows:
```
################### Criteria... | Here's a method I just wrote that uses "mixed selection" as described in Introduction to Statistical Learning. As input, it takes:
* lm, a statsmodels.OLS.fit(Y,X), where X is an array of n ones, where n is the
number of data points, and Y, where Y is the response in the training data
* curr\_preds- a list with ['con... |
17,332,350 | For some reason I can't log into the same account on my home computer as my work computer.
I was able to get Bo10's code to work, but not abernert's and I would really like to understand why.
Here is my updates to abernert's code:
```
import csv
import sys
import json
import urllib2
j = urllib... | 2013/06/26 | [
"https://Stackoverflow.com/questions/17332350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1887261/"
] | The problem is that you're not using the `csv` module, you're using the `pickle` module, and this is what `pickle` output looks like.
To fix it:
```
csvfile = open('output.csv', 'w')
csv.writer(csvfile).writerows(stationList)
csvfile.close()
```
---
Note that you're going out of your way to build a transposed tabl... | As abarnert mentions, you're not actually using the `csv` module that you've imported.
Also, your logic for storing the columns might actually be transposed. I think you might want to do this instead (*edited to fix the tuple/list confusion*):
```
import csv
import json
import urllib2
j = urllib2.urlopen('https://ci... |
42,418,713 | I need to perform an integration with python but with one of the limits being a variable, and not a number (from 0 to z).
I tried the following:
```
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def I(z,y,a): #function I want to integrate
I = (a*(y*(1... | 2017/02/23 | [
"https://Stackoverflow.com/questions/42418713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7569812/"
] | **Edit:** In your code you should only your `args` argument as `agrs=(y, a)`, z should not be included. Then you can access the result of integration by indexing the first element of the returned tuple.
Actually `quad` returns a tuple. The first element in the tuple is the reuslt you want. Since I cannot get your code... | I don't think `quad` accepts vector valued integration boundaries. So in this case you'll actually have to either loop over `z` or use `np.vectorize`. |
42,418,713 | I need to perform an integration with python but with one of the limits being a variable, and not a number (from 0 to z).
I tried the following:
```
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def I(z,y,a): #function I want to integrate
I = (a*(y*(1... | 2017/02/23 | [
"https://Stackoverflow.com/questions/42418713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7569812/"
] | The correct way to call `quad` with your `I` is:
```
In [20]: quad(I, 0, 10, args=(1,2))
Out[20]: (0.6984886554222364, 1.1361829471531105e-11)
```
As Longwen points out, the first argument to `I` is the `z` that `quad` varies. The `(y,a)` are parameters that `quad` passes on to `I` without change.
But you got the e... | I don't think `quad` accepts vector valued integration boundaries. So in this case you'll actually have to either loop over `z` or use `np.vectorize`. |
42,418,713 | I need to perform an integration with python but with one of the limits being a variable, and not a number (from 0 to z).
I tried the following:
```
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def I(z,y,a): #function I want to integrate
I = (a*(y*(1... | 2017/02/23 | [
"https://Stackoverflow.com/questions/42418713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7569812/"
] | **Edit:** In your code you should only your `args` argument as `agrs=(y, a)`, z should not be included. Then you can access the result of integration by indexing the first element of the returned tuple.
Actually `quad` returns a tuple. The first element in the tuple is the reuslt you want. Since I cannot get your code... | The Python consideration is that an empty list (or iterable) is false when casted to a booleans. Imagine you are listing something.
As you are doing computing you may consider the Zero vector, [0,0,0] which in linear alegbra may be considered as zero but is not an empty list.
You error seems to come from an not null ... |
42,418,713 | I need to perform an integration with python but with one of the limits being a variable, and not a number (from 0 to z).
I tried the following:
```
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def I(z,y,a): #function I want to integrate
I = (a*(y*(1... | 2017/02/23 | [
"https://Stackoverflow.com/questions/42418713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7569812/"
] | The correct way to call `quad` with your `I` is:
```
In [20]: quad(I, 0, 10, args=(1,2))
Out[20]: (0.6984886554222364, 1.1361829471531105e-11)
```
As Longwen points out, the first argument to `I` is the `z` that `quad` varies. The `(y,a)` are parameters that `quad` passes on to `I` without change.
But you got the e... | **Edit:** In your code you should only your `args` argument as `agrs=(y, a)`, z should not be included. Then you can access the result of integration by indexing the first element of the returned tuple.
Actually `quad` returns a tuple. The first element in the tuple is the reuslt you want. Since I cannot get your code... |
42,418,713 | I need to perform an integration with python but with one of the limits being a variable, and not a number (from 0 to z).
I tried the following:
```
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def I(z,y,a): #function I want to integrate
I = (a*(y*(1... | 2017/02/23 | [
"https://Stackoverflow.com/questions/42418713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7569812/"
] | The correct way to call `quad` with your `I` is:
```
In [20]: quad(I, 0, 10, args=(1,2))
Out[20]: (0.6984886554222364, 1.1361829471531105e-11)
```
As Longwen points out, the first argument to `I` is the `z` that `quad` varies. The `(y,a)` are parameters that `quad` passes on to `I` without change.
But you got the e... | The Python consideration is that an empty list (or iterable) is false when casted to a booleans. Imagine you are listing something.
As you are doing computing you may consider the Zero vector, [0,0,0] which in linear alegbra may be considered as zero but is not an empty list.
You error seems to come from an not null ... |
62,908,688 | Recently I went on to clean my python code. I felt tiresome to remove all print statements in the code ony by one.
Is there any shortcut in editor or RE for removing or commenting print statements in a python program in one go? | 2020/07/15 | [
"https://Stackoverflow.com/questions/62908688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8721742/"
] | Find / Replace
--------------
* Find Replace `print(` with `# print(` will comment them out
* Probably works in most editors
Using [Notepad++](https://notepad-plus-plus.org/downloads/) with regex
----------------------------------------------------------------------
* Free to download
* Recognizes many programming l... | You should avoid working with print statements. Use the python logging module instead:
```
import logging
logging.debug('debug message')
```
Once you finished your development and dont need debugging information, you can increase the log level:
```
logging.basicConfig(format='%(levelname)s:%(message)s', level=loggi... |
62,908,688 | Recently I went on to clean my python code. I felt tiresome to remove all print statements in the code ony by one.
Is there any shortcut in editor or RE for removing or commenting print statements in a python program in one go? | 2020/07/15 | [
"https://Stackoverflow.com/questions/62908688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8721742/"
] | Find / Replace
--------------
* Find Replace `print(` with `# print(` will comment them out
* Probably works in most editors
Using [Notepad++](https://notepad-plus-plus.org/downloads/) with regex
----------------------------------------------------------------------
* Free to download
* Recognizes many programming l... | 1. Open Text Editor in Ubuntu
2. Press Ctrl + h
3. Replace: print
4. Replace with: # print |
66,530,908 | I am using `gcc10.2`, `c++20`.
I am studying c++ after 2 years of python.
In python we always did run-time check for input validity
```
def createRectangle(x, y, width, height): # just for example
for v in [x, y, width, height]:
if v < 0:
raise ValueError("Cant be negative")
# blahblahbla... | 2021/03/08 | [
"https://Stackoverflow.com/questions/66530908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8471995/"
] | ```
for (int v : {x, y, width, height})
if (v < 0)
throw std::runtime_error("Can't be negative");
```
Note that such loop copies each variable twice. If your variables are heavy to copy (e.g. containers), use pointers instead:
```
for (const int *v : {&x, &y, &width, &height})
if (*v < 0)
...... | In C++:
1. Use an appropriate type so validation (at the point you *use* the variables as opposed to setting them up from some input) is unnecessary, e.g. `unsigned` for a length. C++ is more strongly typed than Python, so you don't need large validation checks to make sure the correct type is passed to a function.
2.... |
55,351,647 | I'm a beginner of python and follow a book to practice.
In my book, the author uses this code
```
s, k = 0
```
but I get the error:
```none
Traceback (most recent call last): File "<stdin>", line 1, in
<module> TypeError: 'int' object is not iterable
```
I want to know what happened here. | 2019/03/26 | [
"https://Stackoverflow.com/questions/55351647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7290997/"
] | You are asking to initialize two variables `s` and `k` using a single int object `0`, which of course is not iterable.
The corrrect syntax being:
```
s, k = 0, 0
```
**Where**
```
s, k = 0, 1
```
Would assign `s = 0` and `k = 1`
>
> Notice the each `int` object on the right being initialized to the
> corresp... | ```
s = k = 0
```
OR
```
s, k = (0, 0)
```
depends on what u need |
55,351,647 | I'm a beginner of python and follow a book to practice.
In my book, the author uses this code
```
s, k = 0
```
but I get the error:
```none
Traceback (most recent call last): File "<stdin>", line 1, in
<module> TypeError: 'int' object is not iterable
```
I want to know what happened here. | 2019/03/26 | [
"https://Stackoverflow.com/questions/55351647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7290997/"
] | You are asking to initialize two variables `s` and `k` using a single int object `0`, which of course is not iterable.
The corrrect syntax being:
```
s, k = 0, 0
```
**Where**
```
s, k = 0, 1
```
Would assign `s = 0` and `k = 1`
>
> Notice the each `int` object on the right being initialized to the
> corresp... | Insted of:
```
s, k = 0
```
Use:
```
s, k = 0,0
``` |
41,377,820 | I downgraded Postgres.app from 9.6 to 9.5 by removing the Postgres.app desktop app. I updated the database by doing
(I downloaded Postgres by downloading Postgres.app Desktop app and I installed Django by doing pip install Django)
```
sudo /usr/libexec/locate.updatedb
```
And it looks like it is initiating database... | 2016/12/29 | [
"https://Stackoverflow.com/questions/41377820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1427176/"
] | This solves the problem for me:
1. uninstall your psycopg2
pip uninstall psycopg2
2. then do this
pip --no-cache-dir install -U psycopg2 | I think that your problem is that the version of `psycopg2` that is currently installed references the C postgres library that was bundled with your previous install of postgres (`/Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib`).
Try uninstalling and reinstalling `psycopg2`.
```
pip uninstall psyc... |
55,454,182 | Read dates from user input in the form yyyy,mm,dd. Then find number of days between dates. Datetime wants integers and input needs to be converted from string to integer. Previous questions seem to involve time or a different OS and those suggestions do not seem to work with Anaconda and Win10. I tried those which seem... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8491388/"
] | Use `.strptime()` to convert string date to date object and then calculate diff
**Ex:**
```
import datetime
InitialDate = "2019,02,10" #input("Enter the begin date as yyyy,mm,dd")
FinalDate = "2019,02,20" #input("Enter the end date as yyyy,mm,dd")
InitialDate = datetime.datetime.strptime(InitialDate, "%Y,%m,%d"... | from datetime import datetime
InitialDate = input("Enter the begin date as yyyy/mm/dd: ")
FinalDate = input("Enter the end date as yyyy/mm/dd: ")
InitialDate = datetime.strptime(InitialDate, '%Y/%m/%d')
FinalDate = datetime.strptime(FinalDate, '%Y/%m/%d')
difference = FinalDate - InitialDate
print(difference.days) |
55,454,182 | Read dates from user input in the form yyyy,mm,dd. Then find number of days between dates. Datetime wants integers and input needs to be converted from string to integer. Previous questions seem to involve time or a different OS and those suggestions do not seem to work with Anaconda and Win10. I tried those which seem... | 2019/04/01 | [
"https://Stackoverflow.com/questions/55454182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8491388/"
] | Use `.strptime()` to convert string date to date object and then calculate diff
**Ex:**
```
import datetime
InitialDate = "2019,02,10" #input("Enter the begin date as yyyy,mm,dd")
FinalDate = "2019,02,20" #input("Enter the end date as yyyy,mm,dd")
InitialDate = datetime.datetime.strptime(InitialDate, "%Y,%m,%d"... | I just had a similar problem, my solution was to make another int with the value of the array. Something like this:
```
ID = InitialDate.split(",")
Id0 = Id[0]
Id1 = Id[1]
Id2 = Id[2]
ID2 = int(Id0),int(Id1),int(Id2)
Iday = datetime.datetime(Id2)
Fd = FinalDate.split(",")
Fd0 = Fd[0]
Fd1 = Fd[1]
Fd2 = Fd[2]
... |
47,794,007 | So time.sleep isnt working. i am on python 3.4.3 and i have not had this problem on my computer with 3.6.
This is my code:
```
import calendar
def ProfileCreation():
Name = input("Name: ")
print("LOADING...")
time.sleep(1)
Age = input("Age: ")
print("LOADING...")
time.sleep(1)
ProfileAns ... | 2017/12/13 | [
"https://Stackoverflow.com/questions/47794007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9035852/"
] | You might want to `import time` as at the moment `time.sleep(1)` isn't actually defined, just add the import to the top of your code and this should fix it. | Change it to following:
```
import calendar
import time
def ProfileCreation():
Name = input("Name: ")
print("LOADING...")
time.sleep(1)
Age = input("Age: ")
print("LOADING...")
time.sleep(1)
ProfileAns = input("This matches no profiles. Create profile? ")
if ProfileAns.lower == 'yes':
... |
47,794,007 | So time.sleep isnt working. i am on python 3.4.3 and i have not had this problem on my computer with 3.6.
This is my code:
```
import calendar
def ProfileCreation():
Name = input("Name: ")
print("LOADING...")
time.sleep(1)
Age = input("Age: ")
print("LOADING...")
time.sleep(1)
ProfileAns ... | 2017/12/13 | [
"https://Stackoverflow.com/questions/47794007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9035852/"
] | You might want to `import time` as at the moment `time.sleep(1)` isn't actually defined, just add the import to the top of your code and this should fix it. | In your import statement you have imported calendar you should import time also. sleep is inside time package.
import calendar
import time
```
def ProfileCreation():
Name = input("Name: ")
print("LOADING...")
time.sleep(1)
Age = input("Age: ")
print("LOADING...")
time.sleep(1)
ProfileAns ... |
44,707,384 | For my evaluation, I wanted to run a rolling 1000 window `OLS regression estimation` of the dataset found in this URL:
<https://drive.google.com/open?id=0B2Iv8dfU4fTUa3dPYW5tejA0bzg>
using the following `Python` script.
```
# /usr/bin/python -tt
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
... | 2017/06/22 | [
"https://Stackoverflow.com/questions/44707384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1731796/"
] | `pd.stats.ols.MovingOLS` was removed in Pandas version 0.20.0
<http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#whatsnew-0200-prior-deprecations>
<https://github.com/pandas-dev/pandas/pull/11898>
I can't find an 'off the shelf' solution for what should be such an obvious use case as rolling regressions.... | It was [deprecated](https://github.com/pandas-dev/pandas/pull/11898) in favor of statsmodels.
See here [examples how to use statsmodels rolling regression](https://www.statsmodels.org/dev/examples/notebooks/generated/rolling_ls.html). |
60,008,614 | I have two dictionaries:
```
members_singles = {'member3': ['PCP3'], 'member4': ['PCP1'], 'member11': ['PCP2'], 'member12':
['PCP3'], 'member14': ['PCP4'], 'member15': ['PCP4'], 'member16': ['PCP4'], 'members17': ['PCP3']}
providers = {
"PCP1" : 3,
"PCP2" : 4,
"PCP3" : 1,
"PCP4" : 2,
"PCP5" : 4,
}
```
I want to it... | 2020/01/31 | [
"https://Stackoverflow.com/questions/60008614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11069614/"
] | When the `providers` count reaches zero, your code adds the provider to the `to_remove_zero` list. But the count may go negative later on, which will add the same provider to the `pcps_in_negative` list. At that point, your code needs to back-track and remove it from the `to_remove_zero` list:
```
providers[provider] ... | This is probably because you are altering the list, while expecting the indices to remain consistent:
```
a = [1,2,3]
a[0]
# 1
a.pop()
# 3
a[0]
# 1
``` |
55,501,746 | **Below is the problem I am running into:**
*Linear Regression - Given 16 pairs of prices (as dependent variable) and
corresponding demands (as independent variable), use the linear regression tool to estimate the best fitting
linear line.*
```
Price Demand
127 3420
134 3400
136 3250
139 3410
140 3190
141 3250
148 28... | 2019/04/03 | [
"https://Stackoverflow.com/questions/55501746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11307363/"
] | I would rewrite this to be simpler and remove unnecessary looping:
```
$filenameOut = "out.html"
#get current working dir
$cwd = Get-ScriptDirectory #(Get-Location).path #PSScriptRoot #(Get-Item -Path ".").FullName
$filenamePathOut = Join-Path $cwd $filenameOut
$InitialAppointmentGenArr = Get-ChildItem -Path $temp
... | Well, let's start with what you are attempting to do, and why it isn't working. If you look at the file object for any of those files (`$file|get-member`), you see that the `FullName` property only has a `get` method, no `set` method, so you can't change that property. So you are never going to change that property wit... |
31,096,151 | I am parsing streaming hex data with python regex. I have the following packet structure that I am trying to extract from the stream of packets:
```
'\xaa\x01\xFF\x44'
```
* \xaa - start of packet
* \x01 - data length [value can vary from 00-FF]
* \xFF - data
* \x44 - end of packet
i want to use python regex to ind... | 2015/06/28 | [
"https://Stackoverflow.com/questions/31096151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2163865/"
] | I ended up doing something as follows:
```
self.packet_regex = \
re.compile('(\xaa)([\x04-\xFF]{1})([\x00-\xFF]{1})([\x10-\xFF]{1})([\x00-\xFF]*)([\x00-\xFF]{1})(\x44)')
match = self.packet_regex.search(self.buffer)
if match and match.groups():
groups = match.groups()
if (ord(groups[1]) - 4) == le... | This is pretty much a work around for what you have asked. Just have a look at it
```
import re
orig_str = '\xaa\x01\xFF\x44'
print orig_str
#converting original hex data into its representation form
st = repr(orig_str)
print st
#getting the representation form of regex and removing leading and trailing single quotes ... |
50,841,542 | I am little bit familiar with np.fromregex. I read the tutorials and tried to implement it to read a data file.
When the file is read using simple python list comprehension, it gives the desired result:
`[400, 401, 405, 408, 412, 414, 420, 423, 433]`.
But, when `np.fromregex` is is gives another format answer:
`[(400... | 2018/06/13 | [
"https://Stackoverflow.com/questions/50841542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Just choose the group and you'll get what you want:
```
dt = [('num', np.int32)]
x = np.fromregex(ifile, regexp, dt)
print(x['num'])
#[400 401 405 408 412 414 420 423 433]
``` | ```
import numpy as np
import cStringIO
import re
data = """
DMStack failed for: lsst_z1.0_400.fits
DMStack failed for: lsst_z1.0_401.fits
DMStack failed for: lsst_z1.0_405.fits
DMStack failed for: lsst_z1.0_408.fits
DMStack failed for: lsst_z1.0_412.fits
DMStack failed for: lsst_z1.0_414.fits
DMStack failed for: lsst... |
50,841,542 | I am little bit familiar with np.fromregex. I read the tutorials and tried to implement it to read a data file.
When the file is read using simple python list comprehension, it gives the desired result:
`[400, 401, 405, 408, 412, 414, 420, 423, 433]`.
But, when `np.fromregex` is is gives another format answer:
`[(400... | 2018/06/13 | [
"https://Stackoverflow.com/questions/50841542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Just choose the group and you'll get what you want:
```
dt = [('num', np.int32)]
x = np.fromregex(ifile, regexp, dt)
print(x['num'])
#[400 401 405 408 412 414 420 423 433]
``` | All the thanks goes to @zipa and @hpaulj, Finally this code works for
python2 with future statements. It also works for python3.
Instead of `dt = [('num', np.int32)]` we need to use `dt = [(str('num'), np.int32)]`.
```
#!python
# -*- coding: utf-8 -*-#
#
# Imports
from __future__ import print_function, division, with... |
63,814,809 | Hi i need to make a project for school where people can insert a review but before the review is posted on twitter it is going to be placed in a database. before it is going to be posted in twitter a moderator needs to check every review to see if there are no swear words etc. i wanted to make a small code in python wh... | 2020/09/09 | [
"https://Stackoverflow.com/questions/63814809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Try this code. I am not clear on what you are trying to do in
`output_table()` data frame.
```
library(shiny)
library(shinyWidgets)
# ui object
ui <- fluidPage(
titlePanel(p("Spatial app", style = "color:#3474A7")),
sidebarLayout(
sidebarPanel(
uiOutput("inputp1"),
numericInput("num", label = ("va... | First of all, you'd need to include a `req` in your `reactive()`, since `input$num` is not available at the initializing od your example:
```r
dt<-reactive({input$button
req(input$num)
name<-c("John","Jack","Bill")
value1<-c(2,4,6)
dt<-data.frame(name,value1)
dt$value1<-dt$value1*isolate(input$num)... |
57,264,952 | very new to python and hope can get some help here. I'm trying to sum up the total from different lists in dictionary
```
{'1': [0, 2, 2, 0, 0], '2': [0, 1, 1, 0, 0], '3': [2, 4, 2, 0, 2]}
```
I have been trying to find a way to sum up the total as follow and append in a new list:
```
'1': [0, 2, 2, 0, 0]
'2': [0, ... | 2019/07/30 | [
"https://Stackoverflow.com/questions/57264952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7280296/"
] | Using `zip()` ([doc](https://docs.python.org/3/library/functions.html#zip)) function to transpose dictionary values and `sum()` to sum them inside list comprehension:
```
d = {'1': [0, 2, 2, 0, 0], '2': [0, 1, 1, 0, 0], '3': [2, 4, 2, 0, 2]}
out = [sum(i) for i in zip(*d.values())]
print(out)
```
Prints:
```
[2, 7... | You can do like this,
```
In [6]: list(map(sum,zip(*d.values())))
Out[6]: [2, 7, 5, 0, 2]
``` |
43,742,143 | I have a text file that contains data in json format
```
{"Header":
{
"name":"test"},
"params":{
"address":"myhouse"
}
}
```
I am trying to read it from a python file and convert it to json format. I have tried with both yaml and json libraries, and, with both libraries, it converts it to json format, but it also co... | 2017/05/02 | [
"https://Stackoverflow.com/questions/43742143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5193545/"
] | Do this:
```
import json
with open("file.json", "r") as f:
obj = json.load(f)
with open("file.json", "w") as f:
json.dump(obj, f, indent = 4[, ensure_ascii = False]) # if your string has some unicode characters, let ensure_ascii to be False.
``` | You can use `json.load` to load a json object from a file.
```
import json
with open("file.json", "r") as f:
obj = json.load(f)
```
The resulting json object delimits strings with `'` rather than `"`, but you can easily use a `replace` call at that point.
```
In [6]: obj
Out[6]: {'Header': {'name': 'test'}, 'pa... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | Do not use relative import.
Simply change it to
```
from solutions import helloWorldPackage as hw
```
**Update**
I initially tested this in PyCharm. PyCharm has a nice feature - it adds content root and source roots to PYTHONPATH (both options are configurable).
You can achieve the same effect in VS Code by adding... | >
> Setup a main module and its source packages paths
> =================================================
>
>
>
Solution found at:
* [https://k0nze.dev/posts/python-relative-imports-vscode/#:~:text=create%20a%20settings.json%20within%20.vscode](https://k0nze.dev/posts/python-relative-imports-vscode/#:%7E:text=cre... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | Do not use relative import.
Simply change it to
```
from solutions import helloWorldPackage as hw
```
**Update**
I initially tested this in PyCharm. PyCharm has a nice feature - it adds content root and source roots to PYTHONPATH (both options are configurable).
You can achieve the same effect in VS Code by adding... | An Answer From 2022
===================
Here's a potential approach from 2022. The issue is identified correctly and if you're using an IDE like VS Code, it doesn't automatically extend the python path and discover modules.
One way you can do this using an .env file that will automatically extend the python path. I u... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | Do not use relative import.
Simply change it to
```
from solutions import helloWorldPackage as hw
```
**Update**
I initially tested this in PyCharm. PyCharm has a nice feature - it adds content root and source roots to PYTHONPATH (both options are configurable).
You can achieve the same effect in VS Code by adding... | I was just going through this with VS Code and Python (using Win10) and found a solution. Below is my project folder. Files in folder "core" import functions from folder "event", and files in folder "unit tests" import functions from folder "core".
I could run and debug the top-level file file\_gui\_tk.py within VS Co... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | You're bumping into two issues. One is you're running your test file from within the directory it's written, and so Python doesn't know what `..` represents. There are a couple of ways to fix this.
One is to take the solution that @lesiak proposed by changing the import to `from solutions import helloWorldPackage` but... | >
> Setup a main module and its source packages paths
> =================================================
>
>
>
Solution found at:
* [https://k0nze.dev/posts/python-relative-imports-vscode/#:~:text=create%20a%20settings.json%20within%20.vscode](https://k0nze.dev/posts/python-relative-imports-vscode/#:%7E:text=cre... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | You're bumping into two issues. One is you're running your test file from within the directory it's written, and so Python doesn't know what `..` represents. There are a couple of ways to fix this.
One is to take the solution that @lesiak proposed by changing the import to `from solutions import helloWorldPackage` but... | An Answer From 2022
===================
Here's a potential approach from 2022. The issue is identified correctly and if you're using an IDE like VS Code, it doesn't automatically extend the python path and discover modules.
One way you can do this using an .env file that will automatically extend the python path. I u... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | You're bumping into two issues. One is you're running your test file from within the directory it's written, and so Python doesn't know what `..` represents. There are a couple of ways to fix this.
One is to take the solution that @lesiak proposed by changing the import to `from solutions import helloWorldPackage` but... | I was just going through this with VS Code and Python (using Win10) and found a solution. Below is my project folder. Files in folder "core" import functions from folder "event", and files in folder "unit tests" import functions from folder "core".
I could run and debug the top-level file file\_gui\_tk.py within VS Co... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | >
> Setup a main module and its source packages paths
> =================================================
>
>
>
Solution found at:
* [https://k0nze.dev/posts/python-relative-imports-vscode/#:~:text=create%20a%20settings.json%20within%20.vscode](https://k0nze.dev/posts/python-relative-imports-vscode/#:%7E:text=cre... | An Answer From 2022
===================
Here's a potential approach from 2022. The issue is identified correctly and if you're using an IDE like VS Code, it doesn't automatically extend the python path and discover modules.
One way you can do this using an .env file that will automatically extend the python path. I u... |
58,709,973 | * when running Python test from withing VS Code using CTRL+F5 I'm getting error message
*ImportError: attempted relative import with no known parent package*
[](https://i.stack.imgur.com/jb... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58709973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/93277/"
] | >
> Setup a main module and its source packages paths
> =================================================
>
>
>
Solution found at:
* [https://k0nze.dev/posts/python-relative-imports-vscode/#:~:text=create%20a%20settings.json%20within%20.vscode](https://k0nze.dev/posts/python-relative-imports-vscode/#:%7E:text=cre... | I was just going through this with VS Code and Python (using Win10) and found a solution. Below is my project folder. Files in folder "core" import functions from folder "event", and files in folder "unit tests" import functions from folder "core".
I could run and debug the top-level file file\_gui\_tk.py within VS Co... |
62,494,807 | I have the following python script
```
from bs4 import BeautifulSoup
import requests
home_dict = []
for year in range(2005, 2021):
if year == 2020:
for month in range(1, 6):
url = 'https://www.rebgv.org/market-watch/MLS-HPI-home-price-comparison.hpi.all.all.' + str(year) + '-' + str(month) + ... | 2020/06/21 | [
"https://Stackoverflow.com/questions/62494807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11303284/"
] | Perhaps try a `try` clause?
```
for year in range(2005, 2021):
month in range(1, 13):
try:
<your code>
except:
continue
``` | As scraping for 1 to 6 months is common for all the years. You can **scrape** those years first. And then if the year is not equal to 2020 you can **scrape** rest of the years |
62,494,807 | I have the following python script
```
from bs4 import BeautifulSoup
import requests
home_dict = []
for year in range(2005, 2021):
if year == 2020:
for month in range(1, 6):
url = 'https://www.rebgv.org/market-watch/MLS-HPI-home-price-comparison.hpi.all.all.' + str(year) + '-' + str(month) + ... | 2020/06/21 | [
"https://Stackoverflow.com/questions/62494807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11303284/"
] | Just define a `dict` with year as key & range of month as values,
```
filter_ = {2020 : (1, 6)}
for year in range(2005, 2021):
start, stop = filter_.get(year, (1,13))
for month in range(start, stop):
url = 'https://www.rebgv.org/market-watch/MLS-HPI-home-price-comparison.hpi.all.all.' + str(
... | As scraping for 1 to 6 months is common for all the years. You can **scrape** those years first. And then if the year is not equal to 2020 you can **scrape** rest of the years |
62,494,807 | I have the following python script
```
from bs4 import BeautifulSoup
import requests
home_dict = []
for year in range(2005, 2021):
if year == 2020:
for month in range(1, 6):
url = 'https://www.rebgv.org/market-watch/MLS-HPI-home-price-comparison.hpi.all.all.' + str(year) + '-' + str(month) + ... | 2020/06/21 | [
"https://Stackoverflow.com/questions/62494807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11303284/"
] | Perhaps try a `try` clause?
```
for year in range(2005, 2021):
month in range(1, 13):
try:
<your code>
except:
continue
``` | Just define a `dict` with year as key & range of month as values,
```
filter_ = {2020 : (1, 6)}
for year in range(2005, 2021):
start, stop = filter_.get(year, (1,13))
for month in range(start, stop):
url = 'https://www.rebgv.org/market-watch/MLS-HPI-home-price-comparison.hpi.all.all.' + str(
... |
67,790,430 | I have a big text file that has around 200K lines of records/lines.
But I need to extract only specific lines which Start with CLM. For example, if the file has 100K lines that start with CLM I should print all that 100K lines alone.
Can anyone help me to achieve this using python script? | 2021/06/01 | [
"https://Stackoverflow.com/questions/67790430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15924358/"
] | this would work:
```
df2[, colnames(df2) %in% colnames(df1)]
x3 x4 x7 x10 x12
1 IL_NA1A_P IL_NA3D_P PROD009_P PROD014_P PROD023A_P
```
You simply check which column-names of `df2` appear also in `df1` and select these columns from `df2`. | If all of `df1` column names are present in `df2` you can use -
```
df2[names(df1)]
# x3 x4 x7 x10 x12
#1 IL_NA1A_P IL_NA3D_P PROD009_P PROD014_P PROD023A_P
```
If only few of `df1` column names are present in `df2` you can either use -
```
df2[intersect(names(df2), names(df1))]
... |
67,790,430 | I have a big text file that has around 200K lines of records/lines.
But I need to extract only specific lines which Start with CLM. For example, if the file has 100K lines that start with CLM I should print all that 100K lines alone.
Can anyone help me to achieve this using python script? | 2021/06/01 | [
"https://Stackoverflow.com/questions/67790430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15924358/"
] | this would work:
```
df2[, colnames(df2) %in% colnames(df1)]
x3 x4 x7 x10 x12
1 IL_NA1A_P IL_NA3D_P PROD009_P PROD014_P PROD023A_P
```
You simply check which column-names of `df2` appear also in `df1` and select these columns from `df2`. | We can also use
```
library(dplyr)
df2 %>%
select_at(vars(names(df1))
``` |
67,790,430 | I have a big text file that has around 200K lines of records/lines.
But I need to extract only specific lines which Start with CLM. For example, if the file has 100K lines that start with CLM I should print all that 100K lines alone.
Can anyone help me to achieve this using python script? | 2021/06/01 | [
"https://Stackoverflow.com/questions/67790430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15924358/"
] | We can also use
```
library(dplyr)
df2 %>%
select_at(vars(names(df1))
``` | If all of `df1` column names are present in `df2` you can use -
```
df2[names(df1)]
# x3 x4 x7 x10 x12
#1 IL_NA1A_P IL_NA3D_P PROD009_P PROD014_P PROD023A_P
```
If only few of `df1` column names are present in `df2` you can either use -
```
df2[intersect(names(df2), names(df1))]
... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | This is not supported by Windows Installer. Elevation is usually handled by the application through its [manifest](http://msdn.microsoft.com/en-us/library/bb756929.aspx).
A solution is to create a wrapper (VBScript or EXE) which uses [ShellExecute](http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx) with... | Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF\_RUNAS\_USER flag on a shortcut.
Some links to such functions include:
* <http://blogs.m... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | This is not supported by Windows Installer. Elevation is usually handled by the application through its [manifest](http://msdn.microsoft.com/en-us/library/bb756929.aspx).
A solution is to create a wrapper (VBScript or EXE) which uses [ShellExecute](http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx) with... | I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my\_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this ... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | This is largely due to the fact that Windows Installer uses 'Advertised shortcuts' for the Windows Installer packages.
There is no way inherently to disable this in Visual Studio, but it is possible to modify the MSI that is produced to make sure that it does not use advertised shortcuts (or uses only one). There are ... | Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF\_RUNAS\_USER flag on a shortcut.
Some links to such functions include:
* <http://blogs.m... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | This is largely due to the fact that Windows Installer uses 'Advertised shortcuts' for the Windows Installer packages.
There is no way inherently to disable this in Visual Studio, but it is possible to modify the MSI that is produced to make sure that it does not use advertised shortcuts (or uses only one). There are ... | I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my\_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this ... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | I know this is quite an old question, but I needed to find an answer and I thought I could help other searchers. I wrote a small function to perform this task in VBScript (pasted below). It is easily adapted to VB.net / VB6.
Return codes from function:
0 - success, changed the shortcut.
99 - shortcut flag alread... | Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF\_RUNAS\_USER flag on a shortcut.
Some links to such functions include:
* <http://blogs.m... |
6,652,492 | I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
```
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-... | 2011/07/11 | [
"https://Stackoverflow.com/questions/6652492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/584676/"
] | I know this is quite an old question, but I needed to find an answer and I thought I could help other searchers. I wrote a small function to perform this task in VBScript (pasted below). It is easily adapted to VB.net / VB6.
Return codes from function:
0 - success, changed the shortcut.
99 - shortcut flag alread... | I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my\_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this ... |
38,644,397 | I am trying to make a login system with python and mysql. I connected to the database, but when I try to insert values into a table, it fails. I'm not sure what's wrong. I am using python 3.5 and the PyMySQL module.
```
#!python3
import pymysql, sys, time
try:
print('Connecting.....')
time... | 2016/07/28 | [
"https://Stackoverflow.com/questions/38644397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6544457/"
] | It looks like the `get`/`getAs` methods mentioned in the example are just convenience wrappers for the `fetch` method. See <https://github.com/http4s/http4s/blob/a4b52b042338ab35d89d260e0bcb39ccec1f1947/client/src/main/scala/org/http4s/client/Client.scala#L116>
Use the `Request` constructor and pass `Method.POST` as t... | ```
import org.http4s.circe._
import org.http4s.dsl._
import io.circe.generic.auto._
case class Name(name: String)
implicit val nameDecoder: EntityDecoder[Name] = jsonOf[Name]
def routes: PartialFunction[Request, Task[Response]] = {
case req @ POST -> Root / "hello" =>
req.decode[Name] { name =>
... |
38,644,397 | I am trying to make a login system with python and mysql. I connected to the database, but when I try to insert values into a table, it fails. I'm not sure what's wrong. I am using python 3.5 and the PyMySQL module.
```
#!python3
import pymysql, sys, time
try:
print('Connecting.....')
time... | 2016/07/28 | [
"https://Stackoverflow.com/questions/38644397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6544457/"
] | It looks like the `get`/`getAs` methods mentioned in the example are just convenience wrappers for the `fetch` method. See <https://github.com/http4s/http4s/blob/a4b52b042338ab35d89d260e0bcb39ccec1f1947/client/src/main/scala/org/http4s/client/Client.scala#L116>
Use the `Request` constructor and pass `Method.POST` as t... | https4s version: 0.14.11
The hard part is how to set the post body. When you dive into the code, you may find `type EntityBody = Process[Task, ByteVector]`. But wtf is it? However, if you have not been ready to dive into scalaz, just use `withBody`.
```
object Client extends App {
val client = PooledHttp1Client()
... |
38,644,397 | I am trying to make a login system with python and mysql. I connected to the database, but when I try to insert values into a table, it fails. I'm not sure what's wrong. I am using python 3.5 and the PyMySQL module.
```
#!python3
import pymysql, sys, time
try:
print('Connecting.....')
time... | 2016/07/28 | [
"https://Stackoverflow.com/questions/38644397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6544457/"
] | https4s version: 0.14.11
The hard part is how to set the post body. When you dive into the code, you may find `type EntityBody = Process[Task, ByteVector]`. But wtf is it? However, if you have not been ready to dive into scalaz, just use `withBody`.
```
object Client extends App {
val client = PooledHttp1Client()
... | ```
import org.http4s.circe._
import org.http4s.dsl._
import io.circe.generic.auto._
case class Name(name: String)
implicit val nameDecoder: EntityDecoder[Name] = jsonOf[Name]
def routes: PartialFunction[Request, Task[Response]] = {
case req @ POST -> Root / "hello" =>
req.decode[Name] { name =>
... |
66,503,032 | Is there anyway that I could make the function below faster and more optimized with `pandas` or `numpy`, the function below adds the sum of `seq45` until the elements of it is equivalent or over 10000.The elements that is being added up to `seq45` are `3,7,11` in order. The reason why i want to increase the speed is to... | 2021/03/06 | [
"https://Stackoverflow.com/questions/66503032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15217016/"
] | You can input numbers using scanner class similar to the following code from w3schools:
```
import java.util.Scanner; // Import the Scanner class
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter username");
... | put count++; after the last print statement |
66,503,032 | Is there anyway that I could make the function below faster and more optimized with `pandas` or `numpy`, the function below adds the sum of `seq45` until the elements of it is equivalent or over 10000.The elements that is being added up to `seq45` are `3,7,11` in order. The reason why i want to increase the speed is to... | 2021/03/06 | [
"https://Stackoverflow.com/questions/66503032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15217016/"
] | Once you get to the basic implementation (as explained by Charisma), you'll notice, that it can take a lot of time if the numbers are huge: you have `high - low + 1` iterations of the loop. Therefore you can start optimizing, to get a result in constant time:
* the first multiple is `qLow * x`, where `qLow` is the [ce... | put count++; after the last print statement |
62,929,576 | I would like to approximate bond yields in python. But the question arose which curve describes this better?
------------------------------------------------------------------------------------------------------------
```
import numpy as np
import matplotlib.pyplot as plt
x = [0.02, 0.22, 0.29, 0.38, 0.52, 0.55, 0.67... | 2020/07/16 | [
"https://Stackoverflow.com/questions/62929576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12412154/"
] | This may help you. I'm not sure but this works for me
### Signout Fuction
```dart
Future _signOut() async {
try {
return await auth.signOut();
} catch (e) {
print(e.toString());
return null;
}
}
```
### Function Usage
```dart
IconButton(
onPressed: () async {
await _auth.signO... | You need to have AuthWidgetBuilder as top-level widget (ideally above MaterialApp) so that the entire widget tree is rebuilt on sign-in / sign-out events.
You could make SplashScreen a child, and have some conditional logic to decide if you should present it.
By the way, if your splash screen doesn't contain any anim... |
61,645,140 | I am really struggling with this issue.
In the below, I take a domain like something.facebook.com and turn it into facebook.com using my UDF.
I get this error though:
```
UnicodeEncodeError: 'ascii' codec can't encode characters in position 64-65: ordinal not in range(128)
```
I've tried a few things to get around... | 2020/05/06 | [
"https://Stackoverflow.com/questions/61645140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9629771/"
] | This seems to solve it. Interestingly, the output is never 'unicode error'
```
def cleanup(domain):
try:
if domain is None or domain == '':
domain = 'empty'
return str(domain)
for tld in toplevel:
if tld in domain:
... | Try this one.
```
def cleanup(domain):
#Test the empt Entry
if domain is None or domain == '':
domain = 'empty'
return domain
listSub = domain.split('.')
result = listSub[1]
#get the part we need www.facebook.com > .facebook.com
for part in listSub[2:]:
result = result + '.' + par... |
13,365,876 | I am using python [tox](http://pypi.python.org/pypi/tox) to run python unittest for several versions of python, but these python interpreters are not all available on all machines or platforms where I'm running tox.
How can I configure tox so it will run tests only when python interpretors are available.
Example of `... | 2012/11/13 | [
"https://Stackoverflow.com/questions/13365876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/99834/"
] | As of Tox version 1.7.2, you can pass the `--skip-missing-interpreters` flag to achieve this behavior. You can also set `skip_missing_interpreters=true` in your `tox.ini` file. More info [here](http://tox.readthedocs.org/en/latest/config.html#confval-skip_missing_interpreters=BOOL).
```
[tox]
envlist =
py24, py25,... | tox will display an Error if an interpreter cannot be found. Question is up if there should be a "SKIPPED" state and making tox return a "0" success result. This should probably be explicitely enabled via a command line option. If you agree, file an issue at <http://bitbucket.org/hpk42/tox> . |
13,365,876 | I am using python [tox](http://pypi.python.org/pypi/tox) to run python unittest for several versions of python, but these python interpreters are not all available on all machines or platforms where I'm running tox.
How can I configure tox so it will run tests only when python interpretors are available.
Example of `... | 2012/11/13 | [
"https://Stackoverflow.com/questions/13365876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/99834/"
] | First if you don't have tox : `pip install tox`.
Use this command : `tox --skip-missing-interpreters` , it skips for the compilers which are not available locally and just runs for the available versions of python | tox will display an Error if an interpreter cannot be found. Question is up if there should be a "SKIPPED" state and making tox return a "0" success result. This should probably be explicitely enabled via a command line option. If you agree, file an issue at <http://bitbucket.org/hpk42/tox> . |
13,365,876 | I am using python [tox](http://pypi.python.org/pypi/tox) to run python unittest for several versions of python, but these python interpreters are not all available on all machines or platforms where I'm running tox.
How can I configure tox so it will run tests only when python interpretors are available.
Example of `... | 2012/11/13 | [
"https://Stackoverflow.com/questions/13365876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/99834/"
] | As of Tox version 1.7.2, you can pass the `--skip-missing-interpreters` flag to achieve this behavior. You can also set `skip_missing_interpreters=true` in your `tox.ini` file. More info [here](http://tox.readthedocs.org/en/latest/config.html#confval-skip_missing_interpreters=BOOL).
```
[tox]
envlist =
py24, py25,... | First if you don't have tox : `pip install tox`.
Use this command : `tox --skip-missing-interpreters` , it skips for the compilers which are not available locally and just runs for the available versions of python |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | The code assumes that the input has one word per line without leading spaces and will count all words that start with two ASCII letters from `'a'`..`'z'`. As the statement in the question is not fully clear, I further assume that the character encoding is ASCII or at least ASCII compatible. (The question states: "there... | Such job is more suitable for languages like Python, Perl, Ruby etc. instead of C. I suggest at least trying C++.
If you don't have to write it in C, here is my Python version: (since you didn't mention it in the question - are you working on an embedded system or something where C/ASM are the only options?)
```py
FI... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | >
> How to count the frequency of the two first letters in a word from a dictionary?
>
>
>
Use a simple [state machine](https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile) to read one character at a time, detect when the character is first 2 letters of a word, then increment a 26x2... | Such job is more suitable for languages like Python, Perl, Ruby etc. instead of C. I suggest at least trying C++.
If you don't have to write it in C, here is my Python version: (since you didn't mention it in the question - are you working on an embedded system or something where C/ASM are the only options?)
```py
FI... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | The idea is to have a two-dimensional array, each dimension holding one of the first two characters of each line. The clever bit is that in C, even a string whose length as reported by `strlen()` to be 1 has two `char`'s - the character and the trailing 0 at the end, so you don't need to special-case cases like `"a"`. ... | Such job is more suitable for languages like Python, Perl, Ruby etc. instead of C. I suggest at least trying C++.
If you don't have to write it in C, here is my Python version: (since you didn't mention it in the question - are you working on an embedded system or something where C/ASM are the only options?)
```py
FI... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | There is no need to read the entire dictionary into memory, or even to buffer lines. The dictionary consists of words, one per line. This means it has this structure:
```
"aardvark\nabacus\n"
```
The first two characters of the file are the first digraph. The other interesting digraphs are all characters which immed... | Such job is more suitable for languages like Python, Perl, Ruby etc. instead of C. I suggest at least trying C++.
If you don't have to write it in C, here is my Python version: (since you didn't mention it in the question - are you working on an embedded system or something where C/ASM are the only options?)
```py
FI... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | You are started in the right direction. You do need a 2D array 27 x 27 for a single case (e.g. lowercase or uppercase), not including digits. To handle digits, just add another 11 x 11 array and map 2-digit frequencies there. The reason you can't use a flat 1D array and map to it without serious indexing gymnastics is ... | Such job is more suitable for languages like Python, Perl, Ruby etc. instead of C. I suggest at least trying C++.
If you don't have to write it in C, here is my Python version: (since you didn't mention it in the question - are you working on an embedded system or something where C/ASM are the only options?)
```py
FI... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | The code assumes that the input has one word per line without leading spaces and will count all words that start with two ASCII letters from `'a'`..`'z'`. As the statement in the question is not fully clear, I further assume that the character encoding is ASCII or at least ASCII compatible. (The question states: "there... | >
> How to count the frequency of the two first letters in a word from a dictionary?
>
>
>
Use a simple [state machine](https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile) to read one character at a time, detect when the character is first 2 letters of a word, then increment a 26x2... |
68,564,322 | I have a 143k lowcase word dictionary and I want to count the frequency of the first two letters
(ie: `aa* = 14, ab* = 534, ac = 714` ... `za = 65,` ... `zz = 0` ) and put it in a bidimensional array.
However I have no idea how to even go about iterating them without switches or a bunch of if elses I tried looking on ... | 2021/07/28 | [
"https://Stackoverflow.com/questions/68564322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16498000/"
] | The code assumes that the input has one word per line without leading spaces and will count all words that start with two ASCII letters from `'a'`..`'z'`. As the statement in the question is not fully clear, I further assume that the character encoding is ASCII or at least ASCII compatible. (The question states: "there... | The idea is to have a two-dimensional array, each dimension holding one of the first two characters of each line. The clever bit is that in C, even a string whose length as reported by `strlen()` to be 1 has two `char`'s - the character and the trailing 0 at the end, so you don't need to special-case cases like `"a"`. ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.