Re: Clean Singleton Docstrings

2016-07-08 Thread Peter Otten
Peter Otten wrote: > You might also file a bug report asking to replace I take that back; the problem is fixed in Python 3.5. -- https://mail.python.org/mailman/listinfo/python-list

Re: Quick poll: gmean or geometric_mean

2016-07-09 Thread Peter Otten
Steven D'Aprano wrote: > As requested in issue 27181 on the bug tracker, I'm adding functions to > calculate the harmonic and geometric means to the statistics module. > > I'd like to get a quick show of hands regarding the names. Which do you > prefer? > > hmean and gmean > > harmonic_mean and

Re: pocketsphinx no module named pocketsphinx found

2016-07-12 Thread Peter Otten
ldompel...@casema.nl wrote: > I try to run an example python file for pocketsphinx but I get this error: > > File "continuous_test.py", line 5, in > from pocketsphinx.pocketsphinx import * > ImportError: No module named pocketsphinx > > Does somebody knows how to repair this. Did you insta

Re: Getting number of neighbours for a 3d numpy arrays

2016-07-12 Thread Peter Otten
Heli wrote: > I have a 3d numpy array containing true/false values for each i,j,k. The > size of the array is a*b*c. > > for each cell with indices i,j,k; I will need to check all its neighbours > and calculate the number of neighbour cells with true values. > > A cell with index i,j,k has the f

Re: Clean Singleton Docstrings

2016-07-13 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Friday, July 8, 2016 at 7:38:56 PM UTC+12, Peter Otten wrote: > >> There is a test >> >> if not object: >> raise ImportError('no Python documentation found for %r' % thing) >> >> in the pydoc mod

Re: Compression

2016-07-14 Thread Peter Otten
Steven D'Aprano wrote: > How about some really random data? > > py> import string > py> data = ''.join(random.choice(string.ascii_letters) for i in > range(21000)) py> len(codecs.encode(data, 'bz2')) > 15220 > > That's actually better than I expected: it's found some redundancy and > saved about

Re: Don't understand why I'm getting this error

2016-07-14 Thread Peter Otten
Carter Temm wrote: > Hi all. > I've been looking at this for a bit, and can't seem to come to a possible > conclusion on what could be happening to get an error. Anyway, here is the > code, then I'll explain. > > http://pastebin.com/raw/YPiTfWbG > > the issue comes when using argv. But when I ch

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Peter Otten
Kent Tong wrote: > Hi, > > I can add new variables to user-defined classes like: > class Test: > ... pass > ... a=Test() a.x=100 > > but it doesn't work if the instances belong to a built-in class such as > str or list: > a='abc' a.x=100 > Traceback (most recent c

Re: can't add variables to instances of built-in classes

2016-07-18 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Monday, July 18, 2016 at 3:04:13 AM UTC+12, Steven D'Aprano wrote: > >> __slots__ is not obsolete, but 99% of the time you shouldn't bother with >> it. > > I find __slots__ very useful. I have them right through my Qahirah classes >

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-18 Thread Peter Otten
Marko Rauhamaa wrote: > Chris Angelico : >> you don't need an infinite amount of paper, except that they work with >> binary rather than decimal, so people think "0.1 + 0.2 ought to be >> exactly 0.3, why isn't it??", and blame floats. > > Oh, if we only had eight fingers on our hand... We alrea

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 6:19:45 PM UTC+12, Chris Angelico wrote: >> >> On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote: >>> >>> On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com >>> wrote: On Tuesday, July 19, 2016 at 3:54

Re: can't add variables to instances of built-in classes

2016-07-20 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote: > >> pylint can detect candidates for accidental attribute creation: > > And __slots__ will prevent them outright. And attributes added intentionally. -- https://mail.python.or

Re: can't add variables to instances of built-in classes

2016-07-21 Thread Peter Otten
breamore...@gmail.com wrote: > I hereby request that the moderators take this idiot offline as he's Mark, please behave yourself. -- https://mail.python.org/mailman/listinfo/python-list

Re: Technique for safely reloading dynamically generated module

2016-07-21 Thread Peter Otten
Malcolm Greene wrote: > We're designing a server application that parses a custom DSL (domain > specific language) source file, generates a Python module with the > associated logic, and runs the associated code. Since this is a server > application, we need to reload the module after each regener

Re: Max size of Python source code and compiled equivalent

