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
47,261,255
I'm trying to execute a dag which needs to be run only once. So I placed the dag execution interval as '@once'. However, I'm getting the error as mentioned in this link - <https://issues.apache.org/jira/browse/AIRFLOW-1400> Now i'm trying to pass the exact date of execution as below: ``` default_args = { 'owner': 'a...
2017/11/13
[ "https://Stackoverflow.com/questions/47261255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7229291/" ]
Grouping by either "TransactionCategory" or "TranCatID" will give you the desired result shown as follows: ``` SELECT TransactionCategory.TransCatName, SUM( `Value`) AS Value FROM Transactions JOIN TransactionCategory on Transactions.TransactionCategory = TransactionCategory.TranCatID GROUP BY TransactionCategory.Tra...
You can use this : ``` SELECT tc.TransCatName Category, SUM(t.Value) as Value FROM TransactionCategory tc LEFT JOIN Transactions t ON tc.TranCatID = t.TransactionCategory group by tc.TransCatName ``` [SQL HERE](http://sqlfiddle.com/#!9/136aa3/1) **OUTPUT** ``` Category | Value ----------------------- Petrol ...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
Since you mentioned you can use **lodash** you can use [`merge`](https://lodash.com/docs/4.17.11#merge) like so: `_.merge(obj1, obj2)` to get your desired result. See working example below: ```js const a = { 1: { foo: 1 }, 2: { bar: 2, fooBar: 3 }, 3: { fooBar: 3 }, }, b = { 1: { foo: 1, bar: 2 }, ...
you can use Object.assign and and assign object properties to empty object. ``` var a = {books: 2}; var b = {notebooks: 1}; var c = Object.assign( {}, a, b ); console.log(c); ``` or You could use merge method from Lodash library. can check here : <https://www.npmjs.com/package/lodash>
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
**I have exactly what you want**. This function will traverse through each nested object and combine it with the other. I've only tested it with 5 nested levels down the tree but, theoretically, it should work for any number of nested objects as it is a recursive function. ``` //this function is similar to object.ass...
you can use Object.assign and and assign object properties to empty object. ``` var a = {books: 2}; var b = {notebooks: 1}; var c = Object.assign( {}, a, b ); console.log(c); ``` or You could use merge method from Lodash library. can check here : <https://www.npmjs.com/package/lodash>
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
Since you mentioned you can use **lodash** you can use [`merge`](https://lodash.com/docs/4.17.11#merge) like so: `_.merge(obj1, obj2)` to get your desired result. See working example below: ```js const a = { 1: { foo: 1 }, 2: { bar: 2, fooBar: 3 }, 3: { fooBar: 3 }, }, b = { 1: { foo: 1, bar: 2 }, ...
This can be easily accomplished with a combination of the neat javascript spread syntax, Array and Object prototype functions, and destructuring patterns. ``` [obj1,obj2].flatMap(Object.entries).reduce((o,[k,v])=>({...o,[k]:{...o[k],...v}}),{}) ``` **As simple as this!** --- For a very detailed explanation of how ...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
**I have exactly what you want**. This function will traverse through each nested object and combine it with the other. I've only tested it with 5 nested levels down the tree but, theoretically, it should work for any number of nested objects as it is a recursive function. ``` //this function is similar to object.ass...
Are you looking like this? we can use this way to merge two objects. ``` const person = { name: 'David Walsh', gender: 'Male' }; const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' }; const summary = {...person, ...attributes}; ``` /\* ``` Object { "eyes": "Blue", "gender": "Male", "hai...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
You can use spread operator. Update : > > if obj2 has some properties that obj1 does not have? > > > Initially i wrote this answer assuming the keys are indexed like `0,1 and so on` but as you mentioned in comment this is not the case than you can build a array of keys and than iterate over it as as very conc...
you can use Object.assign and and assign object properties to empty object. ``` var a = {books: 2}; var b = {notebooks: 1}; var c = Object.assign( {}, a, b ); console.log(c); ``` or You could use merge method from Lodash library. can check here : <https://www.npmjs.com/package/lodash>
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
You can use spread operator. Update : > > if obj2 has some properties that obj1 does not have? > > > Initially i wrote this answer assuming the keys are indexed like `0,1 and so on` but as you mentioned in comment this is not the case than you can build a array of keys and than iterate over it as as very conc...
**I have exactly what you want**. This function will traverse through each nested object and combine it with the other. I've only tested it with 5 nested levels down the tree but, theoretically, it should work for any number of nested objects as it is a recursive function. ``` //this function is similar to object.ass...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
**I have exactly what you want**. This function will traverse through each nested object and combine it with the other. I've only tested it with 5 nested levels down the tree but, theoretically, it should work for any number of nested objects as it is a recursive function. ``` //this function is similar to object.ass...
This can be easily accomplished with a combination of the neat javascript spread syntax, Array and Object prototype functions, and destructuring patterns. ``` [obj1,obj2].flatMap(Object.entries).reduce((o,[k,v])=>({...o,[k]:{...o[k],...v}}),{}) ``` **As simple as this!** --- For a very detailed explanation of how ...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
Since you mentioned you can use **lodash** you can use [`merge`](https://lodash.com/docs/4.17.11#merge) like so: `_.merge(obj1, obj2)` to get your desired result. See working example below: ```js const a = { 1: { foo: 1 }, 2: { bar: 2, fooBar: 3 }, 3: { fooBar: 3 }, }, b = { 1: { foo: 1, bar: 2 }, ...
Are you looking like this? we can use this way to merge two objects. ``` const person = { name: 'David Walsh', gender: 'Male' }; const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' }; const summary = {...person, ...attributes}; ``` /\* ``` Object { "eyes": "Blue", "gender": "Male", "hai...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
You can use spread operator. Update : > > if obj2 has some properties that obj1 does not have? > > > Initially i wrote this answer assuming the keys are indexed like `0,1 and so on` but as you mentioned in comment this is not the case than you can build a array of keys and than iterate over it as as very conc...
This can be easily accomplished with a combination of the neat javascript spread syntax, Array and Object prototype functions, and destructuring patterns. ``` [obj1,obj2].flatMap(Object.entries).reduce((o,[k,v])=>({...o,[k]:{...o[k],...v}}),{}) ``` **As simple as this!** --- For a very detailed explanation of how ...
54,376,661
**To who voted to close because of unclear what I'm asking, here are the questions in my post:** 1. Can anyone tell me what's the result of `y`? 2. Is there anything called sum product in Mathematics? 3. Is `x` subject to broadcasting? 4. Why is `y` a column/row vector? 5. What if `x=np.array([[7],[2],[3]])`? ``` w=n...
2019/01/26
[ "https://Stackoverflow.com/questions/54376661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/746461/" ]
You can use spread operator. Update : > > if obj2 has some properties that obj1 does not have? > > > Initially i wrote this answer assuming the keys are indexed like `0,1 and so on` but as you mentioned in comment this is not the case than you can build a array of keys and than iterate over it as as very conc...
Since you mentioned you can use **lodash** you can use [`merge`](https://lodash.com/docs/4.17.11#merge) like so: `_.merge(obj1, obj2)` to get your desired result. See working example below: ```js const a = { 1: { foo: 1 }, 2: { bar: 2, fooBar: 3 }, 3: { fooBar: 3 }, }, b = { 1: { foo: 1, bar: 2 }, ...
37,297,472
I use Linux Mint 17 'Quiana' and I want to install Watchman to use later Ember.js. Here were my steps: ``` $ git clone https://github.com/facebook/watchman.git ``` then ``` $ cd watchman $ ./autogen.sh $ ./configure.sh ``` and, when I ran `make` to compile files, it returned the following error: ``` pywatchman/b...
2016/05/18
[ "https://Stackoverflow.com/questions/37297472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5846366/" ]
Usually its the `python-dev` libs missing. Are you sure the configure uses the python 3 instead of python 2? Because if thats the case you should install `python-dev` instead of `python3-dev`.
Same problem if you build watchman under rasbian/raspberry. Install "python-dev". -- ``` git clone https://github.com/facebook/watchman.git cd watchman ./autogen.sh ./configure make sudo make install ```
37,297,472
I use Linux Mint 17 'Quiana' and I want to install Watchman to use later Ember.js. Here were my steps: ``` $ git clone https://github.com/facebook/watchman.git ``` then ``` $ cd watchman $ ./autogen.sh $ ./configure.sh ``` and, when I ran `make` to compile files, it returned the following error: ``` pywatchman/b...
2016/05/18
[ "https://Stackoverflow.com/questions/37297472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5846366/" ]
Usually its the `python-dev` libs missing. Are you sure the configure uses the python 3 instead of python 2? Because if thats the case you should install `python-dev` instead of `python3-dev`.
i also did ``` sudo apt-get install python3-dev ``` it was still giving me the error then i ran this command ``` sudo apt-get install python-dev ``` after that. ``` make sudo make install ```
37,297,472
I use Linux Mint 17 'Quiana' and I want to install Watchman to use later Ember.js. Here were my steps: ``` $ git clone https://github.com/facebook/watchman.git ``` then ``` $ cd watchman $ ./autogen.sh $ ./configure.sh ``` and, when I ran `make` to compile files, it returned the following error: ``` pywatchman/b...
2016/05/18
[ "https://Stackoverflow.com/questions/37297472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5846366/" ]
Usually its the `python-dev` libs missing. Are you sure the configure uses the python 3 instead of python 2? Because if thats the case you should install `python-dev` instead of `python3-dev`.
on Fedora 32 run: `sudo dnf install python-devel`
37,297,472
I use Linux Mint 17 'Quiana' and I want to install Watchman to use later Ember.js. Here were my steps: ``` $ git clone https://github.com/facebook/watchman.git ``` then ``` $ cd watchman $ ./autogen.sh $ ./configure.sh ``` and, when I ran `make` to compile files, it returned the following error: ``` pywatchman/b...
2016/05/18
[ "https://Stackoverflow.com/questions/37297472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5846366/" ]
Same problem if you build watchman under rasbian/raspberry. Install "python-dev". -- ``` git clone https://github.com/facebook/watchman.git cd watchman ./autogen.sh ./configure make sudo make install ```
on Fedora 32 run: `sudo dnf install python-devel`
37,297,472
I use Linux Mint 17 'Quiana' and I want to install Watchman to use later Ember.js. Here were my steps: ``` $ git clone https://github.com/facebook/watchman.git ``` then ``` $ cd watchman $ ./autogen.sh $ ./configure.sh ``` and, when I ran `make` to compile files, it returned the following error: ``` pywatchman/b...
2016/05/18
[ "https://Stackoverflow.com/questions/37297472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5846366/" ]
i also did ``` sudo apt-get install python3-dev ``` it was still giving me the error then i ran this command ``` sudo apt-get install python-dev ``` after that. ``` make sudo make install ```
on Fedora 32 run: `sudo dnf install python-devel`
51,811,662
in a python program I have a list that I would like to modify: ``` a = [1,2,3,4,5,1,2,3,1,4,5] ``` Say every time I see 1 in the list, I would like to replace it with 10, 9, 8. My goal is to get: ``` a = [10,9,8,2,3,4,5,10,9,8,2,3,10,9,8,4,5] ``` What's a good way to program this? Currently I have to do a 'replac...
2018/08/12
[ "https://Stackoverflow.com/questions/51811662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2759486/" ]
You **cannot** modify your state object or any of the objects it contains directly; you must instead use `setState`. And when you're setting state based on existing state, you must use the callback version of it; [details](https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous). So in your...
In React, you must never assign to `this.state` directly. Use `this.setState()` instead. The reason is that otherwise React would not know you had changed the state. The only exception to this rule where you assign directly to `this.state` is in your component's constructor.
19,882,594
I am trying to pull company information from the following website: <http://www.theglobeandmail.com/globe-investor/markets/stocks/summary/?q=T-T> I see from there page source that there are nested span statements like: ``` <li class="clearfix"> <span class="label">Low</span> <span class="giw-a-t-sc-data">36.39</span...
2013/11/09
[ "https://Stackoverflow.com/questions/19882594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2974790/" ]
I have faced this problem. The solution is very simple (after a lot of testing and error) You must add id attribute to your tag, for instance: ``` <p:calendar id="date_selector" value="#{dpnl.fechaHasta}" pattern="dd/MM/yyyy" /> ```
At the facet named output use the tag h:outputText instead of p:inputText
19,882,594
I am trying to pull company information from the following website: <http://www.theglobeandmail.com/globe-investor/markets/stocks/summary/?q=T-T> I see from there page source that there are nested span statements like: ``` <li class="clearfix"> <span class="label">Low</span> <span class="giw-a-t-sc-data">36.39</span...
2013/11/09
[ "https://Stackoverflow.com/questions/19882594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2974790/" ]
I have faced this problem. The solution is very simple (after a lot of testing and error) You must add id attribute to your tag, for instance: ``` <p:calendar id="date_selector" value="#{dpnl.fechaHasta}" pattern="dd/MM/yyyy" /> ```
make sure you use java.util.date for your date fields(i.e fechaDesde etc) in your bean.
53,474,065
I am trying to `upgrade` `matplotlib`. I'm doing this via `!pip` and it seems to work. When I check the list in the `IPython console`: ``` !pip list ``` It returns the latest version of `matplotlib` ``` matplotlib 3.0.2 ``` But when I check the version in the editor it returns ``` 2.2.2 ``` The very first lin...
2018/11/26
[ "https://Stackoverflow.com/questions/53474065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Using `str.len` ``` df[df.iloc[:,0].astype(str).str.len()!=7] A 1 1.222222 2 1.222200 ``` dput : ``` df=pd.DataFrame({'A':[1.22222,1.222222,1.2222]}) ```
See if this works `df1 = df['ZipCode'].astype(str).map(len)==5`
53,474,065
I am trying to `upgrade` `matplotlib`. I'm doing this via `!pip` and it seems to work. When I check the list in the `IPython console`: ``` !pip list ``` It returns the latest version of `matplotlib` ``` matplotlib 3.0.2 ``` But when I check the version in the editor it returns ``` 2.2.2 ``` The very first lin...
2018/11/26
[ "https://Stackoverflow.com/questions/53474065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can write this more concisely using Pandas filtering rather than loops and ifs. Here is an example: ``` valid_zips = mydata[mydata.astype(str).str.len() == 7] ``` or ``` zip_code_upper_bound = 100000 valid_zips = mydata[mydata < zip_code_upper_bound] ``` assuming fractional numbers are not included in your s...
See if this works `df1 = df['ZipCode'].astype(str).map(len)==5`
53,474,065
I am trying to `upgrade` `matplotlib`. I'm doing this via `!pip` and it seems to work. When I check the list in the `IPython console`: ``` !pip list ``` It returns the latest version of `matplotlib` ``` matplotlib 3.0.2 ``` But when I check the version in the editor it returns ``` 2.2.2 ``` The very first lin...
2018/11/26
[ "https://Stackoverflow.com/questions/53474065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can write this more concisely using Pandas filtering rather than loops and ifs. Here is an example: ``` valid_zips = mydata[mydata.astype(str).str.len() == 7] ``` or ``` zip_code_upper_bound = 100000 valid_zips = mydata[mydata < zip_code_upper_bound] ``` assuming fractional numbers are not included in your s...
Using `str.len` ``` df[df.iloc[:,0].astype(str).str.len()!=7] A 1 1.222222 2 1.222200 ``` dput : ``` df=pd.DataFrame({'A':[1.22222,1.222222,1.2222]}) ```
62,823,948
I have a dataframe with two levels of columns index. Reproducible Dataset. --------------------- ``` df = pd.DataFrame( [ ['Gaz','Gaz','Gaz','Gaz'], ['X','X','X','X'], ['Y','Y','Y','Y'], ['Z','Z','Z','Z']], columns=pd.MultiIndex.from_arrays([['A','A','C','D'], ['Name','Name','...
2020/07/09
[ "https://Stackoverflow.com/questions/62823948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13875213/" ]
If I understand well you look for a mechanism, that allows you to display a terminal on a web server. Then you want to run an interactive python script on that terminal, right. So in the end the solution to share a terminal does not necessarily have to be written in python, right? (Though I must admit that I prefer p...
*>> Insert security disclaimer here <<* Easiest most hacktastic way to do it is to create a `div` element where you'll store your output and an `input` element to enter commands. Then you can ajax `POST` the command to a back-end controller. The controller would take the command and run it while capturing the output ...
64,267,498
I try to upload a big file (4GB) with a PUT on a DRF viewset. During the upload my memory is stable. At 100%, the python runserver process takes more and more RAM and is killed by the kernel. I have a logging line in the `put` method of this `APIView` but the process is killed before this method call. I use this sett...
2020/10/08
[ "https://Stackoverflow.com/questions/64267498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5877122/" ]
TL;DR: ------ Neither a DRF nor a Django issue, it's a [2.5 years known Daphne issue](https://github.com/django/daphne/issues/126). The solution is to use uvicorn, hypercorn, or something else for the time being. Explanations ------------ What you're seeing here is not coming from Django Rest Framework as: * The Fi...
I don't know if it works with django rest, but you can try to chunk de file. ``` [...] anexo_files = request.FILES.getlist('anexo_file_'+str(k)) index = 0 for file in anexo_files: index = index + 1 extension = os.path.splitext(str(file))[1] nome_arqui...
57,420,008
Recently I came across logging in python. I have the following code in test.py file ``` import logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) logger.debug("test Message") ``` Now, is there any way I can print the resulting `Logrecord` object g...
2019/08/08
[ "https://Stackoverflow.com/questions/57420008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2897115/" ]
There is no return in `debug()` ``` # Here is the snippet for the source code def debug(self, msg, *args, **kwargs): if self.isEnabledFor(DEBUG): self._log(DEBUG, msg, args, **kwargs) ``` If you wanna get LogRecord return, you need to redefine a `debug()`, you can overwrite like this: ``` im...
You can create a handler that instead of formatting the LogRecord instance to a string, just save it in a list to be viewed and inspected later: ``` import logging import sys # A new handler to store "raw" LogRecords instances class RecordsListHandler(logging.Handler): """ A handler class which stores LogReco...
69,497,348
I'm new to python I got a question that might be easy but i can't get it. i wanted to make aprogram that user gives email as username and password as password ,the program should check if email is in corect format and if its not it **should print something and get email again** so i used regex (Im giving this inputs to...
2021/10/08
[ "https://Stackoverflow.com/questions/69497348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16260312/" ]
here is a working code for you: ```py import re regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' def check(email): if (re.fullmatch(regex, email)): return True else: print("invalid input! correct format is like [email protected]") return False while __name__ == '__main_...
You could change your function `check` to return a boolean output that tells you whether the check was successful, as in ``` def check(email): if (re.fullmatch(regex, email)): return True else: print("corect format is like [email protected]") return False ``` And then add a loop to ...
58,752,089
I was writing on VisualCode studio, but I keep getting the same error message. > > selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. > > > Is it simply because you just can't run webdriver on vscode studio? I've already tried ``` from selenium import web...
2019/11/07
[ "https://Stackoverflow.com/questions/58752089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8836876/" ]
I had te same problem and there is two ways to solve this issue. The main reason of this "*unreachable*" path is that visual studio code desn't have permissions to run from the path environment unlike any other system installed programs. So by installing VS Code but the **System Installer** version would be enough. An...
If you're on Windows, go into CMD (Command Prompt) and type in "chromedriver.exe." If chromedriver is executable in PATH, the system will print out "Starting Chromedriver [version]..." Else, you need to chromedriver to path. Then again, it could just be a fault of the IDE, try using Python's built-in IDLE...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
These two websites really boosted my Vim productivity with all languages: <http://nvie.com/posts/how-i-boosted-my-vim/> <http://stevelosh.com/blog/2010/09/coming-home-to-vim/>
Whether or not wavy red lines are displayed is related to the theme you're using, not the syntax checker or language. So long as your syntax file (try <http://www.vim.org/scripts/script.php?script_id=790> ) checks for errors, you can show the errors with something like: ``` :hi Error guifg=#ff0000 gui=underc...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I use the [`PyFlakes` vim script](http://github.com/kevinw/pyflakes-vim), and I'm pretty satisfied with it. Also, if you'd like PEP8 checking, try [this script](http://www.vim.org/scripts/script.php?script_id=2914).
Whether or not wavy red lines are displayed is related to the theme you're using, not the syntax checker or language. So long as your syntax file (try <http://www.vim.org/scripts/script.php?script_id=790> ) checks for errors, you can show the errors with something like: ``` :hi Error guifg=#ff0000 gui=underc...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I'm using [Syntastic](http://www.vim.org/scripts/script.php?script_id=2736) plugin. It's working great so far. I use it instead of just pyflakes (Syntastic uses Pyflakes) because when doing Python development, I develop for web, so I need to edit Javascript and well and having a validation on the fly for various langua...
Whether or not wavy red lines are displayed is related to the theme you're using, not the syntax checker or language. So long as your syntax file (try <http://www.vim.org/scripts/script.php?script_id=790> ) checks for errors, you can show the errors with something like: ``` :hi Error guifg=#ff0000 gui=underc...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
This question was asked in 2010, but as of now, you have a simple solution. After the release of Vim 8 in September 2016, which supports asynchronous I/O support, you can use [Asynchronous Lint Engine](https://github.com/w0rp/ale). It supports most major languages, and of course you have to install the linter you...
Whether or not wavy red lines are displayed is related to the theme you're using, not the syntax checker or language. So long as your syntax file (try <http://www.vim.org/scripts/script.php?script_id=790> ) checks for errors, you can show the errors with something like: ``` :hi Error guifg=#ff0000 gui=underc...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I use the [`PyFlakes` vim script](http://github.com/kevinw/pyflakes-vim), and I'm pretty satisfied with it. Also, if you'd like PEP8 checking, try [this script](http://www.vim.org/scripts/script.php?script_id=2914).
These two websites really boosted my Vim productivity with all languages: <http://nvie.com/posts/how-i-boosted-my-vim/> <http://stevelosh.com/blog/2010/09/coming-home-to-vim/>
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
These two websites really boosted my Vim productivity with all languages: <http://nvie.com/posts/how-i-boosted-my-vim/> <http://stevelosh.com/blog/2010/09/coming-home-to-vim/>
This question was asked in 2010, but as of now, you have a simple solution. After the release of Vim 8 in September 2016, which supports asynchronous I/O support, you can use [Asynchronous Lint Engine](https://github.com/w0rp/ale). It supports most major languages, and of course you have to install the linter you...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I use the [`PyFlakes` vim script](http://github.com/kevinw/pyflakes-vim), and I'm pretty satisfied with it. Also, if you'd like PEP8 checking, try [this script](http://www.vim.org/scripts/script.php?script_id=2914).
I'm using [Syntastic](http://www.vim.org/scripts/script.php?script_id=2736) plugin. It's working great so far. I use it instead of just pyflakes (Syntastic uses Pyflakes) because when doing Python development, I develop for web, so I need to edit Javascript and well and having a validation on the fly for various langua...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I use the [`PyFlakes` vim script](http://github.com/kevinw/pyflakes-vim), and I'm pretty satisfied with it. Also, if you'd like PEP8 checking, try [this script](http://www.vim.org/scripts/script.php?script_id=2914).
This question was asked in 2010, but as of now, you have a simple solution. After the release of Vim 8 in September 2016, which supports asynchronous I/O support, you can use [Asynchronous Lint Engine](https://github.com/w0rp/ale). It supports most major languages, and of course you have to install the linter you...
3,778,486
I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular...
2010/09/23
[ "https://Stackoverflow.com/questions/3778486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453642/" ]
I'm using [Syntastic](http://www.vim.org/scripts/script.php?script_id=2736) plugin. It's working great so far. I use it instead of just pyflakes (Syntastic uses Pyflakes) because when doing Python development, I develop for web, so I need to edit Javascript and well and having a validation on the fly for various langua...
This question was asked in 2010, but as of now, you have a simple solution. After the release of Vim 8 in September 2016, which supports asynchronous I/O support, you can use [Asynchronous Lint Engine](https://github.com/w0rp/ale). It supports most major languages, and of course you have to install the linter you...
35,224,675
I'm preparing a toy `spark.ml` example. `Spark version 1.6.0`, running on top of `Oracle JDK version 1.8.0_65`, pyspark, ipython notebook. First, it hardly has anything to do with [Spark, ML, StringIndexer: handling unseen labels](https://stackoverflow.com/questions/34681534/spark-ml-stringindexer-handling-unseen-labe...
2016/02/05
[ "https://Stackoverflow.com/questions/35224675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3868574/" ]
Okay I think I got this. At least I got this working. Caching the dataframe(including train/test partes) solves the problem. That's what I found in this JIRA issue: <https://issues.apache.org/jira/browse/SPARK-12590>. So it's not a bug, just the fact that `randomSample` might yield a different result on the same, bu...
`Unseen label` [is a generic message which doesn't correspond to a specific column](https://github.com/apache/spark/blob/branch-1.6/mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala#L157). Most likely problem is with a following stage: ``` StringIndexer(inputCol='lang', outputCol='lang_idx') ``` w...
38,385,983
As a beginner creating a simple python text editor I have encountered a confusing bug in which I am able to print out the text file with the read\_file() function when I first open it, but after I amend the text file using write\_file(), reading the file again simple returns whitespace. Additionally, any critique of ...
2016/07/15
[ "https://Stackoverflow.com/questions/38385983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6335429/" ]
First, **file** is a predefined package; please don't use it for a variable name, or you may have trouble getting to some of the facilities. Try **my\_file** or just the C-language **fp** (for "file pointer"). After you write new information to the file, your position pointer (bookmark) is likely at the end of the fil...
When it comes to reading and writing files in python, if you do not call the method `(filename).close()` after making a change to a file, it will not save anything to it because it thinks you're still a) writing to it or b) still reading it! Hope this helps!
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
I think, if i understand you correctly, you can see [here, "Templating in Python"](http://wiki.python.org/moin/Templating).
Use a templating engine such as [Genshi](http://genshi.edgewall.org/) or [Jinja2](https://jinja.palletsprojects.com/en/2.11.x/).
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
Use a templating engine such as [Genshi](http://genshi.edgewall.org/) or [Jinja2](https://jinja.palletsprojects.com/en/2.11.x/).
Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called [yaptu](http://code.activestate.com/recipes/52305/), but modern mature ones as suggested in other answers will probably make you happier;-). However, though it's been a long time since I last used ...
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
[Dominate](https://github.com/Knio/dominate) is a Python library for creating HTML documents and fragments directly in code without using templating. You could create a simple image gallery with something like this: ```py import glob from dominate import document from dominate.tags import * photos = glob.glob('photos...
Use a templating engine such as [Genshi](http://genshi.edgewall.org/) or [Jinja2](https://jinja.palletsprojects.com/en/2.11.x/).
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
I think, if i understand you correctly, you can see [here, "Templating in Python"](http://wiki.python.org/moin/Templating).
Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called [yaptu](http://code.activestate.com/recipes/52305/), but modern mature ones as suggested in other answers will probably make you happier;-). However, though it's been a long time since I last used ...
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
[Dominate](https://github.com/Knio/dominate) is a Python library for creating HTML documents and fragments directly in code without using templating. You could create a simple image gallery with something like this: ```py import glob from dominate import document from dominate.tags import * photos = glob.glob('photos...
I think, if i understand you correctly, you can see [here, "Templating in Python"](http://wiki.python.org/moin/Templating).
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
I think, if i understand you correctly, you can see [here, "Templating in Python"](http://wiki.python.org/moin/Templating).
Python is a batteries included language. So why not use `xml.dom.minidom`? ```py from typing import List from xml.dom.minidom import getDOMImplementation, Document def getDOM() -> Document: impl = getDOMImplementation() dt = impl.createDocumentType( "html", "-//W3C//DTD XHTML 1.0 Strict//EN", ...
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
[Dominate](https://github.com/Knio/dominate) is a Python library for creating HTML documents and fragments directly in code without using templating. You could create a simple image gallery with something like this: ```py import glob from dominate import document from dominate.tags import * photos = glob.glob('photos...
Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called [yaptu](http://code.activestate.com/recipes/52305/), but modern mature ones as suggested in other answers will probably make you happier;-). However, though it's been a long time since I last used ...
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
Python is a batteries included language. So why not use `xml.dom.minidom`? ```py from typing import List from xml.dom.minidom import getDOMImplementation, Document def getDOM() -> Document: impl = getDOMImplementation() dt = impl.createDocumentType( "html", "-//W3C//DTD XHTML 1.0 Strict//EN", ...
Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called [yaptu](http://code.activestate.com/recipes/52305/), but modern mature ones as suggested in other answers will probably make you happier;-). However, though it's been a long time since I last used ...
2,301,163
I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. I really don't think...
2010/02/20
[ "https://Stackoverflow.com/questions/2301163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106534/" ]
[Dominate](https://github.com/Knio/dominate) is a Python library for creating HTML documents and fragments directly in code without using templating. You could create a simple image gallery with something like this: ```py import glob from dominate import document from dominate.tags import * photos = glob.glob('photos...
Python is a batteries included language. So why not use `xml.dom.minidom`? ```py from typing import List from xml.dom.minidom import getDOMImplementation, Document def getDOM() -> Document: impl = getDOMImplementation() dt = impl.createDocumentType( "html", "-//W3C//DTD XHTML 1.0 Strict//EN", ...
37,536,868
Not a maths major or a cs major, I just fool around with python (usually making scripts for simulations/theorycrafting on video games) and I discovered just how bad random.randint is performance wise. It's got me wondering why random.randint or random.randrange are used/made the way they are. I made a function that pro...
2016/05/31
[ "https://Stackoverflow.com/questions/37536868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5511209/" ]
`random.randint()` and others are calling into `random.getrandbits()` which may be less efficient that direct calls to `random()`, but for good reason. It is actually more correct to use a `randint` that calls into `random.getrandbits()`, as it can be done in an unbiased manner. You can see that using random.random ...
This is probably rarely a problem but `randint(0,10**1000)` works while `fastrandint(0,10**1000)` crashes. The slower time is probably the price you need to pay to have a function that works for all possible cases...
37,536,868
Not a maths major or a cs major, I just fool around with python (usually making scripts for simulations/theorycrafting on video games) and I discovered just how bad random.randint is performance wise. It's got me wondering why random.randint or random.randrange are used/made the way they are. I made a function that pro...
2016/05/31
[ "https://Stackoverflow.com/questions/37536868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5511209/" ]
[`randint`](https://hg.python.org/cpython/file/3.5/Lib/random.py#l214) calls [`randrange`](https://hg.python.org/cpython/file/3.5/Lib/random.py#l170) which does a bunch of range/type checks and conversions and then uses [`_randbelow`](https://hg.python.org/cpython/file/3.5/Lib/random.py#l220) to generate a random int. ...
This is probably rarely a problem but `randint(0,10**1000)` works while `fastrandint(0,10**1000)` crashes. The slower time is probably the price you need to pay to have a function that works for all possible cases...
38,101,112
I'm trying to create an iOS Titanium Module using a pre-compiled CommonJS module. As the README file says: > > All JavaScript files in the assets directory are IGNORED except if you create a > file named "com.moduletest.js" in this directory in which case it will be > wrapped by native code, compiled, and used as y...
2016/06/29
[ "https://Stackoverflow.com/questions/38101112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1272263/" ]
There are 2 solutions. 1) Don't put it in assets, but in the `/app/lib` folder as others have mentioned. 2) wrap it as an actual commonjs module, like the [module I wrote](http://github.com/Topener/To.ImageCache) In both cases, you can just use `require('modulename')`. In case 2 you will need to add it to the `tiapp...
I use a slightly different pattern that works excellent: First a small snippet from my "module": ``` Stopwatch = function(listener) { this.totalElapsed = 0; // * elapsed number of ms in total this.listener = (listener != undefined ? listener : null); // * function to receive onTick events }; Stopwatch.protot...
71,821,635
I have installed two frameworks of Python 3.10. There is `wxPython310` for 64-bit Python. But there aren't any `wxPython` for 32-bit Python. I tried to install `wxPython` with `https://wxpython.org/Phoenix/snapshot-builds/wxPython-4.1.2a1.dev5259+d3bdb143.tar.gz`, but it shows me the error code like this. ``` Runni...
2022/04/11
[ "https://Stackoverflow.com/questions/71821635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15512931/" ]
There are some issues with Python 3.10. The easiest way to deal with this situation is to downgrade your python version to 3.9.13. The last wxPython came before Python 3.10 if I am not mistaken. I was going through the same situation and tried a couple of solutions because I did not want to downgrade my python versio...
Common problem with installing various versions is python interpreters that used for the installation Make sure you use compatible version of python to install wxPython310 What IDE you use ? for all case scenarios I would recommend to make sure that the installation done with the right Python version , if you don't k...
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
I like the [answer to this question](http://docs.python.org/2/faq/programming.html#how-can-my-code-discover-the-name-of-an-object) that's found in the Python programming FAQ, quoting Fredrik Lundh: > > The same way as you get the name of that cat you found on your porch: > the cat (object) itself cannot tell you it...
Here's an answer that only became possible as of Python 3.6 with f-strings: ``` x = 10 print(f'{x=}') # Outputs x=10 ```
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
I like the [answer to this question](http://docs.python.org/2/faq/programming.html#how-can-my-code-discover-the-name-of-an-object) that's found in the Python programming FAQ, quoting Fredrik Lundh: > > The same way as you get the name of that cat you found on your porch: > the cat (object) itself cannot tell you it...
**New Solution Using `readline`** If you're in an interactive session, here's an extremely naive solution that will usually work: ``` def show(x): from readline import get_current_history_length, get_history_item print(get_history_item(get_current_history_length()).strip()[5:-1] + ' = ' + str(x)) ``` All it...
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
I forebode that the following solution will gain several criticisms ``` def show(*x): for el in x: fl = None for gname,gobj in globals().iteritems(): if el==gobj: print '%s == %r' % (gname,el) fl = True if not fl: print 'There is no id...
**New Solution Using `readline`** If you're in an interactive session, here's an extremely naive solution that will usually work: ``` def show(x): from readline import get_current_history_length, get_history_item print(get_history_item(get_current_history_length()).strip()[5:-1] + ' = ' + str(x)) ``` All it...
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
No, you cannot know what the name was of the local variable used to pass a value to your function. This is an impossible task in any case. What would be the variable name in the following example? ``` arguments = ('a', 1, 10) somefunction(*(arguments[:2] + [10])) ``` Here we pass in 3 arguments, two taken from a tu...
Here's an answer that only became possible as of Python 3.6 with f-strings: ``` x = 10 print(f'{x=}') # Outputs x=10 ```
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
Not exactly like this. However, you can achieve something similar: ``` def show(**kwargs): print(', '.join('%s=%s' % kv for kv in kwargs.items())) show(a=20) ```
It seems that it's impossible in Python but it's actually possible in C++. ``` #define show(x) std::cout << #x << " = " << x << std::endl ```
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
It seems that it's impossible in Python but it's actually possible in C++. ``` #define show(x) std::cout << #x << " = " << x << std::endl ```
Here's an answer that only became possible as of Python 3.6 with f-strings: ``` x = 10 print(f'{x=}') # Outputs x=10 ```
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
No, you cannot know what the name was of the local variable used to pass a value to your function. This is an impossible task in any case. What would be the variable name in the following example? ``` arguments = ('a', 1, 10) somefunction(*(arguments[:2] + [10])) ``` Here we pass in 3 arguments, two taken from a tu...
**New Solution Using `readline`** If you're in an interactive session, here's an extremely naive solution that will usually work: ``` def show(x): from readline import get_current_history_length, get_history_item print(get_history_item(get_current_history_length()).strip()[5:-1] + ' = ' + str(x)) ``` All it...
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
I forebode that the following solution will gain several criticisms ``` def show(*x): for el in x: fl = None for gname,gobj in globals().iteritems(): if el==gobj: print '%s == %r' % (gname,el) fl = True if not fl: print 'There is no id...
Here's an answer that only became possible as of Python 3.6 with f-strings: ``` x = 10 print(f'{x=}') # Outputs x=10 ```
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
No, you cannot know what the name was of the local variable used to pass a value to your function. This is an impossible task in any case. What would be the variable name in the following example? ``` arguments = ('a', 1, 10) somefunction(*(arguments[:2] + [10])) ``` Here we pass in 3 arguments, two taken from a tu...
I like the [answer to this question](http://docs.python.org/2/faq/programming.html#how-can-my-code-discover-the-name-of-an-object) that's found in the Python programming FAQ, quoting Fredrik Lundh: > > The same way as you get the name of that cat you found on your porch: > the cat (object) itself cannot tell you it...
13,827,543
I like to know what was the local variable names when they are passed to a function. I'm not sure whether this is possible at all. Let's consider this example: function definition: ``` def show(x): print(x) ``` usage: ``` a = 10 show(a) ``` this prints 10. But I like to print "a = 10". Is this possible in pyth...
2012/12/11
[ "https://Stackoverflow.com/questions/13827543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/624074/" ]
No, you cannot know what the name was of the local variable used to pass a value to your function. This is an impossible task in any case. What would be the variable name in the following example? ``` arguments = ('a', 1, 10) somefunction(*(arguments[:2] + [10])) ``` Here we pass in 3 arguments, two taken from a tu...
Not exactly like this. However, you can achieve something similar: ``` def show(**kwargs): print(', '.join('%s=%s' % kv for kv in kwargs.items())) show(a=20) ```
60,877,741
I'm trying to write a script with python/numpy/scipy for data manipulation, fitting and plotting of angle dependent magnetoresistance measurements. I'm new to Python, got the frame code from my PhD advisor, and managed to add few hundred lines of code to the frame. After a while I noticed that some measurements had mul...
2020/03/26
[ "https://Stackoverflow.com/questions/60877741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13131921/" ]
If you only want to consider the valid entries, you can use the inverse of the mask as an index: ``` x = ma.masked_array([1,2,3,4,5,6,7,8,9,10], mask=[0,0,0,0,0,1,1,1,1,1]) # changed mask y = ma.masked_array([1,2,3,4,5,30,35,40,45,50], mask=[0,0,0,0,0,1,1,1,1,1]) fitParamsFunk, fitCovariancesFunk = curve_fit(Funk, x...
The use of mask in numerical calculus is equivalent to the use of the Heaviside step function in analytical calculus. For example this becomes very simple by application for piecewise linear regression: [![enter image description here](https://i.stack.imgur.com/Zg2Z3.gif)](https://i.stack.imgur.com/Zg2Z3.gif) They a...
60,877,741
I'm trying to write a script with python/numpy/scipy for data manipulation, fitting and plotting of angle dependent magnetoresistance measurements. I'm new to Python, got the frame code from my PhD advisor, and managed to add few hundred lines of code to the frame. After a while I noticed that some measurements had mul...
2020/03/26
[ "https://Stackoverflow.com/questions/60877741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13131921/" ]
I think that what you want to do is to define a mask that lists the indices of the "good data points" and then use that as the points to fit (and/or to plot). As a lead author of lmfit, I would recommend using that library for curve-fitting: it has many useful features over `curve_fit`. With this, your example might l...
The use of mask in numerical calculus is equivalent to the use of the Heaviside step function in analytical calculus. For example this becomes very simple by application for piecewise linear regression: [![enter image description here](https://i.stack.imgur.com/Zg2Z3.gif)](https://i.stack.imgur.com/Zg2Z3.gif) They a...
46,497,838
We have a Python client that connects to the Amazon S3 via a VPC endpoint. Our code uses boto and we are able to connect and download from S3. After migration from boto to boto3, we noticed that the VPC endpoint connection no longer works. Below is a copy snippet that can reproduce the problem. ```sh python -c "impor...
2017/09/29
[ "https://Stackoverflow.com/questions/46497838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/456481/" ]
This is most likely a configuration error in your VPC endpoint policies. If your policies are correct, then Boto3 never knows exactly how it's able to reach the S3 location, it really is up to the policies to allow/forbid this type of traffic. Here's a quick walkthrough of what you can do for troubleshooting: <https:/...
It depends on your AWS policies and roles defined. Shortest way to make your code run is to make the S3 bucket Public [ not recommended] else add your IP in the security policies and then re-run the code. Details of it can be found here. <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-ins...
50,648,152
I want to install a rpm package, (e.g. python 3), and all of its dependencies in a linux server that does not have internet connection. How can I do that?
2018/06/01
[ "https://Stackoverflow.com/questions/50648152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128078/" ]
Assuming you already downloaded the package before from another machine that has internet access and FTP the files to your server, you can use the following command to install a rpm ``` rpm -ivh package_name_x85_64.rpm ``` options: * i = This installs a new package. * v = Print verbose information * h = Print 50 ha...
There is a way, but it is quite tricky and might mess up your servers, so be **very careful**. Nomenclature: * **online** : your system that is connected to the repositories * **offline**: your system that is not connected Steps: Compress your rpm database from the **offline** system and transfer it to the **online...
50,648,152
I want to install a rpm package, (e.g. python 3), and all of its dependencies in a linux server that does not have internet connection. How can I do that?
2018/06/01
[ "https://Stackoverflow.com/questions/50648152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128078/" ]
In CentOS/RedHat you can use `yumdownloader` for specific packages, this downloads all RPMs required, then, compress the directory, upload it to the server without Internet access and install RPMs. [Here](https://adrianescutia.github.io/adrianes/snippets/kubernetes/install-kubernetes-docker-offline#download-docker-onl...
Assuming you already downloaded the package before from another machine that has internet access and FTP the files to your server, you can use the following command to install a rpm ``` rpm -ivh package_name_x85_64.rpm ``` options: * i = This installs a new package. * v = Print verbose information * h = Print 50 ha...
50,648,152
I want to install a rpm package, (e.g. python 3), and all of its dependencies in a linux server that does not have internet connection. How can I do that?
2018/06/01
[ "https://Stackoverflow.com/questions/50648152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128078/" ]
In CentOS/RedHat you can use `yumdownloader` for specific packages, this downloads all RPMs required, then, compress the directory, upload it to the server without Internet access and install RPMs. [Here](https://adrianescutia.github.io/adrianes/snippets/kubernetes/install-kubernetes-docker-offline#download-docker-onl...
There is a way, but it is quite tricky and might mess up your servers, so be **very careful**. Nomenclature: * **online** : your system that is connected to the repositories * **offline**: your system that is not connected Steps: Compress your rpm database from the **offline** system and transfer it to the **online...
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
With `bash` version >= 3.0 and a regex: ``` [[ "$string" =~ _(.+)\. ]] && echo "${BASH_REMATCH[1]}" ```
This is easy, except that it includes the initial underscore: ``` ls | grep -o "_[^.]*" ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
With `bash` version >= 3.0 and a regex: ``` [[ "$string" =~ _(.+)\. ]] && echo "${BASH_REMATCH[1]}" ```
Using `sed` ``` $ sed 's/[^_]*_//;s/\..*//' input_file AAA_123_k CCC KK_45 ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
If you need to process the file names one at a time (eg, within a `while read` loop) you can perform two parameter expansions, eg: ``` $ string='/my/directory/file1_AAA_123_k.txt.2' $ tmp="${string#*_}" $ tmp="${tmp%%.*}" $ echo "${tmp}" AAA_123_k ``` One idea to parse a list of file names at the same time: ``` $ c...
This is easy, except that it includes the initial underscore: ``` ls | grep -o "_[^.]*" ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
With your shown samples, with GNU `grep` you could try following code. ``` grep -oP '.*?_\K([^.]*)' Input_file ``` Explanation: Using GNU `grep`'s `-oP` options here to print exact match and to enable PCRE regex respectively. In main program using regex `.*?_\K([^.]*)` to get value between 1st `_` and first occurren...
If you need to process the file names one at a time (eg, within a `while read` loop) you can perform two parameter expansions, eg: ``` $ string='/my/directory/file1_AAA_123_k.txt.2' $ tmp="${string#*_}" $ tmp="${tmp%%.*}" $ echo "${tmp}" AAA_123_k ``` One idea to parse a list of file names at the same time: ``` $ c...
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
A simpler `sed` solution without any capturing group: ```sh sed -E 's/^[^_]*_|\.[^.]*$//g' file AAA_123_k CCC KK_45 ```
Using `sed` ``` $ sed 's/[^_]*_//;s/\..*//' input_file AAA_123_k CCC KK_45 ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
A simpler `sed` solution without any capturing group: ```sh sed -E 's/^[^_]*_|\.[^.]*$//g' file AAA_123_k CCC KK_45 ```
This is easy, except that it includes the initial underscore: ``` ls | grep -o "_[^.]*" ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
You can use a single `sed` command like ```sh sed -n 's~^.*/[^_/]*_\([^/]*\)\.[^./]*$~\1~p' <<< "$string" sed -nE 's~^.*/[^_/]*_([^/]*)\.[^./]*$~\1~p' <<< "$string" ``` See the [online demo](https://ideone.com/1f8XLQ). *Details*: * `^` - start of string * `.*` - any text * `/` - a `/` char * `[^_/]*` - zero or more...
Using `sed` ``` $ sed 's/[^_]*_//;s/\..*//' input_file AAA_123_k CCC KK_45 ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
With `bash` version >= 3.0 and a regex: ``` [[ "$string" =~ _(.+)\. ]] && echo "${BASH_REMATCH[1]}" ```
If you need to process the file names one at a time (eg, within a `while read` loop) you can perform two parameter expansions, eg: ``` $ string='/my/directory/file1_AAA_123_k.txt.2' $ tmp="${string#*_}" $ tmp="${tmp%%.*}" $ echo "${tmp}" AAA_123_k ``` One idea to parse a list of file names at the same time: ``` $ c...
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
You can use a single `sed` command like ```sh sed -n 's~^.*/[^_/]*_\([^/]*\)\.[^./]*$~\1~p' <<< "$string" sed -nE 's~^.*/[^_/]*_([^/]*)\.[^./]*$~\1~p' <<< "$string" ``` See the [online demo](https://ideone.com/1f8XLQ). *Details*: * `^` - start of string * `.*` - any text * `/` - a `/` char * `[^_/]*` - zero or more...
This is easy, except that it includes the initial underscore: ``` ls | grep -o "_[^.]*" ```
71,300,876
Using python elasticsearch-dsl: ``` class Record(Document): tags = Keyword() tags_suggest = Completion(preserve_position_increments=False) def clean(self): self.tags_suggest = { "input": self.tags } class Index: name = 'my-index' settings = { "n...
2022/02/28
[ "https://Stackoverflow.com/questions/71300876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9016861/" ]
With your shown samples, with GNU `grep` you could try following code. ``` grep -oP '.*?_\K([^.]*)' Input_file ``` Explanation: Using GNU `grep`'s `-oP` options here to print exact match and to enable PCRE regex respectively. In main program using regex `.*?_\K([^.]*)` to get value between 1st `_` and first occurren...
Using `sed` ``` $ sed 's/[^_]*_//;s/\..*//' input_file AAA_123_k CCC KK_45 ```
49,889,323
I have a script named `patchWidth.py` and it parses command line arguments with `argparse`: ``` # read command line arguments -- the code is able to process multiple files parser = argparse.ArgumentParser(description='angle simulation trajectories') parser.add_argument('filenames', metavar='filename', type=str, nargs=...
2018/04/18
[ "https://Stackoverflow.com/questions/49889323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2112406/" ]
Yes, you can use the sys module: ``` import sys str(sys.argv) # arguments as string ``` Note that `argv[0]` is the script name. For more information, take a look at the [sys module documentation](https://docs.python.org/3/library/sys.html#sys.argv).
I do not know if it would be the best option, but... ``` import sys " ".join(sys.argv) ``` Will return a string like `/the/path/of/file/my_file.py arg1 arg2 arg3`
49,889,323
I have a script named `patchWidth.py` and it parses command line arguments with `argparse`: ``` # read command line arguments -- the code is able to process multiple files parser = argparse.ArgumentParser(description='angle simulation trajectories') parser.add_argument('filenames', metavar='filename', type=str, nargs=...
2018/04/18
[ "https://Stackoverflow.com/questions/49889323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2112406/" ]
Yes, you can use the sys module: ``` import sys str(sys.argv) # arguments as string ``` Note that `argv[0]` is the script name. For more information, take a look at the [sys module documentation](https://docs.python.org/3/library/sys.html#sys.argv).
This will work with commands that have space-separated strings in them. ``` import sys " ".join("\""+arg+"\"" if " " in arg else arg for arg in sys.argv) ``` Sample output: ``` $ python3 /tmp/derp.py "my arg" 1 2 3 python3 /tmp/derp.py "my arg" 1 2 3 ``` This won't work if there's a string argument with a quotati...
49,889,323
I have a script named `patchWidth.py` and it parses command line arguments with `argparse`: ``` # read command line arguments -- the code is able to process multiple files parser = argparse.ArgumentParser(description='angle simulation trajectories') parser.add_argument('filenames', metavar='filename', type=str, nargs=...
2018/04/18
[ "https://Stackoverflow.com/questions/49889323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2112406/" ]
I do not know if it would be the best option, but... ``` import sys " ".join(sys.argv) ``` Will return a string like `/the/path/of/file/my_file.py arg1 arg2 arg3`
This will work with commands that have space-separated strings in them. ``` import sys " ".join("\""+arg+"\"" if " " in arg else arg for arg in sys.argv) ``` Sample output: ``` $ python3 /tmp/derp.py "my arg" 1 2 3 python3 /tmp/derp.py "my arg" 1 2 3 ``` This won't work if there's a string argument with a quotati...
70,899,538
Right now I have an Arraylist in java. When I call ``` myarraylist.get(0) myarraylist.get(1) myarraylist.get(2) [0, 5, 10, 16] [24, 29, 30, 35, 41, 45, 50] [0, 6, 41, 45, 58] ``` are all different lists. What I need to do is get the first and second element of each of these lists, and put it in a list, like so: ``...
2022/01/28
[ "https://Stackoverflow.com/questions/70899538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17215849/" ]
`List<Integer> sublist = myarraylist.subList(0, 2);` For `List#subList(int fromIndex, int toIndex)` the `toIndex` is exclusive. Therefore, to get the first two elements (indexes 0 and 1), the `toIndex` value has to be 2.
Try reading about Java 8 Stream API, specifically: * [map method](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#map-java.util.function.Function-) * [collect method](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-) This should help you...
70,899,538
Right now I have an Arraylist in java. When I call ``` myarraylist.get(0) myarraylist.get(1) myarraylist.get(2) [0, 5, 10, 16] [24, 29, 30, 35, 41, 45, 50] [0, 6, 41, 45, 58] ``` are all different lists. What I need to do is get the first and second element of each of these lists, and put it in a list, like so: ``...
2022/01/28
[ "https://Stackoverflow.com/questions/70899538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17215849/" ]
`List<Integer> sublist = myarraylist.subList(0, 2);` For `List#subList(int fromIndex, int toIndex)` the `toIndex` is exclusive. Therefore, to get the first two elements (indexes 0 and 1), the `toIndex` value has to be 2.
1. Map through nested lists. 2. Create a sub-list of each nested list. 3. Collect the stream back into a new list. ```java import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; class Scratch { public static void main(String[] args) { List<List<Integ...
24,090,225
Best way to remove all characters of a string until new line character is met python? ``` str = 'fakeline\nfirstline\nsecondline\nthirdline' into str = 'firstline\nsecondline\nthirdline' ```
2014/06/06
[ "https://Stackoverflow.com/questions/24090225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3388884/" ]
Get the index of the newline and use it to [slice](https://stackoverflow.com/questions/509211/pythons-slice-notation) the string: ``` >>> s = 'fakeline\nfirstline\nsecondline\nthirdline' >>> s[s.index('\n')+1:] # add 1 to get the character after the newline 'firstline\nsecondline\nthirdline' ``` Also, don't name you...
str.split("\n") gives a list of all the newline delimited segments. You can simply append the ones you want with + afterwards. For your case, you can use a slice ``` newstr = "".join(str.split("\n")[1::]) ```
24,090,225
Best way to remove all characters of a string until new line character is met python? ``` str = 'fakeline\nfirstline\nsecondline\nthirdline' into str = 'firstline\nsecondline\nthirdline' ```
2014/06/06
[ "https://Stackoverflow.com/questions/24090225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3388884/" ]
Get the index of the newline and use it to [slice](https://stackoverflow.com/questions/509211/pythons-slice-notation) the string: ``` >>> s = 'fakeline\nfirstline\nsecondline\nthirdline' >>> s[s.index('\n')+1:] # add 1 to get the character after the newline 'firstline\nsecondline\nthirdline' ``` Also, don't name you...
You can use [`re.sub()`](https://docs.python.org/2/library/re.html#re.sub) ( *regular expression* replacement ) as well. ``` >>> import re >>> s = 'fakeline\nfirstline\nsecondline\nthirdline' >>> re.sub(r'^.*\n', '', s) 'firstline\nsecondline\nthirdline' ```
42,136,707
Hello I'm trying to make an live info screen to a school project, I'm reading through a file which does a lot of different thing which depending of what line it's reading. ``` dclist = [] interface = "" vrfmem = "" db = sqlite3.connect('data/main.db') cursor = db.cursor() cursor.execute('''SELECT r1 FROM routers''') ...
2017/02/09
[ "https://Stackoverflow.com/questions/42136707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4448852/" ]
You install `gulp` globally for using simple `gulp` command in your terminal and install `gulp` locally (with `package.json` dependency) in order not to lose the dependency, because you can install your project to any computer, call `npm i` and access `gulp` with `./node_modules/.bin/gulp` without any additional instal...
You don't even need to have installed `gulp` globaly. Just have it locally and put gulp commands in package.json scripts like this: ``` "scripts": { "start": "gulp", "speed-test": "gulp speed-test -v", "build-prod": "gulp build-prod", "test": "NODE_ENV=test jasmine JASMINE_CONFIG_PATH=spec/support/ja...
60,445,740
I have an excel file which generates chart based on the data available, the chart name is `thisChart`. I want to copy `thisChart` from excel file to the ppt file. Now I know the 2 ways to do that ie VBA and python(using win32com.client). The problem with VBA is that its really time consuming and it randomly crashes th...
2020/02/28
[ "https://Stackoverflow.com/questions/60445740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6372189/" ]
You can use `CASE` clause to differential which Unit need to be displayed. For example: ``` SELECT (CASE WHEN price_col >= 1000000 THEN CONCAT(price_col/100000,'B') WHEN price_col >= 100000 THEN CONCAT(price_col/100000,'M') WHEN price_col >= 1000 THEN CONCAT(price_col/1000,'K') ELSE price_col END) as new_price_col FR...
SELECT (CASE WHEN length(price)=9 THEN CONCAT(price/100000,'M') ELSE (CASE WHEN lenght(price)=10 THEN CONCAT(price/1000000,'B' END) END) AS price
49,059,461
I have the following Python dict: ``` { 'parameter_010': False, 'parameter_009': False, 'parameter_008': False, 'parameter_005': 'C<sub>MAX</sub>', 'parameter_004': 'L', 'parameter_007': False, 'parameter_006': 'R', 'parameter_001': 'Foo', 'id': 7542, 'parameter_003': 'D', 'parameter_00...
2018/03/01
[ "https://Stackoverflow.com/questions/49059461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5328289/" ]
So, assuming you know that you are working with a JSON and how to deserialize: ``` >>> import json >>> s = """{ ... "parameter_010": false, ... "parameter_009": false, ... "parameter_008": false, ... "parameter_005": "CMAX", ... "parameter_004": "L", ... "parameter_007": false, ... "parameter_006": "R", ...
Here is one solution: ``` list(zip(*sorted(i for i in d.items() if i[0].startswith('parameter') and i[1])))[1] # ('Foo', 'M', 'D', 'L', 'C<sub>MAX</sub>', 'R') ``` **Explanation** * We filter for 2 conditions: key starts with 'parameter' and value is Truthy. * `sorted` on `d.items()` returns a list of tuples sorte...
49,059,461
I have the following Python dict: ``` { 'parameter_010': False, 'parameter_009': False, 'parameter_008': False, 'parameter_005': 'C<sub>MAX</sub>', 'parameter_004': 'L', 'parameter_007': False, 'parameter_006': 'R', 'parameter_001': 'Foo', 'id': 7542, 'parameter_003': 'D', 'parameter_00...
2018/03/01
[ "https://Stackoverflow.com/questions/49059461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5328289/" ]
So, assuming you know that you are working with a JSON and how to deserialize: ``` >>> import json >>> s = """{ ... "parameter_010": false, ... "parameter_009": false, ... "parameter_008": false, ... "parameter_005": "CMAX", ... "parameter_004": "L", ... "parameter_007": false, ... "parameter_006": "R", ...
``` import collections dicty = { "parameter_010": False, "parameter_009": False, "parameter_008": False, "parameter_005": "CMAX", "parameter_004": "L", "parameter_007": False, "parameter_006": "R", "parameter_001": "Foo", "id": 7542, "parameter_003": "D", "parameter_002": "M" } result =...
13,637,150
I am trying to call an .exe file that's not in my local Python directory using `subprocess.call()`. The command (as I type it into cmd.exe) is exactly as follows: `"C:\Program Files\R\R-2.15.2\bin\Rscript.exe" --vanilla C:\python\buyback_parse_guide.r` The script runs, does what I need to do, and I have confirmed the ...
2012/11/30
[ "https://Stackoverflow.com/questions/13637150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/489426/" ]
To quote [the docs](http://docs.python.org/2/library/subprocess.html#popen-constructor): > > If shell is True, it is recommended to pass args as a string rather than as a sequence. > > > Splitting it up (either manually, or via `shlex`) just so `subprocess` can recombine them so the shell can split them again is ...
According to [the docs](http://stat.ethz.ch/R-manual/R-patched/library/utils/html/Rscript.html), Rscript: > > … is an alternative front end for use in #! scripts and other scripting applications. > > > … is convenient for writing #! scripts… (The standard Windows command line has no concept of #! scripts, but Cygwi...
63,106,413
I'm trying to find a python solution to extract the length of a specific sequence within a fasta file using the full header of the sequence as the query. The full header is stored as a variable earlier in the pipeline (i.e. "CONTIG"). I would like to save the output of this script as a variable to then use later on in ...
2020/07/26
[ "https://Stackoverflow.com/questions/63106413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7614836/" ]
You can do it this way: ``` import Bio.SeqIO as IO record_dict = IO.to_dict(IO.parse("genome.fa", "fasta")) print(len(record_dict["chr1"])) ``` or ``` import Bio.SeqIO as IO record_dict = IO.to_dict(IO.parse("genome.fa", "fasta")) seq = record_dict["chr1"] print(len(seq)) ``` EDIT: Alternative code ``` import Bi...
This works, just changed the "CONTIG" variable to a string. Thanks Lucía for all your help the last couple of days! ``` import Bio.SeqIO as IO record_dict = IO.to_dict(IO.parse(ORIGINAL_GENOME, "fasta")) #not the subsample with open(GENOME_SUBSAMPLE, 'r') as FIN: for LINE in FIN: if LINE.startswith('>'):...
35,846,943
I was creating a function to compute trimmed mean. To do this I removed highest and lowest percent of data and then the mean is computed as usual. What I have so far is : ``` def trimmed_mean(data, percent): from numpy import percentile if percent < 50: data_trimmed = [i for i in data ...
2016/03/07
[ "https://Stackoverflow.com/questions/35846943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4408820/" ]
You can take a look at this related question:[Trimmed Mean with Percentage Limit in Python?](https://stackoverflow.com/questions/19441730/trimmed-mean-with-percentage-limit-in-python) In short for scipy version > 0.14.0 the following does the job ``` from scipy import stats m = stats.trim_mean(X, percentage) ``` If...
I would suggest sorting the array first and then just take a "slice in the the middle." ``` #some "fancy" numpy sort or even just plain old sorted() #sorted_data = sorted(data) #uncomment to use plain python sorted n = len(sorted_data) outliers = n*percent/100 #may want some rounding logic if n is small trimmed_data ...
35,846,943
I was creating a function to compute trimmed mean. To do this I removed highest and lowest percent of data and then the mean is computed as usual. What I have so far is : ``` def trimmed_mean(data, percent): from numpy import percentile if percent < 50: data_trimmed = [i for i in data ...
2016/03/07
[ "https://Stackoverflow.com/questions/35846943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4408820/" ]
You can take a look at this related question:[Trimmed Mean with Percentage Limit in Python?](https://stackoverflow.com/questions/19441730/trimmed-mean-with-percentage-limit-in-python) In short for scipy version > 0.14.0 the following does the job ``` from scipy import stats m = stats.trim_mean(X, percentage) ``` If...
Here: ``` import numpy as np def trimmed_mean(data, percent): data = np.array(sorted(data)) trim = int(percent*data.size/100.0) return data[trim:-trim].mean() ```
35,846,943
I was creating a function to compute trimmed mean. To do this I removed highest and lowest percent of data and then the mean is computed as usual. What I have so far is : ``` def trimmed_mean(data, percent): from numpy import percentile if percent < 50: data_trimmed = [i for i in data ...
2016/03/07
[ "https://Stackoverflow.com/questions/35846943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4408820/" ]
You can take a look at this related question:[Trimmed Mean with Percentage Limit in Python?](https://stackoverflow.com/questions/19441730/trimmed-mean-with-percentage-limit-in-python) In short for scipy version > 0.14.0 the following does the job ``` from scipy import stats m = stats.trim_mean(X, percentage) ``` If...
Maybe this'll work: ``` data = [37, 33, 33, 32, 29, 28, 28, 23, 22, 22, 22, 21, 21, 21, 20, 20, 19, 19, 18, 18, 18, 18, 16, 15, 14, 14, 14, 12, 12, 9, 6] percent = .1 # == 10% def trimmed_mean(data, percent): # sort list data = sorted(data) # number of elements to remove from both ends of list g = int...
73,603,035
We know we can use `sep.join()` or `+=` to concatenate strings. For example, ``` a = ["123f", "asd", "y] print("".join(a)) # output: 1234asdy ``` In Java, stringbuilder would creat a new string, and put the two string on the both sides of plus together, so it will cost `O(n^2)`. But in Python, how will `join` method...
2022/09/04
[ "https://Stackoverflow.com/questions/73603035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16395591/" ]
for cpython version 3.X you can see the source code [here](https://github.com/python/cpython/blob/main/Objects/stringlib/join.h) and it does indeed calculate the total length beforehand and only does 1 allocation. On a side note, if your application is limited by the speed of joining strings such that you have to thin...
The operation is O(n). `join` takes an iterable. If its not already a sequence, `join` will create one. Then, using the size of the the separator and the size of each string in the list, a new string object is created. A series of `memcpy` then creates the object. Creating the list, getting the sizes and doing the `mem...
20,169,509
Can I import a word document into a python program so that its content can be read and questions can be answered using the data in the document. what would be procedure of using the data in the file ``` with open('animal data.txt', 'r') ``` i used this but is not working
2013/11/24
[ "https://Stackoverflow.com/questions/20169509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2994135/" ]
XE16 supports OpenGL in live cards. Use the class GlRenderer: <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/timeline/GlRenderer>
I would look at your app and determine if you want to have more user input or not and whether you want it to live in a specific part of your Timeline or just have it be launched when the user wants it. Specifically, since Live Cards live in the Timeline, they will not be able to capture the swipe backward or swipe for...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
Your distortion i believe is caused by the way you are splitting your original image into its individual bands and then resizing it again before putting it into merge; ``` ` image=Image.open("your image") print(image.size) #size is inverted i.e columns first rows second eg: 500,250 #convert to array li_r=list(image...
If using PIL Image convert it to array and then proceed with the below, else using matplotlib or cv2 perform directly. ``` image = cv2.imread('')[:,:,::-1] image_2 = image[10:150,10:100] print(image_2.shape) img_r = image_2[:,:,0] img_g = image_2[:,:,1] img_b = image_2[:,:,2] image_2 = img_r*0.2989 + 0.587*img_g + 0...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
I don't really understand your question but here is an example of something similar I've done recently that seems like it might help: ``` # r, g, and b are 512x512 float arrays with values >= 0 and < 1. from PIL import Image import numpy as np rgbArray = np.zeros((512,512,3), 'uint8') rgbArray[..., 0] = r*256 rgbArray...
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` This code doesnt create 3d array if you pass 3 channels. 2 channels remain.
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
Convert the numpy arrays to `uint8` before passing them to `Image.fromarray` Eg. if you have floats in the range [0..1]: ``` r = Image.fromarray(numpy.uint8(r_array*255.999)) ```
Your distortion i believe is caused by the way you are splitting your original image into its individual bands and then resizing it again before putting it into merge; ``` ` image=Image.open("your image") print(image.size) #size is inverted i.e columns first rows second eg: 500,250 #convert to array li_r=list(image...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` This code doesnt create 3d array if you pass 3 channels. 2 channels remain.
Your distortion i believe is caused by the way you are splitting your original image into its individual bands and then resizing it again before putting it into merge; ``` ` image=Image.open("your image") print(image.size) #size is inverted i.e columns first rows second eg: 500,250 #convert to array li_r=list(image...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
I don't really understand your question but here is an example of something similar I've done recently that seems like it might help: ``` # r, g, and b are 512x512 float arrays with values >= 0 and < 1. from PIL import Image import numpy as np rgbArray = np.zeros((512,512,3), 'uint8') rgbArray[..., 0] = r*256 rgbArray...
If using PIL Image convert it to array and then proceed with the below, else using matplotlib or cv2 perform directly. ``` image = cv2.imread('')[:,:,::-1] image_2 = image[10:150,10:100] print(image_2.shape) img_r = image_2[:,:,0] img_g = image_2[:,:,1] img_b = image_2[:,:,2] image_2 = img_r*0.2989 + 0.587*img_g + 0...