Re: Cult-like behaviour [was Re: Kindness]

2018-07-17 Thread Peter Otten
Marko Rauhamaa wrote: > The practical issue is how you refer to ASCII bytes. What I've resorted > to is: > > if nxt == b":"[0]: > ... You seem to have the compiler's blessing: >>> def f(c): ... return c == b":"[0] ... >>> import dis >>> dis.dis(f) 2 0 LOAD_FAST

Re: doubling the number of tests, but not taking twice as long

2018-07-17 Thread Peter Otten
Larry Martell wrote: > I had some code that did this: > > meas_regex = '_M\d+_' > meas_re = re.compile(meas_regex) > > if meas_re.search(filename): > stuff1() > else: > stuff2() > > I then had to change it to this: > > if meas_re.search(filename): > if 'MeasDisplay' in filename: >

Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread Peter Otten
D'Arcy Cain wrote: > On 2018-07-13 10:28 AM, Peter Otten wrote: >> As far as I can see -- without having access to a netbsd machine -- this > > Would it help if I gave you a login on one? Sorry, no. > Interestingly, I don't have this issue on my NetBSD machine bui

Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread Peter Otten
D'Arcy Cain wrote: > On 2018-07-13 08:05 AM, Peter Otten wrote: >> D'Arcy Cain wrote: >>> Nope. Both are 64 bit. >> >> Just to be 100% sure, what does >> >> $ python2.7 -c 'import struct; print(struct.calcsize("l"

Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-13 Thread Peter Otten
D'Arcy Cain wrote: > On 2018-07-12 07:41 PM, Peter Otten wrote: >> Wild guess: one Python is 64 bit and the other is 32 bit, and you have >> only one version of the library installed. > > Nope. Both are 64 bit. Just to be 100% sure, what does $ python2.

Re: Python 3.6 can find cairo libs but not Python 2.7

2018-07-12 Thread Peter Otten
D'Arcy Cain wrote: > $ python2.7 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > libcairo.so.2 > $ python3.6 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > None > > I have the 3.6 version of py-cairo installed. Any thoughts? > > NetBSD 7.1.2 Wild gu

Re: indexed assignment in list

2018-07-11 Thread Peter Otten
Peter Otten wrote: > a = [[1]] * 7 > > creates a list containing seven references to the same inner list [1]. I. e. it is roughly equivalent to b = [1] a = [b, b, b, b, b, b, b] -- https://mail.python.org/mailman/listinfo/python-list

Re: indexed assignment in list

2018-07-10 Thread Peter Otten
Abdur-Rahmaan Janhangeer wrote: > saw this snippet on the internet : why assigning by index propagates it > all? It doesn't. > a = [[1]] * 7 a > [[1], [1], [1], [1], [1], [1], [1]] > >>> a[0][0] = 2 a > [[2], [2], [2], [2], [2], [2], [2]] > > why not > > [[1], [2], [2], [2], [

Re: Dealing with dicts in doctest

2018-07-05 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: > >> On 05Jul2018 17:57, Steven D'Aprano >> wrote: >>>I have a function which returns a dict, and I want to use doctest to >>>ensure the documentation is correct. So I write a bunch of doctests: >>> >>>def func(a

Re: translating foreign data

2018-06-21 Thread Peter Otten
Ethan Furman wrote: > I need to translate numeric data in a string format into a binary format. > I know there are at least two different > methods of representing parts less that 1, such as "10.5" and "10,5". The > data is encoded using code pages, and can vary depending on the file being > rea

Re: write the values of an ordered dictionary into a file

