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
43,201,211
I hope you can help. I am currently writing a code to extract historical data for various games on SteamSpy.com. After backing the project on Patreon, you get to view the long history of various metrics for each game. I would like to make comparisons between multiple games, and as such I want to extract the data. I k...
2017/04/04
[ "https://Stackoverflow.com/questions/43201211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3494191/" ]
You could try ``` SELECT REPLACE(CONVERT(VARCHAR(11), Date, 6), ' ', '/') + ' 12:00:00 AM' AS Date FROM TableFiles ```
just an idea: select convert(**date**, yourvalue ) + 0.5) .... should use only date part and add an half day?
65,160,481
I'm trying to install neovim on Windows and import my previous init.vim file. I've previously defined my snippets in ultisnips. I'm using windows and ahve tested this in another version of windows and it works, however, at the moment when I run ``` :checkhealth ``` I get the following error: ``` ## Python 3 provide...
2020/12/05
[ "https://Stackoverflow.com/questions/65160481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427492/" ]
**Make sure you have Python3 installed, the following answer also works with Python2.** Check for help: ``` :help provider-python ``` Go to the `PYTHON QUICKSTART` and you will see one of this two options: * For Python 2 plugins: * For Python 3 plugins: *Because you're problem is with python 3 follow this steps t...
It seems, that neovim is confusing python 2 and python 3 somehow. For me it worked just to have renamed python executable in PATH of python 2, that is python.exe -> python2.exe, and now it seems to work fine. However it is maybe not the perfect solution.
65,160,481
I'm trying to install neovim on Windows and import my previous init.vim file. I've previously defined my snippets in ultisnips. I'm using windows and ahve tested this in another version of windows and it works, however, at the moment when I run ``` :checkhealth ``` I get the following error: ``` ## Python 3 provide...
2020/12/05
[ "https://Stackoverflow.com/questions/65160481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427492/" ]
It seems, that neovim is confusing python 2 and python 3 somehow. For me it worked just to have renamed python executable in PATH of python 2, that is python.exe -> python2.exe, and now it seems to work fine. However it is maybe not the perfect solution.
1. Locate the path to the python3 executable using [one of these methods](https://datatofish.com/locate-python-windows/). Copy the path. For me, it was *C:\Users\money\AppData\Local\Programs\Python\Python310*. 2. Then, add this directory to your PATH variable. Search for "View advanced system settings" > "Environment V...
65,160,481
I'm trying to install neovim on Windows and import my previous init.vim file. I've previously defined my snippets in ultisnips. I'm using windows and ahve tested this in another version of windows and it works, however, at the moment when I run ``` :checkhealth ``` I get the following error: ``` ## Python 3 provide...
2020/12/05
[ "https://Stackoverflow.com/questions/65160481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427492/" ]
**Make sure you have Python3 installed, the following answer also works with Python2.** Check for help: ``` :help provider-python ``` Go to the `PYTHON QUICKSTART` and you will see one of this two options: * For Python 2 plugins: * For Python 3 plugins: *Because you're problem is with python 3 follow this steps t...
1. Locate the path to the python3 executable using [one of these methods](https://datatofish.com/locate-python-windows/). Copy the path. For me, it was *C:\Users\money\AppData\Local\Programs\Python\Python310*. 2. Then, add this directory to your PATH variable. Search for "View advanced system settings" > "Environment V...
65,160,481
I'm trying to install neovim on Windows and import my previous init.vim file. I've previously defined my snippets in ultisnips. I'm using windows and ahve tested this in another version of windows and it works, however, at the moment when I run ``` :checkhealth ``` I get the following error: ``` ## Python 3 provide...
2020/12/05
[ "https://Stackoverflow.com/questions/65160481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427492/" ]
**Make sure you have Python3 installed, the following answer also works with Python2.** Check for help: ``` :help provider-python ``` Go to the `PYTHON QUICKSTART` and you will see one of this two options: * For Python 2 plugins: * For Python 3 plugins: *Because you're problem is with python 3 follow this steps t...
I just solved this problem. So let me say what I did. In the beginning, I used the `python3.8.8`, which will create the same issues. I tried to `pip install neovim` and failed. Then I replace the `python3.8.8` with `python3.8.1`. Everything is OK~ So change the version of Python?
65,160,481
I'm trying to install neovim on Windows and import my previous init.vim file. I've previously defined my snippets in ultisnips. I'm using windows and ahve tested this in another version of windows and it works, however, at the moment when I run ``` :checkhealth ``` I get the following error: ``` ## Python 3 provide...
2020/12/05
[ "https://Stackoverflow.com/questions/65160481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2427492/" ]
I just solved this problem. So let me say what I did. In the beginning, I used the `python3.8.8`, which will create the same issues. I tried to `pip install neovim` and failed. Then I replace the `python3.8.8` with `python3.8.1`. Everything is OK~ So change the version of Python?
1. Locate the path to the python3 executable using [one of these methods](https://datatofish.com/locate-python-windows/). Copy the path. For me, it was *C:\Users\money\AppData\Local\Programs\Python\Python310*. 2. Then, add this directory to your PATH variable. Search for "View advanced system settings" > "Environment V...
69,700,550
Shown below is the code from my launch.json file for my Flask application. I have various environment variables defined in the `"env": {}` portion. However, when I run my Flask application from the run.py script, it doesn't seem to recognize the variables. Although the `"FLASK_DEBUG"` is set to `"1"`, the application s...
2021/10/24
[ "https://Stackoverflow.com/questions/69700550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16425143/" ]
This is very inefficient\*, but it meets your requirements: ```ml let transpose (matrix : List<List<_>>) = [ if matrix.Length > 0 then assert(matrix |> List.distinctBy List.length |> List.length = 1) for i = 0 to matrix.[0].Length - 1 do yield [ f...
For better performance, you can convert the list of list to an Array2D, and then create your transposed list from the Array2D. ``` let transpose' xss = let xss = array2D xss let dimx = Array2D.length1 xss - 1 let dimy = Array2D.length2 xss - 1 [ for y=0 to dimy do [ for x=0 to dimx do ...
64,768,621
Hello I am new into python . practicing web scraping with some demo sites . I am trying to scrape this website <http://books.toscrape.com/> and want to extract 1. href 2. name/title 3. start rating/star-rating 4. price/price\_color 5. in-stock availbility/instock availability i written a basic code which goes to each...
2020/11/10
[ "https://Stackoverflow.com/questions/64768621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13597511/" ]
It's for folders that are added in you .proj file, but doesn't exist on a hard drive. My guess is that you are using some kind of version control (git or svn or else) and someone made change to project structure (added folder) but forgot to add that folder to version control system.
For me red cross appeared on all projects because while cloning component from git/stash, most of the files and folder path were too long and are not acceptable. Tried cloning at different path which is smaller and red crosses disappeared.
17,055,642
I was wondering if there is already available a library which does something similar to scrapely <https://github.com/scrapy/scrapely> WHat it does is that you give an example url and then you give the data you want to extract from that html.. ``` url1 = 'http://pypi.python.org/pypi/w3lib/1.1' data = {'name': 'w3lib ...
2013/06/11
[ "https://Stackoverflow.com/questions/17055642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/902885/" ]
The likeliest problem is that you're using backslashes in your file name, so they get interpreted as control characters. The IO error is because the filename is mangled. try ``` stockPath = "C:\\Users\\Dryan\\Desktop\\table.csv" # double slashes to get single slashes in the string ``` or ``` stockPath = "C:/Use...
As joojaa said, try to avoid using backslashes when you can. I try to always convert any incoming path to a forward slashes version, and just before outputting it I normalize it using os.path.normpath. ``` clean_path = any_path_i_have_to_deal_with.replace("\\", "/") # do stuff with it # (concat, XML save, assign to ...
68,728,817
I need some help with respect to changing a dataframe in python. ``` NODE SIGNAL-STRENGTH LOCATION 0 A 76 1 1 A 78 1 2 A 78 1 3 A 79 1 4 A 79 2 5 A ...
2021/08/10
[ "https://Stackoverflow.com/questions/68728817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14548962/" ]
You can do it with a `FULL` join of the tables: ``` SELECT COALESCE(a.name, b.name) AS name, CASE WHEN a.name IS NULL THEN false ELSE true END AS is_in_A, CASE WHEN b.name IS NULL THEN false ELSE true END AS is_in_B FROM a FULL OUTER JOIN b ON b.name = a.name ``` If your database does not support boole...
You can use `union all` and aggregation: ``` select name, sum(in_a), sum(in_b) from ((select name, 1 as in_a, 0 as in_b from a ) union all (select name, 0, 1 from b ) ) ab group by name; ```
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
I recommend searching about the python basics and loops This will make it ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'coo...
Is this what you want? ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } price = 0 while True: ...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
I recommend searching about the python basics and loops This will make it ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'coo...
Code: ===== ``` # items and their prices items = { 'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } users_items = [] # The list of purchased items choice = None while choice != 'nothing': choice = input(...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
I recommend searching about the python basics and loops This will make it ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'coo...
@Vasyl Yovdiy has the most straightforward answer that's easy for a beginner to digest. However, it is missing the different string requirement for subsequent inputs. I would add a variable `first` that controls the string of your input. ``` # items and their prices items = {'banana': 3, 'apple': 2, ...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
I recommend searching about the python basics and loops This will make it ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'coo...
Is this what you were looking for? ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } #Asking for the...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
The problem with your code - ``` if choice in items: the_choice = price[choice] ``` In the above lines of code, what you are trying to do doesn't make sense with what you are trying to achieve. You are probably looking to add each item that user inputs into the `price` list. But you are instead assigning the...
Is this what you want? ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } price = 0 while True: ...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
The problem with your code - ``` if choice in items: the_choice = price[choice] ``` In the above lines of code, what you are trying to do doesn't make sense with what you are trying to achieve. You are probably looking to add each item that user inputs into the `price` list. But you are instead assigning the...
Code: ===== ``` # items and their prices items = { 'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } users_items = [] # The list of purchased items choice = None while choice != 'nothing': choice = input(...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
The problem with your code - ``` if choice in items: the_choice = price[choice] ``` In the above lines of code, what you are trying to do doesn't make sense with what you are trying to achieve. You are probably looking to add each item that user inputs into the `price` list. But you are instead assigning the...
@Vasyl Yovdiy has the most straightforward answer that's easy for a beginner to digest. However, it is missing the different string requirement for subsequent inputs. I would add a variable `first` that controls the string of your input. ``` # items and their prices items = {'banana': 3, 'apple': 2, ...
63,156,890
I'm really new to coding and after learning all the syntax for HTML and CSS I figured I'd move on to python but I'd actually learn how to use it to become a python programmer instead of just learning the syntax So as one of my first small projects I figured id make a small piece of code that'd ask the user for some it...
2020/07/29
[ "https://Stackoverflow.com/questions/63156890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14016707/" ]
The problem with your code - ``` if choice in items: the_choice = price[choice] ``` In the above lines of code, what you are trying to do doesn't make sense with what you are trying to achieve. You are probably looking to add each item that user inputs into the `price` list. But you are instead assigning the...
Is this what you were looking for? ``` # items and their prices items = {'banana': 3, 'apple': 2, 'milk': 12, 'bread': 15, 'orange': 3, 'cheese': 14, 'chicken': 42, 'peanuts':32 , 'butter': 20, 'cooldrink': 18, } #Asking for the...
22,567,083
I'm trying to run this simple example I found [here](https://groups.google.com/forum/#!msg/pyqtgraph/haiJsGhxTaQ/sTtMa195dHsJ), on MacOS X with Anaconda python. ``` import pyqtgraph as pg import time plt = pg.plot() def update(data): plt.plot(data, clear=True) class Thread(pg.QtCore.QThread): newData = pg.Q...
2014/03/21
[ "https://Stackoverflow.com/questions/22567083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2585497/" ]
The `pyqtgraph.plot` method seems buggy to me (anyway, I wasn't able to get it to produce any useful output, but maybe I'm doing something wrong). However, if I create a `PlotWidget` and set up the application "manually", it all works as expected: ``` import pyqtgraph as pg import numpy as np import time app = pg.Qt...
When you call `QThread.start()`, that function returns immediately. What happens is, 1. Thread #1 - creates new thread, #2 2. Thread #2 is created 3. Thread #1 regains control and runs. 4. Thread #1 dies or `thread` variable is cleaned up by GC (garbage collector) - I'm assuming the 2nd scenario should not happen To ...
22,567,083
I'm trying to run this simple example I found [here](https://groups.google.com/forum/#!msg/pyqtgraph/haiJsGhxTaQ/sTtMa195dHsJ), on MacOS X with Anaconda python. ``` import pyqtgraph as pg import time plt = pg.plot() def update(data): plt.plot(data, clear=True) class Thread(pg.QtCore.QThread): newData = pg.Q...
2014/03/21
[ "https://Stackoverflow.com/questions/22567083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2585497/" ]
Your program is exiting immediately because you have given it nothing to do after it starts the thread. The error you see is because the thread is surprised that the main thread has exited without it. Solution: add `QtGui.QApplication.exec_()` to the end of the script. Or, if you have PyQt (not PySide) you can run fr...
When you call `QThread.start()`, that function returns immediately. What happens is, 1. Thread #1 - creates new thread, #2 2. Thread #2 is created 3. Thread #1 regains control and runs. 4. Thread #1 dies or `thread` variable is cleaned up by GC (garbage collector) - I'm assuming the 2nd scenario should not happen To ...
22,567,083
I'm trying to run this simple example I found [here](https://groups.google.com/forum/#!msg/pyqtgraph/haiJsGhxTaQ/sTtMa195dHsJ), on MacOS X with Anaconda python. ``` import pyqtgraph as pg import time plt = pg.plot() def update(data): plt.plot(data, clear=True) class Thread(pg.QtCore.QThread): newData = pg.Q...
2014/03/21
[ "https://Stackoverflow.com/questions/22567083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2585497/" ]
Your program is exiting immediately because you have given it nothing to do after it starts the thread. The error you see is because the thread is surprised that the main thread has exited without it. Solution: add `QtGui.QApplication.exec_()` to the end of the script. Or, if you have PyQt (not PySide) you can run fr...
The `pyqtgraph.plot` method seems buggy to me (anyway, I wasn't able to get it to produce any useful output, but maybe I'm doing something wrong). However, if I create a `PlotWidget` and set up the application "manually", it all works as expected: ``` import pyqtgraph as pg import numpy as np import time app = pg.Qt...
11,466,909
``` node helloworld.js alex ``` I want it to console.log() alex. How do I pass "alex" as an argument into the code? In python ,it is `sys.argv[1]`
2012/07/13
[ "https://Stackoverflow.com/questions/11466909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179736/" ]
You can access command line arguments using `process.argv` in node.js. The array also includes the node command and the application file, so the first custom command line argument will have an index = 2. ``` process.argv[2] === 'alex'; // true ``` <http://nodejs.org/api/process.html#process_process_argv>
If your requirements are more complex and you can take advantage of a command line argument parser, there are several choices. Two that seem popular are * <https://www.npmjs.org/package/minimist> (simple and minimal) * <https://www.npmjs.org/package/nomnom> (option parser with generated usage and commands) More optio...
55,400,056
I have two lists of dicts: `list1` and `list2`. ``` print(list1) [{'name': 'fooa', 'desc': 'bazv', 'city': 1, 'ID': 1}, {'name': 'bard', 'desc': 'besd', 'city': 2, 'ID': 1}, {'name': 'baer', 'desc': 'bees', 'city': 2, 'ID': 1}, {'name': 'aaaa', 'desc': 'bnbb', 'city': 1, 'ID': 2}, {'name': 'cgcc', 'desc': 'dgdd', ...
2019/03/28
[ "https://Stackoverflow.com/questions/55400056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10095977/" ]
You can use [`itertools.product`](https://docs.python.org/3.7/library/itertools.html#itertools.product) and `filter`: ``` from itertools import product list1 = [{'name': 'fooa', 'desc': 'bazv', 'city': 1, 'ID': 1}, {'name': 'bard', 'desc': 'besd', 'city': 2, 'ID': 1}, {'name': 'baer', 'desc': 'bees'...
Having nested loops is not "not pythonic". However, you can achieve the same result with a list comprehension. I don't think it's more readable though: ``` [(i, j) for j in list2 for i in list1 if i['ID'] == j['ID'] and i['city'] == j['city']] ```
55,400,056
I have two lists of dicts: `list1` and `list2`. ``` print(list1) [{'name': 'fooa', 'desc': 'bazv', 'city': 1, 'ID': 1}, {'name': 'bard', 'desc': 'besd', 'city': 2, 'ID': 1}, {'name': 'baer', 'desc': 'bees', 'city': 2, 'ID': 1}, {'name': 'aaaa', 'desc': 'bnbb', 'city': 1, 'ID': 2}, {'name': 'cgcc', 'desc': 'dgdd', ...
2019/03/28
[ "https://Stackoverflow.com/questions/55400056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10095977/" ]
This is a problem well suited for `pandas`. If you convert the lists to DataFrames, matching the records on `ID` and `city` is the same as an [inner join of the two DataFrames](https://stackoverflow.com/questions/53645882/pandas-merging-101). ``` import pandas as pd # convert lists to DataFrames df1 = pd.DataFrame(li...
Having nested loops is not "not pythonic". However, you can achieve the same result with a list comprehension. I don't think it's more readable though: ``` [(i, j) for j in list2 for i in list1 if i['ID'] == j['ID'] and i['city'] == j['city']] ```
55,400,056
I have two lists of dicts: `list1` and `list2`. ``` print(list1) [{'name': 'fooa', 'desc': 'bazv', 'city': 1, 'ID': 1}, {'name': 'bard', 'desc': 'besd', 'city': 2, 'ID': 1}, {'name': 'baer', 'desc': 'bees', 'city': 2, 'ID': 1}, {'name': 'aaaa', 'desc': 'bnbb', 'city': 1, 'ID': 2}, {'name': 'cgcc', 'desc': 'dgdd', ...
2019/03/28
[ "https://Stackoverflow.com/questions/55400056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10095977/" ]
You can use [`itertools.product`](https://docs.python.org/3.7/library/itertools.html#itertools.product) and `filter`: ``` from itertools import product list1 = [{'name': 'fooa', 'desc': 'bazv', 'city': 1, 'ID': 1}, {'name': 'bard', 'desc': 'besd', 'city': 2, 'ID': 1}, {'name': 'baer', 'desc': 'bees'...
This is a problem well suited for `pandas`. If you convert the lists to DataFrames, matching the records on `ID` and `city` is the same as an [inner join of the two DataFrames](https://stackoverflow.com/questions/53645882/pandas-merging-101). ``` import pandas as pd # convert lists to DataFrames df1 = pd.DataFrame(li...
3,824,373
I am quite new at python and regex so please bear with me. I am trying to read in a file, match a particular name using a regex while ignoring the case, and store each time I find it. For example, if the file is composed of `Bill bill biLl biLL`, I need to store each variation in a dictionary or list. Current code: ``...
2010/09/29
[ "https://Stackoverflow.com/questions/3824373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/461063/" ]
I'd use findall: ``` re.findall(r'bill', open(filename).read(), re.I) ``` Easy as pie: ``` >>> s = 'fooBiLL bill BILL bIlL foo bar' >>> import re >>> re.findall(r'bill', s, re.I) ['BiLL', 'bill', 'BILL', 'bIlL'] ```
I think that you want [re.findall](http://localhost/docs/python-2.7-docs-html/library/re.html#re.findall). This is of course available on the compiled regular expression as well. The particular error code that you are getting though, would seem to indicate that you are [not matching your pattern](http://localhost/docs/...
65,890,917
I would like to obtain a nested dictionary from a string, which can be split by delimiter, `:`. ``` s='A:B:C:D' v=['some','object'] desired={'A':{'B':{'C':{'D':v}}}} ``` Is there a "pythonic" way to generate this?
2021/01/25
[ "https://Stackoverflow.com/questions/65890917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12844579/" ]
Hmmm . . . You want the most recent value from the `tracker` table. Then compare that to the existing values and insert where there are differences: ``` INSERT INTO Tracker (customer_id, value, date_of_value) SELECT v.customer_id, v.value, GETDATE() FROM (SELECT v.*, ROW_NUMBER() OVER (PARTITI...
We can create a trigger on the main table to insert a new row into the tracker table: ```sql CREATE TRIGGER trg_Tracking ON MainTable AFTER INSERT, UPDATE AS IF (NOT UPDATE(value) OR NOT EXISTS (SELECT customer_id, value FROM inserted EXCEPT SELECT customer_id, value FROM deleted)) RETURN; -- e...
72,366,129
I want to reach a document, but I always get this error: **FileNotFoundError: [Errno 44] No such file or directory: 'dbs/school/students.ini' )** I've tried putting "/" or "./" before the dbs, but it doesn't work, so I want to know how can I reach that document, the dbs folder is in the same directory where I run the...
2022/05/24
[ "https://Stackoverflow.com/questions/72366129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19059715/" ]
Probably you need to add the file to your paths in your html code like: ``` <py-env> - paths: - dbs/school/students.ini </py-env> ``` This way it should be added to your python environment.
i had the same issue, the solution i found was to insert my file into a github public branch and get the link from my github file, the code is below: ``` from pyodide.http import open_url url_content = open_url('https://raw.githubusercontent.com/') ``` to know more about it read <https://pyodide.org/en/stable/usage...
22,489,243
I'm writing tutorial about "advanced" regular expressions for Python, and I cannot understand ``` lastindex ``` attribute. Why is it always 1 in the given examples: <http://docs.python.org/2/library/re.html#re.MatchObject.lastindex> I mean this example: ``` re.match('((ab))', 'ab').lastindex ``` Why is it 1? Se...
2014/03/18
[ "https://Stackoverflow.com/questions/22489243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1377803/" ]
`lastindex` is the index of the last group that matched. The examples in the documentation include one that uses 2 capturing groups: ``` (a)(b) ``` where `lastindex` is set to 2 as the last capturing group to match was `(b)`. The attribute comes in handy when you have optional capturing groups; compare: ``` >>> re...
In regex groups are captured using `()`. In python `re` the `lastindex` holds the last capturing group. Lets see this small code example: ``` match = re.search("(\w+).+?(\d+).+?(\W+)", "input 123 ---") if match: print match.lastindex ``` In this example, the output will be 3 as I have used three `()` in my rege...
12,059,852
I am new to python or coding , so please be patient with my question, So here's my busy XML ``` <?xml version="1.0" encoding="utf-8"?> <Total> <ID>999</ID> <Response> <Detail> <Nix> <Check>pass</Check> </Nix> <MaxSegment> <Status>V</Status> ...
2012/08/21
[ "https://Stackoverflow.com/questions/12059852", "https://Stackoverflow.com", "https://Stackoverflow.com/users/918460/" ]
Figured it out, add the `UIPopoverController` delegate in addition to the `UISplitViewControllerDelegate`: ```c //Sent when switching to portrait - (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopov...
When you get that first delegate notification, you're passed a reference to the UIPopoverController that will present the hidden view controller. Register as its delegate, then use the [`-popoverControllerDidDismissPopover:`](http://developer.apple.com/library/ios/documentation/uikit/reference/UIPopoverControllerDelega...
50,107,263
I have the following dataframe: ``` 0 1 2 3 4 0 1.JPG NaN NaN NaN NaN 1 2883 2957.0 3412.0 3340.0 miscellaneous 2 3517 3007.0 4062.0 3371.0 miscellaneous 3 5678 3158.0 6299.0 3423.0 miscellaneous 4 ...
2018/04/30
[ "https://Stackoverflow.com/questions/50107263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4663377/" ]
You can use: ``` for n,g in df.assign(grouper = df['0'].where(df['1'].isnull()) .ffill().astype('category'))\ .dropna().groupby('grouper'): g.drop('grouper', axis=1).to_csv(n+'.csv', header=None, index=False) ``` ***Note:*** used astype('category') to pickup tha...
``` # program splits one big csv file into individiual image csv 's import pandas as pd import numpy as np df = pd.read_csv('results.csv', header=None) #df1 = df.replace(np.nan, '1', regex=True) print(df) for n,g in df.assign(grouper = df[0].where(df[1].isnull()) .ffill().astype...
36,243,814
I noticed this while playing around with graph\_tool. Some module attributes only seem to be available when run from ipython. The simplest example (example.py) ``` import graph_tool as gt g = gt.Graph() gt.draw.sfdp_layout(g) ``` Runs without error from ipython using `run example.y', but from the command line,`pyth...
2016/03/27
[ "https://Stackoverflow.com/questions/36243814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1308706/" ]
based on comments: if you are attempting to create a database programmatically, you can't use a connection to an unborn database, so in this situation you must open a connection to `master` database, something like that: ``` "Server = localhost; Database = master; User Id = 123; Password = abc;" ```
``` String str; SqlConnection myConn = new SqlConnection("Server=localhost;User Id = 123; Password = abc;database=master"); str = "CREATE DATABASE database1"; SqlCommand myCommand = new SqlCommand(str, myConn); try { myConn.Open(); myCommand.Exec...
2,125,612
I'm building my first python app on app-engine and wondering if I should use Django or not. What are the strong points of each? If you have references that support your answer, please post them. Maybe we can make a wiki out of this question.
2010/01/24
[ "https://Stackoverflow.com/questions/2125612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16628/" ]
Aral Balkan wrote [a really nice piece](http://aralbalkan.com/1313) addressing this very question. Its a year or so old, so take it with a grain of salt - I think that a lot more emphasis should be put on the awesomeness of django's Object-Relational-Model. Basically, IMHO, it all comes down to whether or not you have ...
If it's not a small project, I try to use Django. You can use the App Engine Patch (<http://code.google.com/p/app-engine-patch/>). However, the ORM cannot use Django's meaning your models.py will still be using GAE's Datastore. One of the advantages of using Django on GAE is session management. GAE does not have a bui...
72,297,725
On my OSX M1 Mac I have the following keyring setup which works with Google Artifact Repository to resolve dependencies when using python on the command line shell. Refer to <https://cloud.google.com/artifact-registry/docs/python/store-python> ``` $ keyring --list-backends keyring.backends.chainer.ChainerBack...
2022/05/19
[ "https://Stackoverflow.com/questions/72297725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/78000/" ]
Based on your description, I suppose you have successfully set up the Python virtual environment (venv) and installed all the dependencies via the terminal (Step 1-4 in <https://cloud.google.com/artifact-registry/docs/python/store-python>). And you want PyCharm also run your Python codes using that virtual environment....
It's basically the same as what you found already on your link but you missed the following site :) 1. Setup service account with `roles/artifactregistry.writer` rights 2. Create key file (json file with your credentials) using `gcloud iam service-accounts keys create FILE_NAME.json --iam-account=SERVICE_ACCOUNT_NAME@...
12,790,065
When I use the python Sybase package, and do a cursor fetch(), one of the columns is a datetime - in the sequence returned, it has a DateTimeType object for this value. I can find it is in the sybasect module but can't find any documentation for this datatype. I would like to be able to convert it to a string output - ...
2012/10/08
[ "https://Stackoverflow.com/questions/12790065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1133237/" ]
I think this is what are you looking for ``` $db = Zend_Db::factory( ...options... ); $select = $db->select() ->from(array('org' => 'orgTable'), array( 'orgid' => 'org.orgid', 'role' =>'org.role', 'userid' =>'...
Here is a `Zend_Db_Select` that returns the result you are looking for. ``` $select = $db->select() ->from(array('org' => 'orgTable'), array('orgid', 'role')) ->join(array('user' => 'userTable'), 'org.userid = user.userid', array('userid', 'firstname')) ->where('o...
12,790,065
When I use the python Sybase package, and do a cursor fetch(), one of the columns is a datetime - in the sequence returned, it has a DateTimeType object for this value. I can find it is in the sybasect module but can't find any documentation for this datatype. I would like to be able to convert it to a string output - ...
2012/10/08
[ "https://Stackoverflow.com/questions/12790065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1133237/" ]
I think this is what are you looking for ``` $db = Zend_Db::factory( ...options... ); $select = $db->select() ->from(array('org' => 'orgTable'), array( 'orgid' => 'org.orgid', 'role' =>'org.role', 'userid' =>'...
In **zend framework 2** , the following code helps you what are you looking for ``` $generated_id = 1 ; $select = new \Zend\Db\Sql\Select( array('org' =>'orgTable')); $select->columns(array('orgid','role') ) ->join( array('user' => 'userTable'), 'org.userid = user.userid', arr...
36,331,946
I installed Linux Mint as Virtual Machine. When I do: ``` python --version ``` I get: ``` Python 2.7.6 ``` I installed seperate python folder acording to [this](http://www.experts-exchange.com/articles/18641/Upgrade-Python-2-7-6-to-Python-2-7-10-on-Linux-Mint-OS.html). and When I do: ``` python2.7 --version ```...
2016/03/31
[ "https://Stackoverflow.com/questions/36331946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1712099/" ]
mPDF uses autosizing tables and this influences, among other things, the font-size as well. When outputting tables with mPDF you need to set: ``` <table style="overflow: wrap"> ``` on every table according to this [answer](https://stackoverflow.com/questions/23760018/mpdf-font-size-not-working). You can set font-s...
kindly use ``` $mpdf->keep_table_proportions = false; ```
62,264,821
Here is my [python](/questions/tagged/python "show questions tagged 'python'") code: ```py while exit: serialnumber = int(input("serial number of product :")) try: if len(str(serialnumber)) == 6: break else: print("serial number cant be used") serialnumber = int...
2020/06/08
[ "https://Stackoverflow.com/questions/62264821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13653559/" ]
You don't need to do any math manually. Simply declare a `DIBSECTION` variable, and then pass a pointer to it to `GetObject()` along with `sizeof()` as the size of that variable, eg: ``` DIBSECTION dib; GetObject(hBitmap, sizeof(dib), &dib); ```
I took out a piece of paper and added up everything myself. A `DIBSECTION` contains 5 parts. ``` typedef struct tagDIBSECTION { BITMAP dsBm; BITMAPINFOHEADER dsBmih; DWORD dsBitfields[3]; HANDLE dshSection; DWORD dsOffset; } DIBSECTION, *LPDIBSECTION, *PDIBSECTION; ...
62,563,923
This seems really basic but I can't seem to figure it out. I am working in a Pyspark Notebook on EMR and have taken a pyspark dataframe and converted it to a pandas dataframe using `toPandas()`. Now, I would like to save this dataframe to the local environment using the following code: ``` movie_franchise_counts.to_c...
2020/06/24
[ "https://Stackoverflow.com/questions/62563923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13136602/" ]
Your not passing anything to updateSettings `google.script.run.updateSettings();`> I would do it like this: ``` <input type = "button" value="Submit" onClick="google.script.run.updateSettings(this.parentNode);" /> ``` I'm running this as a dialog and it runs okay now. I added values to the radio buttons and now th...
Got it to work. The secret was needed to just JSON to properly store the form input criteria. **CODE** ``` function updateSettings(formObject) { var uiForm = SpreadsheetApp.getUi(); JSON.stringify(formObject); var formText = formObject.formQ1; var formRadio = formObject.formQ2; if (formR...
72,688,811
I tried to implement the binary tree program in python. I want to add one more function to get the level of a specific node. eg:- ``` 10 # level 0 / \ 5 15 # level 1 / \ 3 7 # level 2 ``` if we search the level of node 3, it should return ``` class BinaryTree: def __init__(self, d...
2022/06/20
[ "https://Stackoverflow.com/questions/72688811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14931124/" ]
If by "simplify", you mean "shorten", then this is as good as it gets: ``` public get isUsersLimitReached(): boolean { return !this.isAdmin && usersCount >= this.max_users; } ``` Other than that, there's really not much to work with here.
A user limit is reached only if the user is not admin and count exceeds. ``` public get isUsersLimitReached(): boolean { return !this.isAdmin && usersCount >= this.max_users; } ```
67,775,753
This is extended question to [Can we send data from Google cloud storage to SFTP server using GCP Cloud function?](https://stackoverflow.com/questions/67772938/can-we-send-data-from-cloud-storage-to-sftp-server-using-gcp-cloud-function) ```py with pysftp.Connection(host=myHostName, username=myUsername, ...
2021/05/31
[ "https://Stackoverflow.com/questions/67775753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15452168/" ]
For google, there is a formula googlefinance. For yahoo, all datas are imported in the code source within a big json you can fetch by this way ``` var source = UrlFetchApp.fetch(url).getContentText() var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}' var data = JSON.parse(jsonString) ``...
See formula GOOGLEFINANCE in Google Sheets. It's not totally live (about 20 minutes delay) but for many purposes is enough. I use it mostly for currency exchange rates but there far more options: <https://support.google.com/docs/answer/3093281?hl=en> Yahoo Finance and most of live sites are protected against webscrap...
67,775,753
This is extended question to [Can we send data from Google cloud storage to SFTP server using GCP Cloud function?](https://stackoverflow.com/questions/67772938/can-we-send-data-from-cloud-storage-to-sftp-server-using-gcp-cloud-function) ```py with pysftp.Connection(host=myHostName, username=myUsername, ...
2021/05/31
[ "https://Stackoverflow.com/questions/67775753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15452168/" ]
For google, there is a formula googlefinance. For yahoo, all datas are imported in the code source within a big json you can fetch by this way ``` var source = UrlFetchApp.fetch(url).getContentText() var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}' var data = JSON.parse(jsonString) ``...
I also built a Google sheets add-on that allows you to access fundamental and realtime financial data for tens of thousands of global companies, ETFs and Cryptos. You can access fundamental information like revenue or cashflow from specific years. It's still in its early phases but you can check it out in the add-on st...
67,775,753
This is extended question to [Can we send data from Google cloud storage to SFTP server using GCP Cloud function?](https://stackoverflow.com/questions/67772938/can-we-send-data-from-cloud-storage-to-sftp-server-using-gcp-cloud-function) ```py with pysftp.Connection(host=myHostName, username=myUsername, ...
2021/05/31
[ "https://Stackoverflow.com/questions/67775753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15452168/" ]
For google, there is a formula googlefinance. For yahoo, all datas are imported in the code source within a big json you can fetch by this way ``` var source = UrlFetchApp.fetch(url).getContentText() var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}' var data = JSON.parse(jsonString) ``...
Regarding cryptocurrency coins you can simply use `=IMPORTDATA("https://cryptoprices.cc/BTC/")` Google Finance only supports the very biggest coins (BTC, ETH), not much more. Other services usually require fragile web page parsing which is difficult, error prone and not a long term solution. From looking at some of...
46,282,656
I have a test project that looks like this: ``` _ test_project ├- __init__.py ├- main.py └- output.py ``` `__init__.py` is empty, and the other two files look like this: ``` # main.py from . import output ``` and ``` # output.py print("hello world") ``` I would like to import `output.py` just for the side effe...
2017/09/18
[ "https://Stackoverflow.com/questions/46282656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5203563/" ]
Relative imports can only be performed in a package. So, run the code as a package. ``` $ cd /pathabovetest_project $ python -m test_project.main ```
Just do `import output`, that worked for me.
57,712,218
I try to use requests to get a url of file. It works well locally but it doesn't work with nameko. I tried 3 libs of python3.7. But all has the same error. import urllib.request,urllib3,requests it works well locally like this: ```py import requests url = "https://www.python.org/static/img/python-logo.png" r = reque...
2019/08/29
[ "https://Stackoverflow.com/questions/57712218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11994979/" ]
It is an eventlet bug. If it is possible you need to downgrade to Python 3.6. <https://github.com/eventlet/eventlet/issues/526> Nameko has a PR for this issue which is on pause until the above is fixed. <https://github.com/nameko/nameko/pull/644>
I caught the same error with python 3.7, eventlet 0.25.2, requests 2.24.0. It works fine with requests 2.23.0
6,918,719
Whenever I try to create a table using python and sqlite3, it gives me the following error: ``` Traceback (most recent call last) File "directory.py", line 14, in <module> 'Children' TEXT, 'Other' TEXT, 'Masul' TEXT);''') sqlite3.OperationalError: near ")": syntax error ``` The way I'm trying to create the table is:...
2011/08/02
[ "https://Stackoverflow.com/questions/6918719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/764746/" ]
Often when you get this kind of error it is because you are using keywords as column (or table) names. I see that you have a column called `primary`. You will want to put backticks around it or rename it because [it is a keyword in SQLite](http://www.sqlite.org/lang_keywords.html); e.g.: ``` ... `Primary` TEXT, .....
You have a trailing "," before the closing parenthesis.
6,918,719
Whenever I try to create a table using python and sqlite3, it gives me the following error: ``` Traceback (most recent call last) File "directory.py", line 14, in <module> 'Children' TEXT, 'Other' TEXT, 'Masul' TEXT);''') sqlite3.OperationalError: near ")": syntax error ``` The way I'm trying to create the table is:...
2011/08/02
[ "https://Stackoverflow.com/questions/6918719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/764746/" ]
Often when you get this kind of error it is because you are using keywords as column (or table) names. I see that you have a column called `primary`. You will want to put backticks around it or rename it because [it is a keyword in SQLite](http://www.sqlite.org/lang_keywords.html); e.g.: ``` ... `Primary` TEXT, .....
There's a missing `)` in your sample, and since the error is in your SQL you should probably include the actual execute statement not `...`. But i'd say your error is a trailing `,` at the end of the list of your columns.
2,811,822
In other languages (ruby, python, ...) I can use `zip(list1, list2)` which works like this: If `list1 is {1,2,3,4}` and `list2 is {a,b,c}` then `zip(list1, list2)` would return: `{(1,a), (2,b), (3,c), (d,null)}` Is such a method available in .NET's Linq extensions?
2010/05/11
[ "https://Stackoverflow.com/questions/2811822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11545/" ]
.NET 4 gives us a [`Zip`](http://msdn.microsoft.com/en-us/library/dd267698.aspx) method but it is not available in .NET 3.5. If you are curious, [Eric Lippert provides an implementation of `Zip`](http://blogs.msdn.com/ericlippert/archive/2009/05/07/zip-me-up.aspx) that you may find useful.
neither implementation will fill in the missing values (or check that the lengths are the same) as the question asked. here is an implementation that can: ``` public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult> (this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TRes...
31,823,262
I just started python a few days ago and have been working on a calculator (not extremely basic, but also not advanced). The problem doesn't prevent code from running or anything, it is just a visual thing. Output in the console looks like this (stuff in parenthesis is explaining what is happening and is not actually p...
2015/08/05
[ "https://Stackoverflow.com/questions/31823262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5166610/" ]
Your problem is that you're asking for `input()` without specifying what you want. So if you take a look at the first one: `firstNumber = float(input())` It's executing properly, but you hit `enter` it gives an error which is only then you're specifying what you want. Try replacing with these: ``` ... try firstNu...
That's a [nice exercise](http://alfasin.com/2015/08/05/a-simple-calculator-in-python/), and as I wrote in the comments, I would ignore whitespaces, take the expression as a whole from the user and then parse it and calculate the result. Here's a small demo: ``` def is_number(s): try: float(s) retur...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
You're overthinking it This part is trying to do too much ``` for word in words: for i in range(len(word)): temp = string[0:i] + first + string[i:len(string)] print "temp = " + str(temp) perm.append(temp) ``` See how simple it really should be ``` def get_powerset (string): perm = [...
Here's a refactored iterative solution **without** the `itertools` module: ``` def powerset(s): a = [''] for i,c in enumerate(s): for k in range(2**i): a.append(a[k]+c) return a ```
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
Is this what you want? ``` import itertools as it def func(s): for i in range(len(s)+1): for combo in it.combinations(s,i): yield "".join(combo) print list(func("abc")) ```
Use [`powerset`](https://more-itertools.readthedocs.io/en/latest/api.html#more_itertools.powerset) from [`more_itertools`](https://github.com/erikrose/more-itertools): ``` >>> import more_itertools >>> ["".join(p) for p in list(more_itertools.powerset("ab"))] ['', 'a', 'b', 'ab'] ``` This `powerset` is a convenienc...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
There are a method for permutations: ``` >>> import itertools >>> chars = "ABCD" >>> perms = list(itertools.permutations(chars)) >>> print(perms) [('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')] ```
Use [`powerset`](https://more-itertools.readthedocs.io/en/latest/api.html#more_itertools.powerset) from [`more_itertools`](https://github.com/erikrose/more-itertools): ``` >>> import more_itertools >>> ["".join(p) for p in list(more_itertools.powerset("ab"))] ['', 'a', 'b', 'ab'] ``` This `powerset` is a convenienc...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
You're overthinking it This part is trying to do too much ``` for word in words: for i in range(len(word)): temp = string[0:i] + first + string[i:len(string)] print "temp = " + str(temp) perm.append(temp) ``` See how simple it really should be ``` def get_powerset (string): perm = [...
Use [`powerset`](https://more-itertools.readthedocs.io/en/latest/api.html#more_itertools.powerset) from [`more_itertools`](https://github.com/erikrose/more-itertools): ``` >>> import more_itertools >>> ["".join(p) for p in list(more_itertools.powerset("ab"))] ['', 'a', 'b', 'ab'] ``` This `powerset` is a convenienc...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
There are a method for permutations: ``` >>> import itertools >>> chars = "ABCD" >>> perms = list(itertools.permutations(chars)) >>> print(perms) [('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')] ```
Have you tried tracing through what your algorithm actually does? ``` getperm('ab'): first, rem = 'a', 'b' words = getperm('b') first, rem = 'b', '' words = getperm('') words = [''] for word in words: for i in range(len(word)): pass # only called on '', so doesn't matter return []...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
Here's a refactored iterative solution **without** the `itertools` module: ``` def powerset(s): a = [''] for i,c in enumerate(s): for k in range(2**i): a.append(a[k]+c) return a ```
Have you tried tracing through what your algorithm actually does? ``` getperm('ab'): first, rem = 'a', 'b' words = getperm('b') first, rem = 'b', '' words = getperm('') words = [''] for word in words: for i in range(len(word)): pass # only called on '', so doesn't matter return []...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
You're overthinking it This part is trying to do too much ``` for word in words: for i in range(len(word)): temp = string[0:i] + first + string[i:len(string)] print "temp = " + str(temp) perm.append(temp) ``` See how simple it really should be ``` def get_powerset (string): perm = [...
Have you tried tracing through what your algorithm actually does? ``` getperm('ab'): first, rem = 'a', 'b' words = getperm('b') first, rem = 'b', '' words = getperm('') words = [''] for word in words: for i in range(len(word)): pass # only called on '', so doesn't matter return []...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
Here's a refactored iterative solution **without** the `itertools` module: ``` def powerset(s): a = [''] for i,c in enumerate(s): for k in range(2**i): a.append(a[k]+c) return a ```
Use [`powerset`](https://more-itertools.readthedocs.io/en/latest/api.html#more_itertools.powerset) from [`more_itertools`](https://github.com/erikrose/more-itertools): ``` >>> import more_itertools >>> ["".join(p) for p in list(more_itertools.powerset("ab"))] ['', 'a', 'b', 'ab'] ``` This `powerset` is a convenienc...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
Is this what you want? ``` import itertools as it def func(s): for i in range(len(s)+1): for combo in it.combinations(s,i): yield "".join(combo) print list(func("abc")) ```
Have you tried tracing through what your algorithm actually does? ``` getperm('ab'): first, rem = 'a', 'b' words = getperm('b') first, rem = 'b', '' words = getperm('') words = [''] for word in words: for i in range(len(word)): pass # only called on '', so doesn't matter return []...
12,632,421
I'm trying to write python code to print the [powerset](/tags/powerset/info) of a string, but am running into some bugs. Here's what I've got: ``` def getperm (string): perm = [] if len(string) == 0: perm.append("") return perm #if len(string) == 1: # perm.append(string) # perm....
2012/09/28
[ "https://Stackoverflow.com/questions/12632421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390268/" ]
Here's a refactored iterative solution **without** the `itertools` module: ``` def powerset(s): a = [''] for i,c in enumerate(s): for k in range(2**i): a.append(a[k]+c) return a ```
There are a method for permutations: ``` >>> import itertools >>> chars = "ABCD" >>> perms = list(itertools.permutations(chars)) >>> print(perms) [('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')] ```
9,887,319
I am running a server with cherrypy and python script. Currently, there is a web page containing data of a list of people, which i need to get. The format of the web page is as follow: ``` www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2, lastName_2 www.url3.com, firstName_3, lastName_3 ``` I wish to...
2012/03/27
[ "https://Stackoverflow.com/questions/9887319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1008340/" ]
You need the `split(',')` method on each string: ``` data = [ line.split(',') for line in fptr.readlines() ] ```
``` lists = [] for line in data: lists.append([x.strip() for x in line.split(',')]) ```
9,887,319
I am running a server with cherrypy and python script. Currently, there is a web page containing data of a list of people, which i need to get. The format of the web page is as follow: ``` www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2, lastName_2 www.url3.com, firstName_3, lastName_3 ``` I wish to...
2012/03/27
[ "https://Stackoverflow.com/questions/9887319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1008340/" ]
You can iterate over fptr, no need to call `readlines()` ``` data = [line.split(', ') for line in fptr] ```
You need the `split(',')` method on each string: ``` data = [ line.split(',') for line in fptr.readlines() ] ```
9,887,319
I am running a server with cherrypy and python script. Currently, there is a web page containing data of a list of people, which i need to get. The format of the web page is as follow: ``` www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2, lastName_2 www.url3.com, firstName_3, lastName_3 ``` I wish to...
2012/03/27
[ "https://Stackoverflow.com/questions/9887319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1008340/" ]
You need the `split(',')` method on each string: ``` data = [ line.split(',') for line in fptr.readlines() ] ```
If you data is a big 'ole string (potentially with leading or trailing spaces), do it this way: ``` lines=""" www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2 , lastName_2 www.url3.com, firstName_3, lastName_3 """ data=[] for line in lines.split('\n'): t=[e.strip() for e in line...
9,887,319
I am running a server with cherrypy and python script. Currently, there is a web page containing data of a list of people, which i need to get. The format of the web page is as follow: ``` www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2, lastName_2 www.url3.com, firstName_3, lastName_3 ``` I wish to...
2012/03/27
[ "https://Stackoverflow.com/questions/9887319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1008340/" ]
You can iterate over fptr, no need to call `readlines()` ``` data = [line.split(', ') for line in fptr] ```
``` lists = [] for line in data: lists.append([x.strip() for x in line.split(',')]) ```
9,887,319
I am running a server with cherrypy and python script. Currently, there is a web page containing data of a list of people, which i need to get. The format of the web page is as follow: ``` www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2, lastName_2 www.url3.com, firstName_3, lastName_3 ``` I wish to...
2012/03/27
[ "https://Stackoverflow.com/questions/9887319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1008340/" ]
You can iterate over fptr, no need to call `readlines()` ``` data = [line.split(', ') for line in fptr] ```
If you data is a big 'ole string (potentially with leading or trailing spaces), do it this way: ``` lines=""" www.url1.com, firstName_1, lastName_1 www.url2.com, firstName_2 , lastName_2 www.url3.com, firstName_3, lastName_3 """ data=[] for line in lines.split('\n'): t=[e.strip() for e in line...
46,188,797
I use a script to parce some sites and get news from there. Each function in this script parse one site and return list of articles and then I want to combine them all in one big list. If I parce site by site it takes to long and I desided to use multithreading. I found a sample like this one in the bottom, but it seem...
2017/09/13
[ "https://Stackoverflow.com/questions/46188797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6217484/" ]
Solution without `Queue`: ``` NEWS = [] LOCK = Lock() def gather_news(url): while True: news = news_from(url) if not news: break with LOCK: NEWS.append(news) if __name__ == '__main__': T = [] for url in ['url1', 'url2', 'url3']: t = Thread(target=gather_news, ...
All, that you should do, is using a single queue and extend your result array: ``` q1 = Queue() Thread(target=wrapper, args=(last_news_from_bar, q1)).start() Thread(target=wrapper, args=(last_news_from_foo, q1)).start() all_news = [] all_news.extend(q1.get()) all_news.extend(q1.get()) print(all_news) ```
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Since neighboring string constants are automatically concatenated, you can code it like this: ``` s = ("this is my really, really, really, really, really, really, " "really long string that I'd like to shorten.") ``` Note no plus sign, and I added the extra comma and space that follows the formatting of your ...
I've used textwrap.dedent in the past. It's a little cumbersome so I prefer line continuations now but if you really want the block indent, I think this is great. Example Code (where the trim is to get rid of the first '\n' with a slice): ``` import textwrap as tw x = """\ This is a yet another test. T...
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
If you must insert a long string literal and want flake8 to shut up, you can use it's [shutting up directives](http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html). For example, in a testing routine I defined some fake CSV input. I found that splitting it over more lines that it had rows would be mightily confus...
``` message = f"Variable : child({type(child)}) -> is not of"\ " type Node." ``` This syntax worked for me. Note the indentation of the second statement, it should be indented correctly.
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
These are all great answers, but I couldn't find an editor plugin that would help me with editing "implicitly concatenated" strings, so I wrote a package to make it easier on me. On pip (install paragraphs) if whoever's wandering this old thread would like to check it out. Formats multi-line strings the way html does ...
Backslash: ``` s = "this is my really, really, really, really, really, really" + \ "really long string that I'd like to shorten." ``` or wrap in parens: ``` s = ("this is my really, really, really, really, really, really" + "really long string that I'd like to shorten.") ```
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Since neighboring string constants are automatically concatenated, you can code it like this: ``` s = ("this is my really, really, really, really, really, really, " "really long string that I'd like to shorten.") ``` Note no plus sign, and I added the extra comma and space that follows the formatting of your ...
``` message = f"Variable : child({type(child)}) -> is not of"\ " type Node." ``` This syntax worked for me. Note the indentation of the second statement, it should be indented correctly.
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Using **black** [https://github.com/psf/black] I format it like this. ``` help=f"""filters, lista de filtros para cargar las base de conocimiento. Pueden mandarse solo algunos filtros ya que no son obligatorios, por ejemplo, si no se manda sts, se cargarán todos las bases de todos los estados.""", ```
I've used textwrap.dedent in the past. It's a little cumbersome so I prefer line continuations now but if you really want the block indent, I think this is great. Example Code (where the trim is to get rid of the first '\n' with a slice): ``` import textwrap as tw x = """\ This is a yet another test. T...
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Implicit concatenation might be the cleanest solution: ``` s = "this is my really, really, really, really, really, really," \ " really long string that I'd like to shorten." ``` **Edit** On reflection I agree that Todd's suggestion to use brackets rather than line continuation is better for all the reasons he gi...
I think the most important word in your question was "suggests". Coding standards are funny things. Often the guidance they provide has a really good basis when it was written (e.g. most terminals being unable to show > 80 characters on a line), but over time they become functionally obsolete, but still rigidly adher...
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
If you must insert a long string literal and want flake8 to shut up, you can use it's [shutting up directives](http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html). For example, in a testing routine I defined some fake CSV input. I found that splitting it over more lines that it had rows would be mightily confus...
I tend to use a couple of methods not mentioned here for specifying large strings, but these are for very specific scenarios. YMMV... * Multi-line blobs of text, often with formatted tokens (not quite what you were asking, but still useful): ``` error_message = ''' I generally like to see how my helpful, sometimes mu...
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Available options: * **backslash**: `"foo" \ "bar"` * **plus sign** followed by **backslash**: `"foo" + \ "bar"` * **brackets**: + `("foo" "bar")` + **brackets** with **plus sign**: `("foo" + "bar")` + *PEP8, E502: the backslash is redundant between brackets* Avoid ===== Avoid brackets with comma: `("foo", "bar")...
With a `\` you can expand statements to multiple lines: ``` s = "this is my really, really, really, really, really, really" + \ "really long string that I'd like to shorten." ``` should work.
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
You lost a space, and you probably need a line continuation character, ie. a `\`. ``` s = "this is my really, really, really, really, really, really" + \ " really long string that I'd like to shorten." ``` or even: ``` s = "this is my really, really, really, really, really, really" \ " really long string ...
I tend to use a couple of methods not mentioned here for specifying large strings, but these are for very specific scenarios. YMMV... * Multi-line blobs of text, often with formatted tokens (not quite what you were asking, but still useful): ``` error_message = ''' I generally like to see how my helpful, sometimes mu...
1,874,592
As PEP8 suggests keeping below the 80 column rule for your python program, how can I abide to that with long strings, i.e. ``` s = "this is my really, really, really, really, really, really, really long string that I'd like to shorten." ``` How would I go about expanding this to the following line, i.e. ``` s = "th...
2009/12/09
[ "https://Stackoverflow.com/questions/1874592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/154280/" ]
Since neighboring string constants are automatically concatenated, you can code it like this: ``` s = ("this is my really, really, really, really, really, really, " "really long string that I'd like to shorten.") ``` Note no plus sign, and I added the extra comma and space that follows the formatting of your ...
I think the most important word in your question was "suggests". Coding standards are funny things. Often the guidance they provide has a really good basis when it was written (e.g. most terminals being unable to show > 80 characters on a line), but over time they become functionally obsolete, but still rigidly adher...
43,540,159
I am trying to build an executable out of my .py script using Pyinstaller. The problem is that it builds it using Python 2.7 instead of Python 3.5, so my executable won't even run. ``` cali@californiki-pc ~/Desktop $ pyinstaller --onefile Vocabulary.py 25 INFO: PyInstaller: 3.2.1 25 INFO: Python: 2.7.12 26 INFO: Plat...
2017/04/21
[ "https://Stackoverflow.com/questions/43540159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
To overcome the problem you face install PyInstaller using: > > pip3 install pyinstaller > > > Then take care that you run the right one (there will then be two of them in different locations, one in the path of Python2.7 modules and one in the path of Python3.5 modules) Just installed PyInstaller for Python 3.5...
Just set an option -upx-dir in pyinstaller specifying your path for python 3.5. It can be the virtual environment too. For instance: ``` pyinstaller --upx-dir="$HOME/virtual-envs/<your-virtual-env>/lib/python3.5/site-packages/" <your-script>.py' ```
43,540,159
I am trying to build an executable out of my .py script using Pyinstaller. The problem is that it builds it using Python 2.7 instead of Python 3.5, so my executable won't even run. ``` cali@californiki-pc ~/Desktop $ pyinstaller --onefile Vocabulary.py 25 INFO: PyInstaller: 3.2.1 25 INFO: Python: 2.7.12 26 INFO: Plat...
2017/04/21
[ "https://Stackoverflow.com/questions/43540159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Try: ``` py -3.5 -m PyInstaller Vocabulary.py --onefile ``` I think it is case sensitive
Just set an option -upx-dir in pyinstaller specifying your path for python 3.5. It can be the virtual environment too. For instance: ``` pyinstaller --upx-dir="$HOME/virtual-envs/<your-virtual-env>/lib/python3.5/site-packages/" <your-script>.py' ```
61,250,928
``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") while True: for x in range(text): score = int(input("Input score {} : ".format(x+1))) if score <= 0 & score >= 101: break print(int(input("Invalid ...
2020/04/16
[ "https://Stackoverflow.com/questions/61250928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13111498/" ]
Change the if statement: ``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") for x in range(text): score = int(input("Input score {} : ".format(x+1))) while True: if 0 <= score <= 100: break score = int(inp...
try this one: ``` array = [] total = 0 num_of_students = int(input("How many students in your class: ")) print("\n") for x in range(num_of_students): score = int(input("Input score {} : ".format(x + 1))) while True: if score < 0 or score > 100: score = int(input("Invalid score, please re-e...
61,250,928
``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") while True: for x in range(text): score = int(input("Input score {} : ".format(x+1))) if score <= 0 & score >= 101: break print(int(input("Invalid ...
2020/04/16
[ "https://Stackoverflow.com/questions/61250928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13111498/" ]
Change the if statement: ``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") for x in range(text): score = int(input("Input score {} : ".format(x+1))) while True: if 0 <= score <= 100: break score = int(inp...
You could try something like this: ``` score = -1 first_time = True while type(score) != int or score <= 0 or score >= 101 : if first_time: score = int(input("Input score: ")) first_time = False else: score = int(input("Invalid score, please re-enter: ")) array.append(score) ```
61,250,928
``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") while True: for x in range(text): score = int(input("Input score {} : ".format(x+1))) if score <= 0 & score >= 101: break print(int(input("Invalid ...
2020/04/16
[ "https://Stackoverflow.com/questions/61250928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13111498/" ]
Change the if statement: ``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") for x in range(text): score = int(input("Input score {} : ".format(x+1))) while True: if 0 <= score <= 100: break score = int(inp...
I renamed some of your variables. You should always try to using self explanatory variable names. I am also using string interpolation (should be possible for Python +3.6) and comparison chaining. ``` score_list = [] total = 0 number_of_students = int(input("How many students in your class: ")) print("\n") for stude...
61,250,928
``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") while True: for x in range(text): score = int(input("Input score {} : ".format(x+1))) if score <= 0 & score >= 101: break print(int(input("Invalid ...
2020/04/16
[ "https://Stackoverflow.com/questions/61250928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13111498/" ]
try this one: ``` array = [] total = 0 num_of_students = int(input("How many students in your class: ")) print("\n") for x in range(num_of_students): score = int(input("Input score {} : ".format(x + 1))) while True: if score < 0 or score > 100: score = int(input("Invalid score, please re-e...
You could try something like this: ``` score = -1 first_time = True while type(score) != int or score <= 0 or score >= 101 : if first_time: score = int(input("Input score: ")) first_time = False else: score = int(input("Invalid score, please re-enter: ")) array.append(score) ```
61,250,928
``` array = [] total = 0 text = int(input("How many students in your class: ")) print("\n") while True: for x in range(text): score = int(input("Input score {} : ".format(x+1))) if score <= 0 & score >= 101: break print(int(input("Invalid ...
2020/04/16
[ "https://Stackoverflow.com/questions/61250928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13111498/" ]
I renamed some of your variables. You should always try to using self explanatory variable names. I am also using string interpolation (should be possible for Python +3.6) and comparison chaining. ``` score_list = [] total = 0 number_of_students = int(input("How many students in your class: ")) print("\n") for stude...
You could try something like this: ``` score = -1 first_time = True while type(score) != int or score <= 0 or score >= 101 : if first_time: score = int(input("Input score: ")) first_time = False else: score = int(input("Invalid score, please re-enter: ")) array.append(score) ```
62,214,293
I usually start all my scripts with the shebang line ``` #!/usr/bin/env python ``` However our production server has Python 2 as the default `python`, while all of our new scripts and programs are being built under Python 3. To help keep people from accidentally running the script with the default Python 2, I am con...
2020/06/05
[ "https://Stackoverflow.com/questions/62214293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5359531/" ]
Yes, this is a safe bet. [PEP 394](https://www.python.org/dev/peps/pep-0394/) recommends Python 3 be available under the binary name `python3` and most Linux distributions follow this recommendation. In fact, this is the *only* name under which Python 3 has been available in most distributions (the only outlier being ...
I believe that a python 3 version only install's `python3` if there is already another version of python installed, no matter if it is a python 2 or python 3 version, because the standard `python` command would then not work properly for the new version of python. But please correct me if I'm wrong!
38,811,966
I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin [here](http://pastebin.com/DJrZjVkv). Also when I double click the exe file it shows this error: > > C:Users\Afro\AppData\Local\Temp\_MEI51322\VCRUNTIME140.dll is either not designed to ...
2016/08/07
[ "https://Stackoverflow.com/questions/38811966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6483094/" ]
I was haunted with similar issue. It might be that in your case UPX is breaking vcruntime140.dll. Solution to this is turning off UPX, so just add **--noupx** to your pyinstaller call. ``` pyinstaller --noupx --onedir --onefile --windowed get.py ``` Long explanation here: [UPX breaking vcruntime140.dll (64bit)](htt...
In my case it was: ``` pyinstaller --clean --win-private-assemblies --noupx --onedir --onefile script.py ``` **--windowed** caused problems with wxWidgets
38,811,966
I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin [here](http://pastebin.com/DJrZjVkv). Also when I double click the exe file it shows this error: > > C:Users\Afro\AppData\Local\Temp\_MEI51322\VCRUNTIME140.dll is either not designed to ...
2016/08/07
[ "https://Stackoverflow.com/questions/38811966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6483094/" ]
I was haunted with similar issue. It might be that in your case UPX is breaking vcruntime140.dll. Solution to this is turning off UPX, so just add **--noupx** to your pyinstaller call. ``` pyinstaller --noupx --onedir --onefile --windowed get.py ``` Long explanation here: [UPX breaking vcruntime140.dll (64bit)](htt...
I have also met this issue, and the root cause is that I am using upx to compress the file size. The solution is to exclude files which should not be compressed by upx: ``` pyinstaller --onefile --console --upx-dir=/path/to/upx --upx-exclude=vcruntime140.dll --upx-exclude=python36.dll my_script.py ```
38,811,966
I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin [here](http://pastebin.com/DJrZjVkv). Also when I double click the exe file it shows this error: > > C:Users\Afro\AppData\Local\Temp\_MEI51322\VCRUNTIME140.dll is either not designed to ...
2016/08/07
[ "https://Stackoverflow.com/questions/38811966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6483094/" ]
I was haunted with similar issue. It might be that in your case UPX is breaking vcruntime140.dll. Solution to this is turning off UPX, so just add **--noupx** to your pyinstaller call. ``` pyinstaller --noupx --onedir --onefile --windowed get.py ``` Long explanation here: [UPX breaking vcruntime140.dll (64bit)](htt...
I tried with this version of Pyinstaller commands, Add this commands to a `.bat` file and execute the `.bat` file. It worked for me: ``` pyinstaller --log-level=WARN ^ --upx-dir <PATH_TO_UPX.exe_FILE> ^ --upx-exclude vcruntime140.dll ^ --upx-exclude ucrtbase.dll ^ --upx-exclude qwindows.dll ^ --upx...
38,811,966
I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin [here](http://pastebin.com/DJrZjVkv). Also when I double click the exe file it shows this error: > > C:Users\Afro\AppData\Local\Temp\_MEI51322\VCRUNTIME140.dll is either not designed to ...
2016/08/07
[ "https://Stackoverflow.com/questions/38811966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6483094/" ]
I have also met this issue, and the root cause is that I am using upx to compress the file size. The solution is to exclude files which should not be compressed by upx: ``` pyinstaller --onefile --console --upx-dir=/path/to/upx --upx-exclude=vcruntime140.dll --upx-exclude=python36.dll my_script.py ```
In my case it was: ``` pyinstaller --clean --win-private-assemblies --noupx --onedir --onefile script.py ``` **--windowed** caused problems with wxWidgets
38,811,966
I'm trying to create an exe for my python script using pyinstaller each time it runs into errors which can be found in a pastebin [here](http://pastebin.com/DJrZjVkv). Also when I double click the exe file it shows this error: > > C:Users\Afro\AppData\Local\Temp\_MEI51322\VCRUNTIME140.dll is either not designed to ...
2016/08/07
[ "https://Stackoverflow.com/questions/38811966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6483094/" ]
I have also met this issue, and the root cause is that I am using upx to compress the file size. The solution is to exclude files which should not be compressed by upx: ``` pyinstaller --onefile --console --upx-dir=/path/to/upx --upx-exclude=vcruntime140.dll --upx-exclude=python36.dll my_script.py ```
I tried with this version of Pyinstaller commands, Add this commands to a `.bat` file and execute the `.bat` file. It worked for me: ``` pyinstaller --log-level=WARN ^ --upx-dir <PATH_TO_UPX.exe_FILE> ^ --upx-exclude vcruntime140.dll ^ --upx-exclude ucrtbase.dll ^ --upx-exclude qwindows.dll ^ --upx...
45,628,653
I have written a small program in `tkinter` in `python 3.5` I'm making executable out of it using `pyintaller` I have included a custom icon to the window to replace default feather icon of tkinter ``` from tkinter import * from tkinter import messagebox import webbrowser calculator = Tk() calculator.title("TBE Cal...
2017/08/11
[ "https://Stackoverflow.com/questions/45628653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3719167/" ]
Uninstall and re install the visual studio with azure service fabric tools resolved the problem.
![enter image description here](https://i.stack.imgur.com/qvNJB.jpg) I have install only runtime this way. Hope this will help you to install runtime only.
52,287,641
I have a the below `df1`: ``` Date Tickers Qty 01-01-2018 ABC 25 02-01-2018 BCD 25 02-01-2018 XYZ 31 05-01-2018 XYZ 25 ``` and another `df2` as below ``` Date ABC BCD XYZ 01-01-2018 123 5 78 02-01-2018 125 7 79 03-01-2018 127 6 81 04-01-2018 126 ...
2018/09/12
[ "https://Stackoverflow.com/questions/52287641", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6577574/" ]
Use: ``` df11 = df1.pivot('Date', 'Tickers','Qty') df22 = df2.set_index('Date') s = df22.mul(df11).bfill(axis=1).iloc[:, 0] print (s) Date 01-01-2018 3075.0 02-01-2018 175.0 03-01-2018 NaN 04-01-2018 NaN 05-01-2018 2075.0 Name: ABC, dtype: float64 ``` Solution for add new column to `df1`:...
you need to set 'Date' as index and multiply, ``` df1=df1.set_index('Date') df2=df2.set_index('Date') df3=(df2['ABC']*df1['Qty']).reset_index() print(df3) Date 0 0 01-01-2018 3075.0 1 02-01-2018 3125.0 2 03-01-2018 NaN 3 04-01-2018 NaN 4 05-01-2018 3100.0 ```
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
VS2019 also introduced new "enhanced" colors for .NET languages, for which there is a separate option to toggle on and off: [![Tools -> Options -> Text Editor -> C# -> Advanced, "Use enhanced colors for C# and Basic" setting](https://i.stack.imgur.com/IpRoV.png)](https://i.stack.imgur.com/IpRoV.png) The same checkbox...
It is possible to change in `Options->Environment->Fonts and Colors`. There is a list with different `User Memebers - ...` and `User Tyeps - ...` that define these colors. [![enter image description here](https://i.stack.imgur.com/D6XSR.png)](https://i.stack.imgur.com/D6XSR.png) I have actually changed `User Members ...
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
It is possible to change in `Options->Environment->Fonts and Colors`. There is a list with different `User Memebers - ...` and `User Tyeps - ...` that define these colors. [![enter image description here](https://i.stack.imgur.com/D6XSR.png)](https://i.stack.imgur.com/D6XSR.png) I have actually changed `User Members ...
If you are coding in C++ you probably have enhanced color activate. To deactivate go Tool-->Options and from the left menu select Text Editor-->C/C++-->View. Then go to the section "Miscellaneous" on the right and change "Color Scheme" from "Enhanced" to "Visual Studio 2017"
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
Updated answer for 2020. [![Visual Studio 2019 color scheme](https://i.stack.imgur.com/kt09L.png)](https://i.stack.imgur.com/kt09L.png) Make sure this is set to 2019.
It is possible to change in `Options->Environment->Fonts and Colors`. There is a list with different `User Memebers - ...` and `User Tyeps - ...` that define these colors. [![enter image description here](https://i.stack.imgur.com/D6XSR.png)](https://i.stack.imgur.com/D6XSR.png) I have actually changed `User Members ...
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
VS2019 also introduced new "enhanced" colors for .NET languages, for which there is a separate option to toggle on and off: [![Tools -> Options -> Text Editor -> C# -> Advanced, "Use enhanced colors for C# and Basic" setting](https://i.stack.imgur.com/IpRoV.png)](https://i.stack.imgur.com/IpRoV.png) The same checkbox...
If you are coding in C++ you probably have enhanced color activate. To deactivate go Tool-->Options and from the left menu select Text Editor-->C/C++-->View. Then go to the section "Miscellaneous" on the right and change "Color Scheme" from "Enhanced" to "Visual Studio 2017"
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
VS2019 also introduced new "enhanced" colors for .NET languages, for which there is a separate option to toggle on and off: [![Tools -> Options -> Text Editor -> C# -> Advanced, "Use enhanced colors for C# and Basic" setting](https://i.stack.imgur.com/IpRoV.png)](https://i.stack.imgur.com/IpRoV.png) The same checkbox...
Updated answer for 2020. [![Visual Studio 2019 color scheme](https://i.stack.imgur.com/kt09L.png)](https://i.stack.imgur.com/kt09L.png) Make sure this is set to 2019.
55,514,933
am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error: ```py AttributeError: module 'response' has no attribut...
2019/04/04
[ "https://Stackoverflow.com/questions/55514933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6553605/" ]
Updated answer for 2020. [![Visual Studio 2019 color scheme](https://i.stack.imgur.com/kt09L.png)](https://i.stack.imgur.com/kt09L.png) Make sure this is set to 2019.
If you are coding in C++ you probably have enhanced color activate. To deactivate go Tool-->Options and from the left menu select Text Editor-->C/C++-->View. Then go to the section "Miscellaneous" on the right and change "Color Scheme" from "Enhanced" to "Visual Studio 2017"
72,066,195
I want to insert zero at certain locations in an array, but the index position of the location exceeds the size of the array I wanted that as the numbers get inserted one by one, size also gets increased in that process (of the array X), so till it reaches index 62, it will not produce that error. ``` import numpy as...
2022/04/30
[ "https://Stackoverflow.com/questions/72066195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18746410/" ]
Make a copy of `X` into `X_new` so the array gets longer in loop as you desire. ``` X_new = X.copy() for i in desired_location: X_new = np.insert(X_new, i, 0) ```
how silly I was. ``` import numpy as np X = np.arange(0,57,1) desired_location = [ 0, 1, 24, 25, 26, 27, 62, 63] for i in desired_location: X = np.insert(X,i,0) print(X) ```
72,066,195
I want to insert zero at certain locations in an array, but the index position of the location exceeds the size of the array I wanted that as the numbers get inserted one by one, size also gets increased in that process (of the array X), so till it reaches index 62, it will not produce that error. ``` import numpy as...
2022/04/30
[ "https://Stackoverflow.com/questions/72066195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18746410/" ]
Make a copy of `X` into `X_new` so the array gets longer in loop as you desire. ``` X_new = X.copy() for i in desired_location: X_new = np.insert(X_new, i, 0) ```
Converting `tolist()`, inserting and converting to `np.array` is an order of magnitude faster. ``` # %%timeit 10000 loops, best of 5: 117 µs per loop X_new = X for i in desired_location: X_new = np.insert(X_new,i,0) ``` ``` # %%timeit 100000 loops, best of 5: 4.18 µs per loop X_new = X.tolist() for i in desired_...
72,066,195
I want to insert zero at certain locations in an array, but the index position of the location exceeds the size of the array I wanted that as the numbers get inserted one by one, size also gets increased in that process (of the array X), so till it reaches index 62, it will not produce that error. ``` import numpy as...
2022/04/30
[ "https://Stackoverflow.com/questions/72066195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18746410/" ]
how silly I was. ``` import numpy as np X = np.arange(0,57,1) desired_location = [ 0, 1, 24, 25, 26, 27, 62, 63] for i in desired_location: X = np.insert(X,i,0) print(X) ```
Converting `tolist()`, inserting and converting to `np.array` is an order of magnitude faster. ``` # %%timeit 10000 loops, best of 5: 117 µs per loop X_new = X for i in desired_location: X_new = np.insert(X_new,i,0) ``` ``` # %%timeit 100000 loops, best of 5: 4.18 µs per loop X_new = X.tolist() for i in desired_...
2,686,520
For what I've read I need Python-Dev, how do I install it on OSX? I think the problem I have, is, my Xcode was not properly installed, and I don't have the paths where I should. This previous question: [Where is gcc on OSX? I have installed Xcode already](https://stackoverflow.com/questions/2685887/where-is-gcc-on...
2010/04/21
[ "https://Stackoverflow.com/questions/2686520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20654/" ]
Might depend on what version of Mac OSX you have, I have it in these spots: ``` /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h /System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h ``` Also I believe the version of pyth...
Are you sure you want to build Mercurial from source? There are [binary packages available](https://www.mercurial-scm.org/downloads), including the nice [MacHg](http://jasonfharris.com/machg/) which comes with a bundled Mercurial.