Unable to Debug
I am new to python programming. I wrote a code to search for the product names on a page of snapdeal.com . Code: import urllib.request from bs4 import BeautifulSoup as BS url = 'https://www.snapdeal.com/products/electronics-headphones?sort=plrty' response = urllib.request.urlopen(url).read() soup = BS(response, 'html.parser') #for dataprice in soup.find_all('span', class_="lfloat product-price"): #print(dataprice) product_name={} i=0 for title in soup.find_all('p', class_="product-title"): product_name[i]=title.string i += 1 for i in range(1,21): print(product_name[i]) Output: Traceback (most recent call last): Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue Sony MDR-ZX110A Headphones Without Mic (White) Philips SBCHL140/98 Over Ear Headphone Without Mic File "C:/Users/Aritra Bhattacharjee/PycharmProjects/PythonWebModules/Web Scraper.py", line 17, in Intex Desire BT Over Ear Wired With Mic Headphone Black print(product_name[i]) JBL T450 On Ear Wired Headphones With Mic Black KeyError: 20 Motorola Pulse Max Over Ear Wired Headphones With Mic (Black) Philips SHB7250WT/00 Over Ear Wireless Headphones With Mic White Sony MDR-XB650BT On-Ear Extra Bass(XB) Headphones with Bluetooth & NFC (Black) Intex JAZZ Over Ear Wired With Mic Headphone Black Skullcandy S5GBW-J539 On Ear Wireless Headphones With Mic Black JBL C300SI Over Ear Wired Without Mic Headphone Black Zoook Rocker iFit Bluetooth Wireless Headphones With Mic Black Signature VM-46 Over Ear Wired Headphone Without Mic White Sony MDR-G45 Over Ear Wired Without Mic Headphone- Black Motorola Pulse Max Over Ear Wired Headphones With Mic (White) Bose SoundTrue Around-Ear Headphones with Mic (Navy Blue) for Samsung and Android Devices JBL T450 On Ear Wired Headphones With Mic Blue Motorola Pulse 2 Over Ear Wired Headphones With Mic (White) The Output shows some error that I could not understand why...Thanks in Advance -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to Debug
Aritra Bhattacharjee wrote: > I am new to python programming. I wrote a code to search for the product > names on a page of snapdeal.com . > > Code: > import urllib.request > from bs4 import BeautifulSoup as BS > > url = > 'https://www.snapdeal.com/products/electronics-headphones?sort=plrty' > > response = urllib.request.urlopen(url).read() > soup = BS(response, 'html.parser') > > #for dataprice in soup.find_all('span', class_="lfloat product-price"): > #print(dataprice) > product_name={} > i=0 > for title in soup.find_all('p', class_="product-title"): > product_name[i]=title.string > i += 1 > for i in range(1,21): > print(product_name[i]) > > > Output: > Traceback (most recent call last): > Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) > Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue > Sony MDR-ZX110A Headphones Without Mic (White) > Philips SBCHL140/98 Over Ear Headphone Without Mic > File "C:/Users/Aritra Bhattacharjee/PycharmProjects/PythonWebModules/Web > Scraper.py", line 17, in > Intex Desire BT Over Ear Wired With Mic Headphone Black > print(product_name[i]) > JBL T450 On Ear Wired Headphones With Mic Black > KeyError: 20 For the script above the output should end with the line above [snip] > The Output shows some error that I could not understand why...Thanks in > Advance You define a dict product_name and then successively add entries with > i=0 > for title in soup.find_all('p', class_="product-title"): > product_name[i]=title.string > i += 1 This means that the first key will be 0, the second will be 1, and so on up to 19. In the for loop you are looking for the keys 1 to 20, > for i in range(1,21): > print(product_name[i]) so the first match will not be printed, and when you ask for product_name[20] you will get the KeyError and the traceback. How to fix your code? You could rewrite the for loop as for i in range(len(product_name)): print(product_name[i]) which because of len() will work for pages that feature more or less than 20 products. If you plan to remove products from the dict you have to cope with missing indices. On way to do this is iterate to over the values alone: for name in product_name.values(): print(name) If you want to preserve the order on the html page you can iterate over the sorted key/value pairs: for i, name in sorted(product_name.items()): print(i, name) -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to Debug
Le 02/01/17 à 10:04, Aritra Bhattacharjee a écrit : I am new to python programming. I wrote a code to search for the product names on a page of snapdeal.com . Code: import urllib.request from bs4 import BeautifulSoup as BS url = 'https://www.snapdeal.com/products/electronics-headphones?sort=plrty' response = urllib.request.urlopen(url).read() soup = BS(response, 'html.parser') #for dataprice in soup.find_all('span', class_="lfloat product-price"): #print(dataprice) product_name={} i=0 for title in soup.find_all('p', class_="product-title"): product_name[i]=title.string i += 1 for i in range(1,21): print(product_name[i]) Output: Traceback (most recent call last): Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue Sony MDR-ZX110A Headphones Without Mic (White) Philips SBCHL140/98 Over Ear Headphone Without Mic File "C:/Users/Aritra Bhattacharjee/PycharmProjects/PythonWebModules/Web Scraper.py", line 17, in Intex Desire BT Over Ear Wired With Mic Headphone Black print(product_name[i]) JBL T450 On Ear Wired Headphones With Mic Black KeyError: 20 Motorola Pulse Max Over Ear Wired Headphones With Mic (Black) Philips SHB7250WT/00 Over Ear Wireless Headphones With Mic White Sony MDR-XB650BT On-Ear Extra Bass(XB) Headphones with Bluetooth & NFC (Black) Intex JAZZ Over Ear Wired With Mic Headphone Black Skullcandy S5GBW-J539 On Ear Wireless Headphones With Mic Black JBL C300SI Over Ear Wired Without Mic Headphone Black Zoook Rocker iFit Bluetooth Wireless Headphones With Mic Black Signature VM-46 Over Ear Wired Headphone Without Mic White Sony MDR-G45 Over Ear Wired Without Mic Headphone- Black Motorola Pulse Max Over Ear Wired Headphones With Mic (White) Bose SoundTrue Around-Ear Headphones with Mic (Navy Blue) for Samsung and Android Devices JBL T450 On Ear Wired Headphones With Mic Blue Motorola Pulse 2 Over Ear Wired Headphones With Mic (White) The Output shows some error that I could not understand why...Thanks in Advance Try with: for i in product_name: print(i) Vincent -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to Debug
On Monday, January 2, 2017 at 2:35:22 PM UTC+5:30, Aritra Bhattacharjee wrote: > I am new to python programming. I wrote a code to search for the product > names on a page of snapdeal.com . [RM]: Welcome and have fun. > for i in range(1,21): > print(product_name[i]) > > > Output: > Traceback (most recent call last): > Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) > Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue > Sony MDR-ZX110A Headphones Without Mic (White) > Philips SBCHL140/98 Over Ear Headphone Without Mic > File "C:/Users/Aritra Bhattacharjee/PycharmProjects/PythonWebModules/Web > Scraper.py", line 17, in > Intex Desire BT Over Ear Wired With Mic Headphone Black > print(product_name[i]) > JBL T450 On Ear Wired Headphones With Mic Black > KeyError: 20 . . . . . . . . > The Output shows some error that I could not understand why...Thanks in > Advance [RM]: You should read tracebacks stack from the bottom. Initially there will be hiccups but over a period of time you will learn. >From your code snippet: for loop is supplied with a range of 1 to 21 and while >the key value (variable, i) is 20, print fails there. In the previous loop, >where you are using methods in BeautifulSoup, are you sure that many items are >added to the list, product_name. If I were you, in the loop where the list is expanded by adding the product title names, will rename the variable, i, as 'product_counter'. And, in the last for loop, this counter can be used in the rangem like, (0, product_counter). All the best, /Ram -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to Debug
Hello Aritra, Your standard output and standard error are mixed (I don't know why), so error message is not immediate to read. It is: > Traceback (most recent call last): > File "C:/Users/Aritra Bhattacharjee/PycharmProjects/PythonWebModules/Web > Scraper.py", line 17, in > print(product_name[i]) > KeyError: 20 There no such `20` title in `product_name`, so we can deduce that `soup.find_all` found only 19 titles. You can to instead: product_name = [] # a list instead of a dict is enought for title in soup.find_all('p', class_="product-title"): product_name.append(title.string) # or this should work too: # product_name = list(soup.find_all('p', class_="product-title")) for title in product_name: # no need of i variable print(title) Quoting Aritra Bhattacharjee (2017-01-02 10:04:59) > I am new to python programming. I wrote a code to search for the product > names on a page of snapdeal.com . > > Code: > import urllib.request > from bs4 import BeautifulSoup as BS > > url = 'https://www.snapdeal.com/products/electronics-headphones?sort=plrty' > > response = urllib.request.urlopen(url).read() > soup = BS(response, 'html.parser') > > #for dataprice in soup.find_all('span', class_="lfloat product-price"): > #print(dataprice) > product_name={} > i=0 > for title in soup.find_all('p', class_="product-title"): > product_name[i]=title.string > i += 1 > for i in range(1,21): > print(product_name[i]) > > > Output: > Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) > Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue > Sony MDR-ZX110A Headphones Without Mic (White) > Philips SBCHL140/98 Over Ear Headphone Without Mic > Intex Desire BT Over Ear Wired With Mic Headphone Black > JBL T450 On Ear Wired Headphones With Mic Black > Motorola Pulse Max Over Ear Wired Headphones With Mic (Black) > Philips SHB7250WT/00 Over Ear Wireless Headphones With Mic White > Sony MDR-XB650BT On-Ear Extra Bass(XB) Headphones with Bluetooth & NFC (Black) > Intex JAZZ Over Ear Wired With Mic Headphone Black > Skullcandy S5GBW-J539 On Ear Wireless Headphones With Mic Black > JBL C300SI Over Ear Wired Without Mic Headphone Black > Zoook Rocker iFit Bluetooth Wireless Headphones With Mic Black > Signature VM-46 Over Ear Wired Headphone Without Mic White > Sony MDR-G45 Over Ear Wired Without Mic Headphone- Black > Motorola Pulse Max Over Ear Wired Headphones With Mic (White) > Bose SoundTrue Around-Ear Headphones with Mic (Navy Blue) for Samsung and > Android Devices > JBL T450 On Ear Wired Headphones With Mic Blue > Motorola Pulse 2 Over Ear Wired Headphones With Mic (White) > > > The Output shows some error that I could not understand why...Thanks in > Advance > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
RE: Unable to Debug
Aritra Bhattacharjee wrote, on January 02, 2017 1:05 AM: > I am new to python programming. I wrote a code to search for > the product names on a page of snapdeal.com . > > Code: > import urllib.request > from bs4 import BeautifulSoup as BS > > url = > 'https://www.snapdeal.com/products/electronics> -headphones?sort=plrty' > > response = urllib.request.urlopen(url).read() > soup = BS(response, 'html.parser') > > #for dataprice in soup.find_all('span', class_="lfloat > product-price"): > #print(dataprice) > product_name={} > i=0 > for title in soup.find_all('p', class_="product-title"): > product_name[i]=title.string > i += 1 > for i in range(1,21): > print(product_name[i]) > > > Output: > Traceback (most recent call last): > Motorola Pulse 2 Over Ear Wired Headphones With Mic (Black) > Bose SoundLink On-Ear Bluetooth Headphones - Black & Blue > Sony MDR-ZX110A Headphones Without Mic (White) Philips > SBCHL140/98 Over Ear Headphone Without Mic > File "C:/Users/Aritra > Bhattacharjee/PycharmProjects/PythonWebModules/Web > Scraper.py", line 17, in Intex Desire BT Over Ear > Wired With Mic Headphone Black > print(product_name[i]) > JBL T450 On Ear Wired Headphones With Mic Black > KeyError: 20 > Motorola Pulse Max Over Ear Wired Headphones With Mic (Black) > Philips SHB7250WT/00 Over Ear Wireless Headphones With Mic > White Sony MDR-XB650BT On-Ear Extra Bass(XB) Headphones with > Bluetooth & NFC (Black) Intex JAZZ Over Ear Wired With Mic > Headphone Black Skullcandy S5GBW-J539 On Ear Wireless > Headphones With Mic Black JBL C300SI Over Ear Wired Without > Mic Headphone Black Zoook Rocker iFit Bluetooth Wireless > Headphones With Mic Black Signature VM-46 Over Ear Wired > Headphone Without Mic White Sony MDR-G45 Over Ear Wired > Without Mic Headphone- Black Motorola Pulse Max Over Ear > Wired Headphones With Mic (White) Bose SoundTrue Around-Ear > Headphones with Mic (Navy Blue) for Samsung and Android > Devices JBL T450 On Ear Wired Headphones With Mic Blue > Motorola Pulse 2 Over Ear Wired Headphones With Mic (White) > > > The Output shows some error that I could not understand > why...Thanks in Advance This looks like Beautiful Soup. I've only used it once, and can just barely count it as a successful use. But what stands out to me is the "KeyError: 20", which closely follows after the "print(product_name[i])" statement. If product_name is a dictionary (and I see that it is), the key error says that none of product_name's keys has the value that was in 'i' when the error was thrown, ie. the key equal to 20 isn't in the dictionary. Frequently this occurs in a loop that continues beyond the length of the dictionary. The error was thrown in: for i in range(1,21): print(product_name[i]) so my guess is that you didn't have 20 keys in product_name, and the error was thrown when you tried to print product_name[20]. You could try just editting the loop so it only goes up to 20, since all the keys up to 20 were found (and range will stop the loop at one less than the given upper bound): for i in range(1,20): print(product_name[i]) although I wonder why it isn't: for i in range(0,19): print(product_name[i]) since the first item in the dictionary is index 0. Unless you don't want the first one to print for some reason. Hope this helps. D. -- https://mail.python.org/mailman/listinfo/python-list
Re: Cleaning up conditionals
Deborah Swanson writes: > Jussi Piitulainen wrote: [snip] >> With your particular conditions of non-emptiness, which is taken to >> be truth, you can achieve variations of this result with any of the >> following statements: >> >> w = ( l1[v] if len(l1[v]) > 0 else >> l2[v] if len(l2[v]) > 0 else >> l1[v] ) >> >> x = l1[v] if l1[v] else l2[v] if l2[v] else l1[v] >> >> y = l1[v] or l2[v] or l1[v] >> >> z = l1[v] or l2[v] >> >> The last one, which I originally suggested (and still prefer >> when otherwise appropriate), is subtly different from the >> others. That difference should be irrelevant. > > I agree, if the goal was to capture one of the field values in a > scalar value. To store into a list, specify a position in the list as the target. My idea here has been to simply do this to all the relevant positions in both lists, even when it means storing the old value back. See below, concretely, with your two examples and the mixed one from Dennis Lee Bieber, where I introduced a small difference of my own so that corresponding non-empty fields differ. I have made it output Python comments and inserted them at appropriate places. The same function, merge, fills the empty fields from the other list in all three cases using the method z from above. It does no harm when a field is already non-empty. def merge(l1, l2): fields = range(5) for v in fields: l1[v] = l1[v] or l2[v] l2[v] = l2[v] or l1[v] l1 = [ '2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d' ] l2 = [ '2 br, Elk Plains', '12-29', '', '', ''] print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') # Before: # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d'] # ['2 br, Elk Plains', '12-29', '', '', ''] # After: # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d'] # ['2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] l1 = [ '2 br, Elk Plains', '12-26', '', '', ''] l2 = [ '2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d' ] print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') # Before: # ['2 br, Elk Plains', '12-26', '', '', ''] # ['2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] # After: # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d'] # ['2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] l1 = [ '2 br, Elk Plains', '12-26', 'WA/pi', '', ''] l2 = [ '2 br, Elf Plains', '12-29', '', 'house', 'garage, w/d' ] print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') # Before: # ['2 br, Elk Plains', '12-26', 'WA/pi', '', ''] # ['2 br, Elf Plains', '12-29', '', 'house', 'garage, w/d'] # After: # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d'] # ['2 br, Elf Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] -- https://mail.python.org/mailman/listinfo/python-list
RE: Cleaning up conditionals
Jussi Piitulainen wrote, on January 02, 2017 1:44 AM > > Deborah Swanson writes: > > Jussi Piitulainen wrote: > > [snip] > > >> With your particular conditions of non-emptiness, which is > taken to > >> be truth, you can achieve variations of this result with > any of the > >> following statements: > >> > >> w = ( l1[v] if len(l1[v]) > 0 else > >> l2[v] if len(l2[v]) > 0 else > >> l1[v] ) > >> > >> x = l1[v] if l1[v] else l2[v] if l2[v] else l1[v] > >> > >> y = l1[v] or l2[v] or l1[v] > >> > >> z = l1[v] or l2[v] > >> > >> The last one, which I originally suggested (and still prefer > >> when otherwise appropriate), is subtly different from the > >> others. That difference should be irrelevant. > > > > I agree, if the goal was to capture one of the field values in a > > scalar value. > > To store into a list, specify a position in the list as the target. Aha. Now I see your plan. Pardon me, but the single letter variable you were assigning to, with no prior definition, seemed to me to be a scalar. I just couldn't see how that could work. But a list, specifically a list of the 2 rows with identical fields except for the date, makes perfect sense. > My idea here has been to simply do this to all the relevant > positions in both lists, even when it means storing the old > value back. Not a problem, since it's the same value. > See below, concretely, with your two examples and the mixed > one from Dennis Lee Bieber, where I introduced a small > difference of my own so that corresponding non-empty fields > differ. I have made it output Python comments and inserted > them at appropriate places. > > The same function, merge, fills the empty fields from the > other list in all three cases using the method z from above. > It does no harm when a field is already non-empty. > > def merge(l1, l2): > fields = range(5) > for v in fields: > l1[v] = l1[v] or l2[v] > l2[v] = l2[v] or l1[v] > > l1 = [ '2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, w/d' ] > l2 = [ '2 br, Elk Plains', '12-29', '', '', ''] > > print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') > merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') > > # Before: > # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, > w/d'] # ['2 br, Elk Plains', '12-29', '', '', ''] # After: # > ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, > w/d'] # ['2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] > > l1 = [ '2 br, Elk Plains', '12-26', '', '', ''] > l2 = [ '2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, w/d' ] > > print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') > merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') > > # Before: > # ['2 br, Elk Plains', '12-26', '', '', ''] > # ['2 br, Elk Plains', '12-29', 'WA/pi', 'house', 'garage, > w/d'] # After: # ['2 br, Elk Plains', '12-26', 'WA/pi', > 'house', 'garage, w/d'] # ['2 br, Elk Plains', '12-29', > 'WA/pi', 'house', 'garage, w/d'] > > l1 = [ '2 br, Elk Plains', '12-26', 'WA/pi', '', ''] > l2 = [ '2 br, Elf Plains', '12-29', '', 'house', 'garage, w/d' ] > > print('# Before:', l1, l2, sep = '\n# ', end = '\n# ') > merge(l1, l2) print('After:', l1, l2, sep = '\n# ', end = '\n\n') > > # Before: > # ['2 br, Elk Plains', '12-26', 'WA/pi', '', ''] > # ['2 br, Elf Plains', '12-29', '', 'house', 'garage, w/d'] > # After: > # ['2 br, Elk Plains', '12-26', 'WA/pi', 'house', 'garage, > w/d'] # ['2 br, Elf Plains', '12-29', 'WA/pi', 'house', 'garage, w/d'] Very clever, and exactly what I need to accomplish. Well, the first part of it anyway. My second test is if neither of two corresponding fields is empty and they're different, to dump which fields are different into a memo field, but perhaps that could be the first test and then use your merge for the ones that are identical except for the missing data. An example of what I mean is: l1 = [ '2 br, Elk Plains', '12-26', 'WA/pi',''] l2 = [ '2 br, Elf Plains', '12-29', 'OR/co','house', 'garage, w/d' ] which could happen if I didn't know that both Washington and Oregon have an Elk Plains. It would mean 2 functions, but if I can work in the logistics of dealing with all the duplicates (except for the date) in one throw, 2 functions would be worth it. And not a big deal even if I just stick to 2 rows at a time. In fact, just looking at the example I made up above, looks like it would be better to test for fields that are different first, and pass on merging the rows if any differences are found. They can always be merged in a later run after I reconcile the descrepancies. I'll mess around with it tomorrow, but I'll bet this works, and works better than what I have now. -- https://mail.python.org/mailman/listinfo/python-list
Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
Hello, I am having a hard time deciding what IDE or IDE-like code editor should I use. This can be overwhelming. So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, IntelliJ with Python plugin. The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, Pycharm) is that they look like a space craft dashboard and that unwarranted resources consumption and the unnecessary icons. I want my IDE to be minimalistic but powerful. My screen should be mostly “made of code” as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool and python oriented. The problem with Vim is the learning curve, so I know the very basic stuff, but obviously not enough for coding and I do not have time to learn it, it is a pity because there are awesome plugins that turns Vim into a lightweight powerful IDE-like. So now it is not an option but I will reconsider it in the future, learning little by little. Also, I am not very fan GUI guy if the task can be accomplished through the terminal. However, I don’t understand why people underrate GUIs, that said I normally use shortcuts for the most frequent tasks and when I have to do something that is not that frequent then I do it with the mouse, for the latter case in vim you would need to look for that specific command every time. Sublime is my current and preferred code editor. I installed Anaconda, Git integration and a couple of additional plugins that make sublime very powerful. Also, what I like about sublime compared to the full featured IDEs, besides the minimalism, is how you can perform code navigation back and forth so fast, I mean this is something that you can also do with the others but for some subjective reason I specifically love how sublime does it. The code completion in sublime I do not find it very intelligence, the SublimeCodeIntel is better than the one that Anaconda uses but the completions are not as verbose as in the IDEs. Now, I am thinking about giving a try to Visual Studio Code Edition (take a look, it sounds good https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). I need an editor for professional software development. What would you recommend to me? -- https://mail.python.org/mailman/listinfo/python-list
Re: Cleaning up conditionals
Op 31-12-16 om 01:26 schreef Deborah Swanson: >> On 31 December 2016 at 10:00, Deborah Swanson >> wrote: >>> Oops, indentation was messed up when I copied it into the email. >> The indentation of your latest message looks completely >> broken now, you can see it here: >> https://mail.python.org/pipermail/python-list/2016-December/71 > 7758.html > > Hm, I don't know what pipermail does with whitespace but the formatting > in the message at > https://mail.python.org/pipermail/python-list/2016-December/717758.html > is not the same as the message I sent from Outlook. > > Again, it should have been: > > if len(l1[st]) == 0: > if len(l2[st]) > 0: > l1[st] = l2[st] > elif len(l2[st]) == 0: > if len(l1[st]) > 0: > l2[st] = l1[st] I just would like to point out that you could just eliminate each sub-if and just write this as: if len(l1[st]) == 0: l1[st] = l2[st] elif len(l2[st]) == 0: l2[st] = l1[st] If we look at the first branch the eliminated test would prevent the assignment in case l2[st] is empty. But we already know l1[st] is empty. So we are just eliminating the replacement of an empty field with an empty field. There is no harm in that and trying to eliminate it just makes your test unnecessarily complex. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list
Re: Django broken pipe error
On Monday, December 12, 2016 at 6:38:39 PM UTC+1, justin walters wrote: > On Mon, Dec 12, 2016 at 7:27 AM, roma wrote: > > > Thanks Justin, > > > > I believe, the whole database story has no influence on the broken pipe > > error. I've commented out the whole block and leave only return line: > > return HttpResponse(res, content_type="text/plain; charset=utf-8") > > The error is still present. And I have no influence on that. > > > > I call python from js client: > > > > var newTrendReport = new App.TrendReport(); > > newTrendReport.set('search_phrase', search_phrase); > > newTrendReport.set('time_from', time_from); > > newTrendReport.set('time_to', time_to); > > newTrendReport.set('time_scale', time_scale); > > newTrendReport.set('category', category); > > newTrendReport.startExport( > > > > function(response){ > > console.log("Successfully calculated trend report."); > > App.trendPage = new App.TrendPageView(); > > App.trendPage.render(response); > > }, > > ); > > > > go throw: > > > > App.TrendReport = Backbone.Model.extend({ > > urlRoot: "/api/trend_reports/", > > defaults: { > > search_phrase: "", > > time_from: "", > > time_to: "", > > time_scale: "", > > category: "" > > }, > > > > startExportSuffix: "/export_report/", > > > > startExport: function( successCallback, errorCallback ) { > > console.log("start trend calculation"); > > var that = this; > > var ajaxUrl = this.startExportSuffix; > > var options = { > > method: "POST", > > data: this.attributes, > > contentType: "application/json;charset=UTF-8", > > dataType: "json", > > > > error: errorCallback, > > success: successCallback > > }; > > console.log("start trend export sync"); > > App.ajax(ajaxUrl, options); > > } > > > > }); > > > > and come in export_report method. > > > > My urls.py: > > > > url(r'^export_report', ensure_csrf_cookie(views.export_report), > > name="export_report"), > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > I'm not super familiar with the way backbone does http requests, but > something seems off about the startExport function. > It seems to me that you are sending a post request to "/export_report/" > which is an endpoint that I'm guessing is nested > in an include from "/api/trend_reports/". However, it looks like the error > you're getting above says you aren't sending > the request to "https://root.com/api/trend_reports/export_report/";. > Instead, you are sending the request to "https://root.com/export_report/"; . > Though, I'm also not sure that's the case because that would normally throw > a 404. > > I also noticed that you set content type to 'application/json' in your js, > but the view function returns a 'text/plain' content type. Is > There a reason for this? > > The data key in your js http function is set to the attributes variable > which, as far as I can tell, does not exist. > > There's a lot going on here, but I think you can probably narrow it down to > something in your backbone code or the way > backbone handles http requests as the error you are getting is caused by > the client prematurely closing the socket. > It's possible backbone will stop reading the response since it isn't the > same content-type as the request. Thanks a lot Justin, The problem was solved when I employed standard Framework methods for creation of new database object: in JS: var trendModel = new App.TrendModel(); trendModel.set("phrase", search_phrase); trendModel.set("from_time", time_from); trendModel.set(... trendModel.save(... in PY: def create(self, request): ... I've also created extra template and additional View. PageView for some unclear reason didn't support creation of new object - this event just disappeared. Regards, Roman -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
I'd recommend you be willing to put in the time and effort to learn the tools you want to use, if you want to do professional software development. Pick one, use it for a month (at least 100+ hours of hands on keyboard coding). Sublime, Vi are great for Python, since Python doesn't require as much as some other languages, but you sill need to put in the time to learn the tool. On Mon, Jan 2, 2017 at 6:38 AM, Antonio Caminero Garcia < tonycam...@gmail.com> wrote: > Hello, I am having a hard time deciding what IDE or IDE-like code editor > should I use. This can be overwhelming. > > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, > IntelliJ with Python plugin. > > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, > Pycharm) is that they look like a space craft dashboard and that > unwarranted resources consumption and the unnecessary icons. I want my IDE > to be minimalistic but powerful. My screen should be mostly “made of code” > as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool > and python oriented. > > The problem with Vim is the learning curve, so I know the very basic > stuff, but obviously not enough for coding and I do not have time to learn > it, it is a pity because there are awesome plugins that turns Vim into a > lightweight powerful IDE-like. So now it is not an option but I will > reconsider it in the future, learning little by little. Also, I am not very > fan GUI guy if the task can be accomplished through the terminal. However, > I don’t understand why people underrate GUIs, that said I normally use > shortcuts for the most frequent tasks and when I have to do something that > is not that frequent then I do it with the mouse, for the latter case in > vim you would need to look for that specific command every time. > > Sublime is my current and preferred code editor. I installed Anaconda, Git > integration and a couple of additional plugins that make sublime very > powerful. Also, what I like about sublime compared to the full featured > IDEs, besides the minimalism, is how you can perform code navigation back > and forth so fast, I mean this is something that you can also do with the > others but for some subjective reason I specifically love how sublime does > it. The code completion in sublime I do not find it very intelligence, the > SublimeCodeIntel is better than the one that Anaconda uses but the > completions are not as verbose as in the IDEs. > > Now, I am thinking about giving a try to Visual Studio Code Edition (take > a look, it sounds good https://marketplace.visualstudio.com/items? > itemName=donjayamanne.python). I need an editor for professional software > development. What would you recommend to me? > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On 01/02/2017 04:38 AM, Antonio Caminero Garcia wrote: > The problem with Vim is the learning curve, so I know the very basic > stuff, but obviously not enough for coding and I do not have time to > learn it, it is a pity because there are awesome plugins that turns > Vim into a lightweight powerful IDE-like. So now it is not an option > but I will reconsider it in the future, learning little by little. > Also, I am not very fan GUI guy if the task can be accomplished > through the terminal. However, I don’t understand why people > underrate GUIs, that said I normally use shortcuts for the most > frequent tasks and when I have to do something that is not that > frequent then I do it with the mouse, for the latter case in vim you > would need to look for that specific command every time. Really, the basic stuff is enough to be very productive in vim. In fact just knowing how to save and quit is half the battle! A little cheat sheet for vim by your keyboard would be plenty I think. If all you knew was how to change modes, insert, append, change word, yank, delete, and paste, that is 99% of what you'd use every day. You can use normal arrow keys, home, end, and page up and page down for cursor movement in vim, so even if you can't remember ^,$, gg, or GG, you'll do fine. Eventually you can begin to add in other things, like modifiers to c (change). There probably are a lot of nice plugins for ViM, but I use none of them. I just don't find them that useful. I don't seem to need any IDE help with Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Django broken pipe error
On Mon, Jan 2, 2017 at 6:14 AM, wrote: > > Thanks a lot Justin, > > The problem was solved when I employed standard Framework methods for > creation of new database object: > > in JS: > var trendModel = new App.TrendModel(); > trendModel.set("phrase", search_phrase); > trendModel.set("from_time", time_from); > trendModel.set(... > trendModel.save(... > > in PY: > def create(self, request): > ... > > I've also created extra template and additional View. PageView for some > unclear reason didn't support creation of new object - this event just > disappeared. > > Regards, > > Roman > -- > https://mail.python.org/mailman/listinfo/python-list > Glad to hear that you solved the problem! -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Mon, Jan 2, 2017 at 3:38 AM, Antonio Caminero Garcia < tonycam...@gmail.com> wrote: > Hello, I am having a hard time deciding what IDE or IDE-like code editor > should I use. This can be overwhelming. > > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, > IntelliJ with Python plugin. > > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, > Pycharm) is that they look like a space craft dashboard and that > unwarranted resources consumption and the unnecessary icons. I want my IDE > to be minimalistic but powerful. My screen should be mostly “made of code” > as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool > and python oriented. > > The problem with Vim is the learning curve, so I know the very basic > stuff, but obviously not enough for coding and I do not have time to learn > it, it is a pity because there are awesome plugins that turns Vim into a > lightweight powerful IDE-like. So now it is not an option but I will > reconsider it in the future, learning little by little. Also, I am not very > fan GUI guy if the task can be accomplished through the terminal. However, > I don’t understand why people underrate GUIs, that said I normally use > shortcuts for the most frequent tasks and when I have to do something that > is not that frequent then I do it with the mouse, for the latter case in > vim you would need to look for that specific command every time. > > Sublime is my current and preferred code editor. I installed Anaconda, Git > integration and a couple of additional plugins that make sublime very > powerful. Also, what I like about sublime compared to the full featured > IDEs, besides the minimalism, is how you can perform code navigation back > and forth so fast, I mean this is something that you can also do with the > others but for some subjective reason I specifically love how sublime does > it. The code completion in sublime I do not find it very intelligence, the > SublimeCodeIntel is better than the one that Anaconda uses but the > completions are not as verbose as in the IDEs. > > Now, I am thinking about giving a try to Visual Studio Code Edition (take > a look, it sounds good https://marketplace.visualstudio.com/items? > itemName=donjayamanne.python). I need an editor for professional software > development. What would you recommend to me? > -- > https://mail.python.org/mailman/listinfo/python-list > Have yo tried emacs? It's similar to Vim in that it relies very heavily on keyboard shortcuts and such. However, you may like the shortcuts a bit more or find them easier to learn. I side with Marc Brooks in that I believe you should definitely be willing to put in the time to learn an editor of your choice. Becoming an expert at using an editor will make you a lot more productive. Personally, I use Pycharm for most of my projects as I deal with large amounts of different files that can be thousands of lines long. All of the code completion and structure indexing really helps when you need to remember the structure of large applications. Pycharm's debugger integration is also totally awesome. I usually use the debugger to run my tests to get more informative tracebacks or to add breakpoints to failing tests. The git integration is very useful as well because I personally hate Git's CLI. For some small projects I'll use Atom as it gives me a sublime-esque interface without forcing me to use proprietary software. Otherwise I'll use nano for small, single file projects. Have you looked into ipython notebook? It's not exactly an IDE, but it does have built in code completion and makes' it really simple to document your code. -- https://mail.python.org/mailman/listinfo/python-list
Re: learning and experimenting python.
On Sun, 01 Jan 2017 23:02:34 -0800, einstein1410 wrote: > I really don't care the person like you. > Leave my posts, if don't like it. > Why wasting your as well as my time. > Just get lost man, or shut up. _ _ |_| |_| | | /^^^\ | | _| |_ (| "o" |) _| |_ _| | | | _(_---_)_ | | | |_ | | | | |' |_| |_| `| | | | | | | / \ | | \/ / /(. .)\ \ \/ \/ / / | . | \ \ \/ \ \/ /||Y||\ \/ / \__/ || || \__/ () () || || ooO Ooo -- GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On 2-1-2017 12:38, Antonio Caminero Garcia wrote: > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, > Pycharm) > is that they look like a space craft dashboard and that unwarranted resources > consumption and the unnecessary icons. I want my IDE to be minimalistic but > powerful. > My screen should be mostly “made of code” as usually happens in Vim, Sublime > or Atom. > However, Pycharm is really cool and python oriented. [...] > Sublime is my current and preferred code editor. If you like Sublime, and its minimalistic 'Distraction Free Mode', you'll be delighted to know that this exact same feature is in PyCharm as well. Select it (View->Enter distraction free mode), and gone is all the screen clutter and even the menu bar if you so desire. You can focus on just your code. And all of PyCharm's features are still there a mouse click or keyboard shortcut away. Irmen -- https://mail.python.org/mailman/listinfo/python-list
RE: Cleaning up conditionals
Dennis Lee Bieber wrote, on January 02, 2017 8:30 AM: > > On Sun, 1 Jan 2017 18:30:03 -0800, "Deborah Swanson" > declaimed the following: > > >Dennis Lee Bieber wrote, on Sunday, January 01, 2017 6:07 PM > >> > >> > >> l1 2 br, Elk Plains12-26 WA/pi > >> l2 2 br, Elk Plains12-29 > >>house garage, w/d > >> > > >Yes, that's exactly what I'm doing in this bit of code, > making all the > >listings that are identical except for the date be identical > except for > >the date. You may or may not have tried this approach to finding the > > Out of curiosity -- don't those listings have street > addresses? There must be lots of "2 br" units in the city. > > >ideal house, but this is my third house hunt, using essentially the > >same approach, but in a different language each time. > (Python is by far > >the best version. A dictionary with city names as keys, and several > >data items as values has literally cut the task in half.) > > > > Part of the hassle in your schema is that you are > treating the type of unit (2 br) AND the city (as shown in > your sample; I'd hope a full address is available) as a > single data field. Similarly, you have some obscure code > attached to the state. > > > Maybe I've spent too much time with having to optimize > data structures over the last 30 years, but for my view I'd > end up with a relational database (most Python distributions > include SQLite3, so you don't have to manage a full > client-server system [reminds me, I still need to recreate > MySQL on my system, after a drive failure and OS upgrade]). > Something like: > > create table Properties > ( > ID integer auto-increment primary key, > State char, > City char not null, > Address char not null, > Type char, > Code char, > unique (State, City, Address) > ) > > create table Listings > ( ID integer auto-increment primary key, > Property integer references Properties(ID), > Date datetime, > Notes varchar, > unique (Property, Date) > ) > > Since I don't know what your "code" (the "pi" above) > represents, I don't know if it should be in Properties or > Listings, nor if it is a constraint for uniqueness. Type is > "2 br". I put both in the Properties table as you had them > attached to the city and state sample data. I'd have > preferred to put a "not null" on State, but since that is one > of the fields your example allows to be blank (I presume on > the basis that a local town paper may assume the listing is > for said state)... > > The "unique" constraints mean that any combination of > "State, City, Address" only appears once, same for "Property, > Date" combination. > > This would be the master data, which you'd only perform > updates upon. > > For an update you would formulate a SELECT using the > fields you have for State, City, Address (so, if no State, > you'd select on just City, > Address) if multiple records are returned (only possible if > you are missing one of the three fields) you'd have to log > them as ambiguous with the new listing and needing to be hand > adjusted -- eg; you need to add the missing field by hand); > If a single record is returned you can perform an UPDATE for > Type/Code. If no record is returned you insert a new record > with the fields you have. > THEN, using the unique ID of the Properties record, you > INSERT a new listing record with the date and notes -- if the > insert is rejected (duplicate Property/Date) it indicates you > may have already processed that listing before. You can't > check for that until you've determined the ID of the Property itself. > > Determining if a property has multiple listings becomes a SELECT > > select p.State, p.City, p.Address, p.Type, p.Code, > count(l.ID) from Properties as p inner join Listings as l on > p.ID = l.Property group by p.ID order by p.State, p.City, p.Address > > > Yes, you might have to run periodic checks for missing > data fields when the field is allowed to be NULL and is part > of the uniqueness constraint. This would occur, for the > provided schema, if you had inserted a property with a null > State, and then later had a listing with the state provided > -- as the update/insert logic would come back that there is > no entry for (State, City, Address) -- it would not see the > (noState, City, Address) entry. If the State field were set > to "not null" you'd get an error at that time that could be > logged, allowing you to clean up the new data and reprocess > it -- instead of running a series of SELECT statements with > each one leaving out one of the "null allowed" fields > > select p.ID, p.State, p.City, p.Address > from Properties as p > order by p.City, p.Address > > to get all records with the same city/address (with some > work, and using subselects, the report c
Re: learning and experimenting python.
On Jan 2, 2017 10:57 AM, "Wildman via Python-list" wrote: On Sun, 01 Jan 2017 23:02:34 -0800, einstein1410 wrote: > I really don't care the person like you. > Leave my posts, if don't like it. > Why wasting your as well as my time. > Just get lost man, or shut up. [Obscene gesture trimmed] Way to deescalate. This is no more welcome than the post you're replying to. -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Mon, 2 Jan 2017 at 16:24 Michael Torrie wrote: > Really, the basic stuff is enough to be very productive in vim. In fact > just knowing how to save and quit is half the battle! A little cheat > sheet for vim by your keyboard would be plenty I think. If all you knew > was how to change modes, insert, append, change word, yank, delete, and > paste, that is 99% of what you'd use every day. You can use normal > arrow keys, home, end, and page up and page down for cursor movement in > vim, so even if you can't remember ^,$, gg, or GG, you'll do fine. > Eventually you can begin to add in other things, like modifiers to c > (change). > I second this. Make sure you've got all the nice Vim stuff enabled (set nocompatible, set mouse=a etc.). And if you're not comfortable to begin with using normal-mode commands, just stick with the mouse, arrow keys & insert mode. Once you get comfortable with that, perhaps set a target to learn one or two normal-mode commands a week and go from there. I found as soon as I'd learnt to use the direction commands & save I was already more productive in vim than Notepad++ for example, and I just got faster from there. > There probably are a lot of nice plugins for ViM, but I use none of > them. I just don't find them that useful. I don't seem to need any IDE > help with Python. > On the other hand I use bags of plugins. I particularly recommend Jedi if your computer is fast enough (it's a bit of a resource hog), and syntastic as a great way to integrate style checkers & linters into vim. -- -- Matt Wheeler http://funkyh.at -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On 02Jan2017 21:30, Matt Wheeler wrote: On Mon, 2 Jan 2017 at 16:24 Michael Torrie wrote: Really, the basic stuff is enough to be very productive in vim. In fact just knowing how to save and quit is half the battle! A little cheat sheet for vim by your keyboard would be plenty I think. [...] When I was learning vi I'd often spend a day learning a single keystroke. Not because they're hard, but because I wanted it in my typing muscle memory. This approach controlled the numberof new things I was trying to learn (roughly one thing at a time) while still steadily accumulating vi skills. [...] Once you get comfortable with that, perhaps set a target to learn one or two normal-mode commands a week and go from there. Indeed, like that! There probably are a lot of nice plugins for ViM, but I use none of them. I just don't find them that useful. I don't seem to need any IDE help with Python. On the other hand I use bags of plugins. I particularly recommend Jedi if your computer is fast enough (it's a bit of a resource hog), and syntastic as a great way to integrate style checkers & linters into vim. I've been a traditional vi die hard for too long. I moved to vim (as my default) some years ago for: utf-8 support, syntax colouring, filename completion. Recently I'm in a shiny new job with shinier newer people and am starting down the Dark Path of plugins. Presently I'm using ctrlp, which is a great way to open files in a deep/wide code tree, partiularly one which is still unfamiliar. I guess my point here is that, as with others, you don't need to be expert with a particular editor; once past the basics you will be productive and you can steadily accrue skill with it. Regarding IDEs, my environment is a shell terminal and a vim terminal and a browser for doco. Tiled windows (exactly how depends on your platform - I'm on a Mac at present and using Divvy to position windows). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Mon, Jan 2, 2017 at 9:38 AM, Antonio Caminero Garcia < tonycam...@gmail.com> wrote: > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, Pycharm) is that they look like a space craft dashboard and that unwarranted resources consumption and the unnecessary icons. I want my IDE to be minimalistic but powerful. My screen should be mostly “made of code” as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool and python oriented. I use Sublime Text for small scripts and PyCharm Professional for bigger projects and I don't find it resource heavy and the interface is simple enough. You can pretty much hide all menus and sidebars on PyCharm and you'd get pure code (it also has a "Distraction Free" mode), I suggest you to read Pycharm's official doc to know a little more about it. My advice is to NOT overthink it. IDEs and code editor are just tools, just pick one you like and you're done. -- https://mail.python.org/mailman/listinfo/python-list
RE: Cleaning up conditionals
Dennis Lee Bieber wrote on January 02, 2017 8:30 AM > > On Sun, 1 Jan 2017 18:30:03 -0800, "Deborah Swanson" > declaimed the following: > > Out of curiosity -- don't those listings have street > addresses? There must be lots of "2 br" units in the city. > > Part of the hassle in your schema is that you are > treating the type of unit (2 br) AND the city (as shown in > your sample; I'd hope a full address is available) as a > single data field. Similarly, you have some obscure code > attached to the state. haha - what schema? But seriously, I've loosely had one in mind all along, and there are currently 14 columns for each listing. I've just only mentioned the fields involved in the conditional problem I was having. One of those fields (br) is for bedrooms, and another couple I'll add later will be for address, phone, and local features, which may be pulled from my locations dictionary. The Descriptions I made up for my example are very simple short ones. Real webpage titles from Craigslist are frequently very long, complex and full of typos. I go fishing in them for most of the data, but I don't plan on making any effort to clean them up. I think it was you who asked another question that I didn't answer at the time, of why I used those weird 2-letter codes for the field names. It's rather stupidly simple. Since the "database" will be in flux for some time, with columns being moved around, added and deleted, I came up with this little scheme that executes right after the csv has been opened and read into ls[], to avoid having to change any of the subscripts in my code whenever the columns changed: flds = len(ls[0]) cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar = range(0,flds) ls[0] is the title row, so the range is automatically sized to the number of columns in the current csv. If I open a csv with more columns than last time, I hit an IndexError right off, which is a handy reminder if I've forgotten to update the field codes. I'd welcome anyone's improvement on this scheme, if it accomplishes the same result. Also, 'kind' is for the kind of property. I want a house, but I'd consider a cottage, trailer or manufactured home if it's nice and has a garage or a carport. And I want 2 bedrooms (one for my office), but I'm keeping track of 1 brs & even nice studio cabins, just in case I really need to get out of here and into something I can afford quickly. I've also tried to screen the plexes (duplex, triplex, six-plex and what all), apartments, condos and other undesirable "kinds" out of my searches, but they still slip into the results anyway. Craigslist's search function leaves much to be desired. So 'kind' also serves as a place to snag them for later deletion. And it's a red flag when one listing for a property comes up with 'kind' = 'house' and another comes up 'duplex'. For some reason people like to pretend their duplexes are houses, and sometimes they change their titles from duplex to house after they've had to relist it a couple of times. Or they don't say what kind of property it is, and I have to pull up the ad and look at it. Details, details, details. ;) D. -- https://mail.python.org/mailman/listinfo/python-list
Re: Cleaning up conditionals
Deborah Swanson wrote: flds = len(ls[0]) cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar = range(0,flds) You might like to consider converting the row into a namedtuple, then you could refer to the fields using attribute names instead of indexes. You could even use the header row to set up the field names in the namedtuple, so if you reorder the columns in the file, the code would automatically adapt. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Monday, January 2, 2017 at 8:24:29 AM UTC-8, Michael Torrie wrote: > On 01/02/2017 04:38 AM, Antonio Caminero Garcia wrote: > > The problem with Vim is the learning curve, so I know the very basic > > stuff, but obviously not enough for coding and I do not have time to > > learn it, it is a pity because there are awesome plugins that turns > > Vim into a lightweight powerful IDE-like. So now it is not an option > > but I will reconsider it in the future, learning little by little. > > Also, I am not very fan GUI guy if the task can be accomplished > > through the terminal. However, I don’t understand why people > > underrate GUIs, that said I normally use shortcuts for the most > > frequent tasks and when I have to do something that is not that > > frequent then I do it with the mouse, for the latter case in vim you > > would need to look for that specific command every time. > > Really, the basic stuff is enough to be very productive in vim. In fact > just knowing how to save and quit is half the battle! A little cheat > sheet for vim by your keyboard would be plenty I think. If all you knew > was how to change modes, insert, append, change word, yank, delete, and > paste, that is 99% of what you'd use every day. You can use normal > arrow keys, home, end, and page up and page down for cursor movement in > vim, so even if you can't remember ^,$, gg, or GG, you'll do fine. > Eventually you can begin to add in other things, like modifiers to c > (change). > > There probably are a lot of nice plugins for ViM, but I use none of > them. I just don't find them that useful. I don't seem to need any IDE > help with Python. yeah, for me I think of the IDE (and computers in general must be seen like that) as a coworker or as paring programming experience. So I agree I have been developing in Python without IDE a long time and I know if I had some features borrow from full featured IDEs will definitely help me out.I will give a try to Vim asap, now I am trying Visual Studio now and it seems that is all I want. -- https://mail.python.org/mailman/listinfo/python-list
RE: Cleaning up conditionals
Gregory Ewing wrote, on Monday, January 02, 2017 3:28 PM > > Deborah Swanson wrote: > > flds = len(ls[0]) > > cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar = > > range(0,flds) > > You might like to consider converting the row into a > namedtuple, then you could refer to the fields using > attribute names instead of indexes. > > You could even use the header row to set up the field > names in the namedtuple, so if you reorder the columns > in the file, the code would automatically adapt. > > -- > Greg I actually tried putting them into a list early on, but the problem was that it didn't do its main job, which is to help me avoid having to rewrite code everytime the columns change. Once you put the field names or codes into any kind of sequence, they can no longer be used as scalar indices without rewriting code to use their new indices in the tuple or list. Not really any kind of major improvement over counting out each one's position in the row. Unless you know of, and are suggesting, a way to index a sequence with strings instead of integers, so the code could remain untouched with string indices when changes to the columns are made. Certainly might be possible, I simply haven't and probably wouldn't have thought of it since what I have works and I've got tons of other stuff to do. So here's the new question: Is it possible to index a sequence with strings instead of integers? (Dictionaries excluded because dicts are not sequentially ordered in python 3.5 and earlier. Although, I've read that they will be in 3.6 or beyond.) Also, for such a scheme to be superior to what I already have, it needs to be very nearly self-maintaining. I only touch the 2nd of those two lines when I'm adding or deleting columns. -- https://mail.python.org/mailman/listinfo/python-list
trouble with cmd.Cmd and prompting
I'm using cmd.Cmd to write a little FTP-like command line to interface to a storage system of mine and encountering weird behaviour. When I enter a command the next prompt appears _before_ the associated operation runs, or so it appears. Look at this: [~/hg/css-venti(hg:venti)]fleet*> dev ./bin/vt -M -C - -S '[archive]' ftp ~/var/mnt/archive.vt stores = [] S = Store(MappingStore(ConfigWatcher('/Users/cameron/.vtrc')[archive])) ~/var/mnt/archive.vt:/> ls ~/var/mnt/archive.vt:/> precmd: line='ls' -- OnyX.dmg postcmd: stop=None, line='ls' See how the cmd.Cmd prompt "~/var/mnt/archive.vt:/> " appears again right after the "ls", and before its output: precmd: line='ls' -- OnyX.dmg postcmd: stop=None, line='ls' The precmd and postcmd lines are debugging, emitted from my precmd and postcmd methods in the subclass. Has anyone seen this kind of thing before? The salient parts of my class are shown below. It's not complete and I'm happy to post the full thing if people need to see it. The behaviour is the same regardless of the command; even an empty command shows it: ~/var/mnt/archive.vt:/> precmd: line='' postcmd: stop=None, line='' ~/var/mnt/archive.vt:/> precmd: line='' postcmd: stop=None, line='' Any insights or suggestions welcome. Code below. Cheers, Cameron Simpson from cmd import Cmd import readline class FTP(Cmd): def __init__(self, D, sep=None, FS=None, prompt=None): Cmd.__init__(self) self._prompt = prompt if sep is None: sep = '/' # NB: _not_ os.sep self.root = D self.cwd = D self.sep = sep self.fs = FS self._set_prompt() def _set_prompt(self): prompt = self._prompt pwd = '/' + self.op_pwd() self.prompt = ( pwd if prompt is None else ":".join( (prompt, pwd) ) ) + '> ' def precmd(self, line): X("precmd: line=%r", line) return line def postcmd(self, stop, line): X("postcmd: stop=%s, line=%r", stop, line) self._set_prompt() return stop def emptyline(self): pass def do_EOF(self, args): ''' Quit on end of input. ''' return True def do_quit(self, args): ''' Usage: quit ''' return True def do_ls(self, args): ''' Usage: ls [paths...] ''' argv = shlex.split(args) if not argv: argv = sorted(self.cwd.entries.keys()) for name in argv: with Pfx(name): E, P, tail = resolve(self.cwd, name) if tail: error("not found: unresolved path elements: %r", tail) else: M = E.meta S = M.stat() u, g, perms = M.unix_perms typemode = M.unix_typemode typechar = ( '-' if typemode == stat.S_IFREG else 'd' if typemode == stat.S_IFDIR else 's' if typemode == stat.S_IFLNK else '?' ) print("%s%s%s%s %s" % ( typechar, rwx((typemode>>6)&7), rwx((typemode>>3)&7), rwx((typemode)&7), name )) -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
* Antonio Caminero Garcia [170102 02:50]: <> > Now, I am thinking about giving a try to Visual Studio Code > Edition (take a look, it sounds good > https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). > I need an editor for professional software development. What would > you recommend to me? The best thing - as has been emphasised by others regarding this topic - is to establish tools, stick with them and learn them well. I use two approaches on linux: 1)From Gnome terminal I run MC (midnight commander) as my default file manager with vim (in terminal mode) as the MC default editor. This method is used for ad-hoc editing of python source code, but also for system editing in general. 2)I use emacs with elpy mode in GUI mode for large-scale work. Elpy is so helpful, I'm almost embarassed to admit being a pythonist. To compound the embarassment, the elpy developer is extremely helpful and very generous. :) -> I've used gvim (GUI mode) extensively in the past. I find vim more "nimble", thus my preferance for quick-and-dirty edits. Emacs, on the other hand, is enormously extendable and I have implemented extensive keymapping. For me, augmenting keymapping with the emacs help system trumps vim's more nimble approach. In addition, I've implemented an auxilary help system using emacs' built-in browser so that I can call up category - based "cheat-sheats" with simple html highlighting and hyperlinking. My caveat is that both vim and emacs are a tough learning curve. Vimscript extends vim, elisp extends emacs. In both cases, one is essentially learning an additional programming language. One's personal preference for input devices should also be considered, IMHO : I prefer the keyboard over pointing devices and a trackball over a mouse for pointing device. I use a small-footprint 68-key tenkeyless keyboard with a standalone keypad with my left hand (trackball is on the right). I've also programmed the keypad extensively for emacs. The bottom line, as others have stated, is to consistently stick with some approach that fits one's personal preferences. We are fortunate to have so many options. -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Mon, 2 Jan 2017 10:38 pm, Antonio Caminero Garcia wrote: > Hello, I am having a hard time deciding what IDE or IDE-like code editor > should I use. This can be overwhelming. Linux is my IDE. https://sanctum.geek.nz/arabesque/series/unix-as-ide/ I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional GUI-based editor. So my "IDE" is: - Firefox, for doing searches and looking up documentation; - an GUI programmer's editor, preferably one with a tab-based interface, such as geany or kate; - a tab-based terminal. Both geany and kate offer auto-completion based on previously seen words. They won't auto-complete function or method signatures, but in my my experience this is the "ninety percent" solution: word-based auto-complete provides 90% of the auto-complete functionality without the cost of full signature-based auto-complete. In the terminal, I have at least three tabs open: one open to the Python interactive interpreter, for testing code snippets and help(obj); one where I run my unit tests ("python -m unittest myproject_tests"); and one where I do any assorted other tasks, such as file management, checking code into the repo, etc. I've played with mypy a few times, but not used it seriously in any projects. If I did, I would run that from the command line too, like the unit tests. Likewise for any linters or equivalent. > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, > IntelliJ with Python plugin. > > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, > Pycharm) is that they look like a space craft dashboard and that > unwarranted resources consumption and the unnecessary icons. Indeed. If they provide any useful functionality I don't already have, I've never come across it. The only thing I'd like to try is an editor that offers semantic highlighting instead of syntax highlighting: https://medium.com/@evnbr/coding-in-color-3a6db2743a1e I once tried Spyder as an IDE, and found that it was so bloated and slow it couldn't even keep up with my typing. I'm not even a touch typist! I'd start to type a line like: except ValueError as err: and by the time my fingers were hitting the colon, Spyder was displaying `excep` in red flagged with an icon indicating a syntax error. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.4.6rc1 and Python 3.5.3rc1 are now available
On behalf of the Python development community and the Python 3.4 and Python 3.5 release teams, I'm pleased to announce the availability of Python 3.4.6rc1 and Python 3.5.6rc1. Python 3.4 is now in "security fixes only" mode. This is the final stage of support for Python 3.4. Python 3.4 now only receives security fixes, not bug fixes, and Python 3.4 releases are source code only--no more official binary installers will be produced. Python 3.5 is still in active "bug fix" mode. Python 3.5.3rc1 contains many incremental improvements over Python 3.5.2. Both these releases are "release candidates". They should not be considered the final releases, although the final releases should contain only minor differences. Python users are encouraged to test with these releases and report any problems they encounter. You can find Python 3.4.6rc1 here: https://www.python.org/downloads/release/python-346rc1/ And you can find Python 3.5.3rc1 here: https://www.python.org/downloads/release/python-353rc1/ Python 3.4.6 final and Python 3.5.3 final are both scheduled for release on January 16th, 2017. Happy New Year, //arry/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Cleaning up conditionals
Deborah Swanson wrote: Unless you know of, and are suggesting, a way to index a sequence with strings instead of integers, so the code could remain untouched with string indices when changes to the columns are made. I'm talking about this: https://docs.python.org/3/library/collections.html#collections.namedtuple It's like a tuple, but the fields also have names, so you can access them like attributes using dot-notation. Also, for such a scheme to be superior to what I already have, it needs to be very nearly self-maintaining. If you derive the attribute names from the header row, it would be extremely self-maintaining. You would be able to reorder columns without touching the code at all. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: learning and experimenting python.
On 01/02/2017 09:53 AM, Wildman via Python-list wrote: [rude ascii art omitted] That is a completely inappropriate response. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
On Monday, January 2, 2017 at 5:57:51 PM UTC-8, Steve D'Aprano wrote: > On Mon, 2 Jan 2017 10:38 pm, Antonio Caminero Garcia wrote: > > > Hello, I am having a hard time deciding what IDE or IDE-like code editor > > should I use. This can be overwhelming. > > Linux is my IDE. > > https://sanctum.geek.nz/arabesque/series/unix-as-ide/ > > > I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional > GUI-based editor. So my "IDE" is: > > - Firefox, for doing searches and looking up documentation; > > - an GUI programmer's editor, preferably one with a tab-based > interface, such as geany or kate; > > - a tab-based terminal. > > Both geany and kate offer auto-completion based on previously seen words. > They won't auto-complete function or method signatures, but in my my > experience this is the "ninety percent" solution: word-based auto-complete > provides 90% of the auto-complete functionality without the cost of full > signature-based auto-complete. > > In the terminal, I have at least three tabs open: one open to the Python > interactive interpreter, for testing code snippets and help(obj); one where > I run my unit tests ("python -m unittest myproject_tests"); and one where I > do any assorted other tasks, such as file management, checking code into > the repo, etc. > > I've played with mypy a few times, but not used it seriously in any > projects. If I did, I would run that from the command line too, like the > unit tests. Likewise for any linters or equivalent. > > > > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, > > IntelliJ with Python plugin. > > > > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, > > Pycharm) is that they look like a space craft dashboard and that > > unwarranted resources consumption and the unnecessary icons. > > Indeed. If they provide any useful functionality I don't already have, I've > never come across it. The only thing I'd like to try is an editor that > offers semantic highlighting instead of syntax highlighting: > > https://medium.com/@evnbr/coding-in-color-3a6db2743a1e > > I once tried Spyder as an IDE, and found that it was so bloated and slow it > couldn't even keep up with my typing. I'm not even a touch typist! I'd > start to type a line like: > > except ValueError as err: > > > and by the time my fingers were hitting the colon, Spyder was displaying > `excep` in red flagged with an icon indicating a syntax error. > > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. Thanks for remind the Unix capabilities as IDE, that post was cool to read. -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
Guys really thank you for your answers. Basically now I am more emphasizing in learning in depth a tool and get stick to it so I can get a fast workflow. Eventually I will learn Vim and its python developing setup, I know people who have been programming using Vim for almost 20 years and they did not need to change editor (that is really awesome). -- https://mail.python.org/mailman/listinfo/python-list
Re: learning and experimenting python.
On Tuesday, January 3, 2017 at 9:55:35 AM UTC+5:30, Ethan Furman wrote: > On 01/02/2017 09:53 AM, Wildman via Python-list wrote: > > [rude ascii art omitted] > > That is a completely inappropriate response. > > -- > ~Ethan~ Besides 1. Without fix-pitch the ASCII art is undecipherable. [I assume the person in question posted from google groups so most likely he sees it in proportional] 2. He seems to have deleted his posts from GG https://groups.google.com/forum/#!topic/comp.lang.python/KLdkUGOV5lU -- https://mail.python.org/mailman/listinfo/python-list
Re: trouble with cmd.Cmd and prompting
On 03Jan2017 00:14, Dennis Lee Bieber wrote: On Tue, 3 Jan 2017 11:33:15 +1100, Cameron Simpson declaimed the following: I'm using cmd.Cmd to write a little FTP-like command line to interface to a storage system of mine and encountering weird behaviour. When I enter a command the next prompt appears _before_ the associated operation runs, or so it appears. Has anyone seen this kind of thing before? Haven't used the module but there is something I find intriguing in the help system -=-=-=-=- Cmd.precmd(line) Hook method executed just before the command line is interpreted, but after the input prompt is generated and issued. -=-=-=-=- "... AFTER the input prompt is ... issued" I don't know, but that sure sounds to me like the cmd object tends to process one line behind... Though that behavior is not shown in the turtle example in the help system. Hmm. Interesting. I had read that text to imply (based on what I imagined _should_ happen) that the flow of control went: cmdloop: issue prompt> line=input() # or readline line=precmd(line) stop=onecmd(line) # which calls do_blah... stop=postcmd(stop,line) if stop: break but your reading of it suggests that this is possible: issue prompt> cmdloop: line=input() # or readline issue prompt> line=precmd(line) stop=onecmd(line) # which calls do_blah... stop=postcmd(stop,line) if stop: break The text for Cmd.cmdloop starts with this: Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. which argues for the former, and was what I naively expected. I guess I'd better dig out the source; I dislike going that far, not merely out of laziness, but also because the source is not the spec. Thanks for the suggestion, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
RE: Cleaning up conditionals
Gregory Ewing wrote, on January 02, 2017 7:58 PM > > Deborah Swanson wrote: > > Unless you know of, and are suggesting, a way to index a > sequence with > > strings instead of integers, so the code could remain > untouched with > > string indices when changes to the columns are made. > > I'm talking about this: > >https://docs.python.org/3/library/collections.html#collections.namedtup le >It's like a tuple, but the fields also have names, so >you can access them like attributes using dot-notation. > Also, for such a scheme to be superior to what I already have, it > needs to be very nearly self-maintaining. >If you derive the attribute names from the header row, >it would be extremely self-maintaining. You would be able >to reorder columns without touching the code at all. >-- >Greg I've never worked with collections before, and you're the second person on this thread to suggest using them. I'm very intrigued by both your use of collections and Peter Otten's. I think I'm right that core python sequences can't be indexed in any fashion by strings, because strings aren't iterable. I suppose it might be possible for strings to be iterable in some sort of ascii char code order, but that seems like it could get real whacky very fast, and not terribly useful. But a library of functions designed to augment core python certainly would be capable of many things. So I will be checking out collections and your suggested use of namedtuples very soon. I may not need to fix this part of my code, but I would like to learn a new way to do it. And it would be nice to replace the long string of 2-letter variables I currently have with a data structure. They're not really in the way, but they do clutter up the variable list in PyCharm. And using the header row titles as indices would automatically make my code a lot more readable. Thanks! ;) D. -- https://mail.python.org/mailman/listinfo/python-list