Re: curses, ncurses or something else

2018-07-24 Thread Peter Pearson
On Mon, 23 Jul 2018 23:24:18 +0100, John Pote wrote: > I recently wrote a command line app to take a stream of numbers, do some > signal processing on them and display the results on the console. There > may be several output columns of data so a title line is printed first. > But the stream of

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Peter Otten
Robin Becker wrote: > On 31/07/2018 09:16, Paul Moore wrote: >> On 31 July 2018 at 08:40, Robin Becker wrote: >>> A bitbucket user complains that python 3.6.6 with -Wall -b prints >>> warnings for some reportlab code; the >>> example boils down to the following >>> >>> ## >>> C:\code\hg-r

Re: unittest.TestCase.assertRaisesRegex throws DeprecationWarning

2018-07-31 Thread Peter Otten
Uri Even-Chen wrote: > Hi, > > We are using unittest.TestCase.assertRaisesRegex in our Django project > (Speedy Net / Speedy Match - https://github.com/urievenchen/speedy-net), > and I always prefer calling Python function parameters by name. So we call > self.assertRaisesRegex with parameters (k

Re: unittest.TestCase.assertRaisesRegex throws DeprecationWarning

2018-07-31 Thread Peter Otten
Uri Even-Chen wrote: > Do you know what is the problem and why I receive these deprecation > warnings? I poked around a bit and found https://bugs.python.org/issue24134 Perhaps you can make sense of it (I can't). -- https://mail.python.org/mailman/listinfo/python-list

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Peter Otten
Robin Becker wrote: > On 01/08/2018 09:52, Chris Angelico wrote: >> On Wed, Aug 1, 2018 at 6:36 PM, Robin Becker wrote: >>> On 31/07/2018 16:52, Chris Angelico wrote: >>.. >>> >>> it says explicitly that numeric keys will use numeric comparison, but no > . >>> >> >> Technically,

Re: Use a function arg in soup

2018-08-01 Thread Peter Otten
Sayth Renshaw wrote: > Hi. > > I want to use a function argument as an argument to a bs4 search for > attributes. > > I had this working not as a function ># noms = soup.findAll('nomination') > # nom_attrs = [] > # for attr in soup.nomination.attrs: > # nom_attrs.append(attr)

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Peter Otten
Paul Moore wrote: > On Wed, 1 Aug 2018 at 16:10, Robin Becker wrote: >> >> On 01/08/2018 14:38, Chris Angelico wrote: >> > t's a warning designed to help people port code from Py2 to Py3. It's >> > not meant to catch every possible comparison. Unless you are actually >> > porting Py2 code and are

Re: How do I create a variable where one index depends on the value of another index?

2018-08-07 Thread Peter Otten
giannis.dafnomi...@gmail.com wrote: > Hello guys. I'm having an issue with a Python PulP MILP problem. You can > find the simplified code that reproduces the problem here: > > from pulp import * > machines = 2 > I = range(machines) > positions = 2 > J = range(positions) > years = 10 > T = range(y

Re: How do I create a variable where one index depends on the value of another index?

2018-08-07 Thread Peter Otten
giannis.dafnomi...@gmail.com wrote: > Hey Peter. > > This worked like a charm! I can't believe I did not think of that, after > wasting so many hours on it. > > Thank you so much for the help! You can make these things easier to debug by breaking your code into small f

Re: Why this regex for string literals can't handle escaped quotes?.... '"(\\.|[^"])*"'