2016-07-21 Thread Peter Otten
Malcolm Greene wrote: > We're writing a DSL parser that generates Python code. While the size of > our generated code will be small (< 32K), I wanted to re-assure the rest > of our team that there are no reasonable code size boundaries that we > need to be concerned about. I've searched for Python

Re: Caller's module name, function/method name and line number for output to logging

2016-07-25 Thread Peter Otten
Malcolm Greene wrote: > Hi Terry, > >>> Is there a technique for accessing a function's *CALLER* module name, >>> function/method name and line number so that this information can be > >> Look in the inspect module for the inspect stack function. Note that >> when you call the function, it need

Re: Possible to capture cgitb style output in a try/except section?

2016-07-26 Thread Peter Otten
Malcolm Greene wrote: > Is there a way to capture cgitb's extensive output in an except clause > so that cgitb's detailed traceback output can be logged *and* the except > section can handle the exception so the script can continue running? > > My read of the cgitb documentation leads me to beli

Re: NumPy frombuffer giving nonsense values when reading C float array on Windows

2016-07-26 Thread Peter Otten
ursch...@gmail.com wrote: > I'm using ctypes to interface with a binary which returns a void pointer > (ctypes c_void_p) to a nested 64-bit float array: > [[1.0, 2.0], [3.0, 4.0], … ] > then return the pointer so it can be freed > > I'm using the following code to de-reference it: > > # a 10-ele

Re: reshape with xyz ordering

2016-07-26 Thread Peter Otten
Heli wrote: > I sort a file with 4 columns (x,y,z, somevalue) and I sort it using > numpy.lexsort. > > ind=np.lexsort((val,z,y,x)) > > myval=val[ind] > > myval is a 1d numpy array sorted by x,then y, then z and finally val. > > how can I reshape correctly myval so that I get a 3d numpy array >

Re: Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."?

2016-07-26 Thread Peter Otten
Malcolm Greene wrote: > 2. Is there a technique for using glob.glob() to recognize files and >folders that begin with a period, eg. ".profile"? The documentation >states: "If the directory contains files starting with . they won’t >be matched by default.". Any suggestions on what the n

Re: print() function with encoding= and errors= parameters?

2016-08-03 Thread Peter Otten
Random832 wrote: > On Wed, Aug 3, 2016, at 08:29, Malcolm Greene wrote: >> Looking for a way to use the Python 3 print() function with encoding and >> errors parameters. >> Are there any concerns with closing and re-opening sys.stdout so >> sys.stdout has a specific encoding and errors behavior?

Re: cross-platform logging.config: how to set cross platform log (handlers) file location?

2016-08-09 Thread Peter Otten
ber...@gmail.com wrote: > Hello. > > My python script should run on Linux, Win and MacOS, but I can't find a > way to have logging.conf configuration that works out of the box accross > all these OSes. > > I don't want my users to have to edit configuration files manually. > > > If I use a "li

Re: cropping a random part of an image

2016-08-09 Thread Peter Otten
drewes@gmail.com wrote: > I'm new to python and I have 30.000 pictures. > I need to crop, let's say 100, parts of 256x256, randomly out of every > picture. > > I cant find an answer in the net, would be nice if someone could help me > out! You can walk over the files with https://docs.pytho

Re: All of a sudden code started throwing errors