2018-06-21 Thread Peter Otten
Ganesh Pal wrote: > Hi Team There is no team, just some random guys on the net. Sorry to disappoint you... > I need to write the values of an ordered dictionary into a file . All > values should be in a single row with a header list > > > > *Example:* > > > > *student = [("NAME", "John"),

Re: command line utility for cups

2018-06-20 Thread Peter Otten
Brian Oney via Python-list wrote: > Dear all, > > I am having trouble with argparse. I am trying to translate the following > line to a sleek python script: > > lpr -o media=legal -o sides=two-sided-long-edge filename > > Now where I am. > > import argparse > parser = argparse.ArgumentParser(d

Re: Speed of animation with matplotlib.animation

2018-06-19 Thread Peter Otten
ast wrote: > Le 19/06/2018 à 10:57, Peter Otten a écrit : >> ast wrote: >> >>> I noticed that the speed of animations made >>> with module matplotlib.animation always seems >>> wrong. >> >>> dt = 0.1 # 100 ms >> >&g

Re: Speed of animation with matplotlib.animation

2018-06-19 Thread Peter Otten
ast wrote: > I noticed that the speed of animations made > with module matplotlib.animation always seems > wrong. > dt = 0.1 # 100 ms > interval : number, optional > > Delay between frames in milliseconds. Defaults to 200. > > > What's wrong ? >From the above I would conclude that you

Folk etymology, was Re: Python list vs google group

2018-06-18 Thread Peter Otten
Grant Edwards wrote: > On 2018-06-18, Joe Pfeiffer wrote: >> Peter Otten <__pete...@web.de> writes: >> >>> Gene Heskett wrote: >>> >>>> This biggest single thing wrong with any of those old scsi interfaces >>>> is the bus's

Technical altitude, was Re: Python list vs google group

2018-06-18 Thread Peter Otten
Gene Heskett wrote: > On Monday 18 June 2018 09:16:10 Peter Otten wrote: > >> Gene Heskett wrote: >> > This biggest single thing wrong with any of those old scsi >> > interfaces is the bus's 5 volt isolation diode, the designer speced >> > a shotkey

Re: Python list vs google group

2018-06-18 Thread Peter Otten
Gene Heskett wrote: > This biggest single thing wrong with any of those old scsi interfaces is > the bus's 5 volt isolation diode, the designer speced a shotkey(sp) > diode, and some damned bean counter saw the price diff and changed it to Is this a case of

Re: Is it possible to call a class but without a new instance created?

2018-06-18 Thread Peter Otten
Jach Fong wrote: > Is it possible to call a class but without a new instance created? Yes, this is possible in Python, by writing a custom __new__ method. An extreme example: >>> class Three: ... def __new__(*args): return 3 ... >>> a = Three() >>> b = Three() >>> a 3 >>> b 3 >>> a is b Tr

Re: For specific keys , extract non empty values in a dictionary

2018-06-17 Thread Peter Otten
Dennis Lee Bieber wrote: > On Sun, 17 Jun 2018 17:37:25 +0100, MRAB > declaimed the following: > >>On 2018-06-17 15:47, Ganesh Pal wrote: >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not >>> {None} >>> >>> Thanks peter this looks better , except that I will need

Re: For specific keys , extract non empty values in a dictionary

2018-06-16 Thread Peter Otten
Ganesh Pal wrote: > *How do I check few specific/selected keys in a dictionary and extract > their values if they are not empty* You mean not None. > o_num = {'one': 1, > 'three': 3, > 'bar': None, > 'five' : 5, > 'rum' : None, > 'seven' : Non

Re: How to make a button flashing?

2018-06-13 Thread Peter Otten
huey.y.ji...@gmail.com wrote: > Hi All, > > I forgot the syntax of making a button flash, and failed to find an > example in the web. I use Tkinter, to create a button. Then made it > packed, and showed up. Now I am trying to make button b flashing, to make > it get better noticed. I checked the

Re: Question : Input after all prompts in python

2018-06-11 Thread Peter Otten
Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 02:14:26PM +0200, Peter Otten wrote: > >> >> print("1. Enter your name :") >> >> print("2. Enter your age :") >> >> print("3. Enter your gender :") >> >> name = in

Re: Question : Input after all prompts in python

2018-06-11 Thread Peter Otten
Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 11:16:39AM +, Steven D'Aprano wrote: > >> > I want to prompt 3 questions together and then get input for the first >> > question next to question as below. >> > >> > 1. Enter your name : _ >> > 2. Enter your age : >> > 3. Enter your gender : >

Re: Re: FULLSCREEN and DOUBLEBUF

2018-06-10 Thread Peter Otten
Paul St George wrote: > So... > > print pygame.display.get_surface() > gives > > > and > print screen.get_flags() > gives > -2147483648 > To recap: this thread started with a question. How do I know whether > DOUBLEBUF has been set with: > > screen = pygame.display.set_mode((720,480

Re: round

2018-06-07 Thread Peter Otten
ast wrote: > Hi > > round is supposed to provide an integer when > called without any precision argument. > > here is the doc: > > >>> help(round) > > round(number[, ndigits]) -> number > > Round a number to a given precision in decimal digits (default 0 digits). > This returns an int when c

Re: site package does not work

2018-06-06 Thread Peter Otten
Erik Martinson via Python-list wrote: > I am trying to dynamically add a site-package to a script that is run as a > cron job. The method adduseristepackages does not seem to do anything. The function addusersitepackages() seems to be un(der)documented; looking at the source it turns out that th

Re: Attachments

2018-06-05 Thread Peter Otten
Peter J. Holzer wrote: >> However, I did see that particular particular attachment, test.py in >> Jach's original post, and I'm reading c.l.py via gmane. > > comp.lang.python or gmane.comp.python.general? (I see the latter but not > the former on gmane, but I'm accessing it anonymously which migh

Re: tkinter (ttk) combobox dropdown text is white on white

2018-06-05 Thread Peter Otten
Jim Lee wrote: > Oops, I hit "reply" instead of "reply-list" last time. Trying again... > > > On 06/03/2018 02:01 PM, Christian Gollwitzer wrote: >> Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk >>> from tkinter import ttk >>> >>> root = tk.Tk() >>> cb = ttk.Combobox(root) >>> cb.

Re: Attachments

2018-06-04 Thread Peter Otten
Peter J. Holzer wrote: > On 2018-06-04 16:34:08 +, Peter Pearson wrote: >> On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer >> wrote: >> > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: >> >> (For good reasons, attachments are dropped when messages are >> >> distributed on the forum.) >> >

Re: Sorting and spaces.

2018-05-31 Thread Peter Otten
Tobiah wrote: > I had a case today where I needed to sort two string: > > ['Awards', 'Award Winners'] > > I consulted a few sources to get a suggestion as to > what would be correct. My first idea was to throw them > through a Linux command line sort: > > Awards > Award Winners > > Then I did

Re: Pink Floyd: is there anybody in here?

2018-05-30 Thread Peter Otten
Rob Gaddi wrote: > On 05/30/2018 09:34 AM, Paul Rubin wrote: >> I think Usenet posts are no longer getting forwarded to the mailing >> list, but now I wonder if this is getting out at all, even to usenet. >> >> Does anyone see it? >> > > Can't speak for the mailing list, but this came out to Us

Re: Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-29 Thread Peter Otten
Paul St George wrote: > This is very helpful indeed, thank you. Awe-inspiring. > > It occurred to me that I could edit the PIL/ImageShow.py, replacing ‘xv’ > (in five places) with the utility of my choice and using ‘executable’ as > the command. > > Or, is this just not done? No, this tends to

Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-26 Thread Peter Otten
Paul St George wrote: > Thank you. > You are very right. The show() method is intended for debugging purposes > and is useful for that, but what method should I be using and is PIL the > best imaging library for my purposes? I do not want to manipulate > images, I only want to show images (full sc

Re: List replication operator

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 25 May 2018 09:28:01 +0200, Peter Otten wrote: > >> Yet another arcanum to learn for beginners with little return. If you >> cannot refrain from tinkering with the language at least concentrate on >> the features with broad applica

Re: Enums: making a single enum

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote: > Am I silly for wanting to make a single enum? > > I have a three-state flag, True, False or Maybe. Is is confusing or bad > practice to make a single enum for the Maybe case? > > > from enum import Enum > class State(Enum): > Maybe = 2 > > Maybe = State.Maybe > del

Re: Computations on pandas dataframes

2018-05-26 Thread Peter Otten
junkaccoun...@outlook.com wrote: > Hi, > > Python newbie here. I need help with the following two tasks I need to > accomplish using Python: > > > > Creating a matrix of rolling variances > > I have a pandas data frame of six columns, I would like to iteratively > comp

Re: List replication operator

2018-05-25 Thread Peter Otten
Steven D'Aprano wrote: > But what do people think about proposing a new list replication with copy > operator? > > [[]]**5 > > would return a new list consisting of five shallow copies of the inner > list. Yet another arcanum to learn for beginners with little return. If you cannot refrain

Re: Getting Unicode decode error using lxml.iterparse

2018-05-23 Thread Peter Otten
digi...@gmail.com wrote: > I'm trying to read my iTunes library in Python using iterparse. My current > stub is: > parser.add_argument('infile', nargs='?', > type=argparse.FileType('r'), default=sys.stdin) > I'm getting an error on one part of the XML: > > > File "C:\Users\digit\Anaco

Re: Problem of writing long list of lists file to csv

2018-05-22 Thread Peter Otten
subhabangal...@gmail.com wrote: > lst2=lst1[:4] > with open("my_csv.csv","wb") as f: > writer = csv.writer(f) > writer.writerows(lst2) > > Here it is writing only the first four lists. Hint: look at the first line in the quotation above. -- https://mail.python.org/ma

Re: best way to remove leading zeros from a tuple like string

2018-05-21 Thread Peter Otten
bruceg113...@gmail.com wrote: > Looking over the responses, I modified my original code as follows: > s = "(128, 020, 008, 255, -1203,01,-000, -0123)" ",".join([str(int(i)) for i in s[1:-1].split(",")]) > '128,20,8,255,-1203,1,0,-123' I think this looks better with a generator inst

Re: best way to remove leading zeros from a tuple like string

2018-05-20 Thread Peter Otten
bruceg113...@gmail.com wrote: > Lets say I have the following tuple like string. > (128, 020, 008, 255) > > What is the best way to to remove leading zeroes and end up with the > following. > (128, 20, 8, 255)-- I do not care about spaces > > This is the solution I came up with >

Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-05-20 Thread Peter Otten
bellcanada...@gmail.com wrote: > On Thursday, 29 January 2009 12:09:29 UTC-5, Anjanesh Lekshminarayanan > wrote: >> > It does auto-detect it as cp1252- look at the files in the traceback >> > and you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the >> > wrong encoding, try opening it

Re: TypeError: expected string or Unicode object, NoneType found

2018-05-19 Thread Peter Otten
subhabangal...@gmail.com wrote: > I wrote a small piece of following code > > import nltk > from nltk.corpus.reader import TaggedCorpusReader > from nltk.tag import CRFTagger > def NE_TAGGER(): > reader = TaggedCorpusReader('/python27/', r'.*\.pos') > f1=reader.fileids() > print "The

Re: stock quotes off the web, py style

2018-05-16 Thread Peter Otten
Friedrich Rentsch wrote: > >>> ibm = urllib2.urlopen > ("https://api.iextrading.com/1.0/stock/IBM/quote";).read() > >>> ibm = eval (ibm) Dont do this. You are allowing the guys at iextrading.com to execute arbitrary code on your machine. Use ibm = json.loads(ibm) instead or import

Re: itemgetter with default arguments

2018-05-07 Thread Peter Otten
Antoon Pardon wrote: > On 05-05-18 09:33, Peter Otten wrote: >> I think you have established that there is no straight-forward way to >> write this as a lambda. But is adding a default to itemgetter the right >> conclusion? >> >> If there were an exception-c

Re: itemgetter with default arguments

2018-05-05 Thread Peter Otten
Steven D'Aprano wrote: > A re-occurring feature request is to add a default to itemgetter and > attrgetter. For example, we might say: > > from operator import itemgetter > f = itemgetter(1, 6, default="spam") # proposed feature > f("Hello World!") # returns ('e', 'W') > f("Hello") # re

Re: tkinter frame not expanding to fit window?

2018-04-17 Thread Peter Otten
Zobeid Zuma wrote: > I've just started working through the tutorial here → http:// > www.tkdocs.com/tutorial/firstexample.html and I already hit some behavior > that I don't understand. The frame doesn't expand when I resize the > window! The tutorial says these lines should do it: > > mainframe.

Re: specifying the same argument multiple times with argparse

2018-04-16 Thread Peter Otten
Larry Martell wrote: > Is there a way using argparse to be able to specify the same argument > multiple times and have them all go into the same list? action="append" > For example, I'd like to do this: > > script.py -foo bar -foo baz -foo blah > > and have the dest for foo have ['bar', 'baz

Re: Instance variables question

2018-04-16 Thread Peter Otten
Chris Angelico wrote: > On Tue, Apr 17, 2018 at 3:34 AM, Peter Otten <__pete...@web.de> wrote: >> Irv Kalb wrote: >> >>> I have been writing OOP code for many years in other languages and for >>> the >>> past few years in Python. I am writing new

Re: Instance variables question

2018-04-16 Thread Peter Otten
Irv Kalb wrote: > I have been writing OOP code for many years in other languages and for the > past few years in Python. I am writing new curriculum for a course on OOP > in Python. In order to see how others are explaining OOP concepts, I have > been reading as many books and watching as many v

Re: Python Idle not giving my prompt after If line

2018-04-09 Thread Peter Otten
brg...@gmail.com wrote: > On Monday, April 9, 2018 at 3:08:28 AM UTC-4, Peter Otten wrote: >> brg...@gmail.com wrote: >> >> > I typed the If part of an If/Else statement, but did not get a prompt >> > at the beginning of the next line when I hit return. Instea

Re: Python Idle not giving my prompt after If line

2018-04-09 Thread Peter Otten
brg...@gmail.com wrote: > I typed the If part of an If/Else statement, but did not get a prompt at > the beginning of the next line when I hit return. Instead, the cursor > lined up under the "p" of "print." Here is the line of text (it's part of > a longer bit of coding, I copied out of a textboo

Re: logging.FileHandler diff Py2 v Py3

2018-04-03 Thread Peter Otten
Paul Moore wrote: > On 3 April 2018 at 17:54, Peter Otten <__pete...@web.de> wrote: >> I think the culprit is io.open() rather than the logging module. Why does >> >>>>> io.open("/dev/stderr", "a") >> Traceback (most recent call last):

Re: logging.FileHandler diff Py2 v Py3

2018-04-03 Thread Peter Otten
Skip Montanaro wrote: > I've encountered a problem in an application I'm porting from Python > 2.7 to 3.6. The logginng.FileHandler class likes "/dev/stderr" as a > destination in Python 2, but complains in Python 3. > > Python 2.7.14: > import logging logging.FileHandler("/dev/stderr"

Re: check if bytes is all nulls

2018-04-01 Thread Peter Otten
Arkadiusz Bulski wrote: > Thanks, > timeit gives `not any(key)` same performance as `sum(key)==0`. Then you did not feed it the "right" data $ python3 -m timeit -s 'key = b"x" + bytes(10**6)' 'sum(key)' 100 loops, best of 3: 15.7 msec per loop $ python3 -m timeit -s 'key = b"x" + bytes(10**6)' '

Re: check if bytes is all nulls

2018-04-01 Thread Peter Otten
Arkadiusz Bulski wrote: > What would be the most performance efficient way of checking if a bytes is > all zeros? Currently its `key == b'\x00' * len(key)` however, because its > Python 2/3 compatible: > > sum(key) == 0 is invalid > key == bytes(len(key)) is invalid > > I already considered prec

Re: Curious case of UnboundLocalError

2018-03-31 Thread Peter Otten
Johannes Bauer wrote: > On 30.03.2018 13:25, Johannes Bauer wrote: > >>> This mention of collections refers to ... >>> } for (_, collections) in z.items(): >>> >>> ... this local variable. >> >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of "collect

Re: Accessing parent objects

2018-03-24 Thread Peter Otten
D'Arcy Cain wrote: > I'm not even sure how to describe what I am trying to do which perhaps > indicates that what I am trying to do is the wrong solution to my > problem in the first place but let me give it a shot. Look at the > following code. > > class C1(dict): > class C2(object): > de

Re: how to obtain the text for BeautifulSoup object

2018-03-20 Thread Peter Otten
Nathan Zhu wrote: > Hi Team, > > could anyone help me? > > for webpage having source code like this: > ... > > number > name > > > I only can use below sentence, since there are a lot of tag em and tag a > in other area. > output = > bs4.BeautifulSoup(res.content,'lxml').findAll("spa

Re: Keys in dict and keys not in dict

2018-03-19 Thread Peter Otten
Ben Finney wrote: > Chris Angelico writes: > >> Sounds like a set operation to me. >> >> expected = {"foo", "bar", "spam"} >> missing = expected - set(json) > > That works (because iterating a dict returns its keys). But it is less > immediately understandable, IMO, than this:: > > expecte

Re: List slicing on Python 2.7

2018-03-15 Thread Peter Otten
Ned Batchelder wrote: > On 3/15/18 9:57 AM, Vlastimil Brom wrote: >> 2018-03-15 12:54 GMT+01:00 Arkadiusz Bulski : >>> I have a custom class (a lazy list-like container) that needs to support >>> slicing. The __getitem__ checks if index is of slice type, and does a >>> list comprehension over indi

Re: LXML: can't register namespace

2018-03-09 Thread Peter Otten
Stefan Behnel wrote: > Andrew Z schrieb am 07.03.2018 um 05:03: >> Hello, >> with 3.6 and latest greatest lxml: >> >> from lxml import etree >> >> tree = etree.parse('Sample.xml') >> etree.register_namespace('','http://www.example.com') > > The default namespace prefix is spelled None (because

Re: Do not promote `None` as the first argument to `filter` in documentation.

2018-03-06 Thread Peter Otten
Chris Angelico wrote: > On Wed, Mar 7, 2018 at 2:12 AM, Kirill Balunov > wrote: >> >> >> 2018-03-06 17:55 GMT+03:00 Chris Angelico : >>> >>> On Wed, Mar 7, 2018 at 1:48 AM, Kirill Balunov >>> wrote: >>> > Note: For some historical reasons as the first argument you can use >>> > None instead of f

Layers of abstraction, was Re: RFC: Proposal: Deterministic Object Destruction

2018-03-06 Thread Peter Otten
Chris Angelico wrote: > On Tue, Mar 6, 2018 at 10:04 AM, Steven D'Aprano > wrote: >> # Later. >> if __name__ = '__main__': >> # Enter the Kingdom of Nouns. > > Don't you need a NounKingdomEnterer to do that for you? No, for some extra flexibility there should be a NounKingdomEntererFactory

Re: matrix multiplication

2018-02-27 Thread Peter Otten
Seb wrote: > On Tue, 27 Feb 2018 12:25:30 +1300, > Gregory Ewing wrote: > >> Seb wrote: >>> I was wondering is whether there's a faster way of multiplying each >>> row (1x3) of a matrix by another matrix (3x3), compared to looping >>> through the matrix row by row as shown in the code. > >> Jus

Re: Is there are good DRY fix for this painful design pattern?

2018-02-26 Thread Peter Otten
Steven D'Aprano wrote: > I have a class with a large number of parameters (about ten) assigned in > `__init__`. The class then has a number of methods which accept > *optional* arguments with the same names as the constructor/initialiser > parameters. If those arguments are None, the defaults are

Re: help me ?

2018-02-26 Thread Peter Otten
Christian Gollwitzer wrote: > Am 26.02.18 um 10:40 schrieb sotaro...@gmail.com: >> Define 2 lists. The first one must contain the integer values 1, 2 and 3 >> and the second one the string values a, b and c. Iterate through both >> lists to create another list that contains all the combinations of

Re: Writing some floats in a file in an efficient way

2018-02-21 Thread Peter Otten
ast wrote: > Is there a way to write a float with only 8 bytes ? If you want to write the values one-by-one convert them to bytes with struct.pack() and then write the result. To write many values at once use array.array.tofile() or numpy.array.tofile(). -- https://mail.python.org/mailman/l

Re: [Tkinter]Validation to multiple Entry widgets

2018-02-17 Thread Peter Otten
Beppe wrote: > I would validate values input, on key, in multiple Entry widgets create at > run time > > I wrote this snip but even if the entry are created and the callback work > well the relative value is missing > my_list = (2.14,18.3,76.4,2.38,0.425,2.68,1.09,382,8.59,0.495)

Re: What F strings should have been

2018-02-15 Thread Peter Otten
D'Arcy Cain wrote: > A recent post by Terry Jan Reedy got me thinking about formatting. I > like the new(ish) format method for strings and I see some value in F > strings but it only works well with locals. Anything more starts > getting messier than format() and it is supposed to be cleaner.

Re: New to Python and understanding problem

2018-01-29 Thread Peter Otten
Michelle Konzack wrote: > Hello *, > > because I am runing into problems with SOME python based programs, I the > this as opportunity to learn python (after ASM, C, BaSH, CP/M, COBOL, > JS, PHP and perl). > > > OK, I tried to install "blueman" (Bluetooth Manager) on my Debian 9.2 > (Stret

Re: Please help on print string that contains 'tab' and 'newline'

2018-01-28 Thread Peter Otten
Jason Qian via Python-list wrote: > HI > >I have a string that contains \r\n\t > >[Ljava.lang.Object; does not exist*\r\n\t*at >[com.livecluster.core.tasklet > > >I would like to print it as : > > [Ljava.lang.Object; does not exist > tat com.livecluster.core.tasklet > >

Re: How to diagnose this, fails on 3.6.3, works on 3.5.2?

2018-01-24 Thread Peter Otten
Chris Green wrote: > I have a fairly simple little python program to automate starting an > editor on a wiki page. It works fine on the system where I wrote it > (xubuntu 16.04, python 3 version 3.5.2) but it comes up with the > following error on a newer system (xubuntu 17.10, python 3 version >

xpath prob, was Re: Why is there no functional xml?

2018-01-24 Thread Peter Otten
Rustom Mody wrote: > With > # Read above xml with open('soap_response.xml') as f: inp = etree.parse(f) > # namespace dict nsd = {'soap': "http://schemas.xmlsoap.org/soap/envelope/";, 'locns': "http://example.com/"} > > The following behavior is observed — actual responses elided in

Re: Why is there no functional xml?

2018-01-24 Thread Peter Otten
Rustom Mody wrote: >> To generalize that to handle arbitrarily nested lists and namedtuples a >> bit more effort is needed, but I can't see where lxml.objectify could >> make that much easier. > > You really mean that?? > Well sure in the programming world and even more so in the python world > “

Re: Why is there no functional xml?

2018-01-23 Thread Peter Otten
Rustom Mody wrote: > On Sunday, January 21, 2018 at 4:51:34 PM UTC+5:30, Peter Otten wrote: >> Personally I'd probably avoid the extra layer and write a function that >> directly maps dataclasses or database records to xml using the >> conventional elementtree API.

Re: Why is there no functional xml?

2018-01-23 Thread Peter Otten
Rustom Mody wrote: > Its obviously easier in python to put optional/vararg parameters on the > right side rather than on the left of a parameter list. > But its not impossible to get it in the desired order — one just has to > 'hand-parse' the parameter list received as a *param > Thusly: > appoi

Re: Why is there no functional xml?

2018-01-21 Thread Peter Otten
Rustom Mody wrote: > Looking around for how to create (l)xml one sees typical tutorials like > this: > > https://www.blog.pythonlibrary.org/2013/04/30/python-101-intro-to-xml-parsing-with-elementtree/ > > > > Given the requirement to build up this xml: > > > 1181251680 >

Why does random.choice() reject sets? was Re: Speeding up the implementation of Stochastic Gradient Ascent in Python

2018-01-17 Thread Peter Otten
Chris Angelico wrote: > On Thu, Jan 18, 2018 at 6:28 AM, Ned Batchelder > wrote: >> You'll have to replace random.choice() with >> random.choice(list(...)), since you can't random.choice from a set. >> > > Side point: why can't you? You can random.sample from a set, I'm not sure this was a goo

Re: Can utf-8 encoded character contain a byte of TAB?

2018-01-15 Thread Peter Otten
Peng Yu wrote: > Can utf-8 encoded character contain a byte of TAB? Yes; ascii is a subset of utf8. Python 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> ascii = "".join(map(chr, range(128))) >>> uni = asci

Re: Why does pylint give this warning?

2018-01-14 Thread Peter Otten
breamore...@gmail.com wrote: > Why does pylint give this warning? No idea. > The warning is 'C0103:Method name "__len__" doesn't conform to > '_?_?[a-z][A-Za-z0-9]{1,30}$' pattern' but it doesn't complain about > __repr__ or __str__. If there is an explanation out in the wild my search > fu has

Re: Generating SVG from turtle graphics

2018-01-14 Thread Peter Otten
Steven D'Aprano wrote: > I'd like to draw something with turtle, then generate a SVG file from it. > > Is this possible? If this is a one-off job consider creating Postscript from the underlying Canvas: >>> import turtle >>> for i in range(12): ... turtle.forward(100) ... turtle.left(1

Re: Dunder variables

2018-01-09 Thread Peter Otten
Frank Millman wrote: > Hi all > > I have read that one should not call dunder methods in application code. > > Does the same apply to dunder variables? I am thinking of the instance > attribute __dict__, which allows access to the contents of the instance. > > I only want to read from __dict__,

Re: Where did csv.parser() go?

2018-01-02 Thread Peter Otten
ja...@apkudo.com wrote: > I need record the starting offsets of csv rows in a database for fast > seeking later. Unfortunately, using any csv.reader() (or DictReader) tries > to cache, which means: example_Data = "'data > 0123456789ABCDE > 1123456789ABCDE > 2123456789ABCDE > 3123456789ABCDE > ...

Re: CFG Python

2017-12-30 Thread Peter Otten
Ranya wrote: > Let's say I vreated my own CFG in python, How can I check now if a > sentence match this grammar (return true) or it doesn't match it (return > false and the wrong element in the grammar), How can I do this ? Remember, context free grammars may be fine, but context free questions

Re: __contains__ classmethod?

2017-12-18 Thread Peter Otten
Peter Otten wrote: > Tim Chase wrote: > >> Playing around, I had this (happens to be Py2, but gets the same >> result in Py3) code >> >> class X(object): >> ONE = "one" >> TWO = "two" >> _ALL = frozenset(v for k,v in loca

Re: __contains__ classmethod?

2017-12-18 Thread Peter Otten
Tim Chase wrote: > Playing around, I had this (happens to be Py2, but gets the same > result in Py3) code > > class X(object): > ONE = "one" > TWO = "two" > _ALL = frozenset(v for k,v in locals().items() if k.isupper()) > @classmethod > def __contains__(cls, v): > return v in cls._A

Re: argparse.ArgumentParser formatter_class argument

2017-12-17 Thread Peter Otten
Seb wrote: > As far as I can see it is currently impossible to apply more than one > class to an ArgumentParser. For example, I'd like to use both > RawDescriptionHelpFormatter *and* ArgumentDefaultsHelpFormatter in an > ArgumentParser, but it seems that's impossible, as one can only choose a > s

Re: Problem with timeit

2017-12-15 Thread Peter Otten
Thomas Jollans wrote: > On 2017-12-15 11:36, ast wrote: >> Hi >> >> Time measurment with module timeit seems to work with some statements >> but not with some other statements on my computer. >> >> Python version 3.6.3 >> >> from timeit import Timer >> > Timer("'-'.join([str(i) for i in ra

Re: [TKinter]How to set LabelFrames font and color from option file

2017-12-14 Thread Peter Otten
Beppe wrote: > Il giorno giovedì 14 dicembre 2017 15:18:31 UTC+1, Peter Otten ha scritto: >> Beppe wrote: >> >> > I don't succeed in planning the value of the font and color in the >> > LabelFrames using the option_db file, such as >> > >&

Re: [TKinter]How to set LabelFrames font and color from option file

2017-12-14 Thread Peter Otten
Beppe wrote: > I don't succeed in planning the value of the font and color in the > LabelFrames using the option_db file, such as > > *LabelFrame*font: Helvetica 14 > *LabelFrame*foreground: red > > exist a list of the keywordses to use? >>> import tkinter as tk >>> root = tk.Tk() >>> lf = tk.L

Re: Processing Game Help

2017-12-11 Thread Peter Otten
Chris Angelico wrote: > On Tue, Dec 12, 2017 at 5:46 AM, Peter Otten <__pete...@web.de> wrote: >> You can test for a collision and exit if an asteroid is close to a >> spaceship with >> >> for s in spaceship: >> for a in asteroid: >>

Re: Processing Game Help

2017-12-11 Thread Peter Otten
Lauren Porter wrote: > Hello all! I've been trying to create a game in Python Processing where a > spaceship moves horizontally in order to miss a collision with an > asteroid. I'm having difficulty making it so that the game quits when an > asteroid hits the spaceship, could anybody help? Here is

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Peter Otten
Ethan Furman wrote: > On 12/07/2017 10:53 AM, Peter Otten wrote: >> Ethan Furman wrote: >> >>> The simple answer is No, and all the answers agree on that point. >>> >>> It does beg the question of what an identity function is, though. >>> >

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Peter Otten
Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given: > > --> identity(1) > 1

Re: Python-list Digest, Vol 171, Issue 7

2017-12-06 Thread Peter Otten
Chris Angelico wrote: > On Thu, Dec 7, 2017 at 3:56 AM, Dennis Lee Bieber > wrote: >> Granted, the statistics module in newer Python releases makes the >> entire assignment trivial... >> >> ClgubaJva 3.5.3 (qrsnhyg, Wha 26 2017, 16:17:54) [ZFP i.1900 64 ovg >> (NZQ64)] ba jva32. > > Is t

Re: How to get the redirected URL only but not the actual content?

2017-12-02 Thread Peter Otten
Paul Moore wrote: > On 2 December 2017 at 03:32, Peng Yu wrote: >> Where is `?reload=true` from? How to just get the redict URL that one >> would get from the browser? Thanks. >> >>> 'http://ieeexplore.ieee.org:80/document/771073/?reload=true' > > The reload=true comes because > http://ieeexplor

Re: How to get the redirected URL only but not the actual content?

2017-12-01 Thread Peter Otten
Peng Yu wrote: > Hi, > > Does anybody know how only get the redirected URL but not the actual > content? > > I guess the request module probably should be used. But I am not sure > how to do it exactly. > > Can somebody show me the best way to request > (https://doi.org/10.1109/5.771073) and ge

Re: nospam ** infinity?

2017-11-28 Thread Peter Otten
Skip Montanaro wrote: >> I'm 99.5% certain it's not gate_news. > > A funny thing. All messages I have looked at so far with the "nospam" > thing have a Message-ID from binkp.net. (They are also all Usenet > posts.) For example: > > Newsgroups: comp.lang.python > Subject: Re: I have anaconda, but

Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-26 Thread nospam . nospam . Peter Otten
Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine.

<    1   2   3   4   5   6   7   8   9   10   >