Re: Two variants of class hierachy

2016-11-19 Thread Peter Otten
Victor Porton wrote: > I am developing software which shows hierarchical information (tree), > including issues and comments from BitBucket (comments are sub-nodes of > issues, thus it forms a tree). > > There are two kinds of objects in the hierarchy: a. with a (possibly long) > paginated list o

Re: Generic dictionary

2016-11-20 Thread Peter Otten
Thorsten Kampe wrote: > [Crossposted to tutor and general mailing list] > > Hi, > > I'd like to extend the dictionary class by creating a class that acts > like a dictionary if the class is instantiated with a dictionary and > acts like a "dictitem" ([(key1, value1), (key2, value2), ...]) if > i

Re: Clean way to return error codes

2016-11-21 Thread Peter Otten
Steven D'Aprano wrote: > I have a script that can be broken up into four subtasks. If any of those > subtasks fail, I wish to exit with a different exit code and error. > > Assume that the script is going to be run by system administrators who > know no Python and are terrified of tracebacks, and

Re: Numpy slow at vector cross product?

2016-11-21 Thread Peter Otten
Steve D'Aprano wrote: > On Mon, 21 Nov 2016 07:46 am, DFS wrote: > >> import sys, time, numpy as np >> loops=int(sys.argv[1]) >> >> x=np.array([1,2,3]) >> y=np.array([4,5,6]) >> start=time.clock() >> for i in range(loops): >> np.cross(x,y) >> print "Numpy, %s loops: %.2g seconds" %(loops,ti

Re: Setting the exit status from sys.excepthook

2016-11-21 Thread Peter Otten
Steven D'Aprano wrote: > I have script with an exception handler that takes care of writing the > traceback to syslog, and I set it as the global exceptionhook: > > sys.excepthook = my_error_handler > > > When my script raises, my_error_handler is called, as expected, and the > process exits wi

Re: Generic dictionary

2016-11-21 Thread Peter Otten
Thorsten Kampe wrote: >> def GenericDict(dict_or_items): >> if isinstance(dict_or_items, dict): >> return dict(dict_or_items) >> else: >> return SimpleGenericDictWithOnlyTheFalseBranchesImplemented( >> dict_or_items >> ) > > That would be a kind of fact

Re: MemoryError and Pickle

2016-11-21 Thread Peter Otten
Fillmore wrote: > Hi there, Python newbie here. > > I am working with large files. For this reason I figured that I would > capture the large input into a list and serialize it with pickle for > later (faster) usage. But is it really faster? If the pickle is, let's say, twice as large as the or

Re: Result is not Displayed

