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

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 >>

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

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

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,

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

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

2017-11-26 Thread 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

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

2017-11-26 Thread 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

Re: Problem in defining multidimensional array matrix and regression

2017-11-19 Thread Peter Otten
shalu.ash...@gmail.com wrote: > Hi, All, > > I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and > others are predictors (at x). I want to do multiple regression and create > a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I > want to read rainfall

Re: Time travel - how to simplify?

2017-11-18 Thread Peter Otten
Andrew Z wrote: > well, yeah, it's unidirectional and final destination is always the same > and have little to do with the question. > > Say, i have a dict: > > fut_suffix ={ 1 : 'F', > 2 : 'G', > 3 : 'H', > 4 : 'J', > 5 : 'K', >

Re: All the list getting appended of a dict if you are updating only first element list of dict

2017-11-15 Thread Peter Otten
Radhey Parashar wrote: > I am facing 1 issue with python related to append command in a list > class CITY: > > num = 0 > > connectivity = [] The way you wrote it the connectivity list is shared between all instances of the CITY class. Consult a Python tutorial to learn why. To get

Re: dictionary comparing int keys and joins their values if two key are within a certain distance

2017-11-08 Thread Peter Otten
Daiyue Weng wrote: > I have a nested dictionary of defaultdict(dict) whose sub dict have int > keys and lists (list of ints) as values, > > 'A' = {2092: [1573], 2093: [1576, 1575], 2094: [1577], 2095: > [1574]}'B' = {2098: [1], 2099: [2, 3], 2101: [4], 2102: [5]}'C' = > {2001: [6], 2003: [7, 8],

Re: What happens to module's variables after a "from module import" ?

2017-11-07 Thread Peter Otten
ast wrote: > Hello > > Here is my module tmp.py: > > a=0 > > def test(): > global a > print(a) > a+=1 > > If I import function "test" from module "tmp" with: > from tmp import test > > it works > test() > 0 test() > 1 > > But where variable "a" is located ? I

Re: I am trying to delete duplicates but the job just finishes with an exit code 0

2017-11-07 Thread Peter Otten
tysondog...@gmail.com wrote: > I am trying to delete duplicates but the job just finishes with an exit > code 0 and does not delete any duplicates. > > The duplicates for the data always exist in Column F and I am desiring to > delete the entire row B-I > > Any ideas? > > > import openpyxl >

[issue30952] [Windows] include Math extension in SQlite

2017-11-06 Thread Peter Otten
Peter Otten <__pete...@web.de> added the comment: A possible workaround is to use create_function(): >>> import sqlite3, math >>> db = sqlite3.connect(":memory:") >>> db.execute("select sin(?);", (math.pi,)).fetchone() Traceback (m

Re: Read Firefox sqlite files with Python

2017-11-04 Thread Peter Otten
Steve D'Aprano wrote: > I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > > > import sqlite3 > con = sqlite3.connect('foo.sqlite') > with open('dump.sql', 'w') as f: > for line in con.iterdump(): > f.write(line + '\n') > > > The error I get is: > >

Re: Reading a remove csv file

2017-11-02 Thread Peter Otten
ROGER GRAYDON CHRISTMAN wrote: > Just a quick question on how best to read a remote CSV file. > So far, I tried: > > filelink = urllib.request.urlopen(path) > dictread = csv.DictReader(filelink) > for row in dictread:... > But I'm running into the difference between strings and bytes. > I'd

Re: from packaging import version as pack_version ImportError: No module named packaging

2017-10-30 Thread Peter Otten
David Gabriel wrote: > Dears, > > When I run this command I got this error message: > > ubuntu@orchestrateur:/tmp/pack$ virtualenv -p $(which python3.5) . > Running virtualenv with interpreter /usr/local/sbin/. > Traceback (most recent call last): > File "/usr/bin/virtualenv", line 3, in >

Re: h5py.File() gives error message

2017-10-25 Thread Peter Otten
C W wrote: > Oh, I was running a debug file, that's why the path is different. > > The file is here, > https://www.dropbox.com/s/6jx4rzyg9xwl95m/train_catvnoncat.h5?dl=0 > > Is anyone able to get it working? Thank you! Hm, that file seems to contain HTML and that causes an OSError here, too:

Re: Objects with __name__ attribute

2017-10-25 Thread Peter Otten
ast wrote: > Hi, > > I know two Python's objects which have an intrinsic > name, classes and functions. > > def f(): > pass > f.__name__ > 'f' g = f g.__name__ > 'f' > > class Test: > pass > Test.__name__ > 'Test' Test2 = Test Test2.__name__ > 'Test' >

Re: How to debug an unfired tkinter event?

2017-10-19 Thread Peter Otten
jf...@ms4.hinet.net wrote: > Peter Otten於 2017年10月19日星期四 UTC+8下午6時04分39秒寫道: >> jf...@ms4.hinet.net wrote: >> >> > Peter Otten at 2017-10-19 UTC+8 PM 3:24:30 wrote: >> >> It's not clear to me what you mean with this. Did you place the table >> >> fr

Re: Efficient counting of results

2017-10-19 Thread Peter Otten
Israel Brewster wrote: > >> On Oct 19, 2017, at 10:02 AM, Stefan Ram wrote: >> >> Israel Brewster writes: >>> t10 = {'daily': 0, 'WTD': 0, 'MTD': 0, 'YTD': 0,} >>> increment the appropriate bin counts using a bunch of if statements. >> >> I

Re: How to debug an unfired tkinter event?

2017-10-19 Thread Peter Otten
jf...@ms4.hinet.net wrote: > Peter Otten at 2017-10-19 UTC+8 PM 3:24:30 wrote: >> It's not clear to me what you mean with this. Did you place the table >> from the recipe elsewhere inside a window that you created or did you >> make changes in the recipe's code? > > T

Re: How to debug an unfired tkinter event?

2017-10-19 Thread Peter Otten
jf...@ms4.hinet.net wrote: > In last few days, I tried to experiment with the scrolling table > implemented in canvas, started from this example: > http://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars/. > Everything works fine until I moved the scrolling_area instance (which

Re: Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25

2017-10-17 Thread Peter Otten
Daniel Flick wrote: > On Tuesday, October 17, 2017 at 4:25:02 PM UTC-5, Daniel Flick wrote: >> >> Peter, I am not following. Are you saying that there is a function that >> returns the network only? network_address was giving me the mask >> attached to the end but maybe I was doing something

Re: Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25

2017-10-17 Thread Peter Otten
Daniel Flick wrote: > I am very new to Python and have been struggling to find some info on > processing IP addresses. > > get_network returns 192.168.1.128/25 but I need 192.168.1.128 only. I can > do this with netaddr but I am working with Mako templates and ipaddress is > a built in module

Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
Stefan Ram wrote: > Peter Otten <__pete...@web.de> writes: >>team.pop(2) >>Stefan's explanation may work for >>del x >>if you discard >>x = None # get rid of the huge object that x was bound to before >>as a hack > > »x = None« observably has

Re: why del is not a function or method?

2017-10-16 Thread Peter Otten
bartc wrote: > On 16/10/2017 16:58, Stefan Ram wrote: >> Xue Feng writes: >>> I wonder why 'del' is not a function or method. >> >>Assume, >> >> x = 2. >> >>When a function »f« is called with the argument »x«, >>this is written as >> >> f( x ) >> >>. The

Re: unorderable types: list() > int()

2017-10-13 Thread Peter Otten
Andrew Z wrote: > Hello, > pos = {"CLown":10,"BArbie":20} > I want to return integer (10) for the keyword that starts with "CL" > > > cl_ = [v for k, v in pos.items() if k.startswith('CL')] > cl_pos = cl_[0] > if cl_pos > 0: > >blah.. > > > There are 2 issues with the above: > a. ugly -

Re: Logging from files doesn't work

2017-10-12 Thread Peter Otten
Andrew Z wrote: > Hello, > > apparently my reading comprehension is nose diving these days. After > reading python cookbook and a few other tutorials i still can't get a > simple logging from a few files to work. > I suspected my file organization - all files are in the same directory, >

Re: Introducing the "for" loop

2017-10-10 Thread Peter Otten
Stefan Ram wrote: > Which advice do you refer to? Teach the parts that are most useful first, i. e. for loops over anything but range rather than while loops. -- https://mail.python.org/mailman/listinfo/python-list

Re: pathlib PurePosixPath

2017-10-10 Thread Peter Otten
Sayth Renshaw wrote: > Thanks. Updated the script. But shouldn't it create the file if it doesn't > exist? Which none of them will. > pathlib.PurePath(r'C:\Users\Sayth\Projects\results', file_name) > with open(result_path, 'a') as f: > f.write(data) > ##Output >

Re: Is there a way to globally set the print function separator?

2017-10-09 Thread Peter Otten
John Black wrote: > I want sep="" to be the default without having to specify it every time I > call print. Is that possible? No, but you can replace the print function with your own: >>> print = functools.partial(print, sep="") >>> print("I", "recommend", "you", "choose", "another", "name",

Re: why does memory consumption keep growing?

2017-10-06 Thread Peter Otten
Chris Angelico wrote: > On Fri, Oct 6, 2017 at 4:14 PM, Gregory Ewing > wrote: >> Steve D'Aprano wrote: >>> >>> Plus the downtime and labour needed to install the memory, if the >>> computer will even take it. >> >> >> Obviously we need an architecture that supports

Re: How do native namespaces work?

2017-10-05 Thread Peter Otten
Thomas Nyberg wrote: > Hello, > > I'm trying to understand native namespaces. I'm currently using python > 3.5 as packaged in debian 9. I've been following the instructions here: > > https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages > > Those

Re: How do native namespaces work?

2017-10-05 Thread Peter Otten
Thomas Nyberg wrote: > Hello, > > I'm trying to understand native namespaces. I'm currently using python > 3.5 as packaged in debian 9. I've been following the instructions here: > > https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages > > Those

Re: Introducing the "for" loop

2017-10-05 Thread Peter Otten
Stefan Ram wrote: > "ROGER GRAYDON CHRISTMAN" writes: >>On Wed, Oct 4, 2017 22:42 Stefan Ram (r...@zedat.fu-berlin.de) wrote: >>Steve D'Aprano writes: So, "bottom-up" in this case means: iterators should be taught before for-loops. Why?

Re: The "loop and a half"

2017-10-05 Thread Peter Otten
Stefan Ram wrote: > bartc writes: >>Note that your reverse-indentation style is confusing! > > In Python, indentation can be significant. > > Sometimes, some lines in Python must be indented by 0. Are there any editors that do not support a dedent operation? In the

Re: The "loop and a half"

2017-10-03 Thread Peter Otten
Stefan Ram wrote: > Is this the best way to write a "loop and a half" in Python? > > x = 1 > while x: > x = int( input( "Number (enter 0 to terminate)? " )) > if x: > print( f'Square = { x**2 }' ) > > In a C-like language, one could write: > > while x = int( input( "Number

Re: when is filter test applied?

2017-10-03 Thread Peter Otten
Neal Becker wrote: > In the following code (python3): > > for rb in filter (lambda b : b in some_seq, seq): > ... some code that might modify some_seq > > I'm assuming that the test 'b in some_seq' is applied late, at the start > of each iteration (but it doesn't seem to be working that way

Re: on a very slow function

2017-10-02 Thread Peter Otten
bartc wrote: > On 02/10/2017 08:41, Peter Otten wrote: >> Daniel Bastos wrote: >> >>> def make_sequence_non_recursive(N, x0 = 2, c = -1): >>>"What's wrong with this function? It's very slow." >>>last = x0 >>>def sequence

Re: on a very slow function

2017-10-02 Thread Peter Otten
Daniel Bastos wrote: > def make_sequence_non_recursive(N, x0 = 2, c = -1): > "What's wrong with this function? It's very slow." > last = x0 > def sequence(): > nonlocal last > next = last > last = last**2 + c > return next % N > return sequence > > It crawls pretty soon.

Re: Redirecting stdio streams with a context manager

2017-09-29 Thread Peter Otten
Steve D'Aprano wrote: > In the standard library's contextlib.py module, there is a class for > redirecting standard I/O streams, and two public functions. The code is > short enough to reproduce here: > > # From Python 3.5 > > class _RedirectStream: > _stream = None > def __init__(self,

Re: Printing a Chunk Of Words

2017-09-27 Thread Peter Otten
Matt Wheeler wrote: > With deepest apologies to all involved... > > On Tue, 26 Sep 2017 at 08:42 Gregory Ewing > wrote: > >> Ben Bacarisse wrote: >> > Think functional! This is 257 characters: >> >> 250 chars, 17 shorter than the text it produces: >> >>

Re: Spacing conventions

2017-09-27 Thread Peter Otten
Bill wrote: > Ever since I download the MyCharm IDE a few days ago, I've been noticing > all sort of "spacing conventions (from PEP) that are suggested. How do > folks regard these in general? > > For instance, the conventions suggest that > > if x>y : > pass > > should be written >

Re: Parentheses (as after "print")

2017-09-27 Thread Peter Otten
Stefan Ram wrote: > Why do we newbies write »print 2«? Here's another hint. > This is an original transcript of what happened to me today: > > |>>> import( operator ) > | File "", line 1 > |import( operator ) > | ^ > |SyntaxError: invalid syntax > | > |>>> import operator > | >

Re: Newbie problem with urllib.request.urlopen

2017-09-26 Thread Peter Otten
Bernie Connors wrote: > On Tuesday, September 26, 2017 at 12:32:18 PM UTC-3, Bernie Connors wrote: >> Hello, >> >> My first post here on C.L.P. I have only written a few python >> scripts in 2.7 and now I'm trying my first python 3 script. Can >> you tell me why this snippet

Re: Finding keyword arguments in the documentation

2017-09-26 Thread Peter Otten
Jerry Hill wrote: > On Tue, Sep 26, 2017 at 12:32 PM, Peter Otten <__pete...@web.de> wrote: >> Newer Python versions will show >> >> Help on built-in function sin in module math: >> >> sin(x, /) >> Return the sine of x (measured in radians).

Re: Finding keyword arguments in the documentation

2017-09-26 Thread Peter Otten
Stefan Ram wrote: > Here's a console transcript: > > |>>> from math import sin > |>>> help( sin ) > |Help on built-in function sin in module math: > | > |sin(...) > |sin(x) > | > |Return the sine of x (measured in radians). > | > |>>> sin( x = 2.0 ) > |Traceback (most recent call

Re: Running a GUI program haults the calling program (linux)

2017-09-26 Thread Peter Otten
Kryptxy via Python-list wrote: > Sent with [ProtonMail](https://protonmail.com) Secure Email. > >> Original Message >> Subject: Re: Running a GUI program haults the calling program (linux) >> Local Time: 26 September 2017 12:09 PM >> UTC Time: 26 September 2017 06:39 >> From:

Re: TypeError with map with no len()

2017-09-25 Thread Peter Otten
john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1)

Re: Reference cycles

2017-09-24 Thread Peter Otten
Steve D'Aprano wrote: > Is there a way to log when the garbage collector finds and collects a > reference cycle? > > I don't care about objects claimed by the reference counter, I only care > about cycles. I don't know, and I don't think so. Would a structure like a --- b --- c | | | d

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
Peter Otten wrote: > validationma...@gmail.com wrote: > >> i have a code in python to search and replace what i need though is to >> replace the first say 10 instances of the number 1 with 2 and the second >> 10 instances with the number 3. anybody knows how to do that?

Re: search and replace first amount of strings instances with one thing and a second amount of instances with another thing-

2017-09-23 Thread Peter Otten
validationma...@gmail.com wrote: > i have a code in python to search and replace what i need though is to > replace the first say 10 instances of the number 1 with 2 and the second > 10 instances with the number 3. anybody knows how to do that? > > fin = open(r'F:\1\xxx.txt') > fout =

Re: Convert pandas series to string and datetime object

2017-09-22 Thread Peter Otten
Pavol Lisy wrote: > pandas is one of reasons why python is so popular these days. But > "there is only milion way how to do it" (and other unpythonic issues) > I see there every time I am looking at it. :) Yeah, such a useful tool with such a byzantine API, completely at odds with the zen -- I

Re: what is happening in panda "where" clause

2017-09-22 Thread Peter Otten
Exposito, Pedro (RIS-MDW) wrote: > This code does a "where" clause on a panda data frame... > > Code: > import pandas as pd; > col_names = ['Name', 'Age', 'Weight', "Education"]; > # create panda dataframe > x = pd.read_csv('test.dat', sep='|', header=None, names = col_names); >

Re: Convert pandas series to string and datetime object

2017-09-21 Thread Peter Otten
zljubi...@gmail.com wrote: > I have sliced the pandas dataframe > > end_date = df[-1:]['end'] > > type(end_date) > Out[4]: pandas.core.series.Series > > end_date > Out[3]: > 48173 2017-09-20 04:47:59 > Name: end, dtype: datetime64[ns] > > 1.How to get rid of index value 48173 and get

Re: How do I check all variables returned buy the functions exists

2017-09-20 Thread Peter Otten
Bill wrote: > Robin Becker wrote: >> On 16/09/2017 01:58, Steve D'Aprano wrote: >> >>> >>> If you want to test for None specifically: >>> >>> if any(v is None for v in values): >>> print "at least one value was None" >>> >> ... >> >> for some reason that seems slow on my machine

Re: Unicode

2017-09-17 Thread Peter Otten
leam hall wrote: > Doesn't seem to work. The failing code takes the strings as is from the > database. it will occasionally fail when a name comes up that uses > a non-ascii character. Your problem in nuce: the Python 2 __str__() method must not return unicode. >>> class Character: ... def

Re: Design: method in class or general function?

2017-09-11 Thread Peter Otten
Leam Hall wrote: > I do not understand your last sentence about reference cycle. Currently you have - create Career instance which stores character as an attribute - make modifications to character - forget about Career instance My suggestion - create Career instance which stores character

Re: Need to pass a class instance to a gettext fallback

2017-09-08 Thread Peter Otten
Josef Meile wrote: > Hi > > I'm working with gettext and need to define a language Fallback. I got > this working, but with a global variable. I don't really like this and I > would like to pass this variable to the gettext Fallback's contructor, but > I don't know how. For simplicity, I won't

Re: cant't use package internals

2017-09-06 Thread Peter Otten
Andrej Viktorovich wrote: > Hello, > > I have Python package tst in my workspace. > > tst has files: > __init__.py > tst.py > > > content of __init__.py: > print("importing Tst") > > > content of tst.py: > class Tst: > def __init__(self): > print("init Tst") > > > I run python

Re: XML Parsing

2017-09-04 Thread Peter Otten
Sambit Samal wrote: > Hi , > > Need help in Python Script using xml.etree.ElementTree to update the > value of any element in below XML ( e.g SETNPI to be 5 ) based on some > constraint ( e.g ) . Something along the lines from xml.etree import ElementTree as ET tree =

Re: Have do_nothing as default action for dictionary?

2017-09-03 Thread Peter Otten
Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > >

Re: Have do_nothing as default action for dictionary?

2017-09-03 Thread Peter Otten
Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > >

Re: meaning of [ ]

2017-09-03 Thread Peter Otten
Andrej Viktorovich wrote: > Hello, > > Trying to understand command: > [p for p in sys.path] > > It prints array of paths. I suppose p becomes array of strings but what [] > means in this statement? This is called "list comprehension", and paths = [p for p in sys.path if "foo" in p] is

Re: possible bug in while loop test

2017-09-02 Thread Peter Otten
Charles Hixson wrote: > python3 --version > Python 3.5.3 > > Running on Debian stretch > > In this code s is a string parameter > > while (j < k and \ > (s[j].isalnum()) or \ >(s[j] in seps and s[j+1].isalnum()) ): > j = j + 1 > print ("i = {0}, j =

Re: Python string replace the values

2017-09-02 Thread Peter Otten
Steve D'Aprano wrote: > On Sat, 2 Sep 2017 03:13 am, Ganesh Pal wrote: > >> Example : >> >> "a" and "1" => a0001 >> >> "a" and "aa" => c00aa > > Why does the leading 'a' change to a 'c'? Is that a mistake? I'll assume > its a typo. > > You want string slicing. > > base = 'a'

Re: If you are running 32-bit 3.6 on Windows, please test this

2017-09-01 Thread Peter Otten
Pavol Lisy wrote: > On 8/31/17, 20/20 Lab wrote: >> >> >> On 08/31/2017 01:53 AM, Pavol Lisy wrote: > [...] >> Valid point, fired up a windows 10 machine and worked as well. >> >> Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit >> (Intel)] on win32 >>

Re: traceback.format_exc() returns 'None\n'?!

2017-08-31 Thread Peter Otten
Sean DiZazzo wrote: > Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. import traceback tb = traceback.format_exc() type(tb) > tb >

Re: Case-insensitive string equality

2017-08-31 Thread Peter Otten
Steven D'Aprano wrote: > Three times in the last week the devs where I work accidentally > introduced bugs into our code because of a mistake with case-insensitive > string comparisons. They managed to demonstrate three different failures: > > # 1 > a = something().upper() # normalise string >

To mock/patch or not to, was Re: doctest random output?

2017-08-29 Thread Peter Otten
Steven D'Aprano wrote: > Wait... are you saying that importing test_mymodule monkey-patches the > current library? And doesn't un-patch it afterwards? That's horrible. There's something in the library, unittest.mock that makes this relatively safe -- if not painless with

Re: a heisenbug

2017-08-29 Thread Peter Otten
Steve D'Aprano wrote: > On Tue, 29 Aug 2017 07:09 am, Peter Otten wrote: > >> The lesson is that if you use a (sub)module you should never rely on an >> implicit import. > > ... unless the module is documented as automatically importing the > submodule. An e

Re: a heisenbug

2017-08-28 Thread Peter Otten
Chris Angelico wrote: > On Tue, Aug 29, 2017 at 4:59 AM, Stefan Ram > wrote: >> This might be what one calls "heisenbug": >> >> No attribute 'abc' is visible. One tries to >> study it with "help". And next time it's there. >> "help" /did/ help! >> >> Python 3.6.0

Re: A vocabulary trainer

2017-08-28 Thread Peter Otten
Stefan Ram wrote: > My course participants always are impatient for "useful > applications". So at a point in my course where no control > structures (if, for, while, ...) have been introduced yet, > but function calls, function declarations, assignments, > lists and dictionaries

Re: doctest random output?

2017-08-28 Thread Peter Otten
Leam Hall wrote: > Is this a good way to test if random numeric output? It seems to work > under Python 2.6 and 3.6 but that doesn't make it 'good'. > > ### Code > import random > > def my_thing(): >""" Return a random number from 1-6 >>>> 0 < my_thing() <=6 >True >>>> 6 <

Re: BeautifulSoup doesn't work with a threaded input queue?

2017-08-27 Thread Peter Otten
Christopher Reimer via Python-list wrote: > On 8/27/2017 1:31 PM, Peter Otten wrote: > >> Here's a simple example that extracts titles from generated html. It >> seems to work. Does it resemble what you do? > Your example is similar to my code when I'm using a list for the

Re: BeautifulSoup doesn't work with a threaded input queue?

2017-08-27 Thread Peter Otten
Christopher Reimer via Python-list wrote: > On 8/27/2017 11:54 AM, Peter Otten wrote: > >> The documentation >> >> https://www.crummy.com/software/BeautifulSoup/bs4/doc/#making-the-soup >> >> says you can make the BeautifulSoup object from a string or file

Re: BeautifulSoup doesn't work with a threaded input queue?

2017-08-27 Thread Peter Otten
Christopher Reimer via Python-list wrote: > Greetings, > > I have Python 3.6 script on Windows to scrape comment history from a > website. It's currently set up this way: > > Requestor (threads) -> list -> Parser (threads) -> queue -> CVSWriter > (single thread) > > It takes 15 minutes to

Re: Reading the documentation

2017-08-24 Thread Peter Otten
Stefan Ram wrote: > This is a transcript: > from math import floor floor( "2.3" ) > Traceback (most recent call last): > File "", line 1, in > TypeError: must be real number, not str help(floor) > Help on built-in function floor in module math: > > floor(...) > floor(x)

Re: Proposed new syntax

2017-08-24 Thread Peter Otten
Paul Rubin wrote: > Ben Finney writes: >> generate_id = functools.partial(next, itertools.count()) > > Is something wrong with: > > >>> g = itertools.count().next That question seems to be the topic of this subthread. Other than the principle "never call a

[issue31266] attribute error

2017-08-23 Thread Peter Otten
Peter Otten added the comment: You have probably written your own re.py file which shadows the one in the standard library. Once you remove or rename your re.py the error should go away. -- nosy: +peter.otten ___ Python tracker <

Re: python to call or start a fortran a.out

2017-08-21 Thread Peter Otten
Chet Buell wrote: > Need some help with updating python to call or start a fortran a.out > executable > > The problem I am having is I have an old Fortran based model that I need > to run, in the past the fortran was triggered through the following > python code: > > #run fortran > x =

Re: how to create root with treelib?

2017-08-21 Thread Peter Otten
dieter wrote: > Ho Yeung Lee writes: > >> http://treelib.readthedocs.io/en/latest/examples.html >> >> tree = Tree() >> #create root >> tree.create_node((0,0), "root") >> result = [aa[0]] >> previousnode = (0,0) >> > #create root >> ... tree.create_node((0,0), "root")

Re: Ask for help about a tkinter problem

2017-08-20 Thread Peter Otten
jf...@ms4.hinet.net wrote: > I am running a tkinter tutor downloaded from web, > https://github.com/daleathan/widget-tour-py3. there are two files > involved: > > > #file button.py > > from tkinter import * > from tkinter.ttk import * > import infrastructure > ... > class

[issue31214] os.walk has a bug on Windows

2017-08-15 Thread Peter Otten
Peter Otten added the comment: Read the documentation of os.walk() again. It already walks the complete directory tree starting with src. When you invoke it again by calling your copy_dir() method recursively you will of course see once more the files and directories in the respective

Re: Redirecting input of IDLE window

2017-08-14 Thread Peter Otten
Friedrich Rentsch wrote: > Hi, > > I work interactively in an IDLE window most of the time and find > "help (...)" very useful to summarize things. The display comes up > directly (doesn't return a text, which I could edit, assign or store). I > suspect that there are ways to redirect the

Re: Proposed new syntax

2017-08-12 Thread Peter Otten
Rustom Mody wrote: > [ My conjecture: The word ‘comprehension’ used this way in English is > meaningless and is probably an infelicious translation of something which > makes sense in German] The meaning of comprehension is probably closer to "comprise" than "comprehend".

Re: Planning a Python Course for Beginners

2017-08-10 Thread Peter Otten
Marko Rauhamaa wrote: > Peter Otten <__pete...@web.de>: > >> Steve D'Aprano wrote: >>> The C code says: >>> >>>>/* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid >>>>excessive hash collisions for dicts and sets */

Re: Planning a Python Course for Beginners

2017-08-10 Thread Peter Otten
Steve D'Aprano wrote: > The C code says: > >>/* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid >>excessive hash collisions for dicts and sets */ > > which I think agrees with my comment: using the id() itself would put too > many objects in the same bucket (i.e. too many

Re: Planning a Python Course for Beginners

2017-08-10 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, 09 Aug 2017 20:07:48 +0300, Marko Rauhamaa wrote: > >> Good point! A very good __hash__() implementation is: >> >> def __hash__(self): >> return id(self) >> >> In fact, I didn't know Python (kinda) did this by default already. I >> can't find that

Re: __new__ and __init__ - why does this work?

2017-08-09 Thread Peter Otten
Ian Pilcher wrote: > I have created a class to provide a "hash consing"[1] set. > >class UniqueSet(frozenset): > >_registry = dict() > >def __new__(cls, *args, **kwargs): >set = frozenset(*args, **kwargs) >try: >return

Re: ValueError: operands could not be broadcast together with shapes

2017-08-06 Thread Peter Otten
Ho Yeung Lee wrote: > def mse(imageA, imageB): > err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2) > err /= float(imageA.shape[0] * imageA.shape[1]) > return err > > original = cv2.imread("C:\\Users\\hello\\Documents\\words\\" + xx) > later =

Re: program that search string in text file and do something

2017-08-04 Thread Peter Otten
Peter Otten wrote: > What we won't do is write a program for you ready to present to your > teacher. I should have known better :( -- https://mail.python.org/mailman/listinfo/python-list

Re: program that search string in text file and do something

2017-08-04 Thread Peter Otten
alon.naj...@gmail.com wrote: > Hi, I'm new to thing forum and to this programming in python! > > can someone help me and write me how to write a program that do: > - search for a string in certain text file and if it founds the string it > delete the file? and print something? Programming is

Re: how to fast processing one million strings to remove quotes

2017-08-04 Thread Peter Otten
Tim Daneliuk wrote: > On 08/02/2017 10:05 AM, Daiyue Weng wrote: >> Hi, I am trying to removing extra quotes from a large set of strings (a >> list of strings), so for each original string, it looks like, >> >> """str_value1"",""str_value2"",""str_value3"",1,""str_value4""" >> >> >> I like to

Re: how to fast processing one million strings to remove quotes

2017-08-02 Thread Peter Otten
Daiyue Weng wrote: > On 2 August 2017 at 19:13, Peter Otten <__pete...@web.de> wrote: > >> Daiyue Weng wrote: >> >> > Hi, I am trying to removing extra quotes from a large set of strings (a >> > list of strings), so for each original string, it looks li

Re: how to fast processing one million strings to remove quotes

2017-08-02 Thread Peter Otten
Daiyue Weng wrote: > Hi, I am trying to removing extra quotes from a large set of strings (a > list of strings), so for each original string, it looks like, > > """str_value1"",""str_value2"",""str_value3"",1,""str_value4""" Where did you get that strange list from in the first place? If it is

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