2018-08-09 Thread Peter Otten
cseber...@gmail.com wrote: > Why this regex for string literals > can't handle escaped quotes? '"(\\.|[^"])*"' > > See this... > string_re = '"(\\.|[^"])*"' > re.match(string_re, '""') > <_sre.SRE_Match object; span=(0, 6), match='""'> > re.match(string_re, '"aa\"aa"

Re: Import issue in python packages

2018-08-10 Thread Peter Otten
Venkatesh Adiga wrote: > Hi All, > > I am facing issue with python package import. > In my project, I have many directories with different python classes > defined within them. I am trying to import those classes in another python > program, but not able to import them. > Here are my directories

Re: Can't figure out how to do something using ctypes (and maybe struct?)

2018-08-11 Thread Peter Otten
inhahe wrote: > I need to make a list of instances of a Structure, then I need to make an > instance of another Structure, one of the fields of which needs to be an > arbitrary-length array of pointers to the instances in the list. How do I > do that? > > Just in case it helps, I'll include what

Re: Import issue in python packages

2018-08-11 Thread Peter Otten
Venkatesh Adiga wrote: > Thanks Peter... What are the ways to update outside of the python program > without defining environment variable for source code path Otherwise > can I do it once in during initialization of sys.path update? I don't understand the question. Yo

Re: Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread Peter Otten
wfgazd...@gmail.com wrote: > I have a main window open. Then I open a tk.TopLevel dialog window giving > the user multiple choices. He selects one, the corresponding event is > executed. Then in the underlining main window, just by chance there is > another button exactly under the mouse click

Re: Program to output a subset of the composite numbers

2018-08-15 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, 15 Aug 2018 05:34:06 -0700, tomusatov wrote: > >> I am not terribly familiar with Python, but am currently authoring an >> integer sequence for www.oeis.org and was wondering if anyone in the >> community could help me with authoring a Python program that outputs,

Re: Program to output a subset of the composite numbers

2018-08-15 Thread Peter Otten
tomusa...@gmail.com wrote: > Thank you very much! Do you also know how I might slightly alter to > composite numbers that are one less than twice a composite number? > > 15 would be the first number > Since 8 is composite then > > 2*8=16 > 16 - 1=15 Is composite Like >>> def is_composite(n): .

Re: Pylint false positives

2018-08-17 Thread Peter Otten
Chris Angelico wrote: > On Fri, Aug 17, 2018 at 9:49 PM, Jon Ribbens > wrote: >>> "Code running directly under the class" describes every use of the class >>> keyword (except those with an empty body). If you write: >>> >>> class Spam: >>> x = 1 >>> >>> you are running code under the

Re: Pylint false positives

2018-08-17 Thread Peter Otten
Frank Millman wrote: > I find that using a separate method per subclass does exactly what I want, > and that part of my project has been working stably for some time. I think that approach is fine. Do not let a tool have you bend over backwards. Do not give in to pylint's nagging when you are co

Re: ignoring some default fields from SimpleJsonFormatter

2018-08-21 Thread Peter Otten
shradha...@gmail.com wrote: > I am using for my logger > > handler.setFormatter(SimpleJsonFormatter(json.dumps)) Where does SimpleJsonFormatter come from? If it uses the json.dumps argument to serialize a dict you may pass a modified version instead: # untested KEYS_TO_IGNORE = {"fields", "yo

Re: Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-21 Thread Peter Otten
zljubi...@gmail.com wrote: > 1. saving json will result in unordered ini file. It could be solved by > using OrderedDict that will than with json.dumps be saved to file in the > same order as options are added to the ordered dict. dict-s are guaranteed to keep insertion order in Python 3.7, see

Re: zpifile.py error - no crc 32 attribute

2018-08-22 Thread Peter Pearson
On Wed, 22 Aug 2018 13:12:59 +0200, jacob m wrote: [snip] > That's my error: > "import zipfile > File "/home/lib/python3.7/lib/python3.7/zipfile.py", line 19, in > crc32 = zlib.crc32 > AttributeError: module 'zlib' has no attribute 'crc32' " > > I have no idea what to do with that :/ I

Re: Module not found

2018-08-27 Thread Peter Otten
Sharan Basappa wrote: > I am running a program that I got as reference from GitHub. > I am running on windows OS. > > Here is a snippet of the code (initial few lines). > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > __author__ = 'Shilin He' > > import sys > sys.path.insert(0, 'D:\Project

Re: How to sort over dictionaries

2018-08-29 Thread Peter Otten
har...@moonshots.co.in wrote: > On Wednesday, August 29, 2018 at 11:20:26 AM UTC+5:30, John Ladasky wrote: >> The top-level object you are showing is a list [], not a dictionary {}. >> It has dictionaries inside of it though. Do you want to sort the list? >> >> Python's sorted() function return

Re: How to sort over dictionaries

2018-08-29 Thread Peter Otten
har...@moonshots.co.in wrote: > sort = sorted(results, key=lambda res:itemgetter('date')) > print(sort) > > > I have tried the above code peter but it was showing error like > TypeError: '<' not supported between instances of 'operator.itemg

Re: Verifying the integrity/lineage of a file

2018-08-31 Thread Peter Pearson
On Fri, 31 Aug 2018 08:36:52 -0600, Malcolm Greene wrote: > I have use case where I need to distribute binary files to customers and > want to provide a way for our customers to verify the > "integrity/lineage" (I know there's a better description, but can't > think of it) of these files, eg. to g

Re: Verifying the integrity/lineage of a file

2018-09-01 Thread Peter Pearson
On Fri, 31 Aug 2018 12:51:58 -0600, Malcolm Greene wrote: > Thanks for the replies! I'm going to investigate the use of > python-gnupg which is a Python wrapper for the GPG command line > utility. This library is based on gpg.py written by Andrew Kuchling. > I'm all ears if f anyone has any altern

Re: Help Needed : script weird result.

2018-09-01 Thread Peter Pearson
On Sat, 1 Sep 2018 10:11:59 -0700 (PDT), moha...@gmail.com wrote: > All, > > I m trying to run this small script to find the lowest of the given > array of numbers. The script works fine for various combination of > inputs but fails in a weird way for a particular set of inputs, can > anyone point

Re: how to get a value from CSV specific cell (A7) thanks

2018-09-02 Thread Peter Otten
alon.naj...@gmail.com wrote: > how to get a value from CSV specific cell (A7) thanks $ cat csv_sheet.py #!/usr/bin/python3 import re import csv import string LOOKUP = {c: i for i, c in enumerate(string.ascii_uppercase, 1)} def a2i(s): """ >>> a2i("A") 0 >>> a2i("Z

Re: Pass a list of values as options to 3 dropdown menus

2018-09-04 Thread Peter Pearson
On Sun, 2 Sep 2018 13:40:18 -0700 (PDT), Nick Berg wrote: > how can i be able to store a list of values to drop-down menu and then > grab the value that the user selects? > > ** > name = month = year = '' > > # populate names, months, years > names.ad

Re: Pass a list of values as options to 3 dropdown menus

2018-09-04 Thread Peter Pearson
On Tue, 4 Sep 2018 10:13:07 -0700 (PDT), Nick Berg wrote: [snip] > > May i ask how you managed to send an email with a domain > nowhere.invalid ? I would like to do the same. I don't post by sending email, I post by using a news client (slrn), which interacts with the Usenet system (en.wikipedia.o

Re: Pass a list of values as options to 3 dropdown menus

2018-09-05 Thread Peter Pearson
On Sun, 2 Sep 2018 13:40:18 -0700 (PDT), Nick Berg wrote: > how can i be able to store a list of values to drop-down menu and then > grab the value that the user selects? > > ** > name = month = year = '' > > # populate names, months, years > names.ad

Re: I try to edit and find data from a text file with python 2.7 (data from stock market)

2018-09-07 Thread Peter Otten
alon.naj...@gmail.com wrote: > hi, > > I try to edit a text file with python 2.7: > > * AAPL * > Date: September 07 2018 > Time: 14:10:52 > Price: ,068,407 > Ask: None > High: None > Low: None > Previous Close: ,068,407 > Volume: $ 227.35 / $ 221.30 > Market Cap: 20.23 It looks like the

Re: perplexing error

2018-09-08 Thread Peter Otten
you edit a module after importing it the traceback may pick lines that caused the code raising the exception, but now contain something completely different. A little demo: >>> with open("tmp.py", "w") as f: f.write("def f():\n return 1/0\n") ... 21 >>&

Re: perplexing error

2018-09-08 Thread Peter Pearson
On 8 Sep 2018 17:25:52 GMT, Stefan Ram wrote: > Sharan Basappa writes: >> 66 # get the label for each log >> 67 data_df['label'] = (data_df['label'] != '-').astype(int) >>---> 68 #logger.debug("data frame %s \n", data_df) >> 69 logger.debug("\n") >>

Re: "glob.glob('weirdness')" Any thoughts?

2018-09-10 Thread Peter Otten
Max Zettlmeißl via Python-list wrote: >> glob('./Testfile [[]comment]*') >> > > That is about the least correct working solution one could conceive. > Of course your suggested "glob('./Testfile [[]comment]*')" works in > the positive case, but pretty much comes down to a glob('./Testfile > [[]*')

Re: perplexing error

2018-09-10 Thread Peter Pearson
On 8 Sep 2018 19:10:09 GMT, Stefan Ram wrote: > Peter Pearson writes: >>On 8 Sep 2018 17:25:52 GMT, Stefan Ram wrote: >>>In such cases, I do: >>>print( 'at position 1' ) >>This approach is especially valuable when it turns out that >>the f

Re: logging module - how to include method's class name when using %(funcName)

2018-09-11 Thread Peter Otten
Malcolm Greene wrote: > I'm using the Python logging module and looking for a way to include a > method's class name when using %(funcName). Is this possible? When you > have several related classes, just getting the function (method) name is > not enough information to provide context on the code

Re: Python Probability

2018-09-11 Thread Peter Pearson
On Tue, 11 Sep 2018 20:54:23 +0200 (CEST), Bat erdene endzis wrote: [snip] > def dice(): > attacker_dice=[random.randint(1,6) for _ in range(3)] > defender_dice=[random.randint(1,6) for _ in range(2)] > a=max(attacker_dice) > b=max(defender_dice) > for i in range(1000): >

Re: GUI, Python2.7- how to build a loop with a button + textbox

2018-09-12 Thread Peter Pearson
On Tue, 11 Sep 2018 19:51:01 -0700 (PDT), alon.naj...@gmail.com wrote: > hi, > > on python 2.7 how do I build a loop with a button + textbox? > > for example: > > I want the user to enter is name and then press "ok" button, I want > his name to be printed 5 times. Tested on Python 3.5.3: import b

Re: Trying to use threading.local()

2018-09-12 Thread Peter Otten
Steven D'Aprano wrote: > I'm originally posted this on the Python-Ideas list, but this is probably > more appropriate. > > > import time > from threading import Thread, local > > def func(): > pass > > def attach(value): # no new local() here > func.__params__.value = value > >

Re: Trying to use threading.local()

2018-09-13 Thread Peter Otten
Antoon Pardon wrote: > On 12-09-18 22:14, Peter Otten wrote: >> As I understand it you need one local() instance that is shared by all >> workers. Every thead will then see thread-specific values. > > It has always puzzled me how this is useful. The times I work with > th

Re: Trying to use threading.local()

2018-09-13 Thread Peter Otten
Chris Angelico wrote: > On Thu, Sep 13, 2018 at 10:22 PM, Peter Otten <__pete...@web.de> wrote: >> Antoon Pardon wrote: >> >>> On 12-09-18 22:14, Peter Otten wrote: >>>> As I understand it you need one local() instance that is shared by all >>>&

Re: Python in endless loop

2018-09-17 Thread Peter Otten
YnIk wrote: > Dear Python, > Hello. This is an email concerning about my Python program(3.7.0). It > keeps printing out stuff that’s too fast to read. If I try to write code, > it just keeps on going. I have tried Ctrl+C, but even that’s not working. > I searched through all my flies and can’t fin

Re: 2 Bugs: in Python 3 tutorial, and in bugs.python.org tracker registration system

2018-09-22 Thread Peter Otten
Francis Esmonde-White wrote: > Hello, > > I came to report one bug (in the Python 3 tutorial documentation), and ran > into another (functional in bugs.python.org bug tracker registration > system). I have included details for both bugs below. > > Thanks in advance for your assistance, I am lovi

Re: What is not working with my "map" usage?

2018-09-22 Thread Peter Otten
Victor via Python-list wrote: > Let me use a different input args and display them below. Basically, I am > hoping to add up all elements of each nested list. So at first it should > start with [1,11,111] ==> 1+11+111 = 123. But instead, it appears to take > the 1st element from each nested lis

Re: 2 Bugs: in Python 3 tutorial, and in bugs.python.org tracker registration system

2018-09-22 Thread Peter Otten
Brian Oney via Python-list wrote: > That's one thing that confused me. Generators are supposed to be one-off > iterators. Iterators, *I understood* as reusable iterables. The way I think about it, informally: iterables need and __iter__ method, iterators need a __next__ method. In practice all

Re: What is not working with my "map" usage?

2018-09-22 Thread Peter Otten
Victor via Python-list wrote: > On Saturday, September 22, 2018 at 6:22:32 AM UTC-7, Peter Otten wrote: >> Victor via Python-list wrote: >> >> > Let me use a different input args and display them below. Basically, I >> > am >> > hoping to add up all ele

Re: Recommended format for --log-level option

2018-09-25 Thread Peter Otten
Victor Porton wrote: > What is the recommended format for --log-level (or --loglevel?) command > line option? > > Is it a number or NOTSET|DEBUG|INFO|WARNING|ERROR|CRITICAL? Not really a recommendation, but I use choices=["DEBUG", ..., "CRITICAL"], type=str.upper It's not clear to me what it m

Re: clever exit of nested loops

2018-09-26 Thread Peter Otten
vito.detul...@gmail.com wrote: > Hi > Today I've added a couple of lines in my source code, and I'm very ashamed > of it. it "runs", and I know what it does (for now), but it's "too > clever". I have "abused" the "else" clause of the loops to makes a break > "broke" more loops > > > for i in

Re: JPEGImage() hangs

2018-09-28 Thread Peter Pearson
On Fri, 28 Sep 2018 15:01:41 +0100, Chris Green wrote: > Chris Green wrote: >> Brian Oney wrote: >> > Could you please try another tool like `convert'? E.g. >> > >> > $ convert 102_PANA/P1020466.JPG test.png >> > >> > >> > What does that say? >> >> Well, after having returned home with the l

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Peter Otten
jlada...@itu.edu wrote: > On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote: >> I have a list created by:- >> >> fld = shlex.split(ln) >> >> It may contain 3, 4 or 5 entries according to data read into ln. >> What's the neatest way of setting the fourth and fifth entries

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Peter Otten
Ben Finney wrote: > Ben Finney writes: > >> You can use a comprehension, iterating over the full range of index you >> want:: >> >> words = shlex.split(line) >> padding_length = 5 >> words_padded = [ >> (words[index] if index < len(words)) >> for index in range(paddin

Re: What's an elegant way to test for list index existing?

2018-09-30 Thread Peter Otten
Glen D souza wrote: > fld = [ ] > data = shlex.split(ln) > for item in data: >fld.append(item) > fld = fld + [0] * (5 - len(data)) There's no need to make a copy of data, one item at the time. It's a tedious way to build a new list, and you are throwing it away in the next line anyway, a

Re: namedtuples anamoly

2018-10-18 Thread Peter Otten
Vinodhini Balusamy wrote: > Hi, > > I tried using namedtuples and just found a behaviour which I am not able > to conclude as correct behaviour. > > from collections import namedtuple > > (n, categories) = (int(input()), input().split()) > Grade = namedtuple('Grade', categories) > Grade.ID = 1

Re: Python Enhancement Proposal for List methods

2018-10-22 Thread Peter Otten
Siva Sukumar Reddy wrote: > I am really new to Python contribution community want to propose below > methods for List object. Forgive me if this is not the format to send an > email. > > 1. *list.replace( item_to_be_replaced, new_item )*: which replaces all the > occurrences of an element in the

Re: Function factory?

2018-10-24 Thread Peter Otten
f...@lutix.org wrote: > Hello everyone, > > I have 2 functions whose aim is to read a pdf file, the first one manages > an uploaded file, the another one fecth a remote one (via an url). They > are quite the same: > > def handle_uploaded_file(path,file): > #if os.path

Re: customer compare in assertEqual

2018-10-30 Thread Peter Otten
Stone Zhong wrote: > Hi There, > > Now I want to make sure my code calls a function foo with an object t, > however, foo.assert_called_once_with(t) does not work, since t is a model > object and the code may load a different copy of t, so what I really want > to test is "It calls foo with t where

Re: @staticmethod or def function()?

2018-10-31 Thread Peter Otten
Tobiah wrote: > My IDE (pycharm) suggests that I mark my class methods > with @staticmethod when they don't use 'self'. Sounds > good. I did that then it suggested I had the option > to make a regular function instead, at the file level. > That's a possibility. I was thinking that I'd leave > t

Re: pyglet, i don't understand why this code isn't working

2018-11-02 Thread Peter Otten
songbird wrote: > MRAB wrote: >> On 2018-11-02 19:58, songbird wrote: >>> >>>hello, :) >>> >> [snip] >> In __init__ you initialise self.animation_initial_turn_it_off to True. >> >> Nowhere in your code do you change it, so it remains True. > > i wish it were that easy... > > see my_s

Re: Does this behavior have a better design pattern?

2018-11-07 Thread Peter Otten
lampahome wrote: > Above is I thought to make code clear, and this pattern is called simple > factory? This is a factory function: > def get_class(obj): > if obj == 'A1' or obj == 'A2': > return A(obj) > else: > return B(obj) The rest is just cruft ;) > > *Is there bet

Re: Number 7 syntax ERROR

2018-11-08 Thread Peter Otten
NoHaxAllSwagg wrote: > Hello, > I have been experiencing difficulty while trying to run scripts on my IDLE > software, considering that when I run my program, I get an error at the > top of the page in the “Python 3.7.1” area, highlighting the seven telling > me that there is a syntax error, in th

Re: Does this behavior have a better design pattern?

2018-11-08 Thread Peter Otten
Grant Edwards wrote: > On 2018-11-07, Peter Otten <__pete...@web.de> wrote: >> lampahome wrote: >> >>> Above is I thought to make code clear, and this pattern is called simple >>> factory? > > [...] > >>> *Is there better design pattern f

Re: What's wrong with these codes as failed to read the strings in Chinese? Is it because Chinese characters can't be read on Mac? Many thanks

2018-11-09 Thread Peter Otten
Cameron Simpson wrote: > In Python 3 the loop is much cleaner: > > with open('namelist.txt', encoding='utf-8') as f: > for line in f: > line = line.strip() > print("line =", line) In Python 2.7 you can use io.open(): import io with io.open('namelist.txt', encoding='utf-8') a

Re: pandas read_csv

2018-11-09 Thread Peter Otten
Sharan Basappa wrote: > are there any requirements about the format of the CSV file when using > read_csv from pandas? For example, is it necessary that the csv file has > to have same number of columns in every line etc. > ParserError: Error tokenizing data. C error: Expected 1 fields in line 8,

Re: [newbie] tkFileDialog does not show title

2016-03-28 Thread Peter Pearson
On Mon, 28 Mar 2016 14:10:28 -0700 (PDT), jenswaelk...@gmail.com wrote: > I'm using the tkFileDialog-module in Python 2.7, it works fine except > for one thing: when I add a title, the title isn't shown. > > e.g. I have this line of code: > inputfilename=tkFileDialog.askopenfilename(defaultextensio

[OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Peter Otten
Steven D'Aprano wrote: > http://lukeplant.me.uk/blog/posts/why-learning-haskell-python-makes-you-a-worse-programmer/ I was about to post that in a few years' time C# will acquire enough features to make code that follows the functional paradigm feasible in that language. Then I noted that this

Finding methods, was Re: DSL design (was DSLs in perl and python)

2016-03-29 Thread Peter Otten
Rustom Mody wrote: > [How BTW did you folks go about unearth that groupindex?? Dont see it in > [docs] While it's there https://docs.python.org/dev/library/re.html#re.regex.groupindex my personal search algorithm for this category of questions is mostly "I saw something like that before", then

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Peter Otten
Sven R. Kunze wrote: > On 29.03.2016 12:18, Sven R. Kunze wrote: >> On 29.03.2016 11:39, Peter Otten wrote: >>> My question to those who know a bit of C#: what is the state-of-the-art >>> equivalent to >>> >>> "\n".join(foo.descripti

Re: repeat items in a list

2016-03-30 Thread Peter Otten
Michael Selik wrote: > I prefer itertools.chain.from_iterable to the sum trick. > from itertools import chain lst = list('abc') list(chain.from_iterable([s]*3 for s in lst)) > ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'] If you want to make this completely lazy: >>> from functoo

Re: sympy

2016-03-31 Thread Peter Otten
Poul Riis wrote: > Den onsdag den 30. marts 2016 kl. 17.59.49 UTC+2 skrev Steven D'Aprano: >> On Thu, 31 Mar 2016 02:23 am, Poul Riis wrote: >> >> > What I intend to do is to let sympy find the derivative of some >> > welldefined function and next define the foundation derivative as a >> > normal

Re: Slice equivalent to dict.get

2016-03-31 Thread Peter Otten
Steven D'Aprano wrote: > Sometimes people look for a method which is equivalent to dict.get, where > they can set a default value for when the key isn't found: > > > py> d = {1: 'a', 2: 'b'} > py> d.get(999, '?') > '?' > > > The equivalent for sequences such as lists and tuples is a slice. If

Re: sympy

2016-03-31 Thread Peter Otten
Chris Angelico wrote: > On Fri, Apr 1, 2016 at 1:55 AM, Peter Otten <__pete...@web.de> wrote: >> Hm, the two functions fmsympy() and fm() do not return the same value: >> >> $ python -i sympy_diff.py >> 1 evaluations with sympy : dt1 = 0.7178411483764648 &g

Re: Drowning in a teacup?

2016-04-02 Thread Peter Otten
Vito De Tullio wrote: > Michael Selik wrote: > >>> > I need to scan a list of strings. If one of the elements matches the >>> > beginning of a search keyword, that element needs to snap to the front >>> > of the list. >>> >>> I know this post regards the function passing, but, on you specific >>>

Re: i cant seem to figure out the error

2016-04-03 Thread Peter Pearson
On Sun, 3 Apr 2016 16:06:58 +0100, anthony uwaifo wrote: [snip] > > class BankAccount(object): > def __init__(self, balance): > self.balance = balance > > > def deposit(self, amount): > self.amount=amount > self.balance += amount > return self.balance > > > def withdraw(self,

Re: Sorting a list

2016-04-03 Thread Peter Otten
DFS wrote: > cntText = 60 > cntBool = 20 > cntNbrs = 30 > cntDate = 20 > cntBins = 20 > > strText = " text: " > strBool = " boolean: " > strNbrs = " numeric: " > strDate = " date-time:" > strBins = " binary: " > > colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs)

Re: Sorting a list

2016-04-03 Thread Peter Otten
DFS wrote: > On 4/3/2016 3:31 PM, Peter Otten wrote: >>>>> from operator import itemgetter as get >>>>> print "\n".join("{1} {0}".format(*p) for p in sorted( >> ... sorted(colCounts, key=get(1)), key=get(0), reverse=True)) > > K

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Peter Otten
Nagy László Zsolt wrote: > If anyone is interested, a module was born: > > https://bitbucket.org/nagylzs/intervalset > https://pypi.python.org/pypi/intervalset/0.1.1 > > I have some unit tests, but testers and comments are welcome. Why do you limit the intervals to datetime? Are there any assum

Re: 2.7 source import in python 3.x

2016-04-04 Thread Peter Otten
Robin Becker wrote: > A user points out that this code in reportlab uses the now deprecated imp > module > > def _fake_import(fn,name): > if os.path.isfile(fn): > import imp > with open(fn,'rb') as f: > imp.load_source(name,fn,f) > > and suggests I use importl

Re: Sorting a list

2016-04-04 Thread Peter Otten
Random832 wrote: > On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote: >> > That works well. Why is it 'cheating'? >> >> On second thought it isn't ;) > > It does require a numeric type, though. There are lots of types that are > orderable but do

Re: Promoting Python

2016-04-05 Thread Peter Otten
Gordon( Hotmail ) wrote: Welcome! > I am struggling to understand the basic principles of Python having spent > many years as a pure Amateur tinkering with a variety of BASIC as you can > see on my site at http://www.sigord.co.uk/ I think you will agree all > such versions of Basic I have used

Re: functools puzzle

2016-04-06 Thread Peter Otten
George Trojan - NOAA Federal wrote: > Here is my test program: > > ''' generic test ''' > > import functools > import inspect > > def f(): > '''I am f''' > pass > > g = functools.partial(f) > g.__doc__ = '''I am g''' > g.__name__ = 'g' > > def partial(func, *args, **keywords): > d

Re: deque is not a subclass of Sequence.

2016-04-07 Thread Peter Otten
Antoon Pardon wrote: > Second tryal, I hope the formatting doesn't get messed up now > > Playing around with the collections and collections.abc modules in > python3.4 I stumbled upon the following: > from collections.abc import Sequence from collections import deque isinstance(li

Re: deque is not a subclass of Sequence.

2016-04-07 Thread Peter Otten
Antoon Pardon wrote: > Op 07-04-16 om 11:12 schreef Peter Otten: >> >>>>> from collections import deque >>>>> from collections.abc import Sequence >>>>> [name for name in set(dir(Sequence)) - set(dir(deque)) if not >> name.startswith(&qu

Re: read a file and remove Mojibake chars

2016-04-07 Thread Peter Otten
Daiyue Weng wrote: > Hi, when I read a file, the file string contains Mojibake chars at the > beginning, the code is like, > > file_str = open(file_path, 'r', encoding='utf-8').read() > print(repr(open(file_path, 'r', encoding='utf-8').read()) > > part of the string (been printing) containing Mo

Re: Unicode normalisation [was Re: [beginner] What's wrong?]

2016-04-07 Thread Peter Pearson
On Thu, 07 Apr 2016 11:37:50 +1000, Steven D'Aprano wrote: > On Thu, 7 Apr 2016 05:56 am, Thomas 'PointedEars' Lahn wrote: >> Rustom Mody wrote: > >>> So here are some examples to illustrate what I am saying: >>> >>> Example 1 -- Ligatures: >>> >>> Python3 gets it right >> flag = 1 >> flag

Re: COnvert to unicode

2016-04-07 Thread Peter Otten
Joaquin Alzola wrote: > Hi People > > I need to covert this string: > > hello there > this is a test > > (also \n important) > > To this Unicode: > 00680065006c006c006f0020002000740068006500720065000a00740068006900730020006900730020006100200074006500730074000a > Without the \u and space. >

Re: Unicode normalisation [was Re: [beginner] What's wrong?]

2016-04-08 Thread Peter Pearson
On Fri, 08 Apr 2016 16:00:10 +1000, Steven D'Aprano wrote: > On Fri, 8 Apr 2016 02:51 am, Peter Pearson wrote: >> >> The Unicode consortium was certifiably insane when it went into the >> typesetting business. > > They are not, and never have been, in t

Re: Unicode normalisation [was Re: [beginner] What's wrong?]

2016-04-08 Thread Peter Pearson
On Sat, 9 Apr 2016 03:50:16 +1000, Chris Angelico wrote: > On Sat, Apr 9, 2016 at 3:44 AM, Marko Rauhamaa wrote: [snip] >> (As for ligatures, I understand that there might be quite a bit of >> legacy software that dedicated code points and code pages for ligatures. >> Translating that legacy soft

Re: Conditionals in Python cli with -m oneliner

2016-04-09 Thread Peter Otten
gvim wrote: > Given that this work in a Python 3 repl: > import re txt = "Some random text" if re.search(r"\b\w{4}\b", txt): txt 'Some random text' > > and this works on the command line, printing all lines in logs.txt: > > $ python3 -m oneliner -ne 'line' logs.txt > >

Re: function to remove and punctuation

2016-04-10 Thread Peter Otten
gesh...@gmail.com wrote: > how to write a function taking a string parameter, which returns it after > you delete the spaces, punctuation marks, accented characters in python ? Looks like you want to remove more characters than you want to keep. In this case I'd decide what characters too keep f

Re: Change OnScreen Keyboard StringVar (Show linked to one Entry)

2016-04-10 Thread Peter Otten
Diego Lelis wrote: > Hi guys, im having a little problem to make the StringVar Linked to my > OnScreen Keyboard Change when the user click in one Entry. > > Here's my code: > from tkinter import * > > Begin > Code___ > > def frame(

Re: function to remove and punctuation

2016-04-10 Thread Peter Otten
Thomas 'PointedEars' Lahn wrote: > Peter Otten wrote: > >> gesh...@gmail.com wrote: >>> how to write a function taking a string parameter, which returns it >>> after you delete the spaces, punctuation marks, accented characters in >>> python ? >

Re: python pandas convert strings to datetime problems

2016-04-11 Thread Peter Otten
Daiyue Weng wrote: > Hi, I need to compare the years in a Series. The values in the Series is > like '1996', '2015', '2006-01-02' or '20130101' etc. The code I created > is, > > col_value_series = pd.to_datetime(col_value_series, > infer_datetime_format=True) min_year = col_value_series.min().yea

Re: Serious error in int() function?

2016-04-13 Thread Peter Otten
martin.spic...@gmail.com wrote: > Hi, > > there may be a serious error in python's int() function: > > print int(float(2.8/0.1)) > > yields > > 27 > > instead of 28!! > > I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu. > > Is that known? Yes. C has the same error as has every ot

[OT] A doubt about a doubt, was Re: How to XOR a byte output?

2016-04-13 Thread Peter Otten
alister wrote: > On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote: > >> I have a doubt regarding a problem. >> > No, you have a question doubt means you don't believe something > (sorry I know this is not an English language lesson) "doubt" is commonly used that way in Indian English, see

Re: sum accuracy

2016-04-13 Thread Peter Otten
Robin Becker wrote: > Does anyone know if sum does anything special to try and improve accuracy? > My simple tests seem to show it is exactly equivalent to a for loop > summation. If you are worried about accuracy and your values are floating point numbers use math.fsum(): """ fsum(...) fsu

Re: Append/Replace a row in a pandas DataFrame [SOLVED]

2016-04-14 Thread Peter Otten
Paulo da Silva wrote: > Às 21:10 de 13-04-2016, Paulo da Silva escreveu: >> Hi all. > ... > >> [6 rows x 4 columns] >> >>> dft=pd.DataFrame([[1,2,3,4]], >> index=[datetime.date(2016,1,12)],columns=df.columns) >> >>> dft >> A B C D >> 2016-01-12 1 2 3 4 >> >> [1 rows x 4 colu

Accuracy of math.sqrt(), was Re: Serious error in int() function?

2016-04-14 Thread Peter Otten
ast wrote: > > a écrit dans le message de > news:52f7516c-8601-4252-ab16-bc30c59c8...@googlegroups.com... >> Hi, >> >> there may be a serious error in python's int() function: >> >> print int(float(2.8/0.1)) >> >> yields >> >> 27 >> >> instead of 28!! >> >> I am using Python Python 2.7.6, GCC 4.

Re: How to XOR a byte output?

2016-04-14 Thread Peter Otten
durgadevi1 wrote: > >> >> This looks clearer: >> >>>>> code = b'a0\xed\xf0Z\x15]g^\xce3x' >>>>> key = b')U\x81\x9c55*\x08,\xa2WY' >>>>> bytes(c ^ k for c, k in zip(code, key)).decode() >>'Hello world!' >> >> >> Marko > > Hi, I have gotten another error message when working wi

Re: [OT] A doubt about a doubt

2016-04-14 Thread Peter Otten
Rustom Mody wrote: > I have a doubt: > Is it incorrect to correct someone when they are incorrect? No doubt about it. Everyone's a winner... > [Sprinkle a "politically" on the above to taste ] Ah, contradictio in adiecto. That shifts it to definitely maybe. -- https://mail.python.org/mailman

<    10   11   12   13   14   15   16   17   18   19   >