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
16,375,781
I am trying a simple nested for loop in python to scan a threshold-ed image to detect the white pixels and store their location. The problem is that although the array it is reading from is only 160\*120 (19200) it still takes about 6s to execute, my code is as follows and any help or guidance would be greatly apprecia...
2013/05/04
[ "https://Stackoverflow.com/questions/16375781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274632/" ]
First, it shouldn't take 6 seconds. Trying your code on a 160x120 image takes ~0.2 s for me. That said, for good `numpy` performance, you generally want to avoid loops. Sometimes it's simpler to vectorize along all except the smallest axis and loop along that, but when possible you should try to do everything at once....
e you're on python 2.x (2.6 or 2.7). In python 2, every time you call `range` you're creating a list with that many elements. (In this case, you're creating 1 list of `width - 1` length, and then `width - 1` lists of `height - 1` length. One way to speed this up is to make one list of each ahead of time and use that li...
11,705,114
I am reading a bunch of strings from mysql database using python, and after some processing, writing them to a CSV file. However I see some totally junk characters appearing in the csv file. For example when I open the csv using gvim, I see characters like `<92>`,`<89>`, `<94>` etc. Any thoughts? I tried doing string...
2012/07/28
[ "https://Stackoverflow.com/questions/11705114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1546936/" ]
I would try a character class regex similar to ``` "[.!?\\-]" ``` Add whatever characters you wish to match inside the `[]`s. Be careful to escape any characters that might have a special meaning to the regex parser. You then have to iterate through the matches by using `Matcher.find()` until it returns false.
I would try > > `\W` > > > it matches any non-word character. This includes spaces and punctuation, but not underscores. It’s equivalent to [^A-Za-z0-9\_]
11,705,114
I am reading a bunch of strings from mysql database using python, and after some processing, writing them to a CSV file. However I see some totally junk characters appearing in the csv file. For example when I open the csv using gvim, I see characters like `<92>`,`<89>`, `<94>` etc. Any thoughts? I tried doing string...
2012/07/28
[ "https://Stackoverflow.com/questions/11705114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1546936/" ]
I would try a character class regex similar to ``` "[.!?\\-]" ``` Add whatever characters you wish to match inside the `[]`s. Be careful to escape any characters that might have a special meaning to the regex parser. You then have to iterate through the matches by using `Matcher.find()` until it returns false.
I was tring to find how to replace a regex, with keeping other regex part. Example: `Hi , how are you ?` -> `Hi, how are you?`. After studying a little i found that i could create groups, using "()", so just replaced the goup one, that was "(\s)". ```java String a = "Hi , how are you ?"; String p = "(\...
11,705,114
I am reading a bunch of strings from mysql database using python, and after some processing, writing them to a CSV file. However I see some totally junk characters appearing in the csv file. For example when I open the csv using gvim, I see characters like `<92>`,`<89>`, `<94>` etc. Any thoughts? I tried doing string...
2012/07/28
[ "https://Stackoverflow.com/questions/11705114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1546936/" ]
Java does support POSIX character classes in a roundabout way. For punctuation, the Java equivalent of **[:punct:]** is **\p{Punct}**. Please see the following [link](http://www.regular-expressions.info/posixbrackets.html) for details. Here is a concrete, working example that uses the expression in the comments ``` ...
I would try > > `\W` > > > it matches any non-word character. This includes spaces and punctuation, but not underscores. It’s equivalent to [^A-Za-z0-9\_]
11,705,114
I am reading a bunch of strings from mysql database using python, and after some processing, writing them to a CSV file. However I see some totally junk characters appearing in the csv file. For example when I open the csv using gvim, I see characters like `<92>`,`<89>`, `<94>` etc. Any thoughts? I tried doing string...
2012/07/28
[ "https://Stackoverflow.com/questions/11705114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1546936/" ]
Java does support POSIX character classes in a roundabout way. For punctuation, the Java equivalent of **[:punct:]** is **\p{Punct}**. Please see the following [link](http://www.regular-expressions.info/posixbrackets.html) for details. Here is a concrete, working example that uses the expression in the comments ``` ...
I was tring to find how to replace a regex, with keeping other regex part. Example: `Hi , how are you ?` -> `Hi, how are you?`. After studying a little i found that i could create groups, using "()", so just replaced the goup one, that was "(\s)". ```java String a = "Hi , how are you ?"; String p = "(\...
11,705,114
I am reading a bunch of strings from mysql database using python, and after some processing, writing them to a CSV file. However I see some totally junk characters appearing in the csv file. For example when I open the csv using gvim, I see characters like `<92>`,`<89>`, `<94>` etc. Any thoughts? I tried doing string...
2012/07/28
[ "https://Stackoverflow.com/questions/11705114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1546936/" ]
I would try > > `\W` > > > it matches any non-word character. This includes spaces and punctuation, but not underscores. It’s equivalent to [^A-Za-z0-9\_]
I was tring to find how to replace a regex, with keeping other regex part. Example: `Hi , how are you ?` -> `Hi, how are you?`. After studying a little i found that i could create groups, using "()", so just replaced the goup one, that was "(\s)". ```java String a = "Hi , how are you ?"; String p = "(\...
49,557,625
For my exercice I must with selenium and Chrome webdriver with python 2.7 click on the link : > > <https://test.com/console/remote.pl> > > > Below structure of the html file : ``` <div class="leftside" > <span class="spacer spacer-20"></span> <a href="https://test.com" title="Retour à l'accueil"><img cl...
2018/03/29
[ "https://Stackoverflow.com/questions/49557625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4200256/" ]
I think you were pretty close. But as it is a `<div>` tag with *class* attribute set as **leftside** you have to be specific. But again the `<a[3]>` tag won't be the immediate child of `driver.find_element_by_xpath("//div[@class='leftside']` node but a decendent, so instead of `/` you have to induce `//` as follows : ...
The issue is that you need to have a tag name also. So you should either use ``` driver.find_element_by_xpath('//*[@id="leftside"]/a[3]').click() ``` When you don't care about which tag it is. Or you should use the actual tag if you care ``` driver.find_element_by_xpath('//div[@id="leftside"]/a[3]').click() ``` I...
49,557,625
For my exercice I must with selenium and Chrome webdriver with python 2.7 click on the link : > > <https://test.com/console/remote.pl> > > > Below structure of the html file : ``` <div class="leftside" > <span class="spacer spacer-20"></span> <a href="https://test.com" title="Retour à l'accueil"><img cl...
2018/03/29
[ "https://Stackoverflow.com/questions/49557625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4200256/" ]
I think you were pretty close. But as it is a `<div>` tag with *class* attribute set as **leftside** you have to be specific. But again the `<a[3]>` tag won't be the immediate child of `driver.find_element_by_xpath("//div[@class='leftside']` node but a decendent, so instead of `/` you have to induce `//` as follows : ...
i have got a similar problem but i didn't post it so thanks for the post. the xpath is `"//[@class="leftside"]/a[3]"` there is no id with the name **leftside** in your html.
49,544,207
I am using python 2.7. I am looking to calculate compounding returns from daily returns and my current code is pretty slow at calculating returns, so I was looking for areas where I could gain efficiency. What I want to do is pass two dates and a security into a price table and calulate the compounding returns betwee...
2018/03/28
[ "https://Stackoverflow.com/questions/49544207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5293603/" ]
Here is a solution (100x times faster on my computer with some dummy data). ``` import numpy as np price_df = price_df.set_index('asof') def calc_comp_returns_fast(price_df, start_date, end_date, security): rows = price_df[price_df.security_id == security].loc[start_date:end_date] changes = rows.px_last.pct_...
I'm not very familiar with pandas, but I'll give this a shot. Problem with your solution ========================== Your solution currently does a huge amount of unnecessary calculation. This is mostly due to the line: ``` df['return'] = df.px_last.pct_change() ``` This line is actually calcuating the percent ...
49,544,207
I am using python 2.7. I am looking to calculate compounding returns from daily returns and my current code is pretty slow at calculating returns, so I was looking for areas where I could gain efficiency. What I want to do is pass two dates and a security into a price table and calulate the compounding returns betwee...
2018/03/28
[ "https://Stackoverflow.com/questions/49544207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5293603/" ]
Here is a solution (100x times faster on my computer with some dummy data). ``` import numpy as np price_df = price_df.set_index('asof') def calc_comp_returns_fast(price_df, start_date, end_date, security): rows = price_df[price_df.security_id == security].loc[start_date:end_date] changes = rows.px_last.pct_...
We'll use `pd.merge_asof` to grab prices from `prices_df`. However, when we do, we'll need to have relevant dataframes sorted by the date columns we are utilizing. Also, for convenience, I'll aggregate some `pd.merge_asof` parameters in dictionaries to be used as keyword arguments. ``` prices_df = prices_df.sort_value...
51,454,694
Azure Cognitive Services OCR has a demo on the site <https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/#text> On the website, I get pretty accurate results. However, when I try to call the same using the code mentioned in their documentation, I get different and poor results. <https://learn...
2018/07/21
[ "https://Stackoverflow.com/questions/51454694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10093162/" ]
There is now an official Microsoft package for that: * <https://pypi.org/project/azure-cognitiveservices-vision-computervision/> With samples: * <https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/computer_vision_samples.py> Create issue on Github if you have troubles ...
There are two different APIs for recognizing text. The demo page is using the new way, but has the caveat that it only works for English as of this writing. The example code you should be looking at is [here](https://learn.microsoft.com/en-us/azure/cognitive-services/Computer-vision/quickstarts/python-hand-text). If y...
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
return false after the first pair (a,b) where a != b ``` def compare(list1,list2): for a,b in zip(list1[:-2],list2[:-2]): if a != b : return False return True ```
This way: ``` list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1[:-2] == list2[:-2] => True ```
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
return false after the first pair (a,b) where a != b ``` def compare(list1,list2): for a,b in zip(list1[:-2],list2[:-2]): if a != b : return False return True ```
Just slice the lists directly... ================================ `Python` has the syntax for slicing lists which looks like: ``` lst[start:stop:step] ``` a neat feature of this being that you can slice lists up to a position specified from the end using negative values. So if you have a list susch as: ``` lst = [...
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
return false after the first pair (a,b) where a != b ``` def compare(list1,list2): for a,b in zip(list1[:-2],list2[:-2]): if a != b : return False return True ```
If your lists are very large and you want to avoid duplicating them with `list1[:-2]==list2[:-2]`, you can use a generator expression for a more memory-efficient solution: ``` all(a==b for a,b,_ in zip(list1, list2, range(len(list1)-2))) ```
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
This way: ``` list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1[:-2] == list2[:-2] => True ```
Just slice the lists directly... ================================ `Python` has the syntax for slicing lists which looks like: ``` lst[start:stop:step] ``` a neat feature of this being that you can slice lists up to a position specified from the end using negative values. So if you have a list susch as: ``` lst = [...
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
This way: ``` list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1[:-2] == list2[:-2] => True ```
If your lists are very large and you want to avoid duplicating them with `list1[:-2]==list2[:-2]`, you can use a generator expression for a more memory-efficient solution: ``` all(a==b for a,b,_ in zip(list1, list2, range(len(list1)-2))) ```
45,836,036
Comparing two python lists upto n-2 elements: ```py list1 = [1,2,3,'a','b'] list2 = [1,2,3,'c','d'] list1 == list2 => True ``` Excluding the last 2 elements of the 2 lists they are the same. I am able to do it by comparing each and every element of the 2 lists. But is there any other efficient way to do this?
2017/08/23
[ "https://Stackoverflow.com/questions/45836036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7016928/" ]
If your lists are very large and you want to avoid duplicating them with `list1[:-2]==list2[:-2]`, you can use a generator expression for a more memory-efficient solution: ``` all(a==b for a,b,_ in zip(list1, list2, range(len(list1)-2))) ```
Just slice the lists directly... ================================ `Python` has the syntax for slicing lists which looks like: ``` lst[start:stop:step] ``` a neat feature of this being that you can slice lists up to a position specified from the end using negative values. So if you have a list susch as: ``` lst = [...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
For CSS, how about CSS in a Nutshell, by O'Reilly? Nice and thin.
[W3Schools](http://www.w3schools.com/) is a good place to start. However, you might also benefit by poking around the [Mozilla Developer Centre](https://developer.mozilla.org/En) (MDC), which has lots of information about HTML, CSS, and JavaScript. I now almost exclusively use the MDC for looking things up—it has lots...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
I won't suggest w3schools for CSS and XHTML, but [htmldog.com](http://www.htmldog.com). I would suggest something about unobtrouse JavaScript for JS.
The W3Schools site has a try it yourself section that i think will be perfect for you. [W3Schools CSS](http://www.w3schools.com/Css/default.asp) [W3Schools Javascript](http://www.w3schools.com/JS/default.asp)
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
For CSS, how about CSS in a Nutshell, by O'Reilly? Nice and thin.
Install [firebug](http://getfirebug.com/). * It helps inspecting html. * You can edit CSS on the fly. * Has a JavaScript console. [Here](http://net.tutsplus.com/tutorials/other/10-reasons-why-you-should-be-using-firebug/) is a nice article explaining the some features of [firebug](http://getfirebug.com/).
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
You can learn style and best practices on [A List Apart](http://www.alistapart.com/) web site.
Opera recently put a lot of effort into getting people to write a [bunch of tutorials](http://opera.com/wsc/). The quality is high, and they pay attention to feedback (unlike W3Schools). It covers HTML, CSS and JavaScript and I haven't come across a better starting point.
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
Since you are an experienced programmer, a good place to start with javascript might be [Javascript: The Good Parts](https://rads.stackoverflow.com/amzn/click/com/0596517742) by Douglas Crockford. It is a brief but thorough tour of, well, the best parts of javascript (and pretty much all you'll need for quite a while)....
My favourite CSS tutorial site has always been [www.htmldog.com](http://www.htmldog.com). The reason I like it so much is that not only does it teach you CSS, it also teaches you to drop any bad html habits you may have picked up over the years. In my view learning to write clean, semantic html is an important precurso...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
You can learn style and best practices on [A List Apart](http://www.alistapart.com/) web site.
I found <http://htmldog.com/> to be useful when learning HTML/CSS. It teaches w3c compliant HTML and CSS, unlike many other sites. Looking at other people's CSS is also really useful. CSS is pretty simple (ignoring all the browser incompatibilites), so even will little CSS knowledge you can figure out what other people...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
Since you are an experienced programmer, a good place to start with javascript might be [Javascript: The Good Parts](https://rads.stackoverflow.com/amzn/click/com/0596517742) by Douglas Crockford. It is a brief but thorough tour of, well, the best parts of javascript (and pretty much all you'll need for quite a while)....
For CSS, how about CSS in a Nutshell, by O'Reilly? Nice and thin.
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
You can learn style and best practices on [A List Apart](http://www.alistapart.com/) web site.
My favourite CSS tutorial site has always been [www.htmldog.com](http://www.htmldog.com). The reason I like it so much is that not only does it teach you CSS, it also teaches you to drop any bad html habits you may have picked up over the years. In my view learning to write clean, semantic html is an important precurso...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
I found <http://htmldog.com/> to be useful when learning HTML/CSS. It teaches w3c compliant HTML and CSS, unlike many other sites. Looking at other people's CSS is also really useful. CSS is pretty simple (ignoring all the browser incompatibilites), so even will little CSS knowledge you can figure out what other people...
My favourite CSS tutorial site has always been [www.htmldog.com](http://www.htmldog.com). The reason I like it so much is that not only does it teach you CSS, it also teaches you to drop any bad html habits you may have picked up over the years. In my view learning to write clean, semantic html is an important precurso...
746,873
I am a C/C++ programmer with more than 10 years of experience. I also know python and perl, but I've never used this languages for a web development. Now for some reasons I want to move into the web development realm and as part of that transition I have to learn css, javascript, (x)html etc. So I need an advice for...
2009/04/14
[ "https://Stackoverflow.com/questions/746873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/90593/" ]
I would highly recommend you look at [Dev Opera](http://dev.opera.com/), its full of up to date information with a strong focus on webstandards. In particular, the [Web Standards Curriculum](http://dev.opera.com/articles/wsc/) is a great resource for beginners to get started. I really wouldn't rely on the W3 Schools s...
My favourite CSS tutorial site has always been [www.htmldog.com](http://www.htmldog.com). The reason I like it so much is that not only does it teach you CSS, it also teaches you to drop any bad html habits you may have picked up over the years. In my view learning to write clean, semantic html is an important precurso...
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
[Perl](http://www.perl.org/) - interesting that there are so many answers before this
You can do almost-interactive C# and VB.NET using [LINQPad](http://www.linqpad.net/)
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
Lisp and Scheme have interactive mode.
I guess one of the first was LISP. Just try clisp
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
FORTH comes immediately to mind. So does APL. I remember seeing an interactive FORTRAN implementation on an SDS-930 (I think), many, many moons ago.
True to its name, the science-oriented and proprietary [Interactive Data Language](http://en.wikipedia.org/wiki/IDL_%28programming_language%29) (usually just called IDL, but spelled out here to avoid confusion with the other [IDL](http://en.wikipedia.org/wiki/Interface_description_language)) has an interactive mode whi...
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
[Haskell](http://www.haskell.org/) even has two (mainstream) interactive interpreters, [Hugs](http://www.mirrorservice.org/sites/www.haskell.org/hugs/) and [ghci](http://www.haskell.org/haskellwiki/GHC/GHCi).
[Perl](http://www.perl.org/) - interesting that there are so many answers before this
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
* PHP can do that too: [PHP from the command line](http://php.net/manual/en/features.commandline.php) * Does mySQL count? [mySQL Commands](http://dev.mysql.com/doc/refman/4.1/en/mysql-commands.html) * [JavaScript shell in SpiderMonkey](https://developer.mozilla.org/en/Introduction_to_the_JavaScript_shell) (including, b...
Most scripting languages will read from stdin and execute code typed at the console if you don't specify a filename to run. Php and perl will all do it. Ruby has irb. Lua has a more formal interactive mode like python, which will show you the indent level of your code at the prompt. It's very helpful since lua is typ...
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
Most (all?) lisps (including common lisp, scheme and clojure), sml, ocaml, haskell, F#, erlang, scala, ruby, python, lua, groovy, prolog.
Scala has [REPL](http://scala-lang.org/node/2097). > > The Scala Interpreter (often called a REPL for Read-Evaluate-Print > Loop) sits in an unusual design space - an interactive interpreter for > a statically typed language straddles two worlds which historically > have been distinct. In version 2.8 the REPL furt...
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
Any interpreted language is most likely going to have one.
True to its name, the science-oriented and proprietary [Interactive Data Language](http://en.wikipedia.org/wiki/IDL_%28programming_language%29) (usually just called IDL, but spelled out here to avoid confusion with the other [IDL](http://en.wikipedia.org/wiki/Interface_description_language)) has an interactive mode whi...
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
[Haskell](http://www.haskell.org/) even has two (mainstream) interactive interpreters, [Hugs](http://www.mirrorservice.org/sites/www.haskell.org/hugs/) and [ghci](http://www.haskell.org/haskellwiki/GHC/GHCi).
There's one for [C#](http://www.mono-project.com/CsharpRepl).
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
As has been pointed out lots of languages can be used interactively, though how conveniently they can be so used varies quite a bit. The interactive environment I'm most familiar with, and one that I have found among the most congenial of all the free environments for interactive programming I've tried (not that I've t...
You can do almost-interactive C# and VB.NET using [LINQPad](http://www.linqpad.net/)
2,575,219
Python language has a well known feature named [interactive mode](http://docs.python.org/tutorial/interpreter.html#interactive-mode) where the interpreter can read commands directly from tty. I typically use this mode to test if a given module is in the classpath or to play around and test some snippets. Do you kno...
2010/04/04
[ "https://Stackoverflow.com/questions/2575219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/130929/" ]
**Logo** programming language. Some implementations are so interactive that some people don't even use any other mode.
[Erlang](http://www.erlang.org/index.html) does, as well as [Haskell](http://www.haskell.org/) and i'm guessing [Ruby](http://www.ruby-lang.org/en/) does. Also there are Javascript CLIs like [Firebug](http://getfirebug.com/)
59,023,371
I am tryin to have a form submit to a python script using flask. the form is in my index.html - ``` <form action="{{ url_for('/predict') }}" method="POST"> <p>Enter Mileage</p> <input type="text" name="mileage"> <p>Enter Year</p> <input type="text" name="year"> <input type="submit" value="Predict"...
2019/11/24
[ "https://Stackoverflow.com/questions/59023371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4671619/" ]
Instead of `url_for('/predict')`, drop the leading slash and use `url_for('predict')`. `url_for(...)` takes the method name and not the route name.
I was not importing url\_for. ``` from flask import Flask, request, render_template, url_for ```
62,075,847
I tried to create a polygon shapefile in QGIS and read it in python by shapely. An example code looks like this: ``` import fiona from shapely.geometry import shape multipolys = fiona.open(somepath) multi = multipolys[0] coord = shape(multi['geometry']) ``` The EOSGeom\_createLinearRing\_r returned a NULL pointer I...
2020/05/28
[ "https://Stackoverflow.com/questions/62075847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13242482/" ]
I had a similar problem but with the shapely.geometry.LineString. The error I got was ``` ValueError: GEOSGeom_createLineString_r returned a NULL pointer ``` I don't know the reason behind this message, but there are two ways, how to avoid it: 1. Do the following: ``` ... from shapely import speedups ... speedups...
Face the same issue and this work for me `import shapely` `shapely.speedups.disable()`
62,075,847
I tried to create a polygon shapefile in QGIS and read it in python by shapely. An example code looks like this: ``` import fiona from shapely.geometry import shape multipolys = fiona.open(somepath) multi = multipolys[0] coord = shape(multi['geometry']) ``` The EOSGeom\_createLinearRing\_r returned a NULL pointer I...
2020/05/28
[ "https://Stackoverflow.com/questions/62075847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13242482/" ]
Like J. P., I had this issue with creating LineStrings as well. There is [an old issue](https://github.com/Toblerity/Shapely/issues/353) (2016) in the Shapely github repository that seems related. Changing the order of the imports solved the problem for me: ```py from shapely.geometry import LineString import fiona ...
Face the same issue and this work for me `import shapely` `shapely.speedups.disable()`
62,479,608
What's the difference? [docs](https://docs.python.org/3.7/library/types.html#types.FunctionType) show nothing on this, and their `help()` is identical. Is there an object for which `isinstance` will fail with one but not other?
2020/06/19
[ "https://Stackoverflow.com/questions/62479608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10133797/" ]
Back in 1994 I wasn't sure that we would always be using the same implementation type for lambda and def. That's all there is to it. It would be a pain to remove it, so we're just leaving it (it's only one line). If you want to add a note to the docs, feel free to submit a PR.
See [`cpython/Lib/types.py`](https://github.com/python/cpython/blob/a041e116db5f1e78222cbf2c22aae96457372680/Lib/types.py#L11-L13): ``` def _f(): pass FunctionType = type(_f) LambdaType = type(lambda: None) # Same as FunctionType ```
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
1. go the windows cmd prompt 2. go to the python directory 3. then type python -m pip install package-name
I had the same problem with Version 3.5.2. Have you tried `py.exe -m install package-name`? This worked for me.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
1. go the windows cmd prompt 2. go to the python directory 3. then type python -m pip install package-name
If you are working in Pycharm, an easy way is go to file>setting>project interpreter. Click on the + icon you will find on right side probably and then search and install required library.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
1. go the windows cmd prompt 2. go to the python directory 3. then type python -m pip install package-name
As soon as you open a command prompt, use: ``` python -m pip install --upgrade pip ``` then ``` python -m pip install <<package-name>> ```
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
Add the Script folder of python to your environment path or you can do this from command line: ``` python -m pip install package-name ```
As soon as you open a command prompt, use: ``` python -m pip install --upgrade pip ``` then ``` python -m pip install <<package-name>> ```
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
I was having the same problem on Windows 10, This is how I fix it: 1. Click the *search* icon and type **System Environment** 2. In *System Properties* click on **Environment Variables** 3. In *System Variables* tab click **New** 4. Enter **PYTHON3\_SCRIPTS** for the *variable name* and `C:\Users\YOUR USER NAME\AppDat...
If you are working in Pycharm, an easy way is go to file>setting>project interpreter. Click on the + icon you will find on right side probably and then search and install required library.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
run it at the cmd window, not inside the python window. it took me forever to realize my mistake.
I had the same problem with Version 3.5.2. Have you tried `py.exe -m install package-name`? This worked for me.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
run it at the cmd window, not inside the python window. it took me forever to realize my mistake.
If you are working in Pycharm, an easy way is go to file>setting>project interpreter. Click on the + icon you will find on right side probably and then search and install required library.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
If you are working in Pycharm, an easy way is go to file>setting>project interpreter. Click on the + icon you will find on right side probably and then search and install required library.
For those with several python versions of python 3 installed in windows: I solved this issue by executing the pip install command directly from my python35 Scripts folder in cmd...for some reason pip3 pointed to python 34 even though python 35 was set first in environmental variables.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
Add the Script folder of python to your environment path or you can do this from command line: ``` python -m pip install package-name ```
For those with several python versions of python 3 installed in windows: I solved this issue by executing the pip install command directly from my python35 Scripts folder in cmd...for some reason pip3 pointed to python 34 even though python 35 was set first in environmental variables.
34,247,930
I have installed python 3.5 on my Windows 7 machine. When I installed it, I marked the check box to install `pip`. After the installation, I wanted to check whether pip was working, so I typed `pip` on the command line and hit enter, but did not respond. The cursor blinks but it does not display anything. Please help....
2015/12/13
[ "https://Stackoverflow.com/questions/34247930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4542278/" ]
I had the same problem with Version 3.5.2. Have you tried `py.exe -m install package-name`? This worked for me.
For those with several python versions of python 3 installed in windows: I solved this issue by executing the pip install command directly from my python35 Scripts folder in cmd...for some reason pip3 pointed to python 34 even though python 35 was set first in environmental variables.
66,873,774
I'm really new to python and pandas so would you please help me answer this seemingly simple question? I already have an excel file containing my data, now I want to create an array containing those data in python. For example, I have data in excel that look like this: [![enter image description here](https://i.stack....
2021/03/30
[ "https://Stackoverflow.com/questions/66873774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14533186/" ]
This is quite simple; if you take a look at your code you should be able to follow through this sequence of operations. 1. The widget is created. **No action.** *At this point userIconData is null.* 2. `initState` is called. **async http call is initiated.** *userIconData == null* 3. `build` is called. **build occurs,...
The error message is pretty clear to me. `userIconData` is `null` when you pass it to the `Image.memory` constructor. Either use [FutureBuilder](https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html) or a condition to check if `userIconData` is null before rendering image, and manually show a loading indica...
54,392,016
I have a python script were I was experimenting with minmax AI. And so tried to make a tic tac toe game. I had a self calling function to calculate the values and it used a variable called alist(not the one below) which would be given to it by the function before. it would then save it as new list and modify it. This...
2019/01/27
[ "https://Stackoverflow.com/questions/54392016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10976004/" ]
`newlist = alist` does not make a copy of the list. You just have two variable names for the same list. There are several ways to actually copy a list. I usually do this: ``` newlist = alist[:] ``` On the other hand, that will make a new list with the same elements. To make a deep copy of the list: ``` import copy...
You probably want to `deepcopy` your list, as it contains other lists: ``` from copy import deepcopy ``` And then change: ``` newlist = alist ``` to: ``` newlist = deepcopy(alist) ```
70,163,997
I have a folder of python scripts, I want to call each of them and pass in a DB object, this is easily doable, but I would like to do it dynamically, that is if I don't know the name of the script beforehand, is this possible? Let's say all scripts are in the "scripts" subfolder. My caller file: ``` #!/usr/bin/pytho...
2021/11/30
[ "https://Stackoverflow.com/questions/70163997", "https://Stackoverflow.com", "https://Stackoverflow.com/users/468384/" ]
If we work backwards, you'll need your DataFrame to have the addenda information in a single row before using `.to_dict` operation: | id\_number | name | amount | addenda | | --- | --- | --- | --- | | 1234 | ABCD | $100 | [{payment\_related\_info: Car-wash-$30, payment\_related\_info: Maintenance-$70}] | To get here,...
Just apply a groupby and aggregate by creating a dataframe inside like this: ```py data = { "id_number": [1234, 1234], "name": ["ABCD", "ABCD"], "amount": ["$100", "$100"], "addenda": ["Car-wash-$30", "Maintenance-$70"] } df = pd.DataFrame(data=data) df.groupby(by=["id_number", "name", "amount"]) \ ...
25,598,838
I'm really new to python so this is probably a really stupid problem but I honestly have no idea what I'm doing and I have spent hours trying to get this to work. I need to have the user input a date (in string form) and then use this date to return some data (The function get\_data\_for\_date has already previously b...
2014/09/01
[ "https://Stackoverflow.com/questions/25598838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3995938/" ]
Try this sequence : ``` MYApplication.getInstance().clearApplicationData(); android.os.Process.killProcess(android.os.Process.myPid()); Intent intent1 = new Intent(Intent.ACTION_MAIN); intent1.addCategory(Intent.CATEGORY_HOME); intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(int...
Avoid `killProcess` Try this code : ``` Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(startMain); System.exit(-1); ```
25,598,838
I'm really new to python so this is probably a really stupid problem but I honestly have no idea what I'm doing and I have spent hours trying to get this to work. I need to have the user input a date (in string form) and then use this date to return some data (The function get\_data\_for\_date has already previously b...
2014/09/01
[ "https://Stackoverflow.com/questions/25598838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3995938/" ]
This is a fair and simple way of exiting an android app programmatically in my opinion: ``` Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); ``` Hope it helps.
Avoid `killProcess` Try this code : ``` Intent startMain = new Intent(Intent.ACTION_MAIN); startMain.addCategory(Intent.CATEGORY_HOME); startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(startMain); System.exit(-1); ```
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
If you are using Linux and a distribution like Ubuntu, you will definitely break the OS. Don't do it. Moreover, there is no evidence that your installation is broken because of Python, and you may probably not solve your problem.
There's no harm I can see in overwriting a pip installation. So, just follow the [instructions](https://pip.pypa.io/en/stable/installing/) and let us know if you have further problems: 1. Download [get-pip.py](https://bootstrap.pypa.io/get-pip.py). 2. Run python get-pip.py and get on with the rest of your stuff.
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
Your Python files are not specially managed by Python itself. If you uninstall Python, source code files (files with the `.py` extension) won't be affected.
There's no harm I can see in overwriting a pip installation. So, just follow the [instructions](https://pip.pypa.io/en/stable/installing/) and let us know if you have further problems: 1. Download [get-pip.py](https://bootstrap.pypa.io/get-pip.py). 2. Run python get-pip.py and get on with the rest of your stuff.
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
There's no harm I can see in overwriting a pip installation. So, just follow the [instructions](https://pip.pypa.io/en/stable/installing/) and let us know if you have further problems: 1. Download [get-pip.py](https://bootstrap.pypa.io/get-pip.py). 2. Run python get-pip.py and get on with the rest of your stuff.
Before uninstalling python, make sure all your python applications support the new python version. My suggestion is to create virtual environments in your system to use multiple python versions Try Anaconda - <https://www.anaconda.com/> to create multiple virtual environments, where you can run a python version on ea...
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
There's no harm I can see in overwriting a pip installation. So, just follow the [instructions](https://pip.pypa.io/en/stable/installing/) and let us know if you have further problems: 1. Download [get-pip.py](https://bootstrap.pypa.io/get-pip.py). 2. Run python get-pip.py and get on with the rest of your stuff.
It depends on whether you installed the Python or it came with the OS. If you installed Python, it’s no problem at all — your files are safe and uninstalling Python won’t touch them. If you’re planning on uninstalling the Python that came with your OS, I’d advise not do do that — it could cause a whole lot of trouble...
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
If you are using Linux and a distribution like Ubuntu, you will definitely break the OS. Don't do it. Moreover, there is no evidence that your installation is broken because of Python, and you may probably not solve your problem.
Before uninstalling python, make sure all your python applications support the new python version. My suggestion is to create virtual environments in your system to use multiple python versions Try Anaconda - <https://www.anaconda.com/> to create multiple virtual environments, where you can run a python version on ea...
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
If you are using Linux and a distribution like Ubuntu, you will definitely break the OS. Don't do it. Moreover, there is no evidence that your installation is broken because of Python, and you may probably not solve your problem.
It depends on whether you installed the Python or it came with the OS. If you installed Python, it’s no problem at all — your files are safe and uninstalling Python won’t touch them. If you’re planning on uninstalling the Python that came with your OS, I’d advise not do do that — it could cause a whole lot of trouble...
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
Your Python files are not specially managed by Python itself. If you uninstall Python, source code files (files with the `.py` extension) won't be affected.
Before uninstalling python, make sure all your python applications support the new python version. My suggestion is to create virtual environments in your system to use multiple python versions Try Anaconda - <https://www.anaconda.com/> to create multiple virtual environments, where you can run a python version on ea...
63,570,453
I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
2020/08/25
[ "https://Stackoverflow.com/questions/63570453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13931651/" ]
Your Python files are not specially managed by Python itself. If you uninstall Python, source code files (files with the `.py` extension) won't be affected.
It depends on whether you installed the Python or it came with the OS. If you installed Python, it’s no problem at all — your files are safe and uninstalling Python won’t touch them. If you’re planning on uninstalling the Python that came with your OS, I’d advise not do do that — it could cause a whole lot of trouble...
14,068,042
Resently I'm installed Opencv in my machine. Its working in python well(I just checked it by some eg programs). But due to the lack of tutorials in python I decided to move to c. I just run an Hello world program from <http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/> My program is ``` #include <stdlib.h> #...
2012/12/28
[ "https://Stackoverflow.com/questions/14068042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1894272/" ]
First check if highgui.h exists on your machine: ``` sudo find /usr/include -name "highgui.h" ``` If you find it on path lets say "/usr/include/opencv/highgui.h" then use: ``` #include <opencv/highgui.h> in your c file. ``` or while compiling you could add ``` -I/usr/include/opencv in gcc line ``` but then...
I have the following headers in my project: ``` #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/objdetect/objdetect.hpp> #include <opencv2/features2d/features2d.hpp> ``` The version of OpenCV 2.4.2
64,983,755
As of until now, my understanding is that python imports module by the path relative to the directory, despite the source file being anywhere else. for example: ``` bar |-foo.py |-foo1.py ``` so if we want to access `fo01.py` through `foo.py` from `bar`, I would think I need to do `from bar import foo1`. But the ...
2020/11/24
[ "https://Stackoverflow.com/questions/64983755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9817556/" ]
before explaining why and how to make things work. let me put some right code. here is the dir tree(which followed yours) ``` . ├── bar │   ├── foo1.py │   └── foo.py └── examples └── getfoo.py ``` and there is a variable named `var` in foo1.py and foo.py Question I: > > so if we want to access fo01.py throu...
Try importing foo1.py in getfoo1.py using its path. ``` import ../bar/foo1.py ``` Or copy paste foo1.py in examples and then call ``` import foo1.py ``` Please check syntax for "import ../bar/foo1.py"
67,045,619
I have a python script and I used on Kubernetes. After process ended on python script Kubernetes restart pod. And I don't want to this. I tried to add a line of code from python script like that: ``` text = input("please a key for exiting") ``` And I get EOF error, so its depends on container has no EOF config on m...
2021/04/11
[ "https://Stackoverflow.com/questions/67045619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13338897/" ]
You get `unknown field \"restartPolicy\" in io.k8s.api.core.v1.PodTemplateSpec;` because you most probably messed up some indentation. Here is an example deploymeny with **incorrect indentation** of `restartPolicy` field: ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: n...
A PodSpec has a restartPolicy field with possible values Always, OnFailure, and Never. The default value is Always. could you please try OnFailure you have only one container it should work.
67,045,619
I have a python script and I used on Kubernetes. After process ended on python script Kubernetes restart pod. And I don't want to this. I tried to add a line of code from python script like that: ``` text = input("please a key for exiting") ``` And I get EOF error, so its depends on container has no EOF config on m...
2021/04/11
[ "https://Stackoverflow.com/questions/67045619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13338897/" ]
You get `unknown field \"restartPolicy\" in io.k8s.api.core.v1.PodTemplateSpec;` because you most probably messed up some indentation. Here is an example deploymeny with **incorrect indentation** of `restartPolicy` field: ``` apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: n...
you have a single process which ends due to exception you need to correct that logic. and can set OnFailure. If you want to debug your code then you need to catch this error and log it. so that your process should not end or you can run this logic inside a new thread. which will be child thread and in main thread you c...
67,025,052
As I am teaching myself Bash programming, I came across an interesting use case, where **I want to take a list of variables that exist in the environment, and put them into an array. Then, I want to output a list of the variable names and their values, and store that output in an array, one entry per variable.** I'm o...
2021/04/09
[ "https://Stackoverflow.com/questions/67025052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12854372/" ]
OP starts with: ``` VAR_ONE="LIGHT RED" VAR_TWO="DARK GREEN" VAR_THREE="BLUE" VARIABLE_ARRAY=(VAR_ONE VAR_TWO VAR_THREE) ``` OP has provided an answer with 4 sets of code: ``` # first 3 sets of code generate: $ typeset -p outputValues declare -a outputValues=([0]="VAR_ONE: LIGHT RED" [1]="VAR_TWO: DARK GREEN" [2]=...
I've come up with a handful of possible solutions in the last couple days, each one with their own pro's and con's. I won't mark this as the answer for awhile though, since I'm interested in hearing unbiased recommendations. --- My brainstorming solutions thus far: OPTION #1 - FOR-LOOP: ``` alias PrintCommandValues...
1,894,099
I am trying to run the script [csv2json.py](http://www.djangosnippets.org/snippets/1680/) in the Command Prompt, but I get this error: ``` C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1.csv from CSV to JSON as C:\Users\A\Docume...
2009/12/12
[ "https://Stackoverflow.com/questions/1894099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/215094/" ]
``` from os import path in_file = path.join(dirname(__file__), input_file_name ) out_file = path.join(dirname(__file__), input_file_name + ".json" ) [...] ```
You should be using `os.path.join` rather than just concatenating `dirname()` and filenames. ``` import os.path in_file = os.path.join(dirname(__file__), input_file_name) out_file = os.path.join(dirname(__file__), input_file_name + ".json") ``` will fix your problem, though depending on what exactly you're doing, th...
1,894,099
I am trying to run the script [csv2json.py](http://www.djangosnippets.org/snippets/1680/) in the Command Prompt, but I get this error: ``` C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1.csv from CSV to JSON as C:\Users\A\Docume...
2009/12/12
[ "https://Stackoverflow.com/questions/1894099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/215094/" ]
`+` is used incorrectly here, the proper way to combine directory name and file name is using `os.path.join()`. But there is no need to combine directory where script is located with file name, since it's common to pass relative path to current working directory. So, change lines 31-32 to the following: ``` in_file = ...
You should be using `os.path.join` rather than just concatenating `dirname()` and filenames. ``` import os.path in_file = os.path.join(dirname(__file__), input_file_name) out_file = os.path.join(dirname(__file__), input_file_name + ".json") ``` will fix your problem, though depending on what exactly you're doing, th...
1,894,099
I am trying to run the script [csv2json.py](http://www.djangosnippets.org/snippets/1680/) in the Command Prompt, but I get this error: ``` C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1.csv from CSV to JSON as C:\Users\A\Docume...
2009/12/12
[ "https://Stackoverflow.com/questions/1894099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/215094/" ]
`+` is used incorrectly here, the proper way to combine directory name and file name is using `os.path.join()`. But there is no need to combine directory where script is located with file name, since it's common to pass relative path to current working directory. So, change lines 31-32 to the following: ``` in_file = ...
``` from os import path in_file = path.join(dirname(__file__), input_file_name ) out_file = path.join(dirname(__file__), input_file_name + ".json" ) [...] ```
33,545,813
I am creating a Python class but it seems I can't get the constructor class to work properly. Here is my class: ``` class IQM_Prep(SBconcat): def __init__(self,project_dir): self.project_dir=project_dir #path to parent project dir self.models_path=self.__get_models_path__() #path to parent models ...
2015/11/05
[ "https://Stackoverflow.com/questions/33545813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3059024/" ]
Based on the traceback, it seems that either: ``` def __get_models_path__(self): for i in os.listdir(self.project_dir): # 1. this never loops; or if i=='models': # 2. this never evaluates True models_path=os.path.join(self.project_dir,i) # hence this never happens return models_path # a...
`models_path` is initialized only when: * `self.project_dir` has some files/dirs and * one of this file/dir has name `models` If one of this condition is not fullfiled, then `models_path` is not initialized.
21,319,261
I am trying to execute some code on a Beaglebone Black running ubuntu. The script has two primary functions: 1: count digital pulse 2: store the counted pulses in mySQL every 10s or so These two functions need to run idefinitely. My question is how to do get these two functions to run in parallel? Here is my latest c...
2014/01/23
[ "https://Stackoverflow.com/questions/21319261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133624/" ]
This is a perfect problem for a `Queue`! ``` #!/usr/bin/python import Adafruit_BBIO.GPIO as GPIO import MySQLdb import time import thread import Queue from threading import Thread now = time.strftime('%Y-%m-%d %H:%M:%S') total1 = 0 total2 = 0 pulse_objects = Queue.Queue() def insertDB_10sec(pulse_objects): whi...
Why do you need two threads? Move the insert to `countPulse`. That being said: You should not call `insertDB_10sec` here: ``` t2 = Thread(target = insertDB_10sec(now, total1, total2)) ``` Provide the arguments as actual arguments: ``` t2 = Thread(target = insertDB_10sec, args=(now, total1, total2)) ``` This will...
3,023,136
Is it somehow possible to extract .cab files in python?
2010/06/11
[ "https://Stackoverflow.com/questions/3023136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341963/" ]
Not strictly answering what you asked, but if you are running on a windows platform you could spawn a process to do it for you. Taken from Wikipedia: > > Microsoft Windows provides two > command-line tools for creation and > extraction of CAB files. They are > MAKECAB.EXE (included within Windows > packages suc...
Oddly, the [msilib](http://docs.python.org/library/msilib.html) can only create or append to .CAB files, but not extract them. :( However, the [hachoir](https://hachoir.readthedocs.io/en/latest/parser.html) parser module can apparently read & edit Cabinets. (I have not used it, though, so I couldn't tell you how fitti...
3,023,136
Is it somehow possible to extract .cab files in python?
2010/06/11
[ "https://Stackoverflow.com/questions/3023136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341963/" ]
I had the same problem last week so I implemented this in python. Comments, additions and especially pull requests welcome: <https://github.com/hughsie/python-cabarchive>
Oddly, the [msilib](http://docs.python.org/library/msilib.html) can only create or append to .CAB files, but not extract them. :( However, the [hachoir](https://hachoir.readthedocs.io/en/latest/parser.html) parser module can apparently read & edit Cabinets. (I have not used it, though, so I couldn't tell you how fitti...
66,283,314
I am writing a script to automate data collection and was having trouble clicking a link. The website is behind a login, but I navigated that successfully. I ran into problems when trying to navigate to the download page. This is in python using chrome webdriver. I have tried using: ``` find_element_by_partial_link_t...
2021/02/19
[ "https://Stackoverflow.com/questions/66283314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14024634/" ]
This is caused by a typo. `Download` is case-sensitive, make sure you capitalize the `D`!
To click on the element with text as **Download** you can use either of the following [Locator Strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890): * Using `css_selector`: ``` driver.find_element(By.CSS_SELECTOR, "a[title='Download'][href='/itron-m...
27,572,688
I have written the following code using Python 2.7 to search the list 'dem\_nums' for the first three characters from each element in the list 'dems', and if they are not present to append them. When I run the code the list 'dem\_nums' is returned as empty. I've tried using this article to help ([check if a number alre...
2014/12/19
[ "https://Stackoverflow.com/questions/27572688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4289336/" ]
I am not sure I understand your requirement. Why write such a complicated stylesheet when the end result should simply be a total amount of numbers? Also, it seems you are already familiar with the relevant EXSLT functions and with converting strings into numbers. **Stylesheet** ``` <?xml version="1.0" encoding="UTF-...
While I tend to go with the suggestion made by Mathias Müller, I wanted to show how you can do this using a recursive named template: **XSLT 1.0** ``` <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" ind...
2,051,526
As we all know (or should), you can use Django's template system to render email bodies: ``` def email(email, subject, template, context): from django.core.mail import send_mail from django.template import loader, Context send_mail(subject, loader.get_template(template).render(Context(context)), 'from@dom...
2010/01/12
[ "https://Stackoverflow.com/questions/2051526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12870/" ]
This is my third working iteration. It assuming you have an email template like so: ``` {% block subject %}{% endblock %} {% block plain %}{% endblock %} {% block html %}{% endblock %} ``` I've refactored to iterate the email sending over a list by default and there are utility methods for sending to a single email ...
Just use two templates: one for the body and one for the subject.
2,051,526
As we all know (or should), you can use Django's template system to render email bodies: ``` def email(email, subject, template, context): from django.core.mail import send_mail from django.template import loader, Context send_mail(subject, loader.get_template(template).render(Context(context)), 'from@dom...
2010/01/12
[ "https://Stackoverflow.com/questions/2051526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12870/" ]
This is my third working iteration. It assuming you have an email template like so: ``` {% block subject %}{% endblock %} {% block plain %}{% endblock %} {% block html %}{% endblock %} ``` I've refactored to iterate the email sending over a list by default and there are utility methods for sending to a single email ...
I couldn't get template inheritance to work using the `{% body %}` tags, so I switched to a template like this: ``` {% extends "base.txt" %} {% if subject %}Subject{% endif %} {% if body %}Email body{% endif %} {% if html %}<p>HTML body</p>{% endif %} ``` Now we have to render the template three times, but the inhe...
62,191,724
Trying to make use of this package: <https://github.com/microsoft/Simplify-Docx> Can someone pls tell me the proper sequence of actions needed to install and use the package? What I've tried (as a separate commands from vscode terminal): ``` pip install python-docx Git clone <git link> python setup.py install ``` ...
2020/06/04
[ "https://Stackoverflow.com/questions/62191724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9130563/" ]
The problem is that your system doesn't have "docx" module. to install docx module you will have to install docx. steps to install: 1) open CMD prompt. 2) type "pip install docx" if your installation is fresh it may need "simplify" module too.
Like any python package that doesn't come with python, you need to install it before using it. In your terminal window you can install if from the Python package index like this: ```bash pip install simplify-docx ``` or you can install it directly from GitHub like this: ```bash pip install git+git://github.com/micr...
62,191,724
Trying to make use of this package: <https://github.com/microsoft/Simplify-Docx> Can someone pls tell me the proper sequence of actions needed to install and use the package? What I've tried (as a separate commands from vscode terminal): ``` pip install python-docx Git clone <git link> python setup.py install ``` ...
2020/06/04
[ "https://Stackoverflow.com/questions/62191724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9130563/" ]
Amin sama was right - that was indeed an environment issue. Looks like modules were getting globally installed in an older python folder. Different from the python which runs when you try to run python file. So I had to uninstall the older python. After that ``` py --version ``` and ``` Python --version ``` S...
Like any python package that doesn't come with python, you need to install it before using it. In your terminal window you can install if from the Python package index like this: ```bash pip install simplify-docx ``` or you can install it directly from GitHub like this: ```bash pip install git+git://github.com/micr...
19,085,887
I searched and tried following stuff but could not found any solution, please let me know if this is possible: I am trying to develop a python module as wrapper where I call another 3rd party module with its .main() and provide the required parameter which I need to get from command line in my module. I need few param...
2013/09/30
[ "https://Stackoverflow.com/questions/19085887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/948673/" ]
Does this scenario fit? Module B: ``` import argparse parser = argparse.... def main(args): .... if __name__ == '__main__': args = parser.parse_args() main(args) ``` Module A ``` import argparse import B parser = argparse.... # define arguments that A needs to use if _name__=='__main__': args,rest...
Provided that you are calling third-party modules, a possible solution is to change **sys.argv** and **sys.argc** at runtime to reflect the correct parameters for the module you're calling, once you're done with your own parameters.
19,085,887
I searched and tried following stuff but could not found any solution, please let me know if this is possible: I am trying to develop a python module as wrapper where I call another 3rd party module with its .main() and provide the required parameter which I need to get from command line in my module. I need few param...
2013/09/30
[ "https://Stackoverflow.com/questions/19085887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/948673/" ]
Thanks hpaulj, mguijarr and mike, I was able to resolve the issue with all above inputs, like following: My module: ``` import sys import argparse parser = argparse.ArgumentParser(description='something') parser.add_argument('--my_env', help='my environment') if __name__=='__main__': args,rest = parser.parse_kn...
Provided that you are calling third-party modules, a possible solution is to change **sys.argv** and **sys.argc** at runtime to reflect the correct parameters for the module you're calling, once you're done with your own parameters.
51,876,794
I have a text file named `file.txt` with some numbers like the following : ``` 1 79 8.106E-08 2.052E-08 3.837E-08 1 80 -4.766E-09 9.003E-08 4.812E-07 1 90 4.914E-08 1.563E-07 5.193E-07 2 2 9.254E-07 5.166E-06 9.723E-06 2 3 1.366E-06 -5.184E-06 7.580E-06 2 4 2.966E-06 5.979E-07 9.702E-08 2 5 5.254E...
2018/08/16
[ "https://Stackoverflow.com/questions/51876794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8869818/" ]
You can use a `defaultdict`. ``` from collections import defaultdict data = defaultdict(list) with open("file.txt", "r") as f: for line in f: line = line.split() data[line[0]].extend(line[2:]) ```
Try this: ``` from collections import defaultdict diction = defaultdict(list) with open("file.txt") as f: for line in f: key, _, *values = line.strip().split() diction[key].extend(values) print(diction) ``` This is a solution for Python 3, because the statement `a, *b = tuple1` is invalid in P...
51,876,794
I have a text file named `file.txt` with some numbers like the following : ``` 1 79 8.106E-08 2.052E-08 3.837E-08 1 80 -4.766E-09 9.003E-08 4.812E-07 1 90 4.914E-08 1.563E-07 5.193E-07 2 2 9.254E-07 5.166E-06 9.723E-06 2 3 1.366E-06 -5.184E-06 7.580E-06 2 4 2.966E-06 5.979E-07 9.702E-08 2 5 5.254E...
2018/08/16
[ "https://Stackoverflow.com/questions/51876794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8869818/" ]
You can use a `defaultdict`. ``` from collections import defaultdict data = defaultdict(list) with open("file.txt", "r") as f: for line in f: line = line.split() data[line[0]].extend(line[2:]) ```
Make the value of each key in `diction` be a list and extend that list with each iteration. With your code as it is written now when you say `diction[pa[0]] = pa[1:]` you're overwriting the value in `diction[pa[0]]` each time the key appears, which describes the behavior you're seeing. ``` with open("file.txt") as f: ...
51,876,794
I have a text file named `file.txt` with some numbers like the following : ``` 1 79 8.106E-08 2.052E-08 3.837E-08 1 80 -4.766E-09 9.003E-08 4.812E-07 1 90 4.914E-08 1.563E-07 5.193E-07 2 2 9.254E-07 5.166E-06 9.723E-06 2 3 1.366E-06 -5.184E-06 7.580E-06 2 4 2.966E-06 5.979E-07 9.702E-08 2 5 5.254E...
2018/08/16
[ "https://Stackoverflow.com/questions/51876794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8869818/" ]
You can use a `defaultdict`. ``` from collections import defaultdict data = defaultdict(list) with open("file.txt", "r") as f: for line in f: line = line.split() data[line[0]].extend(line[2:]) ```
To do this in a very simple for loop: ``` with open('file.txt') as f: return_dict = {} for item_list in map(str.split, f): if item_list[0] not in return_dict: return_dict[item_list[0]] = [] return_dict[item_list[0]].extend(item_list[1:]) return return_dict ``` Or, if you wan...
51,876,794
I have a text file named `file.txt` with some numbers like the following : ``` 1 79 8.106E-08 2.052E-08 3.837E-08 1 80 -4.766E-09 9.003E-08 4.812E-07 1 90 4.914E-08 1.563E-07 5.193E-07 2 2 9.254E-07 5.166E-06 9.723E-06 2 3 1.366E-06 -5.184E-06 7.580E-06 2 4 2.966E-06 5.979E-07 9.702E-08 2 5 5.254E...
2018/08/16
[ "https://Stackoverflow.com/questions/51876794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8869818/" ]
Try this: ``` from collections import defaultdict diction = defaultdict(list) with open("file.txt") as f: for line in f: key, _, *values = line.strip().split() diction[key].extend(values) print(diction) ``` This is a solution for Python 3, because the statement `a, *b = tuple1` is invalid in P...
Make the value of each key in `diction` be a list and extend that list with each iteration. With your code as it is written now when you say `diction[pa[0]] = pa[1:]` you're overwriting the value in `diction[pa[0]]` each time the key appears, which describes the behavior you're seeing. ``` with open("file.txt") as f: ...
51,876,794
I have a text file named `file.txt` with some numbers like the following : ``` 1 79 8.106E-08 2.052E-08 3.837E-08 1 80 -4.766E-09 9.003E-08 4.812E-07 1 90 4.914E-08 1.563E-07 5.193E-07 2 2 9.254E-07 5.166E-06 9.723E-06 2 3 1.366E-06 -5.184E-06 7.580E-06 2 4 2.966E-06 5.979E-07 9.702E-08 2 5 5.254E...
2018/08/16
[ "https://Stackoverflow.com/questions/51876794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8869818/" ]
Try this: ``` from collections import defaultdict diction = defaultdict(list) with open("file.txt") as f: for line in f: key, _, *values = line.strip().split() diction[key].extend(values) print(diction) ``` This is a solution for Python 3, because the statement `a, *b = tuple1` is invalid in P...
To do this in a very simple for loop: ``` with open('file.txt') as f: return_dict = {} for item_list in map(str.split, f): if item_list[0] not in return_dict: return_dict[item_list[0]] = [] return_dict[item_list[0]].extend(item_list[1:]) return return_dict ``` Or, if you wan...
59,745,214
I have 2 files to copy from a folder to another folder and these are my codes: ``` import shutil src = '/Users/cadellteng/Desktop/Program Booklet/' dst = '/Users/cadellteng/Desktop/Python/' file = ['AI+Product+Manager+Nanodegree+Program+Syllabus.pdf','Artificial+Intelligence+with+Python+Nanodegree+Syllabus+9-5.pdf'] ...
2020/01/15
[ "https://Stackoverflow.com/questions/59745214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3910616/" ]
Just use the below code since `i` doesn't need an extra indexing `file[...]`, because it is not an index: ``` for i in file: shutil.copyfile(src + i, dst + i) ``` If you want to use `range`, use it this way with `len`: ``` for i in range(len(file)): shutil.copyfile(src+file[i], dst+file[i]) ``` But of cou...
Try the code below, and read [for Statement in python](https://docs.python.org/3/tutorial/controlflow.html#for-statements) ``` import shutil src = '/Users/cadellteng/Desktop/Program Booklet/' dst = '/Users/cadellteng/Desktop/Python/' file = ['AI+Product+Manager+Nanodegree+Program+Syllabus.pdf','Artificial+Intelligenc...
64,578,491
The other version of this question wasn't ever answered, the original poster didn't give a full example of their code... I have a function that's meant to import a spreadsheet for formatting purposes. Now, the spreadsheet can come in two forms: 1. As a filename string (excel, .csv, etc) to be imported as a DataFrame ...
2020/10/28
[ "https://Stackoverflow.com/questions/64578491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2954167/" ]
So, one way is to just compare with a string and reading the dataframe in the else condition. The other way would be to use `isinstance` ```py In [21]: dict1 Out[21]: {'a': [1, 2, 3, 4], 'b': [2, 4, 6, 7], 'c': [2, 3, 4, 5]} In [24]: df = pd.DataFrame(dict1) In [28]: isinstance(df, pd.DataFrame) Out[28]: True In [3...
This line is the problem: ``` if type(spreadsheet) == pd.DataFrame: ``` The type of a dataframe is `pandas.core.frame.DataFrame`. [pandas.DataFrame is a class](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) which returns a dataframe when you call it. Either of these would work: ...
16,710,374
I am implementing a huge directed graph consisting of 100,000+ nodes. I am just beginning python so I only know of these two search algorithms. Which one would be more efficient if I wanted to find the shortest distance between any two nodes? Are there any other methods I'm not aware of that would be even better? Than...
2013/05/23
[ "https://Stackoverflow.com/questions/16710374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2155605/" ]
There are indeed several other alternatives to BFS and DFS. One that is quite adequate to computing shortest path is: <http://en.wikipedia.org/wiki/Dijkstra>'s\_algorithm Dijsktra's Algorithm is basically an adaptation of a BFS algorithm, and it's much more efficient than searching the entire graph, if your graph is ...
Take a look at the following two algorithms: 1. [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) - Single source shortest path 2. [Floyd-Warshall algorithm](http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm) - All pairs shortest path
16,710,374
I am implementing a huge directed graph consisting of 100,000+ nodes. I am just beginning python so I only know of these two search algorithms. Which one would be more efficient if I wanted to find the shortest distance between any two nodes? Are there any other methods I'm not aware of that would be even better? Than...
2013/05/23
[ "https://Stackoverflow.com/questions/16710374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2155605/" ]
There are indeed several other alternatives to BFS and DFS. One that is quite adequate to computing shortest path is: <http://en.wikipedia.org/wiki/Dijkstra>'s\_algorithm Dijsktra's Algorithm is basically an adaptation of a BFS algorithm, and it's much more efficient than searching the entire graph, if your graph is ...
If there are no weights for the edges on the graph, a simple Breadth-first search where you access nodes in the graph iteratively and check if any of the new nodes equals the destination-node can be done. If the edges have weights, DJikstra's algorithm and Bellman-Ford algoriths are things which you should be looking a...
16,710,374
I am implementing a huge directed graph consisting of 100,000+ nodes. I am just beginning python so I only know of these two search algorithms. Which one would be more efficient if I wanted to find the shortest distance between any two nodes? Are there any other methods I'm not aware of that would be even better? Than...
2013/05/23
[ "https://Stackoverflow.com/questions/16710374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2155605/" ]
There are indeed several other alternatives to BFS and DFS. One that is quite adequate to computing shortest path is: <http://en.wikipedia.org/wiki/Dijkstra>'s\_algorithm Dijsktra's Algorithm is basically an adaptation of a BFS algorithm, and it's much more efficient than searching the entire graph, if your graph is ...
When you want to find the shortest path you should use BFS and not DFS because BFS explores the closest nodes first so when you reach your goal you know for sure that you used the shortest path and you can stop searching. Whereas DFS explores one branch at a time so when you reach your goal you can't be sure that there...
16,710,374
I am implementing a huge directed graph consisting of 100,000+ nodes. I am just beginning python so I only know of these two search algorithms. Which one would be more efficient if I wanted to find the shortest distance between any two nodes? Are there any other methods I'm not aware of that would be even better? Than...
2013/05/23
[ "https://Stackoverflow.com/questions/16710374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2155605/" ]
Take a look at the following two algorithms: 1. [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) - Single source shortest path 2. [Floyd-Warshall algorithm](http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm) - All pairs shortest path
If there are no weights for the edges on the graph, a simple Breadth-first search where you access nodes in the graph iteratively and check if any of the new nodes equals the destination-node can be done. If the edges have weights, DJikstra's algorithm and Bellman-Ford algoriths are things which you should be looking a...
16,710,374
I am implementing a huge directed graph consisting of 100,000+ nodes. I am just beginning python so I only know of these two search algorithms. Which one would be more efficient if I wanted to find the shortest distance between any two nodes? Are there any other methods I'm not aware of that would be even better? Than...
2013/05/23
[ "https://Stackoverflow.com/questions/16710374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2155605/" ]
Take a look at the following two algorithms: 1. [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) - Single source shortest path 2. [Floyd-Warshall algorithm](http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm) - All pairs shortest path
When you want to find the shortest path you should use BFS and not DFS because BFS explores the closest nodes first so when you reach your goal you know for sure that you used the shortest path and you can stop searching. Whereas DFS explores one branch at a time so when you reach your goal you can't be sure that there...
44,408,625
I am writing a python wrapper for calling programs of the AMOS package (specifically for merging genome assemblies from different sources using good ol' minimus2 from AMOS). The scripts should be called like this when using the shell directly: ``` toAmos -s myinput.fasta -o testoutput.afg minimus2 testoutput -D REFCO...
2017/06/07
[ "https://Stackoverflow.com/questions/44408625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4685799/" ]
### answer Either do: ``` call("toAmos -s " + inputfile +" -o " + output_basename + ".afg") # single string ``` or do: ``` call(["toAmos", "-s", inputfile, "-o", output_basename + ".afg"]) # list of arguments ``` ### discussion In the case of your: ``` call(["toAmos", "-s " + inputfile, "-o " + output_basename...
`-s` and following input file name should be separate arguments to `call`, as they are in the command line: ``` call(["toAmos", "-s", inputfile, "-o", output_basename + ".afg"]) ```
46,460,218
im new in python and world of programming. get to the point. when i run this code and put input let say chicken, it will reply as two leg animal. but i cant get reply for two words things that has space in between like space monkey(althought it appear in my dictionary) so how do i solve it??? my dictionary: example.py...
2017/09/28
[ "https://Stackoverflow.com/questions/46460218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8681243/" ]
Try this in your code . ``` @Override protected String doInBackground(Void... params) { RequestHandler rh = new RequestHandler(); String s = rh.sendGetRequest(konfigurasi.URL_GET_ALL); return s; } @Override protected void onPostExecute(String s) { // edited here try { JSONObject jsonObje...
You need to Debug this issue why your toast is not showing: You have correctly put show Toast code in onPostExecute Now to debug , first put a Log to know the value of s , whether it is ever null or empty. If yes and still toast is not showing, move the dialog dismiss dialog before Toast and check. If Toast still d...
50,388,396
I try to compile this code but I get this errror : ``` NameError: name 'dtype' is not defined ``` Here is the python code : ``` # -*- coding: utf-8 -*- from __future__ import division import pandas as pd import numpy as np import re import missingno as msno from functools import partial import seaborn as sns sns....
2018/05/17
[ "https://Stackoverflow.com/questions/50388396", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9360453/" ]
As written by Amr Keleg, > > If `data` is a pandas dataframe then you can check the type of a > column as follows: > `df['colname'].dtype` or `df.colname.dtype` > > > In that case you need e.g. ``` df['colname'].dtype == np.dtype('datetime64') ``` or ``` df.colname.dtype == np.dtype('datetime64') ```
You should use `type` instead of `dtype`. `type` is a built-in function of python - <https://docs.python.org/3/library/functions.html#type> On the other hand, If `data` is a pandas dataframe then you can check the type of a column as follows: `df['colname'].dtype` or `df.colname.dtype`
50,388,396
I try to compile this code but I get this errror : ``` NameError: name 'dtype' is not defined ``` Here is the python code : ``` # -*- coding: utf-8 -*- from __future__ import division import pandas as pd import numpy as np import re import missingno as msno from functools import partial import seaborn as sns sns....
2018/05/17
[ "https://Stackoverflow.com/questions/50388396", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9360453/" ]
You should use `type` instead of `dtype`. `type` is a built-in function of python - <https://docs.python.org/3/library/functions.html#type> On the other hand, If `data` is a pandas dataframe then you can check the type of a column as follows: `df['colname'].dtype` or `df.colname.dtype`
I have just realized that I could have used: ``` from pandas.api.types import is_string_dtype, is_numeric_dtype ```