2018-11-14 Thread Peter Otten
reproduce the problem: $ mkdir ~/foo $ cd foo $ python3.4 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath(".&qu

Re: Reading 'scientific' csv using Pandas?

2018-11-19 Thread Peter Otten
Martin Schöön wrote: > My pandas is up to date. > > In your example you use the US convention of using "." for decimals > and "," to separate data. This works perfect for me too. > > However, my data files use European conventions: decimal "," and TAB > to separate data: > > col1 col2 > 1,1

Re: on the prng behind random.random()

2018-11-19 Thread Peter Otten
Robert Girault wrote: > Looking at its source code, it seems the PRNG behind random.random() is > Mersenne Twister, but I'm not sure. It also seems that random.random() > is using /dev/urandom. Can someone help me to read that source code? > > I'm talking about CPython, by the way. I'm reading

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Peter Otten
Morten W. Petersen wrote: > Hi there. > > I was adding a port specification feature to my surveil project as shown > here: > > https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4 > > A bit later I was surprised when the script raised an exception, and that > I ha

Re: Injecting methods into instance / class

2018-12-02 Thread Peter Otten
duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > creates the relevant methods in an instance (Py

Re: Injecting methods into instance / class

2018-12-03 Thread Peter Otten
duncan smith wrote: > On 02/12/2018 18:36, Peter Otten wrote: >> class CommonMethods: >> __add__ = add > Ah, I could just bind them within the class, > > mean = mean > max = max etc. > > but I'd somehow convinced myself that didn't wor

Re: How to run an infinite loop on Menu?

2018-12-03 Thread Peter Otten
huey.y.ji...@gmail.com wrote: > Hi Folks, > > I need to run an infinite loop on a Menu button, like this: > > from Tkinter import * > > def run_job(): > i = 0 > while 1: > i = i + 1 > if i > 100: > break > ... > > root = Tk() > menu = Menu(root) > r

Re: Import module from file path

2018-12-04 Thread Peter Otten
Oscar Benjamin wrote: > Hi all, > > I'm looking to import a module given a string representing the path to > the .py file defining the module. For example given this setup > > mkdir -p a/b/c > touch a/__init__.py > touch a/b/__init__.py > touch a/b/c/__init__.py > touch a/b/c/stuff.py > > I hav

Re: tkinter resizable text with grid

2018-12-06 Thread Peter Otten
Paulo da Silva wrote: > Does anybody know why this code does not expand the text widget when I > increase the window size (with mouse)? I want height and width but as > minimum (or may be initial) size. > > import tkinter as tk > > class App: > def __init__(self,master): > self.tboar

Re: polar coordinates?

2018-12-09 Thread Peter Otten
Oscar Benjamin wrote: > On Sun, 9 Dec 2018 at 16:37, Brian Christiansen > wrote: >> >> I have been messing with a program that is inspried by a video on >> youtube that is about the vizualization of pi. I might make a post >> about that program someday, but I want to talk about something else. >

Smarter algo, was Re: 03 digression by brute force

2018-12-14 Thread Peter Otten
jf...@ms4.hinet.net wrote: > Just for fun:-) On my ooold PC, it takes 0.047 seconds to run the > following algorithm on the problem 'SNED + MORE == MONEY". > def tenThousand(u, Cin): # Cin == M > global n > if Cin == M: > print(S, E, N, D, '+', M, O, R, E, '==', M, O, N, E, Y) >

Re: pickle and module versioning

2018-12-17 Thread Peter Otten
Neal Becker wrote: > I find pickle really handy for saving results from my (simulation) > experiments. But recently I realized there is an issue. Reading the > saved results requires loading the pickle, which in turn will load any > referenced > modules. Problem is, what if the modules have cha

Re: Why doesn't a dictionary work in classes?

2018-12-25 Thread Peter Otten
אורי wrote: > Why does this not work: > > class User(ValidateUserPasswordMixin, PermissionsMixin, Entity, > AbstractBaseUser): > GENDER_VALID_VALUES = [choice[0] for choice in GENDER_CHOICES] > GENDERS_DICT = {GENDER_FEMALE: GENDER_FEMALE_STRING, GENDER_MALE: > ALL_GENDERS = [GENDER

Re: Logging - have logger use caller's function name and line number

2018-12-29 Thread Peter Otten
Malcolm Greene wrote: > I have a class method that adds additional context to many of the > class's log messages. Rather than calling, for example, logger.info( > 'message ...' ) I would like to call my_object.log( 'message ...' ) so > that this additional context is managed in a single place. I'

Re: subprocess : AttributeError: 'Popen' object has no attribute 'read'

2019-01-04 Thread Peter Otten
Mohan Mohta wrote: > Hello, > I am trying to grep the keyword (which I got from report_file ) from > report_file > > I tried multiple ways but am unable to get it to work. > > Below are the methods I tried. > > > fp=open(txt_file,'r') > for line in fp : > line=line.strip() >

Re: Are all items in list the same?

2019-01-08 Thread Peter Otten
Tim Chase wrote: > def all_equal(iterable): > i = iter(iterable) > first = next(i) > return all(x == first for x in i) > > It's undefined for an empty list (well, it throws a StopIteration > but you can special-case that), but should hand the cases with > 1 element and 2+ elements (

Re: Are all items in list the same?

2019-01-08 Thread Peter Otten
Bob van der Poel wrote: > I need to see if all the items in my list are the same. I was using set() > for this, but that doesn't work if items are themselves lists. So, > assuming that a is a list of some things, the best I've been able to come > up with it: > > if a.count( targ ) == len(a):

Re: How to find files with a string

2019-01-09 Thread Peter Otten
anton.gridus...@gmail.com wrote: > Hello everyone! > > I need to find a file, that contains a string TeNum > > I try to > > import os > import sys > def find_value(fname): > value = 0 > with open(fname, encoding='cp866') as fn: > try: > for i in fn: >

Re: How can I find the indices of an array with float values in python?

2019-01-10 Thread Peter Otten
Madhavan Bomidi wrote: > I have an array (numpy.ndarray) with shape (1500L,) as below: > > x = array([ 3.e+01, 6.e+01, 9.e+01, ..., > 4.4940e+04, 4.4970e+04, 4.5000e+04]) > > Now, I wanted to determine the indices of the x values between 0.0

Re: Python read text file columnwise

2019-01-12 Thread Peter Otten
shibashib...@gmail.com wrote: > Hello >> >> I'm very new in python. I have a file in the format: >> >> 2018-05-31 16:00:0028.90 81.77 4.3 >> 2018-05-31 20:32:0028.17 84.89 4.1 >> 2018-06-20 04:09:0027.36 88.01 4.8 >> 2018-06-20 04:15:0027.31

Silent data corruption in pandas, was Re: Python read text file columnwise

2019-01-12 Thread Peter Otten
Peter Otten wrote: > shibashib...@gmail.com wrote: > >> Hello >>> >>> I'm very new in python. I have a file in the format: >>> >>> 2018-05-31 16:00:0028.90 81.77 4.3 >>> 2018-05-31 20:32:0028.17 84.89 4.1 &

Re: Silent data corruption in pandas

2019-01-12 Thread Peter Otten
Peter Otten wrote: [Practising the bad habit of public soliloquy] > def parse_datetime(dt): > return datetime.datetime.strptime( > dt.replace(".", ":"), "%Y-%m-%d %H:%M:%S" > ) > > > def date_parser(dates, times): >

Re: How to run a module before install?

2019-01-14 Thread Peter Otten
jf...@ms4.hinet.net wrote: > I had download a module which has the following directory structure: > > [XL-Sudoku-Solver_master] > |__[tests] > |__[xl_sudoku_solver] > |__setup.py |__ __init__.py > |__problem1.txt |__ __main__.py > |__README.md |__ ... > |__ ... > > The s

Re: How to run a module before install?

2019-01-14 Thread Peter Otten
jf...@ms4.hinet.net wrote: >> h:\Temp\XL-Sudoku-Solver-master>py -m xl_sudoku_solver > > Great! it works. Thank you, peter. > > By the way, can you explain what these two command difference means? with > or without a "-m". Or pointing where the docu

Re: get the terminal's size

2019-01-14 Thread Peter Otten
Alex Ternaute wrote: > Hi there, > > I want to know the number of columns of the terminal where python2 writes > it's outputs. > > In a terminal, I type > $ echo $COLUMNS > 100 > > But in Python, os.getenv("COLUMNS") gets nothing. > It gets nothing as well if I try to read the output of "echo $

Re: get the terminal's size

2019-01-14 Thread Peter Otten
Grant Edwards wrote: os.environ["COLUMNS"] > [...] will tell you the terminal size at the time Python was started. I admit that none of my scripts is ambitious enough to try and track changes in terminal size. But still, Grant's post prompted me to reread the doc and source of shutil.get_ter

Re: [tkinter] question about correct use of validation

2019-01-16 Thread Peter Otten
steve wrote: > for determine the maximum number of characters in an entry > > I have read several interpretations for the solution of the problem, but > I wanted to find an alternative way (for convenience of the code) > > I kindly ask for an opinion on the use of validation in this way. > > --

Re: [tkinter] question about correct use of validation

2019-01-17 Thread Peter Otten
steve wrote: > Il 16/01/19 08:51, Peter Otten ha scritto: > >> def make_ui(self): >> ''' create user interface ''' >> >> def vcmd(maxlength): >> return self.parent.register( >&g

Re: [tkinter] question about correct use of validation

2019-01-17 Thread Peter Otten
steve wrote: > Il 17/01/19 14:08, Peter Otten ha scritto: > >> Two remarks: >> >>> self.id1_entry = self.make_entry(self.parent, maxlen=1).pack() >> >> You set all idX_entry attributes to None, as that's what pack() returns. > >

Re: TKinter Newbie question

2019-01-17 Thread Peter Otten
TUA wrote: > Why does the button frame in the code below not show? > tk.Button(bf, padx = 10, relief = tk.GROOVE, text = 'Help') You forgot to layout it with .pack(). > I intend to have it displayed in between the notebook at the top and the > fake statusbar at the bottom. I think for

Re: More elegant way to avoid this hacky implementation of single line reduce for grouping a collection?

2019-01-26 Thread Peter Otten
MRAB wrote: > On 2019-01-25 22:58, Travis Griggs wrote: >> >> grouped = reduce( >> lambda accum, each: (accum[0], >> accum[0][str(each)].append(each)), allValues, >> (defaultdict(list), None))[0] >> >> My question, only for the sake of learning python3 fu/enlighte

Re: Exercize to understand from three numbers which is more high

2019-01-27 Thread Peter Otten
^Bart wrote: >> You have got to a starting point - you have three numbers. Good. >> >> Where do you do go from here? >> >> I would start with two of the numbers, and work out which one is higher. > > # SOLVED!!! Hm, what does your script print if there are equal numbers? -- https://mail.pyt

Re: How to replace space in a string with \n

2019-01-31 Thread Peter Otten
^Bart wrote: >> Why? > > It's a school test, now we should use just what we studied, if than, > else, sequences, etc.! > > ^Bart Hint: you can iterate over the characters of a string >>> for c in "hello": ... print(c) ... h e l l o -- https://mail.python.org/mailman/listinfo/python-l

Re: mask and proper index

2019-02-03 Thread Peter Otten
diego.aves...@gmail.com wrote: > Dear all, > > I am trying to apply a mask to my dataframe: > > mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date) > df = df.loc[mask] > > > It seems to work pretty well. > > After that I crate the cumulative of its element as: > > > PP_cumPP

Re: mask and proper index

2019-02-04 Thread Peter Otten
Diego Avesani wrote: > If I can ask, due to the fact that I am new to thins kind of forum. > In this moment, I have another problem related to the data I am working > on. Should I write another post? You should start a new thread for a new problem, even if for you it is part of the same project

Re: format number is not recognized in a cycle

2019-02-04 Thread Peter Otten
Diego Avesani wrote: > Dear all, > > I have this dataframe: > > datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG > 2012-01-01 06:00, 0.4,100, 911,321, 2.5, 0.0, 0, 0,0 > 2012-01-01 07:00, 0.8,100, 911,198, 0.8, 0.0, 0, 22,0 > 2012-01-01 08:00, 0.6,100, 912, 44, 1.2, 0.0, 30, 22,0 > 20

Re: format number is not recognized in a cycle

2019-02-04 Thread Peter Otten
Diego Avesani wrote: > this is the code: While the example is fine now it runs without error over here, on rather old versions of pandas (0.13.1) and numpy (1.8.2). Therefore I'm out of the debugging cycle for now. -- https://mail.python.org/mailman/listinfo/python-list

Re: format number is not recognized in a cycle

2019-02-04 Thread Peter Otten
Diego Avesani wrote: > Dear Peter, Deal all, > > Trying different options, I manage this solution: > >mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <= >str(end_date[ii])) > > As you can notice, I have put str bef

Re: Loop with else clause

2019-02-05 Thread Peter Otten
DL Neil wrote: > What is the pythonic way to handle the situation where if a condition > exists the loop should be executed, but if it does not something else > should be done? > Possible solution: > To make anything more than the trivial case readable, I think I'd put > the list processing into

Re: how to exit from a nested loop in python

2019-02-08 Thread Peter Otten
Kaka wrote: > for i in range(len(A.hp)): > > for j in range(len(run_parameters.bits_Mod)): > req_slots[j] = math.ceil((A.T[i]) > > for g in Temp[i]["Available_ranges"][j]: > for s in range(g[0], g[-1]): > if (s+req_slots[j]-1) <= g[-1]: >

Re: print console out to a txt or csv file

2019-02-10 Thread Peter Otten
GISDude wrote: > Hi all, > I have been working on some code to list the files of a folder that has > .pdf extension. I have the basic code to create a list, but it prints that > list to the console. I'd like my code to write a txt file that contains > that list (to later import into excel). > > #

Re: more pythonic way

2019-02-11 Thread Peter Otten
Grant Edwards wrote: > On 2019-02-11, Felix Lazaro Carbonell wrote: > >> Could you please tell me wich way of writing this method is more >> pythonic: >> >> def find_monthly_expenses(month=None, year=None): >> month = month or datetime.date.today() >> >> Or it should better be: >> >>

Re: more pythonic way

2019-02-11 Thread Peter Otten
Felix Lazaro Carbonell wrote: > Hello to everyone: > Could you please tell me wich way of writing this method is more pythonic: > def find_monthly_expenses(month=None, year=None): > > month = month or datetime.date.today() > Or it should better be: > if not month: >

Re: A limit to writing to a file from a loop?

2019-02-13 Thread Peter Otten
Steve wrote: > My program reads from a text file (A), modifies the data, and writes to > another file (B). This works until I reach about 300 writes and no more > lines are written to file (B). > > I had to create a Counter and increment it to 250 when it gets reset. > > Upon reset, I close the

Re: using zip for transpose

2019-02-21 Thread Peter Otten
Robin Becker wrote: > In conversion of pandas dataframe to reportlab table I suggested using > this expression > > [list(x) for x in map(list,zip(*[df[i].values for i in df]))] > > which effectively transposes the dataframe. However, it's not clear that > this works for a large number of rows. I

Re: confusion with os.chmod() and follow_symlinks

2019-02-22 Thread Peter Otten
Karsten Hilbert wrote: > Am I confused ? > > ncq@hermes:~$ python3 > Python 3.7.2+ (default, Feb 2 2019, 14:31:48) > [GCC 8.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> print(os.supports_follow_symlinks) > {, , access>, , } >>> os.

Re: Custom logging code(s) / numbers to the log level Error

2019-02-22 Thread Peter Otten
kibt...@gmail.com wrote: > I wanted to write/extend the logging library to have a custom Error number > for each exception (error) the code has. What's the best approach for > this? If possible can someone please provide a good starting code snippet. > Thanks You can pass arbitrary data via the `

Re: Dictionary

2019-02-24 Thread Peter Otten
Himanshu Yadav wrote: > fibs={0:0,1:1} > def rfib(n): > global fibs >if not fibs.get(n): > fibs[n]=rfib(n-2)+rfib(n-1) > return fibs[n] Please use cut and paste to make sure you are not introducing new errors like the inconsistent indentation above. > Why

Re: Trying to read in data for a file to a python application

2019-02-26 Thread Peter Pearson
On Tue, 26 Feb 2019 15:51:38 +, Paul Sutton wrote: > Hi > > I have been trying to write a small application that is essentially user > information application. > > https://raw.githubusercontent.com/zleap/AboutMe/master/Aboutme.py > > So far I have managed to write the data generated to a file,

Re: Dictionary

2019-02-27 Thread Peter Otten
Phu Sam wrote: > The condition 'if not fibs.get(n):' will not work because > n = 0 > fibs.get(0) is 0 so not 0 is 1 > > Here is the modified code that works: > > fibs={0:0,1:1} > def rfib(n): > if n == 0 or n == 1: > return fibs[n] > else: > fibs[n]=rfib(n-2

Re: Decodificar base64 en Odoo 12

2019-03-04 Thread Peter Otten
Angie GL wrote: > Hola a todos, tengo un problema al decodificar el contenido de una > variable base64. > > De esta manera lo hago: > > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) > > > > Al momento de decodificar el resultado que me envía es esto: > > b'\n\n \n \n \n \n \n \n \n \n \n \n

Totally Legit Signing Key?

2019-03-04 Thread Peter Otten
For once I tried to verify a download from python.org, following the steps outlined at https://www.python.org/downloads/#pubkeys """ You can import the release manager public keys by either downloading the public key file from here and then running gpg --import pubkeys.txt """ When I ran the

Re: about types.new_class and module

2019-03-04 Thread Peter Otten
MRAB wrote: > On 2019-03-04 18:02, Jimmy Girardet wrote: >> Hello, >> >> I'm looking for an explanation where live classes created by >> types.new_class() : >> >> py> import types >> >> py> types.new_class('A') >> >> types.A >> >> py> types.A >> >> AttributeError: module 'types' has no attri

Re: Decodificar base64 en Odoo 12

2019-03-05 Thread Peter Otten
angiielovee...@gmail.com wrote: > El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribió: >> Angie GL wrote: >> >> > Hola a todos, tengo un problema al decodificar el contenido de una >> > variable base64. >> > >> > De esta

Re: Decodificar base64 en Odoo 12

2019-03-06 Thread Peter Otten
angiielovee...@gmail.com wrote: > El martes, 5 de marzo de 2019, 3:05:07 (UTC-6), Peter Otten escribió: >> angiielovee...@gmail.com wrote: >> >> > El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribió: >> >> Angie GL wrote: >> >

Re: in a pickle

2019-03-06 Thread Peter Otten
duncan smith wrote: > On 06/03/2019 16:14, duncan smith wrote: >> Hello, >> I've been trying to figure out why one of my classes can be >> pickled but not unpickled. (I realise the problem is probably with the >> pickling, but I get the error when I attempt to unpickle.) >> >> A relatively

Re: ConfigParser: use newline in INI file

2019-03-07 Thread Peter Otten
tony wrote: >> On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: >>> If you want to have \n mean a newline in your config file, you can >>> do the conversion after you read the value: >>> >>> >>> "a\\nb".decode("string-escape") >>> 'a\nb' > How does that translate t

RE: System Beep?

2019-03-08 Thread Peter Otten
Steve wrote: >> You have a typo. It is winsound, not winDsound. > Yes, I saw that. It still failed with, or without, the “d”. I played > with case and the use of (). They all produced similar errors Did you import the winsound module before trying to use it? -- https://mail.python.org/mailma

Re: Converting hex data to image

2019-03-11 Thread Peter Otten
dimplemathew...@gmail.com wrote: > Hi i have a similar challenge where i need to store the thumbnailPhoto > attribute to my local db and display the image every-time user logs in. > But this solution does work . data looks like this: > \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x0

Re: Converting hex data to image

2019-03-12 Thread Peter Otten
dimplemathew...@gmail.com wrote: > On Monday, March 11, 2019 at 4:32:48 PM UTC+5:30, Peter Otten wrote: >> dimplemathew...@gmail.com wrote: >> >> > Hi i have a similar challenge where i need to store the thumbnailPhoto >> > attribute to my local db and display

Re: Converting hex data to image

2019-03-12 Thread Peter Otten
dimplemathew...@gmail.com wrote: >> Save the image to a file (in binary mode!) and then try to open it with >> an image viewer. The data may be corrupted. > > When i tried doing that it says Invalid Image... So it looks like the problem occurs somewhere before you are decoding the image with th

Re: "Post install setup does not work as expected with pip install"

2019-03-12 Thread Peter Otten
Saba Kauser wrote: > Hello, > > I have a post install class that looks like this: > if('darwin' in sys.platform): > class PostInstall(install): > """ Post installation - run install_name_tool on Darwin """ > def run(self): > clipath = os.getenv('IBM_DB_HOME', '@loa

Re: Generator question

2019-03-14 Thread Peter Otten
Pierre Reinbold wrote: > Wow, thank you Ian for this very detailed answer, and thank you for taking > the time for that! Much appreciated! > > If I get this right, I have to somehow fix the value of a_list during the > loop, like when you use the classic default value argument trick with > lambda

Re: tkinter

2019-03-19 Thread Peter Otten
Terry Reedy wrote: > On 3/18/2019 12:00 PM, Informatico de Neurodesarrollo wrote: >> Hello friends: >> >> I am a beginner on programming in python. >> >> I want make a simple program that test continuously (every 5 seg) the >> connection to internet and change the background color when are not

Re: Reasoning of calling a method on class object instead of class instance object

2019-03-19 Thread Peter Otten
Arup Rakshit wrote: > In this piece of code: > > class RefrigeratedShippingContainer(ShippingContainer): > @staticmethod > def _c_to_f(celsius): > return celsius * 9/5 + 32 > @property > def fahrenheit(self): > return RefrigeratedShippingContainer._c_to_f(self.ce

Re: File not closed

2019-03-20 Thread Peter Otten
:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> f = open("/etc/passwd") >>> [1]+ Stopped python3 $ lsof /etc/passwd COMMAND PID USER FD TYPE DEVICE SIZE/

Re: Multiple log files using logging module

2019-03-24 Thread Peter Otten
Luuk wrote: > On 24-3-2019 18:13, Sharan Basappa wrote: >> I have a test program that imports a design program. >> Both the programs need to log messages. >> >> I have tried the following: >> >> 1) Both the programs have the following lines: >> for handler in logging.root.handlers[:]: >> lo

Re: Python 3.7 Bug

2019-03-25 Thread Peter Otten
Bassam Abdul-Baki wrote: > Greetings, > > In the following code, there's a bug on certain parameters. > > -- > > def per(n, steps = 0): > digits = [int(i) for i in str(n)] > result = 1 > for j in digits: > result *= j > steps += 1 > print(steps, result, sep=" - ") > if result ==

Re: Prepare accented characters for HTML

2019-03-28 Thread Peter Otten
Tony van der Hoff wrote: > On 28/03/2019 12:46, Jon Ribbens wrote: >> On 2019-03-28, Tony van der Hoff wrote: >>> Thanks, Chris. The problem is not with the browser, but Jinja crashes. >>> Probably a bug, but I'm too wedded to that engine to change now. I'll >>> raise it on the Jinja bug site. >>

Re: Prepare accented characters for HTML

2019-03-28 Thread Peter Otten
Tony van der Hoff wrote: > On 28/03/2019 16:58, Chris Angelico wrote: >> On Fri, Mar 29, 2019 at 3:47 AM Tony van der Hoff >> wrote: >>> >>> On 28/03/2019 15:09, Peter Otten wrote: >>>> Tony van der Hoff wrote: >>>> >>>>> On

Re: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML)

2019-03-29 Thread Peter Otten
Peter J. Holzer wrote: > On 2019-03-29 12:56:00 +0100, Thomas Jollans wrote: >> On 29/03/2019 12.39, Tony van der Hoff wrote: >> > Running in browser: >> > http://localhost/~tony/private/home/learning/jinja/minimal/minimal.py >> > >> > In apache2

Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Peter Otten
Arup Rakshit wrote: > Hello All, > > Thanks I got it now. > > One related question: Can I use pip3 for example to install packages > project specific, but not globally? So that when I delete the project, all > of them gone also from my disk. For that you can create a "virtual environment": $ p

Re: I really liked this Javscript FizzBuzz can it be as nice in Python?

2019-04-05 Thread Peter Otten
Sayth Renshaw wrote: > I saw this fizzbuzz in Eloquent Javascript and thought its really nice. > Not all the usual if else version, just if. > > for (let n = 1; n <= 100; n++) { > let output = ""; > if (n % 3 == 0) output += "Fizz"; > if (n % 5 == 0) output += "Buzz"; > console.log(output

Re: What is a, b, c, and d in: rect1 = drawing.create_rectangle(a, b, c, d) and circle1 = drawing.create_oval(a, b, c, d)

2019-04-09 Thread Peter Otten
CrazyVideoGamez wrote: > What is a, b, c, and d in: > from tkinter import * > window = Tk() > drawing = Canvas(window, height=500, width=500) > rectangle = drawing.create_rectangle(a, b, c, d) > and: > circle = drawing.create_oval(a, b, c, d) > ??? Here's a picture: http://infohost.nmt.edu/tcc/h

Re: Tkinter performance issues between Windows and Linux

2019-04-13 Thread Peter Otten
Robert Okadar wrote: > Hi community, > > I have developed a tkinter GUI component, Python v3.7. It runs very well > in Linux but seeing a huge performance impact in Windows 10. While in > Linux an almost real-time performance is achieved, in Windows it is slow > to an unusable level. > > The cod

Re: Question regarding the __kwdefaults__ output being None

2019-04-19 Thread Peter Otten
Arup Rakshit wrote: > I have a very basic function. > > def greet(name, msg = "Good morning!"): >""" >This function greets to >the person with the >provided message. > >If message is not provided, >it defaults to "Good >morning!" >""" > >print("Hello",name +

Re: Read the table data from PDF files in Python

2019-04-24 Thread Peter Pearson
On Wed, 24 Apr 2019 02:36:27 -0700 (PDT), mrawat...@gmail.com wrote: > Hello, > Anyone knows how to fetch the data from PDF file having tables with > other text in Python. Need to fetch some cell values based on > condition from that table. You might find pdftotext useful. The command . . . pd

<    12   13   14   15   16   17   18   19   20   21   >