2016-11-22 Thread Peter Otten
prihantoro2...@gmail.com wrote: > Dear all, > > i am new to Python and have this problem > > = > import nltk > puzzle_letters = nltk.FreqDist('egivrvonl') > obligatory = 'r' > wordlist = nltk.corpus.words.words() > [w for w in wordlist if len(w) >= 6 > and obligatory in w > and nltk.FreqDist

Re: Is this pythonic?

2016-11-23 Thread Peter Otten
Frank Millman wrote: > Hi all > > Sometimes I write something that I think is quite clever, but later on I > look at it and ask 'What was I thinking?'. > > I have just come up with a 'clever' solution to a problem. Would this > cause raised eyebrows if you were reviewing this? > > I have a clas

Re: Can I print 2 calendars side by side?

2016-11-23 Thread Peter Otten
Dayton Jones wrote: > I'd like to be able to display 2 calendars side by side, instead of > stacked... is this possible? I'm too lazy to look around for a ready-to-use solution, so here's my own: $ cat side_by_side.py from itertools import zip_longest def zip_lines(*columns, sep=" "): colu

Re: generating list of files matching condition

2016-11-24 Thread Peter Otten
Seb wrote: > Hello, > > Given a list of files: > > In [81]: ec_files[0:10] > Out[81]: > > [u'EC_20160604002000.csv', > u'EC_2016060401.csv', > u'EC_20160604012000.csv', > u'EC_20160604014000.csv', > u'EC_2016060402.csv'] > > where the numbers are are a timestamp with format %Y%m%d%

Re: Help with two issues, buttons and second class object

2016-11-24 Thread Peter Otten
Thomas Grops via Python-list wrote: > Hi I have created some code, which moves a rectangle around and when it > hits the edge it picks a random new direction. It does this by the count > function within my class. I am wanting to create a button to randomly > change count but I my class seems to be

Re: generating list of files matching condition

2016-11-25 Thread Peter Otten
Seb wrote: > On Thu, 24 Nov 2016 10:18:21 +0100, > Peter Otten <__pete...@web.de> wrote: > >> Is win_files huge? Then it might help to avoid going over the entire >> list for every interval. Instead you can sort the list and then add to >> the current list wh

Re: Help with two issues, buttons and second class object

2016-11-25 Thread Peter Otten
Thomas Grops via Python-list wrote: > Peter, in your code what does that self.root = root mean in the __init__ > function of the class In your original script you used global variables to access the tkinter.Tk() object and the canvas. A simplified example: import tkinter class Tank:

Re: Help with two issues, buttons and second class object

2016-11-25 Thread Peter Otten
Thomas Grops via Python-list wrote: > Also I am struggling to understand: > >def move_tank(self, dx, dy): > self.x += dx > self.y += dy > self.canvas.move(self.id, dx, dy) > > Where does the dx and dy values get input? To find the place where the move_tank() method i

Re: correct way to catch exception with Python 'with' statement

2016-11-29 Thread Peter Otten
Marko Rauhamaa wrote: > However, I think the real answer is that you shouldn't mix the "with" > construct with exception handling. Instead you should write: > >try: >f = open("xyz") >except FileNotFoundError: >...[B]... >try: >...[A]... >finally: >f

Re: csv into multiple columns using split function using python

2016-11-30 Thread Peter Otten
handa...@gmail.com wrote: > I am trying to split a specific column of csv into multiple column and > then appending the split values at the end of each row. > > `enter code here` > > import csv > fOpen1=open('Meta_D1.txt') > > reader=csv.reader(fO

Re: async enumeration - possible?

2016-11-30 Thread Peter Otten
Steve D'Aprano wrote: > On Wed, 30 Nov 2016 07:07 am, Marko Rauhamaa wrote: > >> Terry Reedy : >> >>> On 11/29/2016 9:25 AM, Frank Millman wrote: >>> Is there any technical reason for this, or is it just that no-one has got around to writing an asynchronous version yet? >>> >>> Google'

Re: Merge Two List of Dict

2016-12-01 Thread Peter Otten
Nikhil Verma wrote: > Hey guys > > What is the most optimal and pythonic solution forthis situation > > A = [{'person_id': '1', 'adop_count': '2'}, {'person_id': '3', > 'adop_count': '4'}] > *len(A) might be above 10L* > > B = [{'person_id': '1', 'village_id': '3'}, {'person_id': '3', > 'villag

Re: Merge Two List of Dict

2016-12-01 Thread Peter Otten
Peter Otten wrote: > If the data stems from a database you can run (untested) > > select B.village_id, sum(A.adop_count) from A inner join B on A.person_id > = B.person_id; > Oops, I forgot the group-by clause: select B.village_id, sum(A.adop_count) from A inner join B

Re: Can json.dumps create multiple lines

2016-12-01 Thread Peter Otten
Cecil Westerhof wrote: > On Thursday 1 Dec 2016 22:52 CET, Cecil Westerhof wrote: > >> Now I need to convert the database. But that should not be a big >> problem. > > I did the conversion with: > cursor.execute('SELECT tipID FROM tips') > ids = cursor.fetchall() > for id in ids: >

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Peter Otten
Steven D'Aprano wrote: > Tell me Bart, what's the difference between these? > > # Linux > rm * > > and > > # Windows > del * Is there an equivalent to # touch -- -r on Windows? Like in $ tree . |-- -r |-- a | `-- b | `-- c | `-- bar.txt `-- foo.txt 3 directories, 3 files

Re: Get min and max dates

2016-12-08 Thread Peter Heitzer
' + min(dts2)[1] >print 'max: ' + max(dts2)[1] >==== >$python getminmax.py >min: 20-Aug-1997 >max: 07-Nov-2014 >which is correct, but I sense a more pythonic way, or a one-liner list >comprehension, is in there somewhere. I'd use strptime from the time module. Then you could write dts2.append(strptime(d,'%d-%b-%Y) min and max return a struct_time type that can easily converted to the original date format -- Dipl.-Inform(FH) Peter Heitzer, peter.heit...@rz.uni-regensburg.de -- https://mail.python.org/mailman/listinfo/python-list

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Peter Otten
Chris Angelico wrote: > On Fri, Dec 9, 2016 at 1:51 AM, Marco Buttu wrote: >> "if a particular name:object mapping cannot be found in the local >> namespaces, the namespaces of the enclosed scope are being searched next. >> If the search in the enclosed scope is unsuccessful, too, Python moves on

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Peter Otten
Chris Angelico wrote: > On Fri, Dec 9, 2016 at 5:03 AM, Peter Otten <__pete...@web.de> wrote: >>> The "usual optimization" is exactly what you describe: that different >>> bytecodes represent Local, Enclosing, and Global/Built-in scope >>> lookups.

Re: CLP stats: last 500 posts

2016-12-10 Thread Peter Otten
Wildman via Python-list wrote: > On Fri, 09 Dec 2016 16:07:16 -0500, DFS wrote: > >> code (py2.7) >> -- >> import sys as y,nntplib as t,datetime as d >> s='' >> g=y.argv[1] >> n=t.NNTP(s,119,'','') >> r,a,b,e,gn=n.group(g) >> def printSt

Re: Help in creating a dynamic/loop based on variables and CSV files

2016-12-11 Thread Peter Otten
Umar Yusuf wrote: > Hi all, > I need your help with any of these questions? > > 1- > http://stackoverflow.com/questions/41083699/python-create-dynamic-loop-based-on-variables-and-csv You should really make a serious attempt to explain the problem in plain english. Throwing a piece of code at ot

Re: IndexError: list index out of range

2016-12-13 Thread Peter Otten
Elnaz wrote: > hi > i am begginer in python. I have written a code and given this error: > IndexError: list index out of range > > In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block > and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7 bits > for 2 bits: 0

Re: Splitting text into lines

2016-12-13 Thread Peter Otten
George Trojan - NOAA Federal wrote: > I have files containing ASCII text with line s separated by '\r\r\n'. > but it looks cumbersome. I Python2.x I stripped '\r' before passing the > string to split(): > open('FTAK31_PANC_131140.1481629265635').read().replace('\r', '') > 'FTAK31 PANC 13114

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-14 Thread Peter Pearson
On Tue, 13 Dec 2016 19:06:45 -0600, Skip Montanaro wrote: > I know this isn't a Python-specific question, but [snip] > Yes, I know I can use C-[ or the Alt key instead of ESC. I know this isn't the sort of answer you wanted, but . . . Train your fingers to use C-[. I did, decades ago, because

[OT] "Invisible posts", was: Best attack order for groups of numbers trying to destroy each other, given a victory chance for number to number attack.

2016-12-15 Thread Peter Otten
skybuck2...@hotmail.com wrote: > I received a reply from somebody on my ISP newsserver. Apperently his > reply is not visible on google groups. I wonder why, maybe it's a banned > troll or something, but perhaps not. No, that's Dennis Lee Bieber who doesn't want his posts to be kept, and seems t

Re: Mapping with continguous ranges of keys

2016-12-15 Thread Peter Otten
Steve D'Aprano wrote: > I have some key:value data where the keys often are found in contiguous > ranges with identical values. For example: > > {1: "foo", > 2: "foo", > 3: "foo", > # same for keys 4 through 99 > 100: "foo", > 101: "bar", > 102: "bar", > 103: "foobar", > 104: "bar", > 10

Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-15 Thread Peter Pearson
On Wed, 14 Dec 2016 11:50:30 -0600, Skip Montanaro wrote: > On Wed, Dec 14, 2016 at 11:40 AM, Peter Pearson > wrote: >> Train your fingers to use C-[. > > As I recall, the location of the Ctrl key was one of the differences > between Sun and PC101 keyboards. Doesn't

Re: building numpy arrays with regular structure

2016-12-17 Thread Peter Otten
Seb wrote: > Is there an easier way to write a numpy array with a regular structure? > For example, an array with [0, 1] along the diagnal of one of the array > dimensions, and zero elsewhere: > > zz = np.array([[[0, 1], [0, 0], [0, 0]], >[[0, 0], [0, 1], [0, 0]], >

Re: Mapping with continguous ranges of keys

2016-12-17 Thread Peter Otten
Steve D'Aprano wrote: > I have experimented with two solutions, and hope somebody might be able to > suggest some improvements. Attached is the test code I ran, suggestions > for improving the performance will be appreciated. If there was an attachment to this text -- that didn't make it to the

Re: python list index - an easy question

2016-12-17 Thread Peter Otten
John wrote: > Hi, > >I am new to Python, and I believe it's an easy question. I know R and >Matlab. > > x=[1,2,3,4,5,6,7] x[0] > 1 x[1:5] > [2, 3, 4, 5] > * > > My question is: what does x[1:5] mean? By Python's convention, the > first ele

Re: read a table and make a basic plot

2016-12-19 Thread Peter Otten
metal.su...@gmail.com wrote: > Hi, I'm learning python and full of extensive tutorials around. Getting a > bit lost and overflowed in my head with tuples, dictionaries, lists, etc > ... etc... Everything great, but I'd like to perform some basic task while > learning the rest. For example, I'm hav

Re: read a table and make a basic plot

2016-12-19 Thread Peter Otten
Peter Otten wrote: > Here's a simple implementation that assumes both input and output file ... are in TAB-delimited text format. -- https://mail.python.org/mailman/listinfo/python-list

Re: windows utf8 & lxml

2016-12-21 Thread Peter Otten
Sayth Renshaw wrote: > On Tuesday, 20 December 2016 22:54:03 UTC+11, Sayth Renshaw wrote: >> Hi >> >> I have been trying to get a script to work on windows that works on mint. >> The key blocker has been utf8 errors, most of which I have solved. >> >> Now however the last error I am trying to o

Re: [OT] Security question

2016-12-22 Thread Peter Pearson
On Thu, 22 Dec 2016 12:10:40 +0200, Frank Millman wrote: [snip] > > What about the second part of my query? Is it acceptable that they keep > passwords on their system in clear text? Absolutely not. Keeping the passwords, even encrypted, is a reckless invitation to disaster. Chris has done a f

Re: data frame

2016-12-23 Thread Peter Otten
Val Krem via Python-list wrote: > Hi all, > > #!/usr/bin/env python > import sys > import csv > import numpy as np > import pandas as pd > > a= pd.read_csv("s1.csv") > print(a) > > size w1 h1 > 0 512 214 26 > 1 123 250 34 > 2 234 124 25 > 3 334 213 43 > 4 a45 223 3

Re: data frame

2016-12-23 Thread Peter Otten
Val Krem via Python-list wrote: > Here is the first few lines of the data > > > s1.csv > size,w1,h1 > 512,214,26 > 123,250,34 > 234,124,25 > 334,213,43 Did you put these lines here using copy and paste? The fix below depends on the assumption that your data is more like size, w1, h1 512, 214,

Re: I need a lot of help...

2016-12-24 Thread Peter Otten
raulmaqueda6...@gmail.com wrote: > I do not know how to do this exercise, does anyone help me? > > Define the matrix_range (m) function that returns the range of an array > calculated by the Gaussian method. > > It should work with any number of rows and columns. No punctuation will be > given t

Re: I need a lot of help...

2016-12-24 Thread Peter Pearson
On Sat, 24 Dec 2016 02:27:05 -0800 (PST), raulmaqueda6...@gmail.com wrote: > I do not know how to do this exercise, does anyone help me? > > Define the matrix_range (m) function that returns the range of an > array calculated by the Gaussian method. > > It should work with any number of rows and c

Re: I need a lot of help...

2016-12-25 Thread Peter Otten
Peter Otten wrote: > raulmaqueda6...@gmail.com wrote: > >> I do not know how to do this exercise, does anyone help me? >> >> Define the matrix_range (m) function that returns the range of an array >> calculated by the Gaussian method. >> >> It shoul

Re: encoding="utf8" ignored when parsing XML

2016-12-27 Thread Peter Otten
Skip Montanaro wrote: > I am trying to parse some XML which doesn't specify an encoding (Python > 2.7.12 via Anaconda on RH Linux), so it barfs when it encounters non-ASCII > data. No great surprise there, but I'm having trouble getting it to use > another encoding. First, I tried specifying the e

Re: encoding="utf8" ignored when parsing XML

2016-12-27 Thread Peter Otten
Skip Montanaro wrote: > Peter> Isn't UTF-8 the default? > > Apparently not. Sorry, I meant the default for XML. > I believe in my reading it said that it used whatever > locale.getpreferredencoding() returned. That's problematic when you > live in a country

Re: encoding="utf8" ignored when parsing XML

2016-12-27 Thread Peter Otten
Peter Otten wrote: > works, but to go back to the bytes that the XML parser needs the > "preferred encoding", in your case ASCII, will be used. Correction: it's probably sys.getdefaultencoding() rather than locale.getdefaultencoding(). So all systems with a sane configura

Re: ctypes, memory mapped files and context manager

2016-12-27 Thread Peter Otten
Hans-Peter Jansen wrote: > Hi, > > I'm using $subjects combination successfully in a project for > creating/iterating over huge binary files (> 5GB) with impressive > performance, while resource usage keeps pretty low, all with plain Python3 > code. Nice! > > E

Re: ctypes, memory mapped files and context manager

2016-12-28 Thread Peter Otten
Hans-Peter Jansen wrote: > Dear Peter, > > thanks for taking valuable time to look into my issue. You're welcome! > It might be related to my distinct silliness, but the problem persists > with your code as well. Unfortunately I posted the broken toy example rathe

Re: sorting strings numerically while dealing with missing values

2016-12-28 Thread Peter Otten
Larry Martell wrote: > I have a list containing a list of strings that I want to sort > numerically by one of the fields. I am doing this: > > sorted(rows, key=float(itemgetter(sortby))) > > Which works fine as long as all the sort keys convert to a float. No, that cannot work; unless you have

Re: ctypes, memory mapped files and context manager

2016-12-28 Thread Peter Otten
Hans-Peter Jansen wrote: > On Mittwoch, 28. Dezember 2016 13:48:48 Peter Otten wrote: >> Hans-Peter Jansen wrote: >> > Dear Peter, >> > >> > thanks for taking valuable time to look into my issue. >> >> You're welcome! >> >>

Re: ctypes, memory mapped files and context manager

2016-12-29 Thread Peter Otten
Hans-Peter Jansen wrote: > On Mittwoch, 28. Dezember 2016 16:53:53 Hans-Peter Jansen wrote: >> On Mittwoch, 28. Dezember 2016 15:17:22 Hans-Peter Jansen wrote: >> > On Mittwoch, 28. Dezember 2016 13:48:48 Peter Otten wrote: >> > > Hans-Peter Jan

Re: python3 - set '\n\n' as the terminator when writing a formatted LogRecord

2016-12-30 Thread Peter Otten
iMath wrote: > Is it possible to set '\n\n' as the terminator when writing a formatted > LogRecord to a stream by changing the format parameter of > logging.basicConfig? > > I know it is possible using the terminator attribute of StreamHandler > class to implement this, I just wonder Is it possib

Re: ctypes, memory mapped files and context manager

2016-12-30 Thread Peter Otten
eryk sun wrote: > On Thu, Dec 29, 2016 at 12:18 PM, Hans-Peter Jansen wrote: >>> >>> import weakref, ctypes >>> >>> T = ctypes.c_ubyte * 3 >>> >>> t = T() >>> >>> bytes(t) == b"\0" * 3 >>> >

Re: Cleaning up conditionals

2016-12-31 Thread Peter Otten
Deborah Swanson wrote: > Here I have a real mess, in my opinion: [corrected code:] > 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] > Anybody kn

RE: Cleaning up conditionals

2016-12-31 Thread Peter Otten
Deborah Swanson wrote: > Peter Otten wrote: >> Deborah Swanson wrote: >> >> > Here I have a real mess, in my opinion: >> >> [corrected code:] >> >> > if len(l1[st]) == 0: >> > if len(l2[st]) > 0: >>

Re: Unable to Debug

2017-01-02 Thread Peter Otten
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' >

Re: trouble with cmd.Cmd and prompting

2017-01-03 Thread Peter Otten
Cameron Simpson wrote: > 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

Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Peter Otten
Example: you are looking for the minimum absolute value in a series of integers. As soon as you encounter the first 0 it's unnecessary extra work to check the remaining values, but the builtin min() will continue. The solution is a minimum function that allows the user to specify a stop value:

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Jussi Piitulainen wrote: > Peter Otten writes: > >> Example: you are looking for the minimum absolute value in a series of >> integers. As soon as you encounter the first 0 it's unnecessary extra >> work to check the remaining values, but the builtin min() will cont

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Wolfgang Maier wrote: > On 1/6/2017 15:04, Peter Otten wrote: >> Example: you are looking for the minimum absolute value in a series of >> integers. As soon as you encounter the first 0 it's unnecessary extra >> work to check the remaining values, but the builtin min(

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Paul Rubin wrote: > Peter Otten <__pete...@web.de> writes: >> How would you implement stopmin()? > > Use itertools.takewhile I should have mentioned that I had already run into that -- let's call it -- off-by-one bug. -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Steve D'Aprano wrote: > On Sat, 7 Jan 2017 01:04 am, Peter Otten wrote: > >> Example: you are looking for the minimum absolute value in a series of >> integers. As soon as you encounter the first 0 it's unnecessary extra >> work to check the remaining values, b

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Peter Otten wrote: > Example: you are looking for the minimum absolute value in a series of > integers. As soon as you encounter the first 0 it's unnecessary extra work > to check the remaining values, but the builtin min() will continue. > > The solution is a minimum func

Re: python 3 dict: .keys(), .values(), and .item()

2017-01-07 Thread Peter Otten
Ethan Furman wrote: > In Python 2 we have: > >dict().keys() \ >dict().items() --> separate list() of the results >dict().values() / > > and > >dict().iter_keys() \ >dict().iter_items() --> integrated iter() of the results >dict().iter_values() / I guess you di

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
Deborah Swanson wrote: > to do that is with .fget(). Believe me, I tried every possible way to > use instance.A or instance[1] and no way could I get ls[instance.A]. Sorry, no. To get a list of namedtuple instances use: rows = csv.reader(infile) Record = namedtuple("Record", next(rows)) records

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Peter Otten
Paul Rubin wrote: > Paul Rubin writes: >> seems to work, but is ugly. Maybe there's something better. > > def minabs2(xs): > def z(): > for x in xs: > yield abs(x), x > if x==0: break > return min(z())[1] > > is the same thing but

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
Deborah Swanson wrote: > Peter Otten wrote, on January 08, 2017 3:01 AM >> >> Deborah Swanson wrote: >> >> > to do that is with .fget(). Believe me, I tried every > possible way > to >> > use instance.A or instance[1] and no way could I get ls[inst

Re: Help with this code

2017-01-09 Thread Peter Otten
José Manuel Suárez Sierra wrote: > Hello, Welcome! > I am trying to make a code wich compares between 2 or several > sequences (lists). It compares every element in a list with another list > elements. For example, if we have a list_a=["a","b","c","d"] and > list_b=["a","b"] I want to obtain a

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
Deborah Swanson wrote: > Even better, to get hold of all the records with the same Description as > the current row, compare them all, mark all but the different ones for > deletion, and then resume processing the records after the last one? When you look at all fields for deduplication anyway th

Re: Help with this code

2017-01-09 Thread Peter Otten
José Manuel Suárez Sierra wrote: > This is the traceback: > line 18, in > for transf2[j] in transf2: > IndexError: list assignment index out of range > > If I have initialized j=0 (such as i) why does it not work? A for loop for x in y: ... sequentually assigns every value in y to x. So wi

Re: Error message IDLE

2017-01-09 Thread Peter Otten
Gretchen Hasselbring wrote: > FYI > > Turns out I was saving my practice exercises as files (.py) under the > python directory which conflicted with the running of Idle. All cleared > up now. Thanks for the update. Can you tell which file you shadowed to cause the error? Perhaps even if the un

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-09 Thread Peter Otten
Antonio Caminero Garcia wrote: > On Friday, January 6, 2017 at 6:04:33 AM UTC-8, Peter Otten wrote: >> Example: you are looking for the minimum absolute value in a series of >> integers. As soon as you encounter the first 0 it's unnecessary extra >> work to check the

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
Rhodri James wrote: > On 09/01/17 21:40, Deborah Swanson wrote: >> Peter Otten wrote, on January 09, 2017 6:51 AM >>> >>> records = sorted( >>> set(records), >>> key=operator.attrgetter("Description") >>> ) >> >

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
breamore...@gmail.com wrote: > On Monday, January 9, 2017 at 5:34:12 PM UTC, Tim Chase wrote: >> On 2017-01-09 08:31, breamoreboy wrote: >> > On Monday, January 9, 2017 at 2:22:19 PM UTC, Tim Chase wrote: >> > > I usually wrap the iterable in something like >> > > >> > > def pairwise(it): >> >

Re: Enum with only a single member

2017-01-10 Thread Peter Otten
Steven D'Aprano wrote: > Is it silly to create an enumeration with only a single member? That is, a > singleton enum? > > from enum import Enum > > class Unique(Enum): > FOO = auto() > > > The reason I ask is that I have two functions that take an enum argument. > The first takes one of th

Re: Doubt with matrix

2017-01-12 Thread Peter Otten
José Manuel Suárez Sierra wrote: > Hello, I want to go over matrix indexs with this code: > def comparador2(a, b): > c3 = ["0"] # variables > x = -1 # contador de letras aniadidas a c3 > i = 0 # contador bucle secuencia a > j = 0 # contador bucle secuencia b > l1 = len(a)

Re: Find and append file path

2017-01-12 Thread Peter Otten
Tim Chase wrote: > def dir_iter(root): > for fullpath in ( > os.path.join(path, dir_) > for path, dirs, files in os.walk(root) > for dir_ in dirs > ): > if os.path.isdir(fullpath): > yield fullpath Why did you add an explicit

Re: matrix from matrix

2017-01-13 Thread Peter Otten
adnan.conne...@gmail.com wrote: > Hi all, > > I have just started python coding and have ran into my first brick wall. > Can some one please assist me with the following query ? > > I have two Matrices: > 1 – masterMatrix – A 2d matrix containing items in the rows and time as > the columns c

Re: Python Web Scrapping : Within href readonly those value that have href in it

2017-01-14 Thread Peter Otten
shahs...@gmail.com wrote: > I am trying to scrape a webpage just for learning. In that webpage there > are multiple "a" tags. consider the below code > > Something > > Something These are probaly all forward slashes. > Now i want to read only those href in which there is http. My Current co

Re: geopandas bug ?

2017-01-14 Thread Peter Otten
Xristos Xristoou wrote: > i want to create a simple spatial joing using geopandas but i thing so > geopandas has bug ? Have you tried the examples on ? Do they work? If yes, inspect your data, does it have the same format? > geopandas code : > > from geop

Re: geopandas bug ?

2017-01-14 Thread Peter Otten
Xristos Xristoou wrote: > Τη Σάββατο, 14 Ιανουαρίου 2017 - 3:43:10 μ.μ. UTC+2, ο χρήστης Peter Otten > έγραψε: >> Xristos Xristoou wrote: >> >> > i want to create a simple spatial joing using geopandas but i thing so >> > geopandas has bug ? >>

Re: geopandas bug ?

2017-01-14 Thread Peter Otten
Xristos Xristoou wrote: > Τη Σάββατο, 14 Ιανουαρίου 2017 - 4:30:48 μ.μ. UTC+2, ο χρήστης Peter Otten > έγραψε: >> Xristos Xristoou wrote: >> >> > Τη Σάββατο, 14 Ιανουαρίου 2017 - 3:43:10 μ.μ. UTC+2, ο χρήστης Peter >> > Otten έγραψε: >> >> Xristos

Re: geopandas bug ?

2017-01-14 Thread Peter Otten
Xristos Xristoou wrote: >> I suggest that you file a bug report. > > Mr.Peter Otten do you see my shapefiles ?have instersection 100 to 100 i > use instersection on QGIS ad work fine Yes, I downloaded the zipfile at > https://www.dropbox.com/s/2693nfi248z0y9q/files.zip?dl=0 with the and when I

Re: geopandas bug ?

2017-01-14 Thread Peter Otten
Xristos Xristoou wrote: > Τη Σάββατο, 14 Ιανουαρίου 2017 - 6:33:54 μ.μ. UTC+2, ο χρήστης Peter Otten > έγραψε: >> Xristos Xristoou wrote: >> >> >> I suggest that you file a bug report. >> > >> > Mr.Peter Otten do you see my shapefiles ?have inst

Sockets: IPPROTO_IP not supported

2017-01-15 Thread Peter Pearson
Trying to sniff Ethernet packets, I do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) but it results in this: $ sudo python3 sniff_survey.py Traceback (most recent call last): File "sniff_survey.py", line 118, in s = socket.socket(socket.A

Re: Error handling in context managers

2017-01-16 Thread Peter Otten
Israel Brewster wrote: > I generally use context managers for my SQL database connections, so I can > just write code like: > > with psql_cursor() as cursor: > > > And the context manager takes care of making a connection (or getting a > connection from a pool, more likely), and cleaning up

Re: Sockets: IPPROTO_IP not supported

2017-01-16 Thread Peter Pearson
On Mon, 16 Jan 2017 10:17:06 +, Joseph L. Casale wrote: >> Trying to sniff Ethernet packets, I do this: >> >>s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) >> >> but it results in this: >> >> $ sudo python3 sniff_survey.py >> Traceback (most recent call last)

Re: Error handling in context managers

2017-01-17 Thread Peter Otten
Gregory Ewing wrote: > Israel Brewster wrote: >> The problem is that, from time to time, I can't get a connection, the >> result being that cursor is None, > > That's your problem right there -- you want a better-behaved > version of psql_cursor(). > > def get_psql_cursor(): > c = psql_curso

Re: tokenize.untokenize adding line continuation characters

2017-01-17 Thread Peter Otten
Rotwang wrote: > Here's something odd I've found with the tokenize module: tokenizing 'if > x:\ny' and then untokenizing the result adds '\\\n' to the end. > Attempting to tokenize the result again fails because of the backslash > continuation with nothing other than a newline after it. On the

Re: trouble with cmd.Cmd and prompting

2017-01-18 Thread Peter Otten
Cameron Simpson wrote: > On 04Jan2017 12:20, Cameron Simpson wrote: >>I will try to get a minimal example others can run. > > Well I've made some time for this, and it seems to be an interaction with > my python3, the "input" builtin, and readline. Cmd.cmdloop behaves fine if > I turn off the .r

Re: sorting list python

2017-01-18 Thread Peter Otten
Smith wrote: > Hi all, > could you do better? > Thank you in advance > > link code: > https://repl.it/FMin/8 Don't make it unnecessarily hard to find your code -- as long as it's small you can include it into your mail Given > with open('partite.txt', 'r') as f: > splitted = [(int(line.spl

Re: How to create a socket.socket() object from a socket fd?

2017-01-21 Thread Peter Otten
Grant Edwards wrote: > Given a Unix file discriptor for an open TCP socket, I can't figure > out how to create a python 2.7 socket object like those returned by > socket.socket() > > Based on the docs, one might think that socket.fromfd() would do that > (since the docs say that's what it does):

Re: Is it possible to get the Physical memory address of a variable in python?

2017-01-23 Thread Peter Otten
Sourabh Kalal wrote: > how we can access the value from using id.. > like x=10 > id(x) > 3235346364 > > how i can read value 10 using id 3235346364 Use ctypes: $ python3 Python 3.4.3 (default, Nov 17 2016, 01:08:31) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more

Re: PhotoImage.paste

2017-01-24 Thread Peter Otten
rryan@gmail.com wrote: > I'm trying to build a tkinter GUI with python 3.5, and would like to > interactively adjust the color palette for an image by moving the mouse in > the canvas using PIL. In pseudo-code, I have something like > > palette=color_map(x,y) # x,y are scalars indicating t

Re: String Replacement

2017-01-24 Thread Peter Pearson
On Mon, 23 Jan 2017 13:23:38 -0800 (PST), subhabangal...@gmail.com wrote: > I have a string like > > "Trump is $ the president of USA % Obama was $ the president > of USA % Putin is $ the premier of Russia%" > > Here, I want to extract the portions from $...%, which would be > > "the president of

Re: Referencing section name by interpolation in ConfigParser

2017-01-25 Thread Peter Otten
Hans-Peter Jansen wrote: > I would like to use a interpolated section name, e.g.: > > [Section] > secref: %{section}s/whatever > > should result in: > >>>> config['Section']['secref'] > 'Section/whatever' > > Any idea a

Re: Hide text in entry box when i click on it.(GUI using Tkinter in python)

2017-01-25 Thread Peter Otten
hmmeeranrizv...@gmail.com wrote: > Hello Guys, > Here i am creating a entry box with some text,i need to hide the text when > i click on it. Here is my code > > from Tkinter import * > obj = Tk() > b = Entry(obj,width=100) > b.insert(0,"Enter the value to search") > b.pack() > mainloop() You nee

Re: configparser bug

2017-01-25 Thread Peter Otten
Christos Malliopoulos wrote: > Hi, > > I run Ubuntu 16.04 LTS in a VM using VMWare Workstation on a Windows 10 > host. > apt show python-configparser shows 3.3.0r2-2 > On python 2.7.12 I use the following code: > > import configparser as cfg > root = > u'/'.join(os.path.split(os.path.abspath('cf

<    8   9   10   11   12   13   14   15   16   17   >